Skip to content

Commit

Permalink
Share geo links from other apps as suggested on report #62
Browse files Browse the repository at this point in the history
Tested with android calendar app.
  • Loading branch information
Starcommander committed Oct 8, 2018
1 parent f8488e6 commit 076c7b2
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 10 deletions.
4 changes: 2 additions & 2 deletions PocketMaps/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.junjunguo.pocketmaps"
minSdkVersion 19
targetSdkVersion 27
versionCode 12
versionName "2.2"
versionCode 13
versionName "2.3"
}

buildTypes {
Expand Down
22 changes: 20 additions & 2 deletions PocketMaps/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest
package="com.junjunguo.pocketmaps"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="12"
android:versionName="2.2">
android:versionCode="13"
android:versionName="2.3">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Expand Down Expand Up @@ -32,6 +32,24 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.ShowLocationActivity"
android:label="@string/title_activity_map"
android:screenOrientation="portrait"
android:theme="@style/MYAppTheme" >
<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>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="google.navigation" />
<data android:scheme="osmand.navigation" />
</intent-filter>
</activity>
<activity
android:name=".activities.MapActivity"
android:label="@string/title_activity_map"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ private void showSearchEngine()
geoSpinner.setAdapter(adapter);
okButton = (Button) findViewById(R.id.geoOk);
txtLocation = (EditText) findViewById(R.id.geoLocation);
String preText = ShowLocationActivity.locationSearchString;
if (preText != null)
{
txtLocation.setText(preText);
ShowLocationActivity.locationSearchString = null;
}
okButton.setOnClickListener(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,6 @@ private void initSearchLocationHandler(final boolean isStartP, final boolean fro
return true;
case MotionEvent.ACTION_UP:
if (setBg) setBgColor(pointItem, R.color.my_primary);
Intent intent = new Intent(activity, GeocodeActivity.class);
OnClickAddressListener callbackListener = createPosSelectedListener(isStartP);
GeoPoint[] points = null;
if (fromFavourite)
{
Expand All @@ -317,14 +315,23 @@ private void initSearchLocationHandler(final boolean isStartP, final boolean fro
points[2] = new GeoPoint(curLoc.getLatitude(), curLoc.getLongitude());
}
}
GeocodeActivity.setPre(callbackListener, points);
activity.startActivity(intent);
startGeocodeActivity(points, isStartP);
return true;
}
return false;
}
});
}

/** Shows the GeocodeActivity, or Favourites, if points are not null.
* @param points The points to add as favourites, [0]=start [1]=end [2]=cur. **/
public void startGeocodeActivity(GeoPoint[] points, boolean isStartP)
{
Intent intent = new Intent(activity, GeocodeActivity.class);
OnClickAddressListener callbackListener = createPosSelectedListener(isStartP);
GeocodeActivity.setPre(callbackListener, points);
activity.startActivity(intent);
}

private OnClickAddressListener createPosSelectedListener(final boolean isStartP)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ private void updateCurrentLocation(Location location) {
mapActions.showPositionBtn.setImageResource(R.drawable.ic_location_searching_white_24dp);
}
}

public MapActions getMapActions() { return mapActions; }

@Override public void onBackPressed() {
boolean back = mapActions.homeBackKeyPressed();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.junjunguo.pocketmaps.activities;

import java.util.Properties;
import java.util.Set;

import org.oscim.core.GeoPoint;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;

public class ShowLocationActivity extends AppCompatActivity
{
public static String locationSearchString;
public static GeoPoint locationGeoPoint;

@Override protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
handleInput();
showMain();
}

private void handleInput()
{
final Intent intent = getIntent();
try
{
Uri uri = intent.getData();
log("--> Got input uri: " + uri);
Properties prop = new Properties();
try
{
Set<String> keys = uri.getQueryParameterNames();
for (String key : keys)
{
String value = uri.getQueryParameter(key);
prop.setProperty(key, value);
log("--> Got input: " + key + "=" + value);
}
}
catch (UnsupportedOperationException e)
{ // Example: "geo:0,0?q=MySearchLocation"
log("Uri has no parameters, try parsing.");
int index = uri.toString().indexOf("?");
if (index < 0) { throw new IllegalArgumentException("Input-uri has no parameters!"); }
String[] values = uri.toString().substring(index+1).split("\\&");
for (String v : values)
{
index = v.indexOf('=');
if (index < 0) { continue; }
String key = v.substring(0, index);
String val = v.substring(index+1);
prop.setProperty(key, val);
}
}
locationSearchString = prop.getProperty("q");
if (locationSearchString!=null) { return; }
String lat = prop.getProperty("lat");
String lon = prop.getProperty("lat");
if (lat==null || lon==null)
{
throw new IllegalArgumentException("Missing input!");
}
double latD = Double.parseDouble(lat);
double lonD = Double.parseDouble(lon);
locationGeoPoint = new GeoPoint(latD, lonD);
}
catch (Exception e)
{
e.printStackTrace();
logUser("Error getting input: " + e.getMessage());
}
}

@Override protected void onResume()
{
super.onResume();
}

@Override protected void onDestroy()
{
super.onDestroy();
}

private void showMain()
{
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("com.junjunguo.pocketmaps.activities.MapActivity.SELECTNEWMAP", false);
startActivity(intent);
finish();
}

private void log(String str)
{
Log.i(ShowLocationActivity.class.getName(), str);
}

private void logUser(String str)
{
Log.i(ShowLocationActivity.class.getName(), str);
try
{
Toast.makeText(this.getBaseContext(), str, Toast.LENGTH_SHORT).show();
}
catch (Exception e) { e.printStackTrace(); }
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
import com.graphhopper.util.PointList;

import com.junjunguo.pocketmaps.R;
import com.junjunguo.pocketmaps.activities.MapActions;
import com.junjunguo.pocketmaps.activities.MapActivity;
import com.junjunguo.pocketmaps.activities.ShowLocationActivity;
import com.junjunguo.pocketmaps.model.listeners.MapHandlerListener;
import com.junjunguo.pocketmaps.navigator.NaviEngine;
import com.junjunguo.pocketmaps.util.TargetDirComputer;
Expand All @@ -60,7 +63,7 @@ public class MapHandler
private GeoPoint startMarker;
private GeoPoint endMarker;
private boolean needLocation = false;
private Activity activity;
private MapActivity activity;
private MapView mapView;
private ItemizedLayer<MarkerItem> itemizedLayer;
private ItemizedLayer<MarkerItem> customLayer;
Expand Down Expand Up @@ -105,7 +108,7 @@ private MapHandler()
needPathCal = false;
}

public void init(Activity activity, MapView mapView, String currentArea, File mapsFolder)
public void init(MapActivity activity, MapView mapView, String currentArea, File mapsFolder)
{
this.activity = activity;
this.mapView = mapView;
Expand Down Expand Up @@ -176,6 +179,17 @@ protected void onPostExecute(Path o) {
logUser("Finished loading graph.");
}

GeoPoint g = ShowLocationActivity.locationGeoPoint;
String lss = ShowLocationActivity.locationSearchString;
if (g != null)
{
activity.getMapActions().onPressLocation(g);
ShowLocationActivity.locationGeoPoint = null;
}
else if (lss != null)
{
activity.getMapActions().startGeocodeActivity(null, false);
}
prepareInProgress = false;
}
}.execute();
Expand Down

0 comments on commit 076c7b2

Please sign in to comment.