From 9575e4b4c27acc78c1259cb6fe0f6036c74ba1d7 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Fri, 3 May 2013 05:39:54 +0100 Subject: [PATCH 01/14] website - fix loading version number from renamed internal assets - remove various php notice/warnings from the webserver logs --- website/index.php | 4 +++- website/page/code/mobile-download.php | 20 +++++++++++++------- website/page/code/userscript.php | 2 +- website/page/test.php | 11 +++++++---- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/website/index.php b/website/index.php index 2e3ee02d..559bd540 100644 --- a/website/index.php +++ b/website/index.php @@ -86,7 +86,9 @@ $pages = Array ( 'donate' => ' Donate', ); -$page = $_REQUEST['page']; +$page = 'home'; +if ( array_key_exists ( 'page', $_REQUEST ) ) + $page = $_REQUEST['page']; if ( ! array_key_exists ( $page, $pages ) ) $page = "home"; diff --git a/website/page/code/mobile-download.php b/website/page/code/mobile-download.php index 9a15e8de..5da156a6 100644 --- a/website/page/code/mobile-download.php +++ b/website/page/code/mobile-download.php @@ -17,15 +17,21 @@ function getMobileVersion ( $apkfile ) $archive = $apkinfo->getApkArchive(); - $iitc_file = "assets/total-conversion-build.user.js"; - if ( $archive->statName ( $iitc_file ) === FALSE ); - $iitc_file = "assets/iitc.js"; - $stream = $archive->getStream ( $iitc_file ); + $stream = $archive->getStream ( "assets/total-conversion-build.user.js" ); + if ( ! $stream ) + $stream = $archive->getStream ( "assets/iitc.js" ); - $header = loadUserScriptHeader ( $stream ); + if ( $stream ) + { + $header = loadUserScriptHeader ( $stream ); - $result['iitc_version'] = $header['@version']; + $result['iitc_version'] = $header['@version']; + } + else + { + $result['iitc_version'] = 'unknown'; + } return $result; } @@ -40,7 +46,7 @@ function iitcMobileDownload ( $apkfile ) # we need an absolute link for the QR Code # get the URL of this page itself - $pageurl = ($_SERVER['HTTPS'] ? "https" : "http")."://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; + $pageurl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? "https" : "http")."://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $apkurl = url_to_absolute ( $pageurl, $apkfile ); ?> diff --git a/website/page/code/userscript.php b/website/page/code/userscript.php index c229df76..845cc116 100644 --- a/website/page/code/userscript.php +++ b/website/page/code/userscript.php @@ -26,7 +26,7 @@ function loadUserScriptHeader($file) } } - fclose ( $f ); + fclose ( $file ); return $result; } diff --git a/website/page/test.php b/website/page/test.php index c91bdee0..db491779 100644 --- a/website/page/test.php +++ b/website/page/test.php @@ -19,10 +19,13 @@ include_once ( "code/desktop-download.php" ); $path = "test"; -if ( $_REQUEST['build'] == 'experimental' ) - $path = "experimental"; -if ( $_REQUEST['build'] == 'dev' ) - $path = "dev"; +if ( array_key_exists ( 'build', $_REQUEST ) ) +{ + if ( $_REQUEST['build'] == 'experimental' ) + $path = "experimental"; + if ( $_REQUEST['build'] == 'dev' ) + $path = "dev"; +} if ( $path != "test" ) print "
NOTE: A non-standard test build, $path, is currently selected. The notes may not apply! Return to the standard test build.
"; From fb90f9139cd91fc63b3fa65f0c8bd277c2e5112d Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Fri, 3 May 2013 11:34:57 +0200 Subject: [PATCH 02/14] check network state onResume. use cached tiles if on mobile network (see #225) --- .../com/cradle/iitc_mobile/IITC_Mobile.java | 1 + .../com/cradle/iitc_mobile/IITC_WebView.java | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index b779b756..702727c7 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -127,6 +127,7 @@ public class IITC_Mobile extends Activity { Log.d("iitcm", "resuming...setting reset idleTimer"); iitc_view.loadUrl("javascript: window.idleTime = 0"); iitc_view.loadUrl("javascript: window.renderUpdateStatus()"); + iitc_view.updateCaching(); if (user_loc == true) { // Register the listener with the Location Manager to receive location updates diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java index ab9eb115..9da7655b 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java @@ -2,7 +2,10 @@ package com.cradle.iitc_mobile; import android.annotation.SuppressLint; import android.content.Context; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; import android.util.AttributeSet; +import android.util.Log; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; @@ -22,9 +25,10 @@ public class IITC_WebView extends WebView { settings.setDomStorageEnabled(true); settings.setAllowFileAccess(true); settings.setGeolocationEnabled(true); + settings.setAppCacheEnabled(true); settings.setDatabasePath(this.getContext().getApplicationInfo().dataDir + "/databases/"); - settings.setAppCachePath(this.getContext().getApplicationInfo().dataDir + "/cache/"); - settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); + settings.setAppCachePath(this.getContext().getCacheDir().getAbsolutePath()); + // use cache if on mobile network...saves traffic this.js_interface = new IITC_JSInterface(c); this.addJavascriptInterface(js_interface, "android"); @@ -69,4 +73,21 @@ public class IITC_WebView extends WebView { 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; + } + } From 530c3cecf1c997c16a0cf35f06a6a6068123def9 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Fri, 3 May 2013 19:49:12 +0100 Subject: [PATCH 03/14] build script - add optional preBuild and postBuild settings, to allow one or more additional commands to be executed as part of a build. could be used to copy builds to a web server, copy additional files (E.g. .htaccess), trigger browser refresh, etc --- build.py | 10 ++++++++++ buildsettings.py | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/build.py b/build.py index 055c2ef8..270acab0 100755 --- a/build.py +++ b/build.py @@ -168,6 +168,11 @@ else: os.makedirs(outDir) +# run any preBuild commands +for cmd in settings.get('preBuild',[]): + os.system ( cmd ) + + # load main.js, parse, and create main total-conversion-build.user.js main = readfile('main.js') @@ -242,4 +247,9 @@ if buildMobile: shutil.copy("mobile/bin/IITC_Mobile-%s.apk" % buildMobile, os.path.join(outDir,"IITC_Mobile-%s.apk" % buildMobile) ) +# run any postBuild commands +for cmd in settings.get('postBuild',[]): + os.system ( cmd ) + + # vim: ai si ts=4 sw=4 sts=4 et diff --git a/buildsettings.py b/buildsettings.py index 9735ea9f..986b44e9 100644 --- a/buildsettings.py +++ b/buildsettings.py @@ -2,6 +2,14 @@ # if you want to have custom builds, copy this file to "localbuildsettings.py" and make changes there. +# possible fields: +# resourceBaseUrl - optional - the URL base for external resources (all resources embedded in standard IITC) +# distUrlBase - optional - the base URL to use for update checks +# buildMobild - optional - if set, mobild builds are built with 'ant'. requires the Android SDK and appropriate mobile/local.properties file configured +# preBuild - optional - an array of strings to run as commands, via os.system, before building the scripts +# postBuild - optional - an array of string to run as commands, via os.system, after all builds are complete + + buildSettings = { # local: use this build if you're not modifying external resources # no external resources allowed - they're not needed any more @@ -40,6 +48,7 @@ buildSettings = { } + # defaultBuild - the name of the default build to use if none is specified on the build.py command line # (in here as an example - it only works in localbuildsettings.py) #defaultBuild = 'local' From f6e6b76249653428e3bac07c808908ec6e453dd9 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Fri, 3 May 2013 23:53:46 +0200 Subject: [PATCH 04/14] made force-https an option in mobile settings. removed plugin from build --- build.py | 17 +------ mobile/.gitignore | 2 +- mobile/res/values/strings.xml | 2 + mobile/res/xml/preferences.xml | 5 ++ .../com/cradle/iitc_mobile/IITC_Mobile.java | 4 +- .../com/cradle/iitc_mobile/IITC_Settings.java | 48 +++++++++---------- .../com/cradle/iitc_mobile/IITC_WebView.java | 18 ++++++- .../iitc_mobile/IITC_WebViewClient.java | 35 +++++++------- 8 files changed, 67 insertions(+), 64 deletions(-) diff --git a/build.py b/build.py index 270acab0..a81bfe34 100755 --- a/build.py +++ b/build.py @@ -196,15 +196,6 @@ for fn in glob.glob("plugins/*.user.js"): metafn = fn.replace('.user.js', '.meta.js') saveScriptAndMeta(script, os.path.join(outDir,fn), os.path.join(outDir,metafn)) -def copytree(src, dst, symlinks=False, ignore=None): - for item in os.listdir(src): - s = os.path.join(src, item) - d = os.path.join(dst, item) - if os.path.isdir(s): - shutil.copytree(s, d, symlinks, ignore) - else: - shutil.copy2(s, d) - # if we're building mobile too if buildMobile: if buildMobile not in ['debug','release','copyonly']: @@ -228,13 +219,9 @@ if buildMobile: shutil.copy(os.path.join(outDir,"total-conversion-build.user.js"), "mobile/assets/total-conversion-build.user.js") # copy the user location script into the mobile folder. shutil.copy(os.path.join(outDir,"user-location.user.js"), "mobile/assets/user-location.user.js") - # also copy plugins - try: - os.makedirs("mobile/assets/plugins") - except: - pass - copytree(os.path.join(outDir,"plugins"), "mobile/assets/plugins") + shutil.rmtree("mobile/assets/plugins") + shutil.copytree(os.path.join(outDir,"plugins"), "mobile/assets/plugins", ignore=shutil.ignore_patterns('*.meta.js', 'force-https*')) if buildMobile != 'copyonly': diff --git a/mobile/.gitignore b/mobile/.gitignore index c104ea4e..42e4ba7c 100644 --- a/mobile/.gitignore +++ b/mobile/.gitignore @@ -6,6 +6,6 @@ gen/ libs/ proguard-project.txt local.properties -assets/iitc.js +assets/total-conversion-build.user.js assets/user-location.user.js assets/plugins/ diff --git a/mobile/res/values/strings.xml b/mobile/res/values/strings.xml index 26a51274..b4fc8de0 100644 --- a/mobile/res/values/strings.xml +++ b/mobile/res/values/strings.xml @@ -37,6 +37,8 @@ Nice for tablets, looks awful on smartphones Display user location Show users position on map + Force https + Disabling may improve performance Developer options Enable developer mode If enabled, all IITC sources will be loaded from external storage of the Android device. diff --git a/mobile/res/xml/preferences.xml b/mobile/res/xml/preferences.xml index 432b0eab..c667e8f0 100644 --- a/mobile/res/xml/preferences.xml +++ b/mobile/res/xml/preferences.xml @@ -36,6 +36,11 @@ android:key="pref_plugins" android:title="@string/pref_plugins" android:dialogTitle="@string/pref_plugins_title"/> + asset_values = new ArrayList(); for (int i = 0; i < asset_array.length ; i++) { - if (asset_array[i].endsWith("user.js")) { - // find user plugin name for user readable entries - Scanner s = null; - String src = ""; - try { - s = new Scanner(am.open("plugins/" + asset_array[i])).useDelimiter("\\A"); - } catch (IOException e2) { - // TODO Auto-generated catch block - e2.printStackTrace(); - } - if (s != null) src = s.hasNext() ? s.next() : ""; - String header = src.substring(src.indexOf("==UserScript=="), src.indexOf("==/UserScript==")); - // remove new line comments and replace with space - // this way we get double spaces instead of newline + double slash - header = header.replace("\n//", " "); - // get a list of key-value...split on multiple spaces - String[] attributes = header.split(" +"); - String plugin_name = "not found"; - for (int j = 0; j < attributes.length; j++) { - // search for name and use the value - if (attributes[j].equals("@name")) plugin_name = attributes[j+1]; - } - asset_list.add(plugin_name); - // real value - asset_values.add(asset_array[i]); + // find user plugin name for user readable entries + Scanner s = null; + String src = ""; + try { + s = new Scanner(am.open("plugins/" + asset_array[i])).useDelimiter("\\A"); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); } + if (s != null) src = s.hasNext() ? s.next() : ""; + String header = src.substring(src.indexOf("==UserScript=="), src.indexOf("==/UserScript==")); + // remove new line comments and replace with space + // this way we get double spaces instead of newline + double slash + header = header.replace("\n//", " "); + // get a list of key-value...split on multiple spaces + String[] attributes = header.split(" +"); + String plugin_name = "not found"; + for (int j = 0; j < attributes.length; j++) { + // search for name and use the value + if (attributes[j].equals("@name")) plugin_name = attributes[j+1]; + } + asset_list.add(plugin_name); + // real value + asset_values.add(asset_array[i]); } Bundle bundle = getIntent().getExtras(); diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java index 9da7655b..ba705db9 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java @@ -2,8 +2,10 @@ package com.cradle.iitc_mobile; import android.annotation.SuppressLint; import android.content.Context; +import android.content.SharedPreferences; import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.preference.PreferenceManager; import android.util.AttributeSet; import android.util.Log; import android.webkit.WebChromeClient; @@ -65,6 +67,20 @@ public class IITC_WebView extends WebView { } //---------------------------------------------------------------- + @Override + public void loadUrl(String url) { + if (!url.startsWith("javascript:")) { + // force https if enabled in settings + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); + if (sharedPref.getBoolean("pref_force_https", true)) + url = url.replace("http://", "https://"); + else + url = url.replace("https://", "http://"); + Log.d("iitcm", "loading url: " + url); + } + super.loadUrl(url); + } + public IITC_WebViewClient getWebViewClient() { return this.webclient; } @@ -79,7 +95,7 @@ public class IITC_WebView extends WebView { 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"); + Log.d("iitcm", "connected to wifi...load tiles from network"); settings.setCacheMode(WebSettings.LOAD_DEFAULT); } } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java index 60f428c5..4f86d261 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java @@ -135,27 +135,24 @@ public class IITC_WebViewClient extends WebViewClient { String[] plugin_array = plugin_list.toArray(new String[0]); for(int i = 0; i < plugin_list.size(); i++) { - if (plugin_array[i].endsWith("user.js")); - { - Log.d("iitcm", "adding plugin " + plugin_array[i]); - Scanner s = null; - String src = ""; - try { - // load plugins from external storage if dev mode are enabled - if (dev_enabled) { - File js_file = new File(dev_path + "plugins/" + plugin_array[i]); - s = new Scanner(js_file).useDelimiter("\\A"); - } - else - // load plugins from asset folder - s = new Scanner(am.open("plugins/" + plugin_array[i])).useDelimiter("\\A"); - } catch (IOException e2) { - // TODO Auto-generated catch block - e2.printStackTrace(); + Log.d("iitcm", "adding plugin " + plugin_array[i]); + Scanner s = null; + String src = ""; + try { + // load plugins from external storage if dev mode are enabled + if (dev_enabled) { + File js_file = new File(dev_path + "plugins/" + plugin_array[i]); + s = new Scanner(js_file).useDelimiter("\\A"); } - if (s != null) src = s.hasNext() ? s.next() : ""; - view.loadUrl("javascript:" + src); + else + // load plugins from asset folder + s = new Scanner(am.open("plugins/" + plugin_array[i])).useDelimiter("\\A"); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); } + if (s != null) src = s.hasNext() ? s.next() : ""; + view.loadUrl("javascript:" + src); } } From 710f4bf04eaddb18b1f45b72a1dde75f840a31aa Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sat, 4 May 2013 00:08:48 +0200 Subject: [PATCH 05/14] added possibility to load additional plugins from /sdcard/IITC_Mobile/plugins/ --- mobile/AndroidManifest.xml | 4 +-- .../iitc_mobile/IITC_WebViewClient.java | 35 +++++++++++++------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/mobile/AndroidManifest.xml b/mobile/AndroidManifest.xml index 460d70f3..55924f6c 100644 --- a/mobile/AndroidManifest.xml +++ b/mobile/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="16" + android:versionName="0.3.4" > /IITC-Mobile/plugins/ + File directory = new File(iitc_path + "plugins/"); + File[] files = directory.listFiles(); + if (files != null) { + for (int i = 0; i < files.length; ++i) { + try { + String src = ""; + Scanner s = new Scanner(files[i]).useDelimiter("\\A"); + if (s != null) src = s.hasNext() ? s.next() : ""; + Log.d("iitcm", "Loading additional plugin " + iitc_path + files[i]); + view.loadUrl("javascript:" + src); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + } } public void enableTracking(WebView view, boolean dev_enabled) { @@ -169,14 +185,13 @@ public class IITC_WebViewClient extends WebViewClient { try { // load plugin from external storage if dev mode are enabled if (dev_enabled) { - File js_file = new File(dev_path + "user-location.user.js"); + File js_file = new File(iitc_path + "/dev/user-location.user.js"); s = new Scanner(js_file).useDelimiter("\\A"); } else // load plugin from asset folder s = new Scanner(am.open("user-location.user.js")).useDelimiter("\\A"); } catch (IOException e2) { - // TODO Auto-generated catch block e2.printStackTrace(); } if (s != null) src = s.hasNext() ? s.next() : ""; From e57c0b65dd131affc76a1f66f202a2075e43a945 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sat, 4 May 2013 00:24:00 +0200 Subject: [PATCH 06/14] load only *.user.js files as additional plugins --- mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java index 6214883d..d856e6da 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java @@ -165,6 +165,9 @@ public class IITC_WebViewClient extends WebViewClient { if (files != null) { for (int i = 0; i < files.length; ++i) { try { + // the file should be a user.js-file + if (!files[i].toString().endsWith("user.js")) + continue; String src = ""; Scanner s = new Scanner(files[i]).useDelimiter("\\A"); if (s != null) src = s.hasNext() ? s.next() : ""; From 5c254c95b4e258a03a4d4dbfe3d694bfad015a51 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sat, 4 May 2013 01:01:51 +0200 Subject: [PATCH 07/14] added toggle fullscreen button (see #237) --- mobile/AndroidManifest.xml | 4 ++-- mobile/res/menu/main.xml | 5 ++++ mobile/res/values/strings.xml | 1 + .../com/cradle/iitc_mobile/IITC_Mobile.java | 23 +++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/mobile/AndroidManifest.xml b/mobile/AndroidManifest.xml index 55924f6c..51f57ac3 100644 --- a/mobile/AndroidManifest.xml +++ b/mobile/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="17" + android:versionName="0.3.5" > + + Reload IITC Print Version Clear Cache + Toggle fullscreen Get Location local close diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 3831a9ac..9206bd3c 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -24,6 +24,7 @@ import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.ViewTreeObserver.OnGlobalLayoutListener; +import android.view.WindowManager; import android.widget.Toast; public class IITC_Mobile extends Activity { @@ -37,6 +38,7 @@ public class IITC_Mobile extends Activity { private LocationManager loc_mngr = null; private LocationListener loc_listener = null; private boolean keyboad_open = false; + private boolean fullscreen_mode = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -181,6 +183,17 @@ public class IITC_Mobile extends Activity { // we want a self defined behavior for the back button @Override public void onBackPressed() { + // leave fullscreen mode if it is enabled + if (fullscreen_mode) { + // get back action bar + this.getActionBar().show(); + // show notification bar again + WindowManager.LayoutParams attrs = getWindow().getAttributes(); + attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN; + this.getWindow().setAttributes(attrs); + this.fullscreen_mode = false; + return; + } if (this.back_button_pressed) { super.onBackPressed(); return; @@ -219,6 +232,16 @@ public class IITC_Mobile extends Activity { iitc_view.clearFormData(); iitc_view.clearCache(true); return true; + // toggle fullscreen + case R.id.toggle_fullscreen: + // get rid of action bar + this.getActionBar().hide(); + // hide notification bar + WindowManager.LayoutParams attrs = getWindow().getAttributes(); + attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN; + this.getWindow().setAttributes(attrs); + this.fullscreen_mode = true; + return true; // get the users current location and focus it on map case R.id.locate: iitc_view.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 13});"); From 68c089664fc53fb97886054d1e0e09b16f561fa8 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sat, 4 May 2013 01:04:38 +0200 Subject: [PATCH 08/14] show a toast when entering fullscreen mode (see #237) --- mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 9206bd3c..449d8ea0 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -241,6 +241,8 @@ public class IITC_Mobile extends Activity { attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN; this.getWindow().setAttributes(attrs); this.fullscreen_mode = true; + // show a little toast for the user + Toast.makeText(this, "Press back button to exit fullscreen", Toast.LENGTH_SHORT).show(); return true; // get the users current location and focus it on map case R.id.locate: From bbeecfaaafe62fdeaa498d7fb4de91944cff8a81 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sat, 4 May 2013 01:10:01 +0200 Subject: [PATCH 09/14] disable fullscreen if 'toggle fullscreen' is pressed from fullscreen --- .../com/cradle/iitc_mobile/IITC_Mobile.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 449d8ea0..04bf99b1 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -234,15 +234,26 @@ public class IITC_Mobile extends Activity { return true; // toggle fullscreen case R.id.toggle_fullscreen: - // get rid of action bar - this.getActionBar().hide(); - // hide notification bar - WindowManager.LayoutParams attrs = getWindow().getAttributes(); - attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN; - this.getWindow().setAttributes(attrs); - this.fullscreen_mode = true; - // show a little toast for the user - Toast.makeText(this, "Press back button to exit fullscreen", Toast.LENGTH_SHORT).show(); + if (!this.fullscreen_mode) { + // get rid of action bar + this.getActionBar().hide(); + // hide notification bar + WindowManager.LayoutParams attrs = getWindow().getAttributes(); + attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN; + this.getWindow().setAttributes(attrs); + this.fullscreen_mode = true; + // show a little toast for the user + Toast.makeText(this, "Press back button to exit fullscreen", Toast.LENGTH_SHORT).show(); + } + else { + // get back action bar + this.getActionBar().show(); + // show notification bar again + WindowManager.LayoutParams attrs = getWindow().getAttributes(); + attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN; + this.getWindow().setAttributes(attrs); + this.fullscreen_mode = false; + } return true; // get the users current location and focus it on map case R.id.locate: From 041c7dd0bdd795aa342d0dabb79f89970a8fdc84 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sat, 4 May 2013 11:36:32 +0200 Subject: [PATCH 10/14] own method for js-file to string...improve code readability --- .../iitc_mobile/IITC_WebViewClient.java | 110 +++++++++--------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java index d856e6da..d4b003d7 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java @@ -18,7 +18,6 @@ import android.widget.Toast; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileNotFoundException; -import java.io.InputStream; import java.io.IOException; import java.net.URL; import java.util.Scanner; @@ -69,31 +68,23 @@ public class IITC_WebViewClient extends WebViewClient { // if developer mode are enabled, load all iitc script from external storage if (sharedPref.getBoolean("pref_dev_checkbox", true)) { - File js_file = new File(iitc_path + "/dev/total-conversion-build.user.js"); - if (!js_file.exists()) { + js = this.fileToString(iitc_path + "/dev/total-conversion-build.user.js", false); + if (js.equals("false")) { Toast.makeText(context, "File " + iitc_path + "/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(context, "Developer mode enabled", Toast.LENGTH_SHORT).show(); } - Scanner s = null; - s = new Scanner(js_file).useDelimiter("\\A"); - if (s != null) js = s.hasNext() ? s.next() : ""; } else { // load iitc script from web or asset folder if (iitc_source.contains("http")) { URL url = new URL(iitc_source); js = new Scanner(url.openStream(), "UTF-8").useDelimiter("\\A").next(); } else { - InputStream input; - input = c.getAssets().open("total-conversion-build.user.js"); - int size = input.available(); - byte[] buffer = new byte[size]; - input.read(buffer); - input.close(); - js = new String(buffer); + js = this.fileToString("total-conversion-build.user.js", true); } } @@ -131,27 +122,14 @@ public class IITC_WebViewClient extends WebViewClient { // iterate through all enabled plugins and load them if (plugin_list != null) { - AssetManager am = context.getAssets(); String[] plugin_array = plugin_list.toArray(new String[0]); for(int i = 0; i < plugin_list.size(); i++) { Log.d("iitcm", "adding plugin " + plugin_array[i]); - Scanner s = null; - String src = ""; - try { - // load plugins from external storage if dev mode are enabled - if (dev_enabled) { - File js_file = new File(iitc_path + "/dev/plugins/" + plugin_array[i]); - s = new Scanner(js_file).useDelimiter("\\A"); - } - else - // load plugins from asset folder - s = new Scanner(am.open("plugins/" + plugin_array[i])).useDelimiter("\\A"); - } catch (IOException e2) { - e2.printStackTrace(); - } - if (s != null) src = s.hasNext() ? s.next() : ""; - view.loadUrl("javascript:" + src); + if (dev_enabled) + this.loadJS(iitc_path + "/dev/plugins/" + plugin_array[i], false, view); + else + this.loadJS("plugins/" + plugin_array[i], true, view); } } @@ -164,41 +142,63 @@ public class IITC_WebViewClient extends WebViewClient { File[] files = directory.listFiles(); if (files != null) { for (int i = 0; i < files.length; ++i) { - try { - // the file should be a user.js-file - if (!files[i].toString().endsWith("user.js")) - continue; - String src = ""; - Scanner s = new Scanner(files[i]).useDelimiter("\\A"); - if (s != null) src = s.hasNext() ? s.next() : ""; - Log.d("iitcm", "Loading additional plugin " + iitc_path + files[i]); - view.loadUrl("javascript:" + src); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } + if(this.loadJS(files[i].toString(), false, view)) + Log.d("iitcm", "loading additional plugin " + files[i].toString()); } } } public void enableTracking(WebView view, boolean dev_enabled) { Log.d("iitcm", "enable tracking..."); - AssetManager am = context.getAssets(); - Scanner s = null; - String src = ""; - try { // load plugin from external storage if dev mode are enabled - if (dev_enabled) { - File js_file = new File(iitc_path + "/dev/user-location.user.js"); - s = new Scanner(js_file).useDelimiter("\\A"); - } + if (dev_enabled) + this.loadJS(iitc_path + "/dev/user-location.user.js", false, view); else // load plugin from asset folder - s = new Scanner(am.open("user-location.user.js")).useDelimiter("\\A"); - } catch (IOException e2) { - e2.printStackTrace(); + this.loadJS("user-location.user.js", true, view); + } + + // read a file into a string + // use the full path for File + // if asset == true use the asset manager to open file + public String fileToString(String file, boolean asset) { + Scanner s = null; + String src= ""; + if (!asset) { + File js_file = new File(file); + try { + s = new Scanner(js_file).useDelimiter("\\A"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + Log.d("iitcm", "failed to parse file " + file); + return "false"; + } + } else { + // load plugins from asset folder + AssetManager am = context.getAssets(); + try { + s = new Scanner(am.open(file)).useDelimiter("\\A"); + } catch (IOException e) { + e.printStackTrace(); + Log.d("iitcm", "failed to parse file assets/" + file); + return "false"; + } } + if (s != null) src = s.hasNext() ? s.next() : ""; - view.loadUrl("javascript:" + src); + return src; + } + + // read a file into a string + // load it as javascript + public boolean loadJS(String file, boolean asset, WebView view) { + if (!file.endsWith("user.js")) + return false; + String js = fileToString(file, asset); + if (js.equals("false")) + return false; + else view.loadUrl("javascript:" + js); + return true; } // Check every external resource if it’s okay to load it and maybe replace it @@ -242,4 +242,4 @@ public class IITC_WebViewClient extends WebViewClient { return true; } } -} +} \ No newline at end of file From 96ab292a5db71cfb55bcd86cbd3a0d244a1a86b6 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sat, 4 May 2013 11:42:33 +0200 Subject: [PATCH 11/14] add icon to toggle fullscreen action button (see #237) --- mobile/res/menu/main.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mobile/res/menu/main.xml b/mobile/res/menu/main.xml index c02d06d5..a80f271a 100644 --- a/mobile/res/menu/main.xml +++ b/mobile/res/menu/main.xml @@ -17,8 +17,9 @@ + android:showAsAction="ifRoom" + android:title="@string/toggle_fullscreen" + android:icon="@android:drawable/ic_menu_zoom"> Date: Sat, 4 May 2013 12:21:05 +0200 Subject: [PATCH 12/14] let keyboard work in fullscreen mode too --- mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 04bf99b1..af353f35 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -20,6 +20,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.res.Configuration; +import android.graphics.Rect; import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -67,8 +68,14 @@ public class IITC_Mobile extends Activity { iitc_view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { - if ((iitc_view.getRootView().getHeight() - iitc_view.getHeight()) > - iitc_view.getRootView().getHeight()/3) { + Rect r = new Rect(); + //r will be populated with the coordinates of your view that area still visible. + iitc_view.getWindowVisibleDisplayFrame(r); + + int screenHeight = iitc_view.getRootView().getHeight(); + int heightDiff = screenHeight - (r.bottom - r.top); + boolean visible = heightDiff > screenHeight / 3; + if (visible == true) { Log.d("iitcm", "Open Keyboard..."); IITC_Mobile.this.keyboad_open = true; } else { From 897e0bc73171376fa598e13da1459123f630907e Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sat, 4 May 2013 16:31:52 +0200 Subject: [PATCH 13/14] iitc_path has a / at the end...no need to begin the rest of the path with a / (fixes #240) --- mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java index d4b003d7..be0fa8cf 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java @@ -68,10 +68,10 @@ public class IITC_WebViewClient extends WebViewClient { // if developer mode are enabled, load all iitc script from external storage if (sharedPref.getBoolean("pref_dev_checkbox", true)) { - js = this.fileToString(iitc_path + "/dev/total-conversion-build.user.js", false); + js = this.fileToString(iitc_path + "dev/total-conversion-build.user.js", false); if (js.equals("false")) { Toast.makeText(context, "File " + iitc_path + - "/dev/total-conversion-build.user.js not found. " + + "dev/total-conversion-build.user.js not found. " + "Disable developer mode or add iitc files " + "to the dev folder.", Toast.LENGTH_LONG).show(); return; @@ -127,7 +127,7 @@ public class IITC_WebViewClient extends WebViewClient { for(int i = 0; i < plugin_list.size(); i++) { Log.d("iitcm", "adding plugin " + plugin_array[i]); if (dev_enabled) - this.loadJS(iitc_path + "/dev/plugins/" + plugin_array[i], false, view); + this.loadJS(iitc_path + "dev/plugins/" + plugin_array[i], false, view); else this.loadJS("plugins/" + plugin_array[i], true, view); } @@ -152,7 +152,7 @@ public class IITC_WebViewClient extends WebViewClient { Log.d("iitcm", "enable tracking..."); // load plugin from external storage if dev mode are enabled if (dev_enabled) - this.loadJS(iitc_path + "/dev/user-location.user.js", false, view); + this.loadJS(iitc_path + "dev/user-location.user.js", false, view); else // load plugin from asset folder this.loadJS("user-location.user.js", true, view); From de1e553c32d952f2043ae019e1b31d2744046136 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sat, 4 May 2013 16:34:01 +0200 Subject: [PATCH 14/14] made pref_dev_checkbox check false per default --- mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java index be0fa8cf..c75f538b 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java @@ -67,7 +67,7 @@ public class IITC_WebViewClient extends WebViewClient { String js = ""; // if developer mode are enabled, load all iitc script from external storage - if (sharedPref.getBoolean("pref_dev_checkbox", true)) { + if (sharedPref.getBoolean("pref_dev_checkbox", false)) { js = this.fileToString(iitc_path + "dev/total-conversion-build.user.js", false); if (js.equals("false")) { Toast.makeText(context, "File " + iitc_path +