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

Side by Side Diff: webrtc/examples/objc/AppRTCMobile/ios/ARDMainView.m

Issue 2455413002: Remove unnecessary styling for some controls in ARDMainView.m for ios. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #import "ARDMainView.h" 11 #import "ARDMainView.h"
12 12
13 #import "UIImage+ARDUtilities.h" 13 #import "UIImage+ARDUtilities.h"
14 14
15 // TODO(tkchin): retrieve status bar height dynamically.
16 static CGFloat const kStatusBarHeight = 20;
17
18 static CGFloat const kRoomTextButtonSize = 40;
19 static CGFloat const kRoomTextFieldHeight = 40; 15 static CGFloat const kRoomTextFieldHeight = 40;
20 static CGFloat const kRoomTextFieldMargin = 8; 16 static CGFloat const kRoomTextFieldMargin = 8;
21 static CGFloat const kCallControlMargin = 8; 17 static CGFloat const kCallControlMargin = 8;
22 18
23 // Helper view that contains a text field and a clear button. 19 // Helper view that contains a text field and a clear button.
24 @interface ARDRoomTextField : UIView <UITextFieldDelegate> 20 @interface ARDRoomTextField : UIView <UITextFieldDelegate>
25 @property(nonatomic, readonly) NSString *roomText; 21 @property(nonatomic, readonly) NSString *roomText;
26 @end 22 @end
27 23
28 @implementation ARDRoomTextField { 24 @implementation ARDRoomTextField {
29 UITextField *_roomText; 25 UITextField *_roomText;
30 UIButton *_clearButton;
31 } 26 }
32 27
33 - (instancetype)initWithFrame:(CGRect)frame { 28 - (instancetype)initWithFrame:(CGRect)frame {
34 if (self = [super initWithFrame:frame]) { 29 if (self = [super initWithFrame:frame]) {
35 _roomText = [[UITextField alloc] initWithFrame:CGRectZero]; 30 _roomText = [[UITextField alloc] initWithFrame:CGRectZero];
36 _roomText.borderStyle = UITextBorderStyleNone; 31 _roomText.borderStyle = UITextBorderStyleNone;
37 _roomText.font = [UIFont fontWithName:@"Roboto" size:12]; 32 _roomText.font = [UIFont fontWithName:@"Roboto" size:12];
38 _roomText.placeholder = @"Room name"; 33 _roomText.placeholder = @"Room name";
39 _roomText.autocorrectionType = UITextAutocorrectionTypeNo; 34 _roomText.autocorrectionType = UITextAutocorrectionTypeNo;
40 _roomText.autocapitalizationType = UITextAutocapitalizationTypeNone; 35 _roomText.autocapitalizationType = UITextAutocapitalizationTypeNone;
36 _roomText.clearButtonMode = UITextFieldViewModeAlways;
41 _roomText.delegate = self; 37 _roomText.delegate = self;
42 [_roomText addTarget:self
43 action:@selector(textFieldDidChange:)
44 forControlEvents:UIControlEventEditingChanged];
45 [self addSubview:_roomText]; 38 [self addSubview:_roomText];
46 39
47 _clearButton = [UIButton buttonWithType:UIButtonTypeCustom];
48 UIImage *image = [UIImage imageForName:@"ic_clear_black_24dp.png"
49 color:[UIColor colorWithWhite:0 alpha:.4]];
50
51 [_clearButton setImage:image forState:UIControlStateNormal];
52 [_clearButton addTarget:self
53 action:@selector(onClear:)
54 forControlEvents:UIControlEventTouchUpInside];
55 _clearButton.hidden = YES;
56 [self addSubview:_clearButton];
57
58 // Give rounded corners and a light gray border. 40 // Give rounded corners and a light gray border.
59 self.layer.borderWidth = 1; 41 self.layer.borderWidth = 1;
60 self.layer.borderColor = [[UIColor lightGrayColor] CGColor]; 42 self.layer.borderColor = [[UIColor lightGrayColor] CGColor];
61 self.layer.cornerRadius = 2; 43 self.layer.cornerRadius = 2;
62 } 44 }
63 return self; 45 return self;
64 } 46 }
65 47
66 - (void)layoutSubviews { 48 - (void)layoutSubviews {
67 CGRect bounds = self.bounds; 49 _roomText.frame =
68 _clearButton.frame = CGRectMake(CGRectGetMaxX(bounds) - kRoomTextButtonSize, 50 CGRectMake(kRoomTextFieldMargin, 0, CGRectGetWidth(self.bounds) - kRoomTex tFieldMargin,
69 CGRectGetMinY(bounds), 51 kRoomTextFieldHeight);
70 kRoomTextButtonSize,
71 kRoomTextButtonSize);
72 _roomText.frame = CGRectMake(
73 CGRectGetMinX(bounds) + kRoomTextFieldMargin,
74 CGRectGetMinY(bounds),
75 CGRectGetMinX(_clearButton.frame) - CGRectGetMinX(bounds) -
76 kRoomTextFieldMargin,
77 kRoomTextFieldHeight);
78 } 52 }
79 53
80 - (CGSize)sizeThatFits:(CGSize)size { 54 - (CGSize)sizeThatFits:(CGSize)size {
81 size.height = kRoomTextFieldHeight; 55 size.height = kRoomTextFieldHeight;
82 return size; 56 return size;
83 } 57 }
84 58
85 - (NSString *)roomText { 59 - (NSString *)roomText {
86 return _roomText.text; 60 return _roomText.text;
87 } 61 }
88 62
89 #pragma mark - UITextFieldDelegate 63 #pragma mark - UITextFieldDelegate
90 64
91 - (BOOL)textFieldShouldReturn:(UITextField *)textField { 65 - (BOOL)textFieldShouldReturn:(UITextField *)textField {
92 // There is no other control that can take focus, so manually resign focus 66 // There is no other control that can take focus, so manually resign focus
93 // when return (Join) is pressed to trigger |textFieldDidEndEditing|. 67 // when return (Join) is pressed to trigger |textFieldDidEndEditing|.
94 [textField resignFirstResponder]; 68 [textField resignFirstResponder];
95 return YES; 69 return YES;
96 } 70 }
97 71
98 #pragma mark - Private
99
100 - (void)textFieldDidChange:(id)sender {
101 [self updateClearButton];
102 }
103
104 - (void)onClear:(id)sender {
105 _roomText.text = @"";
106 [self updateClearButton];
107 [_roomText resignFirstResponder];
108 }
109
110 - (void)updateClearButton {
111 _clearButton.hidden = _roomText.text.length == 0;
112 }
113
114 @end 72 @end
115 73
116 @implementation ARDMainView { 74 @implementation ARDMainView {
117 ARDRoomTextField *_roomText; 75 ARDRoomTextField *_roomText;
118 UILabel *_callOptionsLabel; 76 UILabel *_callOptionsLabel;
119 UISwitch *_audioOnlySwitch; 77 UISwitch *_audioOnlySwitch;
120 UILabel *_audioOnlyLabel; 78 UILabel *_audioOnlyLabel;
121 UISwitch *_aecdumpSwitch; 79 UISwitch *_aecdumpSwitch;
122 UILabel *_aecdumpLabel; 80 UILabel *_aecdumpLabel;
123 UISwitch *_levelControlSwitch; 81 UISwitch *_levelControlSwitch;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 [self addSubview:_useManualAudioSwitch]; 156 [self addSubview:_useManualAudioSwitch];
199 157
200 _useManualAudioLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 158 _useManualAudioLabel = [[UILabel alloc] initWithFrame:CGRectZero];
201 _useManualAudioLabel.text = @"Use manual audio config"; 159 _useManualAudioLabel.text = @"Use manual audio config";
202 _useManualAudioLabel.font = controlFont; 160 _useManualAudioLabel.font = controlFont;
203 _useManualAudioLabel.textColor = controlFontColor; 161 _useManualAudioLabel.textColor = controlFontColor;
204 [_useManualAudioLabel sizeToFit]; 162 [_useManualAudioLabel sizeToFit];
205 [self addSubview:_useManualAudioLabel]; 163 [self addSubview:_useManualAudioLabel];
206 164
207 _startCallButton = [UIButton buttonWithType:UIButtonTypeSystem]; 165 _startCallButton = [UIButton buttonWithType:UIButtonTypeSystem];
208 _startCallButton.backgroundColor = [UIColor blueColor];
209 _startCallButton.layer.cornerRadius = 10;
210 _startCallButton.clipsToBounds = YES;
211 _startCallButton.contentEdgeInsets = UIEdgeInsetsMake(5, 10, 5, 10);
212 [_startCallButton setTitle:@"Start call" 166 [_startCallButton setTitle:@"Start call"
213 forState:UIControlStateNormal]; 167 forState:UIControlStateNormal];
214 _startCallButton.titleLabel.font = controlFont; 168 _startCallButton.titleLabel.font = controlFont;
215 [_startCallButton setTitleColor:[UIColor whiteColor]
216 forState:UIControlStateNormal];
217 [_startCallButton setTitleColor:[UIColor lightGrayColor]
218 forState:UIControlStateSelected];
219 [_startCallButton sizeToFit]; 169 [_startCallButton sizeToFit];
220 [_startCallButton addTarget:self 170 [_startCallButton addTarget:self
221 action:@selector(onStartCall:) 171 action:@selector(onStartCall:)
222 forControlEvents:UIControlEventTouchUpInside]; 172 forControlEvents:UIControlEventTouchUpInside];
223 [self addSubview:_startCallButton]; 173 [self addSubview:_startCallButton];
224 174
225 // Used to test what happens to sounds when calls are in progress. 175 // Used to test what happens to sounds when calls are in progress.
226 _audioLoopButton = [UIButton buttonWithType:UIButtonTypeSystem]; 176 _audioLoopButton = [UIButton buttonWithType:UIButtonTypeSystem];
227 _audioLoopButton.layer.cornerRadius = 10;
228 _audioLoopButton.clipsToBounds = YES;
229 _audioLoopButton.contentEdgeInsets = UIEdgeInsetsMake(5, 10, 5, 10);
230 _audioLoopButton.titleLabel.font = controlFont; 177 _audioLoopButton.titleLabel.font = controlFont;
231 [_audioLoopButton setTitleColor:[UIColor whiteColor]
232 forState:UIControlStateNormal];
233 [_audioLoopButton setTitleColor:[UIColor lightGrayColor]
234 forState:UIControlStateSelected];
235 [self updateAudioLoopButton]; 178 [self updateAudioLoopButton];
236 [_audioLoopButton addTarget:self 179 [_audioLoopButton addTarget:self
237 action:@selector(onToggleAudioLoop:) 180 action:@selector(onToggleAudioLoop:)
238 forControlEvents:UIControlEventTouchUpInside]; 181 forControlEvents:UIControlEventTouchUpInside];
239 [self addSubview:_audioLoopButton]; 182 [self addSubview:_audioLoopButton];
240 183
241 self.backgroundColor = [UIColor whiteColor]; 184 self.backgroundColor = [UIColor whiteColor];
242 } 185 }
243 return self; 186 return self;
244 } 187 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 _startCallButton.frame = CGRectMake(kCallControlMargin, 282 _startCallButton.frame = CGRectMake(kCallControlMargin,
340 startCallTop, 283 startCallTop,
341 _startCallButton.frame.size.width, 284 _startCallButton.frame.size.width,
342 _startCallButton.frame.size.height); 285 _startCallButton.frame.size.height);
343 } 286 }
344 287
345 #pragma mark - Private 288 #pragma mark - Private
346 289
347 - (void)updateAudioLoopButton { 290 - (void)updateAudioLoopButton {
348 if (_isAudioLoopPlaying) { 291 if (_isAudioLoopPlaying) {
349 _audioLoopButton.backgroundColor = [UIColor redColor];
350 [_audioLoopButton setTitle:@"Stop sound" 292 [_audioLoopButton setTitle:@"Stop sound"
351 forState:UIControlStateNormal]; 293 forState:UIControlStateNormal];
352 [_audioLoopButton sizeToFit]; 294 [_audioLoopButton sizeToFit];
353 } else { 295 } else {
354 _audioLoopButton.backgroundColor = [UIColor greenColor];
355 [_audioLoopButton setTitle:@"Play sound" 296 [_audioLoopButton setTitle:@"Play sound"
356 forState:UIControlStateNormal]; 297 forState:UIControlStateNormal];
357 [_audioLoopButton sizeToFit]; 298 [_audioLoopButton sizeToFit];
358 } 299 }
359 } 300 }
360 301
361 - (void)onToggleAudioLoop:(id)sender { 302 - (void)onToggleAudioLoop:(id)sender {
362 [_delegate mainViewDidToggleAudioLoop:self]; 303 [_delegate mainViewDidToggleAudioLoop:self];
363 } 304 }
364 305
365 - (void)onStartCall:(id)sender { 306 - (void)onStartCall:(id)sender {
366 NSString *room = _roomText.roomText; 307 NSString *room = _roomText.roomText;
367 // If this is a loopback call, allow a generated room name. 308 // If this is a loopback call, allow a generated room name.
368 if (!room.length && _loopbackSwitch.isOn) { 309 if (!room.length && _loopbackSwitch.isOn) {
369 room = [[NSUUID UUID] UUIDString]; 310 room = [[NSUUID UUID] UUIDString];
370 } 311 }
371 room = [room stringByReplacingOccurrencesOfString:@"-" withString:@""]; 312 room = [room stringByReplacingOccurrencesOfString:@"-" withString:@""];
372 [_delegate mainView:self 313 [_delegate mainView:self
373 didInputRoom:room 314 didInputRoom:room
374 isLoopback:_loopbackSwitch.isOn 315 isLoopback:_loopbackSwitch.isOn
375 isAudioOnly:_audioOnlySwitch.isOn 316 isAudioOnly:_audioOnlySwitch.isOn
376 shouldMakeAecDump:_aecdumpSwitch.isOn 317 shouldMakeAecDump:_aecdumpSwitch.isOn
377 shouldUseLevelControl:_levelControlSwitch.isOn 318 shouldUseLevelControl:_levelControlSwitch.isOn
378 useManualAudio:_useManualAudioSwitch.isOn]; 319 useManualAudio:_useManualAudioSwitch.isOn];
379 } 320 }
380 321
381 @end 322 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698