cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marc...@apache.org
Subject android commit: CB-7674 move preference activation back into onCreate()
Date Tue, 30 Sep 2014 23:40:09 GMT
Repository: cordova-android
Updated Branches:
  refs/heads/master ce7d6d69d -> c255a8494


CB-7674 move preference activation back into onCreate()

The preference creation actually needs to be before
super.onCreate(savedInstance) in order to avoid the exception
"requestFeature() must be called before adding content". Also ran into an
issue in the native tests "Whitelist" and "User WebView/Client/Chrome" where
it would throw an exception that the CordovaWebView appView already had
a parent and needed to be removed from that parent before the invocation
to root.addView(appView). So I conditionally remove the wrong parent.
Also made a change to the native tests so the menus test would work.
I also put super.init() back into the template, though invoking it is optional
as loadUrl will call it automatically if needed.


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

Branch: refs/heads/master
Commit: c255a849411826e98d4cbc9b4c3211cb23e8d6b8
Parents: ce7d6d6
Author: Marcel Kinard <cmarcelk@gmail.com>
Authored: Tue Sep 30 18:37:10 2014 -0400
Committer: Marcel Kinard <cmarcelk@gmail.com>
Committed: Tue Sep 30 19:38:34 2014 -0400

----------------------------------------------------------------------
 bin/templates/project/Activity.java             |  1 +
 .../src/org/apache/cordova/CordovaActivity.java | 55 ++++++++++++--------
 test/res/xml/config.xml                         |  1 +
 test/src/org/apache/cordova/test/menus.java     |  3 +-
 4 files changed, 37 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/c255a849/bin/templates/project/Activity.java
----------------------------------------------------------------------
diff --git a/bin/templates/project/Activity.java b/bin/templates/project/Activity.java
index 1bd9e1c..5539519 100644
--- a/bin/templates/project/Activity.java
+++ b/bin/templates/project/Activity.java
@@ -28,6 +28,7 @@ public class __ACTIVITY__ extends CordovaActivity
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
+        super.init();
         // Set by <content src="index.html" /> in config.xml
         loadUrl(launchUrl);
     }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/c255a849/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 bf1fd6a..3c12a97 100755
--- a/framework/src/org/apache/cordova/CordovaActivity.java
+++ b/framework/src/org/apache/cordova/CordovaActivity.java
@@ -49,6 +49,7 @@ import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.ViewParent;
 import android.view.Window;
 import android.view.WindowManager;
 import android.webkit.ValueCallback;
@@ -72,6 +73,7 @@ import android.widget.LinearLayout;
  *       &#64;Override
  *       public void onCreate(Bundle savedInstanceState) {
  *         super.onCreate(savedInstanceState);
+ *         super.init();
  *         // Load your application
  *         loadUrl(launchUrl);
  *       }
@@ -200,14 +202,33 @@ public class CordovaActivity extends Activity implements CordovaInterface
{
     public void onCreate(Bundle savedInstanceState) {
         LOG.i(TAG, "Apache Cordova native platform version " + CordovaWebView.CORDOVA_VERSION
+ " is starting");
         LOG.d(TAG, "CordovaActivity.onCreate()");
+
+        // need to activate preferences before super.onCreate to avoid "requestFeature()
must be called before adding content" exception
+        loadConfig();
+        if(!preferences.getBoolean("ShowTitle", false))
+        {
+            getWindow().requestFeature(Window.FEATURE_NO_TITLE);
+        }
+        
+        if(preferences.getBoolean("SetFullscreen", false))
+        {
+            Log.d(TAG, "The SetFullscreen configuration is deprecated in favor of Fullscreen,
and will be removed in a future version.");
+            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
+                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
+        } else if (preferences.getBoolean("Fullscreen", false)) {
+            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
+                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
+        } else {
+            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
+                    WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
+        }
+
         super.onCreate(savedInstanceState);
 
         if(savedInstanceState != null)
         {
             initCallbackClass = savedInstanceState.getString("callbackClass");
         }
-        
-        loadConfig();
     }
 
     @SuppressWarnings("deprecation")
@@ -227,7 +248,9 @@ public class CordovaActivity extends Activity implements CordovaInterface
{
     @SuppressWarnings("deprecation")
     protected void createViews() {
         // This builds the view.  We could probably get away with NOT having a LinearLayout,
but I like having a bucket!
-        // This builds the view.  We could probably get away with NOT having a LinearLayout,
but I like having a bucket!
+
+        LOG.d(TAG, "CordovaActivity.createViews()");
+
         Display display = getWindowManager().getDefaultDisplay();
         int width = display.getWidth();
         int height = display.getHeight();
@@ -245,6 +268,14 @@ public class CordovaActivity extends Activity implements CordovaInterface
{
 
         // Add web view but make it invisible while loading URL
         appView.setVisibility(View.INVISIBLE);
+        
+        // need to remove appView from any existing parent before invoking root.addView(appView)
+        ViewParent parent = appView.getParent();
+        if ((parent != null) && (parent != root)) {
+            LOG.d(TAG, "removing appView from existing parent");
+            ViewGroup parentGroup = (ViewGroup) parent;
+            parentGroup.removeView(appView);
+        }
         root.addView((View) appView);
         setContentView(root);
 
@@ -302,24 +333,6 @@ public class CordovaActivity extends Activity implements CordovaInterface
{
     public void init(CordovaWebView webView, CordovaWebViewClient webViewClient, CordovaChromeClient
webChromeClient) {
         LOG.d(TAG, "CordovaActivity.init()");
 
-        if(!preferences.getBoolean("ShowTitle", false))
-        {
-            getWindow().requestFeature(Window.FEATURE_NO_TITLE);
-        }
-
-        if(preferences.getBoolean("SetFullscreen", false))
-        {
-            Log.d(TAG, "The SetFullscreen configuration is deprecated in favor of Fullscreen,
and will be removed in a future version.");
-            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
-                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
-        } else if (preferences.getBoolean("Fullscreen", false)) {
-            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
-                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
-        } else {
-            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
-                    WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
-        }
-
         appView = webView != null ? webView : makeWebView();
         if (appView.pluginManager == null) {
             appView.init(this, webViewClient != null ? webViewClient : makeWebViewClient(appView),

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/c255a849/test/res/xml/config.xml
----------------------------------------------------------------------
diff --git a/test/res/xml/config.xml b/test/res/xml/config.xml
index 148bad5..4370357 100644
--- a/test/res/xml/config.xml
+++ b/test/res/xml/config.xml
@@ -34,6 +34,7 @@
     <preference name="loglevel" value="DEBUG" />
     <preference name="useBrowserHistory" value="true" />
     <preference name="exit-on-suspend" value="false" />
+    <preference name="showTitle" value="true" />
     <feature name="Activity">
         <param name="android-package" value="org.apache.cordova.test.ActivityPlugin" />
     </feature>

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/c255a849/test/src/org/apache/cordova/test/menus.java
----------------------------------------------------------------------
diff --git a/test/src/org/apache/cordova/test/menus.java b/test/src/org/apache/cordova/test/menus.java
index 6d0d3f1..9bde03e 100755
--- a/test/src/org/apache/cordova/test/menus.java
+++ b/test/src/org/apache/cordova/test/menus.java
@@ -32,8 +32,7 @@ public class menus extends CordovaActivity {
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        // need the title to be shown for the options menu to be visible
-        preferences.set("showTitle", true);
+        // need the title to be shown (config.xml) for the options menu to be visible
         super.init();
         super.registerForContextMenu(super.appView);
         super.loadUrl("file:///android_asset/www/menus/index.html");


Mime
View raw message