| OLD | NEW |
| 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. | 15 // TODO(tkchin): retrieve status bar height dynamically. |
| 16 static CGFloat const kStatusBarHeight = 20; | 16 static CGFloat const kStatusBarHeight = 20; |
| 17 | 17 |
| 18 static CGFloat const kRoomTextButtonSize = 40; | 18 static CGFloat const kRoomTextButtonSize = 40; |
| 19 static CGFloat const kRoomTextFieldHeight = 40; | 19 static CGFloat const kRoomTextFieldHeight = 40; |
| 20 static CGFloat const kRoomTextFieldMargin = 8; | 20 static CGFloat const kRoomTextFieldMargin = 8; |
| 21 static CGFloat const kCallControlMargin = 8; | 21 static CGFloat const kCallControlMargin = 8; |
| 22 static CGFloat const kAppLabelHeight = 20; | 22 static CGFloat const kAppLabelHeight = 20; |
| 23 | 23 |
| 24 @class ARDRoomTextField; | |
| 25 @protocol ARDRoomTextFieldDelegate <NSObject> | |
| 26 - (void)roomTextField:(ARDRoomTextField *)roomTextField | |
| 27 didInputRoom:(NSString *)room; | |
| 28 @end | |
| 29 | |
| 30 // Helper view that contains a text field and a clear button. | 24 // Helper view that contains a text field and a clear button. |
| 31 @interface ARDRoomTextField : UIView <UITextFieldDelegate> | 25 @interface ARDRoomTextField : UIView <UITextFieldDelegate> |
| 32 @property(nonatomic, weak) id<ARDRoomTextFieldDelegate> delegate; | |
| 33 @property(nonatomic, readonly) NSString *roomText; | 26 @property(nonatomic, readonly) NSString *roomText; |
| 34 @end | 27 @end |
| 35 | 28 |
| 36 @implementation ARDRoomTextField { | 29 @implementation ARDRoomTextField { |
| 37 UITextField *_roomText; | 30 UITextField *_roomText; |
| 38 UIButton *_clearButton; | 31 UIButton *_clearButton; |
| 39 } | 32 } |
| 40 | 33 |
| 41 @synthesize delegate = _delegate; | |
| 42 | |
| 43 - (instancetype)initWithFrame:(CGRect)frame { | 34 - (instancetype)initWithFrame:(CGRect)frame { |
| 44 if (self = [super initWithFrame:frame]) { | 35 if (self = [super initWithFrame:frame]) { |
| 45 _roomText = [[UITextField alloc] initWithFrame:CGRectZero]; | 36 _roomText = [[UITextField alloc] initWithFrame:CGRectZero]; |
| 46 _roomText.borderStyle = UITextBorderStyleNone; | 37 _roomText.borderStyle = UITextBorderStyleNone; |
| 47 _roomText.font = [UIFont fontWithName:@"Roboto" size:12]; | 38 _roomText.font = [UIFont fontWithName:@"Roboto" size:12]; |
| 48 _roomText.placeholder = @"Room name"; | 39 _roomText.placeholder = @"Room name"; |
| 40 _roomText.autocorrectionType = UITextAutocorrectionTypeNo; |
| 41 _roomText.autocapitalizationType = UITextAutocapitalizationTypeNone; |
| 49 _roomText.delegate = self; | 42 _roomText.delegate = self; |
| 50 [_roomText addTarget:self | 43 [_roomText addTarget:self |
| 51 action:@selector(textFieldDidChange:) | 44 action:@selector(textFieldDidChange:) |
| 52 forControlEvents:UIControlEventEditingChanged]; | 45 forControlEvents:UIControlEventEditingChanged]; |
| 53 [self addSubview:_roomText]; | 46 [self addSubview:_roomText]; |
| 54 | 47 |
| 55 _clearButton = [UIButton buttonWithType:UIButtonTypeCustom]; | 48 _clearButton = [UIButton buttonWithType:UIButtonTypeCustom]; |
| 56 UIImage *image = [UIImage imageForName:@"ic_clear_black_24dp.png" | 49 UIImage *image = [UIImage imageForName:@"ic_clear_black_24dp.png" |
| 57 color:[UIColor colorWithWhite:0 alpha:.4]]; | 50 color:[UIColor colorWithWhite:0 alpha:.4]]; |
| 58 | 51 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 89 size.height = kRoomTextFieldHeight; | 82 size.height = kRoomTextFieldHeight; |
| 90 return size; | 83 return size; |
| 91 } | 84 } |
| 92 | 85 |
| 93 - (NSString *)roomText { | 86 - (NSString *)roomText { |
| 94 return _roomText.text; | 87 return _roomText.text; |
| 95 } | 88 } |
| 96 | 89 |
| 97 #pragma mark - UITextFieldDelegate | 90 #pragma mark - UITextFieldDelegate |
| 98 | 91 |
| 99 - (void)textFieldDidEndEditing:(UITextField *)textField { | |
| 100 [_delegate roomTextField:self didInputRoom:textField.text]; | |
| 101 } | |
| 102 | |
| 103 - (BOOL)textFieldShouldReturn:(UITextField *)textField { | 92 - (BOOL)textFieldShouldReturn:(UITextField *)textField { |
| 104 // There is no other control that can take focus, so manually resign focus | 93 // There is no other control that can take focus, so manually resign focus |
| 105 // when return (Join) is pressed to trigger |textFieldDidEndEditing|. | 94 // when return (Join) is pressed to trigger |textFieldDidEndEditing|. |
| 106 [textField resignFirstResponder]; | 95 [textField resignFirstResponder]; |
| 107 return YES; | 96 return YES; |
| 108 } | 97 } |
| 109 | 98 |
| 110 #pragma mark - Private | 99 #pragma mark - Private |
| 111 | 100 |
| 112 - (void)textFieldDidChange:(id)sender { | 101 - (void)textFieldDidChange:(id)sender { |
| 113 [self updateClearButton]; | 102 [self updateClearButton]; |
| 114 } | 103 } |
| 115 | 104 |
| 116 - (void)onClear:(id)sender { | 105 - (void)onClear:(id)sender { |
| 117 _roomText.text = @""; | 106 _roomText.text = @""; |
| 118 [self updateClearButton]; | 107 [self updateClearButton]; |
| 119 [_roomText resignFirstResponder]; | 108 [_roomText resignFirstResponder]; |
| 120 } | 109 } |
| 121 | 110 |
| 122 - (void)updateClearButton { | 111 - (void)updateClearButton { |
| 123 _clearButton.hidden = _roomText.text.length == 0; | 112 _clearButton.hidden = _roomText.text.length == 0; |
| 124 } | 113 } |
| 125 | 114 |
| 126 @end | 115 @end |
| 127 | 116 |
| 128 @interface ARDMainView () <ARDRoomTextFieldDelegate> | |
| 129 @end | |
| 130 | |
| 131 @implementation ARDMainView { | 117 @implementation ARDMainView { |
| 132 UILabel *_appLabel; | 118 UILabel *_appLabel; |
| 133 ARDRoomTextField *_roomText; | 119 ARDRoomTextField *_roomText; |
| 134 UILabel *_callOptionsLabel; | 120 UILabel *_callOptionsLabel; |
| 135 UISwitch *_audioOnlySwitch; | 121 UISwitch *_audioOnlySwitch; |
| 136 UILabel *_audioOnlyLabel; | 122 UILabel *_audioOnlyLabel; |
| 137 UISwitch *_loopbackSwitch; | 123 UISwitch *_loopbackSwitch; |
| 138 UILabel *_loopbackLabel; | 124 UILabel *_loopbackLabel; |
| 139 UIButton *_startCallButton; | 125 UIButton *_startCallButton; |
| 140 } | 126 } |
| 141 | 127 |
| 142 @synthesize delegate = _delegate; | 128 @synthesize delegate = _delegate; |
| 143 | 129 |
| 144 - (instancetype)initWithFrame:(CGRect)frame { | 130 - (instancetype)initWithFrame:(CGRect)frame { |
| 145 if (self = [super initWithFrame:frame]) { | 131 if (self = [super initWithFrame:frame]) { |
| 146 _appLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 132 _appLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 147 _appLabel.text = @"AppRTCDemo"; | 133 _appLabel.text = @"AppRTCDemo"; |
| 148 _appLabel.font = [UIFont fontWithName:@"Roboto" size:34]; | 134 _appLabel.font = [UIFont fontWithName:@"Roboto" size:34]; |
| 149 _appLabel.textColor = [UIColor colorWithWhite:0 alpha:.2]; | 135 _appLabel.textColor = [UIColor colorWithWhite:0 alpha:.2]; |
| 150 [_appLabel sizeToFit]; | 136 [_appLabel sizeToFit]; |
| 151 [self addSubview:_appLabel]; | 137 [self addSubview:_appLabel]; |
| 152 | 138 |
| 153 _roomText = [[ARDRoomTextField alloc] initWithFrame:CGRectZero]; | 139 _roomText = [[ARDRoomTextField alloc] initWithFrame:CGRectZero]; |
| 154 _roomText.delegate = self; | |
| 155 [self addSubview:_roomText]; | 140 [self addSubview:_roomText]; |
| 156 | 141 |
| 157 UIFont *controlFont = [UIFont fontWithName:@"Roboto" size:20]; | 142 UIFont *controlFont = [UIFont fontWithName:@"Roboto" size:20]; |
| 158 UIColor *controlFontColor = [UIColor colorWithWhite:0 alpha:.6]; | 143 UIColor *controlFontColor = [UIColor colorWithWhite:0 alpha:.6]; |
| 159 | 144 |
| 160 _callOptionsLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 145 _callOptionsLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 161 _callOptionsLabel.text = @"Call Options"; | 146 _callOptionsLabel.text = @"Call Options"; |
| 162 _callOptionsLabel.font = controlFont; | 147 _callOptionsLabel.font = controlFont; |
| 163 _callOptionsLabel.textColor = controlFontColor; | 148 _callOptionsLabel.textColor = controlFontColor; |
| 164 [_callOptionsLabel sizeToFit]; | 149 [_callOptionsLabel sizeToFit]; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 CGRectGetMidY(loopbackModeRect)); | 238 CGRectGetMidY(loopbackModeRect)); |
| 254 | 239 |
| 255 CGFloat startCallTop = | 240 CGFloat startCallTop = |
| 256 CGRectGetMaxY(loopbackModeRect) + kCallControlMargin * 3; | 241 CGRectGetMaxY(loopbackModeRect) + kCallControlMargin * 3; |
| 257 _startCallButton.frame = CGRectMake(kCallControlMargin, | 242 _startCallButton.frame = CGRectMake(kCallControlMargin, |
| 258 startCallTop, | 243 startCallTop, |
| 259 _startCallButton.frame.size.width, | 244 _startCallButton.frame.size.width, |
| 260 _startCallButton.frame.size.height); | 245 _startCallButton.frame.size.height); |
| 261 } | 246 } |
| 262 | 247 |
| 263 #pragma mark - ARDRoomTextFieldDelegate | |
| 264 | |
| 265 - (void)roomTextField:(ARDRoomTextField *)roomTextField | |
| 266 didInputRoom:(NSString *)room { | |
| 267 [_delegate mainView:self | |
| 268 didInputRoom:room | |
| 269 isLoopback:NO | |
| 270 isAudioOnly:_audioOnlySwitch.isOn]; | |
| 271 } | |
| 272 | |
| 273 #pragma mark - Private | 248 #pragma mark - Private |
| 274 | 249 |
| 275 - (void)onStartCall:(id)sender { | 250 - (void)onStartCall:(id)sender { |
| 276 NSString *room = _roomText.roomText; | 251 NSString *room = _roomText.roomText; |
| 277 // If this is a loopback call, allow a generated room name. | 252 // If this is a loopback call, allow a generated room name. |
| 278 if (!room.length && _loopbackSwitch.isOn) { | 253 if (!room.length && _loopbackSwitch.isOn) { |
| 279 room = [[NSUUID UUID] UUIDString]; | 254 room = [[NSUUID UUID] UUIDString]; |
| 280 } | 255 } |
| 281 room = [room stringByReplacingOccurrencesOfString:@"-" withString:@""]; | 256 room = [room stringByReplacingOccurrencesOfString:@"-" withString:@""]; |
| 282 [_delegate mainView:self | 257 [_delegate mainView:self |
| 283 didInputRoom:room | 258 didInputRoom:room |
| 284 isLoopback:_loopbackSwitch.isOn | 259 isLoopback:_loopbackSwitch.isOn |
| 285 isAudioOnly:_audioOnlySwitch.isOn]; | 260 isAudioOnly:_audioOnlySwitch.isOn]; |
| 286 } | 261 } |
| 287 | 262 |
| 288 @end | 263 @end |
| OLD | NEW |