1+ //
2+ // WaitingDialog.m
3+ //
4+ //
5+ // Created by Guido Sabatini in 2012
6+ //
7+
8+ #import " WaitingDialog.h"
9+
10+ @interface WaitingDialog () {
11+ UIAlertView *waitingDialog;
12+ }
13+
14+ @property (nonatomic , retain ) UIAlertView *waitingDialog;
15+ -(void )showWaitingDialogWithText : (NSString *)text ;
16+ -(void )hideWaitingDialog ;
17+
18+ @end
19+
20+ @implementation WaitingDialog
21+
22+ @synthesize waitingDialog = _waitingDialog;
23+
24+ -(UIAlertView *)waitingDialog {
25+ if (!_waitingDialog) {
26+ _waitingDialog = [[[UIAlertView alloc ] initWithTitle: @" " message: nil delegate: self cancelButtonTitle: nil otherButtonTitles: nil ] autorelease ];
27+ }
28+ return _waitingDialog;
29+ }
30+
31+ // UNCOMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
32+ // - (void) show:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
33+ // NSString *text = @"Please wait...";
34+ // @try {
35+ // text = [options valueForKey:@"text"];
36+ // }
37+ // @catch (NSException *exception) {
38+ // DLog(@"Cannot read text argument")
39+ // }
40+ //
41+ // [self showWaitingDialogWithText:text];
42+ // }
43+
44+ // COMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
45+ - (void ) show : (CDVInvokedUrlCommand*)command {
46+ NSString *text = @" Please wait..." ;
47+ @try {
48+ text = [command.arguments objectAtIndex: 0 ];
49+ }
50+ @catch (NSException *exception) {
51+ DLog (@" Cannot read text argument" )
52+ }
53+
54+ [self showWaitingDialogWithText: text];
55+ }
56+
57+ // UNCOMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
58+ // - (void) hide:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
59+ // [self hideWaitingDialog];
60+ // }
61+
62+ // COMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
63+ - (void ) hide : (CDVInvokedUrlCommand*)command {
64+ [self hideWaitingDialog ];
65+ }
66+
67+ #pragma mark - PRIVATE METHODS
68+
69+ -(void )showWaitingDialogWithText : (NSString *)text {
70+ [self .waitingDialog setTitle: text];
71+ [self .waitingDialog show ];
72+ UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc ] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge];
73+
74+ // Adjust the indicator so it is up a few pixels from the bottom of the alert
75+ indicator.center = CGPointMake (self.waitingDialog .bounds .size .width / 2 , self.waitingDialog .bounds .size .height - 50 );
76+ [indicator startAnimating ];
77+ [self .waitingDialog addSubview: indicator];
78+ [indicator release ];
79+ }
80+
81+ -(void )hideWaitingDialog {
82+ if (_waitingDialog) {
83+ [self .waitingDialog dismissWithClickedButtonIndex: 0 animated: YES ];
84+ _waitingDialog = nil ;
85+ }
86+ }
87+
88+
89+
90+ @end
0 commit comments