From 59ff94fefb912bf078ece0561017c3e341995bc4 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Tue, 27 Mar 2012 11:28:55 -0700 Subject: [PATCH] Moving init code into the WebView --- .../org/apache/cordova/CordovaWebView.java | 39 ++++++++++++++++++- .../src/org/apache/cordova/DroidGap.java | 26 +------------ 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index b24fc2c9..c55877f1 100644 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -14,7 +14,9 @@ import org.xmlpull.v1.XmlPullParserException; import android.content.Context; import android.content.res.XmlResourceParser; import android.util.AttributeSet; +import android.webkit.WebSettings; import android.webkit.WebView; +import android.webkit.WebSettings.LayoutAlgorithm; public class CordovaWebView extends WebView { @@ -22,26 +24,61 @@ public class CordovaWebView extends WebView { /** The authorization tokens. */ private Hashtable authenticationTokens = new Hashtable(); - + private Context mCtx; /** The whitelist **/ private ArrayList whiteList = new ArrayList(); private HashMap whiteListCache = new HashMap(); public CordovaWebView(Context context) { super(context); + mCtx = context; + setup(); } public CordovaWebView(Context context, AttributeSet attrs) { super(context, attrs); + mCtx = context; + setup(); } public CordovaWebView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + mCtx = context; + setup(); } public CordovaWebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) { super(context, attrs, defStyle, privateBrowsing); + mCtx = context; + setup(); + } + + private void setup() + { + this.setInitialScale(0); + this.setVerticalScrollBarEnabled(false); + this.requestFocusFromTouch(); + + // Enable JavaScript + WebSettings settings = this.getSettings(); + settings.setJavaScriptEnabled(true); + settings.setJavaScriptCanOpenWindowsAutomatically(true); + settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); + + //Set the nav dump for HTC + settings.setNavDump(true); + + // Enable database + settings.setDatabaseEnabled(true); + String databasePath = mCtx.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); + settings.setDatabasePath(databasePath); + + // Enable DOM storage + settings.setDomStorageEnabled(true); + + // Enable built-in geolocation + settings.setGeolocationEnabled(true); } /** diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java index 07eb837b..f5864196 100755 --- a/framework/src/org/apache/cordova/DroidGap.java +++ b/framework/src/org/apache/cordova/DroidGap.java @@ -288,30 +288,6 @@ public class DroidGap extends Activity implements CordovaInterface { this.appView.setWebChromeClient(webChromeClient); this.setWebViewClient(this.appView, webViewClient); - this.appView.setInitialScale(0); - this.appView.setVerticalScrollBarEnabled(false); - this.appView.requestFocusFromTouch(); - - // Enable JavaScript - WebSettings settings = this.appView.getSettings(); - settings.setJavaScriptEnabled(true); - settings.setJavaScriptCanOpenWindowsAutomatically(true); - settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); - - //Set the nav dump for HTC - settings.setNavDump(true); - - // Enable database - settings.setDatabaseEnabled(true); - String databasePath = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); - settings.setDatabasePath(databasePath); - - // Enable DOM storage - settings.setDomStorageEnabled(true); - - // Enable built-in geolocation - settings.setGeolocationEnabled(true); - // Add web view but make it invisible while loading URL this.appView.setVisibility(View.INVISIBLE); root.addView(this.appView); @@ -321,7 +297,7 @@ public class DroidGap extends Activity implements CordovaInterface { this.cancelLoadUrl = false; // Create plugin manager - this.pluginManager = new PluginManager(this.appView, this); + this.pluginManager = new PluginManager(this.appView, this); } /**