Skip to content

Commit 82f6b5c

Browse files
committed
InAppBrowser Compatibility Paldom#34
1 parent 6674a59 commit 82f6b5c

9 files changed

Lines changed: 250 additions & 257 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ cordova prepare
2929
#### SpinnerDialog.hide
3030
SpinnerDialog.hide();
3131

32-
3332
## Quirks
3433
* Cordova 5.0 or higher is required for Windows 10 support.
3534
* Windows 10 Mobile or Windows Phone 8.1 is required as desktop doesn't support StatusBar.

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"id": "cordova-plugin-spinnerdialog",
1414
"platforms": [
1515
"android",
16-
"ios",
17-
"wp8",
16+
"ios",
17+
"wp8",
1818
"windows"
1919
]
2020
},
@@ -24,22 +24,22 @@
2424
"dialog",
2525
"spinnerdialog",
2626
"progress",
27-
"indicator",
28-
"progressindicator",
27+
"indicator",
28+
"progressindicator",
2929
"plugin",
3030
"notification",
3131
"ecosystem:cordova",
3232
"cordova-android",
33-
"cordova-ios",
34-
"cordova-wp8",
33+
"cordova-ios",
34+
"cordova-wp8",
3535
"cordova-windows",
36-
"android",
37-
"ios",
38-
"wp8",
39-
"windows",
40-
"10",
41-
"8.1",
42-
"phone"
36+
"android",
37+
"ios",
38+
"wp8",
39+
"windows",
40+
"10",
41+
"8.1",
42+
"phone"
4343
],
4444
"engines": [
4545
{
@@ -50,4 +50,4 @@
5050
"bugs": {
5151
"url": "https://github.com/filfat-Studios-AB/cordova-plugin-spinnerdialog/issues"
5252
}
53-
}
53+
}

plugin.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!--
3-
cordova-plugin-spinnerdialog
4-
Copyright © 2015 filfat Studios AB
5-
Repo: https://github.com/filfat-Studios-AB/cordova-plugin-spinnerdialog
6-
-->
72
<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
83
xmlns:android="http://schemas.android.com/apk/res/android"
94
xmlns:amazon="http://schemas.android.com/apk/lib/com.amazon.device.ads"

src/android/CallbackProgressDialog.java

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,45 @@
1212

1313
public class CallbackProgressDialog extends ProgressDialog {
1414

15-
public static CallbackContext callbackContext;
16-
17-
public CallbackProgressDialog(Context context) {
18-
super(context);
19-
}
20-
21-
public static CallbackProgressDialog show(Context context,
22-
CharSequence title, CharSequence message, boolean indeterminate,
23-
boolean cancelable, OnCancelListener cancelListener,
24-
CallbackContext callbackContext) {
25-
CallbackProgressDialog.callbackContext = callbackContext;
26-
CallbackProgressDialog dialog = new CallbackProgressDialog(context);
27-
dialog.setTitle(title);
28-
dialog.setMessage(message);
29-
dialog.setIndeterminate(indeterminate);
30-
dialog.setCancelable(cancelable);
31-
dialog.setOnCancelListener(cancelListener);
32-
dialog.show();
33-
return dialog;
34-
}
35-
36-
private void sendCallback() {
37-
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
38-
pluginResult.setKeepCallback(true);
39-
callbackContext.sendPluginResult(pluginResult);
40-
}
41-
42-
@Override
43-
public void onBackPressed() {
44-
sendCallback();
45-
}
46-
47-
@Override
48-
public boolean onTouchEvent(MotionEvent event) {
49-
if (event.getAction() == MotionEvent.ACTION_DOWN) {
50-
sendCallback();
51-
return true;
52-
}
53-
return false;
54-
}
15+
public static CallbackContext callbackContext;
16+
17+
public CallbackProgressDialog(Context context) {
18+
super(context);
19+
}
20+
21+
public static CallbackProgressDialog show(Context context,
22+
CharSequence title, CharSequence message, boolean indeterminate,
23+
boolean cancelable, OnCancelListener cancelListener,
24+
CallbackContext callbackContext) {
25+
CallbackProgressDialog.callbackContext = callbackContext;
26+
CallbackProgressDialog dialog = new CallbackProgressDialog(context);
27+
dialog.setTitle(title);
28+
dialog.setMessage(message);
29+
dialog.setIndeterminate(indeterminate);
30+
dialog.setCancelable(cancelable);
31+
dialog.setOnCancelListener(cancelListener);
32+
dialog.show();
33+
return dialog;
34+
}
35+
36+
private void sendCallback() {
37+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
38+
pluginResult.setKeepCallback(true);
39+
callbackContext.sendPluginResult(pluginResult);
40+
}
41+
42+
@Override
43+
public void onBackPressed() {
44+
sendCallback();
45+
}
46+
47+
@Override
48+
public boolean onTouchEvent(MotionEvent event) {
49+
if (event.getAction() == MotionEvent.ACTION_DOWN) {
50+
sendCallback();
51+
return true;
52+
}
53+
return false;
54+
}
5555

5656
}

src/android/SpinnerDialog.java

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -20,92 +20,92 @@
2020

2121
public class SpinnerDialog extends CordovaPlugin {
2222

23-
public Stack<ProgressDialog> spinnerDialogStack = new Stack<ProgressDialog>();
23+
public Stack<ProgressDialog> spinnerDialogStack = new Stack<ProgressDialog>();
2424

25-
public SpinnerDialog() {
26-
}
25+
public SpinnerDialog() {
26+
}
2727

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")) {
3030

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);
3434

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+
}
110110

111111
}

src/ios/CDVSpinnerDialog.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ - (void) show:(CDVInvokedUrlCommand*)command {
8888

8989
UIViewController *rootViewController = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
9090

91-
[rootViewController.view addSubview:self.overlay];
91+
[[self getTopMostViewController].view addSubview:self.overlay];
9292

9393
}
9494

@@ -107,6 +107,13 @@ - (void) hide {
107107
_overlay = nil;
108108
}
109109
}
110+
- (UIViewController*) getTopMostViewController {
111+
UIViewController *presentingViewController = [[[UIApplication sharedApplication] delegate] window].rootViewController;
112+
while (presentingViewController.presentedViewController != nil) {
113+
presentingViewController = presentingViewController.presentedViewController;
114+
}
115+
return presentingViewController;
116+
}
110117

111118
#pragma mark - PRIVATE METHODS
112119

0 commit comments

Comments
 (0)