From 96add495166459c8e1b6044b4c02afde91aa3557 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sat, 11 May 2013 14:41:15 +0200 Subject: [PATCH] notify android when select spinner is opened/closed (fix for #255) --- code/portal_highlighter.js | 7 +++++++ .../src/com/cradle/iitc_mobile/IITC_JSInterface.java | 9 +++++++++ mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java | 4 ++++ mobile/src/com/cradle/iitc_mobile/IITC_WebView.java | 10 ++++++++++ 4 files changed, 30 insertions(+) diff --git a/code/portal_highlighter.js b/code/portal_highlighter.js index 05bfd911..f048741b 100644 --- a/code/portal_highlighter.js +++ b/code/portal_highlighter.js @@ -33,6 +33,13 @@ window.portalHighlighterControl = function() { }); $("#portal_highlight_select").val(_current_highlighter); $("#portal_highlight_select").change(function(){ changePortalHighlights($(this).val());}); + // notify android that the select spinner is enabled. + // this disables javascript injection on android side. + // if android is not notified, the spinner closes on the next JS call + if (typeof android !== 'undefined' && android && android.spinnerEnabled) { + $("#portal_highlight_select").click(function(){ android.spinnerEnabled(true);}); + $("#portal_highlight_select").focus(function(){ android.spinnerEnabled(false);}); + } $(".leaflet-top.leaflet-left").css('padding-top', '20px'); $(".leaflet-control-scale-line").css('margin-top','25px'); } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java index 4f7510ef..71358af9 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java @@ -5,6 +5,7 @@ import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.util.Log; import android.webkit.JavascriptInterface; import android.widget.Toast; @@ -28,6 +29,14 @@ public class IITC_JSInterface { context.startActivity(intent); } + // disable javascript injection while spinner is enabled + // prevent the spinner from closing automatically + @JavascriptInterface + public void spinnerEnabled(boolean en) { + Log.d("iitcm", "disableJS? " + en); + ((IITC_Mobile) context).getWebView().disableJS(en); + } + // copy link to specific portal to android clipboard @JavascriptInterface public void copy(String s) { diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 0763caa0..a30c8fd9 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -356,4 +356,8 @@ public class IITC_Mobile extends Activity { attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN; this.getWindow().setAttributes(attrs); } + + public IITC_WebView getWebView() { + return this.iitc_view; + } } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java index 6a2bea32..a81efb67 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java @@ -19,6 +19,7 @@ public class IITC_WebView extends WebView { private WebSettings settings; private IITC_WebViewClient webclient; private IITC_JSInterface js_interface; + private boolean disableJS = false; // init web view private void iitc_init(Context c) { @@ -85,6 +86,11 @@ public class IITC_WebView extends WebView { return; } } + // do nothing if script is enabled; + if (this.disableJS == true) { + Log.d("iitcm", "javascript injection disabled...return"); + return; + } if (!url.startsWith("javascript:")) { // force https if enabled in settings SharedPreferences sharedPref = PreferenceManager @@ -123,4 +129,8 @@ public class IITC_WebView extends WebView { return wifi.getState() == NetworkInfo.State.CONNECTED; } + public void disableJS(boolean val) { + this.disableJS = val; + } + }