WIP accepting generic intents with geo:// uri
This commit is contained in:
		
							
								
								
									
										17
									
								
								.idea/deploymentTargetDropDown.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								.idea/deploymentTargetDropDown.xml
									
									
									
										generated
									
									
									
										Normal 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> | ||||
| @@ -17,5 +17,3 @@ This work is heavily based on [matiasdelellis's Nextcloud SSO example](https://g | ||||
|  | ||||
|        | ||||
|  | ||||
| Download it from [the releases page](https://github.com/penguin86/nextcloud-maps-client/releases) | ||||
|  | ||||
|   | ||||
| @@ -50,7 +50,17 @@ | ||||
|  | ||||
|         <activity | ||||
|             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 | ||||
|             android:name=".activity.about.AboutActivity" | ||||
|   | ||||
| @@ -59,6 +59,7 @@ import it.danieleverducci.nextcloudmaps.activity.main.MainActivityViewModel; | ||||
| import it.danieleverducci.nextcloudmaps.api.ApiProvider; | ||||
| import it.danieleverducci.nextcloudmaps.databinding.ActivityGeofavoriteDetailBinding; | ||||
| import it.danieleverducci.nextcloudmaps.model.Geofavorite; | ||||
| import it.danieleverducci.nextcloudmaps.utils.GeoUriParser; | ||||
| import it.danieleverducci.nextcloudmaps.utils.IntentGenerator; | ||||
| import retrofit2.Call; | ||||
| import retrofit2.Callback; | ||||
| @@ -158,8 +159,19 @@ public class GeofavoriteDetailActivity extends AppCompatActivity implements Loca | ||||
|             mGeofavorite.setDateModified(System.currentTimeMillis() / 1000); | ||||
|             mViewHolder.hideActions(); | ||||
|  | ||||
|             // Precompile location | ||||
|             getLocation(); | ||||
|             if (getIntent().getData() != null) { | ||||
|                 // 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); | ||||
|   | ||||
| @@ -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"); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -58,6 +58,7 @@ | ||||
|     <string name="location_permission_required">Location permission is required to create a geofavorite.</string> | ||||
|     <string name="confirm">Save</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="incomplete_geofavorite">Incomplete geofavorite: Name and category are mandatory</string> | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user