| Index: remoting/ios/ui/pin_entry_view_controller.mm
|
| diff --git a/remoting/ios/ui/pin_entry_view_controller.mm b/remoting/ios/ui/pin_entry_view_controller.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f3a59934e59b769d4b5bea3b2c5dd9c74125aac0
|
| --- /dev/null
|
| +++ b/remoting/ios/ui/pin_entry_view_controller.mm
|
| @@ -0,0 +1,90 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#if !defined(__has_feature) || !__has_feature(objc_arc)
|
| +#error "This file requires ARC support."
|
| +#endif
|
| +
|
| +#import "remoting/ios/ui/pin_entry_view_controller.h"
|
| +
|
| +#import "remoting/ios/utility.h"
|
| +
|
| +@interface PinEntryViewController (Private)
|
| +- (void)setFrameForControls;
|
| +@end
|
| +
|
| +@implementation PinEntryViewController
|
| +
|
| +@synthesize delegate = _delegate;
|
| +@synthesize shouldPrompt = _shouldPrompt;
|
| +@synthesize pairingSupported = _pairingSupported;
|
| +
|
| +// Override UIViewController
|
| +- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil {
|
| + // NibName is the * part of your *.xib file
|
| + self = [super initWithNibName:@"pin_entry_view_controller" bundle:nil];
|
| + if (self) {
|
| + // Custom initialization
|
| + }
|
| + return self;
|
| +}
|
| +
|
| +// Override UIViewController
|
| +// Controls are not created immediately, properties must be set before the form
|
| +// is displayed
|
| +- (void)viewWillAppear:(BOOL)animated {
|
| + _host.text = _hostName;
|
| + [_switchAskAgain setOn:!_shouldPrompt];
|
| + if (!_pairingSupported) {
|
| + _switchAskAgain.hidden = YES;
|
| + _shouldSavePin.hidden = YES;
|
| + _switchAskAgain.enabled = NO;
|
| + }
|
| + [self setFrameForControls];
|
| + [_hostPin becomeFirstResponder];
|
| +}
|
| +
|
| +// Override UIViewController
|
| +// When the orientation changes recenter the prompt modal
|
| +- (void)didRotateFromInterfaceOrientation:
|
| + (UIInterfaceOrientation)fromInterfaceOrientation {
|
| + [self setFrameForControls];
|
| +}
|
| +
|
| +// @protocol UITextFieldDelegate, called when the 'enter' key is pressed
|
| +- (BOOL)textFieldShouldReturn:(UITextField*)textField {
|
| + [textField resignFirstResponder];
|
| + if (textField == _hostPin)
|
| + [self buttonConnectClicked:self];
|
| + return YES;
|
| +}
|
| +
|
| +- (IBAction)buttonCancelClicked:(id)sender {
|
| + [_delegate cancelledConnectToHostWithPin];
|
| +}
|
| +
|
| +- (IBAction)buttonConnectClicked:(id)sender {
|
| + [_delegate connectToHostWithPin:_hostPin.text
|
| + shouldPrompt:!_switchAskAgain.isOn];
|
| +}
|
| +
|
| +// Center the prompt modal and account for orientation
|
| +- (void)setFrameForControls {
|
| + CGRect mainFrame = self.view.frame;
|
| +
|
| + CGRect controlFrame = _controlView.frame;
|
| + if (([Utility isInLandscapeMode] &&
|
| + (mainFrame.size.height > mainFrame.size.width)) ||
|
| + (![Utility isInLandscapeMode] &&
|
| + (mainFrame.size.width > mainFrame.size.height))) {
|
| + controlFrame.origin.x =
|
| + (mainFrame.size.height / 2) - (controlFrame.size.width / 2);
|
| + } else {
|
| + controlFrame.origin.x =
|
| + (mainFrame.size.width / 2) - (controlFrame.size.width / 2);
|
| + }
|
| + _controlView.frame = controlFrame;
|
| +}
|
| +
|
| +@end
|
|
|