下面列出了android.webkit.WebSettings#setDatabasePath ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressLint({"SetJavaScriptEnabled"})
private void initViews() {
this.mWebView.setVerticalScrollBarEnabled(false);
this.mWebView.setHorizontalScrollBarEnabled(false);
this.mWebView.setWebViewClient(new FbWebViewClient());
this.mWebView.setWebChromeClient(this.mChromeClient);
this.mWebView.clearFormData();
WebSettings settings = this.mWebView.getSettings();
settings.setSavePassword(false);
settings.setSaveFormData(false);
settings.setCacheMode(-1);
settings.setNeedInitialFocus(false);
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
settings.setRenderPriority(RenderPriority.HIGH);
settings.setJavaScriptEnabled(true);
if (!(this.mWeakContext == null || this.mWeakContext.get() == null)) {
settings.setDatabaseEnabled(true);
settings.setDatabasePath(((Context) this.mWeakContext.get()).getApplicationContext().getDir("databases", 0).getPath());
}
settings.setDomStorageEnabled(true);
this.jsBridge.a(new JsListener(), "sdk_js_if");
this.mWebView.clearView();
this.mWebView.loadUrl(this.mUrl);
this.mWebView.getSettings().setSavePassword(false);
}
@SuppressLint({"SetJavaScriptEnabled"})
private void b() {
this.i.setVerticalScrollBarEnabled(false);
this.i.setHorizontalScrollBarEnabled(false);
this.i.setWebViewClient(new FbWebViewClient());
this.i.setWebChromeClient(this.mChromeClient);
this.i.clearFormData();
WebSettings settings = this.i.getSettings();
settings.setSavePassword(false);
settings.setSaveFormData(false);
settings.setCacheMode(-1);
settings.setNeedInitialFocus(false);
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
settings.setRenderPriority(RenderPriority.HIGH);
settings.setJavaScriptEnabled(true);
if (!(this.c == null || this.c.get() == null)) {
settings.setDatabaseEnabled(true);
settings.setDatabasePath(((Context) this.c.get()).getApplicationContext().getDir("databases", 0).getPath());
}
settings.setDomStorageEnabled(true);
this.jsBridge.a(new JsListener(), "sdk_js_if");
this.i.loadUrl(this.e);
this.i.setLayoutParams(a);
this.i.setVisibility(4);
this.i.getSettings().setSavePassword(false);
}
public void initWebView(String url) {
if (mListener == null) {
throw new RuntimeException("must set listener");
}
if (mContext.get() == null) {
throw new RuntimeException("mContext not find");
}
mUrl = url;
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUserAgentString(ua);
webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); //设置 缓存模式
// 开启 DOM storage API 功能
webSettings.setDomStorageEnabled(true);
//开启 database storage API 功能
webSettings.setDatabaseEnabled(true);
String cacheDirPath = mContext.get().getFilesDir().getAbsolutePath() + APP_CACAHE_DIRNAME;
// String cacheDirPath = getCacheDir().getAbsolutePath()+Constant.APP_DB_DIRNAME;
Log.e("WebView", "cacheDirPath=" + cacheDirPath);
//设置数据库缓存路径
webSettings.setDatabasePath(cacheDirPath);
//设置 Application Caches 缓存目录
webSettings.setAppCachePath(cacheDirPath);
//开启 Application Caches 功能
webSettings.setAppCacheEnabled(true);
Log.e("WebView", "H5--->" + url);
mWebView.setWebViewClient(this);
mCookieManager = CookieManager.getInstance();
mCookieManager.removeAllCookies(null);
mWebView.loadUrl(mUrl);
}
private void init(Context context) {
mPlayer = new WebPlayer(this);
setBackgroundColor(Color.BLACK);
enableJavascript();
WebSettings webSettings = getSettings();
webSettings.setAllowContentAccess(true);
webSettings.setAllowFileAccess(true);
webSettings.setAppCacheEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setDatabasePath(context.getDir("database", Context.MODE_PRIVATE).getPath());
webSettings.setDomStorageEnabled(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setSupportMultipleWindows(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
webSettings.setMediaPlaybackRequiresUserGesture(false);
}
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
}
setWebChromeClient(new ChromeClient());
setWebViewClient(new ViewClient());
}
private void d()
{
n.setVerticalScrollBarEnabled(false);
n.setHorizontalScrollBarEnabled(false);
n.setWebViewClient(new e(this, null));
n.setWebChromeClient(mChromeClient);
n.clearFormData();
WebSettings websettings = n.getSettings();
websettings.setSavePassword(false);
websettings.setSaveFormData(false);
websettings.setCacheMode(-1);
websettings.setNeedInitialFocus(false);
websettings.setBuiltInZoomControls(true);
websettings.setSupportZoom(true);
websettings.setRenderPriority(android.webkit.WebSettings.RenderPriority.HIGH);
websettings.setJavaScriptEnabled(true);
if (o != null && o.get() != null)
{
websettings.setDatabaseEnabled(true);
websettings.setDatabasePath(((Context)o.get()).getApplicationContext().getDir("databases", 0).getPath());
}
websettings.setDomStorageEnabled(true);
jsBridge.a(new f(this, null), "sdk_js_if");
n.clearView();
n.loadUrl(i);
n.getSettings().setSavePassword(false);
}
private void d()
{
j.setVerticalScrollBarEnabled(false);
j.setHorizontalScrollBarEnabled(false);
j.setWebViewClient(new m(this, null));
j.setWebChromeClient(mChromeClient);
j.clearFormData();
WebSettings websettings = j.getSettings();
websettings.setSavePassword(false);
websettings.setSaveFormData(false);
websettings.setCacheMode(-1);
websettings.setNeedInitialFocus(false);
websettings.setBuiltInZoomControls(true);
websettings.setSupportZoom(true);
websettings.setRenderPriority(android.webkit.WebSettings.RenderPriority.HIGH);
websettings.setJavaScriptEnabled(true);
if (c != null && c.get() != null)
{
websettings.setDatabaseEnabled(true);
websettings.setDatabasePath(((Context)c.get()).getApplicationContext().getDir("databases", 0).getPath());
}
websettings.setDomStorageEnabled(true);
jsBridge.a(new n(this, null), "sdk_js_if");
j.loadUrl(f);
j.setLayoutParams(a);
j.setVisibility(4);
j.getSettings().setSavePassword(false);
}
private void initWebSettings() {
WebSettings webSettings = mBaseWebView.getSettings();
if (webSettings == null) return;
//设置字体缩放倍数,默认100
webSettings.setTextZoom(100);
// 支持 Js 使用
webSettings.setJavaScriptEnabled(true);
// 开启DOM缓存
webSettings.setDomStorageEnabled(true);
// 开启数据库缓存
webSettings.setDatabaseEnabled(true);
// 支持自动加载图片
webSettings.setLoadsImagesAutomatically(hasKitkat());
if (isCache) {
// 设置 WebView 的缓存模式
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
// 支持启用缓存模式
webSettings.setAppCacheEnabled(true);
// 设置 AppCache 最大缓存值(现在官方已经不提倡使用,已废弃)
webSettings.setAppCacheMaxSize(8 * 1024 * 1024);
// Android 私有缓存存储,如果你不调用setAppCachePath方法,WebView将不会产生这个目录
webSettings.setAppCachePath(mContext.getCacheDir().getAbsolutePath());
}
// 数据库路径
if (!hasKitkat()) {
webSettings.setDatabasePath(mContext.getDatabasePath("html").getPath());
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
// 关闭密码保存提醒功能
webSettings.setSavePassword(false);
// 支持缩放
webSettings.setSupportZoom(true);
// 设置 UserAgent 属性
webSettings.setUserAgentString("");
// 允许加载本地 html 文件/false
webSettings.setAllowFileAccess(true);
// 允许通过 file url 加载的 Javascript 读取其他的本地文件,Android 4.1 之前默认是true,在 Android 4.1 及以后默认是false,也就是禁止
webSettings.setAllowFileAccessFromFileURLs(false);
// 允许通过 file url 加载的 Javascript 可以访问其他的源,包括其他的文件和 http,https 等其他的源,
// Android 4.1 之前默认是true,在 Android 4.1 及以后默认是false,也就是禁止
// 如果此设置是允许,则 setAllowFileAccessFromFileURLs 不起做用
webSettings.setAllowUniversalAccessFromFileURLs(false);
}
@SuppressWarnings("deprecation")
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
public void initializeSettings(WebSettings settings, Context context) {
//setPageCacheCapacity2(settings);
if (API < 18) {
settings.setAppCacheMaxSize(Long.MAX_VALUE);
}
if (API < 17) {
settings.setEnableSmoothTransition(true);
}
if (API > 16) {
settings.setMediaPlaybackRequiresUserGesture(true);
}
if (API >= Build.VERSION_CODES.LOLLIPOP && !mBrowserController.isIncognito()) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
} else if (API >= Build.VERSION_CODES.LOLLIPOP) {
// We're in Incognito mode, reject
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
}
settings.setDomStorageEnabled(true);
settings.setAppCacheEnabled(true);
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
settings.setDatabaseEnabled(true);
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
settings.setAllowContentAccess(true);
settings.setAllowFileAccess(true);
settings.setDefaultTextEncodingName("utf-8");
if (API > 16) {
settings.setAllowFileAccessFromFileURLs(false);
settings.setAllowUniversalAccessFromFileURLs(false);
}
settings.setAppCachePath(context.getDir("appcache", 0).getPath());
settings.setGeolocationDatabasePath(context.getDir("geolocation", 0).getPath());
if (API < Build.VERSION_CODES.KITKAT) {
settings.setDatabasePath(context.getDir("databases", 0).getPath());
}
}
private void initViews() {
Method method;
WebSettings settings = this.mWebView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setUserAgentString(settings.getUserAgentString() + "/" + UA_PREFIX + this.jsBridge.getVersion() + "/sdk");
settings.setJavaScriptEnabled(true);
Class cls = settings.getClass();
try {
method = cls.getMethod("setPluginsEnabled", new Class[]{Boolean.TYPE});
if (method != null) {
method.invoke(settings, new Object[]{Boolean.valueOf(true)});
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (Throwable th) {
th.printStackTrace();
}
try {
method = cls.getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
if (method != null) {
method.invoke(settings, new Object[]{Boolean.valueOf(true)});
}
} catch (SecurityException e2) {
e2.printStackTrace();
} catch (NoSuchMethodException e3) {
} catch (IllegalArgumentException e4) {
} catch (IllegalAccessException e5) {
} catch (InvocationTargetException e6) {
}
settings.setAppCachePath(getWebViewCacheDir());
settings.setDatabasePath(getWebViewCacheDir());
settings.setDatabaseEnabled(true);
settings.setAppCacheEnabled(true);
if (supportWebViewFullScreen()) {
settings.setUseWideViewPort(true);
if (VERSION.SDK_INT >= 7) {
try {
cls.getMethod("setLoadWithOverviewMode", new Class[]{Boolean.TYPE}).invoke(settings, new Object[]{Boolean.valueOf(true)});
} catch (Exception e7) {
}
}
if (SystemUtils.isSupportMultiTouch()) {
if (SystemUtils.getAndroidSDKVersion() < 11) {
try {
Field declaredField = WebView.class.getDeclaredField("mZoomButtonsController");
declaredField.setAccessible(true);
ZoomButtonsController zoomButtonsController = new ZoomButtonsController(this.mWebView);
zoomButtonsController.getZoomControls().setVisibility(8);
declaredField.set(this.mWebView, zoomButtonsController);
} catch (Exception e8) {
}
} else {
try {
this.mWebView.getSettings().getClass().getMethod("setDisplayZoomControls", new Class[]{Boolean.TYPE}).invoke(this.mWebView.getSettings(), new Object[]{Boolean.valueOf(false)});
} catch (Exception e9) {
}
}
}
}
this.mWebView.setWebViewClient(new d());
this.mWebView.setWebChromeClient(new c());
this.mWebView.setDownloadListener(this.mDownloadListener);
this.mWebView.loadUrl(this.url);
}
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
webView.setInitialScale(0);
webView.setVerticalScrollBarEnabled(false);
// Enable JavaScript
final WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
String manufacturer = android.os.Build.MANUFACTURER;
LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);
//We don't save any form data in the application
settings.setSaveFormData(false);
settings.setSavePassword(false);
// Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
// while we do this
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setMediaPlaybackRequiresUserGesture(false);
// Enable database
// We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
settings.setDatabaseEnabled(true);
settings.setDatabasePath(databasePath);
//Determine whether we're in debug or release mode, and turn on Debugging!
ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
enableRemoteDebugging();
}
settings.setGeolocationDatabasePath(databasePath);
// Enable DOM storage
settings.setDomStorageEnabled(true);
// Enable built-in geolocation
settings.setGeolocationEnabled(true);
// Enable AppCache
// Fix for CB-2282
settings.setAppCacheMaxSize(5 * 1048576);
settings.setAppCachePath(databasePath);
settings.setAppCacheEnabled(true);
// Fix for CB-1405
// Google issue 4641
String defaultUserAgent = settings.getUserAgentString();
// Fix for CB-3360
String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
if (overrideUserAgent != null) {
settings.setUserAgentString(overrideUserAgent);
} else {
String appendUserAgent = preferences.getString("AppendUserAgent", null);
if (appendUserAgent != null) {
settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
}
}
// End CB-3360
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
if (this.receiver == null) {
this.receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
settings.getUserAgentString();
}
};
webView.getContext().registerReceiver(this.receiver, intentFilter);
}
// end CB-1405
}
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
webView.setInitialScale(0);
webView.setVerticalScrollBarEnabled(false);
// Enable JavaScript
final WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
String manufacturer = android.os.Build.MANUFACTURER;
LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);
//We don't save any form data in the application
settings.setSaveFormData(false);
settings.setSavePassword(false);
// Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
// while we do this
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setMediaPlaybackRequiresUserGesture(false);
// Enable database
// We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
settings.setDatabaseEnabled(true);
settings.setDatabasePath(databasePath);
//Determine whether we're in debug or release mode, and turn on Debugging!
ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
enableRemoteDebugging();
}
settings.setGeolocationDatabasePath(databasePath);
// Enable DOM storage
settings.setDomStorageEnabled(true);
// Enable built-in geolocation
settings.setGeolocationEnabled(true);
// Enable AppCache
// Fix for CB-2282
settings.setAppCacheMaxSize(5 * 1048576);
settings.setAppCachePath(databasePath);
settings.setAppCacheEnabled(true);
// Fix for CB-1405
// Google issue 4641
String defaultUserAgent = settings.getUserAgentString();
// Fix for CB-3360
String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
if (overrideUserAgent != null) {
settings.setUserAgentString(overrideUserAgent);
} else {
String appendUserAgent = preferences.getString("AppendUserAgent", null);
if (appendUserAgent != null) {
settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
}
}
// End CB-3360
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
if (this.receiver == null) {
this.receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
settings.getUserAgentString();
}
};
webView.getContext().registerReceiver(this.receiver, intentFilter);
}
// end CB-1405
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
JavaInterface android = new JavaInterface(this);
handler = new Handler();
webview = new WebView(this);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setDomStorageEnabled(true);
String databasePath = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
webSettings.setDatabasePath(databasePath);
// webview.setWebViewClient(new WebViewClient() {
// @Override
// public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Log.i("WebView", "Handling url " + url);
// Uri uri = Uri.parse(url);
// String scheme = uri.getScheme();
// if (scheme.equals(Form.APPINVENTOR_URL_SCHEME)) {
// Intent resultIntent = new Intent();
// resultIntent.setData(uri);
// setResult(RESULT_OK, resultIntent);
// finish();
// } else {
// view.loadUrl(url);
// }
// return true;
// }
// });
webview.setWebChromeClient(new WebChromeClient() {
@Override
public void onExceededDatabaseQuota(String url, String databaseIdentifier,
long currentQuota, long estimatedSize, long totalUsedQuota,
WebStorage.QuotaUpdater quotaUpdater) {
quotaUpdater.updateQuota(5 * 1024 * 1024);
}
});
setContentView(webview);
// Uncomment the line below to enable debugging
// the splash screen (splash.html)
//
// webview.setWebContentsDebuggingEnabled(true);
webview.addJavascriptInterface(android, "Android");
webview.loadUrl("file:///android_asset/splash.html");
}
/**
* @param aWebView
* **/
public static void setupWebViewAttributes(KCWebView aWebView)
{
try
{
WebSettings webSettings = aWebView.getSettings();
setCustomizedUA(webSettings);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
webSettings.setJavaScriptEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setBuiltInZoomControls(false);
webSettings.setSupportZoom(true);
webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webSettings.setAppCachePath(aWebView.getWebPath().getRootPath() + "/webcache");
webSettings.setAppCacheEnabled(true);
// webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setLightTouchEnabled(false);
webSettings.setDomStorageEnabled(true); // supports local storage
webSettings.setDatabaseEnabled(true); // supports local storage
webSettings.setDatabasePath(aWebView.getWebPath().getRootPath() + "/localstorage");
// we are using ApplicationContext when creaing KCWebView, without disabling the "Save Password" dialog
// there will be an exception that would cause crash: "Unable to add window -- token null is not for an application"
webSettings.setSavePassword(false);
aWebView.setHorizontalScrollBarEnabled(false);
// mWebView.setVerticalScrollBarEnabled(false);
aWebView.setScrollbarFadingEnabled(true);
aWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
}
catch (Exception e)
{
KCLog.e(e);
}
}
private void e()
{
k.setVerticalScrollBarEnabled(false);
k.setHorizontalScrollBarEnabled(false);
k.setWebViewClient(new l(this, null));
k.setWebChromeClient(new WebChromeClient());
k.clearFormData();
WebSettings websettings = k.getSettings();
websettings.setSavePassword(false);
websettings.setSaveFormData(false);
websettings.setCacheMode(-1);
websettings.setNeedInitialFocus(false);
websettings.setBuiltInZoomControls(true);
websettings.setSupportZoom(true);
websettings.setRenderPriority(android.webkit.WebSettings.RenderPriority.HIGH);
websettings.setJavaScriptEnabled(true);
if (a != null && a.get() != null)
{
websettings.setDatabaseEnabled(true);
websettings.setDatabasePath(((Context)a.get()).getApplicationContext().getDir("databases", 0).getPath());
}
websettings.setDomStorageEnabled(true);
try
{
Method method = android/webkit/WebView.getMethod("addJavascriptInterface", new Class[] {
java/lang/Object, java/lang/String
});
WebView webview = k;
Object aobj[] = new Object[2];
aobj[0] = new k(this, null);
aobj[1] = "sdk_js_if";
method.invoke(webview, aobj);
}
catch (NoSuchMethodException nosuchmethodexception)
{
nosuchmethodexception.printStackTrace();
}
catch (IllegalArgumentException illegalargumentexception)
{
illegalargumentexception.printStackTrace();
}
catch (IllegalAccessException illegalaccessexception)
{
illegalaccessexception.printStackTrace();
}
catch (InvocationTargetException invocationtargetexception)
{
invocationtargetexception.printStackTrace();
}
catch (Exception exception)
{
Log.e("AuthDialog", exception.getMessage());
}
k.loadUrl(b);
k.setVisibility(4);
k.getSettings().setSavePassword(false);
}
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
webView.setInitialScale(0);
webView.setVerticalScrollBarEnabled(false);
// Enable JavaScript
final WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
String manufacturer = android.os.Build.MANUFACTURER;
LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);
//We don't save any form data in the application
settings.setSaveFormData(false);
settings.setSavePassword(false);
// Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
// while we do this
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setMediaPlaybackRequiresUserGesture(false);
// Enable database
// We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
settings.setDatabaseEnabled(true);
settings.setDatabasePath(databasePath);
//Determine whether we're in debug or release mode, and turn on Debugging!
ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
enableRemoteDebugging();
}
settings.setGeolocationDatabasePath(databasePath);
// Enable DOM storage
settings.setDomStorageEnabled(true);
// Enable built-in geolocation
settings.setGeolocationEnabled(true);
// Enable AppCache
// Fix for CB-2282
settings.setAppCacheMaxSize(5 * 1048576);
settings.setAppCachePath(databasePath);
settings.setAppCacheEnabled(true);
// Fix for CB-1405
// Google issue 4641
String defaultUserAgent = settings.getUserAgentString();
// Fix for CB-3360
String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
if (overrideUserAgent != null) {
settings.setUserAgentString(overrideUserAgent);
} else {
String appendUserAgent = preferences.getString("AppendUserAgent", null);
if (appendUserAgent != null) {
settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
}
}
// End CB-3360
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
if (this.receiver == null) {
this.receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
settings.getUserAgentString();
}
};
webView.getContext().registerReceiver(this.receiver, intentFilter);
}
// end CB-1405
}
@SuppressLint({"SetJavaScriptEnabled", "ShowToast", "ClickableViewAccessibility"})
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Don't show an action bar or title
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Enable hardware acceleration
getWindow().setFlags(LayoutParams.FLAG_HARDWARE_ACCELERATED,
LayoutParams.FLAG_HARDWARE_ACCELERATED);
// Apply previous setting about showing status bar or not
applyFullScreen(isFullScreen());
// Check if screen rotation is locked in settings
boolean isOrientationEnabled = false;
try {
isOrientationEnabled = Settings.System.getInt(getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION) == 1;
} catch (SettingNotFoundException e) {
Log.d(MAIN_ACTIVITY_TAG, "Settings could not be loaded");
}
// If rotation isn't locked and it's a LARGE screen then add orientation changes based on sensor
int screenLayout = getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK;
if (((screenLayout == Configuration.SCREENLAYOUT_SIZE_LARGE)
|| (screenLayout == Configuration.SCREENLAYOUT_SIZE_XLARGE))
&& isOrientationEnabled) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
setContentView(R.layout.activity_main);
DialogChangeLog changeLog = DialogChangeLog.newInstance(this);
if (changeLog.isFirstRun()) {
changeLog.getLogDialog().show();
}
// Load webview with game
mWebView = findViewById(R.id.mainWebView);
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setRenderPriority(RenderPriority.HIGH);
settings.setDatabasePath(getFilesDir().getParentFile().getPath() + "/databases");
// If there is a previous instance restore it in the webview
if (savedInstanceState != null) {
mWebView.restoreState(savedInstanceState);
} else {
// Load webview with current Locale language
mWebView.loadUrl("file:///android_asset/2048/index.html?lang=" + Locale.getDefault().getLanguage());
}
Toast.makeText(getApplication(), R.string.toggle_fullscreen, Toast.LENGTH_SHORT).show();
// Set fullscreen toggle on webview LongClick
mWebView.setOnTouchListener((v, event) -> {
// Implement a long touch action by comparing
// time between action up and action down
long currentTime = System.currentTimeMillis();
if ((event.getAction() == MotionEvent.ACTION_UP)
&& (Math.abs(currentTime - mLastTouch) > mTouchThreshold)) {
boolean toggledFullScreen = !isFullScreen();
saveFullScreen(toggledFullScreen);
applyFullScreen(toggledFullScreen);
} else if (event.getAction() == MotionEvent.ACTION_DOWN) {
mLastTouch = currentTime;
}
// return so that the event isn't consumed but used
// by the webview as well
return false;
});
pressBackToast = Toast.makeText(getApplicationContext(), R.string.press_back_again_to_exit,
Toast.LENGTH_SHORT);
}
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
webView.setInitialScale(0);
webView.setVerticalScrollBarEnabled(false);
// Enable JavaScript
final WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
String manufacturer = android.os.Build.MANUFACTURER;
LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);
//We don't save any form data in the application
settings.setSaveFormData(false);
settings.setSavePassword(false);
// Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
// while we do this
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setMediaPlaybackRequiresUserGesture(false);
// Enable database
// We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
settings.setDatabaseEnabled(true);
settings.setDatabasePath(databasePath);
//Determine whether we're in debug or release mode, and turn on Debugging!
ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
enableRemoteDebugging();
}
settings.setGeolocationDatabasePath(databasePath);
// Enable DOM storage
settings.setDomStorageEnabled(true);
// Enable built-in geolocation
settings.setGeolocationEnabled(true);
// Enable AppCache
// Fix for CB-2282
settings.setAppCacheMaxSize(5 * 1048576);
settings.setAppCachePath(databasePath);
settings.setAppCacheEnabled(true);
// Fix for CB-1405
// Google issue 4641
String defaultUserAgent = settings.getUserAgentString();
// Fix for CB-3360
String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
if (overrideUserAgent != null) {
settings.setUserAgentString(overrideUserAgent);
} else {
String appendUserAgent = preferences.getString("AppendUserAgent", null);
if (appendUserAgent != null) {
settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
}
}
// End CB-3360
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
if (this.receiver == null) {
this.receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
settings.getUserAgentString();
}
};
webView.getContext().registerReceiver(this.receiver, intentFilter);
}
// end CB-1405
}
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
webView.setInitialScale(0);
webView.setVerticalScrollBarEnabled(false);
// Enable JavaScript
final WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
String manufacturer = android.os.Build.MANUFACTURER;
LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);
//We don't save any form data in the application
settings.setSaveFormData(false);
settings.setSavePassword(false);
// Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
// while we do this
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setMediaPlaybackRequiresUserGesture(false);
// Enable database
// We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
settings.setDatabaseEnabled(true);
settings.setDatabasePath(databasePath);
//Determine whether we're in debug or release mode, and turn on Debugging!
ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
enableRemoteDebugging();
}
settings.setGeolocationDatabasePath(databasePath);
// Enable DOM storage
settings.setDomStorageEnabled(true);
// Enable built-in geolocation
settings.setGeolocationEnabled(true);
// Enable AppCache
// Fix for CB-2282
settings.setAppCacheMaxSize(5 * 1048576);
settings.setAppCachePath(databasePath);
settings.setAppCacheEnabled(true);
// Fix for CB-1405
// Google issue 4641
String defaultUserAgent = settings.getUserAgentString();
// Fix for CB-3360
String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
if (overrideUserAgent != null) {
settings.setUserAgentString(overrideUserAgent);
} else {
String appendUserAgent = preferences.getString("AppendUserAgent", null);
if (appendUserAgent != null) {
settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
}
}
// End CB-3360
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
if (this.receiver == null) {
this.receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
settings.getUserAgentString();
}
};
webView.getContext().registerReceiver(this.receiver, intentFilter);
}
// end CB-1405
}