diff --git a/OsmAnd/res/layout/map_marker_item.xml b/OsmAnd/res/layout/map_marker_item.xml new file mode 100644 index 0000000000..58d93922f4 --- /dev/null +++ b/OsmAnd/res/layout/map_marker_item.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index fbff124c19..eaa0ea14bd 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -1,6 +1,12 @@ + #2196f3 + #73b825 + #ff9800 + #e53935 + #d7eb23 + #EE666666 #BBBBBB #FFFFFF diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 9ced0f2f35..f5e8be75ad 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -2,14 +2,9 @@ package net.osmand.plus; import android.content.Context; -import net.osmand.StateChangedListener; import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; import net.osmand.data.PointDescription; -import net.osmand.plus.GeocodingLookupService; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; -import net.osmand.plus.R; import net.osmand.util.Algorithms; import java.util.ArrayList; @@ -21,9 +16,14 @@ public class MapMarkersHelper { private List mapMarkers = new ArrayList<>(); private List mapMarkersHistory = new ArrayList<>(); private OsmandSettings settings; - private List> listeners = new ArrayList>(); + private List listeners = new ArrayList<>(); private OsmandApplication ctx; + public interface MapMarkerChangedListener { + void onMapMarkerChanged(MapMarker mapMarker); + void onMapMarkersChanged(); + } + public static class MapMarker implements LocationPoint { public LatLon point; private PointDescription pointDescription; @@ -112,7 +112,11 @@ public class MapMarkersHelper { GeocodingLookupService.AddressLookupRequest lookupRequest = new GeocodingLookupService.AddressLookupRequest(mapMarker.point, new GeocodingLookupService.OnAddressLookupResult() { @Override public void geocodingDone(String address) { - mapMarker.pointDescription.setName(address); + if (Algorithms.isEmpty(address)) { + mapMarker.pointDescription.setName(PointDescription.getAddressNotFoundStr(ctx)); + } else { + mapMarker.pointDescription.setName(address); + } if (history) { settings.updateMapMarkerHistory(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(), mapMarker.pointDescription, mapMarker.colorIndex); @@ -120,7 +124,7 @@ public class MapMarkersHelper { settings.updateMapMarker(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(), mapMarker.pointDescription, mapMarker.colorIndex); } - refresh(); + updateMarker(mapMarker); } }, null); ctx.getGeocodingLookupService().lookupAddress(lookupRequest); @@ -260,18 +264,30 @@ public class MapMarkersHelper { } } - public void addListener(StateChangedListener l) { - listeners.add(l); + public void addListener(MapMarkerChangedListener l) { + if (!listeners.contains(l)) { + listeners.add(l); + } } - private void updateListeners() { - for (StateChangedListener l : listeners) { - l.stateChanged(null); + public void removeListener(MapMarkerChangedListener l) { + listeners.remove(l); + } + + private void updateMarker(MapMarker marker) { + for (MapMarkerChangedListener l : listeners) { + l.onMapMarkerChanged(marker); + } + } + + private void updateMarkers() { + for (MapMarkerChangedListener l : listeners) { + l.onMapMarkersChanged(); } } public void refresh() { - updateListeners(); + updateMarkers(); } private void cancelAddressRequests() { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 1707636fb4..edf051dfa4 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -110,7 +110,6 @@ public class MapActivityActions implements DialogProvider { public void addMapMarker(double latitude, double longitude, PointDescription pd) { MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper(); markersHelper.addMapMarker(new LatLon(latitude, longitude), pd); - //openMapMarkersActivity(); } public void editWaypoints() { diff --git a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java index 07d7ad6e5f..df9a745159 100644 --- a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java +++ b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java @@ -8,6 +8,8 @@ import net.osmand.StateChangedListener; import net.osmand.ValueHolder; import net.osmand.data.RotatedTileBox; import net.osmand.map.IMapLocationListener; +import net.osmand.plus.MapMarkersHelper; +import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener; import net.osmand.plus.OsmAndConstants; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; @@ -17,10 +19,8 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.AutoZoomMap; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; -import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.mapcontextmenu.MapContextMenu; -import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener; import net.osmand.plus.views.AnimateDraggingMapThread; @@ -29,7 +29,8 @@ import net.osmand.util.MapUtils; import java.util.List; -public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLocationListener, OsmAndCompassListener, IRouteInformationListener { +public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLocationListener, + OsmAndCompassListener, IRouteInformationListener, MapMarkerChangedListener { private static final int AUTO_FOLLOW_MSG_ID = OsmAndConstants.UI_HANDLER_LOCATION_SERVICE + 4; private long lastTimeAutoZooming = 0; @@ -70,15 +71,18 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc } private void addMapMarkersListener(OsmandApplication app) { - app.getMapMarkersHelper().addListener(new StateChangedListener() { + app.getMapMarkersHelper().addListener(this); + } - @Override - public void stateChanged(Void change) { - if(mapView != null) { - mapView.refreshMap(); - } - } - }); + @Override + public void onMapMarkerChanged(MapMarkersHelper.MapMarker mapMarker) { + } + + @Override + public void onMapMarkersChanged() { + if (mapView != null) { + mapView.refreshMap(); + } } public void setMapView(OsmandMapTileView mapView) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 7d8dac5127..c676e25b3e 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -43,6 +43,7 @@ import net.osmand.plus.ContextMenuAdapter.OnRowItemClick; import net.osmand.plus.IconsCache; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -87,7 +88,7 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP; /** */ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicListViewCallbacks, - IRouteInformationListener, WaypointDialogHelperCallbacks { + IRouteInformationListener, WaypointDialogHelperCallbacks, MapMarkerChangedListener { private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(DashboardOnMap.class); private static final String TAG = "DashboardOnMap"; @@ -210,128 +211,128 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis // by default they handle touches for their list items... i.e. they're in charge of drawing // the pressed state (the list selector), handling list item clicks, etc. swipeDismissListener = new SwipeDismissListViewTouchListener( - listView, - new DismissCallbacks() { + listView, + new DismissCallbacks() { - private List deletedMarkers = new ArrayList<>(); + private List deletedMarkers = new ArrayList<>(); - @Override - public boolean canDismiss(int position) { - boolean res = false; - if (listAdapter instanceof StableArrayAdapter) { - List activeObjects = ((StableArrayAdapter) listAdapter).getActiveObjects(); - Object obj = listAdapter.getItem(position); - res = activeObjects.contains(obj); + @Override + public boolean canDismiss(int position) { + boolean res = false; + if (listAdapter instanceof StableArrayAdapter) { + List activeObjects = ((StableArrayAdapter) listAdapter).getActiveObjects(); + Object obj = listAdapter.getItem(position); + res = activeObjects.contains(obj); + } + return res; + } + + @Override + public Undoable onDismiss(final int position) { + final Object item; + final StableArrayAdapter stableAdapter; + final int activeObjPos; + if (listAdapter instanceof StableArrayAdapter) { + stableAdapter = (StableArrayAdapter) listAdapter; + item = stableAdapter.getItem(position); + + if (visibleType == DashboardType.MAP_MARKERS) { + if (!((MapMarker) item).history) { + deletedMarkers.add(item); } - return res; } + stableAdapter.setNotifyOnChange(false); + stableAdapter.remove(item); + stableAdapter.getObjects().remove(item); + activeObjPos = stableAdapter.getActiveObjects().indexOf(item); + stableAdapter.getActiveObjects().remove(item); + stableAdapter.refreshData(); + stableAdapter.notifyDataSetChanged(); + + } else { + item = null; + stableAdapter = null; + activeObjPos = 0; + } + return new Undoable() { @Override - public Undoable onDismiss(final int position) { - final Object item; - final StableArrayAdapter stableAdapter; - final int activeObjPos; - if (listAdapter instanceof StableArrayAdapter) { - stableAdapter = (StableArrayAdapter) listAdapter; - item = stableAdapter.getItem(position); - - if (visibleType == DashboardType.MAP_MARKERS) { - if (!((MapMarker) item).history) { - deletedMarkers.add(item); - } - } - + public void undo() { + if (item != null) { stableAdapter.setNotifyOnChange(false); - stableAdapter.remove(item); - stableAdapter.getObjects().remove(item); - activeObjPos = stableAdapter.getActiveObjects().indexOf(item); - stableAdapter.getActiveObjects().remove(item); - stableAdapter.refreshData(); - stableAdapter.notifyDataSetChanged(); - - } else { - item = null; - stableAdapter = null; - activeObjPos = 0; - } - return new Undoable() { - @Override - public void undo() { - if (item != null) { - stableAdapter.setNotifyOnChange(false); - stableAdapter.insert(item, position); - stableAdapter.getObjects().add(position, item); - stableAdapter.getActiveObjects().add(activeObjPos, item); - stableAdapter.refreshData(); - if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) { - onItemsSwapped(stableAdapter.getActiveObjects()); - } else if (visibleType == DashboardType.MAP_MARKERS) { - deletedMarkers.remove(item); - updateMapMarkers(stableAdapter.getActiveObjects()); - reloadAdapter(); - } - } - } - - @Override - public String getTitle() { - if ((visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) - && (getMyApplication().getRoutingHelper().isRoutePlanningMode() || getMyApplication().getRoutingHelper().isFollowingMode()) - && item != null - && stableAdapter.getActiveObjects().size() == 0) { - return mapActivity.getResources().getString(R.string.cancel_navigation); - } else { - return null; - } - } - }; - } - - @Override - public void onHidePopup() { - if (listAdapter instanceof StableArrayAdapter) { - StableArrayAdapter stableAdapter = (StableArrayAdapter) listAdapter; + stableAdapter.insert(item, position); + stableAdapter.getObjects().add(position, item); + stableAdapter.getActiveObjects().add(activeObjPos, item); stableAdapter.refreshData(); if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) { onItemsSwapped(stableAdapter.getActiveObjects()); } else if (visibleType == DashboardType.MAP_MARKERS) { + deletedMarkers.remove(item); updateMapMarkers(stableAdapter.getActiveObjects()); - } - if (stableAdapter.getActiveObjects().size() == 0) { - hideDashboard(); - if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) { - mapActivity.getMapActions().stopNavigationWithoutConfirm(); - mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().hide(); - } - } else { - if (visibleType == DashboardType.MAP_MARKERS) { - reloadAdapter(); - } + reloadAdapter(); } } } - private void updateMapMarkers(List objects) { - List markers = new ArrayList<>(); - List markersHistory = new ArrayList<>(); - - for (Object obj : objects) { - MapMarker marker = (MapMarker) obj; - if (!marker.history) { - markers.add(marker); - } else { - markersHistory.add(marker); - } + @Override + public String getTitle() { + if ((visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) + && (getMyApplication().getRoutingHelper().isRoutePlanningMode() || getMyApplication().getRoutingHelper().isFollowingMode()) + && item != null + && stableAdapter.getActiveObjects().size() == 0) { + return mapActivity.getResources().getString(R.string.cancel_navigation); + } else { + return null; } - - for (int i = deletedMarkers.size() - 1; i >= 0; i--) { - markersHistory.add(0, (MapMarker) deletedMarkers.get(i)); - } - deletedMarkers.clear(); - - getMyApplication().getMapMarkersHelper().saveMapMarkers(markers, markersHistory); } - }); + }; + } + + @Override + public void onHidePopup() { + if (listAdapter instanceof StableArrayAdapter) { + StableArrayAdapter stableAdapter = (StableArrayAdapter) listAdapter; + stableAdapter.refreshData(); + if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) { + onItemsSwapped(stableAdapter.getActiveObjects()); + } else if (visibleType == DashboardType.MAP_MARKERS) { + updateMapMarkers(stableAdapter.getActiveObjects()); + } + if (stableAdapter.getActiveObjects().size() == 0) { + hideDashboard(); + if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) { + mapActivity.getMapActions().stopNavigationWithoutConfirm(); + mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().hide(); + } + } else { + if (visibleType == DashboardType.MAP_MARKERS) { + reloadAdapter(); + } + } + } + } + + private void updateMapMarkers(List objects) { + List markers = new ArrayList<>(); + List markersHistory = new ArrayList<>(); + + for (Object obj : objects) { + MapMarker marker = (MapMarker) obj; + if (!marker.history) { + markers.add(marker); + } else { + markersHistory.add(marker); + } + } + + for (int i = deletedMarkers.size() - 1; i >= 0; i--) { + markersHistory.add(0, (MapMarker) deletedMarkers.get(i)); + } + deletedMarkers.clear(); + + getMyApplication().getMapMarkersHelper().saveMapMarkers(markers, markersHistory); + } + }); gradientToolbar = mapActivity.getResources().getDrawable(R.drawable.gradient_toolbar).mutate(); if (AndroidUiHelper.isOrientationPortrait(mapActivity)) { @@ -373,6 +374,16 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis dashboardView.addView(actionButton); } + @Override + public void onMapMarkerChanged(MapMarker mapMarker) { + if (visible && visibleType == DashboardType.MAP_MARKERS) { + mapMarkerDialogHelper.updateMarkerView(listView, mapMarker); + } + } + + @Override + public void onMapMarkersChanged() { + } private void updateListBackgroundHeight() { @@ -682,6 +693,10 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis updateListBackgroundHeight(); } applyDayNightMode(); + + if (visibleType == DashboardType.MAP_MARKERS) { + getMyApplication().getMapMarkersHelper().addListener(this); + } } mapActivity.findViewById(R.id.toolbar_back).setVisibility(isBackButtonVisible() ? View.VISIBLE : View.GONE); mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.INVISIBLE); @@ -699,6 +714,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis // addOrUpdateDashboardFragments(); mapActivity.getRoutingHelper().addListener(this); } else { + if (visibleType == DashboardType.MAP_MARKERS) { + getMyApplication().getMapMarkersHelper().removeListener(this); + } if (swipeDismissListener != null) { swipeDismissListener.discardUndo(); } @@ -1012,6 +1030,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis ((DashLocationFragment) df.get()).updateLocation(centerChanged, locationChanged, compassChanged); } } + if (visibleType == DashboardType.MAP_MARKERS) { + mapMarkerDialogHelper.updateLocation(listView, compassChanged); + } } }); diff --git a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java index fd93adc3f5..6b49245d4a 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java @@ -11,19 +11,22 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ImageView; +import android.widget.ListView; import android.widget.TextView; import net.osmand.AndroidUtils; +import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; -import net.osmand.plus.GeocodingLookupService; -import net.osmand.plus.IconsCache; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.dashboard.DashLocationFragment; +import net.osmand.plus.dashboard.DashboardOnMap; +import net.osmand.plus.views.DirectionDrawable; import net.osmand.plus.views.controls.ListDividerShape; import net.osmand.plus.views.controls.StableArrayAdapter; import net.osmand.util.Algorithms; @@ -40,12 +43,21 @@ public class MapMarkerDialogHelper { private MapActivity mapActivity; private OsmandApplication app; + private MapMarkersHelper markersHelper; private boolean sorted; private boolean nightMode; + private boolean useCenter; + private LatLon loc; + private Float heading; + private int screenOrientation; + private boolean reloading; + private long lastUpdateTime; + public MapMarkerDialogHelper(MapActivity mapActivity) { this.mapActivity = mapActivity; app = mapActivity.getMyApplication(); + markersHelper = app.getMapMarkersHelper(); } public boolean isNightMode() { @@ -83,11 +95,14 @@ public class MapMarkerDialogHelper { public StableArrayAdapter getMapMarkersListAdapter() { + screenOrientation = DashLocationFragment.getScreenOrientation(mapActivity); + calculateLocationParams(); + final List objects = getListObjects(); List activeObjects = getActiveObjects(objects); final StableArrayAdapter listAdapter = new StableArrayAdapter(mapActivity, - R.layout.waypoint_reached, R.id.title, objects, activeObjects) { + R.layout.map_marker_item, R.id.title, objects, activeObjects) { @Override public void buildDividers() { @@ -124,23 +139,6 @@ public class MapMarkerDialogHelper { } }; - for (Object p : objects) { - if (p instanceof MapMarker) { - final MapMarker marker = (MapMarker) p; - if (marker.getOriginalPointDescription() != null - && marker.getOriginalPointDescription().isSearchingAddress(mapActivity)) { - GeocodingLookupService.AddressLookupRequest lookupRequest - = new GeocodingLookupService.AddressLookupRequest(marker.point, new GeocodingLookupService.OnAddressLookupResult() { - @Override - public void geocodingDone(String address) { - reloadListAdapter(listAdapter); - } - }, null); - app.getGeocodingLookupService().lookupAddress(lookupRequest); - } - } - } - return listAdapter; } @@ -213,8 +211,12 @@ public class MapMarkerDialogHelper { @Override public void onClick(DialogInterface dialog, int which) { listAdapter.notifyDataSetInvalidated(); - app.getMapMarkersHelper().removeMarkersHistory(); - reloadListAdapter(listAdapter); + markersHelper.removeMarkersHistory(); + if (markersHelper.getActiveMapMarkers().size() == 0) { + mapActivity.getDashboard().hideDashboard(); + } else { + reloadListAdapter(listAdapter); + } } }) .setNegativeButton(R.string.shared_string_no, null) @@ -226,8 +228,12 @@ public class MapMarkerDialogHelper { @Override public void onClick(DialogInterface dialog, int which) { listAdapter.notifyDataSetInvalidated(); - app.getMapMarkersHelper().removeActiveMarkers(); - reloadListAdapter(listAdapter); + markersHelper.removeActiveMarkers(); + if (markersHelper.getMapMarkersHistory().size() == 0) { + mapActivity.getDashboard().hideDashboard(); + } else { + reloadListAdapter(listAdapter); + } } }) .setNegativeButton(R.string.shared_string_no, null) @@ -244,7 +250,7 @@ public class MapMarkerDialogHelper { protected View updateMapMarkerItemView(View v, final MapMarker marker) { if (v == null || v.findViewById(R.id.info_close) == null) { - v = mapActivity.getLayoutInflater().inflate(R.layout.waypoint_reached, null); + v = mapActivity.getLayoutInflater().inflate(R.layout.map_marker_item, null); } updateMapMarkerInfoView(v, marker); final View more = v.findViewById(R.id.all_points); @@ -260,20 +266,56 @@ public class MapMarkerDialogHelper { TextView text = (TextView) localView.findViewById(R.id.waypoint_text); TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow); TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist); - if (!marker.history) { - ((ImageView) localView.findViewById(R.id.waypoint_icon)) - .setImageDrawable(getMapMarkerIcon(app, marker.colorIndex)); - AndroidUtils.setTextPrimaryColor(mapActivity, text, nightMode); - textDist.setTextColor(mapActivity.getResources().getColor(R.color.color_myloc_distance)); + ImageView arrow = (ImageView) localView.findViewById(R.id.direction); + ImageView waypointIcon = (ImageView) localView.findViewById(R.id.waypoint_icon); + TextView waypointDeviation = (TextView) localView.findViewById(R.id.waypoint_deviation); + TextView descText = (TextView) localView.findViewById(R.id.waypoint_desc_text); + if (text == null || textDist == null || arrow == null || waypointIcon == null + || waypointDeviation == null || descText == null) { + return; + } + float[] mes = new float[2]; + if (loc != null && marker.point != null) { + Location.distanceBetween(marker.getLatitude(), marker.getLongitude(), loc.getLatitude(), loc.getLongitude(), mes); + } + boolean newImage = false; + int arrowResId = R.drawable.ic_destination_arrow_white; + DirectionDrawable dd; + if (!(arrow.getDrawable() instanceof DirectionDrawable)) { + newImage = true; + dd = new DirectionDrawable(mapActivity, arrow.getWidth(), arrow.getHeight()); } else { - ((ImageView) localView.findViewById(R.id.waypoint_icon)) - .setImageDrawable(app.getIconsCache() - .getContentIcon(R.drawable.ic_action_flag_dark, !nightMode)); + dd = (DirectionDrawable) arrow.getDrawable(); + } + if (!marker.history) { + dd.setImage(arrowResId, useCenter ? R.color.color_distance : R.color.color_myloc_distance); + } else { + dd.setImage(arrowResId, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light); + } + if (loc == null || heading == null || marker.point == null) { + dd.setAngle(0); + } else { + dd.setAngle(mes[1] - heading + 180 + screenOrientation); + } + if (newImage) { + arrow.setImageDrawable(dd); + } + arrow.setVisibility(View.VISIBLE); + arrow.invalidate(); + + if (!marker.history) { + waypointIcon.setImageDrawable(getMapMarkerIcon(app, marker.colorIndex)); + AndroidUtils.setTextPrimaryColor(mapActivity, text, nightMode); + textDist.setTextColor(mapActivity.getResources() + .getColor(useCenter ? R.color.color_distance : R.color.color_myloc_distance)); + } else { + waypointIcon.setImageDrawable(app.getIconsCache() + .getContentIcon(R.drawable.ic_action_flag_dark, !nightMode)); AndroidUtils.setTextSecondaryColor(mapActivity, text, nightMode); AndroidUtils.setTextSecondaryColor(mapActivity, textDist, nightMode); } - int dist = marker.dist; + int dist = (int) mes[0]; //if (dist > 0) { textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app)); @@ -281,7 +323,7 @@ public class MapMarkerDialogHelper { // textDist.setText(""); //} - localView.findViewById(R.id.waypoint_deviation).setVisibility(View.GONE); + waypointDeviation.setVisibility(View.GONE); String descr; PointDescription pd = marker.getPointDescription(app); @@ -296,10 +338,9 @@ public class MapMarkerDialogHelper { } text.setText(descr); - localView.findViewById(R.id.waypoint_desc_text).setVisibility(View.GONE); + descText.setVisibility(View.GONE); /* String pointDescription = ""; - TextView descText = (TextView) localView.findViewById(R.id.waypoint_desc_text); if (descText != null) { AndroidUtils.setTextSecondaryColor(this, descText, nightMode); pointDescription = marker.getPointDescription(this).getTypeName(); @@ -317,6 +358,44 @@ public class MapMarkerDialogHelper { */ } + protected void updateMapMarkerArrowDistanceView(View localView, final MapMarker marker) { + TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist); + ImageView arrow = (ImageView) localView.findViewById(R.id.direction); + if (textDist == null || arrow == null) { + return; + } + float[] mes = new float[2]; + if (loc != null && marker.point != null) { + Location.distanceBetween(marker.getLatitude(), marker.getLongitude(), loc.getLatitude(), loc.getLongitude(), mes); + } + boolean newImage = false; + int arrowResId = R.drawable.ic_destination_arrow_white; + DirectionDrawable dd; + if (!(arrow.getDrawable() instanceof DirectionDrawable)) { + newImage = true; + dd = new DirectionDrawable(mapActivity, arrow.getWidth(), arrow.getHeight()); + } else { + dd = (DirectionDrawable) arrow.getDrawable(); + } + if (!marker.history) { + dd.setImage(arrowResId, useCenter ? R.color.color_distance : R.color.color_myloc_distance); + } else { + dd.setImage(arrowResId, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light); + } + if (loc == null || heading == null || marker.point == null) { + dd.setAngle(0); + } else { + dd.setAngle(mes[1] - heading + 180 + screenOrientation); + } + if (newImage) { + arrow.setImageDrawable(dd); + } + arrow.invalidate(); + + int dist = (int) mes[0]; + textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app)); + } + public void showOnMap(MapMarker marker) { app.getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(), 15, marker.getPointDescription(mapActivity), true, marker); @@ -343,8 +422,9 @@ public class MapMarkerDialogHelper { } return str; } - + public void reloadListAdapter(ArrayAdapter listAdapter) { + reloading = true; listAdapter.setNotifyOnChange(false); listAdapter.clear(); List objects = getListObjects(); @@ -355,6 +435,7 @@ public class MapMarkerDialogHelper { ((StableArrayAdapter) listAdapter).updateObjects(objects, getActiveObjects(objects)); } listAdapter.notifyDataSetChanged(); + reloading = false; } public void calcDistance(LatLon anchor, List markers) { @@ -366,7 +447,6 @@ public class MapMarkerDialogHelper { protected List getListObjects() { final List objects = new ArrayList<>(); - final MapMarkersHelper markersHelper = app.getMapMarkersHelper(); LatLon mapLocation = new LatLon(mapActivity.getMapView().getLatitude(), mapActivity.getMapView().getLongitude()); @@ -412,20 +492,78 @@ public class MapMarkerDialogHelper { } public static Drawable getMapMarkerIcon(OsmandApplication app, int colorIndex) { - IconsCache iconsCache = app.getIconsCache(); + int colorId; switch (colorIndex) { case 0: - return iconsCache.getIcon(R.drawable.map_marker_blue); + colorId = R.color.marker_blue; + break; case 1: - return iconsCache.getIcon(R.drawable.map_marker_green); + colorId = R.color.marker_green; + break; case 2: - return iconsCache.getIcon(R.drawable.map_marker_orange); + colorId = R.color.marker_orange; + break; case 3: - return iconsCache.getIcon(R.drawable.map_marker_red); + colorId = R.color.marker_red; + break; case 4: - return iconsCache.getIcon(R.drawable.map_marker_yellow); + colorId = R.color.marker_lt_green; + break; default: - return iconsCache.getIcon(R.drawable.map_marker_blue); + colorId = R.color.marker_blue; + } + return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, colorId); + } + + public void updateLocation(ListView listView, boolean compassChanged) { + if ((compassChanged && !mapActivity.getDashboard().isMapLinkedToLocation()) + || reloading || System.currentTimeMillis() - lastUpdateTime < 100) { + return; + } + + lastUpdateTime = System.currentTimeMillis(); + + try { + calculateLocationParams(); + + for (int i = listView.getFirstVisiblePosition(); i <= listView.getLastVisiblePosition(); i++) { + Object obj = listView.getItemAtPosition(i); + View v = listView.getChildAt(i - listView.getFirstVisiblePosition()); + if (obj instanceof MapMarker && v != null) { + updateMapMarkerArrowDistanceView(v, (MapMarker) obj); + } + } + } catch (Exception e) { } } + + public void updateMarkerView(ListView listView, MapMarker marker) { + try { + for (int i = listView.getFirstVisiblePosition(); i <= listView.getLastVisiblePosition(); i++) { + Object obj = listView.getItemAtPosition(i); + View v = listView.getChildAt(i - listView.getFirstVisiblePosition()); + if (obj == marker) { + updateMapMarkerInfoView(v, (MapMarker) obj); + } + } + } catch (Exception e) { + } + } + + private void calculateLocationParams() { + DashboardOnMap d = mapActivity.getDashboard(); + if (d == null) { + return; + } + + float head = d.getHeading(); + float mapRotation = d.getMapRotation(); + LatLon mw = d.getMapViewLocation(); + Location l = d.getMyLocation(); + boolean mapLinked = d.isMapLinkedToLocation() && l != null; + LatLon myLoc = l == null ? null : new LatLon(l.getLatitude(), l.getLongitude()); + useCenter = !mapLinked; + loc = (useCenter ? mw : myLoc); + heading = useCenter ? -mapRotation : head; + } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index c566155fa6..01a5690a01 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -19,6 +19,8 @@ import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.activities.MapActivity; @@ -42,7 +44,8 @@ import net.osmand.util.MapUtils; import java.lang.ref.WeakReference; import java.util.List; -public class MapContextMenu extends MenuTitleController implements StateChangedListener { +public class MapContextMenu extends MenuTitleController implements StateChangedListener, + MapMarkerChangedListener { private MapActivity mapActivity; private MapMultiSelectionMenu mapMultiSelectionMenu; @@ -256,6 +259,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL mapActivity.refreshMap(); + if (object instanceof MapMarker) { + mapActivity.getMyApplication().getMapMarkersHelper().addListener(this); + } + return true; } @@ -308,6 +315,9 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL public void close() { if (active) { active = false; + if (object instanceof MapMarker) { + mapActivity.getMyApplication().getMapMarkersHelper().removeListener(this); + } if (this.object != null) { clearSelectedObject(this.object); } @@ -334,6 +344,22 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } } + @Override + public void onMapMarkerChanged(MapMarker mapMarker) { + if (object == mapMarker) { + String address = ((MapMarker) object).getOnlyName(); + nameStr = address; + pointDescription.setName(address); + WeakReference fragmentRef = findMenuFragment(); + if (fragmentRef != null) + fragmentRef.get().refreshTitle(); + } + } + + @Override + public void onMapMarkersChanged() { + } + @Override public void stateChanged(ApplicationMode change) { appModeChanged = active; @@ -477,7 +503,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAP_MARKERS); } else { mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(), - pointDescription); + getPointDescriptionForTarget()); } close(); } diff --git a/OsmAnd/src/net/osmand/plus/views/controls/SwipeDismissListViewTouchListener.java b/OsmAnd/src/net/osmand/plus/views/controls/SwipeDismissListViewTouchListener.java index 30d78e1c60..1586baa1fe 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/SwipeDismissListViewTouchListener.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/SwipeDismissListViewTouchListener.java @@ -102,6 +102,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener { //private List mPendingDismisses = new ArrayList(); private int mDismissAnimationRefCount = 0; private float mDownX; + private float mDownY; private boolean mSwiping; private VelocityTracker mVelocityTracker; private int mDownPosition; @@ -601,6 +602,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener { int position = mListView.getPositionForView(mSwipeDownView) - mListView.getHeaderViewsCount(); if (mCallbacks == null || mCallbacks.canDismiss(position)) { mDownX = ev.getRawX(); + mDownY = ev.getRawY(); mDownPosition = position; mVelocityTracker = VelocityTracker.obtain(); @@ -629,6 +631,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener { mVelocityTracker.recycle(); mVelocityTracker = null; mDownX = 0; + mDownY = 0; mSwipeDownView = mSwipeDownChild = null; mDownPosition = ListView.INVALID_POSITION; mSwiping = false; @@ -669,6 +672,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener { } mVelocityTracker = null; mDownX = 0; + mDownY = 0; mSwipeDownView = null; mSwipeDownChild = null; mDownPosition = AbsListView.INVALID_POSITION; @@ -683,6 +687,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener { mVelocityTracker.addMovement(ev); float deltaX = ev.getRawX() - mDownX; + float deltaY = ev.getRawY() - mDownY; // Only start swipe in correct direction if (isSwipeDirectionValid(deltaX)) { ViewParent parent = mListView.getParent(); @@ -691,7 +696,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener { // otherwise swipe would not be working. parent.requestDisallowInterceptTouchEvent(true); } - if (Math.abs(deltaX) > mSlop) { + if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) { mSwiping = true; mListView.requestDisallowInterceptTouchEvent(true);