List of usage examples for android.webkit WebView getSettings
public WebSettings getSettings()
From source file:Main.java
public static void SetLayoutAlgorithmTextAutosizing(android.webkit.WebView wv) { try {// www. j ava2 s. co m wv.getSettings().setLayoutAlgorithm(android.webkit.WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); } catch (java.lang.IllegalArgumentException e) { Log.v("breviar", "Can not set TEXT_AUTOSIZING. Cyanogenmod weirdness?"); } }
From source file:Main.java
public static void setWebViewLayout(WebView webView, String content) { if (content.contains("<table")) { webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); } else {/* w ww . ja va 2 s . co m*/ webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); } }
From source file:Main.java
/** * <p>Configures basic settings of the webView (Javascript enabled, DOM storage enabled, * database enabled).</p>/*from w w w . j a v a 2s .co m*/ * * @param webView The shared webView. */ @SuppressLint("SetJavaScriptEnabled") private static void configureWebViewDefaults(WebView webView) { WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); settings.setDatabaseEnabled(true); webView.setWebChromeClient(new WebChromeClient()); }
From source file:Main.java
@SuppressWarnings("deprecation") public static void WebViewSettingsSetDatabasePath(WebView webView, String path) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { webView.getSettings().setDatabasePath(path); }/* w w w .j a va 2s. c om*/ }
From source file:Main.java
public static void disableRiskySettings(WebView webView) { //javascript could be a vector to exploit your applications webView.getSettings().setJavaScriptEnabled(false); //default is off, but just in case. plugins could be a vector to exploit your applications process webView.getSettings().setPluginState(WebSettings.PluginState.OFF); //Should an attacker somehow find themselves in a position to inject script into a WebView, then they could exploit the opportunity to access local resources. This can be somewhat prevented by disabling local file system access. It is enabled by default. The Android WebSettings class can be used to disable local file system access via the public method setAllowFileAccess. //This restricts the WebView to loading local resources from file:///android_asset (assets) and file:///android_res (resources). webView.getSettings().setAllowFileAccess(false); //disable Geolocation API webView.getSettings().setGeolocationEnabled(false); }
From source file:de.mkrtchyan.recoverytools.SettingsFragment.java
public static void showChangelog(Context AppContext) { AlertDialog.Builder dialog = new AlertDialog.Builder(AppContext); dialog.setTitle(R.string.changelog); WebView changes = new WebView(AppContext); changes.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); changes.setWebViewClient(new WebViewClient()); changes.loadUrl(Constants.CHANGELOG_URL); changes.clearCache(true);/*ww w . j a v a 2s . c om*/ dialog.setView(changes); dialog.show(); }
From source file:Main.java
@SuppressLint("SetJavaScriptEnabled") public static void webView_Settings(final Activity from, final WebView webView) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from); String fontSizeST = sharedPref.getString("font", "100"); int fontSize = Integer.parseInt(fontSizeST); webView.getSettings().setAppCachePath(from.getApplicationContext().getCacheDir().getAbsolutePath()); webView.getSettings().setAllowFileAccess(true); webView.getSettings().setAppCacheEnabled(true); webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setDisplayZoomControls(false); webView.getSettings().setTextZoom(fontSize); webView.getSettings().setGeolocationEnabled(false); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setUseWideViewPort(true); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); // load online by default }
From source file:com.dabay6.libraries.androidshared.ui.dialogs.changelog.util.ChangeLogDialogUtils.java
/** * @param context {@link Context} used to retrieve resources. * @param assetName Name of the asset file containing the change log json. * @param style The css style to be applied to the html. * @param callback The callback to call upon dismissal of the change log alert dialog. * * @return {@link AlertDialog} used to display the change log. *///from www . j av a2 s . c o m public static AlertDialog createDialog(final Context context, final String assetName, final String style, final OnChangeLogDialogListener callback) { final AlertDialog.Builder builder; final Resources res = context.getResources(); final String title = res.getString(R.string.change_log_title, AppUtils.getApplicationVersion(context)); final WebSettings settings; final WebView web = new WebView(context); String html; try { html = getHtmlChangeLog(context, assetName, style); settings = web.getSettings(); settings.setSupportZoom(false); } catch (final IOException ex) { html = StringUtils.empty(); Logger.error(TAG, ex.getMessage(), ex); } web.loadData(html, "text/html", "utf-8"); builder = new AlertDialog.Builder(context); builder.setTitle(title).setView(web).setPositiveButton(R.string.change_log_close, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { dialog.dismiss(); if (callback != null) { callback.onChangeLogDismissed(); } } }); return builder.create(); }
From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java
public static void loadText(final WebView webView, final String text) { webView.setWebChromeClient(new WebChromeClient()); webView.setWebViewClient(new WebViewClient()); webView.getSettings().setJavaScriptEnabled(true); webView.loadDataWithBaseURL(BASE_URL, CODE_HTML_PREFIX + MarkdownFormatter.escapeHtml(text) + CODE_HTML_SUFFIX, HttpContentTypes.TEXT_HTML, HTTP.UTF_8, null); }
From source file:de.baumann.browser.helper.helper_webView.java
@SuppressLint("SetJavaScriptEnabled") public static void webView_Settings(final Activity from, final WebView webView) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from); String fontSizeST = sharedPref.getString("font", "100"); int fontSize = Integer.parseInt(fontSizeST); webView.getSettings().setAppCachePath(from.getApplicationContext().getCacheDir().getAbsolutePath()); webView.getSettings().setAppCacheEnabled(true); webView.getSettings().setMixedContentMode(MIXED_CONTENT_COMPATIBILITY_MODE); webView.getSettings().setAllowFileAccess(true); webView.getSettings().setAllowContentAccess(true); webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setDisplayZoomControls(false); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setTextZoom(fontSize); webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); webView.getSettings().setUseWideViewPort(true); webView.getSettings().setLoadWithOverviewMode(true); from.registerForContextMenu(webView); if (sharedPref.getString("nav", "2").equals("1") || sharedPref.getString("nav", "2").equals("3")) { helper_webView.webView_Touch(from, webView); }// w w w . j av a2 s . com if (sharedPref.getString("cookie", "1").equals("2") || sharedPref.getString("cookie", "1").equals("3")) { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptThirdPartyCookies(webView, true); } else { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptThirdPartyCookies(webView, false); } if (sharedPref.getString("started", "").equals("yes")) { if (sharedPref.getString("java_string", "True").equals(from.getString(R.string.app_yes))) { webView.getSettings().setJavaScriptEnabled(true); sharedPref.edit().putString("java_string", from.getString(R.string.app_yes)).apply(); } else { webView.getSettings().setJavaScriptEnabled(false); sharedPref.edit().putString("java_string", from.getString(R.string.app_no)).apply(); } if (sharedPref.getString("pictures_string", "True").equals(from.getString(R.string.app_yes))) { webView.getSettings().setLoadsImagesAutomatically(true); sharedPref.edit().putString("pictures_string", from.getString(R.string.app_yes)).apply(); } else { webView.getSettings().setLoadsImagesAutomatically(false); sharedPref.edit().putString("pictures_string", from.getString(R.string.app_no)).apply(); } if (sharedPref.getString("loc_string", "True").equals(from.getString(R.string.app_yes))) { webView.getSettings().setGeolocationEnabled(true); helper_main.grantPermissionsLoc(from); sharedPref.edit().putString("loc_string", from.getString(R.string.app_yes)).apply(); } else { webView.getSettings().setGeolocationEnabled(false); sharedPref.edit().putString("loc_string", from.getString(R.string.app_no)).apply(); } if (sharedPref.getString("cookie_string", "True").equals(from.getString(R.string.app_yes))) { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); sharedPref.edit().putString("cookie_string", from.getString(R.string.app_yes)).apply(); } else { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(false); sharedPref.edit().putString("cookie_string", from.getString(R.string.app_no)).apply(); } } else { if (sharedPref.getBoolean("java", false)) { webView.getSettings().setJavaScriptEnabled(true); sharedPref.edit().putString("java_string", from.getString(R.string.app_yes)).apply(); } else { webView.getSettings().setJavaScriptEnabled(false); sharedPref.edit().putString("java_string", from.getString(R.string.app_no)).apply(); } if (sharedPref.getBoolean("pictures", false)) { webView.getSettings().setLoadsImagesAutomatically(true); sharedPref.edit().putString("pictures_string", from.getString(R.string.app_yes)).apply(); } else { webView.getSettings().setLoadsImagesAutomatically(false); sharedPref.edit().putString("pictures_string", from.getString(R.string.app_no)).apply(); } if (sharedPref.getBoolean("loc", false)) { webView.getSettings().setGeolocationEnabled(true); helper_main.grantPermissionsLoc(from); sharedPref.edit().putString("loc_string", from.getString(R.string.app_yes)).apply(); } else { webView.getSettings().setGeolocationEnabled(false); sharedPref.edit().putString("loc_string", from.getString(R.string.app_no)).apply(); } if (sharedPref.getString("cookie", "1").equals("1") || sharedPref.getString("cookie", "1").equals("3")) { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); sharedPref.edit().putString("cookie_string", from.getString(R.string.app_yes)).apply(); } else { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(false); sharedPref.edit().putString("cookie_string", from.getString(R.string.app_no)).apply(); } } }