You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ma...@apache.org on 2012/11/28 21:44:21 UTC

android commit: Start adding events to InAppBrowser

Updated Branches:
  refs/heads/master 48f58110f -> a42dc0875


Start adding events to InAppBrowser


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/a42dc087
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/a42dc087
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/a42dc087

Branch: refs/heads/master
Commit: a42dc087565efa3e7f414e57693d145297135e3e
Parents: 48f5811
Author: Simon MacDonald <si...@gmail.com>
Authored: Wed Nov 28 15:44:01 2012 -0500
Committer: Simon MacDonald <si...@gmail.com>
Committed: Wed Nov 28 15:44:01 2012 -0500

----------------------------------------------------------------------
 framework/src/org/apache/cordova/InAppBrowser.java |   24 +++++++--------
 1 files changed, 11 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/a42dc087/framework/src/org/apache/cordova/InAppBrowser.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/InAppBrowser.java b/framework/src/org/apache/cordova/InAppBrowser.java
index 9b747d3..338d344 100644
--- a/framework/src/org/apache/cordova/InAppBrowser.java
+++ b/framework/src/org/apache/cordova/InAppBrowser.java
@@ -209,6 +209,7 @@ public class InAppBrowser extends CordovaPlugin {
      */
     private void closeDialog() {
         // TODO: fire 'exit' event 
+        this.webView.sendJavascript("cordova.fireWindowEvent('exit');");
         if (dialog != null) {
             dialog.dismiss();
         }
@@ -271,6 +272,8 @@ public class InAppBrowser extends CordovaPlugin {
         if (features != null) {
             showLocationBar = features.get(LOCATION).booleanValue();
         }
+        
+        final CordovaWebView thatWebView = this.webView;
 
         // Create dialog in new thread
         Runnable runnable = new Runnable() {
@@ -394,7 +397,7 @@ public class InAppBrowser extends CordovaPlugin {
                 inAppWebView = new WebView(cordova.getActivity());
                 inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
                 inAppWebView.setWebChromeClient(new WebChromeClient());
-                WebViewClient client = new InAppBrowserClient(edittext);
+                WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
                 inAppWebView.setWebViewClient(client);
                 WebSettings settings = inAppWebView.getSettings();
                 settings.setJavaScriptEnabled(true);
@@ -464,6 +467,7 @@ public class InAppBrowser extends CordovaPlugin {
      */
     public class InAppBrowserClient extends WebViewClient {
         EditText edittext;
+        CordovaWebView webView;
 
         /**
          * Constructor.
@@ -471,7 +475,8 @@ public class InAppBrowser extends CordovaPlugin {
          * @param mContext
          * @param edittext
          */
-        public InAppBrowserClient(EditText mEditText) {
+        public InAppBrowserClient(CordovaWebView webView, EditText mEditText) {
+            this.webView = webView;
             this.edittext = mEditText;
         }
 
@@ -495,21 +500,14 @@ public class InAppBrowser extends CordovaPlugin {
                 edittext.setText(newloc);
             }
 
-            // TODO: Fire 'loadstart' event
-            try {
-                JSONObject obj = new JSONObject();
-                obj.put("type", LOCATION_CHANGED_EVENT);
-                obj.put("location", url);
-
-                sendUpdate(obj, true);
-            } catch (JSONException e) {
-                Log.d("InAppBrowser", "This should never happen");
-            }
+            // TODO: Fire 'loadstart' event only on the InAppBrowser object
+            this.webView.sendJavascript("cordova.fireWindowEvent('loadstart', '" + url + "');");
         }
         
         public void onPageFinished(WebView view, String url) {
             super.onPageFinished(view, url);
-            // TODO: Fire 'loadstop' event
+            // TODO: Fire 'loadstop' event only on the InAppBrowser object
+            this.webView.sendJavascript("cordova.fireWindowEvent('loadstop', '" + url + "');");
         }
     }
 }
\ No newline at end of file