diff --git a/OsmAnd/res/color/bottom_navigation_color_selector_dark.xml b/OsmAnd/res/color/bottom_navigation_color_selector_dark.xml new file mode 100644 index 0000000000..803c0606b2 --- /dev/null +++ b/OsmAnd/res/color/bottom_navigation_color_selector_dark.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/OsmAnd/res/color/bottom_navigation_color_selector_light.xml b/OsmAnd/res/color/bottom_navigation_color_selector_light.xml new file mode 100644 index 0000000000..d1537744a1 --- /dev/null +++ b/OsmAnd/res/color/bottom_navigation_color_selector_light.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/OsmAnd/res/layout/fragment_map_markers_dialog.xml b/OsmAnd/res/layout/fragment_map_markers_dialog.xml index d7b9dda1a9..6bc81c6b5e 100644 --- a/OsmAnd/res/layout/fragment_map_markers_dialog.xml +++ b/OsmAnd/res/layout/fragment_map_markers_dialog.xml @@ -98,7 +98,7 @@ android:layout_height="wrap_content" android:background="?attr/bg_color" app:itemBackground="?attr/bg_color" - app:itemIconTint="@drawable/bottom_navigation_color_selector" - app:itemTextColor="@drawable/bottom_navigation_color_selector" + app:itemIconTint="@color/bottom_navigation_color_selector_light" + app:itemTextColor="@color/bottom_navigation_color_selector_light" app:menu="@menu/map_markers_bottom_navigation"/> diff --git a/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml index 1e0030de66..d92053dc9c 100644 --- a/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml @@ -115,6 +115,73 @@ + + + + + + + + + + + + + + + + + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:background="@null" + android:clickable="false" + android:focusable="false"/> + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:background="@null" + android:clickable="false" + android:focusable="false"/> + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:background="@null" + android:clickable="false" + android:focusable="false"/> diff --git a/OsmAnd/res/layout/map_marker_item_header.xml b/OsmAnd/res/layout/map_marker_item_header.xml index 884449ea96..bea554a14b 100644 --- a/OsmAnd/res/layout/map_marker_item_header.xml +++ b/OsmAnd/res/layout/map_marker_item_header.xml @@ -14,24 +14,35 @@ android:orientation="horizontal" android:background="?attr/bg_color"> + + + + - + diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 0f4ddb6a42..da0e14678c 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -55,7 +55,6 @@ android:layout_height="28dp"> diff --git a/OsmAnd/res/layout/map_marker_item_show_hide_history.xml b/OsmAnd/res/layout/map_marker_item_show_hide_history.xml new file mode 100644 index 0000000000..2454538048 --- /dev/null +++ b/OsmAnd/res/layout/map_marker_item_show_hide_history.xml @@ -0,0 +1,25 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 034ca5acff..953168a80d 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,10 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Show guide line + Show arrows on the map + Show passed + Hide passed Remove from Map Markers Descendingly Ascendingly diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 1830656109..9c65a13f1b 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -15,7 +15,6 @@ import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; -import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -40,6 +39,7 @@ public class MapMarkersHelper { private List mapMarkers = new LinkedList<>(); private List mapMarkersHistory = new LinkedList<>(); + private List mapMarkersGroups = new ArrayList<>(); private OsmandSettings settings; private List listeners = new ArrayList<>(); private OsmandApplication ctx; @@ -175,6 +175,11 @@ public class MapMarkersHelper { } } + @Nullable + public MarkersSyncGroup getGroup(String id) { + return markersDbHelper.getGroup(id); + } + public static class MarkersSyncGroup { public static final int FAVORITES_TYPE = 0; @@ -214,6 +219,10 @@ public class MapMarkersHelper { public int getColor() { return color; } + + public void setColor(int color) { + this.color = color; + } } public MapMarkersHelper(OsmandApplication ctx) { @@ -222,6 +231,7 @@ public class MapMarkersHelper { markersDbHelper = ctx.getMapMarkersDbHelper(); startFromMyLocation = settings.ROUTE_MAP_MARKERS_START_MY_LOC.get(); loadMarkers(); + createMapMarkersGroups(); } public boolean isStartFromMyLocation() { @@ -251,7 +261,7 @@ public class MapMarkersHelper { checkAndFixActiveMarkersOrderIfNeeded(); List markersHistory = markersDbHelper.getMarkersHistory(); - sortHistoryMarkers(); + sortMarkers(markersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); mapMarkersHistory.addAll(markersHistory); if (!ctx.isApplicationInitializing()) { @@ -279,73 +289,20 @@ public class MapMarkersHelper { } } - public List getMarkersSortedByGroup() { - Map groupsMap = new LinkedHashMap<>(); - List noGroup = new ArrayList<>(); - for (MapMarker marker : mapMarkers) { - String groupName = marker.groupName; - if (groupName == null) { - noGroup.add(marker); - } else { - MapMarkerGroup group = groupsMap.get(groupName); - if (group == null) { - group = new MapMarkerGroup(groupName, marker.creationDate); - groupsMap.put(groupName, group); - } else { - long markerCreationDate = marker.creationDate; - if (markerCreationDate < group.getCreationDate()) { - group.setCreationDate(markerCreationDate); - } - } - group.getMapMarkers().add(marker); - } - } - List groups = new ArrayList<>(groupsMap.values()); - sortGroups(groups); - - List markers = new ArrayList<>(); - markers.addAll(noGroup); - for (MapMarkerGroup group : groups) { - markers.addAll(group.getMapMarkers()); - } - return markers; - } - - private void sortGroups(List groups) { - Collections.sort(groups, new Comparator() { - @Override - public int compare(MapMarkerGroup group1, MapMarkerGroup group2) { - long t1 = group1.creationDate; - long t2 = group2.creationDate; - if (t1 > t2) { - return -1; - } else if (t1 == t2) { - return 0; - } else { - return 1; - } - } - }); - } - - private void sortHistoryMarkers() { - sortMarkers(true, null); - } - - private void sortMarkers(final boolean history, final OsmandSettings.MapMarkersOrderByMode orderByMode) { + public void sortMarkers(List markers, final boolean visited, final OsmandSettings.MapMarkersOrderByMode orderByMode) { final LatLon location = ctx.getSettings().getLastKnownMapLocation(); - Collections.sort(history ? mapMarkersHistory : mapMarkers, new Comparator() { + Collections.sort(markers, new Comparator() { @Override public int compare(MapMarker mapMarker1, MapMarker mapMarker2) { - if (history || orderByMode.isDateAddedDescending() || orderByMode.isDateAddedAscending()) { - long t1 = history ? mapMarker1.visitedDate : mapMarker1.creationDate; - long t2 = history ? mapMarker2.visitedDate : mapMarker2.creationDate; + if (orderByMode.isDateAddedDescending() || orderByMode.isDateAddedAscending()) { + long t1 = visited ? mapMarker1.visitedDate : mapMarker1.creationDate; + long t2 = visited ? mapMarker2.visitedDate : mapMarker2.creationDate; if (t1 > t2) { - return history || orderByMode.isDateAddedDescending() ? -1 : 1; + return orderByMode.isDateAddedDescending() ? -1 : 1; } else if (t1 == t2) { return 0; } else { - return history || orderByMode.isDateAddedDescending() ? 1 : -1; + return orderByMode.isDateAddedDescending() ? 1 : -1; } } else if (orderByMode.isDistanceDescending() || orderByMode.isDistanceAscending()) { int d1 = (int) MapUtils.getDistance(location, mapMarker1.getLatitude(), mapMarker1.getLongitude()); @@ -367,7 +324,7 @@ public class MapMarkersHelper { } public void orderMarkers(OsmandSettings.MapMarkersOrderByMode orderByMode) { - sortMarkers(false, orderByMode); + sortMarkers(getMapMarkers(), false, orderByMode); checkAndFixActiveMarkersOrderIfNeeded(); } @@ -417,6 +374,9 @@ public class MapMarkersHelper { removeActiveMarkersFromSyncGroup(group.getId()); return; } + if (group.getColor() == -1) { + group.setColor(favGroup.color); + } for (FavouritePoint fp : favGroup.points) { addNewMarkerIfNeeded(group, dbMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName()); @@ -438,7 +398,9 @@ public class MapMarkersHelper { } List gpxPoints = new LinkedList<>(gpx.getPoints()); + int defColor = ContextCompat.getColor(ctx, R.color.marker_red); for (WptPt pt : gpxPoints) { + group.setColor(pt.getColor(defColor)); addNewMarkerIfNeeded(group, dbMarkers, new LatLon(pt.lat, pt.lon), pt.name); } @@ -452,13 +414,10 @@ public class MapMarkersHelper { for (MapMarker marker : markers) { if (marker.id.equals(group.getId() + name)) { exists = true; - int colorIndex = MapMarker.getColorIndex(ctx, ColorDialogs.getNearestColor(group.getColor(), MapMarker.getColors(ctx))); - boolean updateColor = group.getColor() != -1 && marker.colorIndex != colorIndex; - if (!marker.history && (!marker.point.equals(latLon) || updateColor)) { + if (!marker.history && (!marker.point.equals(latLon))) { for (MapMarker m : mapMarkers) { if (m.id.equals(marker.id)) { m.point = latLon; - m.colorIndex = colorIndex; updateMapMarker(m, true); break; } @@ -501,7 +460,7 @@ public class MapMarkersHelper { marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE; mapMarkersHistory.add(marker); checkAndFixActiveMarkersOrderIfNeeded(); - sortHistoryMarkers(); + sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); refresh(); } } @@ -511,11 +470,12 @@ public class MapMarkersHelper { markersDbHelper.addMarker(marker); if (marker.history) { mapMarkersHistory.add(marker); - sortHistoryMarkers(); + sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); } else { mapMarkers.add(marker); checkAndFixActiveMarkersOrderIfNeeded(); } + addMarkerToGroup(marker); refresh(); } } @@ -527,7 +487,7 @@ public class MapMarkersHelper { marker.history = false; mapMarkers.add(position, marker); checkAndFixActiveMarkersOrderIfNeeded(); - sortHistoryMarkers(); + sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); refresh(); } } @@ -541,7 +501,7 @@ public class MapMarkersHelper { mapMarkers.add(marker); } checkAndFixActiveMarkersOrderIfNeeded(); - sortHistoryMarkers(); + sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); refresh(); } } @@ -551,6 +511,7 @@ public class MapMarkersHelper { markersDbHelper.removeMarker(marker, true); mapMarkersHistory.remove(marker); refresh(); + removeMarkerFromGroup(marker); } } @@ -623,7 +584,7 @@ public class MapMarkersHelper { } mapMarkersHistory.addAll(mapMarkers); mapMarkers.clear(); - sortHistoryMarkers(); + sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); refresh(); } @@ -632,6 +593,7 @@ public class MapMarkersHelper { markersDbHelper.clearAllMarkersHistory(); mapMarkersHistory.clear(); refresh(); + removeHistoryMarkersFromGroups(); } public void addMarkersSyncGroup(MarkersSyncGroup group) { @@ -675,8 +637,7 @@ public class MapMarkersHelper { private void addMarkers(List points, List historyNames, @Nullable MarkersSyncGroup group) { if (points.size() > 0) { - boolean randomColor = group == null || group.getColor() == -1; - int colorIndex = randomColor ? -1 : MapMarker.getColorIndex(ctx, ColorDialogs.getNearestColor(group.getColor(), MapMarker.getColors(ctx))); + int colorIndex = -1; for (int i = 0; i < points.size(); i++) { LatLon point = points.get(i); PointDescription historyName = historyNames.get(i); @@ -689,16 +650,14 @@ public class MapMarkersHelper { if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) { pointDescription.setName(PointDescription.getSearchAddressStr(ctx)); } - if (randomColor) { - if (colorIndex == -1) { - if (mapMarkers.size() > 0) { - colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; - } else { - colorIndex = 0; - } + if (colorIndex == -1) { + if (mapMarkers.size() > 0) { + colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; } else { - colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; + colorIndex = 0; } + } else { + colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; } MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0); @@ -714,6 +673,7 @@ public class MapMarkersHelper { marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE; markersDbHelper.addMarker(marker); mapMarkers.add(marker); + addMarkerToGroup(marker); checkAndFixActiveMarkersOrderIfNeeded(); } } @@ -856,15 +816,165 @@ public class MapMarkersHelper { GPXUtilities.writeGpxFile(fout, file, ctx); } - public static class MapMarkerGroup { - private String name; - private List mapMarkers = new ArrayList<>(); - private long creationDate; - - public MapMarkerGroup(String name, long creationDate) { - this.name = name; - this.creationDate = creationDate; + private void removeHistoryMarkersFromGroups() { + for (MapMarkersGroup markersGroup : mapMarkersGroups) { + List activeMarkers = new ArrayList<>(); + for (MapMarker marker : markersGroup.getMarkers()) { + if (!marker.history) { + activeMarkers.add(marker); + } + } + markersGroup.setMarkers(activeMarkers); + updateShowHideHistoryButtonInGroup(markersGroup); } + } + + private void updateShowHideHistoryButtonInGroup(MapMarkersGroup mapMarkersGroup) { + int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size(); + ShowHideHistoryButton showHideHistoryButton = mapMarkersGroup.getShowHideHistoryButton(); + if (showHideHistoryButton != null && historyMarkersCount == 0) { + mapMarkersGroup.setShowHideHistoryButton(null); + } else if (historyMarkersCount > 0) { + showHideHistoryButton = new ShowHideHistoryButton(); + showHideHistoryButton.setShowHistory(false); + showHideHistoryButton.setMarkerGroup(mapMarkersGroup); + mapMarkersGroup.setShowHideHistoryButton(showHideHistoryButton); + } + } + + private void addMarkerToGroup(MapMarker marker) { + if (marker != null) { + MapMarkersGroup mapMarkersGroup = getMapMarkerGroupByName(marker.groupName); + if (mapMarkersGroup != null) { + mapMarkersGroup.getMarkers().add(marker); + updateShowHideHistoryButtonInGroup(mapMarkersGroup); + if (mapMarkersGroup.getName() == null) { + sortMarkers(mapMarkersGroup.getMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); + } + } else { + MapMarkersGroup group = createMapMarkerGroup(marker); + group.getMarkers().add(marker); + createHeaderAndHistoryButtonInGroup(group); + } + } + } + + private MapMarkersGroup createMapMarkerGroup(MapMarker marker) { + MapMarkersGroup group = new MapMarkersGroup(); + group.setName(marker.groupName); + MapMarkersHelper.MarkersSyncGroup syncGroup = getGroup(marker.groupKey); + if (syncGroup != null) { + group.setType(syncGroup.getType()); + } + group.setColor(MapMarker.getColorId(marker.colorIndex)); + group.setCreationDate(marker.creationDate); + mapMarkersGroups.add(group); + return group; + } + + private void createHeaderAndHistoryButtonInGroup(MapMarkersGroup group) { + GroupHeader header = new GroupHeader(); + int type = group.getType(); + if (type != -1) { + header.setIconRes(type == MapMarkersHelper.MarkersSyncGroup.FAVORITES_TYPE ? R.drawable.ic_action_fav_dark : R.drawable.ic_action_track_16); + } + header.setGroup(group); + group.setGroupHeader(header); + updateShowHideHistoryButtonInGroup(group); + } + + private void removeMarkerFromGroup(MapMarker marker) { + if (marker != null) { + MapMarkersGroup mapMarkersGroup = getMapMarkerGroupByName(marker.groupName); + if (mapMarkersGroup != null) { + mapMarkersGroup.getMarkers().remove(marker); + updateShowHideHistoryButtonInGroup(mapMarkersGroup); + } + } + } + + public List getMapMarkersGroups() { + return mapMarkersGroups; + } + + private void createMapMarkersGroups() { + List markers = new ArrayList<>(); + markers.addAll(mapMarkers); + markers.addAll(mapMarkersHistory); + + Map groupsMap = new LinkedHashMap<>(); + MapMarkersGroup noGroup = null; + for (MapMarker marker : markers) { + String groupName = marker.groupName; + if (groupName == null) { + if (noGroup == null) { + noGroup = new MapMarkersGroup(); + noGroup.setCreationDate(marker.creationDate); + } + noGroup.getMarkers().add(marker); + } else { + MapMarkersGroup group = groupsMap.get(groupName); + if (group == null) { + group = createMapMarkerGroup(marker); + groupsMap.put(groupName, group); + } else { + long markerCreationDate = marker.creationDate; + if (markerCreationDate < group.getCreationDate()) { + group.setCreationDate(markerCreationDate); + } + } + group.getMarkers().add(marker); + } + } + mapMarkersGroups = new ArrayList<>(groupsMap.values()); + sortGroups(mapMarkersGroups); + + for (MapMarkersGroup group : mapMarkersGroups) { + createHeaderAndHistoryButtonInGroup(group); + } + + if (noGroup != null) { + sortMarkers(noGroup.getMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); + mapMarkersGroups.add(0, noGroup); + } + } + + private void sortGroups(List groups) { + Collections.sort(groups, new Comparator() { + @Override + public int compare(MapMarkersGroup group1, MapMarkersGroup group2) { + long t1 = group1.getCreationDate(); + long t2 = group2.getCreationDate(); + if (t1 > t2) { + return -1; + } else if (t1 == t2) { + return 0; + } else { + return 1; + } + } + }); + } + + public MapMarkersGroup getMapMarkerGroupByName(String name) { + for (MapMarkersGroup group : mapMarkersGroups) { + if ((name == null && group.getName() == null) + || (group.getName() != null && group.getName().equals(name))) { + return group; + } + } + return null; + } + + public static class MapMarkersGroup { + private String name; + private GroupHeader header; + private int type = -1; + private List markers = new ArrayList<>(); + private long creationDate; + private ShowHideHistoryButton showHideHistoryButton; + private int color; + private boolean disabled; public String getName() { return name; @@ -874,12 +984,48 @@ public class MapMarkersHelper { this.name = name; } - public List getMapMarkers() { - return mapMarkers; + public GroupHeader getGroupHeader() { + return header; } - public void setMapMarkers(List mapMarkers) { - this.mapMarkers = mapMarkers; + public void setGroupHeader(GroupHeader header) { + this.header = header; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public List getActiveMarkers() { + List activeMarkers = new ArrayList<>(); + for (MapMarker marker : markers) { + if (!marker.history) { + activeMarkers.add(marker); + } + } + return activeMarkers; + } + + public List getHistoryMarkers() { + List historyMarkers = new ArrayList<>(); + for (MapMarker marker : markers) { + if (marker.history) { + historyMarkers.add(marker); + } + } + return historyMarkers; + } + + public List getMarkers() { + return markers; + } + + public void setMarkers(List markers) { + this.markers = markers; } public long getCreationDate() { @@ -889,5 +1035,71 @@ public class MapMarkersHelper { public void setCreationDate(long creationDate) { this.creationDate = creationDate; } + + public ShowHideHistoryButton getShowHideHistoryButton() { + return showHideHistoryButton; + } + + public void setShowHideHistoryButton(ShowHideHistoryButton showHideHistoryButton) { + this.showHideHistoryButton = showHideHistoryButton; + } + + public int getColor() { + return color; + } + + public void setColor(int color) { + this.color = color; + } + + public boolean isDisabled() { + return disabled; + } + + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } + } + + public static class ShowHideHistoryButton { + private boolean showHistory; + private MapMarkersGroup group; + + public boolean isShowHistory() { + return showHistory; + } + + public void setShowHistory(boolean showHistory) { + this.showHistory = showHistory; + } + + public MapMarkersGroup getMapMarkerGroup() { + return group; + } + + public void setMarkerGroup(MapMarkersGroup group) { + this.group = group; + } + } + + public static class GroupHeader { + private int iconRes; + private MapMarkersGroup group; + + public int getIconRes() { + return iconRes; + } + + public void setIconRes(int iconRes) { + this.iconRes = iconRes; + } + + public MapMarkersGroup getGroup() { + return group; + } + + public void setGroup(MapMarkersGroup group) { + this.group = group; + } } } diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index d07a2b40d4..ad96b84af6 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -38,6 +38,7 @@ import android.location.LocationManager; import android.os.Build; import android.os.Bundle; import android.provider.Settings; +import android.support.annotation.Nullable; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AlertDialog; import android.util.Log; @@ -69,11 +70,14 @@ public class OsmAndLocationProvider implements SensorEventListener { private static final int GPS_DIST_REQUEST = 0; private static final int NOT_SWITCH_TO_NETWORK_WHEN_GPS_LOST_MS = 12000; - private static final long STALE_LOCATION_TIMEOUT = 1000 * 60 * 60; // 60 minutes - public static final long STALE_LOCATION_TIMEOUT_FOR_ICON = 1000 * 60 * 5; // 5 minutes + private static final long STALE_LOCATION_TIMEOUT = 1000 * 60 * 5; // 5 minutes + private static final long STALE_LOCATION_TIMEOUT_FOR_UI = 1000 * 60 * 15; // 15 minutes private static final int UPDATES_BEFORE_CHECK_LOCATION = 100; private int updatesCounter; + private int updatesCounterUi; + + private net.osmand.Location cachedLocation; private long lastTimeGPSLocationFixed = 0; private boolean gpsSignalLost; @@ -877,6 +881,26 @@ public class OsmAndLocationProvider implements SensorEventListener { return location; } + @Nullable + public net.osmand.Location getLastStaleKnownLocation() { + if (updatesCounterUi == 0) { + net.osmand.Location newLoc = getLastKnownLocation(); + if (newLoc == null) { + if (cachedLocation != null && System.currentTimeMillis() - cachedLocation.getTime() > STALE_LOCATION_TIMEOUT_FOR_UI) { + cachedLocation = null; + } + } else { + cachedLocation = newLoc; + } + } + if (updatesCounterUi == UPDATES_BEFORE_CHECK_LOCATION) { + updatesCounterUi = 0; + } else { + updatesCounterUi++; + } + return cachedLocation; + } + public void showNavigationInfo(TargetPoint pointToNavigate, Context uiActivity) { getNavigationInfo().show(pointToNavigate, getHeading(), uiActivity); diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index b533b3857e..34216131d9 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -713,6 +713,9 @@ public class OsmandSettings { public final CommonPreference RULER_MODE = new EnumIntPreference<>("ruler_mode", RulerMode.FIRST, RulerMode.values()).makeGlobal(); + public final CommonPreference SHOW_LINES_TO_FIRST_MARKERS = new BooleanPreference("show_lines_to_first_markers", false).makeGlobal(); + public final CommonPreference SHOW_ARROWS_TO_FIRST_MARKERS = new BooleanPreference("show_arrows_to_first_markers", false).makeGlobal(); + public final CommonPreference USE_MAPILLARY_FILTER = new BooleanPreference("use_mapillary_filters", false).makeGlobal(); public final CommonPreference MAPILLARY_FILTER_USER_KEY = new StringPreference("mapillary_filter_user_key", "").makeGlobal(); public final CommonPreference MAPILLARY_FILTER_USERNAME = new StringPreference("mapillary_filter_username", "").makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 5b8dddc12d..300df40f42 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -24,9 +24,9 @@ import net.osmand.plus.OsmandSettings.MapMarkersOrderByMode; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashboardOnMap; -import net.osmand.plus.mapmarkers.ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener; import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener; import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment.OrderByFragmentListener; +import net.osmand.plus.mapmarkers.ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener; import java.util.ArrayList; import java.util.Arrays; @@ -44,12 +44,14 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm private LockableViewPager viewPager; private TextView orderByModeTitle; + private boolean lightTheme; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); OsmandApplication app = getMyApplication(); - boolean isLightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; - int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; + lightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; + int themeId = lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; setStyle(STYLE_NO_FRAME, themeId); } @@ -95,6 +97,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container); Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.map_markers_toolbar); + if (!lightTheme) { + toolbar.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.actionbar_dark_color)); + } orderByModeTitle = toolbar.findViewById(R.id.order_by_mode_text); setOrderByMode(getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.get()); @@ -121,6 +126,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm viewPager.setAdapter(adapter); BottomNavigationView bottomNav = mainView.findViewById(R.id.map_markers_bottom_navigation); + if (!lightTheme) { + bottomNav.setItemIconTintList(ContextCompat.getColorStateList(getContext(), R.color.bottom_navigation_color_selector_dark)); + bottomNav.setItemTextColor(ContextCompat.getColorStateList(getContext(), R.color.bottom_navigation_color_selector_dark)); + } bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java index 6ef6cbd9fa..c340f1dff7 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java @@ -22,43 +22,45 @@ import net.osmand.util.MapUtils; public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassListener, OsmAndLocationListener { - public static final String TAG = "MapMarkersGroupsFragment"; + public static final String TAG = "MapMarkersGroupsFragment"; - private MapMarkersGroupsAdapter adapter; + private MapMarkersGroupsAdapter adapter; private Float heading; private Location location; private boolean locationUpdateStarted; - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - final RecyclerView recyclerView = new RecyclerView(getContext()); - recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - final MapActivity mapActivity = (MapActivity) getActivity(); + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + final RecyclerView recyclerView = new RecyclerView(getContext()); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + final MapActivity mapActivity = (MapActivity) getActivity(); - adapter = new MapMarkersGroupsAdapter(mapActivity); + adapter = new MapMarkersGroupsAdapter(mapActivity); recyclerView.setAdapter(adapter); - return recyclerView; - } + return recyclerView; + } - void updateAdapter() { - if (adapter != null) { - adapter.notifyDataSetChanged(); - } - } + void updateAdapter() { + if (adapter != null) { + adapter.createDisplayGroups(); + adapter.updateShowDirectionMarkers(); + adapter.notifyDataSetChanged(); + } + } - @Override - public void onResume() { - super.onResume(); - adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity())); - startLocationUpdate(); - } + @Override + public void onResume() { + super.onResume(); + adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity())); + startLocationUpdate(); + } - @Override - public void onPause() { - super.onPause(); - stopLocationUpdate(); - } + @Override + public void onPause() { + super.onPause(); + stopLocationUpdate(); + } void startLocationUpdate() { OsmandApplication app = getMyApplication(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java index 48063aef11..3e26135a91 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java @@ -1,7 +1,9 @@ package net.osmand.plus.mapmarkers; +import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; @@ -43,7 +45,7 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment } ((ImageView) mainView.findViewById(R.id.sort_by_icon)) - .setImageDrawable(getIcon(R.drawable.ic_sort_waypoint_dark, R.color.on_map_icon_color)); + .setImageDrawable(getContentIcon(R.drawable.ic_sort_waypoint_dark)); OsmandSettings.MapMarkersMode mode = getMyApplication().getSettings().MAP_MARKERS_MODE.get(); ImageView showDirectionIcon = (ImageView) mainView.findViewById(R.id.show_direction_icon); int imageResId = 0; @@ -55,16 +57,16 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment imageResId = R.drawable.ic_action_device_widget; break; } - showDirectionIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); + showDirectionIcon.setBackgroundDrawable(getContentIcon(R.drawable.ic_action_device_top)); if (imageResId != 0) { showDirectionIcon.setImageDrawable(getIcon(imageResId, R.color.dashboard_blue)); } ((ImageView) mainView.findViewById(R.id.build_route_icon)) - .setImageDrawable(getIcon(R.drawable.map_directions, R.color.on_map_icon_color)); + .setImageDrawable(getContentIcon(R.drawable.map_directions)); ((ImageView) mainView.findViewById(R.id.save_as_new_track_icon)) - .setImageDrawable(getIcon(R.drawable.ic_action_polygom_dark, R.color.on_map_icon_color)); + .setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark)); ((ImageView) mainView.findViewById(R.id.move_all_to_history_icon)) - .setImageDrawable(getIcon(R.drawable.ic_action_history2, R.color.on_map_icon_color)); + .setImageDrawable(getContentIcon(R.drawable.ic_action_history2)); ((TextView) mainView.findViewById(R.id.show_direction_text_view)).setText(getMyApplication().getSettings().MAP_MARKERS_MODE.get().toHumanString(getActivity())); @@ -171,6 +173,11 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment } } + @Override + protected Drawable getContentIcon(@DrawableRes int id) { + return getIcon(id, getMyApplication().getSettings().isLightContent() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark); + } + interface MarkerOptionsFragmentListener { void sortByOnClick(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java index 168f9e281a..cd044f5ff6 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java @@ -1,7 +1,9 @@ package net.osmand.plus.mapmarkers; +import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; @@ -121,6 +123,11 @@ public class OrderByBottomSheetDialogFragment extends BottomSheetDialogFragment } } + @Override + protected Drawable getContentIcon(@DrawableRes int id) { + return getIcon(id, settings.isLightContent() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark); + } + private View.OnClickListener orderByModeOnClickListener = new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java index 43148b2a13..a7d10456db 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java @@ -1,7 +1,10 @@ package net.osmand.plus.mapmarkers; +import android.app.Activity; +import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.view.ContextThemeWrapper; @@ -12,6 +15,7 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; +import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.RadioButton; import android.widget.TextView; @@ -19,6 +23,7 @@ import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; @@ -38,8 +43,9 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final OsmandSettings settings = getMyApplication().getSettings(); portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - night = !getMyApplication().getSettings().isLightContent(); + night = !settings.isLightContent(); final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_show_direction_bottom_sheet_dialog, container); @@ -47,7 +53,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); } - OsmandSettings.MapMarkersMode mode = getMyApplication().getSettings().MAP_MARKERS_MODE.get(); + OsmandSettings.MapMarkersMode mode = settings.MAP_MARKERS_MODE.get(); highlightSelectedItem(mode, true); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { @@ -84,16 +90,44 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra ((TextView) mainView.findViewById(R.id.show_direction_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); } + final CompoundButton showArrowsToggle = (CompoundButton) mainView.findViewById(R.id.show_arrows_switch); + showArrowsToggle.setChecked(settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()); + mainView.findViewById(R.id.show_arrows_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + boolean newState = !settings.SHOW_ARROWS_TO_FIRST_MARKERS.get(); + settings.SHOW_ARROWS_TO_FIRST_MARKERS.set(newState); + showArrowsToggle.setChecked(newState); + if (getMapActivity() != null) { + getMapActivity().refreshMap(); + } + } + }); + + final CompoundButton showLinesToggle = (CompoundButton) mainView.findViewById(R.id.show_guide_line_switch); + showLinesToggle.setChecked(settings.SHOW_LINES_TO_FIRST_MARKERS.get()); + mainView.findViewById(R.id.show_guide_line_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + boolean newState = !settings.SHOW_LINES_TO_FIRST_MARKERS.get(); + settings.SHOW_LINES_TO_FIRST_MARKERS.set(newState); + showLinesToggle.setChecked(newState); + if (getMapActivity() != null) { + getMapActivity().refreshMap(); + } + } + }); + ImageView topBarIcon = (ImageView) mainView.findViewById(R.id.top_bar_icon); topBarIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); - topBarIcon.setImageDrawable(getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue)); + topBarIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_device_topbar)); ImageView widgetIcon = (ImageView) mainView.findViewById(R.id.widget_icon); widgetIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); - widgetIcon.setImageDrawable(getIcon(R.drawable.ic_action_device_widget, R.color.dashboard_blue)); + widgetIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_device_widget)); ImageView noneIcon = (ImageView) mainView.findViewById(R.id.none_icon); - noneIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); + noneIcon.setBackgroundDrawable(getContentIcon(R.drawable.ic_action_device_top)); mainView.findViewById(R.id.top_bar_row).setOnClickListener(showDirectionOnClickListener); mainView.findViewById(R.id.widget_row).setOnClickListener(showDirectionOnClickListener); @@ -157,6 +191,19 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra } } + @Override + protected Drawable getContentIcon(@DrawableRes int id) { + return getIcon(id, night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); + } + + private MapActivity getMapActivity() { + Activity activity = getActivity(); + if (activity != null) { + return (MapActivity) activity; + } + return null; + } + private void highlightSelectedItem(OsmandSettings.MapMarkersMode mode, boolean check) { int iconBgColor = check ? R.color.dashboard_blue : R.color.on_map_icon_color; int iconColor = check ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java index 8f6f7ddcc4..d8748a8786 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java @@ -1,20 +1,26 @@ package net.osmand.plus.mapmarkers.adapters; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.SwitchCompat; import android.view.View; import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.TextView; import net.osmand.plus.R; public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder { - final TextView date; - final ImageButton optionsBtn; + final ImageView icon; + final View iconSpace; + final TextView title; + final SwitchCompat disableGroupSwitch; public MapMarkerHeaderViewHolder(View itemView) { super(itemView); - date = itemView.findViewById(R.id.date_title); - optionsBtn = itemView.findViewById(R.id.date_options_button); + icon = (ImageView) itemView.findViewById(R.id.icon); + iconSpace = itemView.findViewById(R.id.icon_space); + title = (TextView) itemView.findViewById(R.id.title); + disableGroupSwitch = (SwitchCompat) itemView.findViewById(R.id.disable_group_switch); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index d531c4d1f7..de5e198d43 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -96,7 +96,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter items = new ArrayList<>(); - private boolean night; - private int screenOrientation; - private LatLon location; - private Float heading; - private boolean useCenter; + private List items = new ArrayList<>(); + private boolean night; + private int screenOrientation; + private LatLon location; + private Float heading; + private boolean useCenter; + private boolean showDirectionEnabled; + private List showDirectionMarkers; - public MapMarkersGroupsAdapter(MapActivity mapActivity) { - this.app = mapActivity.getMyApplication(); - night = !mapActivity.getMyApplication().getSettings().isLightContent(); + public MapMarkersGroupsAdapter(MapActivity mapActivity) { + this.mapActivity = mapActivity; + app = mapActivity.getMyApplication(); + night = !mapActivity.getMyApplication().getSettings().isLightContent(); + updateShowDirectionMarkers(); createDisplayGroups(); - } + } - public void createDisplayGroups() { + public void updateShowDirectionMarkers() { + showDirectionEnabled = app.getSettings().MAP_MARKERS_MODE.get() != OsmandSettings.MapMarkersMode.NONE;; + List mapMarkers = app.getMapMarkersHelper().getMapMarkers(); + int markersCount = mapMarkers.size(); + showDirectionMarkers = new ArrayList<>(mapMarkers.subList(0, markersCount > 0 ? markersCount > 1 ? 2 : 1 : 0)); + } + + public void createDisplayGroups() { items.clear(); + List groups = app.getMapMarkersHelper().getMapMarkersGroups(); + for (int i = 0; i < groups.size(); i++) { + MapMarkersGroup group = groups.get(i); + String markerGroupName = group.getName(); + if (markerGroupName == null) { + int previousDateHeader = -1; + int monthsDisplayed = 0; - List markersHistory = app.getMapMarkersHelper().getMarkersSortedByGroup(); - - int previousDateHeader = -1; - String previousNameHeader = ""; - int monthsDisplayed = 0; - - Calendar currentDateCalendar = Calendar.getInstance(); - currentDateCalendar.setTimeInMillis(System.currentTimeMillis()); - int currentDay = currentDateCalendar.get(Calendar.DAY_OF_YEAR); - int currentMonth = currentDateCalendar.get(Calendar.MONTH); - int currentYear = currentDateCalendar.get(Calendar.YEAR); - Calendar markerCalendar = Calendar.getInstance(); - for (int i = 0; i < markersHistory.size(); i++) { - MapMarker marker = markersHistory.get(i); - markerCalendar.setTimeInMillis(marker.creationDate); - int markerDay = markerCalendar.get(Calendar.DAY_OF_YEAR); - int markerMonth = markerCalendar.get(Calendar.MONTH); - int markerYear = markerCalendar.get(Calendar.YEAR); - String markerGroupName = marker.groupName; - if (markerGroupName != null && markerGroupName.equals("")) { - markerGroupName = app.getString(R.string.shared_string_favorites); - } - if (markerGroupName == null && markerYear == currentYear) { - if (markerDay == currentDay && previousDateHeader != TODAY_HEADER) { - items.add(TODAY_HEADER); - previousDateHeader = TODAY_HEADER; - } else if (markerDay == currentDay - 1 && previousDateHeader != YESTERDAY_HEADER) { - items.add(YESTERDAY_HEADER); - previousDateHeader = YESTERDAY_HEADER; - } else if (currentDay - markerDay >= 2 && currentDay - markerDay <= 8 && previousDateHeader != LAST_SEVEN_DAYS_HEADER) { - items.add(LAST_SEVEN_DAYS_HEADER); - previousDateHeader = LAST_SEVEN_DAYS_HEADER; - } else if (currentDay - markerDay > 8 && monthsDisplayed < 3 && previousDateHeader != markerMonth) { - items.add(markerMonth); - previousDateHeader = markerMonth; - monthsDisplayed += 1; - } else if (currentMonth - markerMonth >= 4 && previousDateHeader != THIS_YEAR_HEADER) { - items.add(THIS_YEAR_HEADER); - previousDateHeader = THIS_YEAR_HEADER; + Calendar currentDateCalendar = Calendar.getInstance(); + currentDateCalendar.setTimeInMillis(System.currentTimeMillis()); + int currentDay = currentDateCalendar.get(Calendar.DAY_OF_YEAR); + int currentMonth = currentDateCalendar.get(Calendar.MONTH); + int currentYear = currentDateCalendar.get(Calendar.YEAR); + Calendar markerCalendar = Calendar.getInstance(); + List groupMarkers = group.getActiveMarkers(); + for (int j = 0; j < groupMarkers.size(); j++) { + MapMarker marker = groupMarkers.get(j); + markerCalendar.setTimeInMillis(marker.creationDate); + int markerDay = markerCalendar.get(Calendar.DAY_OF_YEAR); + int markerMonth = markerCalendar.get(Calendar.MONTH); + int markerYear = markerCalendar.get(Calendar.YEAR); + if (markerYear == currentYear) { + if (markerDay == currentDay && previousDateHeader != TODAY_HEADER) { + items.add(TODAY_HEADER); + previousDateHeader = TODAY_HEADER; + } else if (markerDay == currentDay - 1 && previousDateHeader != YESTERDAY_HEADER) { + items.add(YESTERDAY_HEADER); + previousDateHeader = YESTERDAY_HEADER; + } else if (currentDay - markerDay >= 2 && currentDay - markerDay <= 8 && previousDateHeader != LAST_SEVEN_DAYS_HEADER) { + items.add(LAST_SEVEN_DAYS_HEADER); + previousDateHeader = LAST_SEVEN_DAYS_HEADER; + } else if (currentDay - markerDay > 8 && monthsDisplayed < 3 && previousDateHeader != markerMonth) { + items.add(markerMonth); + previousDateHeader = markerMonth; + monthsDisplayed += 1; + } else if (currentMonth - markerMonth >= 4 && previousDateHeader != THIS_YEAR_HEADER) { + items.add(THIS_YEAR_HEADER); + previousDateHeader = THIS_YEAR_HEADER; + } + } else if (previousDateHeader != markerYear) { + items.add(markerYear); + previousDateHeader = markerYear; + } + items.add(marker); + } + } else { + GroupHeader header = group.getGroupHeader(); + items.add(header); + ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton(); + if (showHideHistoryButton != null && showHideHistoryButton.isShowHistory()) { + items.addAll(group.getMarkers()); + } else { + items.addAll(group.getActiveMarkers()); + } + if (showHideHistoryButton != null) { + items.add(showHideHistoryButton); } - } else if (markerGroupName == null && previousDateHeader != markerYear) { - items.add(markerYear); - previousDateHeader = markerYear; - } else if (markerGroupName != null && !previousNameHeader.equals(markerGroupName)) { - items.add(markerGroupName); - previousNameHeader = markerGroupName; } - items.add(marker); } } - public void setLocation(LatLon location) { - this.location = location; - } + public void setLocation(LatLon location) { + this.location = location; + } - public void setHeading(Float heading) { - this.heading = heading; - } + public void setHeading(Float heading) { + this.heading = heading; + } - public void setUseCenter(boolean useCenter) { - this.useCenter = useCenter; - } + public void setUseCenter(boolean useCenter) { + this.useCenter = useCenter; + } - public void setScreenOrientation(int screenOrientation) { - this.screenOrientation = screenOrientation; - } + public void setScreenOrientation(int screenOrientation) { + this.screenOrientation = screenOrientation; + } - @Override - public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { if (viewType == MARKER_TYPE) { View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false); return new MapMarkerItemViewHolder(view); } else if (viewType == HEADER_TYPE) { View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_header, viewGroup, false); return new MapMarkerHeaderViewHolder(view); + } else if (viewType == SHOW_HIDE_HISTORY_TYPE) { + View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_show_hide_history, viewGroup, false); + return new MapMarkersShowHideHistoryViewHolder(view); } else { throw new IllegalArgumentException("Unsupported view type"); } - } + } - @Override - public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + @Override + public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) { IconsCache iconsCache = app.getIconsCache(); if (holder instanceof MapMarkerItemViewHolder) { final MapMarkerItemViewHolder itemViewHolder = (MapMarkerItemViewHolder) holder; final MapMarker marker = (MapMarker) getItem(position); - itemViewHolder.iconReorder.setVisibility(View.GONE); + + final boolean markerInHistory = marker.history; int color = MapMarker.getColorId(marker.colorIndex); - itemViewHolder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color)); + ImageView markerImageViewToUpdate; + int drawableResToUpdate; + final boolean markerToHighlight = showDirectionMarkers.contains(marker); + if (showDirectionEnabled && markerToHighlight) { + itemViewHolder.iconDirection.setVisibility(View.GONE); + + itemViewHolder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_arrow_marker_diretion, color)); + itemViewHolder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.list_divider_dark : R.color.markers_top_bar_background)); + itemViewHolder.title.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_white)); + itemViewHolder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_divider_color)); + itemViewHolder.optionsBtn.setBackgroundDrawable(mapActivity.getResources().getDrawable(R.drawable.marker_circle_background_on_map_with_inset)); + itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getIcon(markerInHistory ? R.drawable.ic_action_reset_to_default_dark : R.drawable.ic_action_marker_passed, R.color.color_white)); + itemViewHolder.description.setTextColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_color)); + + drawableResToUpdate = R.drawable.ic_arrow_marker_diretion; + markerImageViewToUpdate = itemViewHolder.icon; + } else { + itemViewHolder.iconDirection.setVisibility(View.VISIBLE); + + itemViewHolder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color)); + itemViewHolder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.bg_color_dark : R.color.bg_color_light)); + itemViewHolder.title.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.color_white : R.color.color_black)); + itemViewHolder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light)); + itemViewHolder.optionsBtn.setBackgroundDrawable(mapActivity.getResources().getDrawable(R.drawable.marker_circle_background_light_with_inset)); + itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(markerInHistory ? R.drawable.ic_action_reset_to_default_dark : R.drawable.ic_action_marker_passed)); + itemViewHolder.description.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.dash_search_icon_dark : R.color.icon_color)); + + drawableResToUpdate = R.drawable.ic_direction_arrow; + markerImageViewToUpdate = itemViewHolder.iconDirection; + } itemViewHolder.title.setText(marker.getName(app)); - itemViewHolder.description.setText(app.getString(R.string.passed, new SimpleDateFormat("MMM dd", Locale.getDefault()).format(new Date(marker.visitedDate)))); + if (markerInHistory) { + itemViewHolder.point.setVisibility(View.VISIBLE); + itemViewHolder.description.setVisibility(View.VISIBLE); + itemViewHolder.description.setText(app.getString(R.string.passed, new SimpleDateFormat("MMM dd", Locale.getDefault()).format(new Date(marker.visitedDate)))); + } else { + itemViewHolder.point.setVisibility(View.GONE); + itemViewHolder.description.setVisibility(View.GONE); + } - itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reset_to_default_dark)); + String markerGroupName = marker.groupName; + final MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupByName(markerGroupName); itemViewHolder.optionsBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { -// int position = itemViewHolder.getAdapterPosition(); -// if (position < 0) { -// return; -// } -// app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0); -// notifyItemRemoved(position); + int position = itemViewHolder.getAdapterPosition(); + if (position < 0) { + return; + } + if (markerInHistory) { + app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0); + if (group != null) { + ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton(); + if (showHideHistoryButton != null) { + if (group.getHistoryMarkers().size() == 0) { + items.remove(showHideHistoryButton); + group.setShowHideHistoryButton(null); + } + } + } + } else { + app.getMapMarkersHelper().moveMapMarkerToHistory(marker); + if (group != null) { + ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton(); + if (showHideHistoryButton == null) { + items.remove(marker); + showHideHistoryButton = new ShowHideHistoryButton(); + showHideHistoryButton.setShowHistory(false); + showHideHistoryButton.setMarkerGroup(group); + int index = getLastDisplayItemIndexOfGroup(group); + if (index != -1) { + items.add(index + 1, showHideHistoryButton); + group.setShowHideHistoryButton(showHideHistoryButton); + } + } else if (!showHideHistoryButton.isShowHistory()) { + items.remove(marker); + } + } + } + updateShowDirectionMarkers(); + notifyDataSetChanged(); } }); + itemViewHolder.iconReorder.setVisibility(View.GONE); itemViewHolder.flagIconLeftSpace.setVisibility(View.VISIBLE); - itemViewHolder.iconDirection.setVisibility(View.GONE); - itemViewHolder.leftPointSpace.setVisibility(View.GONE); - itemViewHolder.rightPointSpace.setVisibility(View.GONE); - if (position == getItemCount() - 1) { - itemViewHolder.bottomShadow.setVisibility(View.VISIBLE); + boolean lastItem = position == getItemCount() - 1; + if ((getItemCount() > position + 1 && getItemViewType(position + 1) == HEADER_TYPE) || lastItem) { itemViewHolder.divider.setVisibility(View.GONE); } else { - itemViewHolder.bottomShadow.setVisibility(View.GONE); itemViewHolder.divider.setVisibility(View.VISIBLE); } + itemViewHolder.bottomShadow.setVisibility(lastItem ? View.VISIBLE : View.GONE); + + LatLon markerLatLon = new LatLon(marker.getLatitude(), marker.getLongitude()); + DashLocationFragment.updateLocationView(useCenter, location, + heading, markerImageViewToUpdate, drawableResToUpdate, markerToHighlight ? color : 0, + itemViewHolder.distance, markerLatLon, + screenOrientation, app, mapActivity, true); } else if (holder instanceof MapMarkerHeaderViewHolder) { - final MapMarkerHeaderViewHolder dateViewHolder = (MapMarkerHeaderViewHolder) holder; + final MapMarkerHeaderViewHolder headerViewHolder = (MapMarkerHeaderViewHolder) holder; final Object header = getItem(position); String headerString; if (header instanceof Integer) { + headerViewHolder.icon.setVisibility(View.GONE); + headerViewHolder.iconSpace.setVisibility(View.VISIBLE); Integer dateHeader = (Integer) header; if (dateHeader == TODAY_HEADER) { headerString = app.getString(R.string.today); @@ -183,35 +290,77 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter historyMarkers = showHideHistoryButton.getMapMarkerGroup().getHistoryMarkers(); + int pos = holder.getAdapterPosition(); + if (showHistory) { + showHideHistoryButton.setShowHistory(false); + items.removeAll(historyMarkers); + } else { + showHideHistoryButton.setShowHistory(true); + items.addAll(pos, historyMarkers); + } + notifyDataSetChanged(); + } + }); } - } + } @Override public int getItemViewType(int position) { Object item = items.get(position); if (item instanceof MapMarker) { return MARKER_TYPE; - } else if (item instanceof String || item instanceof Integer) { + } else if (item instanceof GroupHeader || item instanceof Integer) { return HEADER_TYPE; + } else if (item instanceof ShowHideHistoryButton) { + return SHOW_HIDE_HISTORY_TYPE; } else { throw new IllegalArgumentException("Unsupported view type"); } } - @Override - public int getItemCount() { - return items.size(); - } + @Override + public int getItemCount() { + return items.size(); + } - public Object getItem(int position) { - return items.get(position); - } + public Object getItem(int position) { + return items.get(position); + } private String getMonth(int month) { SimpleDateFormat dateFormat = new SimpleDateFormat("LLLL", Locale.getDefault()); @@ -219,4 +368,22 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter markers = group.getActiveMarkers(); + int index = -1; + for (MapMarker marker : markers) { + int markerIndex = items.indexOf(marker); + if (markerIndex > index) { + index = markerIndex; + } + } + if (index == -1) { + GroupHeader header = group.getGroupHeader(); + if (header != null) { + index = items.indexOf(group.getGroupHeader()); + } + } + return index; + } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index bb8e4d969c..4941755174 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -160,7 +160,8 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter selectedItems = new LinkedHashSet<>(); + private LinkedHashMap> selectedItems = new LinkedHashMap<>(); private Set selectedGroups = new LinkedHashSet<>(); private ActionMode actionMode; private SearchView searchView; @@ -213,6 +214,26 @@ public class TrackPointFragment extends OsmandExpandableListFragment { return view; } + private int getSelectedItemsCount() { + int count = 0; + for (Set set : selectedItems.values()) { + if (set != null) { + count += set.size(); + } + } + return count; + } + + private Set getSelectedItems() { + Set result = new LinkedHashSet<>(); + for (Set set : selectedItems.values()) { + if (set != null) { + result.addAll(set); + } + } + return result; + } + private void addPoint(PointDescription pointDescription) { getTrackActivity().addPoint(pointDescription); } @@ -488,9 +509,10 @@ public class TrackPointFragment extends OsmandExpandableListFragment { } private void deleteItemsAction() { - if (selectedItems.size() > 0) { + int size = getSelectedItemsCount(); + if (size > 0) { AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); - b.setMessage(getString(R.string.points_delete_multiple, selectedItems.size())); + b.setMessage(getString(R.string.points_delete_multiple, size)); b.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -524,7 +546,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment { GPXFile gpx = getGpx(); SavingTrackHelper savingTrackHelper = app.getSavingTrackHelper(); if (gpx != null) { - for (GpxDisplayItem item : selectedItems) { + for (GpxDisplayItem item : getSelectedItems()) { if (gpx.showCurrentTrack) { savingTrackHelper.deletePointData(item.locationStart); } else { @@ -606,26 +628,32 @@ public class TrackPointFragment extends OsmandExpandableListFragment { } private void selectMapMarkersImpl() { - if (!selectedItems.isEmpty()) { + if (getSelectedItemsCount() > 0) { if (getSettings().USE_MAP_MARKERS.get()) { MapMarkersHelper markersHelper = app.getMapMarkersHelper(); - List points = new ArrayList<>(); - List names = new ArrayList<>(); - for(GpxDisplayItem i : selectedItems) { - if (i.locationStart != null) { - points.add(new LatLon(i.locationStart.lat, i.locationStart.lon)); - names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, i.name)); + List points = new LinkedList<>(); + List names = new LinkedList<>(); + for (Map.Entry> entry : selectedItems.entrySet()) { + if (entry.getKey() == GpxDisplayItemType.TRACK_POINTS) { + File gpx = getGpxDataItem().getFile(); + MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), + AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE); + markersHelper.addMarkersSyncGroup(syncGroup); + markersHelper.syncGroup(syncGroup); + } else { + for (GpxDisplayItem i : entry.getValue()) { + if (i.locationStart != null) { + points.add(new LatLon(i.locationStart.lat, i.locationStart.lon)); + names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, i.name)); + } + } + markersHelper.addMapMarkers(points, names, null); } } - File gpx = getGpxDataItem().getFile(); - MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), - AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE); - markersHelper.addMarkersSyncGroup(syncGroup); - markersHelper.addMapMarkers(points, names, syncGroup); MapActivity.launchMapActivityMoveToTop(getActivity()); } else { final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper(); - for (GpxDisplayItem i : selectedItems) { + for (GpxDisplayItem i : getSelectedItems()) { if (i.locationStart != null) { targetPointsHelper.navigateToPoint(new LatLon(i.locationStart.lat, i.locationStart.lon), false, targetPointsHelper.getIntermediatePoints().size() + 1, @@ -679,10 +707,10 @@ public class TrackPointFragment extends OsmandExpandableListFragment { } private void selectFavoritesImpl() { - if (!selectedItems.isEmpty()) { + if (getSelectedItemsCount() > 0) { AlertDialog.Builder b = new AlertDialog.Builder(getTrackActivity()); final EditText editText = new EditText(getTrackActivity()); - String name = selectedItems.iterator().next().group.getName(); + String name = getSelectedItems().iterator().next().group.getName(); if(name.indexOf('\n') > 0) { name = name.substring(0, name.indexOf('\n')); } @@ -700,7 +728,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment { actionMode.finish(); } FavouritesDbHelper fdb = app.getFavorites(); - for(GpxDisplayItem i : selectedItems) { + for(GpxDisplayItem i : getSelectedItems()) { if (i.locationStart != null) { FavouritePoint fp = new FavouritePoint(i.locationStart.lat, i.locationStart.lon, i.name, editText.getText().toString()); if (!Algorithms.isEmpty(i.description)) { @@ -719,8 +747,9 @@ public class TrackPointFragment extends OsmandExpandableListFragment { } private void updateSelectionMode(ActionMode m) { - if (selectedItems.size() > 0) { - m.setTitle(selectedItems.size() + " " + getMyApplication().getString(R.string.shared_string_selected_lowercase)); + int size = getSelectedItemsCount(); + if (size > 0) { + m.setTitle(size + " " + getMyApplication().getString(R.string.shared_string_selected_lowercase)); } else { m.setTitle(""); } @@ -733,9 +762,19 @@ public class TrackPointFragment extends OsmandExpandableListFragment { GpxDisplayItem item = adapter.getChild(groupPosition, childPosition); ch.setChecked(!ch.isChecked()); if (ch.isChecked()) { - selectedItems.add(item); + Set set = selectedItems.get(item.group.getType()); + if (set != null) { + set.add(item); + } else { + set = new LinkedHashSet<>(); + set.add(item); + selectedItems.put(item.group.getType(), set); + } } else { - selectedItems.remove(item); + Set set = selectedItems.get(item.group.getType()); + if (set != null) { + set.remove(item); + } } updateSelectionMode(actionMode); } else { @@ -876,13 +915,17 @@ public class TrackPointFragment extends OsmandExpandableListFragment { if (ch.isChecked()) { selectedGroups.add(groupPosition); if (items != null) { - selectedItems.addAll(items); + Set set = selectedItems.get(group.getType()); + if (set != null) { + set.addAll(items); + } else { + set = new LinkedHashSet<>(items); + selectedItems.put(group.getType(), set); + } } } else { selectedGroups.remove(groupPosition); - if (items != null) { - selectedItems.removeAll(items); - } + selectedItems.remove(group.getType()); } adapter.notifyDataSetInvalidated(); updateSelectionMode(actionMode); @@ -979,7 +1022,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment { final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item); if (selectionMode) { ch.setVisibility(View.VISIBLE); - ch.setChecked(selectedItems.contains(gpxItem)); + ch.setChecked(selectedItems.get(gpxItem.group.getType()) != null && selectedItems.get(gpxItem.group.getType()).contains(gpxItem)); row.findViewById(R.id.icon).setVisibility(View.GONE); options.setVisibility(View.GONE); ch.setOnClickListener(new View.OnClickListener() { @@ -987,9 +1030,19 @@ public class TrackPointFragment extends OsmandExpandableListFragment { @Override public void onClick(View v) { if (ch.isChecked()) { - selectedItems.add(gpxItem); + Set set = selectedItems.get(gpxItem.group.getType()); + if (set != null) { + set.add(gpxItem); + } else { + set = new LinkedHashSet<>(); + set.add(gpxItem); + selectedItems.put(gpxItem.group.getType(), set); + } } else { - selectedItems.remove(gpxItem); + Set set = selectedItems.get(gpxItem.group.getType()); + if (set != null) { + set.remove(gpxItem); + } } updateSelectionMode(actionMode); } diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 50bb769fca..88dd4bf182 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -797,7 +797,7 @@ public class MapControlsLayer extends OsmandMapLayer { private void updateMyLocation(RoutingHelper rh, boolean dialogOpened) { Location lastKnownLocation = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); - boolean enabled = lastKnownLocation != null && !isLocationOutdated(lastKnownLocation); + boolean enabled = lastKnownLocation != null; boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation(); if (!enabled) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 8107ee7ba7..556e90c20f 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -8,13 +8,9 @@ import android.graphics.Path; import android.graphics.PointF; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; -import android.os.Handler; -import android.os.Message; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; -import android.view.GestureDetector; -import android.view.MotionEvent; import net.osmand.Location; import net.osmand.data.LatLon; @@ -23,7 +19,6 @@ import net.osmand.data.QuadPoint; import net.osmand.data.RotatedTileBox; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; -import net.osmand.plus.OsmAndConstants; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; @@ -36,11 +31,12 @@ import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory; import java.util.ArrayList; import java.util.List; +import gnu.trove.list.array.TIntArrayList; + public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider, IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider { + protected static final int DIST_TO_SHOW = 80; - protected static final long USE_FINGER_LOCATION_DELAY = 1000; - private static final int MAP_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 6; private final MapActivity map; private OsmandMapTileView view; @@ -66,16 +62,14 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private Bitmap arrowToDestination; private float[] calculations = new float[2]; + private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine"); private Paint paint; private Path path; private List route = new ArrayList<>(); - private LatLon fingerLocation; - private boolean hasMoved; - private boolean moving; - private boolean useFingerLocation; - private GestureDetector longTapDetector; - private Handler handler; + private TIntArrayList tx = new TIntArrayList(); + private TIntArrayList ty = new TIntArrayList(); + private Path linePath = new Path(); private ContextMenuLayer contextMenuLayer; @@ -190,50 +184,23 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi @Override public void initLayer(OsmandMapTileView view) { this.view = view; - handler = new Handler(); initUI(); - longTapDetector = new GestureDetector(view.getContext(), new GestureDetector.OnGestureListener() { - @Override - public boolean onDown(MotionEvent e) { - return false; - } - - @Override - public void onShowPress(MotionEvent e) { - - } - - @Override - public boolean onSingleTapUp(MotionEvent e) { - return false; - } - - @Override - public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { - return false; - } - - @Override - public void onLongPress(MotionEvent e) { - cancelFingerAction(); - } - - @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - return false; - } - }); } @Override public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { - widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : null, tileBox.getZoom()); + Location myLoc = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation(); + widgetsFactory.updateInfo(myLoc == null + ? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude()), tileBox.getZoom()); + OsmandSettings settings = map.getMyApplication().getSettings(); - if (tileBox.getZoom() < 3 || !map.getMyApplication().getSettings().USE_MAP_MARKERS.get()) { + if (tileBox.getZoom() < 3 || !settings.USE_MAP_MARKERS.get()) { return; } + lineAttrs.updatePaints(view, nightMode, tileBox); + MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); if (route.size() > 0) { path.reset(); @@ -259,6 +226,30 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } List activeMapMarkers = markersHelper.getMapMarkers(); + + if (settings.SHOW_LINES_TO_FIRST_MARKERS.get() && myLoc != null) { + int locX = tileBox.getPixXFromLonNoRot(myLoc.getLongitude()); + int locY = tileBox.getPixYFromLatNoRot(myLoc.getLatitude()); + int[] colors = MapMarker.getColors(map); + for (int i = 0; i < activeMapMarkers.size() && i < 2; i++) { + MapMarker marker = activeMapMarkers.get(i); + int markerX = tileBox.getPixXFromLonNoRot(marker.getLongitude()); + int markerY = tileBox.getPixYFromLatNoRot(marker.getLatitude()); + linePath.reset(); + tx.clear(); + ty.clear(); + linePath.moveTo(locX, locY); + linePath.lineTo(markerX, markerY); + tx.add(locX); + ty.add(locY); + tx.add(markerX); + ty.add(markerY); + calculatePath(tileBox, tx, ty, linePath); + lineAttrs.paint.setColor(colors[marker.colorIndex]); + canvas.drawPath(linePath, lineAttrs.paint); + } + } + for (MapMarker marker : activeMapMarkers) { if (isLocationVisible(tileBox, marker) && !overlappedByWaypoint(marker) && !isInMotion(marker)) { @@ -273,34 +264,26 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } } - boolean show = useFingerLocation || - (map.getMyApplication().getSettings().MAP_MARKERS_MODE.get() == OsmandSettings.MapMarkersMode.WIDGETS - && map.getMyApplication().getSettings().SHOW_DESTINATION_ARROW.get()); - if (show) { - LatLon loc = fingerLocation; - if (!useFingerLocation) { - loc = tileBox.getCenterLatLon(); - } - if (loc != null) { - List mapMarkers = markersHelper.getMapMarkers(); - int i = 0; - for (MapMarker marker : mapMarkers) { - if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) { - canvas.save(); - net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(), - marker.getLatitude(), marker.getLongitude(), calculations); - float bearing = calculations[1] - 90; - float radiusBearing = DIST_TO_SHOW * tileBox.getDensity(); - final QuadPoint cp = tileBox.getCenterPixelPoint(); - canvas.rotate(bearing, cp.x, cp.y); - canvas.translate(-24 * tileBox.getDensity() + radiusBearing, -22 * tileBox.getDensity()); - canvas.drawBitmap(arrowToDestination, cp.x, cp.y, getMarkerDestPaint(marker.colorIndex)); - canvas.restore(); - } - i++; - if (i > 1) { - break; - } + if (settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()) { + LatLon loc = tileBox.getCenterLatLon(); + List mapMarkers = markersHelper.getMapMarkers(); + int i = 0; + for (MapMarker marker : mapMarkers) { + if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) { + canvas.save(); + net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(), + marker.getLatitude(), marker.getLongitude(), calculations); + float bearing = calculations[1] - 90; + float radiusBearing = DIST_TO_SHOW * tileBox.getDensity(); + final QuadPoint cp = tileBox.getCenterPixelPoint(); + canvas.rotate(bearing, cp.x, cp.y); + canvas.translate(-24 * tileBox.getDensity() + radiusBearing, -22 * tileBox.getDensity()); + canvas.drawBitmap(arrowToDestination, cp.x, cp.y, getMarkerDestPaint(marker.colorIndex)); + canvas.restore(); + } + i++; + if (i > 1) { + break; } } } @@ -354,57 +337,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi public void destroyLayer() { } - @Override - public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { - if (!longTapDetector.onTouchEvent(event)) { - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - float x = event.getX(); - float y = event.getY(); - fingerLocation = tileBox.getLatLonFromPixel(x, y); - hasMoved = false; - moving = true; - break; - - case MotionEvent.ACTION_MOVE: - if (!hasMoved) { - if (!handler.hasMessages(MAP_REFRESH_MESSAGE)) { - Message msg = Message.obtain(handler, new Runnable() { - @Override - public void run() { - handler.removeMessages(MAP_REFRESH_MESSAGE); - if (moving) { - if (!useFingerLocation) { - useFingerLocation = true; - map.refreshMap(); - } - } - } - }); - msg.what = MAP_REFRESH_MESSAGE; - handler.sendMessageDelayed(msg, USE_FINGER_LOCATION_DELAY); - } - hasMoved = true; - } - break; - - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_CANCEL: - cancelFingerAction(); - break; - } - } - return super.onTouchEvent(event, tileBox); - } - - private void cancelFingerAction() { - handler.removeMessages(MAP_REFRESH_MESSAGE); - useFingerLocation = false; - moving = false; - fingerLocation = null; - map.refreshMap(); - } - @Override public boolean drawInScreenPixels() { return false; diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index dc09eca433..0c2592cd07 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -16,13 +16,11 @@ import android.os.Build; import android.support.annotation.NonNull; import android.view.MotionEvent; -import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.data.QuadRect; import net.osmand.data.QuadTree; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ContextMenuAdapter; -import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.render.OsmandRenderer; @@ -40,8 +38,6 @@ import gnu.trove.list.array.TIntArrayList; public abstract class OsmandMapLayer { - protected static final int UPDATES_BEFORE_CHECK_LOCATION = 40; - protected List fullObjectsLatLon; protected List smallObjectsLatLon; @@ -51,22 +47,6 @@ public abstract class OsmandMapLayer { TWO_POINTERS_ZOOM_OUT } - private int updatesCounter; - private boolean locationOutdated; - - boolean isLocationOutdated(Location location) { - if (location != null && updatesCounter == 0) { - locationOutdated = System.currentTimeMillis() - location.getTime() > - OsmAndLocationProvider.STALE_LOCATION_TIMEOUT_FOR_ICON; - } - if (updatesCounter == UPDATES_BEFORE_CHECK_LOCATION) { - updatesCounter = 0; - } else { - updatesCounter++; - } - return locationOutdated; - } - public boolean isMapGestureAllowed(MapGestureType type) { return true; } diff --git a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java index f66c05713f..860b0cc58f 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java @@ -64,8 +64,7 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay aroundArea.setAntiAlias(true); locationProvider = view.getApplication().getLocationProvider(); - updateIcons(view.getSettings().getApplicationMode(), false, - isLocationOutdated(locationProvider.getLastKnownLocation())); + updateIcons(view.getSettings().getApplicationMode(), false, locationProvider.getLastKnownLocation() == null); } @Override @@ -86,9 +85,9 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay } // draw boolean nm = nightMode != null && nightMode.isNightMode(); - Location lastKnownLocation = locationProvider.getLastKnownLocation(); + Location lastKnownLocation = locationProvider.getLastStaleKnownLocation(); updateIcons(view.getSettings().getApplicationMode(), nm, - isLocationOutdated(lastKnownLocation)); + view.getApplication().getLocationProvider().getLastKnownLocation() == null); if(lastKnownLocation == null || view == null){ return; }