diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 4244e9f6..197fde9e 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -16,26 +16,16 @@
-
-
-
-
-
-
-
+
-
-
-
-
-
+
+
-
@@ -58,8 +48,20 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -76,8 +78,8 @@
-
-
+
+
@@ -88,8 +90,8 @@
-
-
+
+
@@ -100,7 +102,7 @@
-
+
@@ -112,8 +114,8 @@
-
-
+
+
@@ -121,8 +123,8 @@
-
-
+
+
@@ -130,11 +132,20 @@
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -154,9 +165,6 @@
- List<Con
- appCacheEnabled
- List<Content
NOTE
onGeolocationPermissionsShowPrompt
"onGeolocationPermissionsShowPrompt"
@@ -184,6 +192,9 @@
onJs
onJsAlert
defaultValue
+ onJsA
+ toMap()
+ .toMap()
activity.getPreferences(0)
@@ -242,7 +253,6 @@
-
@@ -250,16 +260,16 @@
-
-
-
+
+
+
+
-
@@ -270,6 +280,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -326,17 +347,6 @@
-
-
-
-
-
-
-
-
-
-
-
@@ -487,11 +497,11 @@
-
+
-
-
+
+
@@ -501,7 +511,7 @@
-
+
@@ -509,7 +519,7 @@
-
+
@@ -748,23 +758,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -793,23 +786,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -817,16 +793,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -837,6 +803,13 @@
+
+
+
+
+
+
+
@@ -844,17 +817,10 @@
-
+
-
-
-
-
-
-
-
-
-
+
+
@@ -863,7 +829,7 @@
-
+
@@ -871,10 +837,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
diff --git a/android/build.gradle b/android/build.gradle
index fc587565..e53aab08 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -1,16 +1,3 @@
-def PLUGIN = "flutter_inappbrowser";
-def ANDROIDX_WARNING = "flutterPluginsAndroidXWarning";
-gradle.buildFinished { buildResult ->
- if (buildResult.failure && !rootProject.ext.has(ANDROIDX_WARNING)) {
- println ' *********************************************************'
- println 'WARNING: This version of ' + PLUGIN + ' will break your Android build if it or its dependencies aren\'t compatible with AndroidX.'
- println ' See https://goo.gl/CP92wY for more information on the problem and how to fix it.'
- println ' This warning prints for all Android build failures. The real root cause of the error may be unrelated.'
- println ' *********************************************************'
- rootProject.ext.set(ANDROIDX_WARNING, true);
- }
-}
-
group 'com.pichillilorenzo.flutter_inappbrowser'
version '1.0-SNAPSHOT'
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebChromeClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebChromeClient.java
index 0df49d0d..b20461e8 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebChromeClient.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebChromeClient.java
@@ -112,67 +112,78 @@ public class InAppWebChromeClient extends WebChromeClient {
getChannel().invokeMethod("onJsAlert", obj, new MethodChannel.Result() {
@Override
public void success(Object response) {
- Map responseMap = (Map) response;
- String responseMessage = (String) responseMap.get("message");
- String confirmButtonTitle = (String) responseMap.get("confirmButtonTitle");
- boolean handledByClient = (boolean) responseMap.get("handledByClient");
- if (handledByClient) {
- Integer action = (Integer) responseMap.get("action");
- action = action != null ? action : 1;
- switch (action) {
- case 0:
- result.confirm();
- break;
- case 1:
- default:
- result.cancel();
- }
- } else {
- String alertMessage = (responseMessage != null && !responseMessage.isEmpty()) ? responseMessage : message;
- Log.d(LOG_TAG, alertMessage);
- DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- result.confirm();
- dialog.dismiss();
+ String responseMessage = null;
+ String confirmButtonTitle = null;
+
+ if (response != null) {
+ Map responseMap = (Map) response;
+ responseMessage = (String) responseMap.get("message");
+ confirmButtonTitle = (String) responseMap.get("confirmButtonTitle");
+ Boolean handledByClient = (Boolean) responseMap.get("handledByClient");
+ if (handledByClient != null && handledByClient) {
+ Integer action = (Integer) responseMap.get("action");
+ action = action != null ? action : 1;
+ switch (action) {
+ case 0:
+ result.confirm();
+ break;
+ case 1:
+ default:
+ result.cancel();
}
- };
-
- AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(view.getContext(), R.style.Theme_AppCompat_Dialog_Alert);
- alertDialogBuilder.setMessage(alertMessage);
- if (confirmButtonTitle != null && !confirmButtonTitle.isEmpty()) {
- alertDialogBuilder.setPositiveButton(confirmButtonTitle, clickListener);
- } else {
- alertDialogBuilder.setPositiveButton(android.R.string.ok, clickListener);
+ return;
}
-
- alertDialogBuilder.setOnCancelListener(new DialogInterface.OnCancelListener() {
- @Override
- public void onCancel(DialogInterface dialog) {
- result.cancel();
- dialog.dismiss();
- }
- });
-
- AlertDialog alertDialog = alertDialogBuilder.create();
- alertDialog.show();
}
+
+ createAlertDialog(view, message, result, responseMessage, confirmButtonTitle);
}
@Override
public void error(String s, String s1, Object o) {
Log.e(LOG_TAG, s + ", " + s1);
+ result.cancel();
}
@Override
public void notImplemented() {
-
+ createAlertDialog(view, message, result, null, null);
}
});
return true;
}
+ public void createAlertDialog(WebView view, String message, final JsResult result, String responseMessage, String confirmButtonTitle) {
+ String alertMessage = (responseMessage != null && !responseMessage.isEmpty()) ? responseMessage : message;
+
+ DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ result.confirm();
+ dialog.dismiss();
+ }
+ };
+
+ AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(view.getContext(), R.style.Theme_AppCompat_Dialog_Alert);
+ alertDialogBuilder.setMessage(alertMessage);
+ if (confirmButtonTitle != null && !confirmButtonTitle.isEmpty()) {
+ alertDialogBuilder.setPositiveButton(confirmButtonTitle, clickListener);
+ } else {
+ alertDialogBuilder.setPositiveButton(android.R.string.ok, clickListener);
+ }
+
+ alertDialogBuilder.setOnCancelListener(new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ result.cancel();
+ dialog.dismiss();
+ }
+ });
+
+ AlertDialog alertDialog = alertDialogBuilder.create();
+ alertDialog.show();
+ }
+
@Override
public boolean onJsConfirm(final WebView view, String url, final String message,
final JsResult result) {
@@ -184,79 +195,91 @@ public class InAppWebChromeClient extends WebChromeClient {
getChannel().invokeMethod("onJsConfirm", obj, new MethodChannel.Result() {
@Override
public void success(Object response) {
- Map responseMap = (Map) response;
- String responseMessage = (String) responseMap.get("message");
- String confirmButtonTitle = (String) responseMap.get("confirmButtonTitle");
- String cancelButtonTitle = (String) responseMap.get("cancelButtonTitle");
- boolean handledByClient = (boolean) responseMap.get("handledByClient");
- if (handledByClient) {
- Integer action = (Integer) responseMap.get("action");
- action = action != null ? action : 1;
- switch (action) {
- case 0:
- result.confirm();
- break;
- case 1:
- default:
- result.cancel();
- }
- } else {
- String alertMessage = (responseMessage != null && !responseMessage.isEmpty()) ? responseMessage : message;
- DialogInterface.OnClickListener confirmClickListener = new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- result.confirm();
- dialog.dismiss();
- }
- };
- DialogInterface.OnClickListener cancelClickListener = new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- result.cancel();
- dialog.dismiss();
- }
- };
+ String responseMessage = null;
+ String confirmButtonTitle = null;
+ String cancelButtonTitle = null;
- AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(view.getContext(), R.style.Theme_AppCompat_Dialog_Alert);
- alertDialogBuilder.setMessage(alertMessage);
- if (confirmButtonTitle != null && !confirmButtonTitle.isEmpty()) {
- alertDialogBuilder.setPositiveButton(confirmButtonTitle, confirmClickListener);
- } else {
- alertDialogBuilder.setPositiveButton(android.R.string.ok, confirmClickListener);
- }
- if (cancelButtonTitle != null && !cancelButtonTitle.isEmpty()) {
- alertDialogBuilder.setNegativeButton(cancelButtonTitle, cancelClickListener);
- } else {
- alertDialogBuilder.setNegativeButton(android.R.string.cancel, cancelClickListener);
- }
-
- alertDialogBuilder.setOnCancelListener(new DialogInterface.OnCancelListener() {
- @Override
- public void onCancel(DialogInterface dialog) {
- result.cancel();
- dialog.dismiss();
+ if (response != null) {
+ Map responseMap = (Map) response;
+ responseMessage = (String) responseMap.get("message");
+ confirmButtonTitle = (String) responseMap.get("confirmButtonTitle");
+ cancelButtonTitle = (String) responseMap.get("cancelButtonTitle");
+ Boolean handledByClient = (Boolean) responseMap.get("handledByClient");
+ if (handledByClient != null && handledByClient) {
+ Integer action = (Integer) responseMap.get("action");
+ action = action != null ? action : 1;
+ switch (action) {
+ case 0:
+ result.confirm();
+ break;
+ case 1:
+ default:
+ result.cancel();
}
- });
-
- AlertDialog alertDialog = alertDialogBuilder.create();
- alertDialog.show();
+ return;
+ }
}
+
+ createConfirmDialog(view, message, result, responseMessage, confirmButtonTitle, cancelButtonTitle);
}
@Override
public void error(String s, String s1, Object o) {
Log.e(LOG_TAG, s + ", " + s1);
+ result.cancel();
}
@Override
public void notImplemented() {
-
+ createConfirmDialog(view, message, result, null, null, null);
}
});
return true;
}
+ public void createConfirmDialog(WebView view, String message, final JsResult result, String responseMessage, String confirmButtonTitle, String cancelButtonTitle) {
+ String alertMessage = (responseMessage != null && !responseMessage.isEmpty()) ? responseMessage : message;
+ DialogInterface.OnClickListener confirmClickListener = new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ result.confirm();
+ dialog.dismiss();
+ }
+ };
+ DialogInterface.OnClickListener cancelClickListener = new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ result.cancel();
+ dialog.dismiss();
+ }
+ };
+
+ AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(view.getContext(), R.style.Theme_AppCompat_Dialog_Alert);
+ alertDialogBuilder.setMessage(alertMessage);
+ if (confirmButtonTitle != null && !confirmButtonTitle.isEmpty()) {
+ alertDialogBuilder.setPositiveButton(confirmButtonTitle, confirmClickListener);
+ } else {
+ alertDialogBuilder.setPositiveButton(android.R.string.ok, confirmClickListener);
+ }
+ if (cancelButtonTitle != null && !cancelButtonTitle.isEmpty()) {
+ alertDialogBuilder.setNegativeButton(cancelButtonTitle, cancelClickListener);
+ } else {
+ alertDialogBuilder.setNegativeButton(android.R.string.cancel, cancelClickListener);
+ }
+
+ alertDialogBuilder.setOnCancelListener(new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ result.cancel();
+ dialog.dismiss();
+ }
+ });
+
+ AlertDialog alertDialog = alertDialogBuilder.create();
+ alertDialog.show();
+ }
+
@Override
public boolean onJsPrompt(final WebView view, String url, final String message,
final String defaultValue, final JsPromptResult result) {
@@ -269,99 +292,112 @@ public class InAppWebChromeClient extends WebChromeClient {
getChannel().invokeMethod("onJsPrompt", obj, new MethodChannel.Result() {
@Override
public void success(Object response) {
- Map responseMap = (Map) response;
- String responseMessage = (String) responseMap.get("message");
- String responseDefaultValue = (String) responseMap.get("defaultValue");
- String confirmButtonTitle = (String) responseMap.get("confirmButtonTitle");
- String cancelButtonTitle = (String) responseMap.get("cancelButtonTitle");
- final String value = (String) responseMap.get("value");
- boolean handledByClient = (boolean) responseMap.get("handledByClient");
- if (handledByClient) {
- Integer action = (Integer) responseMap.get("action");
- action = action != null ? action : 1;
- switch (action) {
- case 0:
- if (value != null)
+ String responseMessage = null;
+ String responseDefaultValue = null;
+ String confirmButtonTitle = null;
+ String cancelButtonTitle = null;
+ String value = null;
+
+ if (response != null) {
+ Map responseMap = (Map) response;
+ responseMessage = (String) responseMap.get("message");
+ responseDefaultValue = (String) responseMap.get("defaultValue");
+ confirmButtonTitle = (String) responseMap.get("confirmButtonTitle");
+ cancelButtonTitle = (String) responseMap.get("cancelButtonTitle");
+ value = (String) responseMap.get("value");
+ Boolean handledByClient = (Boolean) responseMap.get("handledByClient");
+ if (handledByClient != null && handledByClient) {
+ Integer action = (Integer) responseMap.get("action");
+ action = action != null ? action : 1;
+ switch (action) {
+ case 0:
result.confirm(value);
- else
- result.confirm();
- break;
- case 1:
- default:
- result.cancel();
- }
- } else {
- FrameLayout layout = new FrameLayout(view.getContext());
-
- final EditText input = new EditText(view.getContext());
- input.setMaxLines(1);
- input.setText((responseDefaultValue != null && !responseDefaultValue.isEmpty()) ? responseDefaultValue : defaultValue);
- LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.MATCH_PARENT,
- LinearLayout.LayoutParams.MATCH_PARENT);
- input.setLayoutParams(lp);
-
- layout.setPaddingRelative(45,15,45,0);
- layout.addView(input);
-
- String alertMessage = (responseMessage != null && !responseMessage.isEmpty()) ? responseMessage : message;
- DialogInterface.OnClickListener confirmClickListener = new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- String text = input.getText().toString();
- result.confirm(value != null ? value : text);
- dialog.dismiss();
+ break;
+ case 1:
+ default:
+ result.cancel();
}
- };
- DialogInterface.OnClickListener cancelClickListener = new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- result.cancel();
- dialog.dismiss();
- }
- };
-
- AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(view.getContext(), R.style.Theme_AppCompat_Dialog_Alert);
- alertDialogBuilder.setMessage(alertMessage);
- if (confirmButtonTitle != null && !confirmButtonTitle.isEmpty()) {
- alertDialogBuilder.setPositiveButton(confirmButtonTitle, confirmClickListener);
- } else {
- alertDialogBuilder.setPositiveButton(android.R.string.ok, confirmClickListener);
+ return;
}
- if (cancelButtonTitle != null && !cancelButtonTitle.isEmpty()) {
- alertDialogBuilder.setNegativeButton(cancelButtonTitle, cancelClickListener);
- } else {
- alertDialogBuilder.setNegativeButton(android.R.string.cancel, cancelClickListener);
- }
-
- alertDialogBuilder.setOnCancelListener(new DialogInterface.OnCancelListener() {
- @Override
- public void onCancel(DialogInterface dialog) {
- result.cancel();
- dialog.dismiss();
- }
- });
-
- AlertDialog alertDialog = alertDialogBuilder.create();
- alertDialog.setView(layout);
- alertDialog.show();
}
+
+ createPromptDialog(view, message, defaultValue, result, responseMessage, responseDefaultValue, value, cancelButtonTitle, confirmButtonTitle);
}
@Override
public void error(String s, String s1, Object o) {
Log.e(LOG_TAG, s + ", " + s1);
+ result.cancel();
}
@Override
public void notImplemented() {
-
+ createPromptDialog(view, message, defaultValue, result, null, null, null, null, null);
}
});
return true;
}
+ public void createPromptDialog(WebView view, String message, String defaultValue, final JsPromptResult result, String responseMessage, String responseDefaultValue, String value, String cancelButtonTitle, String confirmButtonTitle) {
+ FrameLayout layout = new FrameLayout(view.getContext());
+
+ final EditText input = new EditText(view.getContext());
+ input.setMaxLines(1);
+ input.setText((responseDefaultValue != null && !responseDefaultValue.isEmpty()) ? responseDefaultValue : defaultValue);
+ LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.MATCH_PARENT,
+ LinearLayout.LayoutParams.MATCH_PARENT);
+ input.setLayoutParams(lp);
+
+ layout.setPaddingRelative(45,15,45,0);
+ layout.addView(input);
+
+ String alertMessage = (responseMessage != null && !responseMessage.isEmpty()) ? responseMessage : message;
+
+ final String finalValue = value;
+ DialogInterface.OnClickListener confirmClickListener = new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ String text = input.getText().toString();
+ result.confirm(finalValue != null ? finalValue : text);
+ dialog.dismiss();
+ }
+ };
+ DialogInterface.OnClickListener cancelClickListener = new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ result.cancel();
+ dialog.dismiss();
+ }
+ };
+
+ AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(view.getContext(), R.style.Theme_AppCompat_Dialog_Alert);
+ alertDialogBuilder.setMessage(alertMessage);
+ if (confirmButtonTitle != null && !confirmButtonTitle.isEmpty()) {
+ alertDialogBuilder.setPositiveButton(confirmButtonTitle, confirmClickListener);
+ } else {
+ alertDialogBuilder.setPositiveButton(android.R.string.ok, confirmClickListener);
+ }
+ if (cancelButtonTitle != null && !cancelButtonTitle.isEmpty()) {
+ alertDialogBuilder.setNegativeButton(cancelButtonTitle, cancelClickListener);
+ } else {
+ alertDialogBuilder.setNegativeButton(android.R.string.cancel, cancelClickListener);
+ }
+
+ alertDialogBuilder.setOnCancelListener(new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ result.cancel();
+ dialog.dismiss();
+ }
+ });
+
+ AlertDialog alertDialog = alertDialogBuilder.create();
+ alertDialog.setView(layout);
+ alertDialog.show();
+ }
+
@Override
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, android.os.Message resultMsg)
{
diff --git a/example/assets/index.html b/example/assets/index.html
index 69ff2616..93a71e2e 100644
--- a/example/assets/index.html
+++ b/example/assets/index.html
@@ -55,13 +55,14 @@
});
});
$(document).ready(function() {
+ /*
alert("Alert Popup");
console.log(confirm("Press a button!"));
- console.log(prompt("Please enter your name", "Harry Potter"));
-
+ console.log(prompt("Please enter your name", "Lorenzo"));
+ */
console.log("jQuery ready");
-/*
+ /*
if ("geolocation" in navigator) {
console.log("Geolocation API enabled");
navigator.geolocation.getCurrentPosition(function(position) {
@@ -69,7 +70,8 @@
});
} else {
console.log("No geolocation API");
- }*/
+ }
+ */
});