| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 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/ios/ui/pin_entry_view_controller.h" |
| 10 |
| 11 #import "remoting/ios/utility.h" |
| 12 |
| 13 @interface PinEntryViewController (Private) |
| 14 - (void)setFrameForControls; |
| 15 @end |
| 16 |
| 17 @implementation PinEntryViewController |
| 18 |
| 19 @synthesize delegate = _delegate; |
| 20 @synthesize shouldPrompt = _shouldPrompt; |
| 21 @synthesize pairingSupported = _pairingSupported; |
| 22 |
| 23 // Override UIViewController |
| 24 - (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil { |
| 25 // NibName is the * part of your *.xib file |
| 26 self = [super initWithNibName:@"pin_entry_view_controller" bundle:nil]; |
| 27 if (self) { |
| 28 // Custom initialization |
| 29 } |
| 30 return self; |
| 31 } |
| 32 |
| 33 // Override UIViewController |
| 34 // Controls are not created immediately, properties must be set before the form |
| 35 // is displayed |
| 36 - (void)viewWillAppear:(BOOL)animated { |
| 37 _host.text = _hostName; |
| 38 [_switchAskAgain setOn:!_shouldPrompt]; |
| 39 if (!_pairingSupported) { |
| 40 _switchAskAgain.hidden = YES; |
| 41 _shouldSavePin.hidden = YES; |
| 42 _switchAskAgain.enabled = NO; |
| 43 } |
| 44 [self setFrameForControls]; |
| 45 [_hostPin becomeFirstResponder]; |
| 46 } |
| 47 |
| 48 // Override UIViewController |
| 49 // When the orientation changes recenter the prompt modal |
| 50 - (void)didRotateFromInterfaceOrientation: |
| 51 (UIInterfaceOrientation)fromInterfaceOrientation { |
| 52 [self setFrameForControls]; |
| 53 } |
| 54 |
| 55 // @protocol UITextFieldDelegate, called when the 'enter' key is pressed |
| 56 - (BOOL)textFieldShouldReturn:(UITextField*)textField { |
| 57 [textField resignFirstResponder]; |
| 58 if (textField == _hostPin) |
| 59 [self buttonConnectClicked:self]; |
| 60 return YES; |
| 61 } |
| 62 |
| 63 - (IBAction)buttonCancelClicked:(id)sender { |
| 64 [_delegate cancelledConnectToHostWithPin]; |
| 65 } |
| 66 |
| 67 - (IBAction)buttonConnectClicked:(id)sender { |
| 68 [_delegate connectToHostWithPin:_hostPin.text |
| 69 shouldPrompt:!_switchAskAgain.isOn]; |
| 70 } |
| 71 |
| 72 // Center the prompt modal and account for orientation |
| 73 - (void)setFrameForControls { |
| 74 CGRect mainFrame = self.view.frame; |
| 75 |
| 76 CGRect controlFrame = _controlView.frame; |
| 77 if (([Utility isInLandscapeMode] && |
| 78 (mainFrame.size.height > mainFrame.size.width)) || |
| 79 (![Utility isInLandscapeMode] && |
| 80 (mainFrame.size.width > mainFrame.size.height))) { |
| 81 controlFrame.origin.x = |
| 82 (mainFrame.size.height / 2) - (controlFrame.size.width / 2); |
| 83 } else { |
| 84 controlFrame.origin.x = |
| 85 (mainFrame.size.width / 2) - (controlFrame.size.width / 2); |
| 86 } |
| 87 _controlView.frame = controlFrame; |
| 88 } |
| 89 |
| 90 @end |
| OLD | NEW |