List of usage examples for android.webkit WebSettings LOAD_CACHE_ONLY
int LOAD_CACHE_ONLY
To view the source code for android.webkit WebSettings LOAD_CACHE_ONLY.
Click Source Link
From source file:org.safegees.safegees.gui.fragment.InfoFragment.java
public void setLoaderDependingConnectivity(boolean isConnected) { if (webView != null) { if (isConnected) { webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); } else {/*from www . j a va 2 s . c o m*/ webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY); } } }
From source file:com.danvelazco.fbwrapper.activity.BaseFacebookWebViewActivity.java
/** * Update the cache mode depending on the network connection state of the device. *//* ww w. j av a2 s .c o m*/ private void updateCacheMode() { if (checkNetworkConnection()) { Logger.d(LOG_TAG, "Setting cache mode to: LOAD_DEFAULT"); mWebSettings.setCacheMode(WebSettings.LOAD_DEFAULT); } else { Logger.d(LOG_TAG, "Setting cache mode to: LOAD_CACHE_ONLY"); mWebSettings.setCacheMode(WebSettings.LOAD_CACHE_ONLY); } }
From source file:org.chromium.android_webview.test.AwSettingsTest.java
@SmallTest @Feature({ "AndroidWebView", "Preferences" }) public void testCacheMode() throws Throwable { final TestAwContentsClient contentClient = new TestAwContentsClient(); final AwTestContainerView testContainer = createAwTestContainerViewOnMainSync(contentClient); final AwContents awContents = testContainer.getAwContents(); final AwSettings awSettings = getAwSettingsOnUiThread(testContainer.getAwContents()); clearCacheOnUiThread(awContents, true); assertEquals(WebSettings.LOAD_DEFAULT, awSettings.getCacheMode()); TestWebServer webServer = null;//from ww w . j a v a 2 s . com try { webServer = new TestWebServer(false); final String htmlPath = "/testCacheMode.html"; final String url = webServer.setResponse(htmlPath, "response", null); awSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); loadUrlSync(awContents, contentClient.getOnPageFinishedHelper(), url); assertEquals(1, webServer.getRequestCount(htmlPath)); loadUrlSync(awContents, contentClient.getOnPageFinishedHelper(), url); assertEquals(1, webServer.getRequestCount(htmlPath)); awSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); loadUrlSync(awContents, contentClient.getOnPageFinishedHelper(), url); assertEquals(2, webServer.getRequestCount(htmlPath)); loadUrlSync(awContents, contentClient.getOnPageFinishedHelper(), url); assertEquals(3, webServer.getRequestCount(htmlPath)); awSettings.setCacheMode(WebSettings.LOAD_CACHE_ONLY); loadUrlSync(awContents, contentClient.getOnPageFinishedHelper(), url); assertEquals(3, webServer.getRequestCount(htmlPath)); loadUrlSync(awContents, contentClient.getOnPageFinishedHelper(), url); assertEquals(3, webServer.getRequestCount(htmlPath)); final String htmlNotInCachePath = "/testCacheMode-not-in-cache.html"; final String urlNotInCache = webServer.setResponse(htmlNotInCachePath, "", null); loadUrlSyncAndExpectError(awContents, contentClient.getOnPageFinishedHelper(), contentClient.getOnReceivedErrorHelper(), urlNotInCache); assertEquals(0, webServer.getRequestCount(htmlNotInCachePath)); } finally { if (webServer != null) webServer.shutdown(); } }
From source file:org.chromium.android_webview.test.AwSettingsTest.java
@SmallTest @Feature({ "AndroidWebView", "Preferences" }) // As our implementation of network loads blocking uses the same net::URLRequest settings, make // sure that setting cache mode doesn't accidentally enable network loads. The reference // behaviour is that when network loads are blocked, setting cache mode has no effect. public void testCacheModeWithBlockedNetworkLoads() throws Throwable { final TestAwContentsClient contentClient = new TestAwContentsClient(); final AwTestContainerView testContainer = createAwTestContainerViewOnMainSync(contentClient); final AwContents awContents = testContainer.getAwContents(); final AwSettings awSettings = getAwSettingsOnUiThread(testContainer.getAwContents()); clearCacheOnUiThread(awContents, true); assertEquals(WebSettings.LOAD_DEFAULT, awSettings.getCacheMode()); awSettings.setBlockNetworkLoads(true); TestWebServer webServer = null;//from w w w .jav a 2 s . co m try { webServer = new TestWebServer(false); final String htmlPath = "/testCacheModeWithBlockedNetworkLoads.html"; final String url = webServer.setResponse(htmlPath, "response", null); loadUrlSyncAndExpectError(awContents, contentClient.getOnPageFinishedHelper(), contentClient.getOnReceivedErrorHelper(), url); assertEquals(0, webServer.getRequestCount(htmlPath)); awSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); loadUrlSyncAndExpectError(awContents, contentClient.getOnPageFinishedHelper(), contentClient.getOnReceivedErrorHelper(), url); assertEquals(0, webServer.getRequestCount(htmlPath)); awSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); loadUrlSyncAndExpectError(awContents, contentClient.getOnPageFinishedHelper(), contentClient.getOnReceivedErrorHelper(), url); assertEquals(0, webServer.getRequestCount(htmlPath)); awSettings.setCacheMode(WebSettings.LOAD_CACHE_ONLY); loadUrlSyncAndExpectError(awContents, contentClient.getOnPageFinishedHelper(), contentClient.getOnReceivedErrorHelper(), url); assertEquals(0, webServer.getRequestCount(htmlPath)); } finally { if (webServer != null) webServer.shutdown(); } }