Java Code Examples for android.webkit.WebSettings#setAppCachePath()
The following examples show how to use
android.webkit.WebSettings#setAppCachePath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebActivity.java From Android-Plugin-Framework with MIT License | 6 votes |
private void setUpWebViewSetting() { WebSettings webSettings = web.getSettings(); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);// 根据cache-control决定是否从网络上取数据 webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true);// 显示放大缩小 webSettings.setJavaScriptEnabled(true); // webSettings.setPluginsEnabled(true); webSettings.setPluginState(WebSettings.PluginState.ON); webSettings.setUserAgentString(webSettings.getUserAgentString()); webSettings.setDomStorageEnabled(true); webSettings.setAppCacheEnabled(true); webSettings.setAppCachePath(getCacheDir().getPath()); webSettings.setUseWideViewPort(true);// 影响默认满屏和双击缩放 webSettings.setLoadWithOverviewMode(true);// 影响默认满屏和手势缩放 }
Example 2
Source File: TestCaseListActivity.java From Android-Plugin-Framework with MIT License | 6 votes |
private void setUpWebViewSetting(WebView web) { WebSettings webSettings = web.getSettings(); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);// 根据cache-control决定是否从网络上取数据 webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true);// 显示放大缩小 webSettings.setJavaScriptEnabled(true); // webSettings.setPluginsEnabled(true); webSettings.setPluginState(WebSettings.PluginState.ON); webSettings.setUserAgentString(webSettings.getUserAgentString()); webSettings.setDomStorageEnabled(true); webSettings.setAppCacheEnabled(true); webSettings.setAppCachePath(getCacheDir().getPath()); webSettings.setUseWideViewPort(true);// 影响默认满屏和双击缩放 webSettings.setLoadWithOverviewMode(true);// 影响默认满屏和手势缩放 }
Example 3
Source File: WebViewActivity.java From movienow with GNU General Public License v3.0 | 5 votes |
private void initWebSettings() { WebSettings webSettings = webViewT.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); webSettings.setSupportZoom(true); webSettings.setDisplayZoomControls(false); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setAllowFileAccess(true); webSettings.setDefaultTextEncodingName("UTF-8"); webSettings.setLoadWithOverviewMode(true); webSettings.setUseWideViewPort(true); webSettings.setDomStorageEnabled(true); webSettings.setAppCacheMaxSize(1024 * 1024 * 8); String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath(); webSettings.setAppCachePath(appCachePath); webSettings.setAllowFileAccess(true); webSettings.setAppCacheEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int mDensity = metrics.densityDpi; if (mDensity == 240) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR); } else if (mDensity == 160) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM); } else if (mDensity == 120) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.CLOSE); } else if (mDensity == DisplayMetrics.DENSITY_XHIGH) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR); } else if (mDensity == DisplayMetrics.DENSITY_TV) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR); } else { webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM); } }
Example 4
Source File: ReadabilityActivity.java From Ninja with Apache License 2.0 | 5 votes |
private void initWebView() { webView.setAlwaysDrawnWithCacheEnabled(true); webView.setAnimationCacheEnabled(true); webView.setDrawingCacheBackgroundColor(0x00000000); webView.setDrawingCacheEnabled(true); webView.setWillNotCacheDrawing(false); webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); webView.setFocusable(true); webView.setFocusableInTouchMode(true); webView.setScrollbarFadingEnabled(true); webView.setHorizontalScrollBarEnabled(true); webView.setVerticalScrollBarEnabled(true); webView.setBackground(null); webView.getRootView().setBackground(null); int color = sp.getInt(getString(R.string.sp_readability_background), getResources().getColor(R.color.white)); webView.setBackgroundColor(color); WebSettings webSettings = webView.getSettings(); webSettings.setAppCacheEnabled(true); webSettings.setAppCachePath(getCacheDir().toString()); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); webSettings.setDefaultTextEncodingName(BrowserUnit.URL_ENCODING); webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); webSettings.setLoadWithOverviewMode(true); webSettings.setTextZoom(100); webSettings.setUseWideViewPort(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { webSettings.setLoadsImagesAutomatically(true); } else { webSettings.setLoadsImagesAutomatically(false); } }
Example 5
Source File: MainActivity.java From webTube with GNU General Public License v3.0 | 5 votes |
public void setUpWebview() { // To save login info CookieHelper.acceptCookies(webView, true); // Some settings WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(false); webSettings.setAllowFileAccess(false); webSettings.setDatabaseEnabled(true); String cachePath = mApplicationContext .getDir("cache", Context.MODE_PRIVATE).getPath(); webSettings.setAppCachePath(cachePath); webSettings.setAllowFileAccess(true); webSettings.setAppCacheEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); webView.setHorizontalScrollBarEnabled(false); webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); webView.setBackgroundColor(Color.WHITE); webView.setScrollbarFadingEnabled(true); webView.setNetworkAvailable(true); }
Example 6
Source File: Tab2Fragment.java From HelloActivityAndFragment with Apache License 2.0 | 5 votes |
@SuppressLint("JavascriptInterface") private void initWebView() { // Settings WebSettings settings = webView.getSettings(); settings.setDefaultTextEncodingName("GBK"); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); settings.setGeolocationEnabled(true); // settings.setDisplayZoomControls(false); settings.setBuiltInZoomControls(true); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setDatabaseEnabled(true); settings.setAppCacheEnabled(true); settings.setAppCachePath(this.getContext().getCacheDir().getAbsolutePath()); settings.setDisplayZoomControls(false); webView.requestFocus(); webView.setWebViewClient(new WebViewClient() { }); webView.setWebChromeClient(new WebChromeClient() { }); }
Example 7
Source File: CacheableWebView.java From materialistic with Apache License 2.0 | 5 votes |
private void enableCache() { WebSettings webSettings = getSettings(); webSettings.setAppCacheEnabled(true); webSettings.setAllowFileAccess(true); webSettings.setAppCachePath(getContext().getApplicationContext() .getCacheDir().getAbsolutePath()); setCacheModeInternal(); }
Example 8
Source File: CommonWebView.java From gank.io-unofficial-android-client with Apache License 2.0 | 5 votes |
private void init() { if (isInEditMode()) { return; } WebSettings settings = getSettings(); settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(false); //设置缓存模式 settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //开启DOM storage API功能 settings.setDomStorageEnabled(true); //开启database storage 功能 settings.setDatabaseEnabled(true); String cacheDir = getContext().getFilesDir().getAbsolutePath() + "web_cache"; settings.setAppCachePath(cacheDir); settings.setAppCacheEnabled(true); settings.setLoadsImagesAutomatically(true); settings.setDefaultTextEncodingName(ENCODING_UTF_8); settings.setBlockNetworkImage(false); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); setHorizontalScrollBarEnabled(false); }
Example 9
Source File: CodeWebView.java From OpenHub with GNU General Public License v3.0 | 5 votes |
@SuppressLint("SetJavaScriptEnabled") private void init(AttributeSet attrs) { if (attrs != null) { TypedArray tp = getContext().obtainStyledAttributes(attrs, R.styleable.CodeWebView); try { backgroundColor = tp.getColor(R.styleable.CodeWebView_webview_background, ViewUtils.getWindowBackground(getContext())); setBackgroundColor(backgroundColor); } finally { tp.recycle(); } } setWebChromeClient(new ChromeClient()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { setWebViewClient(new WebClientN()); } else { setWebViewClient(new WebClient()); } WebSettings settings = getSettings(); settings.setJavaScriptEnabled(true); settings.setAppCachePath(getContext().getCacheDir().getPath()); settings.setAppCacheEnabled(true); settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); settings.setDefaultTextEncodingName("utf-8"); boolean isLoadImageEnable = PrefUtils.isLoadImageEnable(); settings.setLoadsImagesAutomatically(isLoadImageEnable); settings.setBlockNetworkImage(!isLoadImageEnable); setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { WebView.HitTestResult result = getHitTestResult(); if (hitLinkResult(result) && !StringUtils.isBlank(result.getExtra())) { AppUtils.copyToClipboard(getContext(), result.getExtra()); return true; } return false; } }); }
Example 10
Source File: WebViewActivity.java From DanDanPlayForAndroid with MIT License | 5 votes |
@SuppressLint("SetJavaScriptEnabled") private void initWebSetting(){ WebSettings webSetting = mWebView.getSettings(); webSetting.setJavaScriptEnabled(true); // WebSettings.LOAD_DEFAULT 如果本地缓存可用且没有过期则使用本地缓存,否加载网络数据 默认值 // WebSettings.LOAD_CACHE_ELSE_NETWORK 优先加载本地缓存数据,无论缓存是否过期 // WebSettings.LOAD_NO_CACHE 只加载网络数据,不加载本地缓存 // WebSettings.LOAD_CACHE_ONLY 只加载缓存数据,不加载网络数据 //Tips:有网络可以使用LOAD_DEFAULT 没有网时用LOAD_CACHE_ELSE_NETWORK webSetting.setCacheMode(android.webkit.WebSettings.LOAD_NO_CACHE); webSetting.setAppCacheEnabled(true); //开启H5(APPCache)缓存功能websettings.setAppCacheMaxSize(1024*1024*8); String appCachePath = this.getApplicationContext().getCacheDir().getAbsolutePath(); webSetting.setAppCachePath(appCachePath); //开启 DOM storage API 功能 较大存储空间,使用简单 webSetting.setDomStorageEnabled(true); //开启 Application Caches 功能 方便构建离线APP 不推荐使用 webSetting.setAppCacheEnabled(true); //支持通过JS打开新窗口 webSetting.setJavaScriptCanOpenWindowsAutomatically(true); //视图适应窗口 // webSetting.setUseWideViewPort(true); // webSetting.setLoadWithOverviewMode(true); webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); //允许 WebView 使用 File 协议 webSetting.setAllowFileAccess(true); //允许webview对文件的操作 webSetting.setAllowUniversalAccessFromFileURLs(true); webSetting.setAllowFileAccessFromFileURLs(true); }
Example 11
Source File: NinjaWebView.java From Ninja with Apache License 2.0 | 5 votes |
private synchronized void initWebSettings() { WebSettings webSettings = getSettings(); userAgentOriginal = webSettings.getUserAgentString(); webSettings.setAllowContentAccess(true); webSettings.setAllowFileAccess(true); webSettings.setAllowFileAccessFromFileURLs(true); webSettings.setAllowUniversalAccessFromFileURLs(true); webSettings.setAppCacheEnabled(true); webSettings.setAppCachePath(context.getCacheDir().toString()); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); webSettings.setDatabaseEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setGeolocationDatabasePath(context.getFilesDir().toString()); webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webSettings.setDefaultTextEncodingName(BrowserUnit.URL_ENCODING); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { webSettings.setLoadsImagesAutomatically(true); } else { webSettings.setLoadsImagesAutomatically(false); } }
Example 12
Source File: QuickWebView.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 初始化设置 */ public void settingWebView() { WebSettings settings = getSettings(); String ua = settings.getUserAgentString(); // 设置浏览器UA,JS端通过UA判断是否属于Quick环境 settings.setUserAgentString(ua + " QuickHybridJs/" + BuildConfig.VERSION_NAME); // 设置支持JS settings.setJavaScriptEnabled(true); // 设置是否支持meta标签来控制缩放 settings.setUseWideViewPort(true); // 缩放至屏幕的大小 settings.setLoadWithOverviewMode(true); // 设置内置的缩放控件(若SupportZoom为false,该设置项无效) settings.setBuiltInZoomControls(true); // 设置缓存模式 // LOAD_DEFAULT 根据HTTP协议header中设置的cache-control属性来执行加载策略 // LOAD_CACHE_ELSE_NETWORK 只要本地有无论是否过期都从本地获取 settings.setCacheMode(WebSettings.LOAD_DEFAULT); settings.setDomStorageEnabled(true); // 设置AppCache 需要H5页面配置manifest文件(官方已不推介使用) String appCachePath = getContext().getCacheDir().getAbsolutePath(); settings.setAppCachePath(appCachePath); settings.setAppCacheEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // 强制开启android webview debug模式使用Chrome inspect(https://developers.google.com/web/tools/chrome-devtools/remote-debugging/) WebView.setWebContentsDebuggingEnabled(true); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().setAcceptThirdPartyCookies(this, true); } }
Example 13
Source File: BaseActivity.java From ZhihuDaily with Apache License 2.0 | 5 votes |
private void initWebView() { WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); settings.setLoadWithOverviewMode(true); settings.setBuiltInZoomControls(true); settings.setDomStorageEnabled(true); settings.setDatabaseEnabled(true); settings.setSupportZoom(false); settings.setAppCachePath(getCacheDir().getAbsolutePath() + "/webViewCache"); settings.setAppCacheEnabled(true); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); mWebView.setWebChromeClient(new WebChromeClient()); }
Example 14
Source File: EditAreaView.java From 920-text-editor-v2 with Apache License 2.0 | 4 votes |
public EditAreaView(Context context, AttributeSet attrs) { super(context, attrs); if (L.debug) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setWebContentsDebuggingEnabled(true); } } setLongClickable(false); setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { return true; } }); WebSettings ws = getSettings(); ws.setDefaultZoom(WebSettings.ZoomDensity.FAR); ws.setAllowContentAccess(true); ws.setAllowFileAccess(true); ws.setBuiltInZoomControls(false); ws.setDefaultTextEncodingName("utf-8"); ws.setDisplayZoomControls(false); ws.setSupportZoom(false); ws.setLoadWithOverviewMode(false); ws.setJavaScriptEnabled(true); ws.setAppCacheEnabled(false); ws.setDomStorageEnabled(true); ws.setAppCacheMaxSize(1024*1024*80); ws.setAppCachePath(context.getCacheDir().getPath()); // ws.setAllowFileAccess(true); ws.setCacheMode(WebSettings.LOAD_DEFAULT); addJavascriptInterface(new JavascriptApi(), "AndroidEditor"); setWebViewClient(new EditorViewClient()); setWebChromeClient(new EditorViewChromeClient()); pref = Pref.getInstance(getContext()); ThemeList.Theme theme = pref.getThemeInfo(); boolean isDark = false; if (theme != null) { isDark = theme.isDark; } String html = null; try { InputStream is = getContext().getAssets().open("editor.html"); html = IOUtils.readFile(is, "utf-8"); is.close(); } catch (Exception e) { L.e(e); UIUtils.toast(getContext(), R.string.editor_create_unknown_exception); return; } if (!isDark) html = html.replaceAll("<\\!\\-\\-\\{DARK\\-START\\}\\-\\->[\\w\\W]+?<\\!\\-\\-\\{DARK\\-END\\}\\-\\->", ""); loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", "file:///android_asset/"); //fix dark theme background spark setBackgroundColor(Color.TRANSPARENT); pref.registerOnSharedPreferenceChangeListener(this); onSharedPreferenceChanged(null, Pref.KEY_FONT_SIZE); onSharedPreferenceChanged(null, Pref.KEY_CURSOR_WIDTH); onSharedPreferenceChanged(null, Pref.KEY_SHOW_LINE_NUMBER); onSharedPreferenceChanged(null, Pref.KEY_WORD_WRAP); onSharedPreferenceChanged(null, Pref.KEY_SHOW_WHITESPACE); onSharedPreferenceChanged(null, Pref.KEY_TAB_SIZE); onSharedPreferenceChanged(null, Pref.KEY_AUTO_INDENT); onSharedPreferenceChanged(null, Pref.KEY_AUTO_CAPITALIZE); onSharedPreferenceChanged(null, Pref.KEY_INSERT_SPACE_FOR_TAB); onSharedPreferenceChanged(null, Pref.KEY_THEME); onSharedPreferenceChanged(null, Pref.KEY_TOUCH_TO_ADJUST_TEXT_SIZE); enableHighlight(pref.isHighlight()); setReadOnly(pref.isReadOnly()); }
Example 15
Source File: SystemWebViewEngine.java From keemob with MIT License | 4 votes |
@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 }
Example 16
Source File: LightningView.java From browser with GNU General Public License v2.0 | 4 votes |
@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()); } }
Example 17
Source File: MainActivity.java From SlimSocial-for-Facebook with GNU General Public License v2.0 | 4 votes |
private void SetupWebView() { webViewFacebook = findViewById(webView); webViewFacebook.setListener(this, this); webViewFacebook.clearPermittedHostnames(); webViewFacebook.addPermittedHostname("facebook.com"); webViewFacebook.addPermittedHostname("fbcdn.net"); webViewFacebook.addPermittedHostname("fb.com"); webViewFacebook.addPermittedHostname("fb.me"); /* webViewFacebook.addPermittedHostname("m.facebook.com"); webViewFacebook.addPermittedHostname("h.facebook.com"); webViewFacebook.addPermittedHostname("touch.facebook.com"); webViewFacebook.addPermittedHostname("mbasic.facebook.com"); webViewFacebook.addPermittedHostname("touch.facebook.com"); webViewFacebook.addPermittedHostname("messenger.com"); */ webViewFacebook.requestFocus(View.FOCUS_DOWN); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);//remove the keyboard issue WebSettings settings = webViewFacebook.getSettings(); webViewFacebook.setDesktopMode(true); settings.setUserAgentString("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"); settings.setJavaScriptEnabled(true); //set text zoom int zoom = Integer.parseInt(savedPreferences.getString("pref_textSize", "100")); settings.setTextZoom(zoom); //set Geolocation settings.setGeolocationEnabled(savedPreferences.getBoolean("pref_allowGeolocation", true)); // Use WideViewport and Zoom out if there is no viewport defined settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); // better image sizing support settings.setSupportZoom(true); settings.setDisplayZoomControls(false); settings.setBuiltInZoomControls(true); // set caching settings.setAppCachePath(getCacheDir().getAbsolutePath()); settings.setAppCacheEnabled(true); settings.setLoadsImagesAutomatically(!savedPreferences.getBoolean("pref_doNotDownloadImages", false));//to save data settings.setDisplayZoomControls(false); }
Example 18
Source File: Main2Activity.java From styT with Apache License 2.0 | 4 votes |
@SuppressLint("SetJavaScriptEnabled") private void initWebSettings() { WebSettings settings = sMm.getSettings(); settings.setUserAgentString("" + SPUtils.get(Main2Activity.this, "if_7", ""));//UA //支持获取手势焦点 sMm.requestFocusFromTouch(); //支持JS settings.setJavaScriptEnabled((Boolean) SPUtils.get(Main2Activity.this, "if_1", true)); //支持插件 // settings.setPluginState(WebSettings.PluginState.ON); //设置适应屏幕 settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); //支持缩放 settings.setSupportZoom((Boolean) SPUtils.get(Main2Activity.this, "if_3", false)); // 支持缩放 //隐藏原生的缩放控件 settings.setDisplayZoomControls(false); //支持内容重新布局 settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); settings.supportMultipleWindows(); settings.setSupportMultipleWindows(false); //设置缓存模式 settings.setGeolocationEnabled((Boolean) SPUtils.get(Main2Activity.this, "if_2", true));//允许地理位置可用 settings.setDomStorageEnabled(true); settings.setDatabaseEnabled((Boolean) SPUtils.get(Main2Activity.this, "if_4", true)); settings.setCacheMode(WebSettings.LOAD_DEFAULT); settings.setAppCacheEnabled(true); settings.setAppCachePath(sMm.getContext().getCacheDir().getAbsolutePath()); //settings.setRenderPriority(WebSettings.RenderPriority.HIGH); //提高渲染的优先级 //设置可访问文件 settings.setAllowFileAccess(true); //当webview调用requestFocus时为webview设置节点 settings.setNeedInitialFocus(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } //支持自动加载图片 if (Build.VERSION.SDK_INT >= 19) { settings.setLoadsImagesAutomatically((Boolean) SPUtils.get(Main2Activity.this, "if_5", true));//图片 } else { settings.setLoadsImagesAutomatically(false); } // settings.setNeedInitialFocus(true); //设置编码格式 //settings.setDefaultTextEncodingName("UTF-8"); }
Example 19
Source File: KCWebView.java From kerkee_android with GNU General Public License v3.0 | 4 votes |
/** * @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); } }
Example 20
Source File: Browse9PForumActivity.java From v9porn with MIT License | 4 votes |
@SuppressLint("SetJavaScriptEnabled") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_browse9_porn); ButterKnife.bind(this); historyIdStack = new Stack<>(); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setAppCacheEnabled(true); webSettings.setAppCachePath(AppCacheUtils.getRxCacheDir(context).getAbsolutePath()); mWebView.setWebChromeClient( new InjectedChromeClient("HostApp", HostJsScope.class) ); mWebView.setBackgroundColor(0); mWebView.setBackgroundResource(0); mWebView.setVisibility(View.INVISIBLE); mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.contains("tid=")) { int starIndex = url.indexOf("tid="); String tidStr = StringUtils.subString(url, starIndex + 4, starIndex + 10); if (!TextUtils.isEmpty(tidStr) && TextUtils.isDigitsOnly(tidStr)) { Long id = Long.parseLong(tidStr); presenter.loadContent(id); historyIdStack.push(id); } else { Logger.t(TAG).d(tidStr); showMessage("暂不支持直接打开此链接", TastyToast.INFO); } } return true; } }); AppUtils.setColorSchemeColors(context, swipeLayout); f9PronItem = (F9PronItem) getIntent().getSerializableExtra(Keys.KEY_INTENT_BROWSE_FORUM_9PORN_ITEM); presenter.loadContent(f9PronItem.getTid()); historyIdStack.push(f9PronItem.getTid()); imageList = new ArrayList<>(); boolean needShowTip = presenter.isNeedShowTipFirstViewForum9Content(); if (needShowTip) { showTipDialog(); } fabFunction.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showOpenNewForum(); } }); }