| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #if !defined(__has_feature) || !__has_feature(objc_arc) | 5 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 6 #error "This file requires ARC support." | 6 #error "This file requires ARC support." |
| 7 #endif | 7 #endif |
| 8 | 8 |
| 9 #import "remoting/ios/app/pin_entry_view.h" | 9 #import "remoting/ios/app/pin_entry_view.h" |
| 10 | 10 |
| 11 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" | 11 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" |
| 12 #import "remoting/ios/app/remoting_theme.h" | 12 #import "remoting/ios/app/remoting_theme.h" |
| 13 | 13 |
| 14 static const CGFloat kMargin = 5.f; | 14 static const CGFloat kMargin = 5.f; |
| 15 static const CGFloat kPadding = 6.f; | 15 static const CGFloat kPadding = 8.f; |
| 16 static const CGFloat kLineSpace = 12.f; | 16 static const CGFloat kLineSpace = 12.f; |
| 17 | 17 |
| 18 @interface PinEntryView () { | 18 @interface PinEntryView ()<UITextFieldDelegate> { |
| 19 UISwitch* _pairingSwitch; | 19 UISwitch* _pairingSwitch; |
| 20 UILabel* _pairingLabel; | 20 UILabel* _pairingLabel; |
| 21 MDCFloatingButton* _pinButton; | 21 MDCFloatingButton* _pinButton; |
| 22 UITextField* _pinEntry; | 22 UITextField* _pinEntry; |
| 23 } | 23 } |
| 24 @end | 24 @end |
| 25 | 25 |
| 26 @implementation PinEntryView | 26 @implementation PinEntryView |
| 27 | 27 |
| 28 @synthesize delegate = _delegate; | 28 @synthesize delegate = _delegate; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 45 _pairingLabel.text = @"Remember my PIN on this device."; | 45 _pairingLabel.text = @"Remember my PIN on this device."; |
| 46 [self addSubview:_pairingLabel]; | 46 [self addSubview:_pairingLabel]; |
| 47 | 47 |
| 48 _pinButton = | 48 _pinButton = |
| 49 [MDCFloatingButton floatingButtonWithShape:MDCFloatingButtonShapeMini]; | 49 [MDCFloatingButton floatingButtonWithShape:MDCFloatingButtonShapeMini]; |
| 50 [_pinButton setImage:RemotingTheme.arrowIcon forState:UIControlStateNormal]; | 50 [_pinButton setImage:RemotingTheme.arrowIcon forState:UIControlStateNormal]; |
| 51 [_pinButton addTarget:self | 51 [_pinButton addTarget:self |
| 52 action:@selector(didTapPinEntry:) | 52 action:@selector(didTapPinEntry:) |
| 53 forControlEvents:UIControlEventTouchUpInside]; | 53 forControlEvents:UIControlEventTouchUpInside]; |
| 54 _pinButton.translatesAutoresizingMaskIntoConstraints = NO; | 54 _pinButton.translatesAutoresizingMaskIntoConstraints = NO; |
| 55 _pinButton.enabled = NO; |
| 55 [self addSubview:_pinButton]; | 56 [self addSubview:_pinButton]; |
| 56 | 57 |
| 57 _pinEntry = [[UITextField alloc] init]; | 58 _pinEntry = [[UITextField alloc] init]; |
| 58 _pinEntry.textColor = [UIColor whiteColor]; | 59 _pinEntry.textColor = [UIColor whiteColor]; |
| 59 _pinEntry.secureTextEntry = YES; | 60 _pinEntry.secureTextEntry = YES; |
| 60 _pinEntry.keyboardType = UIKeyboardTypeNumberPad; | 61 _pinEntry.keyboardType = UIKeyboardTypeNumberPad; |
| 61 // TODO(nicholss): L18N this. | 62 // TODO(nicholss): L18N this. |
| 62 _pinEntry.attributedPlaceholder = [[NSAttributedString alloc] | 63 _pinEntry.attributedPlaceholder = [[NSAttributedString alloc] |
| 63 initWithString:@"Enter PIN" | 64 initWithString:@"Enter PIN" |
| 64 attributes:@{ | 65 attributes:@{ |
| 65 NSForegroundColorAttributeName : | 66 NSForegroundColorAttributeName : |
| 66 [UIColor colorWithRed:1.f green:1.f blue:1.f alpha:0.5] | 67 [UIColor colorWithRed:1.f green:1.f blue:1.f alpha:0.5] |
| 67 }]; | 68 }]; |
| 69 _pinEntry.delegate = self; |
| 68 [self addSubview:_pinEntry]; | 70 [self addSubview:_pinEntry]; |
| 69 } | 71 } |
| 70 return self; | 72 return self; |
| 71 } | 73 } |
| 72 | 74 |
| 73 #pragma mark - UIView | 75 #pragma mark - UIView |
| 74 | 76 |
| 75 - (BOOL)canBecomeFirstResponder { | 77 - (BOOL)canBecomeFirstResponder { |
| 76 return [_pinEntry canBecomeFirstResponder]; | 78 return [_pinEntry canBecomeFirstResponder]; |
| 77 } | 79 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 104 _pairingSwitch.center = CGPointMake( | 106 _pairingSwitch.center = CGPointMake( |
| 105 kMargin + _pairingSwitch.frame.size.width / 2.f, | 107 kMargin + _pairingSwitch.frame.size.width / 2.f, |
| 106 buttonSize + _pairingSwitch.frame.size.height / 2.f + kLineSpace); | 108 buttonSize + _pairingSwitch.frame.size.height / 2.f + kLineSpace); |
| 107 | 109 |
| 108 _pairingLabel.frame = | 110 _pairingLabel.frame = |
| 109 CGRectMake(kMargin + _pairingSwitch.frame.size.width + kPadding, | 111 CGRectMake(kMargin + _pairingSwitch.frame.size.width + kPadding, |
| 110 buttonSize + kLineSpace, 0.f, 0.f); | 112 buttonSize + kLineSpace, 0.f, 0.f); |
| 111 [_pairingLabel sizeToFit]; | 113 [_pairingLabel sizeToFit]; |
| 112 } | 114 } |
| 113 | 115 |
| 116 #pragma mark - UITextFieldDelegate |
| 117 |
| 118 - (BOOL)textField:(UITextField*)textField |
| 119 shouldChangeCharactersInRange:(NSRange)range |
| 120 replacementString:(NSString*)string { |
| 121 if (textField == _pinEntry) { |
| 122 NSUInteger length = _pinEntry.text.length - range.length + string.length; |
| 123 _pinButton.enabled = length >= 6; |
| 124 } |
| 125 return YES; |
| 126 } |
| 127 |
| 128 - (BOOL)textFieldShouldReturn:(UITextField*)textField { |
| 129 NSLog(@"textFieldShouldReturn"); |
| 130 if ([_pinButton isEnabled]) { |
| 131 [self didTapPinEntry:textField]; |
| 132 return YES; |
| 133 } |
| 134 return NO; |
| 135 } |
| 136 |
| 137 #pragma mark - Public |
| 138 |
| 139 - (void)clearPinEntry { |
| 140 _pinEntry.text = @""; |
| 141 _pinButton.enabled = NO; |
| 142 } |
| 143 |
| 114 #pragma mark - Private | 144 #pragma mark - Private |
| 115 | 145 |
| 116 - (void)didTapPinEntry:(id)sender { | 146 - (void)didTapPinEntry:(id)sender { |
| 117 [_delegate didProvidePin:_pinEntry.text createPairing:_pairingSwitch.isOn]; | 147 [_delegate didProvidePin:_pinEntry.text createPairing:_pairingSwitch.isOn]; |
| 118 [_pinEntry endEditing:YES]; | 148 [_pinEntry endEditing:YES]; |
| 119 } | 149 } |
| 120 | 150 |
| 121 @end | 151 @end |
| OLD | NEW |