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

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

Issue 2846603002: Updating Pin Entry View and creating Connection Status View. (Closed)
Patch Set: Use viewWillLayoutSubviews. Created 3 years, 7 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;
18 MDCNavigationBar* _navBar;
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 @"buttonSize" : @70.0
113 };
114
115 [self.view addConstraints:[NSLayoutConstraint
116 constraintsWithVisualFormat:@"|[navBar]|"
117 options:0
118 metrics:metrics
119 views:views]];
120 [self.view addConstraints:
121 [NSLayoutConstraint
122 constraintsWithVisualFormat:@"|-[imageView(==imageSize)]-|"
123 options:0
124 metrics:metrics
125 views:views]];
126
127 [self.view addConstraints:
128 [NSLayoutConstraint
129 constraintsWithVisualFormat:@"|-[titleLabel]-|"
130 options:NSLayoutFormatAlignAllCenterX
131 metrics:metrics
132 views:views]];
133 [self.view addConstraints:[NSLayoutConstraint
134 constraintsWithVisualFormat:@"|[entryView]|"
135 options:0
136 metrics:metrics
137 views:views]];
138 NSString* vViewConstraint =
139 @"V:|[navBar]-[imageView(==imageSize)]-[titleLabel]-[entryView]|";
140 [self.view addConstraints:[NSLayoutConstraint
141 constraintsWithVisualFormat:vViewConstraint
142 options:0
143 metrics:metrics
144 views:views]];
145
146 [entryView addConstraints:
147 [NSLayoutConstraint
148 constraintsWithVisualFormat:
149 @"|-[pinEntry]-[pinButton(==buttonSize)]-|"
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
« no previous file with comments | « remoting/client/ios/app/pin_entry_view_controller.h ('k') | remoting/client/ios/app/remoting_view_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698