You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by na...@apache.org on 2014/10/09 22:22:47 UTC

[15/19] git commit: CB-7674 move preference activation back into onCreate()

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.

Conflicts:

	bin/templates/project/Activity.java


Project: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/commit/0585fd5f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/tree/0585fd5f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/diff/0585fd5f

Branch: refs/heads/master
Commit: 0585fd5f32cb010391904c3c0d1eeb52d00dd584
Parents: 40a3abb
Author: Marcel Kinard <cm...@gmail.com>
Authored: Tue Sep 30 18:37:10 2014 -0400
Committer: Prabhjot Singh <pr...@amazon.com>
Committed: Mon Oct 6 18:56:51 2014 +0530

----------------------------------------------------------------------
 bin/templates/project/Activity.java             |  3 --
 .../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, 36 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/0585fd5f/bin/templates/project/Activity.java
----------------------------------------------------------------------
diff --git a/bin/templates/project/Activity.java b/bin/templates/project/Activity.java
index ff04622..ff2c933 100644
--- a/bin/templates/project/Activity.java
+++ b/bin/templates/project/Activity.java
@@ -37,9 +37,6 @@ public class __ACTIVITY__ extends CordovaActivity
         if (this.appView != null) {
             // Set by <content src="index.html" /> in config.xml
             loadUrl(launchUrl);
-
         }
-       
-
     }
 }

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/0585fd5f/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 f0b6f7b..57e2e46 100755
--- a/framework/src/org/apache/cordova/CordovaActivity.java
+++ b/framework/src/org/apache/cordova/CordovaActivity.java
@@ -52,6 +52,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 com.amazon.android.webkit.AmazonValueCallback;
@@ -77,6 +78,7 @@ import android.widget.LinearLayout;
  *       &#64;Override
  *       public void onCreate(Bundle savedInstanceState) {
  *         super.onCreate(savedInstanceState);
+ *         super.init();
  *         // Load your application
  *         loadUrl(launchUrl);
  *       }
@@ -214,6 +216,27 @@ 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);
 
         factory = buildAmazonWebkitFactory();
@@ -222,8 +245,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         {
             initCallbackClass = savedInstanceState.getString("callbackClass");
         }
-        
-        loadConfig();
     }
 
     @SuppressWarnings("deprecation")
@@ -243,7 +264,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();
@@ -261,6 +284,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);
 
@@ -393,24 +424,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-amazon-fireos/blob/0585fd5f/test/res/xml/config.xml
----------------------------------------------------------------------
diff --git a/test/res/xml/config.xml b/test/res/xml/config.xml
index 60489a7..baf8ed0 100644
--- a/test/res/xml/config.xml
+++ b/test/res/xml/config.xml
@@ -33,6 +33,7 @@
     <log level="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-amazon-fireos/blob/0585fd5f/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");


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org