diff --git a/code/dialog.js b/code/dialog.js index 81c196d5..96595b3d 100644 --- a/code/dialog.js +++ b/code/dialog.js @@ -55,6 +55,11 @@ window.dialog = function(options) { var jqID = '#' + id; var html = ''; + // hint for iitc mobile that a dialog was opened + if (typeof android !== 'undefined' && android && android.dialogOpened) { + android.dialogOpened(id); + } + // Convert text to HTML if necessary if(options.text) { html = window.convertTextToTableMagic(options.text); diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java index 70011373..284d624a 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java @@ -74,6 +74,12 @@ public class IITC_JSInterface { } }); } + + @JavascriptInterface + public void dialogOpened(String id) { + ((IITC_Mobile) context).dialogOpened(id); + } + // get layers and list them in a dialog @JavascriptInterface public void setLayers(String base_layer, String overlay_layer) { diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 3c5c5339..a9297f44 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -47,6 +47,7 @@ public class IITC_Mobile extends Activity { private MenuItem searchMenuItem; private boolean desktop = false; private boolean reload_needed = false; + private ArrayList dialogStack = new ArrayList(); // Used for custom back stack handling private ArrayList backStack = new ArrayList(); @@ -264,6 +265,17 @@ public class IITC_Mobile extends Activity { // we want a self defined behavior for the back button @Override public void onBackPressed() { + // first kill all open iitc dialogs + if (!dialogStack.isEmpty()) { + int last = dialogStack.size() - 1; + String id = dialogStack.get(last); + dialogStack.remove(last); + iitc_view.loadUrl("javascript: " + + "var selector = $(window.DIALOGS['" + id + "']); " + + "selector.dialog('close'); " + + "selector.remove();"); + return; + } // exit fullscreen mode if it is enabled and action bar is disabled or the back stack is empty if (fullscreen_mode && (backStack.isEmpty() || fullscreen_actionbar)) { this.toggleFullscreen(); @@ -522,4 +534,10 @@ public class IITC_Mobile extends Activity { item = menu.findItem(R.id.menu_debug); item.setVisible(!desktop); } + + // called by the javascript interface + public void dialogOpened(String id) { + Log.d("iitcm", "Dialog " + id + " added"); + dialogStack.add(id); + } }