mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
Moving init code into the WebView
This commit is contained in:
parent
f3c29840a7
commit
59ff94fefb
@ -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<String, AuthenticationToken> authenticationTokens = new Hashtable<String, AuthenticationToken>();
|
||||
|
||||
private Context mCtx;
|
||||
/** The whitelist **/
|
||||
private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
|
||||
private HashMap<String, Boolean> whiteListCache = new HashMap<String,Boolean>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user