From 83dbdf4e186dc7c1ec3622a56e35bbc748d66b04 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Mon, 20 May 2013 11:34:40 +0200 Subject: [PATCH 1/3] split layers in 2 different dialogs --- .../cradle/iitc_mobile/IITC_JSInterface.java | 94 +++++++++++++------ 1 file changed, 66 insertions(+), 28 deletions(-) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java index c49f266a..3b4fd299 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java @@ -24,11 +24,11 @@ public class IITC_JSInterface { // context of main activity Context context; HashMap layer_ids; - boolean[] active_array; - String[] all_layers; + boolean[] overlay_is_active; + int active_base_layer; + String[] overlay_layers, base_layers; int num_base_layers; int num_overlay_layers; - int active_base_layer; IITC_JSInterface(Context c) { layer_ids = new HashMap(); @@ -65,26 +65,27 @@ public class IITC_JSInterface { } @JavascriptInterface - public void setLayers(String base_layers, String overlay_layers) { + public void setLayers(String base_layer, String overlay_layer) { JSONArray base_layersJSON = null; JSONArray overlay_layersJSON = null; try { - base_layersJSON = new JSONArray(base_layers); - overlay_layersJSON = new JSONArray(overlay_layers); + base_layersJSON = new JSONArray(base_layer); + overlay_layersJSON = new JSONArray(overlay_layer); } catch (JSONException e) { e.printStackTrace(); } + // get length and initialize arrays num_base_layers = base_layersJSON.length(); num_overlay_layers = overlay_layersJSON.length(); - int total_lenght = num_base_layers + num_overlay_layers; - active_array = new boolean[total_lenght]; - all_layers = new String[total_lenght]; + overlay_is_active = new boolean[num_overlay_layers]; + overlay_layers = new String[num_overlay_layers]; + base_layers = new String[num_base_layers]; layer_ids.clear(); // --------------- overlay layers ------------------------ - for (int i = 0; i < overlay_layersJSON.length(); ++i) { + for (int i = 0; i < num_overlay_layers; ++i) { try { String layer = overlay_layersJSON.getString(i); layer = layer.replace("{", ""); @@ -101,8 +102,8 @@ public class IITC_JSInterface { } name = name.replace("\"", ""); layer_ids.put(name, id); - all_layers[i] = name; - active_array[i] = isActive; + this.overlay_layers[i] = name; + this.overlay_is_active[i] = isActive; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -110,7 +111,7 @@ public class IITC_JSInterface { } // --------------- base layers ------------------------ - for (int i = 0; i < base_layersJSON.length(); ++i) { + for (int i = 0; i < num_base_layers; ++i) { try { String layer = base_layersJSON.getString(i); layer = layer.replace("{", ""); @@ -127,41 +128,78 @@ public class IITC_JSInterface { } name = name.replace("\"", ""); layer_ids.put(name, id); - all_layers[i + num_overlay_layers] = name; - active_array[i + num_overlay_layers] = isActive; - if (isActive) active_base_layer = i + num_overlay_layers; + this.base_layers[i] = name; + if (isActive) active_base_layer = i; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } + // show overlay layers by default + show_multi_selection(); + } + // show all overlay layers in a multi selection list dialog + private void show_multi_selection() { // build the layer chooser dialog - AlertDialog.Builder d = new AlertDialog.Builder(context); + AlertDialog.Builder d_m = new AlertDialog.Builder(context); OnMultiChoiceClickListener m_listener = new OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { // activate clicked layer ((IITC_Mobile) context).getWebView().loadUrl("javascript: window.layerChooser.showLayer(" - + layer_ids.get(all_layers[which]) + "," - + active_array[which] + ");"); - // disable old base layer...we can only have one active base layer - if (which >= num_overlay_layers) { - active_array[active_base_layer] = false; - ((AlertDialog) dialog).getListView().setItemChecked(active_base_layer, false); - active_base_layer = which; - } + + layer_ids.get(overlay_layers[which]) + "," + + overlay_is_active[which] + ");"); } }; - d.setMultiChoiceItems(all_layers, active_array , m_listener); - d.setPositiveButton("Close", new OnClickListener() { + + d_m.setMultiChoiceItems(overlay_layers, overlay_is_active , m_listener); + d_m.setPositiveButton("Base Layers", new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + show_single_selection(); + dialog.cancel(); + } + }); + d_m.setNegativeButton("Close", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); - d.show(); + d_m.setTitle("Overlay Layers"); + d_m.show(); + } + // show all base layers in a single selection list dialog + private void show_single_selection() { + OnClickListener s_listener = new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // activate clicked layer + ((IITC_Mobile) context).getWebView().loadUrl("javascript: window.layerChooser.showLayer(" + + layer_ids.get(base_layers[which]) + "," + + true + ");"); + active_base_layer = which; + } + }; + AlertDialog.Builder d_s = new AlertDialog.Builder(context); + d_s.setSingleChoiceItems(base_layers, active_base_layer, s_listener); + d_s.setPositiveButton("Overlay Layers", new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + show_multi_selection(); + dialog.cancel(); + } + }); + d_s.setNegativeButton("Close", new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.cancel(); + } + }); + d_s.setTitle("Base Layers"); + d_s.show(); } } From 74a77d874fc03bc1811463fd479ce208a51b8a24 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Mon, 20 May 2013 12:05:40 +0200 Subject: [PATCH 2/3] some comments and update README+HACKING --- mobile/HACKING.md | 2 +- mobile/README.md | 12 +++- .../cradle/iitc_mobile/IITC_JSInterface.java | 71 ++++++++++++------- .../com/cradle/iitc_mobile/IITC_Mobile.java | 1 + 4 files changed, 57 insertions(+), 29 deletions(-) diff --git a/mobile/HACKING.md b/mobile/HACKING.md index a3250ddb..0ebdb3dc 100644 --- a/mobile/HACKING.md +++ b/mobile/HACKING.md @@ -29,4 +29,4 @@ Building the APK Set the ANDROID_HOME environment variable: ```export ANDROID_HOME=/path/to/android_sdk``` Then build the app via the build.py script ```./build.py mobile``` -- **Eclipse:** Just import this project and klick the build button. Ensure that you have iitc.js in your assets folder. This is automatically created, when executing ```./build.py mobile```. Otherwise, just copy the IITC script to the assets folder and rename it to iitc.js +- **Eclipse:** Just import this project and klick the build button. Ensure that you have total-conversion-build.user.js and user-location.user.js in your assets folder. This is automatically created, when executing ```./build.py mobile```. Otherwise, just copy the scripts to the assets folder. diff --git a/mobile/README.md b/mobile/README.md index 074034ff..280dee9e 100644 --- a/mobile/README.md +++ b/mobile/README.md @@ -7,16 +7,24 @@ The Android App behaves like the desktop version, but uses the mobile view, whic - plugin support +- support for unofficial plugins. just copy the *.user.js file to ```/IITC_Mobile/plugins/``` and they should be parsed on start-up + +- in-app layer chooser + +- in-app IITC buttons + +- show users current location + - a geo intent is sent, when a portals Map link is clicked (lets you navigate to portals) - a geolocate button (you have to enable GPS satellites + location access to use this feature) -- toggle between desktop and mobile view (nice for tablets) - - possibility to use a custom IITC script source - a click on Portal link copies it to clipboard +- developer mode: all script source will be loaded from ```/IITC_Mobile/dev/``` + - more features will be added soon... **The App only works with Android 4.0+** diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java index 3b4fd299..8aff9177 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_JSInterface.java @@ -64,11 +64,18 @@ public class IITC_JSInterface { .show(); } + // get layers and list them in a dialog @JavascriptInterface public void setLayers(String base_layer, String overlay_layer) { + /* + * the layer strings have a form like: + * [{"layerId":27,"name":"MapQuest OSM","active":true},{"layerId":28,"name":"Default Ingress Map","active":false}] + * Put it in a JSONArray and parse it + */ JSONArray base_layersJSON = null; JSONArray overlay_layersJSON = null; + Log.d("iitcm", base_layer); try { base_layersJSON = new JSONArray(base_layer); overlay_layersJSON = new JSONArray(overlay_layer); @@ -84,6 +91,42 @@ public class IITC_JSInterface { base_layers = new String[num_base_layers]; layer_ids.clear(); + // --------------- base layers ------------------------ + for (int i = 0; i < num_base_layers; ++i) { + try { + String layer = base_layersJSON.getString(i); + layer = layer.replace("{", ""); + layer = layer.replace("}", ""); + /* + * we now should have a string like + * ["layerId":27,"name":"MapQuest OSM","active":true] + * split it on , + */ + String[] layers = layer.split(","); + /* + * we should have 3 strings in a form like + * "name":"MapQuest OSM" + * get the values and get rid of the quotation marks + */ + String id = ""; + String name = ""; + boolean isActive = false; + for (int j = 0; j < layers.length; ++j) { + String[] values = layers[j].split(":"); + if (values[0].contains("active")) isActive = values[1].equals("true"); + if (values[0].contains("layerId")) id = values[1]; + if (values[0].contains("name")) name = values[1]; + } + name = name.replace("\"", ""); + layer_ids.put(name, id); + this.base_layers[i] = name; + if (isActive) active_base_layer = i; + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + // --------------- overlay layers ------------------------ for (int i = 0; i < num_overlay_layers; ++i) { try { @@ -109,32 +152,6 @@ public class IITC_JSInterface { e.printStackTrace(); } } - - // --------------- base layers ------------------------ - for (int i = 0; i < num_base_layers; ++i) { - try { - String layer = base_layersJSON.getString(i); - layer = layer.replace("{", ""); - layer = layer.replace("}", ""); - String[] layers = layer.split(","); - String id = ""; - String name = ""; - boolean isActive = false; - for (int j = 0; j < layers.length; ++j) { - String[] values = layers[j].split(":"); - if (values[0].contains("active")) isActive = values[1].equals("true"); - if (values[0].contains("layerId")) id = values[1]; - if (values[0].contains("name")) name = values[1]; - } - name = name.replace("\"", ""); - layer_ids.put(name, id); - this.base_layers[i] = name; - if (isActive) active_base_layer = i; - } catch (JSONException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } // show overlay layers by default show_multi_selection(); } @@ -155,6 +172,7 @@ public class IITC_JSInterface { }; d_m.setMultiChoiceItems(overlay_layers, overlay_is_active , m_listener); + // switch to base layers d_m.setPositiveButton("Base Layers", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -186,6 +204,7 @@ public class IITC_JSInterface { }; AlertDialog.Builder d_s = new AlertDialog.Builder(context); d_s.setSingleChoiceItems(base_layers, active_base_layer, s_listener); + // switch to overlay layers d_s.setPositiveButton("Overlay Layers", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index c3e5686d..2af11b89 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -262,6 +262,7 @@ public class IITC_Mobile extends Activity { toggleFullscreen(); return true; case R.id.layer_chooser: + // the getLayers function calls the setLayers method of IITC_JSInterface iitc_view.loadUrl("javascript: window.layerChooser.getLayers()"); return true; // get the users current location and focus it on map From 0f77c664c0e3077e1b87c9cab04c765a6c2e6b56 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Mon, 20 May 2013 12:11:29 +0200 Subject: [PATCH 3/3] replaced deadlink to breunigs github --- mobile/HACKING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mobile/HACKING.md b/mobile/HACKING.md index 0ebdb3dc..403fc7f3 100644 --- a/mobile/HACKING.md +++ b/mobile/HACKING.md @@ -17,7 +17,7 @@ Debugging If you want to debug the APK, I suggest [reading up on Google’s documentation](https://developer.android.com/index.html). -Debugging IITC(M) **after** it has booted is relatively easy: you can switch to the “debug” tab, which is a low end developer console. It renders all calls to `console.*`, so you can use it just like you expect. It may be easier to develop in a desktop browser. Set it up like explained [in the normal hacking guide](https://github.com/breunigs/ingress-intel-total-conversion/blob/gh-pages/HACKING.md), but fake your user agent or modify the detection in `code/smartphone.js` and `main.js`. The device ID is printed to the debug console on IITC boot. +Debugging IITC(M) **after** it has booted is relatively easy: you can switch to the “debug” tab, which is a low end developer console. It renders all calls to `console.*`, so you can use it just like you expect. It may be easier to develop in a desktop browser. Set it up like explained [in the normal hacking guide](https://github.com/jonatkins/ingress-intel-total-conversion/blob/master/HACKING.md), but fake your user agent or modify the detection in `code/smartphone.js` and `main.js`. The device ID is printed to the debug console on IITC boot. Debugging IITC(M) **before** it has booted requires the Android Developer Tools. Connecting your device and running `adb logcat` should print the debug log to your computer until the low-end dev console mentioned above is available.