You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/03/07 02:33:10 UTC
[5/7] git commit: fix for CB-5534
fix for CB-5534
Signed-off-by: Joe Bowser <bo...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/commit/6f373f7e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/tree/6f373f7e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/diff/6f373f7e
Branch: refs/heads/master
Commit: 6f373f7ed9993b81f5b735e3ee347e516585a916
Parents: 300f1e7
Author: Oliver Moran <ol...@gmail.com>
Authored: Fri Feb 28 19:58:14 2014 +0000
Committer: Joe Bowser <bo...@apache.org>
Committed: Fri Feb 28 14:04:25 2014 -0800
----------------------------------------------------------------------
src/android/InAppBrowser.java | 29 ++++++++++-------
src/android/InAppBrowserDialog.java | 54 ++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/6f373f7e/src/android/InAppBrowser.java
----------------------------------------------------------------------
diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java
index 16ecd70..796036f 100644
--- a/src/android/InAppBrowser.java
+++ b/src/android/InAppBrowser.java
@@ -19,9 +19,8 @@
package org.apache.cordova.inappbrowser;
import android.annotation.SuppressLint;
-import android.app.Dialog;
+import org.apache.cordova.inappbrowser.InAppBrowserDialog;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -80,7 +79,7 @@ public class InAppBrowser extends CordovaPlugin {
private static final String CLEAR_ALL_CACHE = "clearcache";
private static final String CLEAR_SESSION_CACHE = "clearsessioncache";
- private Dialog dialog;
+ private InAppBrowserDialog dialog;
private WebView inAppWebView;
private EditText edittext;
private CallbackContext callbackContext;
@@ -337,12 +336,21 @@ public class InAppBrowser extends CordovaPlugin {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
- childView.loadUrl("about:blank");
+ childView.setWebViewClient(new WebViewClient() {
+ // NB: wait for about:blank before dismissing
+ public void onPageFinished(WebView view, String url) {
if (dialog != null) {
dialog.dismiss();
}
}
});
+ // NB: From SDK 19: "If you call methods on WebView from any thread
+ // other than your app's UI thread, it can cause unexpected results."
+ // http://developer.android.com/guide/webapps/migrating.html#Threads
+ childView.loadUrl("about:blank");
+ }
+ });
+
try {
JSONObject obj = new JSONObject();
obj.put("type", EXIT_EVENT);
@@ -350,7 +358,6 @@ public class InAppBrowser extends CordovaPlugin {
} catch (JSONException ex) {
Log.d(LOG_TAG, "Should never happen");
}
-
}
/**
@@ -398,6 +405,10 @@ public class InAppBrowser extends CordovaPlugin {
return this.showLocationBar;
}
+ private InAppBrowser getInAppBrowser(){
+ return this;
+ }
+
/**
* Display a new browser with the specified URL.
*
@@ -448,15 +459,11 @@ public class InAppBrowser extends CordovaPlugin {
public void run() {
// Let's create the main dialog
- dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
+ dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(true);
- dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
- public void onDismiss(DialogInterface dialog) {
- closeDialog();
- }
- });
+ dialog.setInAppBroswer(getInAppBrowser());
// Main container layout
LinearLayout main = new LinearLayout(cordova.getActivity());
http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/6f373f7e/src/android/InAppBrowserDialog.java
----------------------------------------------------------------------
diff --git a/src/android/InAppBrowserDialog.java b/src/android/InAppBrowserDialog.java
new file mode 100644
index 0000000..124e211
--- /dev/null
+++ b/src/android/InAppBrowserDialog.java
@@ -0,0 +1,54 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+package org.apache.cordova.inappbrowser;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.Context;
+import android.util.Log;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Created by Oliver on 22/11/2013.
+ */
+public class InAppBrowserDialog extends Dialog {
+ Context context;
+ InAppBrowser inAppBrowser = null;
+
+ public InAppBrowserDialog(Context context, int theme) {
+ super(context, theme);
+ this.context = context;
+ }
+
+ public void setInAppBroswer(InAppBrowser browser) {
+ this.inAppBrowser = browser;
+ }
+
+ public void onBackPressed () {
+ if (this.inAppBrowser == null) {
+ this.dismiss();
+ } else {
+ // better to go through the in inAppBrowser
+ // because it does a clean up
+ this.inAppBrowser.closeDialog();
+ }
+ }
+}