Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: remoting/client/ios/app/pin_entry_view_controller.mm

Issue 2795163003: CRD iOS: Adding pin entry view controller. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_controller.h"
10
11 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
12 #import "ios/third_party/material_components_ios/src/components/NavigationBar/sr c/MaterialNavigationBar.h"
13
14 static const CGFloat kHostCardIconSize = 45.f;
15
16 @interface PinEntryViewController () {
17 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
18 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
19 }
20 @end
21
22 @implementation PinEntryViewController
23
24 - (id)initWithCallback:(PinEntryModalCallback)callback {
25 self = [super init];
26 if (self) {
27 _callback = callback;
28 }
29 return self;
30 }
31
32 #pragma mark - UIViewController
33
34 - (void)viewDidLoad {
35 [super viewDidLoad];
36 self.view.backgroundColor = [UIColor whiteColor];
37
38 // TODO(nicholss): Localize this file.
39 self.navigationItem.rightBarButtonItem =
40 [[UIBarButtonItem alloc] initWithTitle:@"CANCEL"
41 style:UIBarButtonItemStylePlain
42 target:self
43 action:@selector(didTapCancel:)];
44
45 _navBar = [[MDCNavigationBar alloc] initWithFrame:CGRectZero];
46 [_navBar observeNavigationItem:self.navigationItem];
47
48 [_navBar setBackgroundColor:[UIColor blackColor]];
49 MDCNavigationBarTextColorAccessibilityMutator* mutator =
50 [[MDCNavigationBarTextColorAccessibilityMutator alloc] init];
51 [mutator mutate:_navBar];
52
53 [self.view addSubview:_navBar];
54 _navBar.translatesAutoresizingMaskIntoConstraints = NO;
55
56 UIView* entryView = [[UIView alloc] initWithFrame:CGRectZero];
57
58 [self.view addSubview:entryView];
59 entryView.translatesAutoresizingMaskIntoConstraints = NO;
60
61 UIImageView* imageView = [[UIImageView alloc]
62 initWithFrame:CGRectMake(0, 0, kHostCardIconSize, kHostCardIconSize)];
63 imageView.contentMode = UIViewContentModeCenter;
64 imageView.alpha = 0.87f;
65 imageView.backgroundColor = UIColor.lightGrayColor;
66 imageView.layer.cornerRadius = kHostCardIconSize / 2.f;
67 imageView.layer.masksToBounds = YES;
68 imageView.translatesAutoresizingMaskIntoConstraints = NO;
69 [self.view addSubview:imageView];
70
71 UILabel* titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
72 titleLabel.textColor = [UIColor colorWithWhite:0 alpha:0.87f];
73 titleLabel.text = @"Host XXX";
74 titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
75 [self.view addSubview:titleLabel];
76 [titleLabel sizeToFit];
77
78 MDCRaisedButton* pinButton = [[MDCRaisedButton alloc] init];
79 [pinButton setTitle:@"->" forState:UIControlStateNormal];
80 [pinButton sizeToFit];
81 [pinButton addTarget:self
82 action:@selector(didTapPinEntry:)
83 forControlEvents:UIControlEventTouchUpInside];
84 pinButton.translatesAutoresizingMaskIntoConstraints = NO;
85 [entryView addSubview:pinButton];
86
87 UITextField* pinEntry =
88 [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 100, 10)];
89 pinEntry.textAlignment = NSTextAlignmentCenter;
90 pinEntry.secureTextEntry = YES;
91 pinEntry.autoresizingMask = UIViewAutoresizingFlexibleWidth;
92 pinEntry.keyboardType = UIKeyboardTypeNumberPad;
93 pinEntry.attributedPlaceholder =
94 [[NSAttributedString alloc] initWithString:@"Enter PIN"];
95 [entryView addSubview:pinEntry];
96 pinEntry.translatesAutoresizingMaskIntoConstraints = NO;
97 [pinEntry sizeToFit];
98
99 NSDictionary* views = @{
100 @"entryView" : entryView,
101 @"navBar" : _navBar,
102 @"imageView" : imageView,
103 @"titleLabel" : titleLabel,
104 @"pinEntry" : pinEntry,
105 @"pinButton" : pinButton
106 };
107
108 NSDictionary* metrics =
109 @{ @"imageEdge" : @150.0,
110 @"padding" : @15.0,
111 @"imageSize" : @45.0 };
112
113 [self.view addConstraints:[NSLayoutConstraint
114 constraintsWithVisualFormat:@"|[navBar]|"
115 options:0
116 metrics:metrics
117 views:views]];
118 [self.view addConstraints:
119 [NSLayoutConstraint
120 constraintsWithVisualFormat:@"|-[imageView(==imageSize)]-|"
121 options:0
122 metrics:metrics
123 views:views]];
124
125 [self.view addConstraints:
126 [NSLayoutConstraint
127 constraintsWithVisualFormat:@"|-[titleLabel]-|"
128 options:NSLayoutFormatAlignAllCenterX
129 metrics:metrics
130 views:views]];
131 [self.view addConstraints:[NSLayoutConstraint
132 constraintsWithVisualFormat:@"|[entryView]|"
133 options:0
134 metrics:metrics
135 views:views]];
136 [self.view
137 addConstraints:[NSLayoutConstraint
138 constraintsWithVisualFormat:@"V:|[navBar]-[imageView(="
nicholss 2017/04/05 16:25:41 Stupid auto formatter, this is unreadable. I am mo
139 @"=imageSize)]-["
140 @"titleLabel]-[entryView]"
141 @"|"
142 options:0
143 metrics:metrics
144 views:views]];
145
146 [entryView
147 addConstraints:
148 [NSLayoutConstraint
149 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.
150 options:NSLayoutFormatAlignAllCenterY
151 metrics:metrics
152 views:views]];
153 [entryView addConstraints:
154 [NSLayoutConstraint
155 constraintsWithVisualFormat:@"V:|->=padding-[pinButton]"
156 options:0
157 metrics:metrics
158 views:views]];
159 [entryView
160 addConstraints:[NSLayoutConstraint
161 constraintsWithVisualFormat:@"V:|->=padding-[pinEntry]"
162 options:0
163 metrics:metrics
164 views:views]];
165 [entryView layoutIfNeeded];
166 }
167
168 - (void)viewWillAppear:(BOOL)animated {
169 [super viewWillAppear:animated];
170
171 [self.navigationController setNavigationBarHidden:YES animated:animated];
172 }
173
174 #pragma mark - Private
175
176 - (void)didTapPinEntry:(id)sender {
177 NSLog(@"%@ was tapped.", NSStringFromClass([sender class]));
178 }
179
180 - (void)didTapCancel:(id)sender {
181 NSLog(@"%@ was tapped.", NSStringFromClass([sender class]));
182 }
183
184 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698