-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNotification.m
207 lines (165 loc) · 6.22 KB
/
Notification.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
//
// Notification.m
// PhoneGap
//
// Created by Michael Nachbaur on 16/04/09.
// Copyright 2009 Decaf Ninja Software. All rights reserved.
//
#import "Notification.h"
#import "Categories.h"
#import "UIColor-Expanded.h"
@implementation Notification
@synthesize loadingView;
- (void)alert:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
NSString* message = [arguments objectAtIndex:0];
NSString* title = [options objectForKey:@"title"];
NSString* button = [options objectForKey:@"buttonLabel"];
NSString* imgPath = [options objectForKey:@"imgPath"];
if (!title)
title = @"Alert";
if (!button)
button = @"OK";
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:title
message:message
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
if (imgPath) {
CGRect myImageRect = CGRectMake(15.0f, 10.0f, 50.0f, 50.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:imgPath]];
[alertView addSubview:myImage];
}
NSArray* labels = [ button componentsSeparatedByString:@","];
int count = [ labels count ];
for(int n = 0; n < count; n++)
{
[ alertView addButtonWithTitle:[labels objectAtIndex:n]];
}
[alertView show];
[alertView release];
}
- (void)prompt:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
NSString* message = [arguments objectAtIndex:0];
NSString* title = [options objectForKey:@"title"];
NSString* button = [options objectForKey:@"buttonLabel"];
if (!title)
title = @"Prompt";
if (!button)
button = @"OK";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:button otherButtonTitles: nil];
[alert addTextFieldWithValue:@"" label:@""];
[alert show];
[alert release];
//myTextField.secureTextEntry = YES;
}
/**
Callback invoked when an alert dialog's buttons are clicked.
Passes the index + label back to JS
*/
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonLabel = [alertView buttonTitleAtIndex:buttonIndex];
NSString * jsCallBack = [NSString stringWithFormat:@"navigator.notification._alertCallback(%d,\"%@\");", buttonIndex, buttonLabel];
[webView stringByEvaluatingJavaScriptFromString:jsCallBack];
}
- (void)activityStart:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
//[(UIActivityIndicatorView*)[self.webView.window viewWithTag:2] startAnimating];
NSLog(@"Activity starting");
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
}
- (void)activityStop:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
//[(UIActivityIndicatorView*)[self.webView.window viewWithTag:2] stopAnimating];
NSLog(@"Activitiy stopping ");
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = NO;
}
- (void)vibrate:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
- (void)loadingStart:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
if (self.loadingView != nil) {
return;
}
CGFloat strokeOpacity, backgroundOpacity;
//CGFloat boxLength = [LoadingView defaultBoxLength];
CGFloat boxLength = 240;
BOOL fullScreen = YES;
BOOL bounceAnimation = NO;
NSString* colorCSSString;
NSString* labelText;
strokeOpacity = [[options objectForKey:@"strokeOpacity"] floatValue];
backgroundOpacity = [[options objectForKey:@"backgroundOpacity"] floatValue];
id fullScreenValue = [options objectForKey:@"fullScreen"];
if (fullScreenValue != nil)
{
fullScreen = [fullScreenValue boolValue];
if (!fullScreen) { // here we take into account rectSquareLength, if any
boxLength = fmax(boxLength, [[options objectForKey:@"boxLength"] floatValue]);
}
}
id bounceAnimationValue = [options objectForKey:@"bounceAnimation"];
if (bounceAnimationValue != nil)
{
bounceAnimation = [bounceAnimationValue boolValue];
}
colorCSSString = [options objectForKey:@"strokeColor"];
labelText = [options objectForKey:@"labelText"];
if (!labelText) {
labelText = [LoadingView defaultLabelText];
}
UIColor* strokeColor = [LoadingView defaultStrokeColor];
if (strokeOpacity <= 0) {
strokeOpacity = [LoadingView defaultStrokeOpacity];
}
if (backgroundOpacity <= 0) {
backgroundOpacity = [LoadingView defaultBackgroundOpacity];
}
if (colorCSSString) {
UIColor* tmp = [UIColor colorWithName:colorCSSString];
if (tmp) {
strokeColor = tmp;
} else {
tmp = [UIColor colorWithHexString:colorCSSString];
if (tmp) {
strokeColor = tmp;
}
}
}
self.loadingView = [LoadingView loadingViewInView:[super appViewController].view strokeOpacity:strokeOpacity
backgroundOpacity:backgroundOpacity
strokeColor:strokeColor fullScreen:fullScreen labelText:labelText
bounceAnimation:bounceAnimation boxLength:boxLength];
NSRange minMaxDuration = NSMakeRange(2, 120);// 1 hour max? :)
NSString* durationKey = @"duration";
// the view will be shown for a minimum of this value if durationKey is not set
self.loadingView.minDuration = [options integerValueForKey:@"minDuration" defaultValue:minMaxDuration.location withRange:minMaxDuration];
// if there's a duration set, we set a timer to close the view
if ([options valueForKey:durationKey]) {
NSTimeInterval duration = [options integerValueForKey:durationKey defaultValue:minMaxDuration.location withRange:minMaxDuration];
[self performSelector:@selector(loadingStop:withDict:) withObject:nil afterDelay:duration];
}
}
- (void)loadingStop:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
if (self.loadingView != nil)
{
NSLog(@"Loading stop");
NSTimeInterval diff = [[NSDate date] timeIntervalSinceDate:self.loadingView.timestamp] - self.loadingView.minDuration;
if (diff >= 0) {
[self.loadingView removeView]; // the superview will release (see removeView doc), so no worries for below
self.loadingView = nil;
} else {
[self performSelector:@selector(loadingStop:withDict:) withObject:nil afterDelay:-1*diff];
}
}
}
@end