-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointInfoViewController.m
executable file
·235 lines (212 loc) · 7.3 KB
/
PointInfoViewController.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
//
// ViewController.m
// PointInfoViewController
//
// Created by Junfeng Shen on 18/2/12.
// Copyright (c) 2012 SYSU. All rights reserved.
//
#import "PointInfoViewController.h"
#define NumPerTime 15
@implementation PointInfoViewController
@synthesize pInfo;
- (id)initWithPoint:(pointInfo *)p{
self = [super initWithStyle:UITableViewStyleGrouped];
self.pInfo = p;
db = [[DatabaseOperation alloc] init];
stumbler = [[Stumbler alloc] init];
[db getSamplesForPoint:self.pInfo];
formatter1 = [[NSDateFormatter alloc] init];
[formatter1 setDateFormat:@"yyyy-MM-dd HH:mm"];
formatter2 = [[NSDateFormatter alloc] init];
[formatter2 setDateFormat:@"HH:mm:ss yyyy-MM-dd"];
nextSampleID = [db getNextSampleID];
for(int i = 0; i<self.pInfo.samples.count; i++){
sampleInfo *s = [self.pInfo.samples objectAtIndex:i];
s.signalCount = [db getSignalCountForSample:s];
}
busyIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[busyIndicator hidesWhenStopped];
return self;
}
- (void)dealloc{
[self.pInfo release];
[db release];
[stumbler release];
[formatter1 release];
[formatter2 release];
[busyIndicator release];
[super dealloc];
}
- (NSInteger)getNextSampleID{
nextSampleID ++;
[db setNextSampleID:nextSampleID];
return nextSampleID-1;
}
#pragma mark - View lifecycle
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
switch (section) {
case 0:
return 1;
case 1:
return 3;
case 2:
return self.pInfo.samples.count;
}
return 0;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 3;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell;
switch (indexPath.section) {
case 0:
cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
if(cell == nil)
cell = [[[NSBundle mainBundle] loadNibNamed:@"ButtonCell" owner:self options:nil] objectAtIndex:0];
break;
case 1:
cell = [tableView dequeueReusableCellWithIdentifier:@"infoCell"];
if(cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"infoCell"];
switch (indexPath.row) {
case 0:
cell.textLabel.text = @"cooradinate";
cell.detailTextLabel.text = [NSString stringWithFormat:@"(%.0f, %.0f)",pInfo.coordinate.x, pInfo.coordinate.y];
break;
case 1:
cell.textLabel.text = @"create time";
cell.detailTextLabel.text = [formatter1 stringFromDate:self.pInfo.createDate];
break;
case 2:
cell.textLabel.text = @"samples count";
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d", self.pInfo.samples.count];
break;
}
break;
case 2:
cell = [tableView dequeueReusableCellWithIdentifier:@"sampleCell"];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"sampleCell"];
sampleInfo *tmp = [self.pInfo.samples objectAtIndex:(self.pInfo.samples.count - 1 - [indexPath row])];
cell.textLabel.text = [NSString stringWithFormat:@"%@", [formatter2 stringFromDate:tmp.capDate]];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Number of captured AP = %d", tmp.signalCount];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
break;
}
return cell;
}
- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
switch (section) {
case 0:
return nil;
case 1:
return @"Basic information";
case 2:
return @"Captured samples";
}
return nil;
}
- (NSIndexPath*)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.section == 1)
return nil;
else
return indexPath;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
switch(indexPath.section){
case 0:
NSLog(@"capture signals");
self.tableView.userInteractionEnabled = NO;
[self performSelectorInBackground:@selector(captureSample) withObject:nil];
[[tableView cellForRowAtIndexPath:indexPath] setSelected:NO];
return;
case 1:
return;
case 2:
nextLevel = YES;
[self.navigationController pushViewController:[[SampleInfoViewController alloc] initWithSample:[self.pInfo.samples objectAtIndex:(self.pInfo.samples.count - 1 - indexPath.row)]] animated:YES];
[[tableView cellForRowAtIndexPath:indexPath] setSelected:NO];
}
}
- (void)captureSample{
[self performSelectorInBackground:@selector(setBusy) withObject:nil];
sampleInfo* sample;
for(int i=0; i<NumPerTime; i++){
sample = [[sampleInfo alloc] initWithDate];
if ([stumbler scanNetwork:sample] == NO){
//if([StumblerSimulator scanNetwork:sample] == NO){
UIAlertView *al =[[UIAlertView alloc] initWithTitle:@"Capture Failed" message:@"Please turn on Wi-Fi option in Setting" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[self performSelectorInBackground:@selector(resetBusy) withObject:nil];
[al show];
[al release];
}else{
sample.sId = [self getNextSampleID];
[self.pInfo.samples addObject:sample];
[db addSample:sample forPoint:self.pInfo];
self.pInfo.sampleCount = self.pInfo.samples.count;
[self performSelector:@selector(resetBusy)];
}
[sample release];
NSLog(@"the %d th sample",i+1);
[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
}
self.tableView.userInteractionEnabled = YES;
}
- (void)setBusy{
[busyIndicator startAnimating];
}
- (void)resetBusy{
[busyIndicator stopAnimating];}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.section == 2)
return YES;
else
return NO;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[db delSample:[self.pInfo.samples objectAtIndex:(self.pInfo.samples.count - 1 - indexPath.row)]];
[self.pInfo.samples removeObjectAtIndex:(self.pInfo.samples.count - 1 - indexPath.row)];
self.pInfo.sampleCount = self.pInfo.samples.count;
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView reloadData];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
nextLevel = NO;
self.navigationItem.title = @"PointInfo";
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:busyIndicator];
self.navigationItem.rightBarButtonItem = item;
[item release];
}
- (void)viewDidAppear:(BOOL)animated
{
if(nextLevel == YES)
nextLevel = NO;
else
preHide = self.navigationController.isNavigationBarHidden;
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if(nextLevel){
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
else
[self.navigationController setNavigationBarHidden:preHide animated:YES];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[self.tableView reloadData];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end