Added compass arrows. Fix bugs

This commit is contained in:
Alexey Kulish 2016-02-11 15:28:37 +03:00
parent ac4d6b16a4
commit a8de5408b0
9 changed files with 519 additions and 180 deletions

View file

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/view_transparent_selection"
android:id="@+id/package_delivered_layout"
android:minHeight="50dp"
android:descendantFocusability="blocksDescendants">
<ImageView
android:id="@+id/waypoint_icon"
android:src="@drawable/ic_action_fav_dark"
android:layout_height="25dp"
android:layout_width="56dp"
android:layout_gravity="center_vertical" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/waypoint_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:ellipsize="end"
android:layout_gravity="center_vertical"
android:textSize="@dimen/default_list_text_size" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="4dp"
android:src="@drawable/ic_destination_arrow_white"
android:visibility="gone"/>
<TextView
android:id="@+id/waypoint_dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:textColor="@color/color_myloc_distance"
android:maxLines="1"
android:textSize="@dimen/default_sub_text_size"/>
<TextView
android:id="@+id/waypoint_deviation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:textColor="@color/secondary_text_dark"
android:layout_marginLeft="6dp"
android:drawablePadding="2dp"
android:maxLines="1"
android:textSize="@dimen/default_sub_text_size"/>
<TextView
android:id="@+id/waypoint_desc_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:layout_gravity="bottom"
android:layout_weight="1"
android:textColor="@color/secondary_text_dark"
android:textSize="@dimen/default_sub_text_size" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="@+id/all_points"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/shared_string_more"
android:layout_gravity="center_vertical"
android:layout_marginRight="2dp"
android:visibility="gone"
android:focusable="false"
android:scaleType="center"
style="@style/Widget.AppCompat.ActionButton"
android:src="@drawable/map_overflow_menu_white" />
<ImageButton
android:id="@+id/info_close"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/shared_string_close"
android:layout_gravity="center_vertical"
android:layout_marginRight="2dp"
style="@style/Widget.AppCompat.ActionButton"
android:focusable="false"
android:scaleType="center"
android:src="@drawable/ic_action_remove_dark" />
<ImageView
android:id="@+id/info_move"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="2dp"
android:focusable="false"
android:clickable="false"
android:scaleType="center"
android:src="@drawable/ic_flat_list_dark"
android:visibility="gone"/>
</LinearLayout>

View file

@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="marker_blue">#2196f3</color>
<color name="marker_green">#73b825</color>
<color name="marker_orange">#ff9800</color>
<color name="marker_red">#e53935</color>
<color name="marker_lt_green">#d7eb23</color>
<color name="popup_bg_color">#EE666666</color> <color name="popup_bg_color">#EE666666</color>
<color name="popup_separator_color">#BBBBBB</color> <color name="popup_separator_color">#BBBBBB</color>
<color name="popup_text_color">#FFFFFF</color> <color name="popup_text_color">#FFFFFF</color>

View file

@ -2,14 +2,9 @@ package net.osmand.plus;
import android.content.Context; import android.content.Context;
import net.osmand.StateChangedListener;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint; import net.osmand.data.LocationPoint;
import net.osmand.data.PointDescription; 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 net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,9 +16,14 @@ public class MapMarkersHelper {
private List<MapMarker> mapMarkers = new ArrayList<>(); private List<MapMarker> mapMarkers = new ArrayList<>();
private List<MapMarker> mapMarkersHistory = new ArrayList<>(); private List<MapMarker> mapMarkersHistory = new ArrayList<>();
private OsmandSettings settings; private OsmandSettings settings;
private List<StateChangedListener<Void>> listeners = new ArrayList<StateChangedListener<Void>>(); private List<MapMarkerChangedListener> listeners = new ArrayList<>();
private OsmandApplication ctx; private OsmandApplication ctx;
public interface MapMarkerChangedListener {
void onMapMarkerChanged(MapMarker mapMarker);
void onMapMarkersChanged();
}
public static class MapMarker implements LocationPoint { public static class MapMarker implements LocationPoint {
public LatLon point; public LatLon point;
private PointDescription pointDescription; private PointDescription pointDescription;
@ -112,7 +112,11 @@ public class MapMarkersHelper {
GeocodingLookupService.AddressLookupRequest lookupRequest = new GeocodingLookupService.AddressLookupRequest(mapMarker.point, new GeocodingLookupService.OnAddressLookupResult() { GeocodingLookupService.AddressLookupRequest lookupRequest = new GeocodingLookupService.AddressLookupRequest(mapMarker.point, new GeocodingLookupService.OnAddressLookupResult() {
@Override @Override
public void geocodingDone(String address) { public void geocodingDone(String address) {
if (Algorithms.isEmpty(address)) {
mapMarker.pointDescription.setName(PointDescription.getAddressNotFoundStr(ctx));
} else {
mapMarker.pointDescription.setName(address); mapMarker.pointDescription.setName(address);
}
if (history) { if (history) {
settings.updateMapMarkerHistory(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(), settings.updateMapMarkerHistory(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(),
mapMarker.pointDescription, mapMarker.colorIndex); mapMarker.pointDescription, mapMarker.colorIndex);
@ -120,7 +124,7 @@ public class MapMarkersHelper {
settings.updateMapMarker(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(), settings.updateMapMarker(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(),
mapMarker.pointDescription, mapMarker.colorIndex); mapMarker.pointDescription, mapMarker.colorIndex);
} }
refresh(); updateMarker(mapMarker);
} }
}, null); }, null);
ctx.getGeocodingLookupService().lookupAddress(lookupRequest); ctx.getGeocodingLookupService().lookupAddress(lookupRequest);
@ -260,18 +264,30 @@ public class MapMarkersHelper {
} }
} }
public void addListener(StateChangedListener<Void> l) { public void addListener(MapMarkerChangedListener l) {
if (!listeners.contains(l)) {
listeners.add(l); listeners.add(l);
} }
}
private void updateListeners() { public void removeListener(MapMarkerChangedListener l) {
for (StateChangedListener<Void> l : listeners) { listeners.remove(l);
l.stateChanged(null); }
private void updateMarker(MapMarker marker) {
for (MapMarkerChangedListener l : listeners) {
l.onMapMarkerChanged(marker);
}
}
private void updateMarkers() {
for (MapMarkerChangedListener l : listeners) {
l.onMapMarkersChanged();
} }
} }
public void refresh() { public void refresh() {
updateListeners(); updateMarkers();
} }
private void cancelAddressRequests() { private void cancelAddressRequests() {

View file

@ -110,7 +110,6 @@ public class MapActivityActions implements DialogProvider {
public void addMapMarker(double latitude, double longitude, PointDescription pd) { public void addMapMarker(double latitude, double longitude, PointDescription pd) {
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper(); MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
markersHelper.addMapMarker(new LatLon(latitude, longitude), pd); markersHelper.addMapMarker(new LatLon(latitude, longitude), pd);
//openMapMarkersActivity();
} }
public void editWaypoints() { public void editWaypoints() {

View file

@ -8,6 +8,8 @@ import net.osmand.StateChangedListener;
import net.osmand.ValueHolder; import net.osmand.ValueHolder;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.map.IMapLocationListener; 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.OsmAndConstants;
import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; 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.OsmandSettings.AutoZoomMap;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.mapcontextmenu.MapContextMenu; 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;
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener; import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.AnimateDraggingMapThread;
@ -29,7 +29,8 @@ import net.osmand.util.MapUtils;
import java.util.List; 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 static final int AUTO_FOLLOW_MSG_ID = OsmAndConstants.UI_HANDLER_LOCATION_SERVICE + 4;
private long lastTimeAutoZooming = 0; private long lastTimeAutoZooming = 0;
@ -70,16 +71,19 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
} }
private void addMapMarkersListener(OsmandApplication app) { private void addMapMarkersListener(OsmandApplication app) {
app.getMapMarkersHelper().addListener(new StateChangedListener<Void>() { app.getMapMarkersHelper().addListener(this);
}
@Override @Override
public void stateChanged(Void change) { public void onMapMarkerChanged(MapMarkersHelper.MapMarker mapMarker) {
}
@Override
public void onMapMarkersChanged() {
if (mapView != null) { if (mapView != null) {
mapView.refreshMap(); mapView.refreshMap();
} }
} }
});
}
public void setMapView(OsmandMapTileView mapView) { public void setMapView(OsmandMapTileView mapView) {
this.mapView = mapView; this.mapView = mapView;

View file

@ -43,6 +43,7 @@ import net.osmand.plus.ContextMenuAdapter.OnRowItemClick;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -87,7 +88,7 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
/** /**
*/ */
public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicListViewCallbacks, public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicListViewCallbacks,
IRouteInformationListener, WaypointDialogHelperCallbacks { IRouteInformationListener, WaypointDialogHelperCallbacks, MapMarkerChangedListener {
private static final org.apache.commons.logging.Log LOG = private static final org.apache.commons.logging.Log LOG =
PlatformUtil.getLog(DashboardOnMap.class); PlatformUtil.getLog(DashboardOnMap.class);
private static final String TAG = "DashboardOnMap"; private static final String TAG = "DashboardOnMap";
@ -373,6 +374,16 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
dashboardView.addView(actionButton); 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() { private void updateListBackgroundHeight() {
@ -682,6 +693,10 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
updateListBackgroundHeight(); updateListBackgroundHeight();
} }
applyDayNightMode(); 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.toolbar_back).setVisibility(isBackButtonVisible() ? View.VISIBLE : View.GONE);
mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.INVISIBLE); mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.INVISIBLE);
@ -699,6 +714,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
// addOrUpdateDashboardFragments(); // addOrUpdateDashboardFragments();
mapActivity.getRoutingHelper().addListener(this); mapActivity.getRoutingHelper().addListener(this);
} else { } else {
if (visibleType == DashboardType.MAP_MARKERS) {
getMyApplication().getMapMarkersHelper().removeListener(this);
}
if (swipeDismissListener != null) { if (swipeDismissListener != null) {
swipeDismissListener.discardUndo(); swipeDismissListener.discardUndo();
} }
@ -1012,6 +1030,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
((DashLocationFragment) df.get()).updateLocation(centerChanged, locationChanged, compassChanged); ((DashLocationFragment) df.get()).updateLocation(centerChanged, locationChanged, compassChanged);
} }
} }
if (visibleType == DashboardType.MAP_MARKERS) {
mapMarkerDialogHelper.updateLocation(listView, compassChanged);
}
} }
}); });

View file

@ -11,19 +11,22 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; 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;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; 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.ListDividerShape;
import net.osmand.plus.views.controls.StableArrayAdapter; import net.osmand.plus.views.controls.StableArrayAdapter;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -40,12 +43,21 @@ public class MapMarkerDialogHelper {
private MapActivity mapActivity; private MapActivity mapActivity;
private OsmandApplication app; private OsmandApplication app;
private MapMarkersHelper markersHelper;
private boolean sorted; private boolean sorted;
private boolean nightMode; 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) { public MapMarkerDialogHelper(MapActivity mapActivity) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
app = mapActivity.getMyApplication(); app = mapActivity.getMyApplication();
markersHelper = app.getMapMarkersHelper();
} }
public boolean isNightMode() { public boolean isNightMode() {
@ -83,11 +95,14 @@ public class MapMarkerDialogHelper {
public StableArrayAdapter getMapMarkersListAdapter() { public StableArrayAdapter getMapMarkersListAdapter() {
screenOrientation = DashLocationFragment.getScreenOrientation(mapActivity);
calculateLocationParams();
final List<Object> objects = getListObjects(); final List<Object> objects = getListObjects();
List<Object> activeObjects = getActiveObjects(objects); List<Object> activeObjects = getActiveObjects(objects);
final StableArrayAdapter listAdapter = new StableArrayAdapter(mapActivity, 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 @Override
public void buildDividers() { 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; return listAdapter;
} }
@ -213,9 +211,13 @@ public class MapMarkerDialogHelper {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
listAdapter.notifyDataSetInvalidated(); listAdapter.notifyDataSetInvalidated();
app.getMapMarkersHelper().removeMarkersHistory(); markersHelper.removeMarkersHistory();
if (markersHelper.getActiveMapMarkers().size() == 0) {
mapActivity.getDashboard().hideDashboard();
} else {
reloadListAdapter(listAdapter); reloadListAdapter(listAdapter);
} }
}
}) })
.setNegativeButton(R.string.shared_string_no, null) .setNegativeButton(R.string.shared_string_no, null)
.show(); .show();
@ -226,9 +228,13 @@ public class MapMarkerDialogHelper {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
listAdapter.notifyDataSetInvalidated(); listAdapter.notifyDataSetInvalidated();
app.getMapMarkersHelper().removeActiveMarkers(); markersHelper.removeActiveMarkers();
if (markersHelper.getMapMarkersHistory().size() == 0) {
mapActivity.getDashboard().hideDashboard();
} else {
reloadListAdapter(listAdapter); reloadListAdapter(listAdapter);
} }
}
}) })
.setNegativeButton(R.string.shared_string_no, null) .setNegativeButton(R.string.shared_string_no, null)
.show(); .show();
@ -244,7 +250,7 @@ public class MapMarkerDialogHelper {
protected View updateMapMarkerItemView(View v, final MapMarker marker) { protected View updateMapMarkerItemView(View v, final MapMarker marker) {
if (v == null || v.findViewById(R.id.info_close) == null) { 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); updateMapMarkerInfoView(v, marker);
final View more = v.findViewById(R.id.all_points); 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 text = (TextView) localView.findViewById(R.id.waypoint_text);
TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow); TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow);
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist); TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
if (!marker.history) { ImageView arrow = (ImageView) localView.findViewById(R.id.direction);
((ImageView) localView.findViewById(R.id.waypoint_icon)) ImageView waypointIcon = (ImageView) localView.findViewById(R.id.waypoint_icon);
.setImageDrawable(getMapMarkerIcon(app, marker.colorIndex)); TextView waypointDeviation = (TextView) localView.findViewById(R.id.waypoint_deviation);
AndroidUtils.setTextPrimaryColor(mapActivity, text, nightMode); TextView descText = (TextView) localView.findViewById(R.id.waypoint_desc_text);
textDist.setTextColor(mapActivity.getResources().getColor(R.color.color_myloc_distance)); 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 { } else {
((ImageView) localView.findViewById(R.id.waypoint_icon)) dd = (DirectionDrawable) arrow.getDrawable();
.setImageDrawable(app.getIconsCache() }
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)); .getContentIcon(R.drawable.ic_action_flag_dark, !nightMode));
AndroidUtils.setTextSecondaryColor(mapActivity, text, nightMode); AndroidUtils.setTextSecondaryColor(mapActivity, text, nightMode);
AndroidUtils.setTextSecondaryColor(mapActivity, textDist, nightMode); AndroidUtils.setTextSecondaryColor(mapActivity, textDist, nightMode);
} }
int dist = marker.dist; int dist = (int) mes[0];
//if (dist > 0) { //if (dist > 0) {
textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app)); textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app));
@ -281,7 +323,7 @@ public class MapMarkerDialogHelper {
// textDist.setText(""); // textDist.setText("");
//} //}
localView.findViewById(R.id.waypoint_deviation).setVisibility(View.GONE); waypointDeviation.setVisibility(View.GONE);
String descr; String descr;
PointDescription pd = marker.getPointDescription(app); PointDescription pd = marker.getPointDescription(app);
@ -296,10 +338,9 @@ public class MapMarkerDialogHelper {
} }
text.setText(descr); text.setText(descr);
localView.findViewById(R.id.waypoint_desc_text).setVisibility(View.GONE); descText.setVisibility(View.GONE);
/* /*
String pointDescription = ""; String pointDescription = "";
TextView descText = (TextView) localView.findViewById(R.id.waypoint_desc_text);
if (descText != null) { if (descText != null) {
AndroidUtils.setTextSecondaryColor(this, descText, nightMode); AndroidUtils.setTextSecondaryColor(this, descText, nightMode);
pointDescription = marker.getPointDescription(this).getTypeName(); 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) { public void showOnMap(MapMarker marker) {
app.getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(), app.getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
15, marker.getPointDescription(mapActivity), true, marker); 15, marker.getPointDescription(mapActivity), true, marker);
@ -345,6 +424,7 @@ public class MapMarkerDialogHelper {
} }
public void reloadListAdapter(ArrayAdapter<Object> listAdapter) { public void reloadListAdapter(ArrayAdapter<Object> listAdapter) {
reloading = true;
listAdapter.setNotifyOnChange(false); listAdapter.setNotifyOnChange(false);
listAdapter.clear(); listAdapter.clear();
List<Object> objects = getListObjects(); List<Object> objects = getListObjects();
@ -355,6 +435,7 @@ public class MapMarkerDialogHelper {
((StableArrayAdapter) listAdapter).updateObjects(objects, getActiveObjects(objects)); ((StableArrayAdapter) listAdapter).updateObjects(objects, getActiveObjects(objects));
} }
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
reloading = false;
} }
public void calcDistance(LatLon anchor, List<MapMarker> markers) { public void calcDistance(LatLon anchor, List<MapMarker> markers) {
@ -366,7 +447,6 @@ public class MapMarkerDialogHelper {
protected List<Object> getListObjects() { protected List<Object> getListObjects() {
final List<Object> objects = new ArrayList<>(); final List<Object> objects = new ArrayList<>();
final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
LatLon mapLocation = LatLon mapLocation =
new LatLon(mapActivity.getMapView().getLatitude(), mapActivity.getMapView().getLongitude()); new LatLon(mapActivity.getMapView().getLatitude(), mapActivity.getMapView().getLongitude());
@ -412,20 +492,78 @@ public class MapMarkerDialogHelper {
} }
public static Drawable getMapMarkerIcon(OsmandApplication app, int colorIndex) { public static Drawable getMapMarkerIcon(OsmandApplication app, int colorIndex) {
IconsCache iconsCache = app.getIconsCache(); int colorId;
switch (colorIndex) { switch (colorIndex) {
case 0: case 0:
return iconsCache.getIcon(R.drawable.map_marker_blue); colorId = R.color.marker_blue;
break;
case 1: case 1:
return iconsCache.getIcon(R.drawable.map_marker_green); colorId = R.color.marker_green;
break;
case 2: case 2:
return iconsCache.getIcon(R.drawable.map_marker_orange); colorId = R.color.marker_orange;
break;
case 3: case 3:
return iconsCache.getIcon(R.drawable.map_marker_red); colorId = R.color.marker_red;
break;
case 4: case 4:
return iconsCache.getIcon(R.drawable.map_marker_yellow); colorId = R.color.marker_lt_green;
break;
default: 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;
}
} }

View file

@ -19,6 +19,8 @@ import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; 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.R;
import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -42,7 +44,8 @@ import net.osmand.util.MapUtils;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.List; import java.util.List;
public class MapContextMenu extends MenuTitleController implements StateChangedListener<ApplicationMode> { public class MapContextMenu extends MenuTitleController implements StateChangedListener<ApplicationMode>,
MapMarkerChangedListener {
private MapActivity mapActivity; private MapActivity mapActivity;
private MapMultiSelectionMenu mapMultiSelectionMenu; private MapMultiSelectionMenu mapMultiSelectionMenu;
@ -256,6 +259,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
mapActivity.refreshMap(); mapActivity.refreshMap();
if (object instanceof MapMarker) {
mapActivity.getMyApplication().getMapMarkersHelper().addListener(this);
}
return true; return true;
} }
@ -308,6 +315,9 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
public void close() { public void close() {
if (active) { if (active) {
active = false; active = false;
if (object instanceof MapMarker) {
mapActivity.getMyApplication().getMapMarkersHelper().removeListener(this);
}
if (this.object != null) { if (this.object != null) {
clearSelectedObject(this.object); 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<MapContextMenuFragment> fragmentRef = findMenuFragment();
if (fragmentRef != null)
fragmentRef.get().refreshTitle();
}
}
@Override
public void onMapMarkersChanged() {
}
@Override @Override
public void stateChanged(ApplicationMode change) { public void stateChanged(ApplicationMode change) {
appModeChanged = active; appModeChanged = active;
@ -477,7 +503,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAP_MARKERS); mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAP_MARKERS);
} else { } else {
mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(), mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(),
pointDescription); getPointDescriptionForTarget());
} }
close(); close();
} }

View file

@ -102,6 +102,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
//private List<PendingDismissData> mPendingDismisses = new ArrayList<PendingDismissData>(); //private List<PendingDismissData> mPendingDismisses = new ArrayList<PendingDismissData>();
private int mDismissAnimationRefCount = 0; private int mDismissAnimationRefCount = 0;
private float mDownX; private float mDownX;
private float mDownY;
private boolean mSwiping; private boolean mSwiping;
private VelocityTracker mVelocityTracker; private VelocityTracker mVelocityTracker;
private int mDownPosition; private int mDownPosition;
@ -601,6 +602,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
int position = mListView.getPositionForView(mSwipeDownView) - mListView.getHeaderViewsCount(); int position = mListView.getPositionForView(mSwipeDownView) - mListView.getHeaderViewsCount();
if (mCallbacks == null || mCallbacks.canDismiss(position)) { if (mCallbacks == null || mCallbacks.canDismiss(position)) {
mDownX = ev.getRawX(); mDownX = ev.getRawX();
mDownY = ev.getRawY();
mDownPosition = position; mDownPosition = position;
mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker = VelocityTracker.obtain();
@ -629,6 +631,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
mVelocityTracker.recycle(); mVelocityTracker.recycle();
mVelocityTracker = null; mVelocityTracker = null;
mDownX = 0; mDownX = 0;
mDownY = 0;
mSwipeDownView = mSwipeDownChild = null; mSwipeDownView = mSwipeDownChild = null;
mDownPosition = ListView.INVALID_POSITION; mDownPosition = ListView.INVALID_POSITION;
mSwiping = false; mSwiping = false;
@ -669,6 +672,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
} }
mVelocityTracker = null; mVelocityTracker = null;
mDownX = 0; mDownX = 0;
mDownY = 0;
mSwipeDownView = null; mSwipeDownView = null;
mSwipeDownChild = null; mSwipeDownChild = null;
mDownPosition = AbsListView.INVALID_POSITION; mDownPosition = AbsListView.INVALID_POSITION;
@ -683,6 +687,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
mVelocityTracker.addMovement(ev); mVelocityTracker.addMovement(ev);
float deltaX = ev.getRawX() - mDownX; float deltaX = ev.getRawX() - mDownX;
float deltaY = ev.getRawY() - mDownY;
// Only start swipe in correct direction // Only start swipe in correct direction
if (isSwipeDirectionValid(deltaX)) { if (isSwipeDirectionValid(deltaX)) {
ViewParent parent = mListView.getParent(); ViewParent parent = mListView.getParent();
@ -691,7 +696,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
// otherwise swipe would not be working. // otherwise swipe would not be working.
parent.requestDisallowInterceptTouchEvent(true); parent.requestDisallowInterceptTouchEvent(true);
} }
if (Math.abs(deltaX) > mSlop) { if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
mSwiping = true; mSwiping = true;
mListView.requestDisallowInterceptTouchEvent(true); mListView.requestDisallowInterceptTouchEvent(true);