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/07/08 20:46:31 UTC

[6/9] android commit: Provide CordovaPlugin with CordovaPreferences. Add new Plugin.initialize()

Provide CordovaPlugin with CordovaPreferences. Add new Plugin.initialize()

This adds CordovaPlugin.initialize() (no args) and deprecates
CordovaPlugin.initialize(app, webView). This will allow us to refactor
more easily by using the package-private privateInitialize() to set
fields.


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

Branch: refs/heads/4.0.x
Commit: 04ccb06e3f6297f3956d847507423c66006eae08
Parents: d31ee20
Author: Andrew Grieve <ag...@chromium.org>
Authored: Tue Jul 8 14:26:21 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Jul 8 14:26:21 2014 -0400

----------------------------------------------------------------------
 framework/src/org/apache/cordova/App.java       |  8 ++------
 .../src/org/apache/cordova/CordovaActivity.java |  3 ++-
 .../src/org/apache/cordova/CordovaPlugin.java   | 21 +++++++++++++++-----
 .../src/org/apache/cordova/CordovaWebView.java  |  8 +++++++-
 .../src/org/apache/cordova/PluginEntry.java     |  2 +-
 5 files changed, 28 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/04ccb06e/framework/src/org/apache/cordova/App.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/App.java b/framework/src/org/apache/cordova/App.java
index 2112519..c488f10 100755
--- a/framework/src/org/apache/cordova/App.java
+++ b/framework/src/org/apache/cordova/App.java
@@ -47,16 +47,12 @@ public class App extends CordovaPlugin {
     /**
      * Sets the context of the Command. This can then be used to do things like
      * get file paths associated with the Activity.
-     *
-     * @param cordova The context of the main Activity.
-     * @param webView The CordovaWebView Cordova is running in.
      */
-    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
-        super.initialize(cordova, webView);
+    @Override
+    public void initialize() {
         this.initTelephonyReceiver();
     }
 
-
     /**
      * Executes the request and returns PluginResult.
      *

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/04ccb06e/framework/src/org/apache/cordova/CordovaActivity.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java
index 0d07957..371172c 100755
--- a/framework/src/org/apache/cordova/CordovaActivity.java
+++ b/framework/src/org/apache/cordova/CordovaActivity.java
@@ -227,7 +227,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         }
 
         appView = makeWebView();
-        appView.init(this, makeWebViewClient(appView), makeChromeClient(appView), pluginEntries, whitelist);
+        appView.init(this, makeWebViewClient(appView), makeChromeClient(appView), pluginEntries, whitelist, preferences);
 
         // TODO: Have the views set this themselves.
         if (preferences.getBoolean("DisallowOverscroll", false)) {
@@ -240,6 +240,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         setVolumeControlStream(AudioManager.STREAM_MUSIC);
     }
 
+    @SuppressWarnings("deprecation")
     protected void loadConfig() {
         ConfigXmlParser parser = new ConfigXmlParser();
         parser.parse(this);

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/04ccb06e/framework/src/org/apache/cordova/CordovaPlugin.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaPlugin.java b/framework/src/org/apache/cordova/CordovaPlugin.java
index 8111e7b..eff66c8 100644
--- a/framework/src/org/apache/cordova/CordovaPlugin.java
+++ b/framework/src/org/apache/cordova/CordovaPlugin.java
@@ -32,21 +32,32 @@ import android.net.Uri;
  * Plugins must extend this class and override one of the execute methods.
  */
 public class CordovaPlugin {
+    @Deprecated // This is never set.
     public String id;
     public CordovaWebView webView;					// WebView object
     public CordovaInterface cordova;
+    protected CordovaPreferences preferences;
 
-    /**
-     * @param cordova The context of the main Activity.
-     * @param webView The associated CordovaWebView.
-     */
-    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
+    void privateInitialize(CordovaInterface cordova, CordovaWebView webView, CordovaPreferences preferences) {
         assert this.cordova == null;
         this.cordova = cordova;
         this.webView = webView;
+        this.preferences = preferences;
+        initialize(cordova, webView);
+        initialize();
+    }
+
+    @Deprecated // Override initialize() instead.
+    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
     }
 
     /**
+     * This is where you can do start-up logic with protected fields set.
+     */
+    protected void initialize() {
+    }
+    
+    /**
      * Executes the request.
      *
      * This method is called from the WebView thread. To do a non-trivial amount of work, use:

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/04ccb06e/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 fb442cc..7c1974c 100755
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -92,6 +92,7 @@ public class CordovaWebView extends WebView {
     private Whitelist whitelist;
     // The URL passed to loadUrl(), not necessarily the URL of the current page.
     String loadedUrl;
+    private CordovaPreferences preferences;
 
     class ActivityResult {
         
@@ -135,7 +136,7 @@ public class CordovaWebView extends WebView {
 
     // Use two-phase init so that the control will work with XML layouts.
     public void init(CordovaInterface cordova, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient,
-            List<PluginEntry> pluginEntries, Whitelist whitelist) {
+            List<PluginEntry> pluginEntries, Whitelist whitelist, CordovaPreferences preferences) {
         if (this.cordova != null) {
             throw new IllegalStateException();
         }
@@ -143,6 +144,7 @@ public class CordovaWebView extends WebView {
         this.viewClient = webViewClient;
         this.chromeClient = webChromeClient;
         this.whitelist = whitelist;
+        this.preferences = preferences;
         super.setWebChromeClient(webChromeClient);
         super.setWebViewClient(webViewClient);
 
@@ -903,4 +905,8 @@ public class CordovaWebView extends WebView {
     public CordovaResourceApi getResourceApi() {
         return resourceApi;
     }
+
+    public CordovaPreferences getPreferences() {
+        return preferences;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/04ccb06e/framework/src/org/apache/cordova/PluginEntry.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/PluginEntry.java b/framework/src/org/apache/cordova/PluginEntry.java
index c54f6cb..e94cf1c 100755
--- a/framework/src/org/apache/cordova/PluginEntry.java
+++ b/framework/src/org/apache/cordova/PluginEntry.java
@@ -98,7 +98,7 @@ public class PluginEntry {
             Class<?> c = getClassByName(this.pluginClass);
             if (isCordovaPlugin(c)) {
                 this.plugin = (CordovaPlugin) c.newInstance();
-                this.plugin.initialize(ctx, webView);
+                this.plugin.privateInitialize(ctx, webView, webView.getPreferences());
                 return plugin;
             }
         } catch (Exception e) {