From 076c7b2c61f7c63fd6824d1de15fb262d5445d39 Mon Sep 17 00:00:00 2001 From: Starcom Date: Mon, 8 Oct 2018 22:43:57 +0200 Subject: [PATCH] Share geo links from other apps as suggested on report #62 Tested with android calendar app. --- PocketMaps/app/build.gradle | 4 +- PocketMaps/app/src/main/AndroidManifest.xml | 22 +++- .../activities/GeocodeActivity.java | 6 + .../pocketmaps/activities/MapActions.java | 15 ++- .../pocketmaps/activities/MapActivity.java | 2 + .../activities/ShowLocationActivity.java | 112 ++++++++++++++++++ .../junjunguo/pocketmaps/map/MapHandler.java | 18 ++- 7 files changed, 169 insertions(+), 10 deletions(-) create mode 100644 PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/activities/ShowLocationActivity.java diff --git a/PocketMaps/app/build.gradle b/PocketMaps/app/build.gradle index dde935f..44dee17 100644 --- a/PocketMaps/app/build.gradle +++ b/PocketMaps/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "com.junjunguo.pocketmaps" minSdkVersion 19 targetSdkVersion 27 - versionCode 12 - versionName "2.2" + versionCode 13 + versionName "2.3" } buildTypes { diff --git a/PocketMaps/app/src/main/AndroidManifest.xml b/PocketMaps/app/src/main/AndroidManifest.xml index b4a86d3..fe3e716 100644 --- a/PocketMaps/app/src/main/AndroidManifest.xml +++ b/PocketMaps/app/src/main/AndroidManifest.xml @@ -2,8 +2,8 @@ + android:versionCode="13" + android:versionName="2.3"> @@ -32,6 +32,24 @@ + + + + + + + + + + + + + + Got input uri: " + uri); + Properties prop = new Properties(); + try + { + Set keys = uri.getQueryParameterNames(); + for (String key : keys) + { + String value = uri.getQueryParameter(key); + prop.setProperty(key, value); + log("--> Got input: " + key + "=" + value); + } + } + catch (UnsupportedOperationException e) + { // Example: "geo:0,0?q=MySearchLocation" + log("Uri has no parameters, try parsing."); + int index = uri.toString().indexOf("?"); + if (index < 0) { throw new IllegalArgumentException("Input-uri has no parameters!"); } + String[] values = uri.toString().substring(index+1).split("\\&"); + for (String v : values) + { + index = v.indexOf('='); + if (index < 0) { continue; } + String key = v.substring(0, index); + String val = v.substring(index+1); + prop.setProperty(key, val); + } + } + locationSearchString = prop.getProperty("q"); + if (locationSearchString!=null) { return; } + String lat = prop.getProperty("lat"); + String lon = prop.getProperty("lat"); + if (lat==null || lon==null) + { + throw new IllegalArgumentException("Missing input!"); + } + double latD = Double.parseDouble(lat); + double lonD = Double.parseDouble(lon); + locationGeoPoint = new GeoPoint(latD, lonD); + } + catch (Exception e) + { + e.printStackTrace(); + logUser("Error getting input: " + e.getMessage()); + } + } + + @Override protected void onResume() + { + super.onResume(); + } + + @Override protected void onDestroy() + { + super.onDestroy(); + } + + private void showMain() + { + Intent intent = new Intent(this, MainActivity.class); + intent.putExtra("com.junjunguo.pocketmaps.activities.MapActivity.SELECTNEWMAP", false); + startActivity(intent); + finish(); + } + + private void log(String str) + { + Log.i(ShowLocationActivity.class.getName(), str); + } + + private void logUser(String str) + { + Log.i(ShowLocationActivity.class.getName(), str); + try + { + Toast.makeText(this.getBaseContext(), str, Toast.LENGTH_SHORT).show(); + } + catch (Exception e) { e.printStackTrace(); } + } +} + diff --git a/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/map/MapHandler.java b/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/map/MapHandler.java index c2d1cc3..685131b 100644 --- a/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/map/MapHandler.java +++ b/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/map/MapHandler.java @@ -45,6 +45,9 @@ import com.graphhopper.util.PointList; import com.junjunguo.pocketmaps.R; +import com.junjunguo.pocketmaps.activities.MapActions; +import com.junjunguo.pocketmaps.activities.MapActivity; +import com.junjunguo.pocketmaps.activities.ShowLocationActivity; import com.junjunguo.pocketmaps.model.listeners.MapHandlerListener; import com.junjunguo.pocketmaps.navigator.NaviEngine; import com.junjunguo.pocketmaps.util.TargetDirComputer; @@ -60,7 +63,7 @@ public class MapHandler private GeoPoint startMarker; private GeoPoint endMarker; private boolean needLocation = false; - private Activity activity; + private MapActivity activity; private MapView mapView; private ItemizedLayer itemizedLayer; private ItemizedLayer customLayer; @@ -105,7 +108,7 @@ private MapHandler() needPathCal = false; } - public void init(Activity activity, MapView mapView, String currentArea, File mapsFolder) + public void init(MapActivity activity, MapView mapView, String currentArea, File mapsFolder) { this.activity = activity; this.mapView = mapView; @@ -176,6 +179,17 @@ protected void onPostExecute(Path o) { logUser("Finished loading graph."); } + GeoPoint g = ShowLocationActivity.locationGeoPoint; + String lss = ShowLocationActivity.locationSearchString; + if (g != null) + { + activity.getMapActions().onPressLocation(g); + ShowLocationActivity.locationGeoPoint = null; + } + else if (lss != null) + { + activity.getMapActions().startGeocodeActivity(null, false); + } prepareInProgress = false; } }.execute();