diff --git a/OsmAnd/res/layout/map_context_menu_fragment.xml b/OsmAnd/res/layout/map_context_menu_fragment.xml
index 02e743d21d..6ada5a299d 100644
--- a/OsmAnd/res/layout/map_context_menu_fragment.xml
+++ b/OsmAnd/res/layout/map_context_menu_fragment.xml
@@ -33,13 +33,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
+ android:layout_marginBottom="16dp"
android:orientation="horizontal">
+ android:layout_height="match_parent">
-
+ android:orientation="horizontal">
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ android:layout_marginTop="4dp">
-
+
-
+
-
+
+
+
@@ -116,7 +150,9 @@
android:layout_marginTop="-16dp"
android:paddingBottom="4dp"
android:clickable="true"
- android:orientation="horizontal">
+ android:orientation="horizontal"
+ tools:visibility="visible"
+ android:visibility="gone">
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java
index 88569a4852..4a5b1ae24d 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java
@@ -399,6 +399,10 @@ public class MapContextMenu extends MenuTitleController {
return menuController == null || menuController.buttonsVisible();
}
+ public boolean displayDistanceDirection() {
+ return menuController != null && menuController.displayDistanceDirection();
+ }
+
public void updateData() {
if (menuController != null) {
menuController.updateData();
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java
index d06fa1e907..53af782668 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java
@@ -29,26 +29,31 @@ import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
+import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.IconsCache;
+import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
+import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController;
import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController;
import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.OsmandMapTileView;
+import net.osmand.util.MapUtils;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_BOTTOM_DP;
import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP;
-public class MapContextMenuFragment extends Fragment implements DownloadEvents {
+public class MapContextMenuFragment extends Fragment implements DownloadEvents, OsmAndLocationListener, OsmAndCompassListener {
public static final String TAG = "MapContextMenuFragment";
@@ -84,6 +89,10 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
private int origMarkerY;
private boolean customMapCenter;
+ private LatLon location;
+ private Float heading;
+ private int screenOrientation;
+
private class SingleTapConfirm implements OnGestureListener {
@Override
@@ -550,6 +559,26 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
}
}
+ @Override
+ public void onResume() {
+ super.onResume();
+ screenOrientation = DashLocationFragment.getScreenOrientation(getActivity());
+ if (menu.displayDistanceDirection()) {
+ if (location == null) {
+ location = getMyApplication().getSettings().getLastKnownMapLocation();
+ }
+ getMyApplication().getLocationProvider().addLocationListener(this);
+ getMyApplication().getLocationProvider().addCompassListener(this);
+ }
+ }
+
+ @Override
+ public void onPause() {
+ getMyApplication().getLocationProvider().removeLocationListener(this);
+ getMyApplication().getLocationProvider().removeCompassListener(this);
+ super.onPause();
+ }
+
@Override
public void onDestroyView() {
super.onDestroyView();
@@ -641,6 +670,15 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
line1.setText(menu.getTitleStr());
// Text line 2
+ TextView distanceText = (TextView) view.findViewById(R.id.distance);
+ ImageView direction = (ImageView) view.findViewById(R.id.direction);
+ if (menu.displayDistanceDirection()) {
+ updateDistanceDirection();
+ } else {
+ direction.setVisibility(View.GONE);
+ distanceText.setVisibility(View.GONE);
+ }
+
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
line2.setText(menu.getLocationStr());
Drawable icon = menu.getSecondLineIcon();
@@ -650,6 +688,14 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
}
}
+ private void updateDistanceDirection() {
+ TextView distanceText = (TextView) view.findViewById(R.id.distance);
+ ImageView direction = (ImageView) view.findViewById(R.id.direction);
+ boolean mapLinked = getMapActivity().getMapViewTrackingUtilities().isMapLinkedToLocation() && location != null;
+ DashLocationFragment.updateLocationView(!mapLinked, location, heading, direction, distanceText,
+ menu.getLatLon().getLatitude(), menu.getLatLon().getLongitude(), screenOrientation, getMyApplication(), getActivity());
+ }
+
private int getPosY() {
return getPosY(false);
}
@@ -870,5 +916,26 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
return dm.heightPixels;
}
+
+ @Override
+ public void updateLocation(Location location) {
+ if (location != null) {
+ this.location = new LatLon(location.getLatitude(), location.getLongitude());
+ updateDistanceDirection();
+ }
+; }
+
+ @Override
+ public void updateCompassValue(float value) {
+ // 99 in next line used to one-time initalize arrows (with reference vs. fixed-north direction) on non-compass
+ // devices
+ float lastHeading = heading != null ? heading : 99;
+ heading = value;
+ if (Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) {
+ updateDistanceDirection();
+ } else {
+ heading = lastHeading;
+ }
+ }
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java
index 3c2ccbdf04..824a626ddc 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java
@@ -220,7 +220,11 @@ public abstract class MenuController extends BaseMenuController {
return menuType != MenuType.STANDARD;
}
- public boolean displayStreetNameinTitle() {
+ public boolean displayStreetNameInTitle() {
+ return false;
+ }
+
+ public boolean displayDistanceDirection() {
return false;
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java
index 97fc3d1580..6c3d30eef4 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java
@@ -59,8 +59,8 @@ public abstract class MenuTitleController {
return typeStr;
} else {
if (Algorithms.isEmpty(streetStr)) {
- return PointDescription.getLocationName(getMapActivity(),
- getLatLon().getLatitude(), getLatLon().getLongitude(), true).replaceAll("\n", "");
+ return "";//PointDescription.getLocationName(getMapActivity(),
+ //getLatLon().getLatitude(), getLatLon().getLongitude(), true).replaceAll("\n", "");
} else {
return streetStr;
}
@@ -147,7 +147,7 @@ public abstract class MenuTitleController {
if (!Algorithms.isEmpty(streetStr)) {
MenuController menuController = getMenuController();
- if (menuController == null || menuController.displayStreetNameinTitle()) {
+ if (menuController == null || menuController.displayStreetNameInTitle()) {
nameStr = streetStr;
addressUnknown = false;
streetStr = "";
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java
index cf381faa1d..09aaf607be 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java
@@ -48,6 +48,11 @@ public class FavouritePointMenuController extends MenuController {
return true;
}
+ @Override
+ public boolean displayDistanceDirection() {
+ return true;
+ }
+
@Override
public Drawable getLeftIcon() {
return FavoriteImageDrawable.getOrCreate(getMapActivity().getMyApplication(), fav.getColor(), true);
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/HistoryMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/HistoryMenuController.java
index 0a8167d7c9..2d9adbc951 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/HistoryMenuController.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/HistoryMenuController.java
@@ -31,6 +31,11 @@ public class HistoryMenuController extends MenuController {
return (typeName != null && !typeName.isEmpty());
}
+ @Override
+ public boolean displayDistanceDirection() {
+ return true;
+ }
+
@Override
public Drawable getLeftIcon() {
return getIcon(SearchHistoryFragment.getItemIcon(entry.getName()));
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ParkingPositionMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ParkingPositionMenuController.java
index 9f9886a4ae..e973ad4b8b 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ParkingPositionMenuController.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ParkingPositionMenuController.java
@@ -51,6 +51,11 @@ public class ParkingPositionMenuController extends MenuController {
return !Algorithms.isEmpty(parkingDescription);
}
+ @Override
+ public boolean displayDistanceDirection() {
+ return true;
+ }
+
@Override
public Drawable getLeftIcon() {
return getIcon(R.drawable.ic_action_parking_dark, R.color.map_widget_blue, R.color.osmand_orange);
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java
index 773f52532b..b28b806bd9 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java
@@ -29,7 +29,12 @@ public class PointDescriptionMenuController extends MenuController {
}
@Override
- public boolean displayStreetNameinTitle() {
+ public boolean displayStreetNameInTitle() {
+ return true;
+ }
+
+ @Override
+ public boolean displayDistanceDirection() {
return true;
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java
index a2d44d4db5..563d2dc37d 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java
@@ -46,6 +46,11 @@ public class TargetPointMenuController extends MenuController {
return !Algorithms.isEmpty(getNameStr());
}
+ @Override
+ public boolean displayDistanceDirection() {
+ return true;
+ }
+
@Override
public Drawable getLeftIcon() {
if (!targetPoint.intermediate) {
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java
index 2d743e797c..73d0f49948 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java
@@ -47,6 +47,11 @@ public class WptPtMenuController extends MenuController {
return wpt.category != null;
}
+ @Override
+ public boolean displayDistanceDirection() {
+ return true;
+ }
+
@Override
public Drawable getLeftIcon() {
return FavoriteImageDrawable.getOrCreate(getMapActivity().getMyApplication(), wpt.getColor(), true);