diff --git a/OsmAnd/res/layout/home_work_card.xml b/OsmAnd/res/layout/home_work_card.xml
index 20c0aebbad..eb6a47484e 100644
--- a/OsmAnd/res/layout/home_work_card.xml
+++ b/OsmAnd/res/layout/home_work_card.xml
@@ -9,9 +9,15 @@
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+
+
+
-
+ android:layout_height="14dp">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml
index ccb74ececa..ec6a83b6aa 100644
--- a/OsmAnd/res/values/sizes.xml
+++ b/OsmAnd/res/values/sizes.xml
@@ -278,6 +278,7 @@
32dp
40dp
60dp
+ 56dp
52dp
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index 6eea77d3c6..990f90a80e 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -10,6 +10,7 @@
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
Thx - Hardy
-->
+ Previous route
Add home
Add work
Work
diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java
index dc9a485173..cf0ca59460 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java
@@ -1894,6 +1894,9 @@ public class OsmandSettings {
public final static String START_POINT_DESCRIPTION_BACKUP = "start_point_description_backup"; //$NON-NLS-1$
public final static String INTERMEDIATE_POINTS_BACKUP = "intermediate_points_backup"; //$NON-NLS-1$
public final static String INTERMEDIATE_POINTS_DESCRIPTION_BACKUP = "intermediate_points_description_backup"; //$NON-NLS-1$
+ public final static String MY_LOC_POINT_LAT = "my_loc_point_lat";
+ public final static String MY_LOC_POINT_LON = "my_loc_point_lon";
+ public final static String MY_LOC_POINT_DESCRIPTION = "my_loc_point_description";
public final static String HOME_POINT_LAT = "home_point_lat";
public final static String HOME_POINT_LON = "home_point_lon";
@@ -1988,6 +1991,34 @@ public class OsmandSettings {
settingsAPI.getString(globalPreferences, POINT_NAVIGATE_DESCRIPTION, ""), getPointToNavigate());
}
+ public LatLon getPointToNavigateBackup() {
+ float lat = settingsAPI.getFloat(globalPreferences, POINT_NAVIGATE_LAT_BACKUP, 0);
+ float lon = settingsAPI.getFloat(globalPreferences, POINT_NAVIGATE_LON_BACKUP, 0);
+ if (lat == 0 && lon == 0) {
+ return null;
+ }
+ return new LatLon(lat, lon);
+ }
+
+ public LatLon getPointToStartBackup() {
+ float lat = settingsAPI.getFloat(globalPreferences, START_POINT_LAT_BACKUP, 0);
+ float lon = settingsAPI.getFloat(globalPreferences, START_POINT_LON_BACKUP, 0);
+ if (lat == 0 && lon == 0) {
+ return null;
+ }
+ return new LatLon(lat, lon);
+ }
+
+ public PointDescription getStartPointDescriptionBackup() {
+ return PointDescription.deserializeFromString(
+ settingsAPI.getString(globalPreferences, START_POINT_DESCRIPTION_BACKUP, ""), getPointToStart());
+ }
+
+ public PointDescription getPointNavigateDescriptionBackup() {
+ return PointDescription.deserializeFromString(
+ settingsAPI.getString(globalPreferences, POINT_NAVIGATE_DESCRIPTION_BACKUP, ""), getPointToNavigate());
+ }
+
public LatLon getHomePoint() {
float lat = settingsAPI.getFloat(globalPreferences, HOME_POINT_LAT, 0);
float lon = settingsAPI.getFloat(globalPreferences, HOME_POINT_LON, 0);
@@ -2026,6 +2057,30 @@ public class OsmandSettings {
settingsAPI.edit(globalPreferences).putString(WORK_POINT_DESCRIPTION, PointDescription.serializeToString(p)).commit();
}
+ public LatLon getMyLocationToStart() {
+ float lat = settingsAPI.getFloat(globalPreferences, MY_LOC_POINT_LAT, 0);
+ float lon = settingsAPI.getFloat(globalPreferences, MY_LOC_POINT_LON, 0);
+ if (lat == 0 && lon == 0) {
+ return null;
+ }
+ return new LatLon(lat, lon);
+ }
+
+ public PointDescription getMyLocationToStartDescription() {
+ return PointDescription.deserializeFromString(
+ settingsAPI.getString(globalPreferences, MY_LOC_POINT_DESCRIPTION, ""), getMyLocationToStart());
+ }
+
+ public void setMyLocationToStart(double latitude, double longitude, PointDescription p) {
+ settingsAPI.edit(globalPreferences).putFloat(MY_LOC_POINT_LAT, (float) latitude).putFloat(MY_LOC_POINT_LON, (float) longitude).commit();
+ settingsAPI.edit(globalPreferences).putString(MY_LOC_POINT_DESCRIPTION, PointDescription.serializeToString(p)).commit();
+ }
+
+ public void clearMyLocationToStart() {
+ settingsAPI.edit(globalPreferences).remove(MY_LOC_POINT_LAT).remove(MY_LOC_POINT_LON).
+ remove(MY_LOC_POINT_DESCRIPTION).commit();
+ }
+
public int isRouteToPointNavigateAndClear() {
int vl = settingsAPI.getInt(globalPreferences, POINT_NAVIGATE_ROUTE, 0);
if (vl != 0) {
diff --git a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java
index 797ef72def..e059cb9db6 100644
--- a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java
+++ b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java
@@ -23,6 +23,9 @@ public class TargetPointsHelper {
private List intermediatePoints = new ArrayList<>();
private TargetPoint pointToNavigate = null;
private TargetPoint pointToStart = null;
+ private TargetPoint pointToNavigateBackup = null;
+ private TargetPoint pointToStartBackup = null;
+ private TargetPoint myLocationToStart = null;
private OsmandSettings settings;
private RoutingHelper routingHelper;
private List> listeners = new ArrayList<>();
@@ -35,6 +38,7 @@ public class TargetPointsHelper {
private AddressLookupRequest targetPointRequest;
private AddressLookupRequest homePointRequest;
private AddressLookupRequest workPointRequest;
+ private AddressLookupRequest myLocationPointRequest;
public interface TargetPointChangedListener {
void onTargetPointChanged(TargetPoint targetPoint);
@@ -156,11 +160,15 @@ public class TargetPointsHelper {
}
lookupAddressForHomePoint();
lookupAddressForWorkPoint();
+ lookupAddressForMyLocationPoint();
}
private void readFromSettings() {
pointToNavigate = TargetPoint.create(settings.getPointToNavigate(), settings.getPointNavigateDescription());
pointToStart = TargetPoint.createStartPoint(settings.getPointToStart(), settings.getStartPointDescription());
+ pointToNavigateBackup = TargetPoint.create(settings.getPointToNavigateBackup(), settings.getPointNavigateDescriptionBackup());
+ pointToStartBackup = TargetPoint.createStartPoint(settings.getPointToStartBackup(), settings.getStartPointDescriptionBackup());
+ myLocationToStart = TargetPoint.create(settings.getMyLocationToStart(), settings.getMyLocationToStartDescription());
intermediatePoints.clear();
List ips = settings.getIntermediatePoints();
List desc = settings.getIntermediatePointDescriptions(ips.size());
@@ -188,6 +196,13 @@ public class TargetPointsHelper {
}
}
+ private void readMyLocationPointFromSettings() {
+ myLocationToStart = TargetPoint.create(settings.getMyLocationToStart(), settings.getMyLocationToStartDescription());
+ if (!ctx.isApplicationInitializing()) {
+ lookupAddressForMyLocationPoint();
+ }
+ }
+
private void lookupAddressForIntermediatePoint(final TargetPoint targetPoint) {
if (targetPoint != null && targetPoint.pointDescription.isSearchingAddress(ctx)) {
cancelPointAddressRequests(targetPoint.point);
@@ -294,6 +309,27 @@ public class TargetPointsHelper {
}
}
+ private void lookupAddressForMyLocationPoint() {
+ if (myLocationToStart != null && myLocationToStart.isSearchingAddress(ctx)
+ && (myLocationPointRequest == null || !myLocationPointRequest.getLatLon().equals(workPoint.point))) {
+ cancelWorkPointAddressRequest();
+ myLocationPointRequest = new AddressLookupRequest(workPoint.point, new GeocodingLookupService.OnAddressLookupResult() {
+ @Override
+ public void geocodingDone(String address) {
+ myLocationPointRequest = null;
+ if (myLocationToStart != null) {
+ myLocationToStart.pointDescription.setName(address);
+ settings.setMyLocationToStart(myLocationToStart.point.getLatitude(), myLocationToStart.point.getLongitude(),
+ myLocationToStart.pointDescription);
+ updateRouteAndRefresh(false);
+ updateTargetPoint(myLocationToStart);
+ }
+ }
+ }, null);
+ ctx.getGeocodingLookupService().lookupAddress(myLocationPointRequest);
+ }
+ }
+
public TargetPoint getPointToNavigate() {
return pointToNavigate;
}
@@ -301,7 +337,19 @@ public class TargetPointsHelper {
public TargetPoint getPointToStart() {
return pointToStart;
}
-
+
+ public TargetPoint getPointToNavigateBackup() {
+ return pointToNavigateBackup;
+ }
+
+ public TargetPoint getPointToStartBackup() {
+ return pointToStartBackup;
+ }
+
+ public TargetPoint getMyLocationToStart() {
+ return myLocationToStart;
+ }
+
public PointDescription getStartPointDescription(){
return settings.getStartPointDescription();
}
@@ -421,6 +469,7 @@ public class TargetPointsHelper {
settings.clearPointToStart();
if (clearBackup) {
settings.backupTargetPoints();
+ updateMyLocationToStart();
}
pointToNavigate = null;
pointToStart = null;
@@ -481,6 +530,15 @@ public class TargetPointsHelper {
updateListeners();
}
+ public void updateMyLocationToStart() {
+ if (pointToStart == null) {
+ Location lastKnownLocation = ctx.getLocationProvider().getLastKnownLocation();
+ LatLon latLon = lastKnownLocation != null ?
+ new LatLon(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude()) : null;
+ setMyLocationPoint(latLon, false, null);
+ }
+ }
+
private void updateRoutingHelper() {
LatLon start = settings.getPointToStart();
LatLon finish = settings.getPointToNavigate();
@@ -494,7 +552,6 @@ public class TargetPointsHelper {
}
}
-
private Location wrap(LatLon l) {
if(l == null) {
return null;
@@ -669,6 +726,25 @@ public class TargetPointsHelper {
updateRouteAndRefresh(updateRoute);
}
+ public void setMyLocationPoint(final LatLon startPoint, boolean updateRoute, PointDescription name) {
+ if (startPoint != null) {
+ final PointDescription pointDescription;
+ if (name == null) {
+ pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, "");
+ } else {
+ pointDescription = name;
+ }
+ if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) {
+ pointDescription.setName(PointDescription.getSearchAddressStr(ctx));
+ }
+ settings.setMyLocationToStart(startPoint.getLatitude(), startPoint.getLongitude(), pointDescription);
+ } else {
+ settings.clearMyLocationToStart();
+ }
+ readMyLocationPointFromSettings();
+ updateRouteAndRefresh(updateRoute);
+ }
+
public boolean checkPointToNavigateShort(){
if (pointToNavigate == null){
ctx.showShortToastMessage(R.string.mark_final_location_first);
diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java
index 92c865c514..c3488587aa 100644
--- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java
+++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java
@@ -50,6 +50,7 @@ import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.HomeWorkCard;
+import net.osmand.plus.routepreparationmenu.cards.PreviousRouteCard;
import net.osmand.plus.routepreparationmenu.cards.PublicTransportCard;
import net.osmand.plus.routepreparationmenu.cards.SimpleRouteCard;
import net.osmand.plus.routing.IRouteInformationListener;
@@ -379,6 +380,17 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
} else {
HomeWorkCard homeWorkCard = new HomeWorkCard(mapActivity);
menuCards.add(homeWorkCard);
+
+ TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
+ TargetPoint startBackup = targetPointsHelper.getPointToStartBackup();
+ if (startBackup == null) {
+ startBackup = targetPointsHelper.getMyLocationToStart();
+ }
+ TargetPoint destinationBackup = targetPointsHelper.getPointToNavigateBackup();
+ if (startBackup != null && destinationBackup != null) {
+ PreviousRouteCard previousRouteCard = new PreviousRouteCard(mapActivity);
+ menuCards.add(previousRouteCard);
+ }
}
setupCards();
}
diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java
index 262e53fe4d..797b60a2b6 100644
--- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java
+++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/HomeWorkCard.java
@@ -33,9 +33,9 @@ public class HomeWorkCard extends BaseCard {
TextView homeDescr = (TextView) view.findViewById(R.id.home_button_descr);
final TextView workDescr = (TextView) view.findViewById(R.id.work_button_descr);
- homeDescr.setText(homePoint != null ? homePoint.getPointDescription(mapActivity).getName() :
+ homeDescr.setText(homePoint != null ? homePoint.getPointDescription(mapActivity).getSimpleName(mapActivity, false) :
mapActivity.getString(R.string.shared_string_add));
- workDescr.setText(workPoint != null ? workPoint.getPointDescription(mapActivity).getName() :
+ workDescr.setText(workPoint != null ? workPoint.getPointDescription(mapActivity).getSimpleName(mapActivity, false) :
mapActivity.getString(R.string.shared_string_add));
View homeButton = view.findViewById(R.id.home_button);
diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PreviousRouteCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PreviousRouteCard.java
index 8e1fde139a..58874a64fe 100644
--- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PreviousRouteCard.java
+++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PreviousRouteCard.java
@@ -1,6 +1,16 @@
package net.osmand.plus.routepreparationmenu.cards;
+import android.graphics.drawable.Drawable;
+import android.support.v7.widget.AppCompatImageView;
+import android.view.View;
+import android.widget.TextView;
+
+import net.osmand.AndroidUtils;
+import net.osmand.plus.R;
+import net.osmand.plus.TargetPointsHelper;
+import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
+import net.osmand.util.Algorithms;
public class PreviousRouteCard extends BaseCard {
@@ -10,16 +20,50 @@ public class PreviousRouteCard extends BaseCard {
@Override
public int getCardLayoutId() {
- return 0;
+ return R.layout.prev_route_card;
}
@Override
protected void updateContent() {
+ final TargetPointsHelper targetPointsHelper = mapActivity.getMyApplication().getTargetPointsHelper();
+ TextView startTitle = (TextView) view.findViewById(R.id.start_title);
+ TextView destinationTitle = (TextView) view.findViewById(R.id.destination_title);
+ TargetPoint startPoint = targetPointsHelper.getPointToStartBackup();
+ boolean myLocation = false;
+ if (startPoint == null) {
+ myLocation = true;
+ startPoint = targetPointsHelper.getMyLocationToStart();
+ }
+ StringBuilder startText = new StringBuilder(myLocation ? mapActivity.getText(R.string.my_location) : "");
+ if (startPoint != null) {
+ String descr = startPoint.getPointDescription(mapActivity).getSimpleName(mapActivity, false);
+ if (!Algorithms.isEmpty(descr)) {
+ if (startText.length() > 0) {
+ startText.append(" — ");
+ }
+ startText.append(descr);
+ }
+ }
+ startTitle.setText(startText.toString());
+ TargetPoint destinationPoint = targetPointsHelper.getPointToNavigateBackup();
+ destinationTitle.setText(destinationPoint != null ?
+ destinationPoint.getPointDescription(mapActivity).getSimpleName(mapActivity, false) : "");
+ View homeButton = view.findViewById(R.id.card_button);
+ homeButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ targetPointsHelper.restoreTargetPoints(true);
+ }
+ });
}
@Override
protected void applyDayNightMode() {
-
+ AndroidUtils.setTextSecondaryColor(app, (TextView) view.findViewById(R.id.start_title), nightMode);
+ AndroidUtils.setTextPrimaryColor(app, (TextView) view.findViewById(R.id.destination_title), nightMode);
+ Drawable img = app.getUIUtilities().getIcon(R.drawable.ic_action_previous_route, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light);
+ ((AppCompatImageView) view.findViewById(R.id.card_img)).setImageDrawable(img);
+ AndroidUtils.setBackground(app, view.findViewById(R.id.card_content), nightMode, R.color.route_info_bg_light, R.color.route_info_bg_dark);
}
}
diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java
index bfb069fe9b..23518063de 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java
@@ -279,6 +279,10 @@ public class RoutingHelper {
}
public void updateLocation(Location currentLocation) {
+ if (settings.getPointToStart() == null && settings.getMyLocationToStart() == null && currentLocation != null) {
+ app.getTargetPointsHelper().setMyLocationPoint(
+ new LatLon(currentLocation.getLatitude(), currentLocation.getLongitude()), false, null);
+ }
if(isFollowingMode() || (settings.getPointToStart() == null && isRoutePlanningMode) ||
app.getLocationProvider().getLocationSimulation().isRouteAnimating()) {
setCurrentLocation(currentLocation, false);