You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2013/01/11 19:25:01 UTC

[1/10] android commit: This is as far as we can get fixing the Camera plugin by recovering state

This is as far as we can get fixing the Camera plugin by recovering state


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

Branch: refs/heads/master
Commit: 5ca233779d11177ec2bef97afa2910d383d6d4a2
Parents: 81f283e
Author: Joe Bowser <bo...@apache.org>
Authored: Thu Nov 8 15:42:28 2012 -0800
Committer: Joe Bowser <bo...@apache.org>
Committed: Thu Nov 8 15:42:28 2012 -0800

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaWebView.java     |   39 ++++++++++++-
 .../org/apache/cordova/CordovaWebViewClient.java   |    1 +
 framework/src/org/apache/cordova/DroidGap.java     |   44 ++++++++++++++-
 .../src/org/apache/cordova/api/PluginManager.java  |    2 +-
 4 files changed, 79 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/5ca23377/framework/src/org/apache/cordova/CordovaWebView.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java
index 4740610..a2b6566 100755
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -28,6 +28,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.cordova.api.CordovaInterface;
+import org.apache.cordova.api.CordovaPlugin;
 import org.apache.cordova.api.LOG;
 import org.apache.cordova.api.PluginManager;
 import org.apache.cordova.api.PluginResult;
@@ -103,6 +104,23 @@ public class CordovaWebView extends WebView {
     /** custom view created by the browser (a video player for example) */
     private View mCustomView;
     private WebChromeClient.CustomViewCallback mCustomViewCallback;
+
+    private ActivityResult mResult = null;
+
+    class ActivityResult {
+        
+        int request;
+        int result;
+        Intent incoming;
+        
+        public ActivityResult(int req, int res, Intent intent) {
+            request = req;
+            result = res;
+            incoming = intent;
+        }
+
+        
+    }
     
     static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
             new FrameLayout.LayoutParams(
@@ -497,8 +515,9 @@ public class CordovaWebView extends WebView {
         if (LOG.isLoggable(LOG.DEBUG) && !url.startsWith("javascript:")) {
             LOG.d(TAG, ">>> loadUrlNow()");
         }
-        if (url.startsWith("file://") || url.indexOf(this.baseUrl) == 0 || url.startsWith("javascript:") || this.isUrlWhiteListed(url)) {
-            super.loadUrl(url);            
+        boolean isDocument = this.baseUrl != null && url.indexOf(this.baseUrl) == 0;
+        if (url.startsWith("file://") || isDocument || url.startsWith("javascript:") || this.isUrlWhiteListed(url)) {
+            super.loadUrl(url);
         }
     }
 
@@ -922,9 +941,8 @@ public class CordovaWebView extends WebView {
     public void handleResume(boolean keepRunning, boolean activityResultKeepRunning)
     {
 
-        // Send resume event to JavaScript
         this.loadUrl("javascript:try{cordova.fireDocumentEvent('resume');}catch(e){console.log('exception firing resume event from native');};");
-
+        
         // Forward to plugins
         if (this.pluginManager != null) {
             this.pluginManager.onResume(keepRunning);
@@ -1060,4 +1078,17 @@ public class CordovaWebView extends WebView {
 	public boolean isCustomViewShowing() {
 	    return mCustomView != null;
 	}
+	
+	public WebBackForwardList restoreState(Bundle savedInstanceState)
+	{
+	    WebBackForwardList myList = super.restoreState(savedInstanceState);
+	    Log.d(TAG, "WebView restoration crew now restoring!");
+	    //Initialize the plugin manager once more
+	    this.pluginManager.init();
+	    return myList;
+	}
+
+    public void storeResult(int requestCode, int resultCode, Intent intent) {
+        mResult = new ActivityResult(requestCode, resultCode, intent);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/5ca23377/framework/src/org/apache/cordova/CordovaWebViewClient.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebViewClient.java b/framework/src/org/apache/cordova/CordovaWebViewClient.java
index b0c318c..63ab325 100755
--- a/framework/src/org/apache/cordova/CordovaWebViewClient.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewClient.java
@@ -295,6 +295,7 @@ public class CordovaWebViewClient extends WebViewClient {
         // not loaded yet then just set a flag so that the onNativeReady can be fired
         // from the JS side when the JS gets to that code.
         if (!url.equals("about:blank")) {
+            LOG.d(TAG, "Trying to fire onNativeReady");
             this.appView.loadUrl("javascript:try{ cordova.require('cordova/channel').onNativeReady.fire();}catch(e){_nativeReady = true;}");
             this.appView.postMessage("onNativeReady", null);
         }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/5ca23377/framework/src/org/apache/cordova/DroidGap.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java
index f504d2e..51c9c59 100755
--- a/framework/src/org/apache/cordova/DroidGap.java
+++ b/framework/src/org/apache/cordova/DroidGap.java
@@ -186,6 +186,17 @@ public class DroidGap extends Activity implements CordovaInterface {
     // when another application (activity) is started.
     protected boolean keepRunning = true;
 
+    private int lastRequestCode;
+
+    private Object responseCode;
+
+    private Intent lastIntent;
+
+    private Object lastResponseCode;
+
+    private String initCallbackClass;
+
+
     /**
     * Sets the authentication token.
     *
@@ -252,11 +263,15 @@ public class DroidGap extends Activity implements CordovaInterface {
     @SuppressWarnings("deprecation")
     @Override
     public void onCreate(Bundle savedInstanceState) {
-        //preferences = new PreferenceSet();
 
         LOG.d(TAG, "DroidGap.onCreate()");
         super.onCreate(savedInstanceState);
 
+        if(savedInstanceState != null)
+        {
+            initCallbackClass = savedInstanceState.getString("callbackClass");
+        }
+        
         if(!this.getBooleanProperty("showTitle", false))
         {
             getWindow().requestFeature(Window.FEATURE_NO_TITLE);
@@ -344,6 +359,7 @@ public class DroidGap extends Activity implements CordovaInterface {
 
         // Clear cancel flag
         this.cancelLoadUrl = false;
+        
     }
 
     /**
@@ -806,9 +822,22 @@ public class DroidGap extends Activity implements CordovaInterface {
      * @param data              An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
      */
     protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
+        Log.d(TAG, "Incoming Result");
         super.onActivityResult(requestCode, resultCode, intent);
         CordovaPlugin callback = this.activityResultCallback;
-        if (callback != null) {
+        if(callback == null)
+        {
+            if(initCallbackClass != null)
+            {
+                this.activityResultCallback = appView.pluginManager.getPlugin(initCallbackClass);
+                callback = activityResultCallback;
+                Log.d(TAG, "We have a callback to send this result to");
+                callback.onActivityResult(requestCode, resultCode, intent);
+            }
+        }
+        else
+        {
+            Log.d(TAG, "We have a callback to send this result to");
             callback.onActivityResult(requestCode, resultCode, intent);
         }
     }
@@ -1091,4 +1120,15 @@ public class DroidGap extends Activity implements CordovaInterface {
     public ExecutorService getThreadPool() {
         return threadPool;
     }
+    
+    protected void onSaveInstanceState(Bundle outState)
+    {
+        super.onSaveInstanceState(outState);
+        if(this.activityResultCallback != null)
+        {
+            String cClass = this.activityResultCallback.getClass().getName();
+            outState.putString("callbackClass", cClass);
+        }
+    }
 }
+    

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/5ca23377/framework/src/org/apache/cordova/api/PluginManager.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/PluginManager.java b/framework/src/org/apache/cordova/api/PluginManager.java
index cafa79d..98bb157 100755
--- a/framework/src/org/apache/cordova/api/PluginManager.java
+++ b/framework/src/org/apache/cordova/api/PluginManager.java
@@ -248,7 +248,7 @@ public class PluginManager {
      * @param service       The name of the service.
      * @return              CordovaPlugin or null
      */
-    private CordovaPlugin getPlugin(String service) {
+    public CordovaPlugin getPlugin(String service) {
         PluginEntry entry = this.entries.get(service);
         if (entry == null) {
             return null;