Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to open location in another app #1396

Merged
merged 6 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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=".settings.SettingsActivity"
Expand Down
50 changes: 50 additions & 0 deletions app/src/main/java/de/westnordost/streetcomplete/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.graphics.Rect;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import androidx.annotation.AnyThread;
Expand Down Expand Up @@ -46,10 +47,14 @@
import android.widget.TextView;
import android.widget.Toast;

import com.mapzen.tangram.LngLat;

import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.concurrent.FutureTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.inject.Inject;

Expand Down Expand Up @@ -247,6 +252,36 @@ public void onServiceDisconnected(ComponentName className)
{
questController.deleteOld();
}

Intent intent = getIntent();
Uri data = intent.getData();
if (Intent.ACTION_VIEW.equals(intent.getAction()) && data != null)
{
if ("geo".equals(data.getScheme()))
{
double latitude = 0;
double longitude = 0;
float zoom = -1;

String geoUriRegex = "^geo:(-?[0-9]*\\.?[0-9]+),(-?[0-9]*\\.?[0-9]+).*?(?:\\?z=([0-9]*\\.?[0-9]+))?";
Pattern pattern = Pattern.compile(geoUriRegex);
Matcher matcher = pattern.matcher(data.toString());
while (matcher.find())
{
latitude = Double.parseDouble(matcher.group(1));
longitude = Double.parseDouble(matcher.group(2));
if (matcher.group(3) != null) {
zoom = Float.valueOf(matcher.group(3));
}
}

mapFragment.setPosition(new LngLat(longitude, latitude));
if (zoom != -1)
{
mapFragment.setZoom(zoom);
}
}
}
}

@Override public void onStart()
Expand Down Expand Up @@ -416,6 +451,21 @@ private void confirmUndo(final OsmQuest quest)
if(isConnected()) downloadDisplayedArea();
else Toast.makeText(this, R.string.offline, Toast.LENGTH_SHORT).show();
return true;
case R.id.action_open_location:
LatLon position = mapFragment.getPosition();
float zoom = mapFragment.getZoom();

Uri uri = Uri.parse(String.format("geo:%f,%f?z=%f",
position.getLatitude(),
position.getLongitude(),
zoom
));

intent = new Intent(Intent.ACTION_VIEW, uri);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
return true;
}

return super.onOptionsItemSelected(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,16 @@ public void setMapOrientation(float rotation, float tilt)
onMapOrientation(rotation, tilt);
}

public void setPosition(LngLat position)
{
controller.setPosition(position);
}

public void setZoom(float zoom)
{
controller.setZoom(zoom);
}

public float getRotation()
{
return controller != null ? controller.getRotation() : 0;
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
android:icon="@drawable/ic_undo_white_24dp" android:orderInCategory="1" app:showAsAction="ifRoom" />
<item android:id="@+id/action_download" android:title="@string/action_download"
android:orderInCategory="2" app:showAsAction="never" />
<item android:id="@+id/action_open_location" android:title="@string/action_open_location"
android:orderInCategory="3" app:showAsAction="never" />
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="3" app:showAsAction="never" />
<item android:id="@+id/action_about" android:title="@string/action_about"
android:orderInCategory="4" app:showAsAction="never" />
<item android:id="@+id/action_about" android:title="@string/action_about"
android:orderInCategory="5" app:showAsAction="never" />

</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -650,4 +650,5 @@ Otherwise, you can download another keyboard in the app store. Popular keyboards
<string name="theme_dark">Dark</string>
<string name="theme_system_default">System default</string>
<string name="quest_accessible_for_pedestrians_separate_sidewalk_explanation">This street was tagged as having no sidewalk on either side. In the case that there is a sidewalk after all but it is displayed as a separate way, please answer \"sidewalk\".</string>
<string name="action_open_location">Open location in another app</string>
</resources>