From 4a00059cdfef2cb8fca8c13ca5b00672feba144b Mon Sep 17 00:00:00 2001 From: maximilianovermeyer Date: Sat, 27 Nov 2021 14:44:53 +0100 Subject: [PATCH 1/6] Removed Debug build types for easy debugging with Android Studio --- app/build.gradle | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b2afc7dd..4f454c33 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,17 +36,6 @@ android { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } - userdebug { - initWith release - minifyEnabled false - versionNameSuffix "-userdebug_"+new Date().format("yyyyMMDD") - } - debug { - initWith release - minifyEnabled false - signingConfig signingConfigs.debug - versionNameSuffix "-debug_"+new Date().format("yyyyMMDD-HHmm00ss") - } } } -- 2.39.2 From c133dbcbc73a0d6b7d7da5bf0255a0cd37329fd1 Mon Sep 17 00:00:00 2001 From: maximilianovermeyer Date: Sat, 27 Nov 2021 14:47:01 +0100 Subject: [PATCH 2/6] Removed Debug build types for easy debugging with Android Studio --- app/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 4f454c33..42a15f9f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,7 +37,6 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } - } dependencies { -- 2.39.2 From e4564dc6c08f6b12239614b76dc4aafda47ac201 Mon Sep 17 00:00:00 2001 From: maximilianovermeyer Date: Sat, 27 Nov 2021 15:00:14 +0100 Subject: [PATCH 3/6] Updated gradle plugin and replaced deprecated jcenter repo with mavenCentral --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index a9203aac..00157145 100644 --- a/build.gradle +++ b/build.gradle @@ -21,11 +21,11 @@ buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.3' + classpath 'com.android.tools.build:gradle:7.0.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } @@ -34,7 +34,7 @@ buildscript { allprojects { repositories { google() - jcenter() + mavenCentral() } } -- 2.39.2 From 14a176fae756a5f3f3ae5204ef8819edf4056cd4 Mon Sep 17 00:00:00 2001 From: maximilianovermeyer Date: Sat, 27 Nov 2021 15:27:28 +0100 Subject: [PATCH 4/6] Added "browsable" intent category to MainActivity for improved geo intent handling --- app/src/main/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52183b6d..e30d7015 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -50,6 +50,7 @@ + -- 2.39.2 From b0a7ba3f5514301f3b09387c57e9ed5733e2c1bc Mon Sep 17 00:00:00 2001 From: maximilianovermeyer Date: Sat, 27 Nov 2021 17:55:21 +0100 Subject: [PATCH 5/6] Match geo intents with regex for better handling of different formats --- .../MainActivity.java | 92 +++++++++++-------- 1 file changed, 53 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/de/kaffeemitkoffein/tinyweatherforecastgermany/MainActivity.java b/app/src/main/java/de/kaffeemitkoffein/tinyweatherforecastgermany/MainActivity.java index e8d485e8..452b1939 100644 --- a/app/src/main/java/de/kaffeemitkoffein/tinyweatherforecastgermany/MainActivity.java +++ b/app/src/main/java/de/kaffeemitkoffein/tinyweatherforecastgermany/MainActivity.java @@ -53,6 +53,8 @@ import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.Executor; import java.util.concurrent.Executors; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class MainActivity extends Activity { @@ -485,46 +487,13 @@ public class MainActivity extends Activity { } }); // check if a geo intent was sent - Intent geo_intent = getIntent(); - if (geo_intent!=null){ - String intent_action = geo_intent.getAction(); - if (intent_action!=null){ - if (intent_action.equals(Intent.ACTION_VIEW)){ - String intent_scheme = geo_intent.getScheme(); - if (intent_scheme!=null){ - if (intent_scheme.equals("geo")){ - String received_geolocation = geo_intent.getData().toString(); - if (received_geolocation!=null){ - try { - String received_latitude = received_geolocation.substring(received_geolocation.indexOf(":")+1,received_geolocation.indexOf(",")); - String received_longitude = received_geolocation.substring(received_geolocation.indexOf(",")+1,received_geolocation.indexOf("?")); - String received_zoom = received_geolocation.substring(received_geolocation.indexOf("z=")+2); - Location own_location = new Location("manual"); - own_location.setTime(Calendar.getInstance().getTimeInMillis()); - try { - double latitude = Location.convert(standardizeGeo(received_latitude)); - double longitude = Location.convert(standardizeGeo(received_longitude)); - own_location.setLatitude(latitude); - own_location.setLongitude(longitude); - launchStationSearchByLocation(own_location); - } catch (Exception e){ - // invalid geo coordinates - PrivateLog.log(getApplicationContext(),PrivateLog.MAIN, PrivateLog.ERR,"received geo intent, but unable to read it: "+e.getMessage()); - PrivateLog.log(getApplicationContext(),PrivateLog.MAIN, PrivateLog.ERR,"geo content was: "+received_geolocation); - Toast.makeText(getApplicationContext(),getApplicationContext().getResources().getString(R.string.georeceive_error),Toast.LENGTH_LONG).show(); - } - } catch (IndexOutOfBoundsException e){ - PrivateLog.log(getApplicationContext(),PrivateLog.MAIN, PrivateLog.ERR,"received geo intent, but unable to parse it poroperly: "+e.getMessage()); - PrivateLog.log(getApplicationContext(),PrivateLog.MAIN, PrivateLog.ERR,"geo content was: "+received_geolocation); - // invalid geo-string (uri) - Toast.makeText(getApplicationContext(),getApplicationContext().getResources().getString(R.string.georeceive_error),Toast.LENGTH_LONG).show(); - } - } - } - } - } - } + + Location intentLocation = getLocationForGeoIntent(getIntent()); + + if (intentLocation!=null){ + launchStationSearchByLocation(intentLocation); } + executor.execute(new Runnable() { @Override public void run() { @@ -533,6 +502,51 @@ public class MainActivity extends Activity { }); } + private Location getLocationForGeoIntent(Intent intent) { + if (intent==null) + { + return null; + } + String intent_action = intent.getAction(); + + if (!Objects.equals(intent_action, Intent.ACTION_VIEW)) + { + return null; + } + + String intent_scheme = intent.getScheme(); + if (intent_scheme==null || !intent_scheme.equalsIgnoreCase("geo")) + { + return null; + } + + String received_geolocation = intent.getData().toString(); + if (received_geolocation!=null) { + try { + Pattern pattern_lat_long = Pattern.compile("geo:(?-?[\\d]*\\.?[\\d]*),(?-?[\\d]*\\.?[\\d]*)", Pattern.CASE_INSENSITIVE); + Matcher m = pattern_lat_long.matcher(received_geolocation); + m.find(); + String received_latitude = m.group(1); //Can be replaced with 'm.group("latitude")' for better readability as soon as min API level is 26 + String received_longitude = m.group(2); //Can be replaced with 'm.group("longitude")' for better readability as soon as min API level is 26 + + Location own_location = new Location("manual"); + own_location.setTime(Calendar.getInstance().getTimeInMillis()); + double latitude = Location.convert(standardizeGeo(received_latitude)); + double longitude = Location.convert(standardizeGeo(received_longitude)); + own_location.setLatitude(latitude); + own_location.setLongitude(longitude); + return own_location; + } + catch (Exception e) { + // invalid geo-string (uri) + PrivateLog.log(getApplicationContext(), PrivateLog.MAIN, PrivateLog.ERR, "received geo intent, but unable to read it: " + e.getMessage()); + PrivateLog.log(getApplicationContext(), PrivateLog.MAIN, PrivateLog.ERR, "geo content was: " + received_geolocation); + Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.georeceive_error), Toast.LENGTH_LONG).show(); + } + } + return null; + } + private void errorDialog(Exception e){ AlertDialog.Builder builder = new AlertDialog.Builder(this,0); builder.setCancelable(true); -- 2.39.2 From aab6b97abced3e59186204ede74d33ca1c3a6b36 Mon Sep 17 00:00:00 2001 From: maximilianovermeyer Date: Wed, 1 Dec 2021 11:40:36 +0100 Subject: [PATCH 6/6] MainActivity.getLocationForGeoIntent: Updated javadoc --- .../tinyweatherforecastgermany/MainActivity.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/de/kaffeemitkoffein/tinyweatherforecastgermany/MainActivity.java b/app/src/main/java/de/kaffeemitkoffein/tinyweatherforecastgermany/MainActivity.java index 452b1939..20852b6a 100644 --- a/app/src/main/java/de/kaffeemitkoffein/tinyweatherforecastgermany/MainActivity.java +++ b/app/src/main/java/de/kaffeemitkoffein/tinyweatherforecastgermany/MainActivity.java @@ -502,6 +502,18 @@ public class MainActivity extends Activity { }); } + + /** + * Returns a location for a geo intent. + *

+ * Checks if an intent's scheme is "geo". If so, and the intent data is following the pattern + * "latitude,longitude[optional parameters with non-numeric separator]", the content is used to populate a new location + * object. If it's a geo intent, but it's not following the mentioned pattern, the user is + * informed about the mismatch via a toast and a log message is written. + * + * @param intent the intent to analyze + * @return a new Location object with latitude/longitude from the intent or null if the intent is not a valid geo scheme intent. + */ private Location getLocationForGeoIntent(Intent intent) { if (intent==null) { -- 2.39.2