diff --git a/mobile/IITC_Mobile.iml b/mobile/IITC_Mobile.iml
index 7647439e..66d0a847 100644
--- a/mobile/IITC_Mobile.iml
+++ b/mobile/IITC_Mobile.iml
@@ -9,7 +9,7 @@
-
+
diff --git a/mobile/res/values/strings.xml b/mobile/res/values/strings.xml
index abec316b..e6fb797d 100644
--- a/mobile/res/values/strings.xml
+++ b/mobile/res/values/strings.xml
@@ -97,8 +97,8 @@
Nice for tablets, looks awful on smartphones
Force https
Disabling may improve performance
- Move cache to external storage
- Restart required! Write cache to sdCard. Saves internal storage.
+ Move tiles cache to external storage
+ Restart required! Write cache to sdCard.
External storage has to be mounted.
Press back button twice to exit
Avoids accidental exits
@@ -116,10 +116,6 @@
IITC source
Load IITC main script from url or use local script. Currently used source:
- Aggressive Caching
- Prefer cached values even if they are expired…saves traffic but
- may result in login issues
-
- System Bar
- Action Bar
@@ -133,17 +129,6 @@
- 16
-
- - Always
- - Mobile data only (default)
- - Never
-
-
- - 0
- - 1
- - 2
-
-
Clear Cookies
Search
Choose account to login
diff --git a/mobile/res/xml/preferences.xml b/mobile/res/xml/preferences.xml
index df042414..089dcebc 100644
--- a/mobile/res/xml/preferences.xml
+++ b/mobile/res/xml/preferences.xml
@@ -112,14 +112,6 @@
-
-
= Build.VERSION_CODES.KITKAT && (mFullscreenStatus & FS_SYSBAR) != 0) {
- systemUiVisibility |= SYSTEM_UI_FLAG_IMMERSIVE;
- }
- setSystemUiVisibility(systemUiVisibility);
+ if (isInFullscreen() && (getFullscreenStatus() & (FS_NAVBAR)) != 0) {
+ int systemUiVisibility = SYSTEM_UI_FLAG_HIDE_NAVIGATION;
+ // in immersive mode the user can interact with the app while the navbar is hidden
+ // this mode is available since KitKat
+ // you can leave this mode by swiping down from the top of the screen. this does only work
+ // when the app is in total-fullscreen mode
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && (mFullscreenStatus & FS_SYSBAR) != 0) {
+ systemUiVisibility |= SYSTEM_UI_FLAG_IMMERSIVE;
}
+ setSystemUiVisibility(systemUiVisibility);
+ }
}
};
- setWebChromeClient(new WebChromeClient() {
- /**
- * our webchromeclient should share geolocation with the iitc script
- *
- * allow access by default
- */
- @Override
- public void onGeolocationPermissionsShowPrompt(String origin,
- GeolocationPermissions.Callback callback) {
- callback.invoke(origin, true, false);
- }
-
- /**
- * display progress bar in activity
- */
- @Override
- public void onProgressChanged(WebView view, int newProgress) {
- super.onProgressChanged(view, newProgress);
-
- // maximum for newProgress is 100
- // maximum for setProgress is 10,000
- ((Activity) getContext()).setProgress(newProgress * 100);
- }
-
- /**
- * remove splash screen if any JS error occurs
- */
- @Override
- public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
- if (consoleMessage.messageLevel() == ConsoleMessage.MessageLevel.ERROR) {
- mIitc.setLoadingState(false);
- }
- return super.onConsoleMessage(consoleMessage);
- }
- });
-
- mIitcWebViewClient = new IITC_WebViewClient(c);
+ mIitcWebChromeClient = new IITC_WebChromeClient(mIitc);
+ setWebChromeClient(mIitcWebChromeClient);
+ mIitcWebViewClient = new IITC_WebViewClient(mIitc);
setWebViewClient(mIitcWebViewClient);
}
@@ -271,36 +236,8 @@ public class IITC_WebView extends WebView {
return mJsInterface;
}
- public void updateCaching(boolean login) {
- switch (Integer.parseInt(mSharedPrefs.getString("pref_caching", "1"))) {
- case 0:
- mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
- break;
- case 2:
- mSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
- break;
- default:
- if (getUrl() != null) {
- login |= getUrl().contains("accounts.google.com");
- }
- // use cache if on mobile network...saves traffic
- if (!isConnectedToWifi() && !login) {
- Log.d("iitcm", "not connected to wifi...load tiles from cache");
- mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
- } else {
- if (login) {
- Log.d("iitcm", "login...load tiles from network");
- } else {
- Log.d("iitcm", "connected to wifi...load tiles from network");
- }
- mSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
- }
- break;
- }
- }
-
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
- private boolean isConnectedToWifi() {
+ public boolean isConnectedToWifi() {
ConnectivityManager conMan = (ConnectivityManager) getContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java
index f1e8af47..8d9e022d 100644
--- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java
+++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java
@@ -43,10 +43,12 @@ public class IITC_WebViewClient extends WebViewClient {
private String mIitcScript = null;
private String mIitcPath = null;
private boolean mIitcInjected = false;
- private final Context mContext;
+ private final IITC_Mobile mIitc;
+ private final IITC_TileManager mTileManager;
- public IITC_WebViewClient(Context c) {
- this.mContext = c;
+ public IITC_WebViewClient(IITC_Mobile iitc) {
+ this.mIitc = iitc;
+ this.mTileManager = new IITC_TileManager(mIitc);
this.mIitcPath = Environment.getExternalStorageDirectory().getPath()
+ "/IITC_Mobile/";
}
@@ -113,13 +115,13 @@ public class IITC_WebViewClient extends WebViewClient {
js = this.fileToString(mIitcPath
+ "dev/total-conversion-build.user.js", false);
if (js.equals("false")) {
- Toast.makeText(mContext, "File " + mIitcPath +
+ Toast.makeText(mIitc, "File " + mIitcPath +
"dev/total-conversion-build.user.js not found. " +
"Disable developer mode or add iitc files to the dev folder.",
Toast.LENGTH_LONG).show();
return;
} else {
- Toast.makeText(mContext, "Developer mode enabled",
+ Toast.makeText(mIitc, "Developer mode enabled",
Toast.LENGTH_SHORT).show();
}
} else {
@@ -145,7 +147,7 @@ public class IITC_WebViewClient extends WebViewClient {
mIitcInjected = false;
}
- PackageManager pm = mContext.getPackageManager();
+ PackageManager pm = mIitc.getPackageManager();
boolean hasMultitouch = pm
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
boolean forcedZoom = sharedPref.getBoolean("pref_user_zoom", false);
@@ -193,8 +195,6 @@ public class IITC_WebViewClient extends WebViewClient {
@Override
public void onReceivedLoginRequest(WebView view, String realm, String account, String args) {
Log.d("iitcm", "Login requested: " + realm + " " + account + " " + args);
- Log.d("iitcm", "logging in...updating caching mode");
- ((IITC_WebView) view).updateCaching(true);
mIitcInjected = false;
//((IITC_Mobile) mContext).onReceivedLoginRequest(this, view, realm, account, args);
}
@@ -202,7 +202,7 @@ public class IITC_WebViewClient extends WebViewClient {
public void loadPlugins(WebView view) {
// get the plugin preferences
SharedPreferences sharedPref = PreferenceManager
- .getDefaultSharedPreferences(mContext);
+ .getDefaultSharedPreferences(mIitc);
boolean dev_enabled = sharedPref.getBoolean("pref_dev_checkbox", false);
String path = (dev_enabled) ? mIitcPath + "dev/plugins/" : "plugins/";
@@ -261,7 +261,7 @@ public class IITC_WebViewClient extends WebViewClient {
}
} else {
// load plugins from asset folder
- AssetManager am = mContext.getAssets();
+ AssetManager am = mIitc.getAssets();
try {
s = new Scanner(am.open(file)).useDelimiter("\\A");
} catch (IOException e) {
@@ -285,7 +285,20 @@ public class IITC_WebViewClient extends WebViewClient {
@Override
public WebResourceResponse shouldInterceptRequest(final WebView view,
String url) {
- if (url.contains("/css/common.css")) {
+ // if any tiles are requested, handle it with IITC_TileManager
+ if (url.matches(".*tile.*jpg.*") // mapquest tiles | ovi tiles
+ || url.matches(".*tile.*png.*") // cloudmade tiles
+ || url.matches(".*mts.*googleapis.*smartmaps") // google tiles
+ || url.matches(".*tile.*jpeg.*") // bing tiles
+ || url.matches(".*maps.*yandex.*tiles.*") // yandex maps
+ ) {
+ try {
+ return mTileManager.getTile(url);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return super.shouldInterceptRequest(view, url);
+ }
+ } else if (url.contains("/css/common.css")) {
return new WebResourceResponse("text/css", "UTF-8", STYLE);
// } else if (url.contains("gen_dashboard.js")) {
// // define initialize function to get rid of JS ReferenceError on intel page's 'onLoad'
@@ -318,11 +331,7 @@ public class IITC_WebViewClient extends WebViewClient {
Log.d("iitcm",
"should be an internal clicked position link...reload script for: "
+ url);
- ((IITC_Mobile) mContext).loadUrl(url);
- }
- if (url.contains("logout")) {
- Log.d("iitcm", "logging out...updating caching mode");
- ((IITC_WebView) view).updateCaching(true);
+ mIitc.loadUrl(url);
}
return false;
} else {
@@ -330,7 +339,7 @@ public class IITC_WebViewClient extends WebViewClient {
"no ingress intel link, start external app to load url: "
+ url);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
- mContext.startActivity(intent);
+ mIitc.startActivity(intent);
return true;
}
}
diff --git a/mobile/src/com/cradle/iitc_mobile/async/DownloadTile.java b/mobile/src/com/cradle/iitc_mobile/async/DownloadTile.java
new file mode 100644
index 00000000..42882c93
--- /dev/null
+++ b/mobile/src/com/cradle/iitc_mobile/async/DownloadTile.java
@@ -0,0 +1,62 @@
+package com.cradle.iitc_mobile.async;
+
+import android.os.AsyncTask;
+import android.util.Log;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+public class DownloadTile extends AsyncTask {
+
+ private String mFilePath;
+ private String mFileName;
+
+ public DownloadTile(String path, String fileName) {
+ mFilePath = path;
+ mFileName = fileName;
+
+ }
+
+ @Override
+ protected Boolean doInBackground(String... urls) {
+ URL tileUrl = null;
+ URLConnection conn = null;
+ try {
+ tileUrl = new URL(urls[0]);
+ conn = tileUrl.openConnection();
+ File file = new File(mFilePath, mFileName);
+ // update tile if needed, else return
+ if (conn.getLastModified() < file.lastModified()) return true;
+ InputStream is = null;
+ is = conn.getInputStream();
+ Log.d("iitcm", "writing to file: " + file.toString());
+ File output = writeTileToFile(is, file, mFilePath);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ private File writeTileToFile(InputStream inStream, File file, String path) throws Exception {
+ File filePath = new File(path);
+ filePath.mkdirs();
+ FileOutputStream outStream = new FileOutputStream(file);
+ int bufferSize = 1024;
+ byte[] buffer = new byte[bufferSize];
+ int len = 0;
+ while ((len = inStream.read(buffer)) != -1) {
+ outStream.write(buffer, 0, len);
+ }
+ if(outStream!=null) outStream.close();
+ return file;
+ }
+
+}