Support for geobookmark creation from external geo uris
This commit is contained in:
parent
065ef2bea6
commit
fd14eea4b9
@ -24,8 +24,8 @@ android {
|
||||
applicationId "it.danieleverducci.nextcloudmaps"
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 30
|
||||
versionCode 4
|
||||
versionName "0.3.2"
|
||||
versionCode 5
|
||||
versionName "0.3.3"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
@ -167,6 +167,7 @@ public class GeofavoriteDetailActivity extends AppCompatActivity implements Loca
|
||||
mGeofavorite.setLng(coords[1]);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Toast.makeText(this, R.string.error_unsupported_uri, Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
} else {
|
||||
// Precompile location with current one
|
||||
|
@ -56,6 +56,7 @@ import it.danieleverducci.nextcloudmaps.activity.login.LoginActivity;
|
||||
import it.danieleverducci.nextcloudmaps.activity.main.NavigationAdapter.NavigationItem;
|
||||
import it.danieleverducci.nextcloudmaps.activity.main.SortingOrderDialogFragment.OnSortingOrderListener;
|
||||
import it.danieleverducci.nextcloudmaps.model.Geofavorite;
|
||||
import it.danieleverducci.nextcloudmaps.utils.GeoUriParser;
|
||||
import it.danieleverducci.nextcloudmaps.utils.IntentGenerator;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package it.danieleverducci.nextcloudmaps.utils;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -8,12 +9,21 @@ import java.util.regex.Pattern;
|
||||
import it.danieleverducci.nextcloudmaps.model.Geofavorite;
|
||||
|
||||
public class GeoUriParser {
|
||||
private static final Pattern PATTERN_GEO = Pattern.compile("geo:[\\d.]+,[\\d.]+");
|
||||
private static final Pattern PATTERN_GEO = Pattern.compile("geo:(-?[\\d.]+),(-?[\\d.]+)");
|
||||
|
||||
public static double[] parseUri(Uri uri) throws IllegalArgumentException {
|
||||
Matcher m = PATTERN_GEO.matcher(uri.getPath());
|
||||
if (m.find()) {
|
||||
return new double[]{0, 0};
|
||||
if (uri == null)
|
||||
throw new IllegalArgumentException("no uri");
|
||||
|
||||
Matcher m = PATTERN_GEO.matcher(uri.toString());
|
||||
if (m.find() && m.groupCount() == 2) {
|
||||
String sLat = m.group(1);
|
||||
String sLon = m.group(2);
|
||||
try {
|
||||
return new double[]{Double.parseDouble(sLat), Double.parseDouble(sLon)};
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("unable to parse uri");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("unable to parse uri");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user