tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 1 | /* |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 3 | * |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #import "ARDMainView.h" |
| 12 | |
| 13 | #import "UIImage+ARDUtilities.h" |
| 14 | |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 15 | static CGFloat const kRoomTextFieldHeight = 40; |
| 16 | static CGFloat const kRoomTextFieldMargin = 8; |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 17 | static CGFloat const kCallControlMargin = 8; |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 18 | |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 19 | // Helper view that contains a text field and a clear button. |
| 20 | @interface ARDRoomTextField : UIView <UITextFieldDelegate> |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 21 | @property(nonatomic, readonly) NSString *roomText; |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 22 | @end |
| 23 | |
| 24 | @implementation ARDRoomTextField { |
| 25 | UITextField *_roomText; |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 26 | } |
| 27 | |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 28 | - (instancetype)initWithFrame:(CGRect)frame { |
| 29 | if (self = [super initWithFrame:frame]) { |
| 30 | _roomText = [[UITextField alloc] initWithFrame:CGRectZero]; |
| 31 | _roomText.borderStyle = UITextBorderStyleNone; |
| 32 | _roomText.font = [UIFont fontWithName:@"Roboto" size:12]; |
| 33 | _roomText.placeholder = @"Room name"; |
haysc | edd8fef | 2015-12-08 11:08:39 -0800 | [diff] [blame] | 34 | _roomText.autocorrectionType = UITextAutocorrectionTypeNo; |
| 35 | _roomText.autocapitalizationType = UITextAutocapitalizationTypeNone; |
denicija | ae70876 | 2016-11-02 03:02:29 -0700 | [diff] [blame] | 36 | _roomText.clearButtonMode = UITextFieldViewModeAlways; |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 37 | _roomText.delegate = self; |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 38 | [self addSubview:_roomText]; |
| 39 | |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 40 | // Give rounded corners and a light gray border. |
| 41 | self.layer.borderWidth = 1; |
| 42 | self.layer.borderColor = [[UIColor lightGrayColor] CGColor]; |
| 43 | self.layer.cornerRadius = 2; |
| 44 | } |
| 45 | return self; |
| 46 | } |
| 47 | |
| 48 | - (void)layoutSubviews { |
denicija | ae70876 | 2016-11-02 03:02:29 -0700 | [diff] [blame] | 49 | _roomText.frame = |
| 50 | CGRectMake(kRoomTextFieldMargin, 0, CGRectGetWidth(self.bounds) - kRoomTextFieldMargin, |
| 51 | kRoomTextFieldHeight); |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | - (CGSize)sizeThatFits:(CGSize)size { |
| 55 | size.height = kRoomTextFieldHeight; |
| 56 | return size; |
| 57 | } |
| 58 | |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 59 | - (NSString *)roomText { |
| 60 | return _roomText.text; |
| 61 | } |
| 62 | |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 63 | #pragma mark - UITextFieldDelegate |
| 64 | |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 65 | - (BOOL)textFieldShouldReturn:(UITextField *)textField { |
| 66 | // There is no other control that can take focus, so manually resign focus |
| 67 | // when return (Join) is pressed to trigger |textFieldDidEndEditing|. |
| 68 | [textField resignFirstResponder]; |
| 69 | return YES; |
| 70 | } |
| 71 | |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 72 | @end |
| 73 | |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 74 | @implementation ARDMainView { |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 75 | ARDRoomTextField *_roomText; |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 76 | UILabel *_callOptionsLabel; |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 77 | UISwitch *_loopbackSwitch; |
| 78 | UILabel *_loopbackLabel; |
| 79 | UIButton *_startCallButton; |
Zeke Chin | 615fabb | 2016-02-24 10:58:52 -0800 | [diff] [blame] | 80 | UIButton *_audioLoopButton; |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @synthesize delegate = _delegate; |
Tze Kwang Chin | 307a092 | 2016-03-21 13:57:40 -0700 | [diff] [blame] | 84 | @synthesize isAudioLoopPlaying = _isAudioLoopPlaying; |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 85 | |
| 86 | - (instancetype)initWithFrame:(CGRect)frame { |
| 87 | if (self = [super initWithFrame:frame]) { |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 88 | _roomText = [[ARDRoomTextField alloc] initWithFrame:CGRectZero]; |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 89 | [self addSubview:_roomText]; |
| 90 | |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 91 | UIFont *controlFont = [UIFont fontWithName:@"Roboto" size:20]; |
| 92 | UIColor *controlFontColor = [UIColor colorWithWhite:0 alpha:.6]; |
| 93 | |
| 94 | _callOptionsLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 95 | _callOptionsLabel.text = @"Call Options"; |
| 96 | _callOptionsLabel.font = controlFont; |
| 97 | _callOptionsLabel.textColor = controlFontColor; |
| 98 | [_callOptionsLabel sizeToFit]; |
| 99 | [self addSubview:_callOptionsLabel]; |
| 100 | |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 101 | _loopbackSwitch = [[UISwitch alloc] initWithFrame:CGRectZero]; |
| 102 | [_loopbackSwitch sizeToFit]; |
| 103 | [self addSubview:_loopbackSwitch]; |
| 104 | |
| 105 | _loopbackLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 106 | _loopbackLabel.text = @"Loopback mode"; |
| 107 | _loopbackLabel.font = controlFont; |
| 108 | _loopbackLabel.textColor = controlFontColor; |
| 109 | [_loopbackLabel sizeToFit]; |
| 110 | [self addSubview:_loopbackLabel]; |
| 111 | |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 112 | _startCallButton = [UIButton buttonWithType:UIButtonTypeSystem]; |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 113 | [_startCallButton setTitle:@"Start call" |
| 114 | forState:UIControlStateNormal]; |
| 115 | _startCallButton.titleLabel.font = controlFont; |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 116 | [_startCallButton sizeToFit]; |
| 117 | [_startCallButton addTarget:self |
| 118 | action:@selector(onStartCall:) |
| 119 | forControlEvents:UIControlEventTouchUpInside]; |
| 120 | [self addSubview:_startCallButton]; |
| 121 | |
Zeke Chin | 615fabb | 2016-02-24 10:58:52 -0800 | [diff] [blame] | 122 | // Used to test what happens to sounds when calls are in progress. |
| 123 | _audioLoopButton = [UIButton buttonWithType:UIButtonTypeSystem]; |
Zeke Chin | 615fabb | 2016-02-24 10:58:52 -0800 | [diff] [blame] | 124 | _audioLoopButton.titleLabel.font = controlFont; |
Zeke Chin | 615fabb | 2016-02-24 10:58:52 -0800 | [diff] [blame] | 125 | [self updateAudioLoopButton]; |
| 126 | [_audioLoopButton addTarget:self |
| 127 | action:@selector(onToggleAudioLoop:) |
| 128 | forControlEvents:UIControlEventTouchUpInside]; |
| 129 | [self addSubview:_audioLoopButton]; |
| 130 | |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 131 | self.backgroundColor = [UIColor whiteColor]; |
| 132 | } |
| 133 | return self; |
| 134 | } |
| 135 | |
Tze Kwang Chin | 307a092 | 2016-03-21 13:57:40 -0700 | [diff] [blame] | 136 | - (void)setIsAudioLoopPlaying:(BOOL)isAudioLoopPlaying { |
| 137 | if (_isAudioLoopPlaying == isAudioLoopPlaying) { |
| 138 | return; |
| 139 | } |
| 140 | _isAudioLoopPlaying = isAudioLoopPlaying; |
| 141 | [self updateAudioLoopButton]; |
| 142 | } |
| 143 | |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 144 | - (void)layoutSubviews { |
| 145 | CGRect bounds = self.bounds; |
| 146 | CGFloat roomTextWidth = bounds.size.width - 2 * kRoomTextFieldMargin; |
| 147 | CGFloat roomTextHeight = [_roomText sizeThatFits:bounds.size].height; |
denicija | 6d6762c | 2016-10-28 04:53:16 -0700 | [diff] [blame] | 148 | _roomText.frame = |
| 149 | CGRectMake(kRoomTextFieldMargin, kRoomTextFieldMargin, roomTextWidth, roomTextHeight); |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 150 | |
| 151 | CGFloat callOptionsLabelTop = |
| 152 | CGRectGetMaxY(_roomText.frame) + kCallControlMargin * 4; |
| 153 | _callOptionsLabel.frame = CGRectMake(kCallControlMargin, |
| 154 | callOptionsLabelTop, |
| 155 | _callOptionsLabel.frame.size.width, |
| 156 | _callOptionsLabel.frame.size.height); |
| 157 | |
Anders Carlsson | e150058 | 2017-06-15 16:05:13 +0200 | [diff] [blame] | 158 | CGFloat loopbackModeTop = CGRectGetMaxY(_callOptionsLabel.frame) + kCallControlMargin * 2; |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 159 | CGRect loopbackModeRect = CGRectMake(kCallControlMargin * 3, |
| 160 | loopbackModeTop, |
| 161 | _loopbackSwitch.frame.size.width, |
| 162 | _loopbackSwitch.frame.size.height); |
| 163 | _loopbackSwitch.frame = loopbackModeRect; |
| 164 | CGFloat loopbackModeLabelCenterX = CGRectGetMaxX(loopbackModeRect) + |
| 165 | kCallControlMargin + _loopbackLabel.frame.size.width / 2; |
| 166 | _loopbackLabel.center = CGPointMake(loopbackModeLabelCenterX, |
| 167 | CGRectGetMidY(loopbackModeRect)); |
| 168 | |
Anders Carlsson | e150058 | 2017-06-15 16:05:13 +0200 | [diff] [blame] | 169 | CGFloat audioLoopTop = CGRectGetMaxY(loopbackModeRect) + kCallControlMargin * 3; |
Zeke Chin | 615fabb | 2016-02-24 10:58:52 -0800 | [diff] [blame] | 170 | _audioLoopButton.frame = CGRectMake(kCallControlMargin, |
| 171 | audioLoopTop, |
| 172 | _audioLoopButton.frame.size.width, |
| 173 | _audioLoopButton.frame.size.height); |
| 174 | |
| 175 | CGFloat startCallTop = |
| 176 | CGRectGetMaxY(_audioLoopButton.frame) + kCallControlMargin * 3; |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 177 | _startCallButton.frame = CGRectMake(kCallControlMargin, |
| 178 | startCallTop, |
| 179 | _startCallButton.frame.size.width, |
| 180 | _startCallButton.frame.size.height); |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 181 | } |
| 182 | |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 183 | #pragma mark - Private |
| 184 | |
Zeke Chin | 615fabb | 2016-02-24 10:58:52 -0800 | [diff] [blame] | 185 | - (void)updateAudioLoopButton { |
Tze Kwang Chin | 307a092 | 2016-03-21 13:57:40 -0700 | [diff] [blame] | 186 | if (_isAudioLoopPlaying) { |
Zeke Chin | 615fabb | 2016-02-24 10:58:52 -0800 | [diff] [blame] | 187 | [_audioLoopButton setTitle:@"Stop sound" |
| 188 | forState:UIControlStateNormal]; |
| 189 | [_audioLoopButton sizeToFit]; |
| 190 | } else { |
Zeke Chin | 615fabb | 2016-02-24 10:58:52 -0800 | [diff] [blame] | 191 | [_audioLoopButton setTitle:@"Play sound" |
| 192 | forState:UIControlStateNormal]; |
| 193 | [_audioLoopButton sizeToFit]; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | - (void)onToggleAudioLoop:(id)sender { |
Tze Kwang Chin | 307a092 | 2016-03-21 13:57:40 -0700 | [diff] [blame] | 198 | [_delegate mainViewDidToggleAudioLoop:self]; |
Zeke Chin | 615fabb | 2016-02-24 10:58:52 -0800 | [diff] [blame] | 199 | } |
| 200 | |
haysc | 913e645 | 2015-10-02 11:44:03 -0700 | [diff] [blame] | 201 | - (void)onStartCall:(id)sender { |
Anders Carlsson | e150058 | 2017-06-15 16:05:13 +0200 | [diff] [blame] | 202 | [_delegate mainView:self didInputRoom:_roomText.roomText isLoopback:_loopbackSwitch.isOn]; |
tkchin@webrtc.org | ef2a5dd | 2015-01-15 22:38:21 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | @end |