|
20 | 20 |
|
21 | 21 | public class SpinnerDialog extends CordovaPlugin { |
22 | 22 |
|
23 | | - public Stack<ProgressDialog> spinnerDialogStack = new Stack<ProgressDialog>(); |
| 23 | + public Stack<ProgressDialog> spinnerDialogStack = new Stack<ProgressDialog>(); |
24 | 24 |
|
25 | | - public SpinnerDialog() { |
26 | | - } |
| 25 | + public SpinnerDialog() { |
| 26 | + } |
27 | 27 |
|
28 | | - public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { |
29 | | - if (action.equals("show")) { |
| 28 | + public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { |
| 29 | + if (action.equals("show")) { |
30 | 30 |
|
31 | | - final String title = "null".equals(args.getString(0)) ? null : args.getString(0); |
32 | | - final String message = "null".equals(args.getString(1)) ? null : args.getString(1); |
33 | | - final boolean isFixed = args.getBoolean(2); |
| 31 | + final String title = "null".equals(args.getString(0)) ? null : args.getString(0); |
| 32 | + final String message = "null".equals(args.getString(1)) ? null : args.getString(1); |
| 33 | + final boolean isFixed = args.getBoolean(2); |
34 | 34 |
|
35 | | - final CordovaInterface cordova = this.cordova; |
36 | | - Runnable runnable = new Runnable() { |
37 | | - public void run() { |
38 | | - |
39 | | - DialogInterface.OnCancelListener onCancelListener = new DialogInterface.OnCancelListener() { |
40 | | - public void onCancel(DialogInterface dialog) { |
41 | | - if (!isFixed) { |
42 | | - while (!SpinnerDialog.this.spinnerDialogStack.empty()) { |
43 | | - SpinnerDialog.this.spinnerDialogStack.pop().dismiss(); |
44 | | - callbackContext.success(); |
45 | | - } |
46 | | - } |
47 | | - } |
48 | | - }; |
49 | | - |
50 | | - ProgressDialog dialog; |
51 | | - if (isFixed) { |
52 | | - //If there is a progressDialog yet change the text |
53 | | - if (!SpinnerDialog.this.spinnerDialogStack.empty()) { |
54 | | - dialog = SpinnerDialog.this.spinnerDialogStack.peek(); |
55 | | - if (title != null) { |
56 | | - dialog.setTitle(title); |
57 | | - } |
58 | | - if (message!=null) { |
59 | | - dialog.setMessage(message); |
60 | | - } |
61 | | - } |
62 | | - else{ |
63 | | - dialog = CallbackProgressDialog.show(cordova.getActivity(), title, message, true, false, null, callbackContext); |
64 | | - SpinnerDialog.this.spinnerDialogStack.push(dialog); |
65 | | - } |
66 | | - } else { |
67 | | - //If there is a progressDialog yet change the text |
68 | | - if (!SpinnerDialog.this.spinnerDialogStack.empty()) { |
69 | | - dialog = SpinnerDialog.this.spinnerDialogStack.peek(); |
70 | | - if (title != null) { |
71 | | - dialog.setTitle(title); |
72 | | - } |
73 | | - if (message!=null) { |
74 | | - dialog.setMessage(message); |
75 | | - } |
76 | | - } |
77 | | - else{ |
78 | | - dialog = ProgressDialog.show(cordova.getActivity(), title, message, true, true, onCancelListener); |
79 | | - SpinnerDialog.this.spinnerDialogStack.push(dialog); |
80 | | - } |
81 | | - } |
82 | | - |
83 | | - if (title == null && message == null) { |
84 | | - dialog.setContentView(new ProgressBar(cordova.getActivity())); |
85 | | - dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); |
86 | | - } |
87 | | - |
88 | | - |
89 | | - } |
90 | | - }; |
91 | | - this.cordova.getActivity().runOnUiThread(runnable); |
92 | | - |
93 | | - } else if (action.equals("hide")) { |
94 | | - |
95 | | - Runnable runnable = new Runnable() { |
96 | | - public void run() { |
97 | | - |
98 | | - if (!SpinnerDialog.this.spinnerDialogStack.empty()) { |
99 | | - SpinnerDialog.this.spinnerDialogStack.pop().dismiss(); |
100 | | - } |
101 | | - |
102 | | - } |
103 | | - }; |
104 | | - this.cordova.getActivity().runOnUiThread(runnable); |
105 | | - |
106 | | - } |
107 | | - |
108 | | - return true; |
109 | | - } |
| 35 | + final CordovaInterface cordova = this.cordova; |
| 36 | + Runnable runnable = new Runnable() { |
| 37 | + public void run() { |
| 38 | + |
| 39 | + DialogInterface.OnCancelListener onCancelListener = new DialogInterface.OnCancelListener() { |
| 40 | + public void onCancel(DialogInterface dialog) { |
| 41 | + if (!isFixed) { |
| 42 | + while (!SpinnerDialog.this.spinnerDialogStack.empty()) { |
| 43 | + SpinnerDialog.this.spinnerDialogStack.pop().dismiss(); |
| 44 | + callbackContext.success(); |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + }; |
| 49 | + |
| 50 | + ProgressDialog dialog; |
| 51 | + if (isFixed) { |
| 52 | + //If there is a progressDialog yet change the text |
| 53 | + if (!SpinnerDialog.this.spinnerDialogStack.empty()) { |
| 54 | + dialog = SpinnerDialog.this.spinnerDialogStack.peek(); |
| 55 | + if (title != null) { |
| 56 | + dialog.setTitle(title); |
| 57 | + } |
| 58 | + if (message!=null) { |
| 59 | + dialog.setMessage(message); |
| 60 | + } |
| 61 | + } |
| 62 | + else{ |
| 63 | + dialog = CallbackProgressDialog.show(cordova.getActivity(), title, message, true, false, null, callbackContext); |
| 64 | + SpinnerDialog.this.spinnerDialogStack.push(dialog); |
| 65 | + } |
| 66 | + } else { |
| 67 | + //If there is a progressDialog yet change the text |
| 68 | + if (!SpinnerDialog.this.spinnerDialogStack.empty()) { |
| 69 | + dialog = SpinnerDialog.this.spinnerDialogStack.peek(); |
| 70 | + if (title != null) { |
| 71 | + dialog.setTitle(title); |
| 72 | + } |
| 73 | + if (message!=null) { |
| 74 | + dialog.setMessage(message); |
| 75 | + } |
| 76 | + } |
| 77 | + else{ |
| 78 | + dialog = ProgressDialog.show(cordova.getActivity(), title, message, true, true, onCancelListener); |
| 79 | + SpinnerDialog.this.spinnerDialogStack.push(dialog); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + if (title == null && message == null) { |
| 84 | + dialog.setContentView(new ProgressBar(cordova.getActivity())); |
| 85 | + dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); |
| 86 | + } |
| 87 | + |
| 88 | + |
| 89 | + } |
| 90 | + }; |
| 91 | + this.cordova.getActivity().runOnUiThread(runnable); |
| 92 | + |
| 93 | + } else if (action.equals("hide")) { |
| 94 | + |
| 95 | + Runnable runnable = new Runnable() { |
| 96 | + public void run() { |
| 97 | + |
| 98 | + if (!SpinnerDialog.this.spinnerDialogStack.empty()) { |
| 99 | + SpinnerDialog.this.spinnerDialogStack.pop().dismiss(); |
| 100 | + } |
| 101 | + |
| 102 | + } |
| 103 | + }; |
| 104 | + this.cordova.getActivity().runOnUiThread(runnable); |
| 105 | + |
| 106 | + } |
| 107 | + |
| 108 | + return true; |
| 109 | + } |
110 | 110 |
|
111 | 111 | } |
0 commit comments