This repository has been archived by the owner on Feb 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainView.m
executable file
·329 lines (280 loc) · 8.69 KB
/
MainView.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#import "MainView.h"
@implementation MainView
@synthesize myPicker, pickerArray, imageView, textField;
- (IBAction)doNothing {
}
- (IBAction)loadView {
firstRun = TRUE;
UIDevice *myCurrentDevice = [UIDevice currentDevice];
theID.text = [myCurrentDevice uniqueIdentifier];
locationObtained = FALSE;
textField.delegate = self; ///added for keyboard
[theSpiner startAnimating];
locmanager = [[CLLocationManager alloc] init]; //added
locmanager.distanceFilter = 100;
locmanager.desiredAccuracy = kCLLocationAccuracyBest;
[locmanager setDelegate: self]; //added
[locmanager startUpdatingLocation]; //added
imageView.image = [UIImage imageNamed:@"Speech_bubble.png"];
theCategory.text = @"All";
//pickerArray = [[NSArray arrayWithObjects:@"All", @"Event", @"Me", nil] retain];
myPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 245.0, 0.0, 0.0)];
myPicker.delegate = self;
myPicker.showsSelectionIndicator = YES;
[self addSubview:myPicker];
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == textField) {
[textField resignFirstResponder];
}
return YES;
}
// Called when the location is updated
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSDate* eventDate = newLocation.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 5.0 ) {
NSString *lat = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude ];
NSString *lng = [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude ];
theLat.text = lat;
theLng.text = lng;
[theSpiner stopAnimating];
[theSpiner removeFromSuperview];
if (firstRun) {
theStatus.text = @" Location obtained! Pick category, write and post Or pick category and search .";
}
firstRun = FALSE;
locationObtained = TRUE;
} else {
//theStatus.text = @"Unable to locate you. Try again later.";
}
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error //added
{
[locmanager startUpdatingLocation]; //added
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
//return [pickerArray count];
return 13;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
NSString *title = nil;
if (row == 1) {
title = @"Activism";
}
if (row == 0) {
title = @"All";
}
if (row == 2) {
title = @"Carpool";
}
if (row == 3) {
title = @"Event";
}
if (row == 4) {
title = @"Fish & Game";
}
if (row == 5) {
title = @"Free";
}
if (row == 6) {
title = @"Join Me";
}
//if (row == 7) {
// title = @"Me";
//}
if (row == 7) {
title = @"Merchandise";
}
if (row == 8) {
title = @"Nature";
}
if (row == 9) {
title = @"News";
}
if (row == 10) {
title = @"Party";
}
if (row == 11) {
title = @"People";
}
if (row == 12) {
title = @"Traffic";
}
return title;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
switch (row)
{
case 1:
{
theCategory.text = @"Activism";
if (locationObtained){
theStatus.text = @"Protest Demonstration Rioting ";
}
break;
}
case 0:
{
//imageView.image = [UIImage imageNamed:@"Speech_bubble.png"];
theCategory.text = @"All";
if (locationObtained){
theStatus.text = @"Returns all items going on Now!";
}
break;
}
case 2:
{
theCategory.text = @"Carpool";
if (locationObtained){
theStatus.text = @"Driver: going north Passenger: going west New York or bust! ";
}
break;
}
case 3:
{
theCategory.text = @"Event";
if (locationObtained){
theStatus.text = @"Street performer Ladies' night Extra tickets ";
}
break;
}
case 4:
{
theCategory.text = @"FishGame";
if (locationObtained){
theStatus.text = @"8 Point Deer 100lb Sturgeon Decoy ";
}
break;
}
case 5:
{
theCategory.text = @"Free";
if (locationObtained){
theStatus.text = @"Food Free samples Couch u-haul ";
}
break;
}
case 6:
{
theCategory.text = @"JoinMe";
if (locationObtained){
theStatus.text = @"Tennis anyone? Golf? Basketball?";
}
break;
}
// case 7:
// {
// theCategory.text = @"Me";
// if (locationObtained){
// theStatus.text = @"Search only your items going on Now!";
// }
// break;
// }
case 7:
{
theCategory.text = @"Merchandise";
if (locationObtained){
theStatus.text = @"Clearance sale Wii - got mine, 2 left Garage Sale";
}
break;
}
case 8:
{
theCategory.text = @"Nature";
if (locationObtained){
theStatus.text = @"Migration Tornado Plants in bloom ";
}
break;
}
case 9:
{
theCategory.text = @"News";
if (locationObtained){
theStatus.text = @"Car Chase Fire Military crackdown ";
}
break;
}
case 10:
{
theCategory.text = @"Party";
if (locationObtained){
theStatus.text = @"College Party Tailgate Tupperware party ";
}
break;
}
case 11:
{
theCategory.text = @"People";
if (locationObtained){
theStatus.text = @"Celebrity sighting Politician Rock star ";
}
break;
}
case 12:
{
theCategory.text = @"Traffic";
if (locationObtained){
theStatus.text = @"Accident Speed Trap Construction ";
}
break;
}
}
}
- (IBAction)post:(id)sender {
if (locationObtained){
[locmanager stopUpdatingLocation];
NSString *alt = @"1";
NSString *tags = @"version1";
NSString *deviceID = theID.text;
NSString *name = textField.text;
NSString *description = theCategory.text;
NSString *lat = theLat.text;
NSString *lng = theLng.text;
NSString *urlEncodedName = (NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)name, NULL, CFSTR(";/?:@&=+$,"), kCFStringEncodingUTF8);
NSString *mystring = [NSString stringWithFormat: @"http://now1.scoutic.com/gen/request?operation=add;alt=%@;tag=%@;userId=%@;name=%@;description=%@;lat=%@&lng=%@",alt,tags,deviceID,urlEncodedName,description,lat,lng];
NSString *urlEncodedURL = (NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)mystring, NULL, CFSTR(";/?:@&=+$,"), kCFStringEncodingUTF8);
NSString *finalUrl = [NSString stringWithFormat: @"maps://maps.google.com/maps?f=q&hl=en&geocode=&q=%@",urlEncodedURL];
NSURL *url = [NSURL URLWithString:finalUrl];
[[UIApplication sharedApplication] openURL:url];
}
else{
//theStatus.text = @"Wait till location found";
}
}
- (IBAction)search:(id)sender {
if (locationObtained){
[locmanager stopUpdatingLocation];
NSString *alt = @"2";
NSString *tags = @"version1";
NSString *deviceID = theID.text;
NSString *name = @"search";
NSString *description = theCategory.text;
NSString *lat = theLat.text;
NSString *lng = theLng.text;
NSString *urlEncodedName = (NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)name, NULL, CFSTR(";/?:@&=+$,"), kCFStringEncodingUTF8);
NSString *mystring = [NSString stringWithFormat: @"http://now1.scoutic.com/gen/request?operation=add;alt=%@;tag=%@;userId=%@;name=%@;description=%@;lat=%@&lng=%@",alt,tags,deviceID,urlEncodedName,description,lat,lng];
NSString *urlEncodedURL = (NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)mystring, NULL, CFSTR(";/?:@&=+$,"), kCFStringEncodingUTF8);
NSString *finalUrl = [NSString stringWithFormat: @"maps://maps.google.com/maps?f=q&hl=en&geocode=&q=%@",urlEncodedURL];
NSURL *url = [NSURL URLWithString:finalUrl];
[[UIApplication sharedApplication] openURL:url];
}
else{
//theStatus.text = @"Wait till location found";
}
}
- (void) dealloc
{
[myPicker release];
[textField release];
[pickerArray release];
[imageView release];
[super dealloc];
}
@end