Moving init code into the WebView

This commit is contained in:
Joe Bowser 2012-03-27 11:28:55 -07:00
parent f3c29840a7
commit 59ff94fefb
2 changed files with 39 additions and 26 deletions

View File

@ -14,7 +14,9 @@ import org.xmlpull.v1.XmlPullParserException;
import android.content.Context; import android.content.Context;
import android.content.res.XmlResourceParser; import android.content.res.XmlResourceParser;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebSettings.LayoutAlgorithm;
public class CordovaWebView extends WebView { public class CordovaWebView extends WebView {
@ -22,26 +24,61 @@ public class CordovaWebView extends WebView {
/** The authorization tokens. */ /** The authorization tokens. */
private Hashtable<String, AuthenticationToken> authenticationTokens = new Hashtable<String, AuthenticationToken>(); private Hashtable<String, AuthenticationToken> authenticationTokens = new Hashtable<String, AuthenticationToken>();
private Context mCtx;
/** The whitelist **/ /** The whitelist **/
private ArrayList<Pattern> whiteList = new ArrayList<Pattern>(); private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
private HashMap<String, Boolean> whiteListCache = new HashMap<String,Boolean>(); private HashMap<String, Boolean> whiteListCache = new HashMap<String,Boolean>();
public CordovaWebView(Context context) { public CordovaWebView(Context context) {
super(context); super(context);
mCtx = context;
setup();
} }
public CordovaWebView(Context context, AttributeSet attrs) { public CordovaWebView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mCtx = context;
setup();
} }
public CordovaWebView(Context context, AttributeSet attrs, int defStyle) { public CordovaWebView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
mCtx = context;
setup();
} }
public CordovaWebView(Context context, AttributeSet attrs, int defStyle, public CordovaWebView(Context context, AttributeSet attrs, int defStyle,
boolean privateBrowsing) { boolean privateBrowsing) {
super(context, attrs, defStyle, 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);
} }
/** /**

View File

@ -288,30 +288,6 @@ public class DroidGap extends Activity implements CordovaInterface {
this.appView.setWebChromeClient(webChromeClient); this.appView.setWebChromeClient(webChromeClient);
this.setWebViewClient(this.appView, webViewClient); 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 // Add web view but make it invisible while loading URL
this.appView.setVisibility(View.INVISIBLE); this.appView.setVisibility(View.INVISIBLE);
root.addView(this.appView); root.addView(this.appView);