WIP accepting generic intents with geo:// uri

This commit is contained in:
Daniele 2021-09-30 20:52:09 +02:00
parent 15cea67818
commit 96b88a398c
6 changed files with 64 additions and 5 deletions

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/Nexus_4_API_30.avd" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2021-09-30T18:16:49.313988Z" />
</component>
</project>

View File

@ -17,5 +17,3 @@ This work is heavily based on [matiasdelellis's Nextcloud SSO example](https://g
![Screenshot 1](screenshots/1.png) ![Screenshot 1](screenshots/2.png) ![Screenshot 1](screenshots/1.png) ![Screenshot 1](screenshots/2.png)
Download it from [the releases page](https://github.com/penguin86/nextcloud-maps-client/releases)

View File

@ -50,7 +50,17 @@
<activity <activity
android:name=".activity.detail.GeofavoriteDetailActivity" android:name=".activity.detail.GeofavoriteDetailActivity"
android:theme="@style/AppTheme"/> android:theme="@style/AppTheme">
<!-- standard "geo" scheme -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="geo"/>
</intent-filter>
</activity>
<activity <activity
android:name=".activity.about.AboutActivity" android:name=".activity.about.AboutActivity"

View File

@ -59,6 +59,7 @@ import it.danieleverducci.nextcloudmaps.activity.main.MainActivityViewModel;
import it.danieleverducci.nextcloudmaps.api.ApiProvider; import it.danieleverducci.nextcloudmaps.api.ApiProvider;
import it.danieleverducci.nextcloudmaps.databinding.ActivityGeofavoriteDetailBinding; import it.danieleverducci.nextcloudmaps.databinding.ActivityGeofavoriteDetailBinding;
import it.danieleverducci.nextcloudmaps.model.Geofavorite; import it.danieleverducci.nextcloudmaps.model.Geofavorite;
import it.danieleverducci.nextcloudmaps.utils.GeoUriParser;
import it.danieleverducci.nextcloudmaps.utils.IntentGenerator; import it.danieleverducci.nextcloudmaps.utils.IntentGenerator;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
@ -158,8 +159,19 @@ public class GeofavoriteDetailActivity extends AppCompatActivity implements Loca
mGeofavorite.setDateModified(System.currentTimeMillis() / 1000); mGeofavorite.setDateModified(System.currentTimeMillis() / 1000);
mViewHolder.hideActions(); mViewHolder.hideActions();
// Precompile location if (getIntent().getData() != null) {
getLocation(); // Opened by external generic intent: parse URI
try {
double[] coords = GeoUriParser.parseUri(getIntent().getData());
mGeofavorite.setLat(coords[0]);
mGeofavorite.setLng(coords[1]);
} catch (IllegalArgumentException e) {
Toast.makeText(this, R.string.error_unsupported_uri, Toast.LENGTH_SHORT).show();
}
} else {
// Precompile location with current one
getLocation();
}
} }
mViewHolder.updateView(mGeofavorite); mViewHolder.updateView(mGeofavorite);

View File

@ -0,0 +1,21 @@
package it.danieleverducci.nextcloudmaps.utils;
import android.net.Uri;
import java.util.regex.Matcher;
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.]+");
public static double[] parseUri(Uri uri) throws IllegalArgumentException {
Matcher m = PATTERN_GEO.matcher(uri.getPath());
if (m.find()) {
return new double[]{0, 0};
} else {
throw new IllegalArgumentException("unable to parse uri");
}
}
}

View File

@ -58,6 +58,7 @@
<string name="location_permission_required">Location permission is required to create a geofavorite.</string> <string name="location_permission_required">Location permission is required to create a geofavorite.</string>
<string name="confirm">Save</string> <string name="confirm">Save</string>
<string name="error_saving_geofavorite">Unable to save geofavorite</string> <string name="error_saving_geofavorite">Unable to save geofavorite</string>
<string name="error_unsupported_uri">Unable to obtain coordinates from shared data</string>
<string name="geofavorite_saved">Geofavorite saved</string> <string name="geofavorite_saved">Geofavorite saved</string>
<string name="incomplete_geofavorite">Incomplete geofavorite: Name and category are mandatory</string> <string name="incomplete_geofavorite">Incomplete geofavorite: Name and category are mandatory</string>