Skip to content
Browse files

Modal dialog to give a waiting feedback to users

  • Loading branch information...
1 parent c74a9be commit 20c94047c8bbfce8826ae618e2d44ab436d0c7fa @guidosabatini guidosabatini committed
View
20 Android/WaitingDialog/README.md
@@ -0,0 +1,20 @@
+# Waiting dialog for Android applications
+
+_Created by `Guido Sabatini`_
+
+Creates a modal dialog to give a waiting feedback to users
+You can only show and dismiss the dialog, it will block user interactions. You can set the text appearing in the dialog
+NOTE: this is not a progress dialog, you can not show progress
+
+ // To SHOW a modal waiting dialog
+ window.plugins.waitingDialog.show("Your dialog text");
+
+ // To HIDE the dialog
+ window.plugins.waitingDialog.hide();
+
+If you want to show a waiting dialog for a certain amount of time, you can use javascript setTimeout
+
+ // show dialog
+ window.plugins.waitingDialog.show("Your dialog text");
+ // automatically hide dialog after 5 seconds
+ setTimeout(function() {window.plugins.waitingDialog.hide();}, 5000);
View
49 Android/WaitingDialog/WaitingDialog.java
@@ -0,0 +1,49 @@
+package org.apache.cordova;
+
+import org.apache.cordova.api.CallbackContext;
+import org.apache.cordova.api.CordovaPlugin;
+import org.apache.cordova.api.LOG;
+import org.json.JSONArray;
+import org.json.JSONException;
+import android.app.ProgressDialog;
+
+public class WaitingDialog extends CordovaPlugin {
+
+ private ProgressDialog waitingDialog = null;
+
+ @Override
+ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
+ if ("show".equals(action)) {
+ String text = "Please wait";
+ try {
+ text = args.getString(0);
+ } catch (Exception e) {
+ LOG.d("WaitingDialog", "Text parameter not valid, using default");
+ }
+ showWaitingDialog(text);
+ callbackContext.success();
+ return true;
+ } else if ("hide".equals(action)) {
+ hideWaitingDialog();
+ callbackContext.success();
+ return true;
+ }
+ return false;
+ }
+
+ public void showWaitingDialog(String text) {
+ waitingDialog = ProgressDialog.show(this.cordova.getActivity(), "", text);
+ LOG.d("WaitingDialog", "Dialog shown, waiting hide command");
+ }
+
+ public void hideWaitingDialog() {
+ if (waitingDialog != null) {
+ waitingDialog.dismiss();
+ LOG.d("WaitingDialog", "Dialog dismissed");
+ waitingDialog = null;
+ } else {
+ LOG.d("WaitingDialog", "Nothing to dismiss");
+ }
+ }
+
+}
View
25 Android/WaitingDialog/WaitingDialog.js
@@ -0,0 +1,25 @@
+// window.plugins.waitingDialog
+
+function WaitingDialog() {
+}
+
+WaitingDialog.prototype.show = function(text) {
+ cordova.exec(null, null, "WaitingDialog", "show", [text]);
+}
+
+WaitingDialog.prototype.hide = function() {
+ cordova.exec(null, null, "WaitingDialog", "hide", []);
+}
+
+cordova.addConstructor(function() {
+ if(!window.plugins) {
+ window.plugins = {};
+ }
+
+ // shim to work in 1.5 and 1.6
+ if (!window.Cordova) {
+ window.Cordova = cordova;
+ };
+
+ window.plugins.waitingDialog = new WaitingDialog();
+});
View
20 iOS/WaitingDialog/README.md
@@ -0,0 +1,20 @@
+# Waiting dialog for iOS applications
+
+_Created by `Guido Sabatini`_
+
+Creates a modal dialog to give a waiting feedback to users
+You can only show and dismiss the dialog, it will block user interactions. You can set the text appearing in the dialog
+NOTE: this is not a progress dialog, you can not show progress
+
+ // To SHOW a modal waiting dialog
+ window.plugins.waitingDialog.show("Your dialog text");
+
+ // To HIDE the dialog
+ window.plugins.waitingDialog.hide();
+
+If you want to show a waiting dialog for a certain amount of time, you can use javascript setTimeout
+
+ // show dialog
+ window.plugins.waitingDialog.show("Your dialog text");
+ // automatically hide dialog after 5 seconds
+ setTimeout(function() {window.plugins.waitingDialog.hide();}, 5000);
View
23 iOS/WaitingDialog/WaitingDialog.h
@@ -0,0 +1,23 @@
+//
+// WaitingDialog.h
+//
+//
+// Created by Guido Sabatini in 2012
+//
+
+#import <Foundation/Foundation.h>
+#import <Cordova/CDVPlugin.h>
+
+
+@interface WaitingDialog : CDVPlugin {
+
+}
+
+// UNCOMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
+//- (void) show:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+// COMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
+- (void) show:(CDVInvokedUrlCommand*)command;
+- (void) hide:(CDVInvokedUrlCommand*)command;
+
+@end
View
25 iOS/WaitingDialog/WaitingDialog.js
@@ -0,0 +1,25 @@
+// window.plugins.waitingDialog
+
+function WaitingDialog() {
+}
+
+WaitingDialog.prototype.show = function(text) {
+ cordova.exec(null, null, "WaitingDialog", "show", [text]);
+}
+
+WaitingDialog.prototype.hide = function() {
+ cordova.exec(null, null, "WaitingDialog", "hide", []);
+}
+
+cordova.addConstructor(function() {
+ if(!window.plugins) {
+ window.plugins = {};
+ }
+
+ // shim to work in 1.5 and 1.6
+ if (!window.Cordova) {
+ window.Cordova = cordova;
+ };
+
+ window.plugins.waitingDialog = new WaitingDialog();
+});
View
90 iOS/WaitingDialog/WaitingDialog.m
@@ -0,0 +1,90 @@
+//
+// WaitingDialog.m
+//
+//
+// Created by Guido Sabatini in 2012
+//
+
+#import "WaitingDialog.h"
+
+@interface WaitingDialog () {
+ UIAlertView *waitingDialog;
+}
+
+@property (nonatomic, retain) UIAlertView *waitingDialog;
+-(void)showWaitingDialogWithText:(NSString*)text;
+-(void)hideWaitingDialog;
+
+@end
+
+@implementation WaitingDialog
+
+@synthesize waitingDialog = _waitingDialog;
+
+-(UIAlertView *)waitingDialog {
+ if (!_waitingDialog) {
+ _waitingDialog = [[[UIAlertView alloc] initWithTitle:@"" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
+ }
+ return _waitingDialog;
+}
+
+// UNCOMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
+//- (void) show:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
+// NSString *text = @"Please wait...";
+// @try {
+// text = [options valueForKey:@"text"];
+// }
+// @catch (NSException *exception) {
+// DLog(@"Cannot read text argument")
+// }
+//
+// [self showWaitingDialogWithText:text];
+//}
+
+// COMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
+- (void) show:(CDVInvokedUrlCommand*)command {
+ NSString *text = @"Please wait...";
+ @try {
+ text = [command.arguments objectAtIndex:0];
+ }
+ @catch (NSException *exception) {
+ DLog(@"Cannot read text argument")
+ }
+
+ [self showWaitingDialogWithText:text];
+}
+
+// UNCOMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
+//- (void) hide:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
+// [self hideWaitingDialog];
+//}
+
+// COMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
+- (void) hide:(CDVInvokedUrlCommand*)command {
+ [self hideWaitingDialog];
+}
+
+#pragma mark - PRIVATE METHODS
+
+-(void)showWaitingDialogWithText:(NSString *)text {
+ [self.waitingDialog setTitle:text];
+ [self.waitingDialog show];
+ UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
+
+ // Adjust the indicator so it is up a few pixels from the bottom of the alert
+ indicator.center = CGPointMake(self.waitingDialog.bounds.size.width / 2, self.waitingDialog.bounds.size.height - 50);
+ [indicator startAnimating];
+ [self.waitingDialog addSubview:indicator];
+ [indicator release];
+}
+
+-(void)hideWaitingDialog {
+ if (_waitingDialog) {
+ [self.waitingDialog dismissWithClickedButtonIndex:0 animated:YES];
+ _waitingDialog = nil;
+ }
+}
+
+
+
+@end

0 comments on commit 20c9404

Please sign in to comment.
Something went wrong with that request. Please try again.