-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateViewController.m
239 lines (191 loc) · 9.16 KB
/
CreateViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//
// CreateViewController.m
// ActionTap
//
// Created by Joshua Liu on 3/29/15.
// Copyright (c) 2015 Sebastian Cain. All rights reserved.
//
#import "CreateViewController.h"
@interface CreateViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>
@end
@implementation CreateViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view setBackgroundColor:[UIColor colorWithRed:40/255.0 green:40/255.0 blue:40/255.0 alpha:1.0]];
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(cancelNumberPad)];
[cancelButton setTintColor:[UIColor whiteColor]];
UIBarButtonItem *donebutton = [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)];
[donebutton setTintColor:[UIColor whiteColor]];
numberToolbar.items = [NSArray arrayWithObjects:
cancelButton,
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
donebutton,
nil];
[numberToolbar sizeToFit];
self.numberToolbar = numberToolbar;
UIButton *resignButton = [[UIButton alloc]initWithFrame:self.view.frame];
resignButton.userInteractionEnabled = NO;
self.resignButton = resignButton;
[self.resignButton addTarget:self action:@selector(resignKeyboard) forControlEvents:UIControlEventTouchUpInside ];
[self.view addSubview:self.resignButton];
// UILabel *actionLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, 0, 100, 100)];
// actionLabel.center = CGPointMake(CGRectGetMidX(self.view.frame)-100, 50);
// actionLabel.text = @"Action:";
// [actionLabel setTextColor:[UIColor whiteColor]];
// [actionLabel setFont:[UIFont fontWithName:@"AvenirNext-UltraLight" size:20]];
// [self.view addSubview:actionLabel];
self.action = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, 0, 300, 100)];
self.action.center = CGPointMake(CGRectGetMidX(self.view.frame), 75);
self.action.text = @"[Action]";
[self.action setTextColor:[UIColor whiteColor]];
[self.action setFont:[UIFont fontWithName:@"AvenirNext-UltraLight" size:20]];
[self.view addSubview:self.action];
self.schemes = [[NSArray alloc] initWithObjects:@"Workflow",@"Music",@"Phone",@"SMS", @"Weather",@"Web", @"Mail", @"Maps", @"Facetime", nil];
UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(20, 100, self.view.frame.size.width-40, self.view.frame.size.height - 200)];
[tableView setDataSource:self];
[tableView setDelegate:self];
[tableView setBackgroundColor:[UIColor colorWithRed:40/255.0 green:40/255.0 blue:40/255.0 alpha:1.0]];
self.tableView = tableView;
[self.view addSubview:tableView];
UIButton *confirmButton = [[UIButton alloc]initWithFrame:CGRectMake(0,0,100,50)];
[confirmButton setCenter:CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height-50)];
//confirmButton.backgroundColor = [UIColor blueColor];
[confirmButton setTitle:@"Confirm" forState:UIControlStateNormal];
[confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[confirmButton.titleLabel setFont:[UIFont fontWithName:@"AvenirNext-UltraLight" size:20]];
[confirmButton addTarget:self action:@selector(showMainMenu) forControlEvents:UIControlEventTouchUpInside];
self.confirmButton = confirmButton;
[self.view addSubview:confirmButton];
}
-(void)showMainMenu {
[self performSegueWithIdentifier:@"showMainMenu" sender:self];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.resignButton.userInteractionEnabled =YES;
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
self.textfield = [[UITextField alloc] initWithFrame:CGRectMake(100, 10, 250, 80)];
[self.textfield addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
self.textfield.delegate = self;
[self.textfield setTextColor:[UIColor whiteColor]];
[self.textfield setFont:[UIFont fontWithName:@"AvenirNext-Regular" size:17]];
if (indexPath.row == 2 || indexPath.row == 3) {
self.textfield.inputAccessoryView = self.numberToolbar;
self.textfield.keyboardType = UIKeyboardTypeNumberPad;
}
[cell addSubview:self.textfield];
if (indexPath.row == 0) {
self.action.text = @"Run workflow: ";
} else if (indexPath.row == 1) {
self.action.text = @"Play/Pause Music";
[self.textfield removeFromSuperview];
} else if (indexPath.row == 2) {
self.action.text = @"Call: ";
} else if (indexPath.row == 3) {
self.action.text = @"Send text to: ";
} else if (indexPath.row == 4) {
self.action.text = @"Check Weather";
[self.textfield removeFromSuperview];
} else if (indexPath.row == 5) {
self.action.text = @"Visit Website: ";
} else if (indexPath.row == 6) {
self.action.text = @"Check Mail ";
[self.textfield removeFromSuperview];
} else if (indexPath.row == 7) {
self.action.text = @"Directions to: ";
} else if (indexPath.row == 8) {
self.action.text = @"Facetime: ";
}
self.originalLabelText = self.action.text;
self.selectedRowIndex = indexPath.row;
self.arrayindex = indexPath.row;
[tableView beginUpdates];
[tableView endUpdates];
}
-(void)cancelNumberPad {
[self.textfield resignFirstResponder];
self.textfield.text = @"";
}
-(void)doneWithNumberPad{
[self.textfield resignFirstResponder];
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.textfield removeFromSuperview];
}
-(void)textFieldDidChange :(UITextField *)theTextField{
self.schemeValue = theTextField.text;
self.action.text = [self.originalLabelText stringByAppendingString:self.schemeValue];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//check if the index actually exists
if(indexPath.row == self.selectedRowIndex) {
return 100;
}
return 44;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
[cell setBackgroundColor:[UIColor colorWithRed:40/255.0 green:40/255.0 blue:40/255.0 alpha:1.0]];
UIView *bgColorView = [[UIView alloc] init];
bgColorView.backgroundColor = [UIColor colorWithRed:50/255.0 green:50/255.0 blue:50/255.0 alpha:1.0];
[cell setSelectedBackgroundView:bgColorView];
cell.textLabel.text = self.schemes[indexPath.row];
[cell.textLabel setFont:[UIFont fontWithName:@"AvenirNext-Regular" size:17]];
[cell.textLabel setTextColor:[UIColor whiteColor]];
return cell;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.schemes count];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)resignKeyboard{
[self.textfield resignFirstResponder];
self.resignButton.userInteractionEnabled = NO;
}
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
MainViewController *mainVC = (MainViewController*)segue.destinationViewController;
mainVC.pickedPattern = self.pickedPattern;
mainVC.pickedPatternName = self.pickedPatternName;
mainVC.patternPicked = YES;
NSString *url;
if (self.arrayindex == 0) {
url = [@"workflow://run-workflow?name=" stringByAppendingString:self.schemeValue];
} else if (self.arrayindex == 1) {
url = @"music:";
} else if (self.arrayindex == 2) {
url = [@"tel:" stringByAppendingString:self.schemeValue];
} else if (self.arrayindex == 3) {
url = [@"sms:" stringByAppendingString:self.schemeValue];
} else if (self.arrayindex == 4) {
url = @"http://weather.com";
} else if (self.arrayindex == 5) {
url = [@"http://" stringByAppendingString:self.schemeValue];
} else if (self.arrayindex == 6) {
url = [@"mailto:" stringByAppendingString:self.schemeValue];
} else if (self.arrayindex == 7) {
url = [@"http://maps.apple.com/?q=" stringByAppendingString:self.schemeValue];
} else if (self.arrayindex == 8) {
url = [@"facetime:" stringByAppendingString:self.schemeValue];
}
mainVC.pickedPattern.url = url;
mainVC.shouldJumpToPage3 = YES;
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
@end