This commit is contained in:
Vitaliy 2020-12-17 17:16:01 +02:00
parent 323cb915d6
commit 4c7f39abb8
10 changed files with 117 additions and 48 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

@ -177,6 +177,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";
@ -208,7 +209,7 @@ public class OsmandAidlApi {
private static final ApplicationMode DEFAULT_PROFILE = ApplicationMode.CAR; private static final ApplicationMode DEFAULT_PROFILE = ApplicationMode.CAR;
private static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[]{ private static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[] {
ApplicationMode.CAR, ApplicationMode.CAR,
ApplicationMode.BICYCLE, ApplicationMode.BICYCLE,
ApplicationMode.PEDESTRIAN ApplicationMode.PEDESTRIAN
@ -287,7 +288,7 @@ public class OsmandAidlApi {
} }
private void initOsmandTelegram() { private void initOsmandTelegram() {
String[] packages = new String[]{"net.osmand.telegram", "net.osmand.telegram.debug"}; String[] packages = new String[] {"net.osmand.telegram", "net.osmand.telegram.debug"};
Intent intent = new Intent("net.osmand.telegram.InitApp"); Intent intent = new Intent("net.osmand.telegram.InitApp");
for (String pack : packages) { for (String pack : packages) {
intent.setComponent(new ComponentName(pack, "net.osmand.telegram.InitAppBroadcastReceiver")); intent.setComponent(new ComponentName(pack, "net.osmand.telegram.InitAppBroadcastReceiver"));
@ -601,6 +602,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() {
@ -608,12 +610,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);
} }
} }
} }
@ -667,6 +669,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() {
@ -674,12 +677,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);
} }
} }
} }
@ -698,7 +703,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);
} }
} }
} }
@ -1652,8 +1658,8 @@ 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);
@ -1664,13 +1670,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);
@ -1681,6 +1688,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;
} }
@ -1720,12 +1728,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

@ -693,7 +693,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;
@ -704,7 +704,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;
@ -814,7 +815,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";
@ -237,7 +239,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);
} }
@ -289,6 +292,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) {
@ -297,12 +301,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);
} }
} }
@ -348,6 +352,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) {
@ -356,12 +361,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;
} }
@ -629,7 +634,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)) {
@ -670,12 +676,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);
} }
} }
} }
@ -705,23 +711,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) {
@ -745,12 +750,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();
@ -791,7 +799,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));
} }