check network state onResume. use cached tiles if on mobile network (see #225)
This commit is contained in:
parent
9575e4b4c2
commit
fb90f9139c
@ -127,6 +127,7 @@ public class IITC_Mobile extends Activity {
|
|||||||
Log.d("iitcm", "resuming...setting reset idleTimer");
|
Log.d("iitcm", "resuming...setting reset idleTimer");
|
||||||
iitc_view.loadUrl("javascript: window.idleTime = 0");
|
iitc_view.loadUrl("javascript: window.idleTime = 0");
|
||||||
iitc_view.loadUrl("javascript: window.renderUpdateStatus()");
|
iitc_view.loadUrl("javascript: window.renderUpdateStatus()");
|
||||||
|
iitc_view.updateCaching();
|
||||||
|
|
||||||
if (user_loc == true) {
|
if (user_loc == true) {
|
||||||
// Register the listener with the Location Manager to receive location updates
|
// Register the listener with the Location Manager to receive location updates
|
||||||
|
@ -2,7 +2,10 @@ package com.cradle.iitc_mobile;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
import android.webkit.WebChromeClient;
|
import android.webkit.WebChromeClient;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
@ -22,9 +25,10 @@ public class IITC_WebView extends WebView {
|
|||||||
settings.setDomStorageEnabled(true);
|
settings.setDomStorageEnabled(true);
|
||||||
settings.setAllowFileAccess(true);
|
settings.setAllowFileAccess(true);
|
||||||
settings.setGeolocationEnabled(true);
|
settings.setGeolocationEnabled(true);
|
||||||
|
settings.setAppCacheEnabled(true);
|
||||||
settings.setDatabasePath(this.getContext().getApplicationInfo().dataDir + "/databases/");
|
settings.setDatabasePath(this.getContext().getApplicationInfo().dataDir + "/databases/");
|
||||||
settings.setAppCachePath(this.getContext().getApplicationInfo().dataDir + "/cache/");
|
settings.setAppCachePath(this.getContext().getCacheDir().getAbsolutePath());
|
||||||
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
// use cache if on mobile network...saves traffic
|
||||||
this.js_interface = new IITC_JSInterface(c);
|
this.js_interface = new IITC_JSInterface(c);
|
||||||
this.addJavascriptInterface(js_interface, "android");
|
this.addJavascriptInterface(js_interface, "android");
|
||||||
|
|
||||||
@ -69,4 +73,21 @@ public class IITC_WebView extends WebView {
|
|||||||
return this.js_interface;
|
return this.js_interface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateCaching() {
|
||||||
|
if (!this.isConnectedToWifi())
|
||||||
|
{
|
||||||
|
Log.d("iitcm", "not connected to wifi...load tiles from cache");
|
||||||
|
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
||||||
|
} else {
|
||||||
|
Log.d("iitcm", "connected to wifi...load tiles network");
|
||||||
|
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isConnectedToWifi() {
|
||||||
|
ConnectivityManager conMan = (ConnectivityManager) getContext().getSystemService( Context.CONNECTIVITY_SERVICE );
|
||||||
|
NetworkInfo wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||||
|
return wifi.getState() == NetworkInfo.State.CONNECTED;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user