List of usage examples for android.webkit WebSettings setAppCacheMaxSize
@Deprecated public abstract void setAppCacheMaxSize(long appCacheMaxSize);
From source file:com.usabusi.newsreader.ArticleFragment.java
/** * Sets up the UI. It consists if a single WebView. *//*w ww.j a va 2s . co m*/ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mWebView = new WebView(getActivity()); //http://stackoverflow.com/questions/17259537/load-webview-from-cache WebSettings webSettings = mWebView.getSettings(); // Enable JavaScript webSettings.setJavaScriptEnabled(true); // enable javascript mWebView.setHorizontalScrollBarEnabled(false); webSettings.setAppCacheMaxSize(5 * 1024 * 1024); // 5MB webSettings.setAppCachePath(getActivity().getApplicationContext().getCacheDir().getAbsolutePath()); webSettings.setAllowFileAccess(true); webSettings.setAppCacheEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); // load online by default //http://stackoverflow.com/questions/25161720/url-opened-in-browser-instead-of-web-view mWebView.setVisibility(View.VISIBLE); webSettings.setPluginState(WebSettings.PluginState.ON); webSettings.setBuiltInZoomControls(true); //final Activity activity = this; // Make WebClient mWebView.setWebViewClient(new WebViewClient() { // Trace Errors public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Toast.makeText(getActivity().getApplicationContext(), description, Toast.LENGTH_SHORT).show(); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { //http://developer.android.com/guide/webapps/webview.html#HandlingNavigation // view.loadUrl(url); // return true; return false; } }); loadWebView(); return mWebView; }
From source file:org.openqa.selendroid.server.model.SelendroidWebDriver.java
private void configureWebView(final WebView view) { ServerInstrumentation.getInstance().runOnUiThread(new Runnable() { @Override// ww w .j av a 2s . co m public void run() { view.clearCache(true); view.clearFormData(); view.clearHistory(); view.setFocusable(true); view.setFocusableInTouchMode(true); view.setNetworkAvailable(true); view.setWebChromeClient(new MyWebChromeClient()); WebSettings settings = view.getSettings(); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setSupportMultipleWindows(true); settings.setBuiltInZoomControls(true); settings.setJavaScriptEnabled(true); settings.setAppCacheEnabled(true); settings.setAppCacheMaxSize(10 * 1024 * 1024); settings.setAppCachePath(""); settings.setDatabaseEnabled(true); settings.setDomStorageEnabled(true); settings.setGeolocationEnabled(true); settings.setSaveFormData(false); settings.setSavePassword(false); settings.setRenderPriority(WebSettings.RenderPriority.HIGH); // Flash settings settings.setPluginState(WebSettings.PluginState.ON); // Geo location settings settings.setGeolocationEnabled(true); settings.setGeolocationDatabasePath("/data/data/selendroid"); } }); }
From source file:com.example.administrator.mywebviewdrawsign.SysWebView.java
/** * Initialize webview./* w ww . j a v a 2 s . co m*/ */ @SuppressLint({ "NewApi", "SetJavaScriptEnabled" }) private void setup() { this.setInitialScale(0); this.setVerticalScrollBarEnabled(true); this.setHorizontalScrollBarEnabled(true); this.requestFocusFromTouch(); // Enable JavaScript WebSettings settings = this.getSettings(); settings.setBuiltInZoomControls(false);// ?? settings.setUseWideViewPort(false); settings.setLoadWithOverviewMode(true); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); settings.setAllowFileAccess(true); settings.setAppCacheMaxSize(1024 * 1024 * 32); settings.setAppCachePath(mContext.getFilesDir().getPath() + "/cache"); settings.setAppCacheEnabled(true); settings.setCacheMode(WebSettings.LOAD_DEFAULT); // Set Cache Mode: LOAD_NO_CACHE is noly for debug //settings.setCacheMode(WebSettings.LOAD_NO_CACHE); //enablePageCache(settings,5); //enableWorkers(settings); // Enable database settings.setDatabaseEnabled(true); String databasePath = mContext.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); // Enable DOM storage settings.setDomStorageEnabled(true); // Enable built-in geolocation settings.setGeolocationEnabled(true); // Improve render performance settings.setRenderPriority(WebSettings.RenderPriority.HIGH); if (Build.VERSION.SDK_INT >= 21) { settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } }
From source file:io.selendroid.server.model.SelendroidWebDriver.java
private void configureWebView(final WebView view) { ServerInstrumentation.getInstance().getCurrentActivity().runOnUiThread(new Runnable() { @Override/*from w w w . ja v a 2 s . co m*/ public void run() { try { view.clearCache(true); view.clearFormData(); view.clearHistory(); view.setFocusable(true); view.setFocusableInTouchMode(true); view.setNetworkAvailable(true); // need to check the class name rather than checking instanceof // since when it is not an instanceof, it likely means the app under test // does not contain the Cordova project and this will cause a RuntimeException if (view.getClass().getSimpleName().equalsIgnoreCase("CordovaWebView")) { CordovaWebView webview = (CordovaWebView) view; CordovaInterface ci = null; chromeClient = new ExtendedCordovaChromeClient(null, webview); } else { chromeClient = new SelendroidWebChromeClient(); } view.setWebChromeClient(chromeClient); WebSettings settings = view.getSettings(); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setSupportMultipleWindows(true); settings.setBuiltInZoomControls(true); settings.setJavaScriptEnabled(true); settings.setAppCacheEnabled(true); settings.setAppCacheMaxSize(10 * 1024 * 1024); settings.setAppCachePath(""); settings.setDatabaseEnabled(true); settings.setDomStorageEnabled(true); settings.setGeolocationEnabled(true); settings.setSaveFormData(false); settings.setSavePassword(false); settings.setRenderPriority(WebSettings.RenderPriority.HIGH); // Flash settings settings.setPluginState(WebSettings.PluginState.ON); // Geo location settings settings.setGeolocationEnabled(true); settings.setGeolocationDatabasePath("/data/data/selendroid"); } catch (Exception e) { SelendroidLogger.error("Error configuring web view", e); } } }); }
From source file:com.acrutiapps.browser.ui.components.CustomWebView.java
@SuppressLint("SetJavaScriptEnabled") public void loadSettings() { WebSettings settings = getSettings(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); settings.setJavaScriptEnabled(prefs.getBoolean(Constants.PREFERENCE_ENABLE_JAVASCRIPT, true)); settings.setLoadsImagesAutomatically(prefs.getBoolean(Constants.PREFERENCE_ENABLE_IMAGES, true)); settings.setUseWideViewPort(prefs.getBoolean(Constants.PREFERENCE_USE_WIDE_VIEWPORT, true)); settings.setLoadWithOverviewMode(prefs.getBoolean(Constants.PREFERENCE_LOAD_WITH_OVERVIEW, false)); settings.setGeolocationEnabled(prefs.getBoolean(Constants.PREFERENCE_ENABLE_GEOLOCATION, true)); settings.setSaveFormData(prefs.getBoolean(Constants.PREFERENCE_REMEMBER_FORM_DATA, true)); settings.setSavePassword(prefs.getBoolean(Constants.PREFERENCE_REMEMBER_PASSWORDS, true)); settings.setTextZoom(prefs.getInt(Constants.PREFERENCE_TEXT_SCALING, 100)); int minimumFontSize = prefs.getInt(Constants.PREFERENCE_MINIMUM_FONT_SIZE, 1); settings.setMinimumFontSize(minimumFontSize); settings.setMinimumLogicalFontSize(minimumFontSize); boolean useInvertedDisplay = prefs.getBoolean(Constants.PREFERENCE_INVERTED_DISPLAY, false); setWebSettingsProperty(settings, "inverted", useInvertedDisplay ? "true" : "false"); if (useInvertedDisplay) { setWebSettingsProperty(settings, "inverted_contrast", Float.toString(prefs.getInt(Constants.PREFERENCE_INVERTED_DISPLAY_CONTRAST, 100) / 100f)); }/*from w w w . j ava 2 s. co m*/ settings.setUserAgentString(prefs.getString(Constants.PREFERENCE_USER_AGENT, Constants.USER_AGENT_ANDROID)); settings.setPluginState(PluginState .valueOf(prefs.getString(Constants.PREFERENCE_PLUGINS, PluginState.ON_DEMAND.toString()))); CookieManager.getInstance().setAcceptCookie(prefs.getBoolean(Constants.PREFERENCE_ACCEPT_COOKIES, true)); settings.setSupportZoom(true); settings.setDisplayZoomControls(false); settings.setBuiltInZoomControls(true); settings.setSupportMultipleWindows(true); settings.setEnableSmoothTransition(true); if (mPrivateBrowsing) { settings.setGeolocationEnabled(false); settings.setSaveFormData(false); settings.setSavePassword(false); settings.setAppCacheEnabled(false); settings.setDatabaseEnabled(false); settings.setDomStorageEnabled(false); } else { // HTML5 API flags settings.setAppCacheEnabled(true); settings.setDatabaseEnabled(true); settings.setDomStorageEnabled(true); // HTML5 configuration settings. settings.setAppCacheMaxSize(3 * 1024 * 1024); settings.setAppCachePath(mContext.getDir("appcache", 0).getPath()); settings.setDatabasePath(mContext.getDir("databases", 0).getPath()); settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath()); } setLongClickable(true); setDownloadListener(this); }
From source file:org.apache.cordova.AndroidWebView.java
/** * Initialize webview.//w w w . j a v a2 s . co m */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") private void setup() { this.setInitialScale(0); this.setVerticalScrollBarEnabled(false); if (shouldRequestFocusOnInit()) { this.requestFocusFromTouch(); } // Enable JavaScript WebSettings settings = this.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); // Set the nav dump for HTC 2.x devices (disabling for ICS, deprecated entirely for Jellybean 4.2) try { Method gingerbread_getMethod = WebSettings.class.getMethod("setNavDump", new Class[] { boolean.class }); String manufacturer = android.os.Build.MANUFACTURER; Log.d(TAG, "CordovaWebView is running on device made by: " + manufacturer); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB && android.os.Build.MANUFACTURER.contains("HTC")) { gingerbread_getMethod.invoke(settings, true); } } catch (NoSuchMethodException e) { Log.d(TAG, "We are on a modern version of Android, we will deprecate HTC 2.3 devices in 2.8"); } catch (IllegalArgumentException e) { Log.d(TAG, "Doing the NavDump failed with bad arguments"); } catch (IllegalAccessException e) { Log.d(TAG, "This should never happen: IllegalAccessException means this isn't Android anymore"); } catch (InvocationTargetException e) { Log.d(TAG, "This should never happen: InvocationTargetException means this isn't Android anymore."); } //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 if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) Level16Apis.enableUniversalAccess(settings); // Enable database // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16 String databasePath = this.cordova.getActivity().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! try { final String packageName = this.cordova.getActivity().getPackageName(); final PackageManager pm = this.cordova.getActivity().getPackageManager(); ApplicationInfo appInfo; appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { setWebContentsDebuggingEnabled(true); } } catch (IllegalArgumentException e) { Log.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! "); e.printStackTrace(); } catch (NameNotFoundException e) { Log.d(TAG, "This should never happen: Your application's package can't be found."); e.printStackTrace(); } 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); String pathToCache = this.cordova.getActivity().getApplicationContext() .getDir("database", Context.MODE_PRIVATE).getPath(); settings.setAppCachePath(pathToCache); settings.setAppCacheEnabled(true); // Fix for CB-1405 // Google issue 4641 this.updateUserAgentString(); 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) { updateUserAgentString(); } }; this.cordova.getActivity().registerReceiver(this.receiver, intentFilter); } // end CB-1405 pluginManager = new PluginManager(this, this.cordova); jsMessageQueue = new NativeToJsMessageQueue(this, cordova); exposedJsApi = new AndroidExposedJsApi(pluginManager, jsMessageQueue); resourceApi = new CordovaResourceApi(this.getContext(), pluginManager); exposeJsInterface(); }