OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 6 #error "This file requires ARC support." |
| 7 #endif |
| 8 |
| 9 #import "remoting/client/ios/app/pin_entry_view.h" |
| 10 |
| 11 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" |
| 12 |
| 13 static const CGFloat kMargin = 5.f; |
| 14 static const CGFloat kPadding = 6.f; |
| 15 static const CGFloat kLineSpace = 12.f; |
| 16 |
| 17 @interface PinEntryView () { |
| 18 UISwitch* _pairingSwitch; |
| 19 UILabel* _pairingLabel; |
| 20 MDCFloatingButton* _pinButton; |
| 21 UITextField* _pinEntry; |
| 22 } |
| 23 @end |
| 24 |
| 25 @implementation PinEntryView |
| 26 |
| 27 @synthesize delegate = _delegate; |
| 28 |
| 29 - (id)initWithFrame:(CGRect)frame { |
| 30 self = [super initWithFrame:frame]; |
| 31 if (self) { |
| 32 self.backgroundColor = [UIColor clearColor]; |
| 33 |
| 34 _pairingSwitch = [[UISwitch alloc] init]; |
| 35 _pairingSwitch.tintColor = |
| 36 [UIColor colorWithRed:1.f green:1.f blue:1.f alpha:0.5]; |
| 37 _pairingSwitch.transform = CGAffineTransformMakeScale(0.5, 0.5); |
| 38 [self addSubview:_pairingSwitch]; |
| 39 |
| 40 _pairingLabel = [[UILabel alloc] init]; |
| 41 _pairingLabel.textColor = |
| 42 [UIColor colorWithRed:1.f green:1.f blue:1.f alpha:0.5]; |
| 43 _pairingLabel.font = [UIFont systemFontOfSize:12.f]; |
| 44 _pairingLabel.text = @"Remember my PIN on this device."; |
| 45 [self addSubview:_pairingLabel]; |
| 46 |
| 47 _pinButton = |
| 48 [MDCFloatingButton floatingButtonWithShape:MDCFloatingButtonShapeMini]; |
| 49 [_pinButton setTitle:@"+" forState:UIControlStateNormal]; |
| 50 |
| 51 // TODO(nicholss): Update "->" to the arrow icon. |
| 52 [_pinButton setTitle:@"->" forState:UIControlStateNormal]; |
| 53 [_pinButton addTarget:self |
| 54 action:@selector(didTapPinEntry:) |
| 55 forControlEvents:UIControlEventTouchUpInside]; |
| 56 _pinButton.translatesAutoresizingMaskIntoConstraints = NO; |
| 57 [self addSubview:_pinButton]; |
| 58 |
| 59 _pinEntry = [[UITextField alloc] init]; |
| 60 _pinEntry.textColor = [UIColor whiteColor]; |
| 61 _pinEntry.secureTextEntry = YES; |
| 62 _pinEntry.keyboardType = UIKeyboardTypeNumberPad; |
| 63 // TODO(nicholss): L18N this. |
| 64 _pinEntry.attributedPlaceholder = [[NSAttributedString alloc] |
| 65 initWithString:@"Enter PIN" |
| 66 attributes:@{ |
| 67 NSForegroundColorAttributeName : |
| 68 [UIColor colorWithRed:1.f green:1.f blue:1.f alpha:0.5] |
| 69 }]; |
| 70 [self addSubview:_pinEntry]; |
| 71 } |
| 72 return self; |
| 73 } |
| 74 |
| 75 #pragma mark - UIView |
| 76 |
| 77 - (BOOL)canBecomeFirstResponder { |
| 78 return [_pinEntry canBecomeFirstResponder]; |
| 79 } |
| 80 |
| 81 - (BOOL)becomeFirstResponder { |
| 82 return [_pinEntry becomeFirstResponder]; |
| 83 } |
| 84 |
| 85 - (BOOL)endEditing:(BOOL)force { |
| 86 return [_pinEntry endEditing:force]; |
| 87 } |
| 88 |
| 89 - (void)layoutSubviews { |
| 90 [super layoutSubviews]; |
| 91 |
| 92 [_pinButton sizeToFit]; |
| 93 CGFloat buttonSize = _pinButton.frame.size.width; // Assume circle. |
| 94 |
| 95 _pinEntry.frame = |
| 96 CGRectMake(kMargin, 0.f, |
| 97 self.frame.size.width - kPadding - kMargin * 2.f - buttonSize, |
| 98 buttonSize); |
| 99 |
| 100 [_pinButton sizeToFit]; |
| 101 _pinButton.frame = |
| 102 CGRectMake(self.frame.size.width - kPadding - kMargin - buttonSize, 0.f, |
| 103 buttonSize, buttonSize); |
| 104 |
| 105 [_pairingSwitch sizeToFit]; |
| 106 _pairingSwitch.center = CGPointMake( |
| 107 kMargin + _pairingSwitch.frame.size.width / 2.f, |
| 108 buttonSize + _pairingSwitch.frame.size.height / 2.f + kLineSpace); |
| 109 |
| 110 _pairingLabel.frame = |
| 111 CGRectMake(kMargin + _pairingSwitch.frame.size.width + kPadding, |
| 112 buttonSize + kLineSpace, 0.f, 0.f); |
| 113 [_pairingLabel sizeToFit]; |
| 114 } |
| 115 |
| 116 #pragma mark - Private |
| 117 |
| 118 - (void)didTapPinEntry:(id)sender { |
| 119 [_delegate didProvidePin:_pinEntry.text createPairing:_pairingSwitch.isOn]; |
| 120 [_pinEntry endEditing:YES]; |
| 121 } |
| 122 |
| 123 @end |
OLD | NEW |