Chromium Code Reviews| Index: remoting/client/ios/app/pin_entry_view_controller.mm |
| diff --git a/remoting/client/ios/app/pin_entry_view_controller.mm b/remoting/client/ios/app/pin_entry_view_controller.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..118e2104ba14610b41cfd9684478cc3683f7bfcd |
| --- /dev/null |
| +++ b/remoting/client/ios/app/pin_entry_view_controller.mm |
| @@ -0,0 +1,184 @@ |
| +// Copyright 2017 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/client/ios/app/pin_entry_view_controller.h" |
| + |
| +#import "ios/third_party/material_components_ios/src/components/Buttons/src/MaterialButtons.h" |
| +#import "ios/third_party/material_components_ios/src/components/NavigationBar/src/MaterialNavigationBar.h" |
| + |
| +static const CGFloat kHostCardIconSize = 45.f; |
| + |
| +@interface PinEntryViewController () { |
| + PinEntryModalCallback _callback; |
|
Lambros
2017/04/05 00:17:40
This callback doesn't seem to be fired anywhere?
nicholss
2017/04/05 16:25:41
The class is not finished yet, I have not gotten t
|
| + MDCNavigationBar* _navBar; |
|
Lambros
2017/04/05 00:17:40
Does this need to be a member? It is only used in
nicholss
2017/04/05 16:25:41
It needs to be held because it is not added to a v
|
| +} |
| +@end |
| + |
| +@implementation PinEntryViewController |
| + |
| +- (id)initWithCallback:(PinEntryModalCallback)callback { |
| + self = [super init]; |
| + if (self) { |
| + _callback = callback; |
| + } |
| + return self; |
| +} |
| + |
| +#pragma mark - UIViewController |
| + |
| +- (void)viewDidLoad { |
| + [super viewDidLoad]; |
| + self.view.backgroundColor = [UIColor whiteColor]; |
| + |
| + // TODO(nicholss): Localize this file. |
| + self.navigationItem.rightBarButtonItem = |
| + [[UIBarButtonItem alloc] initWithTitle:@"CANCEL" |
| + style:UIBarButtonItemStylePlain |
| + target:self |
| + action:@selector(didTapCancel:)]; |
| + |
| + _navBar = [[MDCNavigationBar alloc] initWithFrame:CGRectZero]; |
| + [_navBar observeNavigationItem:self.navigationItem]; |
| + |
| + [_navBar setBackgroundColor:[UIColor blackColor]]; |
| + MDCNavigationBarTextColorAccessibilityMutator* mutator = |
| + [[MDCNavigationBarTextColorAccessibilityMutator alloc] init]; |
| + [mutator mutate:_navBar]; |
| + |
| + [self.view addSubview:_navBar]; |
| + _navBar.translatesAutoresizingMaskIntoConstraints = NO; |
| + |
| + UIView* entryView = [[UIView alloc] initWithFrame:CGRectZero]; |
| + |
| + [self.view addSubview:entryView]; |
| + entryView.translatesAutoresizingMaskIntoConstraints = NO; |
| + |
| + UIImageView* imageView = [[UIImageView alloc] |
| + initWithFrame:CGRectMake(0, 0, kHostCardIconSize, kHostCardIconSize)]; |
| + imageView.contentMode = UIViewContentModeCenter; |
| + imageView.alpha = 0.87f; |
| + imageView.backgroundColor = UIColor.lightGrayColor; |
| + imageView.layer.cornerRadius = kHostCardIconSize / 2.f; |
| + imageView.layer.masksToBounds = YES; |
| + imageView.translatesAutoresizingMaskIntoConstraints = NO; |
| + [self.view addSubview:imageView]; |
| + |
| + UILabel* titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| + titleLabel.textColor = [UIColor colorWithWhite:0 alpha:0.87f]; |
| + titleLabel.text = @"Host XXX"; |
| + titleLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| + [self.view addSubview:titleLabel]; |
| + [titleLabel sizeToFit]; |
| + |
| + MDCRaisedButton* pinButton = [[MDCRaisedButton alloc] init]; |
| + [pinButton setTitle:@"->" forState:UIControlStateNormal]; |
| + [pinButton sizeToFit]; |
| + [pinButton addTarget:self |
| + action:@selector(didTapPinEntry:) |
| + forControlEvents:UIControlEventTouchUpInside]; |
| + pinButton.translatesAutoresizingMaskIntoConstraints = NO; |
| + [entryView addSubview:pinButton]; |
| + |
| + UITextField* pinEntry = |
| + [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 100, 10)]; |
| + pinEntry.textAlignment = NSTextAlignmentCenter; |
| + pinEntry.secureTextEntry = YES; |
| + pinEntry.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
| + pinEntry.keyboardType = UIKeyboardTypeNumberPad; |
| + pinEntry.attributedPlaceholder = |
| + [[NSAttributedString alloc] initWithString:@"Enter PIN"]; |
| + [entryView addSubview:pinEntry]; |
| + pinEntry.translatesAutoresizingMaskIntoConstraints = NO; |
| + [pinEntry sizeToFit]; |
| + |
| + NSDictionary* views = @{ |
| + @"entryView" : entryView, |
| + @"navBar" : _navBar, |
| + @"imageView" : imageView, |
| + @"titleLabel" : titleLabel, |
| + @"pinEntry" : pinEntry, |
| + @"pinButton" : pinButton |
| + }; |
| + |
| + NSDictionary* metrics = |
| + @{ @"imageEdge" : @150.0, |
| + @"padding" : @15.0, |
| + @"imageSize" : @45.0 }; |
| + |
| + [self.view addConstraints:[NSLayoutConstraint |
| + constraintsWithVisualFormat:@"|[navBar]|" |
| + options:0 |
| + metrics:metrics |
| + views:views]]; |
| + [self.view addConstraints: |
| + [NSLayoutConstraint |
| + constraintsWithVisualFormat:@"|-[imageView(==imageSize)]-|" |
| + options:0 |
| + metrics:metrics |
| + views:views]]; |
| + |
| + [self.view addConstraints: |
| + [NSLayoutConstraint |
| + constraintsWithVisualFormat:@"|-[titleLabel]-|" |
| + options:NSLayoutFormatAlignAllCenterX |
| + metrics:metrics |
| + views:views]]; |
| + [self.view addConstraints:[NSLayoutConstraint |
| + constraintsWithVisualFormat:@"|[entryView]|" |
| + options:0 |
| + metrics:metrics |
| + views:views]]; |
| + [self.view |
| + addConstraints:[NSLayoutConstraint |
| + constraintsWithVisualFormat:@"V:|[navBar]-[imageView(=" |
|
nicholss
2017/04/05 16:25:41
Stupid auto formatter, this is unreadable. I am mo
|
| + @"=imageSize)]-[" |
| + @"titleLabel]-[entryView]" |
| + @"|" |
| + options:0 |
| + metrics:metrics |
| + views:views]]; |
| + |
| + [entryView |
| + addConstraints: |
| + [NSLayoutConstraint |
| + constraintsWithVisualFormat:@"|-[pinEntry]-[pinButton(==70)]-|" |
|
Lambros
2017/04/05 00:17:40
What is ==70 here?
nicholss
2017/04/05 16:25:41
Magic... I will fix.
|
| + options:NSLayoutFormatAlignAllCenterY |
| + metrics:metrics |
| + views:views]]; |
| + [entryView addConstraints: |
| + [NSLayoutConstraint |
| + constraintsWithVisualFormat:@"V:|->=padding-[pinButton]" |
| + options:0 |
| + metrics:metrics |
| + views:views]]; |
| + [entryView |
| + addConstraints:[NSLayoutConstraint |
| + constraintsWithVisualFormat:@"V:|->=padding-[pinEntry]" |
| + options:0 |
| + metrics:metrics |
| + views:views]]; |
| + [entryView layoutIfNeeded]; |
| +} |
| + |
| +- (void)viewWillAppear:(BOOL)animated { |
| + [super viewWillAppear:animated]; |
| + |
| + [self.navigationController setNavigationBarHidden:YES animated:animated]; |
| +} |
| + |
| +#pragma mark - Private |
| + |
| +- (void)didTapPinEntry:(id)sender { |
| + NSLog(@"%@ was tapped.", NSStringFromClass([sender class])); |
| +} |
| + |
| +- (void)didTapCancel:(id)sender { |
| + NSLog(@"%@ was tapped.", NSStringFromClass([sender class])); |
| +} |
| + |
| +@end |