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

Side by Side Diff: remoting/client/ios/app/client_connection_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/client_connection_view_controller.h"
10
11 #import "ios/third_party/material_components_ios/src/components/ActivityIndicato r/src/MDCActivityIndicator.h"
12 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
13 #import "ios/third_party/material_components_ios/src/components/NavigationBar/sr c/MaterialNavigationBar.h"
14 #import "remoting/client/ios/app/pin_entry_view.h"
15 #import "remoting/client/ios/domain/client_session_details.h"
16 #import "remoting/client/ios/session/remoting_client.h"
17
18 #include "base/strings/sys_string_conversions.h"
19 #include "remoting/protocol/client_authentication_config.h"
20
21 static const CGFloat kIconRadius = 30.f;
22 static const CGFloat kActivityIndicatorStrokeWidth = 3.f;
23 static const CGFloat kActivityIndicatorRadius = 33.f;
24
25 static const CGFloat kPinEntryViewWidth = 240.f;
26 static const CGFloat kPinEntryViewHeight = 90.f;
27
28 static const CGFloat kCenterShift = -80.f;
29 static const CGFloat kPadding = 20.f;
30 static const CGFloat kMargin = 20.f;
31
32 static const CGFloat kBarHeight = 58.f;
33
34 @interface ClientConnectionViewController ()<PinEntryDelegate> {
35 UIImageView* _iconView;
36 MDCActivityIndicator* _activityIndicator;
37 UILabel* _statusLabel;
38 MDCNavigationBar* _navBar;
39 PinEntryView* _pinEntryView;
40 NSString* _remoteHostName;
41 }
42 @end
43
44 @implementation ClientConnectionViewController
45
46 @synthesize state = _state;
47 @synthesize delegate = _delegate;
48
49 - (id)init {
50 self = [super init];
51 if (self) {
52 self.navigationItem.rightBarButtonItem =
53 [[UIBarButtonItem alloc] initWithTitle:@"CANCEL"
54 style:UIBarButtonItemStylePlain
55 target:self
56 action:@selector(didTapCancel:)];
57
58 _navBar = [[MDCNavigationBar alloc] initWithFrame:CGRectZero];
59 [_navBar observeNavigationItem:self.navigationItem];
60
61 [_navBar setBackgroundColor:[UIColor blackColor]];
62 MDCNavigationBarTextColorAccessibilityMutator* mutator =
63 [[MDCNavigationBarTextColorAccessibilityMutator alloc] init];
64 [mutator mutate:_navBar];
65 [self.view addSubview:_navBar];
66 _navBar.translatesAutoresizingMaskIntoConstraints = NO;
67 _remoteHostName = @"";
68 }
69 return self;
70 }
71
72 #pragma mark - UIViewController
73
74 - (void)loadView {
75 [super loadView];
76
77 self.view.backgroundColor = [UIColor blackColor];
78
79 _activityIndicator = [[MDCActivityIndicator alloc] initWithFrame:CGRectZero];
80 [self.view addSubview:_activityIndicator];
81
82 _statusLabel = [[UILabel alloc] initWithFrame:CGRectZero];
83 [self.view addSubview:_statusLabel];
84
85 _iconView = [[UIImageView alloc] initWithFrame:CGRectZero];
86 [self.view addSubview:_iconView];
87
88 _pinEntryView = [[PinEntryView alloc] init];
89 [self.view addSubview:_pinEntryView];
90 _pinEntryView.delegate = self;
91 }
92
93 - (void)viewDidLoad {
94 [super viewDidLoad];
95
96 _iconView.contentMode = UIViewContentModeCenter;
97 _iconView.alpha = 0.87f;
98 _iconView.backgroundColor = UIColor.lightGrayColor;
99 _iconView.layer.cornerRadius = kIconRadius;
100 _iconView.layer.masksToBounds = YES;
101 _iconView.image = [UIImage imageNamed:@"ic_desktop"];
102
103 _activityIndicator.radius = kActivityIndicatorRadius;
104 _activityIndicator.trackEnabled = YES;
105 _activityIndicator.strokeWidth = kActivityIndicatorStrokeWidth;
106 _activityIndicator.cycleColors = @[ [UIColor whiteColor] ];
107
108 _statusLabel.numberOfLines = 1;
109 _statusLabel.lineBreakMode = NSLineBreakByTruncatingTail;
110 _statusLabel.textColor = [UIColor whiteColor];
111 _statusLabel.textAlignment = NSTextAlignmentCenter;
112
113 _pinEntryView.hidden = YES;
114 }
115
116 - (void)viewWillLayoutSubviews {
117 [super viewWillLayoutSubviews];
118
119 _navBar.frame = CGRectMake(0.f, 0.f, self.view.frame.size.width, kBarHeight);
120 [_navBar setNeedsLayout];
121
122 _iconView.frame = CGRectMake(0, 0, kIconRadius * 2, kIconRadius * 2.f);
123 _iconView.center =
124 CGPointMake(self.view.center.x, self.view.center.y + kCenterShift);
125
126 [_activityIndicator sizeToFit];
127 _activityIndicator.center = _iconView.center;
128
129 _statusLabel.frame =
130 CGRectMake(kMargin, _activityIndicator.center.y + kIconRadius + kPadding,
131 self.view.frame.size.width - kMargin * 2.f,
132 _statusLabel.font.pointSize * _statusLabel.numberOfLines);
133
134 _pinEntryView.frame = CGRectMake(
135 (self.view.frame.size.width - kPinEntryViewWidth) / 2.f,
136 _statusLabel.frame.origin.y + _statusLabel.frame.size.height + kPadding,
137 kPinEntryViewWidth, kPinEntryViewHeight);
138 }
139
140 - (void)viewWillAppear:(BOOL)animated {
141 [super viewWillAppear:animated];
142 [self.navigationController setNavigationBarHidden:YES animated:animated];
143
144 [[NSNotificationCenter defaultCenter]
145 addObserver:self
146 selector:@selector(hostSessionStatusChanged:)
147 name:kHostSessionStatusChanged
148 object:nil];
149 }
150
151 - (void)viewDidAppear:(BOOL)animated {
152 [super viewDidAppear:animated];
153 [[NSNotificationCenter defaultCenter]
154 addObserver:self
155 selector:@selector(keyboardWillShow:)
156 name:UIKeyboardWillShowNotification
157 object:nil];
158
159 [[NSNotificationCenter defaultCenter]
160 addObserver:self
161 selector:@selector(keyboardWillHide:)
162 name:UIKeyboardWillHideNotification
163 object:nil];
164
165 [_activityIndicator startAnimating];
166 }
167
168 - (void)viewWillDisappear:(BOOL)animated {
169 [super viewWillDisappear:animated];
170 [_activityIndicator stopAnimating];
171 [[NSNotificationCenter defaultCenter] removeObserver:self];
172 }
173
174 #pragma mark - Keyboard
175
176 - (void)keyboardWillShow:(NSNotification*)notification {
177 CGSize keyboardSize =
178 [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey]
179 CGRectValue]
180 .size;
181
182 [UIView
183 animateWithDuration:0.3
184 animations:^{
185 CGRect f = self.view.frame;
186 CGFloat newHeight =
187 self.view.frame.size.height - keyboardSize.height;
188 CGFloat overlap =
189 newHeight - (_pinEntryView.frame.origin.y +
190 _pinEntryView.frame.size.height + kPadding);
191 if (overlap < 0) {
192 f.origin.y = overlap;
193 self.view.frame = f;
194 }
195 }];
196 }
197
198 - (void)keyboardWillHide:(NSNotification*)notification {
199 [UIView animateWithDuration:0.3
200 animations:^{
201 CGRect f = self.view.frame;
202 f.origin.y = 0.f;
203 self.view.frame = f;
204 }];
205 }
206
207 #pragma mark - Properties
208
209 - (void)setState:(ClientConnectionViewState)state {
210 _state = state;
211 switch (_state) {
212 case ClientViewConnecting:
213 [self showConnectingState];
214 break;
215 case ClientViewPinPrompt:
216 [self showPinPromptState];
217 break;
218 case ClientViewConnected:
219 [self showConnectedState];
220 break;
221 }
222 }
223
224 - (void)setDelegate:(id<ClientConnectionViewControllerDelegate>)delegate {
225 _delegate = delegate;
226 if (_delegate) {
227 _remoteHostName = [_delegate getConnectingHostName];
228 // To get the view to use the new remote host name.
229 [self setState:_state];
230 }
231 }
232
233 #pragma mark - Private
234
235 - (void)showConnectingState {
236 [_pinEntryView endEditing:YES];
237 _statusLabel.text =
238 [NSString stringWithFormat:@"Connecting to %@", _remoteHostName];
239 [_activityIndicator stopAnimating];
240 _activityIndicator.cycleColors = @[ [UIColor whiteColor] ];
241 _activityIndicator.indicatorMode = MDCActivityIndicatorModeIndeterminate;
242 _activityIndicator.hidden = NO;
243 _pinEntryView.hidden = YES;
244 [_activityIndicator startAnimating];
245 }
246
247 - (void)showPinPromptState {
248 _statusLabel.text = [NSString stringWithFormat:@"%@", _remoteHostName];
249 [_activityIndicator stopAnimating];
250 _activityIndicator.hidden = YES;
251 _pinEntryView.hidden = NO;
252 [_pinEntryView becomeFirstResponder];
253 }
254
255 - (void)showConnectedState {
256 [_pinEntryView endEditing:YES];
257 _statusLabel.text =
258 [NSString stringWithFormat:@"Connected to %@", _remoteHostName];
259 _activityIndicator.progress = 0.0;
260 _pinEntryView.hidden = YES;
261 _activityIndicator.hidden = NO;
262 _activityIndicator.indicatorMode = MDCActivityIndicatorModeDeterminate;
263 _activityIndicator.cycleColors = @[ [UIColor greenColor] ];
264 [_activityIndicator startAnimating];
265 _activityIndicator.progress = 1.0;
266 [self dismissViewControllerAnimated:YES
267 completion:^{
268 [_delegate clientConnected];
269 }];
270 }
271
272 - (void)didProvidePin:(NSString*)pin createPairing:(BOOL)createPairing {
273 // TODO(nicholss): There is an open question if createPairing is supported on
274 // iOS. Need to fingure this out.
275 [[NSNotificationCenter defaultCenter]
276 postNotificationName:kHostSessionPinProvided
277 object:self
278 userInfo:[NSDictionary dictionaryWithObject:pin
279 forKey:kHostSessionPin]];
280 }
281
282 - (void)didTapCancel:(id)sender {
283 NSLog(@"%@ was tapped.", NSStringFromClass([sender class]));
284 // TODO(nicholss): Need to cancel the pending connection.
285 [self dismissViewControllerAnimated:YES completion:nil];
286 }
287
288 - (void)hostSessionStatusChanged:(NSNotification*)notification {
289 ClientConnectionViewState state;
290 ClientSessionDetails* sessionDetails =
291 [[notification userInfo] objectForKey:kSessionDetails];
292 switch (sessionDetails.state) {
293 case SessionInitializing:
294 // Same as HostConnecting in UI. Fall-though.
295 case SessionAuthenticated:
296 // Same as HostConnecting in UI. Fall-though.
297 case SessionConnecting:
298 state = ClientViewConnecting;
299 break;
300 case SessionPinPrompt:
301 state = ClientViewPinPrompt;
302 break;
303 case SessionConnected:
304 state = ClientViewConnected;
305 break;
306 case SessionFailed:
307 // TODO(nicholss): Implement.
308 case SessionClosed:
309 // TODO(nicholss): Implement.
310 default:
311 LOG(ERROR) << "Unknown State for Session, " << sessionDetails.state;
312 return;
313 }
314 [[NSOperationQueue mainQueue] addOperationWithBlock:^{
315 [self setState:state];
316 }];
317 }
318
319 @end
OLDNEW
« no previous file with comments | « remoting/client/ios/app/client_connection_view_controller.h ('k') | remoting/client/ios/app/host_view_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698