Merge pull request #10429 from osmandapp/fix_10396

Fix_10396
This commit is contained in:
vshcherb 2020-12-17 17:49:42 +01:00 committed by GitHub
commit 2fcea75c68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 115 additions and 46 deletions

View file

@ -11,15 +11,18 @@ public class NavigateGpxParams extends AidlParams {
private String data; private String data;
private Uri uri; private Uri uri;
private boolean force; private boolean force;
private boolean needLocationPermission;
public NavigateGpxParams(String data, boolean force) { public NavigateGpxParams(String data, boolean force, boolean needLocationPermission) {
this.data = data; this.data = data;
this.force = force; this.force = force;
this.needLocationPermission = needLocationPermission;
} }
public NavigateGpxParams(Uri uri, boolean force) { public NavigateGpxParams(Uri uri, boolean force, boolean needLocationPermission) {
this.uri = uri; this.uri = uri;
this.force = force; this.force = force;
this.needLocationPermission = needLocationPermission;
} }
public NavigateGpxParams(Parcel in) { public NavigateGpxParams(Parcel in) {
@ -50,11 +53,16 @@ public class NavigateGpxParams extends AidlParams {
return force; return force;
} }
public boolean isNeedLocationPermission() {
return needLocationPermission;
}
@Override @Override
public void writeToBundle(Bundle bundle) { public void writeToBundle(Bundle bundle) {
bundle.putString("data", data); bundle.putString("data", data);
bundle.putParcelable("uri", uri); bundle.putParcelable("uri", uri);
bundle.putBoolean("force", force); bundle.putBoolean("force", force);
bundle.putBoolean("needLocationPermission", needLocationPermission);
} }
@Override @Override
@ -62,5 +70,6 @@ public class NavigateGpxParams extends AidlParams {
data = bundle.getString("data"); data = bundle.getString("data");
uri = bundle.getParcelable("uri"); uri = bundle.getParcelable("uri");
force = bundle.getBoolean("force"); force = bundle.getBoolean("force");
needLocationPermission = bundle.getBoolean("needLocationPermission");
} }
} }

View file

@ -17,8 +17,10 @@ public class NavigateParams extends AidlParams {
private double destLon; private double destLon;
private boolean force; private boolean force;
private boolean needLocationPermission;
public NavigateParams(String startName, double startLat, double startLon, String destName, double destLat, double destLon, String profile, boolean force) { public NavigateParams(String startName, double startLat, double startLon, String destName, double destLat,
double destLon, String profile, boolean force, boolean needLocationPermission) {
this.startName = startName; this.startName = startName;
this.startLat = startLat; this.startLat = startLat;
this.startLon = startLon; this.startLon = startLon;
@ -27,6 +29,7 @@ public class NavigateParams extends AidlParams {
this.destLon = destLon; this.destLon = destLon;
this.profile = profile; this.profile = profile;
this.force = force; this.force = force;
this.needLocationPermission = needLocationPermission;
} }
public NavigateParams(Parcel in) { public NavigateParams(Parcel in) {
@ -77,6 +80,10 @@ public class NavigateParams extends AidlParams {
return force; return force;
} }
public boolean isNeedLocationPermission() {
return needLocationPermission;
}
@Override @Override
public void writeToBundle(Bundle bundle) { public void writeToBundle(Bundle bundle) {
bundle.putString("startName", startName); bundle.putString("startName", startName);
@ -87,6 +94,7 @@ public class NavigateParams extends AidlParams {
bundle.putDouble("destLon", destLon); bundle.putDouble("destLon", destLon);
bundle.putString("profile", profile); bundle.putString("profile", profile);
bundle.putBoolean("force", force); bundle.putBoolean("force", force);
bundle.putBoolean("needLocationPermission", needLocationPermission);
} }
@Override @Override
@ -99,5 +107,6 @@ public class NavigateParams extends AidlParams {
destLon = bundle.getDouble("destLon"); destLon = bundle.getDouble("destLon");
profile = bundle.getString("profile"); profile = bundle.getString("profile");
force = bundle.getBoolean("force"); force = bundle.getBoolean("force");
needLocationPermission = bundle.getBoolean("needLocationPermission");
} }
} }

View file

@ -17,10 +17,11 @@ public class NavigateSearchParams extends AidlParams {
private double searchLon; private double searchLon;
private boolean force; private boolean force;
private boolean needLocationPermission;
public NavigateSearchParams(String startName, double startLat, double startLon, public NavigateSearchParams(String startName, double startLat, double startLon,
String searchQuery, double searchLat, double searchLon, String searchQuery, double searchLat, double searchLon,
String profile, boolean force) { String profile, boolean force, boolean needLocationPermission) {
this.startName = startName; this.startName = startName;
this.startLat = startLat; this.startLat = startLat;
this.startLon = startLon; this.startLon = startLon;
@ -29,6 +30,7 @@ public class NavigateSearchParams extends AidlParams {
this.searchLon = searchLon; this.searchLon = searchLon;
this.profile = profile; this.profile = profile;
this.force = force; this.force = force;
this.needLocationPermission = needLocationPermission;
} }
public NavigateSearchParams(Parcel in) { public NavigateSearchParams(Parcel in) {
@ -79,6 +81,10 @@ public class NavigateSearchParams extends AidlParams {
return force; return force;
} }
public boolean isNeedLocationPermission() {
return needLocationPermission;
}
@Override @Override
public void writeToBundle(Bundle bundle) { public void writeToBundle(Bundle bundle) {
bundle.putString("startName", startName); bundle.putString("startName", startName);
@ -89,6 +95,7 @@ public class NavigateSearchParams extends AidlParams {
bundle.putBoolean("force", force); bundle.putBoolean("force", force);
bundle.putDouble("searchLat", searchLat); bundle.putDouble("searchLat", searchLat);
bundle.putDouble("searchLon", searchLon); bundle.putDouble("searchLon", searchLon);
bundle.putBoolean("needLocationPermission", needLocationPermission);
} }
@Override @Override
@ -101,5 +108,6 @@ public class NavigateSearchParams extends AidlParams {
force = bundle.getBoolean("force"); force = bundle.getBoolean("force");
searchLat = bundle.getDouble("searchLat"); searchLat = bundle.getDouble("searchLat");
searchLon = bundle.getDouble("searchLon"); searchLon = bundle.getDouble("searchLon");
needLocationPermission = bundle.getBoolean("needLocationPermission");
} }
} }

View file

@ -182,6 +182,7 @@ public class OsmandAidlApi {
private static final String AIDL_DATA = "aidl_data"; private static final String AIDL_DATA = "aidl_data";
private static final String AIDL_URI = "aidl_uri"; private static final String AIDL_URI = "aidl_uri";
private static final String AIDL_FORCE = "aidl_force"; private static final String AIDL_FORCE = "aidl_force";
private static final String AIDL_LOCATION_PERMISSION = "aidl_location_permission";
private static final String AIDL_SEARCH_QUERY = "aidl_search_query"; private static final String AIDL_SEARCH_QUERY = "aidl_search_query";
private static final String AIDL_SEARCH_LAT = "aidl_search_lat"; private static final String AIDL_SEARCH_LAT = "aidl_search_lat";
private static final String AIDL_SEARCH_LON = "aidl_search_lon"; private static final String AIDL_SEARCH_LON = "aidl_search_lon";
@ -606,6 +607,7 @@ public class OsmandAidlApi {
final RoutingHelper routingHelper = app.getRoutingHelper(); final RoutingHelper routingHelper = app.getRoutingHelper();
boolean force = intent.getBooleanExtra(AIDL_FORCE, true); boolean force = intent.getBooleanExtra(AIDL_FORCE, true);
final boolean locationPermission = intent.getBooleanExtra(AIDL_LOCATION_PERMISSION, false);
if (routingHelper.isFollowingMode() && !force) { if (routingHelper.isFollowingMode() && !force) {
mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() { mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() {
@ -613,12 +615,12 @@ public class OsmandAidlApi {
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
MapActivity mapActivity = mapActivityRef.get(); MapActivity mapActivity = mapActivityRef.get();
if (mapActivity != null && !routingHelper.isFollowingMode()) { if (mapActivity != null && !routingHelper.isFollowingMode()) {
ExternalApiHelper.startNavigation(mapActivity, start, startDesc, dest, destDesc, profile); ExternalApiHelper.startNavigation(mapActivity, start, startDesc, dest, destDesc, profile, locationPermission);
} }
} }
}); });
} else { } else {
ExternalApiHelper.startNavigation(mapActivity, start, startDesc, dest, destDesc, profile); ExternalApiHelper.startNavigation(mapActivity, start, startDesc, dest, destDesc, profile, locationPermission);
} }
} }
} }
@ -672,6 +674,7 @@ public class OsmandAidlApi {
if (searchLocation != null) { if (searchLocation != null) {
final RoutingHelper routingHelper = app.getRoutingHelper(); final RoutingHelper routingHelper = app.getRoutingHelper();
boolean force = intent.getBooleanExtra(AIDL_FORCE, true); boolean force = intent.getBooleanExtra(AIDL_FORCE, true);
final boolean locationPermission = intent.getBooleanExtra(AIDL_LOCATION_PERMISSION, false);
if (routingHelper.isFollowingMode() && !force) { if (routingHelper.isFollowingMode() && !force) {
mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() { mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() {
@ -679,12 +682,14 @@ public class OsmandAidlApi {
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
MapActivity mapActivity = mapActivityRef.get(); MapActivity mapActivity = mapActivityRef.get();
if (mapActivity != null && !routingHelper.isFollowingMode()) { if (mapActivity != null && !routingHelper.isFollowingMode()) {
ExternalApiHelper.searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, false); ExternalApiHelper.searchAndNavigate(mapActivity, searchLocation, start,
startDesc, profile, searchQuery, false, locationPermission);
} }
} }
}); });
} else { } else {
ExternalApiHelper.searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, false); ExternalApiHelper.searchAndNavigate(mapActivity, searchLocation, start,
startDesc, profile, searchQuery, false, locationPermission);
} }
} }
} }
@ -703,7 +708,8 @@ public class OsmandAidlApi {
GPXFile gpx = loadGpxFileFromIntent(mapActivity, intent); GPXFile gpx = loadGpxFileFromIntent(mapActivity, intent);
if (gpx != null) { if (gpx != null) {
boolean force = intent.getBooleanExtra(AIDL_FORCE, false); boolean force = intent.getBooleanExtra(AIDL_FORCE, false);
ExternalApiHelper.saveAndNavigateGpx(mapActivity, gpx, force); boolean locationPermission = intent.getBooleanExtra(AIDL_LOCATION_PERMISSION, false);
ExternalApiHelper.saveAndNavigateGpx(mapActivity, gpx, force, locationPermission);
} }
} }
} }
@ -1658,7 +1664,7 @@ public class OsmandAidlApi {
boolean navigate(String startName, double startLat, double startLon, boolean navigate(String startName, double startLat, double startLon,
String destName, double destLat, double destLon, String destName, double destLat, double destLon,
String profile, boolean force) { String profile, boolean force, boolean requestLocationPermission) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(AIDL_NAVIGATE); intent.setAction(AIDL_NAVIGATE);
intent.putExtra(AIDL_START_NAME, startName); intent.putExtra(AIDL_START_NAME, startName);
@ -1669,13 +1675,14 @@ public class OsmandAidlApi {
intent.putExtra(AIDL_DEST_LON, destLon); intent.putExtra(AIDL_DEST_LON, destLon);
intent.putExtra(AIDL_PROFILE, profile); intent.putExtra(AIDL_PROFILE, profile);
intent.putExtra(AIDL_FORCE, force); intent.putExtra(AIDL_FORCE, force);
intent.putExtra(AIDL_LOCATION_PERMISSION, requestLocationPermission);
app.sendBroadcast(intent); app.sendBroadcast(intent);
return true; return true;
} }
boolean navigateSearch(String startName, double startLat, double startLon, boolean navigateSearch(String startName, double startLat, double startLon,
String searchQuery, double searchLat, double searchLon, String searchQuery, double searchLat, double searchLon,
String profile, boolean force) { String profile, boolean force, boolean requestLocationPermission) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(AIDL_NAVIGATE_SEARCH); intent.setAction(AIDL_NAVIGATE_SEARCH);
intent.putExtra(AIDL_START_NAME, startName); intent.putExtra(AIDL_START_NAME, startName);
@ -1686,6 +1693,7 @@ public class OsmandAidlApi {
intent.putExtra(AIDL_SEARCH_LON, searchLon); intent.putExtra(AIDL_SEARCH_LON, searchLon);
intent.putExtra(AIDL_PROFILE, profile); intent.putExtra(AIDL_PROFILE, profile);
intent.putExtra(AIDL_FORCE, force); intent.putExtra(AIDL_FORCE, force);
intent.putExtra(AIDL_LOCATION_PERMISSION, requestLocationPermission);
app.sendBroadcast(intent); app.sendBroadcast(intent);
return true; return true;
} }
@ -1725,12 +1733,13 @@ public class OsmandAidlApi {
return true; return true;
} }
boolean navigateGpx(String data, Uri uri, boolean force) { boolean navigateGpx(String data, Uri uri, boolean force, boolean requestLocationPermission) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(AIDL_NAVIGATE_GPX); intent.setAction(AIDL_NAVIGATE_GPX);
intent.putExtra(AIDL_DATA, data); intent.putExtra(AIDL_DATA, data);
intent.putExtra(AIDL_URI, uri); intent.putExtra(AIDL_URI, uri);
intent.putExtra(AIDL_FORCE, force); intent.putExtra(AIDL_FORCE, force);
intent.putExtra(AIDL_LOCATION_PERMISSION, requestLocationPermission);
app.sendBroadcast(intent); app.sendBroadcast(intent);
return true; return true;
} }

View file

@ -44,6 +44,7 @@ import net.osmand.aidl.gpx.RemoveGpxParams;
import net.osmand.aidl.gpx.ShowGpxParams; import net.osmand.aidl.gpx.ShowGpxParams;
import net.osmand.aidl.gpx.StartGpxRecordingParams; import net.osmand.aidl.gpx.StartGpxRecordingParams;
import net.osmand.aidl.gpx.StopGpxRecordingParams; import net.osmand.aidl.gpx.StopGpxRecordingParams;
import net.osmand.aidl.lock.SetLockStateParams;
import net.osmand.aidl.map.ALatLon; import net.osmand.aidl.map.ALatLon;
import net.osmand.aidl.map.SetMapLocationParams; import net.osmand.aidl.map.SetMapLocationParams;
import net.osmand.aidl.maplayer.AddMapLayerParams; import net.osmand.aidl.maplayer.AddMapLayerParams;
@ -85,10 +86,9 @@ import net.osmand.aidl.quickaction.QuickActionParams;
import net.osmand.aidl.search.SearchParams; import net.osmand.aidl.search.SearchParams;
import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.search.SearchResult;
import net.osmand.aidl.tiles.ASqliteDbFile; import net.osmand.aidl.tiles.ASqliteDbFile;
import net.osmand.aidl.lock.SetLockStateParams;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.settings.backend.OsmAndAppCustomization;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmAndAppCustomization;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -736,7 +736,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
return params != null && api != null && api.navigate( return params != null && api != null && api.navigate(
params.getStartName(), params.getStartLat(), params.getStartLon(), params.getStartName(), params.getStartLat(), params.getStartLon(),
params.getDestName(), params.getDestLat(), params.getDestLon(), params.getDestName(), params.getDestLat(), params.getDestLon(),
params.getProfile(), params.isForce()); params.getProfile(), params.isForce(), params.isNeedLocationPermission());
} catch (Exception e) { } catch (Exception e) {
handleException(e); handleException(e);
return false; return false;
@ -747,7 +747,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
public boolean navigateGpx(NavigateGpxParams params) { public boolean navigateGpx(NavigateGpxParams params) {
try { try {
OsmandAidlApi api = getApi("navigateGpx"); OsmandAidlApi api = getApi("navigateGpx");
return params != null && api != null && api.navigateGpx(params.getData(), params.getUri(), params.isForce()); return params != null && api != null && api.navigateGpx(params.getData(), params.getUri(),
params.isForce(), params.isNeedLocationPermission());
} catch (Exception e) { } catch (Exception e) {
handleException(e); handleException(e);
return false; return false;
@ -857,7 +858,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
return params != null && api != null && api.navigateSearch( return params != null && api != null && api.navigateSearch(
params.getStartName(), params.getStartLat(), params.getStartLon(), params.getStartName(), params.getStartLat(), params.getStartLon(),
params.getSearchQuery(), params.getSearchLat(), params.getSearchLon(), params.getSearchQuery(), params.getSearchLat(), params.getSearchLon(),
params.getProfile(), params.isForce()); params.getProfile(), params.isForce(), params.isNeedLocationPermission());
} catch (Exception e) { } catch (Exception e) {
handleException(e); handleException(e);
return false; return false;
@ -1328,6 +1329,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
return false; return false;
} }
} }
@Override @Override
public boolean setLockState(SetLockStateParams params) { public boolean setLockState(SetLockStateParams params) {
try { try {

View file

@ -696,7 +696,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
return params != null && api != null && api.navigate( return params != null && api != null && api.navigate(
params.getStartName(), params.getStartLat(), params.getStartLon(), params.getStartName(), params.getStartLat(), params.getStartLon(),
params.getDestName(), params.getDestLat(), params.getDestLon(), params.getDestName(), params.getDestLat(), params.getDestLon(),
params.getProfile(), params.isForce()); params.getProfile(), params.isForce(), params.isNeedLocationPermission());
} catch (Exception e) { } catch (Exception e) {
handleException(e); handleException(e);
return false; return false;
@ -707,7 +707,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
public boolean navigateGpx(NavigateGpxParams params) { public boolean navigateGpx(NavigateGpxParams params) {
try { try {
OsmandAidlApi api = getApi("navigateGpx"); OsmandAidlApi api = getApi("navigateGpx");
return params != null && api != null && api.navigateGpx(params.getData(), params.getUri(), params.isForce()); return params != null && api != null && api.navigateGpx(params.getData(), params.getUri(),
params.isForce(), params.isNeedLocationPermission());
} catch (Exception e) { } catch (Exception e) {
handleException(e); handleException(e);
return false; return false;
@ -817,7 +818,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
return params != null && api != null && api.navigateSearch( return params != null && api != null && api.navigateSearch(
params.getStartName(), params.getStartLat(), params.getStartLon(), params.getStartName(), params.getStartLat(), params.getStartLon(),
params.getSearchQuery(), params.getSearchLat(), params.getSearchLon(), params.getSearchQuery(), params.getSearchLat(), params.getSearchLon(),
params.getProfile(), params.isForce()); params.getProfile(), params.isForce(), params.isNeedLocationPermission());
} catch (Exception e) { } catch (Exception e) {
handleException(e); handleException(e);
return false; return false;

View file

@ -9,15 +9,18 @@ public class NavigateGpxParams implements Parcelable {
private String data; private String data;
private Uri uri; private Uri uri;
private boolean force; private boolean force;
private boolean needLocationPermission;
public NavigateGpxParams(String data, boolean force) { public NavigateGpxParams(String data, boolean force, boolean needLocationPermission) {
this.data = data; this.data = data;
this.force = force; this.force = force;
this.needLocationPermission = needLocationPermission;
} }
public NavigateGpxParams(Uri uri, boolean force) { public NavigateGpxParams(Uri uri, boolean force, boolean needLocationPermission) {
this.uri = uri; this.uri = uri;
this.force = force; this.force = force;
this.needLocationPermission = needLocationPermission;
} }
public NavigateGpxParams(Parcel in) { public NavigateGpxParams(Parcel in) {
@ -48,22 +51,27 @@ public class NavigateGpxParams implements Parcelable {
return force; return force;
} }
public boolean isNeedLocationPermission() {
return needLocationPermission;
}
@Override @Override
public void writeToParcel(Parcel out, int flags) { public void writeToParcel(Parcel out, int flags) {
out.writeString(data); out.writeString(data);
out.writeParcelable(uri, flags); out.writeParcelable(uri, flags);
out.writeByte((byte) (force ? 1 : 0)); out.writeByte((byte) (force ? 1 : 0));
out.writeByte((byte) (needLocationPermission ? 1 : 0));
} }
private void readFromParcel(Parcel in) { private void readFromParcel(Parcel in) {
data = in.readString(); data = in.readString();
uri = in.readParcelable(Uri.class.getClassLoader()); uri = in.readParcelable(Uri.class.getClassLoader());
force = in.readByte() != 0; force = in.readByte() != 0;
needLocationPermission = in.readByte() != 0;
} }
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;
} }
} }

View file

@ -13,8 +13,10 @@ public class NavigateParams implements Parcelable {
private double destLon; private double destLon;
private String profile; private String profile;
private boolean force; private boolean force;
private boolean needLocationPermission;
public NavigateParams(String startName, double startLat, double startLon, String destName, double destLat, double destLon, String profile, boolean force) { public NavigateParams(String startName, double startLat, double startLon, String destName, double destLat,
double destLon, String profile, boolean force, boolean needLocationPermission) {
this.startName = startName; this.startName = startName;
this.startLat = startLat; this.startLat = startLat;
this.startLon = startLon; this.startLon = startLon;
@ -23,6 +25,7 @@ public class NavigateParams implements Parcelable {
this.destLon = destLon; this.destLon = destLon;
this.profile = profile; this.profile = profile;
this.force = force; this.force = force;
this.needLocationPermission = needLocationPermission;
} }
public NavigateParams(Parcel in) { public NavigateParams(Parcel in) {
@ -73,6 +76,10 @@ public class NavigateParams implements Parcelable {
return force; return force;
} }
public boolean isNeedLocationPermission() {
return needLocationPermission;
}
@Override @Override
public void writeToParcel(Parcel out, int flags) { public void writeToParcel(Parcel out, int flags) {
out.writeString(startName); out.writeString(startName);
@ -83,6 +90,7 @@ public class NavigateParams implements Parcelable {
out.writeDouble(destLon); out.writeDouble(destLon);
out.writeString(profile); out.writeString(profile);
out.writeByte((byte) (force ? 1 : 0)); out.writeByte((byte) (force ? 1 : 0));
out.writeByte((byte) (needLocationPermission ? 1 : 0));
} }
private void readFromParcel(Parcel in) { private void readFromParcel(Parcel in) {
@ -94,11 +102,11 @@ public class NavigateParams implements Parcelable {
destLon = in.readDouble(); destLon = in.readDouble();
profile = in.readString(); profile = in.readString();
force = in.readByte() != 0; force = in.readByte() != 0;
needLocationPermission = in.readByte() != 0;
} }
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;
} }
} }

View file

@ -13,10 +13,11 @@ public class NavigateSearchParams implements Parcelable {
private double searchLon; private double searchLon;
private String profile; private String profile;
private boolean force; private boolean force;
private boolean needLocationPermission;
public NavigateSearchParams(String startName, double startLat, double startLon, public NavigateSearchParams(String startName, double startLat, double startLon,
String searchQuery, double searchLat, double searchLon, String searchQuery, double searchLat, double searchLon,
String profile, boolean force) { String profile, boolean force, boolean needLocationPermission) {
this.startName = startName; this.startName = startName;
this.startLat = startLat; this.startLat = startLat;
this.startLon = startLon; this.startLon = startLon;
@ -25,6 +26,7 @@ public class NavigateSearchParams implements Parcelable {
this.searchLon = searchLon; this.searchLon = searchLon;
this.profile = profile; this.profile = profile;
this.force = force; this.force = force;
this.needLocationPermission = needLocationPermission;
} }
public NavigateSearchParams(Parcel in) { public NavigateSearchParams(Parcel in) {
@ -75,6 +77,10 @@ public class NavigateSearchParams implements Parcelable {
return force; return force;
} }
public boolean isNeedLocationPermission() {
return needLocationPermission;
}
@Override @Override
public void writeToParcel(Parcel out, int flags) { public void writeToParcel(Parcel out, int flags) {
out.writeString(startName); out.writeString(startName);
@ -85,6 +91,7 @@ public class NavigateSearchParams implements Parcelable {
out.writeByte((byte) (force ? 1 : 0)); out.writeByte((byte) (force ? 1 : 0));
out.writeDouble(searchLat); out.writeDouble(searchLat);
out.writeDouble(searchLon); out.writeDouble(searchLon);
out.writeByte((byte) (needLocationPermission ? 1 : 0));
} }
private void readFromParcel(Parcel in) { private void readFromParcel(Parcel in) {
@ -96,11 +103,11 @@ public class NavigateSearchParams implements Parcelable {
force = in.readByte() != 0; force = in.readByte() != 0;
searchLat = in.readDouble(); searchLat = in.readDouble();
searchLon = in.readDouble(); searchLon = in.readDouble();
needLocationPermission = in.readByte() != 0;
} }
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;
} }
} }

View file

@ -30,6 +30,7 @@ import net.osmand.data.PointDescription;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -129,6 +130,7 @@ public class ExternalApiHelper {
public static final String PARAM_URI = "uri"; public static final String PARAM_URI = "uri";
public static final String PARAM_DATA = "data"; public static final String PARAM_DATA = "data";
public static final String PARAM_FORCE = "force"; public static final String PARAM_FORCE = "force";
public static final String PARAM_LOCATION_PERMISSION = "location_permission";
public static final String PARAM_START_NAME = "start_name"; public static final String PARAM_START_NAME = "start_name";
public static final String PARAM_DEST_NAME = "dest_name"; public static final String PARAM_DEST_NAME = "dest_name";
@ -240,7 +242,8 @@ public class ExternalApiHelper {
if (gpx != null) { if (gpx != null) {
if (navigate) { if (navigate) {
boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false); boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false);
saveAndNavigateGpx(mapActivity, gpx, force); boolean locationPermission = uri.getBooleanQueryParameter(PARAM_LOCATION_PERMISSION, false);
saveAndNavigateGpx(mapActivity, gpx, force, locationPermission);
} else { } else {
app.getSelectedGpxHelper().setGpxFileToDisplay(gpx); app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
} }
@ -292,6 +295,7 @@ public class ExternalApiHelper {
final PointDescription destDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, destName); final PointDescription destDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, destName);
boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false); boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false);
final boolean locationPermission = uri.getBooleanQueryParameter(PARAM_LOCATION_PERMISSION, false);
final RoutingHelper routingHelper = app.getRoutingHelper(); final RoutingHelper routingHelper = app.getRoutingHelper();
if (routingHelper.isFollowingMode() && !force) { if (routingHelper.isFollowingMode() && !force) {
@ -300,12 +304,12 @@ public class ExternalApiHelper {
@Override @Override
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
if (!routingHelper.isFollowingMode()) { if (!routingHelper.isFollowingMode()) {
startNavigation(mapActivity, start, startDesc, dest, destDesc, profile); startNavigation(mapActivity, start, startDesc, dest, destDesc, profile, locationPermission);
} }
} }
}); });
} else { } else {
startNavigation(mapActivity, start, startDesc, dest, destDesc, profile); startNavigation(mapActivity, start, startDesc, dest, destDesc, profile, locationPermission);
} }
} }
@ -351,6 +355,7 @@ public class ExternalApiHelper {
resultCode = RESULT_CODE_ERROR_SEARCH_LOCATION_UNDEFINED; resultCode = RESULT_CODE_ERROR_SEARCH_LOCATION_UNDEFINED;
} else { } else {
boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false); boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false);
final boolean locationPermission = uri.getBooleanQueryParameter(PARAM_LOCATION_PERMISSION, false);
final RoutingHelper routingHelper = app.getRoutingHelper(); final RoutingHelper routingHelper = app.getRoutingHelper();
if (routingHelper.isFollowingMode() && !force) { if (routingHelper.isFollowingMode() && !force) {
@ -359,12 +364,12 @@ public class ExternalApiHelper {
@Override @Override
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
if (!routingHelper.isFollowingMode()) { if (!routingHelper.isFollowingMode()) {
searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, showSearchResults); searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, showSearchResults, locationPermission);
} }
} }
}); });
} else { } else {
searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, showSearchResults); searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, showSearchResults, locationPermission);
} }
resultCode = Activity.RESULT_OK; resultCode = Activity.RESULT_OK;
} }
@ -632,7 +637,8 @@ public class ExternalApiHelper {
return null; return null;
} }
public static void saveAndNavigateGpx(MapActivity mapActivity, final GPXFile gpxFile, final boolean force) { public static void saveAndNavigateGpx(MapActivity mapActivity, final GPXFile gpxFile,
final boolean force, final boolean checkLocationPermission) {
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity); final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
if (Algorithms.isEmpty(gpxFile.path)) { if (Algorithms.isEmpty(gpxFile.path)) {
@ -673,12 +679,12 @@ public class ExternalApiHelper {
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
MapActivity mapActivity = mapActivityRef.get(); MapActivity mapActivity = mapActivityRef.get();
if (mapActivity != null && !routingHelper.isFollowingMode()) { if (mapActivity != null && !routingHelper.isFollowingMode()) {
ExternalApiHelper.startNavigation(mapActivity, gpxFile); ExternalApiHelper.startNavigation(mapActivity, gpxFile, checkLocationPermission);
} }
} }
}); });
} else { } else {
startNavigation(mapActivity, gpxFile); startNavigation(mapActivity, gpxFile, checkLocationPermission);
} }
} }
} }
@ -711,23 +717,22 @@ public class ExternalApiHelper {
mapContextMenu.show(new LatLon(lat, lon), pointDescription, object); mapContextMenu.show(new LatLon(lat, lon), pointDescription, object);
} }
static public void startNavigation(MapActivity mapActivity, static public void startNavigation(MapActivity mapActivity, @NonNull GPXFile gpx, boolean checkLocationPermission) {
@NonNull GPXFile gpx) { startNavigation(mapActivity, gpx, null, null, null, null, null, checkLocationPermission);
startNavigation(mapActivity, gpx, null, null, null, null, null);
} }
static public void startNavigation(MapActivity mapActivity, static public void startNavigation(MapActivity mapActivity,
@Nullable LatLon from, @Nullable PointDescription fromDesc, @Nullable LatLon from, @Nullable PointDescription fromDesc,
@Nullable LatLon to, @Nullable PointDescription toDesc, @Nullable LatLon to, @Nullable PointDescription toDesc,
@NonNull ApplicationMode mode) { @NonNull ApplicationMode mode, boolean checkLocationPermission) {
startNavigation(mapActivity, null, from, fromDesc, to, toDesc, mode); startNavigation(mapActivity, null, from, fromDesc, to, toDesc, mode, checkLocationPermission);
} }
static private void startNavigation(MapActivity mapActivity, static private void startNavigation(MapActivity mapActivity,
GPXFile gpx, GPXFile gpx,
LatLon from, PointDescription fromDesc, LatLon from, PointDescription fromDesc,
LatLon to, PointDescription toDesc, LatLon to, PointDescription toDesc,
ApplicationMode mode) { ApplicationMode mode, boolean checkLocationPermission) {
OsmandApplication app = mapActivity.getMyApplication(); OsmandApplication app = mapActivity.getMyApplication();
RoutingHelper routingHelper = app.getRoutingHelper(); RoutingHelper routingHelper = app.getRoutingHelper();
if (gpx == null) { if (gpx == null) {
@ -751,12 +756,15 @@ public class ExternalApiHelper {
app.getRoutingHelper().notifyIfRouteIsCalculated(); app.getRoutingHelper().notifyIfRouteIsCalculated();
routingHelper.setCurrentLocation(app.getLocationProvider().getLastKnownLocation(), false); routingHelper.setCurrentLocation(app.getLocationProvider().getLastKnownLocation(), false);
} }
if (checkLocationPermission) {
OsmAndLocationProvider.requestFineLocationPermissionIfNeeded(mapActivity);
}
} }
static public void searchAndNavigate(@NonNull MapActivity mapActivity, @NonNull final LatLon searchLocation, static public void searchAndNavigate(@NonNull MapActivity mapActivity, @NonNull final LatLon searchLocation,
@Nullable final LatLon from, @Nullable final PointDescription fromDesc, @Nullable final LatLon from, @Nullable final PointDescription fromDesc,
@NonNull final ApplicationMode mode, @NonNull final String searchQuery, @NonNull final ApplicationMode mode, @NonNull final String searchQuery,
final boolean showSearchResults) { final boolean showSearchResults, final boolean checkLocationPermission) {
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity); final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
OsmandApplication app = mapActivity.getMyApplication(); OsmandApplication app = mapActivity.getMyApplication();
@ -797,7 +805,7 @@ public class ExternalApiHelper {
LatLon to = new LatLon(res.getLatitude(), res.getLongitude()); LatLon to = new LatLon(res.getLatitude(), res.getLongitude());
PointDescription toDesc = new PointDescription( PointDescription toDesc = new PointDescription(
PointDescription.POINT_TYPE_TARGET, res.getLocalName() + ", " + res.getLocalTypeName()); PointDescription.POINT_TYPE_TARGET, res.getLocalName() + ", " + res.getLocalTypeName());
startNavigation(mapActivity, from, fromDesc, to, toDesc, mode); startNavigation(mapActivity, from, fromDesc, to, toDesc, mode, checkLocationPermission);
} else { } else {
mapActivity.getMyApplication().showToastMessage(mapActivity.getString(R.string.search_nothing_found)); mapActivity.getMyApplication().showToastMessage(mapActivity.getString(R.string.search_nothing_found));
} }