Fixed map markers UI

This commit is contained in:
Alexey Kulish 2016-02-17 19:31:32 +03:00
parent d55526661b
commit 214f144555
6 changed files with 439 additions and 307 deletions

View file

@ -28,7 +28,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="@color/markers_top_bar_background" android:background="@color/markers_top_bar_background"
android:minHeight="@dimen/map_address_height"> android:minHeight="50dp">
<LinearLayout <LinearLayout
android:id="@+id/map_marker_row" android:id="@+id/map_marker_row"
@ -42,8 +42,8 @@
<ImageView <ImageView
android:id="@+id/map_marker_arrow" android:id="@+id/map_marker_arrow"
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="30dp" android:layout_height="24dp"
android:src="@drawable/map_arrow_to_destination"/> android:src="@drawable/ic_arrow_marker_diretion"/>
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
@ -67,7 +67,6 @@
android:id="@+id/map_marker_address" android:id="@+id/map_marker_address"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:text="Dmitrievskaya st., 45" android:text="Dmitrievskaya st., 45"
@ -102,7 +101,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="@color/markers_top_bar_2nd_background" android:background="@color/markers_top_bar_2nd_background"
android:minHeight="@dimen/map_address_height" android:minHeight="50dp"
android:visibility="visible"> android:visibility="visible">
@ -118,8 +117,8 @@
<ImageView <ImageView
android:id="@+id/map_marker_arrow_2nd" android:id="@+id/map_marker_arrow_2nd"
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="30dp" android:layout_height="24dp"
android:src="@drawable/map_arrow_to_destination"/> android:src="@drawable/ic_arrow_marker_diretion"/>
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
@ -144,7 +143,6 @@
android:id="@+id/map_marker_address_2nd" android:id="@+id/map_marker_address_2nd"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:text="Dmitrievskaya st., 45" android:text="Dmitrievskaya st., 45"

View file

@ -161,7 +161,7 @@
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minHeight="@dimen/map_address_height" android:minHeight="60dp"
android:background="@color/markers_top_bar_background"> android:background="@color/markers_top_bar_background">
<LinearLayout <LinearLayout
@ -171,20 +171,20 @@
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:gravity="center_vertical" android:gravity="center_vertical"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
android:id="@+id/map_marker_arrow" android:id="@+id/map_marker_arrow"
android:layout_width="60dp" android:layout_width="66dp"
android:layout_height="40dp" android:layout_height="36dp"
android:src="@drawable/map_arrow_to_destination"/> android:src="@drawable/ic_arrow_marker_diretion"/>
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
@ -200,7 +200,6 @@
android:id="@+id/map_marker_address" android:id="@+id/map_marker_address"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:textColor="@color/marker_top_2nd_line_color" android:textColor="@color/marker_top_2nd_line_color"
android:textStyle="bold" android:textStyle="bold"
android:maxLines="1" android:maxLines="1"
@ -233,7 +232,7 @@
android:id="@+id/map_markers_top_bar_2nd" android:id="@+id/map_markers_top_bar_2nd"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minHeight="@dimen/map_address_height" android:minHeight="50dp"
android:background="@color/markers_top_bar_2nd_background" android:background="@color/markers_top_bar_2nd_background"
android:visibility="visible"> android:visibility="visible">
@ -254,9 +253,9 @@
<ImageView <ImageView
android:id="@+id/map_marker_arrow_2nd" android:id="@+id/map_marker_arrow_2nd"
android:layout_width="60dp" android:layout_width="66dp"
android:layout_height="30dp" android:layout_height="24dp"
android:src="@drawable/map_arrow_to_destination"/> android:src="@drawable/ic_arrow_marker_diretion"/>
<RelativeLayout <RelativeLayout
android:layout_width="0dp" android:layout_width="0dp"

View file

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="markers_top_bar_background">#145256</color> <color name="markers_top_bar_background">#0f5257</color>
<color name="markers_top_bar_2nd_background">#0e3b3e</color> <color name="markers_top_bar_2nd_background">#0c4347</color>
<color name="marker_top_2nd_line_color">#588689</color> <color name="marker_top_2nd_line_color">#859899</color>
<color name="marker_blue">#2196f3</color> <color name="marker_blue">#2196f3</color>
<color name="marker_green">#73b825</color> <color name="marker_green">#73b825</color>

View file

@ -8,12 +8,15 @@ import net.osmand.data.PointDescription;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
public class MapMarkersHelper { public class MapMarkersHelper {
public static final int MAP_MARKERS_COLORS_COUNT = 7; public static final int MAP_MARKERS_COLORS_COUNT = 7;
private List<MapMarker> mapMarkers = new ArrayList<>(); private List<MapMarker> mapMarkers = new ArrayList<>();
private List<MapMarker> mapMarkersPositions = new ArrayList<>();
private List<MapMarker> mapMarkersHistory = new ArrayList<>(); private List<MapMarker> mapMarkersHistory = new ArrayList<>();
private OsmandSettings settings; private OsmandSettings settings;
private List<MapMarkerChangedListener> listeners = new ArrayList<>(); private List<MapMarkerChangedListener> listeners = new ArrayList<>();
@ -29,14 +32,16 @@ public class MapMarkersHelper {
public LatLon point; public LatLon point;
private PointDescription pointDescription; private PointDescription pointDescription;
public int colorIndex; public int colorIndex;
public int pos;
public int index; public int index;
public boolean history; public boolean history;
public int dist; public int dist;
public MapMarker(LatLon point, PointDescription name, int colorIndex, int index) { public MapMarker(LatLon point, PointDescription name, int colorIndex, int pos, int index) {
this.point = point; this.point = point;
this.pointDescription = name; this.pointDescription = name;
this.colorIndex = colorIndex; this.colorIndex = colorIndex;
this.pos = pos;
this.index = index; this.index = index;
} }
@ -89,24 +94,58 @@ public class MapMarkersHelper {
List<LatLon> ips = settings.getMapMarkersPoints(); List<LatLon> ips = settings.getMapMarkersPoints();
List<String> desc = settings.getMapMarkersPointDescriptions(ips.size()); List<String> desc = settings.getMapMarkersPointDescriptions(ips.size());
List<Integer> colors = settings.getMapMarkersColors(ips.size()); List<Integer> colors = settings.getMapMarkersColors(ips.size());
List<Integer> positions = settings.getMapMarkersPositions(ips.size());
int colorIndex = 0;
int pos = 0;
for (int i = 0; i < ips.size(); i++) { for (int i = 0; i < ips.size(); i++) {
if (colors.size() > i) {
colorIndex = colors.get(i);
}
if (positions.size() > i) {
pos = positions.get(i);
} else {
pos++;
}
MapMarker mapMarker = new MapMarker(ips.get(i), MapMarker mapMarker = new MapMarker(ips.get(i),
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colors.get(i), i); PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex,
pos, i);
mapMarkers.add(mapMarker); mapMarkers.add(mapMarker);
lookupAddress(mapMarker, false); lookupAddress(mapMarker, false);
} }
updatePositionArray();
ips = settings.getMapMarkersHistoryPoints(); ips = settings.getMapMarkersHistoryPoints();
desc = settings.getMapMarkersHistoryPointDescriptions(ips.size()); desc = settings.getMapMarkersHistoryPointDescriptions(ips.size());
colors = settings.getMapMarkersHistoryColors(ips.size()); colors = settings.getMapMarkersHistoryColors(ips.size());
for (int i = 0; i < ips.size(); i++) { for (int i = 0; i < ips.size(); i++) {
MapMarker mapMarker = new MapMarker(ips.get(i), MapMarker mapMarker = new MapMarker(ips.get(i),
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colors.get(i), i); PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colors.get(i), 0, i);
mapMarker.history = true; mapMarker.history = true;
mapMarkersHistory.add(mapMarker); mapMarkersHistory.add(mapMarker);
lookupAddress(mapMarker, true); lookupAddress(mapMarker, true);
} }
} }
private void updatePositionArray() {
mapMarkersPositions.clear();
mapMarkersPositions.addAll(mapMarkers);
Collections.sort(mapMarkersPositions, new Comparator<MapMarker>() {
@Override
public int compare(MapMarker lhs, MapMarker rhs) {
return lhs.pos < rhs.pos ? -1 : (lhs.pos == rhs.pos ? 0 : 1);
}
});
}
public void normalizePositions() {
for (int i = 0; i < mapMarkersPositions.size(); i++) {
MapMarker marker = mapMarkersPositions.get(i);
marker.pos = i;
}
saveMapMarkers(mapMarkers, null);
}
private void lookupAddress(final MapMarker mapMarker, final boolean history) { private void lookupAddress(final MapMarker mapMarker, final boolean history) {
if (mapMarker != null && mapMarker.pointDescription.isSearchingAddress(ctx)) { if (mapMarker != null && mapMarker.pointDescription.isSearchingAddress(ctx)) {
cancelPointAddressRequests(mapMarker.point); cancelPointAddressRequests(mapMarker.point);
@ -123,7 +162,7 @@ public class MapMarkersHelper {
mapMarker.pointDescription, mapMarker.colorIndex); mapMarker.pointDescription, mapMarker.colorIndex);
} else { } else {
settings.updateMapMarker(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(), settings.updateMapMarker(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(),
mapMarker.pointDescription, mapMarker.colorIndex); mapMarker.pointDescription, mapMarker.colorIndex, mapMarker.pos);
} }
updateMarker(mapMarker); updateMarker(mapMarker);
} }
@ -140,6 +179,7 @@ public class MapMarkersHelper {
for (MapMarker marker : mapMarkers) { for (MapMarker marker : mapMarkers) {
marker.index = ind++; marker.index = ind++;
} }
updatePositionArray();
refresh(); refresh();
} }
@ -147,6 +187,10 @@ public class MapMarkersHelper {
return mapMarkers; return mapMarkers;
} }
public List<MapMarker> getMapMarkersPositions() {
return mapMarkersPositions;
}
public List<MapMarker> getMapMarkersHistory() { public List<MapMarker> getMapMarkersHistory() {
return mapMarkersHistory; return mapMarkersHistory;
} }
@ -176,25 +220,19 @@ public class MapMarkersHelper {
markers.add(marker); markers.add(marker);
} }
mapMarkers = markers; mapMarkers = markers;
saveMapMarkers(mapMarkers, mapMarkersHistory); saveMapMarkers(mapMarkers, null);
readFromSettings();
refresh();
} }
public void removeActiveMarkers() { public void removeActiveMarkers() {
cancelAddressRequests(); cancelAddressRequests();
settings.clearActiveMapMarkers(); settings.clearActiveMapMarkers();
mapMarkers.clear();
readFromSettings(); readFromSettings();
refresh(); refresh();
} }
public void removeMarkersHistory() { public void removeMarkersHistory() {
cancelAddressRequests(); cancelAddressRequests();
settings.clearMapMarkersHistory(); settings.clearMapMarkersHistory();
mapMarkersHistory.clear();
readFromSettings(); readFromSettings();
refresh(); refresh();
} }
@ -214,6 +252,7 @@ public class MapMarkersHelper {
double[] longitudes = new double[points.size()]; double[] longitudes = new double[points.size()];
List<PointDescription> pointDescriptions = new ArrayList<>(); List<PointDescription> pointDescriptions = new ArrayList<>();
int[] colorIndexes = new int[points.size()]; int[] colorIndexes = new int[points.size()];
int[] positions = new int[points.size()];
int[] indexes = new int[points.size()]; int[] indexes = new int[points.size()];
for (int i = 0; i < points.size(); i++) { for (int i = 0; i < points.size(); i++) {
LatLon point = points.get(i); LatLon point = points.get(i);
@ -241,11 +280,12 @@ public class MapMarkersHelper {
longitudes[i] = point.getLongitude(); longitudes[i] = point.getLongitude();
pointDescriptions.add(pointDescription); pointDescriptions.add(pointDescription);
colorIndexes[i] = colorIndex; colorIndexes[i] = colorIndex;
positions[i] = -1 - i;
indexes[i] = 0; indexes[i] = 0;
} }
settings.insertMapMarkers(latitudes, longitudes, pointDescriptions, colorIndexes, indexes); settings.insertMapMarkers(latitudes, longitudes, pointDescriptions, colorIndexes, positions, indexes);
readFromSettings(); readFromSettings();
refresh(); normalizePositions();
} }
} }
@ -278,12 +318,14 @@ public class MapMarkersHelper {
List<LatLon> ls = new ArrayList<>(markers.size()); List<LatLon> ls = new ArrayList<>(markers.size());
List<String> names = new ArrayList<>(markers.size()); List<String> names = new ArrayList<>(markers.size());
List<Integer> colors = new ArrayList<>(markers.size()); List<Integer> colors = new ArrayList<>(markers.size());
List<Integer> positions = new ArrayList<>(markers.size());
for (MapMarker marker : markers) { for (MapMarker marker : markers) {
ls.add(marker.point); ls.add(marker.point);
names.add(PointDescription.serializeToString(marker.pointDescription)); names.add(PointDescription.serializeToString(marker.pointDescription));
colors.add(marker.colorIndex); colors.add(marker.colorIndex);
positions.add(marker.pos);
} }
settings.saveMapMarkers(ls, names, colors); settings.saveMapMarkers(ls, names, colors, positions);
} }
if (markersHistory != null) { if (markersHistory != null) {

File diff suppressed because it is too large Load diff

View file

@ -90,7 +90,7 @@ public class MapMarkersWidgetsFactory {
}); });
IconsCache iconsCache = map.getMyApplication().getIconsCache(); IconsCache iconsCache = map.getMyApplication().getIconsCache();
if (isLandscapeLayout() && helper.getActiveMapMarkers().size() > 1) { if (isLandscapeLayout() && helper.getMapMarkersPositions().size() > 1) {
moreButton.setVisibility(View.GONE); moreButton.setVisibility(View.GONE);
} else { } else {
moreButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_overflow_menu_white, R.color.marker_top_2nd_line_color)); moreButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_overflow_menu_white, R.color.marker_top_2nd_line_color));
@ -129,16 +129,16 @@ public class MapMarkersWidgetsFactory {
} }
private void removeMarker(int index) { private void removeMarker(int index) {
if (helper.getActiveMapMarkers().size() > index) { if (helper.getMapMarkersPositions().size() > index) {
MapMarker marker = helper.getActiveMapMarkers().get(index); MapMarker marker = helper.getMapMarkersPositions().get(index);
helper.removeMapMarker(marker.index); helper.removeMapMarker(marker.index);
helper.addMapMarkerHistory(marker); helper.addMapMarkerHistory(marker);
} }
} }
private void showMarkerOnMap(int index) { private void showMarkerOnMap(int index) {
if (helper.getActiveMapMarkers().size() > index) { if (helper.getMapMarkersPositions().size() > index) {
MapMarker marker = helper.getActiveMapMarkers().get(index); MapMarker marker = helper.getMapMarkersPositions().get(index);
MapMarkerDialogHelper.showMarkerOnMap(map, marker); MapMarkerDialogHelper.showMarkerOnMap(map, marker);
} }
} }
@ -173,7 +173,7 @@ public class MapMarkersWidgetsFactory {
return; return;
} }
List<MapMarker> markers = helper.getActiveMapMarkers(); List<MapMarker> markers = helper.getMapMarkersPositions();
if (zoom < 3 || markers.size() == 0 if (zoom < 3 || markers.size() == 0
|| !map.getMyApplication().getSettings().SHOW_MAP_MARKERS_TOOLBAR.get() || !map.getMyApplication().getSettings().SHOW_MAP_MARKERS_TOOLBAR.get()
|| map.getMyApplication().getRoutingHelper().isFollowingMode() || map.getMyApplication().getRoutingHelper().isFollowingMode()
@ -223,9 +223,9 @@ public class MapMarkersWidgetsFactory {
} else { } else {
dd = (DirectionDrawable) arrowImg.getDrawable(); dd = (DirectionDrawable) arrowImg.getDrawable();
} }
dd.setImage(R.drawable.map_arrow_to_destination, MapMarkerDialogHelper.getMapMarkerColorId(marker.colorIndex)); dd.setImage(R.drawable.ic_arrow_marker_diretion, MapMarkerDialogHelper.getMapMarkerColorId(marker.colorIndex));
if (heading != null && loc != null) { if (heading != null && loc != null) {
dd.setAngle(mes[1] - heading + 90 + screenOrientation); dd.setAngle(mes[1] - heading + 180 + screenOrientation);
} }
if (newImage) { if (newImage) {
arrowImg.setImageDrawable(dd); arrowImg.setImageDrawable(dd);