diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml
index 04b4b8035a..fdfd8c2bde 100644
--- a/OsmAnd/AndroidManifest.xml
+++ b/OsmAnd/AndroidManifest.xml
@@ -40,7 +40,7 @@
+ tools:overrideLibrary="com.getkeepsafe.taptargetview, studio.carbonylgroup.textfieldboxes"/>
diff --git a/OsmAnd/build.gradle b/OsmAnd/build.gradle
index 38697f2e4b..348c7b40f6 100644
--- a/OsmAnd/build.gradle
+++ b/OsmAnd/build.gradle
@@ -399,6 +399,9 @@ dependencies {
exclude group: 'com.android.support'
}
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
+ compile ("com.github.HITGIF:TextFieldBoxes:1.3.2"){
+ exclude group: 'com.android.support'
+ }
}
if(analytics) {
println "Apply GMS plugin"
diff --git a/OsmAnd/no_translate.xml b/OsmAnd/no_translate.xml
index 1e2c77f356..a55605f15a 100644
--- a/OsmAnd/no_translate.xml
+++ b/OsmAnd/no_translate.xml
@@ -32,4 +32,5 @@
Reopen
items modified
OsmAnd Unlimited
+ Markers
diff --git a/OsmAnd/res/drawable/marker_circle_background_dark_n.xml b/OsmAnd/res/drawable/marker_circle_background_dark_n.xml
new file mode 100644
index 0000000000..b7f47f5b54
--- /dev/null
+++ b/OsmAnd/res/drawable/marker_circle_background_dark_n.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/drawable/marker_circle_background_dark_n_with_inset.xml b/OsmAnd/res/drawable/marker_circle_background_dark_n_with_inset.xml
new file mode 100644
index 0000000000..ad071dcc25
--- /dev/null
+++ b/OsmAnd/res/drawable/marker_circle_background_dark_n_with_inset.xml
@@ -0,0 +1,7 @@
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/drawable/marker_circle_background_dark_with_inset.xml b/OsmAnd/res/drawable/marker_circle_background_dark_with_inset.xml
new file mode 100644
index 0000000000..84a47130c9
--- /dev/null
+++ b/OsmAnd/res/drawable/marker_circle_background_dark_with_inset.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout-land/fragment_measurement_tool.xml b/OsmAnd/res/layout-land/fragment_measurement_tool.xml
index 88782a4fb5..9a611c8672 100644
--- a/OsmAnd/res/layout-land/fragment_measurement_tool.xml
+++ b/OsmAnd/res/layout-land/fragment_measurement_tool.xml
@@ -33,11 +33,9 @@
+ android:background="?attr/selectableItemBackground">
+ android:visibility="gone"
+ tools:text="@string/add_point_after"/>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml
new file mode 100644
index 0000000000..e1a67fc667
--- /dev/null
+++ b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml
@@ -0,0 +1,152 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/fragment_map_markers_dialog.xml b/OsmAnd/res/layout/fragment_map_markers_dialog.xml
index 6bc81c6b5e..f513542ed8 100644
--- a/OsmAnd/res/layout/fragment_map_markers_dialog.xml
+++ b/OsmAnd/res/layout/fragment_map_markers_dialog.xml
@@ -5,8 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:osmand="http://schemas.android.com/tools"
- android:orientation="vertical"
- xmlns:tools="http://schemas.android.com/tools">
+ android:orientation="vertical">
-
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:gravity="center_vertical"
+ android:text="@string/map_markers"
+ android:textColor="@color/color_white"
+ osmand:typeface="@string/font_roboto_medium"
+ android:textSize="@dimen/dialog_header_text_size"/>
-
-
-
-
-
-
-
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:gravity="center_vertical"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:paddingRight="16dp"
+ android:paddingLeft="16dp"
+ android:text="@string/shared_string_options"
+ osmand:typeface="@string/font_roboto_regular"
+ android:textAllCaps="true"
+ android:textSize="@dimen/default_list_text_size"
+ android:textColor="@color/color_white"
+ android:background="?attr/selectableItemBackground"/>
diff --git a/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml
index d5fd81800e..66cfb182c6 100644
--- a/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml
+++ b/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml
@@ -97,7 +97,7 @@
android:layout_gravity="center_vertical|end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.ListItemTitle"
- android:textColor="@color/map_widget_blue_pressed"
+ tools:textColor="@color/map_widget_blue_pressed"
tools:text="Top bar"/>
@@ -110,6 +110,35 @@
android:layout_marginTop="@dimen/measurement_tool_bottom_divider_margin_top"
android:background="?attr/dashboard_divider"/>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/OsmAnd/res/layout/fragment_marker_save_as_track_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_save_as_track_bottom_sheet_dialog.xml
new file mode 100644
index 0000000000..099da8e742
--- /dev/null
+++ b/OsmAnd/res/layout/fragment_marker_save_as_track_bottom_sheet_dialog.xml
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
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 d92053dc9c..7cda4ecc40 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
@@ -182,136 +182,144 @@
android:layout_marginTop="@dimen/bottom_sheet_content_padding_small"
android:background="?attr/dashboard_divider"/>
-
+ android:layout_height="@dimen/bottom_sheet_list_item_height">
-
+
-
+
-
-
+
-
+
+
+
+
+
+ android:layout_height="@dimen/bottom_sheet_list_item_height">
-
+
-
+
-
-
+
-
+
+
+
+
+
+ android:layout_height="@dimen/bottom_sheet_list_item_height">
-
+
-
+
-
-
+
+
+
+
+
+
diff --git a/OsmAnd/res/layout/fragment_measurement_tool.xml b/OsmAnd/res/layout/fragment_measurement_tool.xml
index 6b5a3da674..2c76e6e020 100644
--- a/OsmAnd/res/layout/fragment_measurement_tool.xml
+++ b/OsmAnd/res/layout/fragment_measurement_tool.xml
@@ -29,10 +29,8 @@
+ android:layout_height="@dimen/measurement_tool_up_down_row_height"
+ android:background="?attr/selectableItemBackground">
+ android:visibility="gone"
+ tools:text="@string/add_point_after"/>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/OsmAnd/res/layout/input_coordinate_keyboard_item.xml b/OsmAnd/res/layout/input_coordinate_keyboard_item.xml
new file mode 100644
index 0000000000..34d5446a4c
--- /dev/null
+++ b/OsmAnd/res/layout/input_coordinate_keyboard_item.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml
index da0e14678c..98c29f7025 100644
--- a/OsmAnd/res/layout/map_marker_item_new.xml
+++ b/OsmAnd/res/layout/map_marker_item_new.xml
@@ -7,12 +7,18 @@
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
+
+
+ android:layout_height="wrap_content"
+ android:background="?attr/bg_color"
+ android:orientation="vertical">
+ android:layout_height="wrap_content"
+ android:visibility="gone"
+ tools:visibility="visible"/>
-
+ android:layout_height="wrap_content"
+ android:gravity="center_vertical">
+
+
@@ -92,13 +108,12 @@
+ android:layout_height="match_parent"/>
+ android:layout_height="match_parent"/>
+
-
+ tools:background="?attr/dashboard_divider"/>
-
+
diff --git a/OsmAnd/res/layout/markers_track_name_edit_text.xml b/OsmAnd/res/layout/markers_track_name_edit_text.xml
new file mode 100644
index 0000000000..336170833b
--- /dev/null
+++ b/OsmAnd/res/layout/markers_track_name_edit_text.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/markers_track_name_text_field_box.xml b/OsmAnd/res/layout/markers_track_name_text_field_box.xml
new file mode 100644
index 0000000000..1679a91832
--- /dev/null
+++ b/OsmAnd/res/layout/markers_track_name_text_field_box.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/use_location_card.xml b/OsmAnd/res/layout/use_location_card.xml
new file mode 100644
index 0000000000..7178fc7fbb
--- /dev/null
+++ b/OsmAnd/res/layout/use_location_card.xml
@@ -0,0 +1,97 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/OsmAnd/res/menu/map_markers_bottom_navigation.xml b/OsmAnd/res/menu/map_markers_bottom_navigation.xml
index 694432c5ef..f39c7fb596 100644
--- a/OsmAnd/res/menu/map_markers_bottom_navigation.xml
+++ b/OsmAnd/res/menu/map_markers_bottom_navigation.xml
@@ -12,6 +12,6 @@
diff --git a/OsmAnd/res/values-large/sizes.xml b/OsmAnd/res/values-large/sizes.xml
index c0fdc5aa68..34c65cffdd 100644
--- a/OsmAnd/res/values-large/sizes.xml
+++ b/OsmAnd/res/values-large/sizes.xml
@@ -104,6 +104,7 @@
6dp
12dp
330dp
+ 48dp
78dp
18dp
24dp
diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml
index 27bd83e435..ddca75eb3b 100644
--- a/OsmAnd/res/values/colors.xml
+++ b/OsmAnd/res/values/colors.xml
@@ -262,4 +262,6 @@
#17828a
#f2f4ff
+ #525e66
+
\ No newline at end of file
diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml
index 8ff94dfbef..2c50a73b5b 100644
--- a/OsmAnd/res/values/sizes.xml
+++ b/OsmAnd/res/values/sizes.xml
@@ -169,6 +169,7 @@
4dp
8dp
220dp
+ 48dp
52dp
12dp
16dp
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index d6c3a5b41c..6abc19baf2 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -9,6 +9,18 @@
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
-->
+ Use location
+ Add your location as first point to plan perfect route.
+ My Location
+ Finish
+ Plan route
+ Sort
+ Coordinate input
+ is saved
+ OsmAnd will save all your markers to a separate file, you can enter filename:
+ Save as track
+ Move to history
+ Group will be removed after restart
Show guide line
Show arrows on the map
Show \'Last used\' date
diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java
index 9c65a13f1b..09fef6e6c1 100644
--- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java
+++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java
@@ -4,7 +4,6 @@ import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
-import android.text.format.DateFormat;
import net.osmand.IndexConstants;
import net.osmand.data.FavouritePoint;
@@ -20,16 +19,13 @@ import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import java.io.File;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
-import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER;
@@ -230,6 +226,7 @@ public class MapMarkersHelper {
settings = ctx.getSettings();
markersDbHelper = ctx.getMapMarkersDbHelper();
startFromMyLocation = settings.ROUTE_MAP_MARKERS_START_MY_LOC.get();
+ removeDisabledGroups();
loadMarkers();
createMapMarkersGroups();
}
@@ -372,6 +369,7 @@ public class MapMarkersHelper {
}
if (!favGroup.visible) {
removeActiveMarkersFromSyncGroup(group.getId());
+ removeActiveMarkersFromGroup(group.getId());
return;
}
if (group.getColor() == -1) {
@@ -394,6 +392,7 @@ public class MapMarkersHelper {
GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
if (gpx == null) {
removeActiveMarkersFromSyncGroup(group.getId());
+ removeActiveMarkersFromGroup(group.getId());
return;
}
@@ -441,6 +440,7 @@ public class MapMarkersHelper {
if (!marker.history) {
markersDbHelper.removeMarker(marker, false);
mapMarkers.remove(marker);
+ removeMarkerFromGroup(marker);
needRefresh = true;
}
}
@@ -480,6 +480,21 @@ public class MapMarkersHelper {
}
}
+ public void addMarker(MapMarker marker, int position) {
+ if (marker != null) {
+ markersDbHelper.addMarker(marker);
+ if (marker.history) {
+ mapMarkersHistory.add(position, marker);
+ sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
+ } else {
+ mapMarkers.add(position, marker);
+ checkAndFixActiveMarkersOrderIfNeeded();
+ }
+ addMarkerToGroup(marker);
+ refresh();
+ }
+ }
+
public void restoreMarkerFromHistory(MapMarker marker, int position) {
if (marker != null) {
markersDbHelper.restoreMapMarkerFromHistory(marker);
@@ -506,12 +521,17 @@ public class MapMarkersHelper {
}
}
- public void removeMarkerFromHistory(MapMarker marker) {
+ public void removeMarker(MapMarker marker) {
if (marker != null) {
- markersDbHelper.removeMarker(marker, true);
- mapMarkersHistory.remove(marker);
- refresh();
+ boolean history = marker.history;
+ markersDbHelper.removeMarker(marker, history);
+ if (history) {
+ mapMarkersHistory.remove(marker);
+ } else {
+ mapMarkers.remove(marker);
+ }
removeMarkerFromGroup(marker);
+ refresh();
}
}
@@ -531,6 +551,18 @@ public class MapMarkersHelper {
return mapMarkersHistory;
}
+ public void deselectAllActiveMarkers() {
+ for (MapMarker m : mapMarkers) {
+ m.selected = false;
+ }
+ }
+
+ public void selectAllActiveMarkers() {
+ for (MapMarker m : mapMarkers) {
+ m.selected = true;
+ }
+ }
+
public List getSelectedMarkers() {
List list = new ArrayList<>();
for (MapMarker m : this.mapMarkers) {
@@ -610,9 +642,24 @@ public class MapMarkersHelper {
if (removeActiveMarkers) {
removeActiveMarkersFromSyncGroup(id);
}
+ MapMarkersGroup group = getMapMarkerGroupByName(id);
+ if (group != null) {
+ mapMarkersGroups.remove(group);
+ }
}
}
+ public void removeDisabledGroups() {
+ markersDbHelper.removeDisabledGroups();
+ }
+
+ public void updateGroupDisabled(String id, boolean disabled) {
+ if (id != null) {
+ markersDbHelper.updateSyncGroupDisabled(id, disabled);
+ }
+ loadMarkers();
+ }
+
public void removeActiveMarkersFromSyncGroup(String syncGroupId) {
if (syncGroupId != null) {
markersDbHelper.removeActiveMarkersFromSyncGroup(syncGroupId);
@@ -652,7 +699,7 @@ public class MapMarkersHelper {
}
if (colorIndex == -1) {
if (mapMarkers.size() > 0) {
- colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
+ colorIndex = (mapMarkers.get(0).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
} else {
colorIndex = 0;
}
@@ -672,7 +719,7 @@ public class MapMarkersHelper {
marker.history = false;
marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE;
markersDbHelper.addMarker(marker);
- mapMarkers.add(marker);
+ mapMarkers.add(0, marker);
addMarkerToGroup(marker);
checkAndFixActiveMarkersOrderIfNeeded();
}
@@ -688,7 +735,7 @@ public class MapMarkersHelper {
}
}
- public void moveMapMarker(@Nullable MapMarker marker, LatLon latLon) {
+ public void moveMapMarker(MapMarker marker, LatLon latLon) {
if (marker != null) {
LatLon point = new LatLon(latLon.getLatitude(), latLon.getLongitude());
int index = mapMarkers.indexOf(marker);
@@ -699,6 +746,7 @@ public class MapMarkersHelper {
markersDbHelper.updateMarker(marker);
checkAndFixActiveMarkersOrderIfNeeded();
refresh();
+ lookupAddress(marker);
}
}
@@ -792,13 +840,11 @@ public class MapMarkersHelper {
}
}
- public void generateGpx() {
+ public String generateGpx(String fileName) {
final File dir = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers");
if (!dir.exists()) {
dir.mkdirs();
}
- Date date = new Date();
- String fileName = DateFormat.format("yyyy-MM-dd", date).toString() + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(date);
File fout = new File(dir, fileName + ".gpx");
int ind = 1;
while (fout.exists()) {
@@ -814,6 +860,7 @@ public class MapMarkersHelper {
file.addPoint(wpt);
}
GPXUtilities.writeGpxFile(fout, file, ctx);
+ return fout.getAbsolutePath();
}
private void removeHistoryMarkersFromGroups() {
@@ -825,15 +872,36 @@ public class MapMarkersHelper {
}
}
markersGroup.setMarkers(activeMarkers);
- updateShowHideHistoryButtonInGroup(markersGroup);
+ updateGroup(markersGroup);
}
}
- private void updateShowHideHistoryButtonInGroup(MapMarkersGroup mapMarkersGroup) {
+ private void removeActiveMarkersFromGroup(String groupId) {
+ MapMarkersGroup group = getMapMarkerGroupByKey(groupId);
+ if (group != null) {
+ List markers = group.getMarkers();
+ List historyMarkers = new ArrayList<>();
+ for (MapMarker marker : markers) {
+ if (marker.history) {
+ historyMarkers.add(marker);
+ }
+ }
+ group.setMarkers(historyMarkers);
+ updateGroup(group);
+ }
+ }
+
+ public void updateGroup(MapMarkersGroup mapMarkersGroup) {
+ if (mapMarkersGroup.getMarkers().size() == 0) {
+ mapMarkersGroups.remove(mapMarkersGroup);
+ return;
+ }
int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size();
ShowHideHistoryButton showHideHistoryButton = mapMarkersGroup.getShowHideHistoryButton();
- if (showHideHistoryButton != null && historyMarkersCount == 0) {
- mapMarkersGroup.setShowHideHistoryButton(null);
+ if (showHideHistoryButton != null) {
+ if (historyMarkersCount == 0) {
+ mapMarkersGroup.setShowHideHistoryButton(null);
+ }
} else if (historyMarkersCount > 0) {
showHideHistoryButton = new ShowHideHistoryButton();
showHideHistoryButton.setShowHistory(false);
@@ -847,7 +915,7 @@ public class MapMarkersHelper {
MapMarkersGroup mapMarkersGroup = getMapMarkerGroupByName(marker.groupName);
if (mapMarkersGroup != null) {
mapMarkersGroup.getMarkers().add(marker);
- updateShowHideHistoryButtonInGroup(mapMarkersGroup);
+ updateGroup(mapMarkersGroup);
if (mapMarkersGroup.getName() == null) {
sortMarkers(mapMarkersGroup.getMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
}
@@ -861,26 +929,34 @@ public class MapMarkersHelper {
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());
+ if (marker.groupName != null) {
+ group.setName(marker.groupName);
+ group.setGroupKey(marker.groupKey);
+ MapMarkersHelper.MarkersSyncGroup syncGroup = getGroup(marker.groupKey);
+ if (syncGroup != null) {
+ group.setType(syncGroup.getType());
+ } else {
+ group.setType(MarkersSyncGroup.FAVORITES_TYPE);
+ }
+ group.setColor(MapMarker.getColorId(marker.colorIndex));
}
- group.setColor(MapMarker.getColorId(marker.colorIndex));
group.setCreationDate(marker.creationDate);
mapMarkersGroups.add(group);
+ sortGroups();
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);
+ if (group.getName() != null) {
+ 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);
+ updateGroup(group);
}
- header.setGroup(group);
- group.setGroupHeader(header);
- updateShowHideHistoryButtonInGroup(group);
}
private void removeMarkerFromGroup(MapMarker marker) {
@@ -888,7 +964,7 @@ public class MapMarkersHelper {
MapMarkersGroup mapMarkersGroup = getMapMarkerGroupByName(marker.groupName);
if (mapMarkersGroup != null) {
mapMarkersGroup.getMarkers().remove(marker);
- updateShowHideHistoryButtonInGroup(mapMarkersGroup);
+ updateGroup(mapMarkersGroup);
}
}
}
@@ -915,7 +991,17 @@ public class MapMarkersHelper {
} else {
MapMarkersGroup group = groupsMap.get(groupName);
if (group == null) {
- group = createMapMarkerGroup(marker);
+ group = new MapMarkersGroup();
+ group.setName(marker.groupName);
+ group.setGroupKey(marker.groupKey);
+ MapMarkersHelper.MarkersSyncGroup syncGroup = getGroup(marker.groupKey);
+ if (syncGroup != null) {
+ group.setType(syncGroup.getType());
+ } else {
+ group.setType(MarkersSyncGroup.FAVORITES_TYPE);
+ }
+ group.setColor(MapMarker.getColorId(marker.colorIndex));
+ group.setCreationDate(marker.creationDate);
groupsMap.put(groupName, group);
} else {
long markerCreationDate = marker.creationDate;
@@ -927,33 +1013,44 @@ public class MapMarkersHelper {
}
}
mapMarkersGroups = new ArrayList<>(groupsMap.values());
- sortGroups(mapMarkersGroups);
+ if (noGroup != null) {
+ mapMarkersGroups.add(noGroup);
+ }
+ sortGroups();
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;
+ private void sortGroups() {
+ if (mapMarkersGroups.size() > 0) {
+ MapMarkersGroup noGroup = null;
+ for (int i = 0; i < mapMarkersGroups.size(); i++) {
+ MapMarkersGroup group = mapMarkersGroups.get(i);
+ if (group.getName() == null) {
+ sortMarkers(group.getMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
+ noGroup = mapMarkersGroups.remove(i);
}
}
- });
+ Collections.sort(mapMarkersGroups, 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;
+ }
+ }
+ });
+ if (noGroup != null) {
+ mapMarkersGroups.add(0, noGroup);
+ }
+ }
}
public MapMarkersGroup getMapMarkerGroupByName(String name) {
@@ -966,8 +1063,19 @@ public class MapMarkersHelper {
return null;
}
+ public MapMarkersGroup getMapMarkerGroupByKey(String key) {
+ for (MapMarkersGroup group : mapMarkersGroups) {
+ if ((key == null && group.getGroupKey() == null)
+ || (group.getGroupKey() != null && group.getGroupKey().equals(key))) {
+ return group;
+ }
+ }
+ return null;
+ }
+
public static class MapMarkersGroup {
private String name;
+ private String groupKey;
private GroupHeader header;
private int type = -1;
private List markers = new ArrayList<>();
@@ -984,6 +1092,14 @@ public class MapMarkersHelper {
this.name = name;
}
+ public String getGroupKey() {
+ return groupKey;
+ }
+
+ public void setGroupKey(String groupKey) {
+ this.groupKey = groupKey;
+ }
+
public GroupHeader getGroupHeader() {
return header;
}
diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java
index 34216131d9..cacd826bae 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java
@@ -3158,12 +3158,17 @@ public class OsmandSettings {
}
public enum MapMarkersOrderByMode {
+ CUSTOM,
DISTANCE_DESC,
DISTANCE_ASC,
NAME,
DATE_ADDED_DESC,
DATE_ADDED_ASC;
+ public boolean isCustom() {
+ return this == CUSTOM;
+ }
+
public boolean isDistanceDescending() {
return this == DISTANCE_DESC;
}
diff --git a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java
index 9bb7048e14..a2af444f0f 100644
--- a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java
@@ -187,14 +187,8 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
addToMarkersView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- List points = new ArrayList<>(group.points.size());
- List names = new ArrayList<>(group.points.size());
- for (FavouritePoint fp : group.points) {
- points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
- names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
- }
markersHelper.addMarkersSyncGroup(syncGroup);
- markersHelper.addMapMarkers(points, names, syncGroup);
+ markersHelper.syncGroup(syncGroup);
dismiss();
MapActivity.launchMapActivityMoveToTop(getActivity());
}
diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java
index 3f19935655..481ba3154f 100644
--- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java
+++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java
@@ -411,14 +411,16 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
new MarkersSyncGroup(favGr.name, favGr.name, MarkersSyncGroup.FAVORITES_TYPE, favGr.color);
if (entry.getValue().size() == favGr.points.size()) {
markersHelper.addMarkersSyncGroup(syncGr);
+ markersHelper.syncGroup(syncGr);
+ } else {
+ for (FavouritePoint fp : entry.getValue()) {
+ points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
+ names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
+ }
+ markersHelper.addMapMarkers(points, names, syncGr);
+ points.clear();
+ names.clear();
}
- for (FavouritePoint fp : entry.getValue()) {
- points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
- names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
- }
- markersHelper.addMapMarkers(points, names, syncGr);
- points.clear();
- names.clear();
}
MapActivity.launchMapActivityMoveToTop(getActivity());
} else {
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
index 1d0f79320b..a20d730996 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
@@ -59,6 +59,7 @@ import net.osmand.plus.AppInitializer;
import net.osmand.plus.AppInitializer.AppInitializeListener;
import net.osmand.plus.AppInitializer.InitEvents;
import net.osmand.plus.ApplicationMode;
+import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener;
@@ -97,6 +98,8 @@ import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenuFragment;
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu;
+import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
+import net.osmand.plus.mapmarkers.PlanRouteFragment;
import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.measurementtool.NewGpxData;
@@ -503,6 +506,12 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return;
}
}
+ if (getPlanRouteFragment() != null) {
+ if (getPlanRouteFragment().quit(true)) {
+ MapMarkersDialogFragment.showInstance(this);
+ }
+ return;
+ }
if (getMeasurementToolFragment() != null) {
getMeasurementToolFragment().quit(true);
return;
@@ -1724,6 +1733,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return fragment!= null && !fragment.isDetached() && !fragment.isRemoving() ? (QuickSearchDialogFragment) fragment : null;
}
+ public PlanRouteFragment getPlanRouteFragment() {
+ Fragment fragment = getSupportFragmentManager().findFragmentByTag(PlanRouteFragment.TAG);
+ return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (PlanRouteFragment) fragment : null;
+ }
+
public MeasurementToolFragment getMeasurementToolFragment() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(MeasurementToolFragment.TAG);
return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (MeasurementToolFragment) fragment : null;
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java
new file mode 100644
index 0000000000..e3cc6b2e56
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java
@@ -0,0 +1,148 @@
+package net.osmand.plus.mapmarkers;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v4.app.DialogFragment;
+import android.support.v4.content.ContextCompat;
+import android.support.v7.widget.Toolbar;
+import android.text.InputType;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.widget.ArrayAdapter;
+import android.widget.EditText;
+import android.widget.GridView;
+import android.widget.TextView;
+
+import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.OsmandSettings;
+import net.osmand.plus.R;
+import net.osmand.plus.activities.MapActivity;
+
+public class CoordinateInputDialogFragment extends DialogFragment {
+
+ public static final String TAG = "CoordinateInputDialogFragment";
+
+ private boolean lightTheme;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ OsmandApplication app = getMyApplication();
+ lightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
+ int themeId = lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
+ setStyle(STYLE_NO_FRAME, themeId);
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ final View mainView = inflater.inflate(R.layout.fragment_coordinate_input_dialog, container);
+ final MapActivity mapActivity = getMapActivity();
+
+ Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.coordinate_input_toolbar);
+ if (!lightTheme) {
+ toolbar.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.actionbar_dark_color));
+ }
+
+ toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back));
+ toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ dismiss();
+ }
+ });
+ final View optionsButton = mainView.findViewById(R.id.options_button);
+ optionsButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+
+ }
+ });
+
+ final EditText latitudeEditText = (EditText) mainView.findViewById(R.id.latitude_edit_text);
+ final EditText longitudeEditText = (EditText) mainView.findViewById(R.id.longitude_edit_text);
+ final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text);
+
+ View.OnTouchListener editTextOnTouchListener = new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View view, MotionEvent motionEvent) {
+ EditText editText = null;
+ switch (view.getId()) {
+ case R.id.latitude_edit_text:
+ editText = latitudeEditText;
+ break;
+ case R.id.longitude_edit_text:
+ editText = longitudeEditText;
+ break;
+ case R.id.name_edit_text:
+ editText = nameEditText;
+ break;
+ }
+ if (editText != null) {
+ editText.requestFocus();
+ }
+ return true;
+ }
+ };
+
+ latitudeEditText.setOnTouchListener(editTextOnTouchListener);
+ longitudeEditText.setOnTouchListener(editTextOnTouchListener);
+ nameEditText.setOnTouchListener(editTextOnTouchListener);
+
+ String[] keyboardItems = new String[] { "1", "2", "3",
+ "4", "5", "6",
+ "7", "8", "9",
+ getString(R.string.shared_string_delete), "0", getString(R.string.shared_string_clear) };
+ GridView keyboardGrid = (GridView) mainView.findViewById(R.id.keyboard_grid_view);
+ KeyboardAdapter keyboardAdapter = new KeyboardAdapter(mapActivity, keyboardItems);
+ keyboardGrid.setAdapter(keyboardAdapter);
+
+ return mainView;
+ }
+
+ private MapActivity getMapActivity() {
+ return (MapActivity) getActivity();
+ }
+
+ private OsmandApplication getMyApplication() {
+ return (OsmandApplication) getActivity().getApplication();
+ }
+
+ public static boolean showInstance(@NonNull MapActivity mapActivity) {
+ try {
+ if (mapActivity.isActivityDestroyed()) {
+ return false;
+ }
+ CoordinateInputDialogFragment fragment = new CoordinateInputDialogFragment();
+ fragment.show(mapActivity.getSupportFragmentManager(), TAG);
+ return true;
+ } catch (RuntimeException e) {
+ return false;
+ }
+ }
+
+ private class KeyboardAdapter extends ArrayAdapter {
+
+ KeyboardAdapter(@NonNull Context context, String[] items) {
+ super(context, 0, items);
+ }
+
+ @NonNull
+ @Override
+ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
+ if (convertView == null) {
+ convertView = LayoutInflater.from(getContext()).inflate(R.layout.input_coordinate_keyboard_item, parent, false);
+ }
+
+ ((TextView) convertView.findViewById(R.id.keyboard_item)).setText(getItem(position));
+
+ return convertView;
+ }
+ }
+
+}
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java
index 2736766568..82fdef7d74 100644
--- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java
@@ -11,6 +11,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.plus.MapMarkersHelper.MapMarker;
@@ -32,16 +33,20 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
private Location location;
private Float heading;
private boolean locationUpdateStarted;
+ private boolean compassUpdateAllowed = true;
@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();
+ boolean isSmartphone = getResources().getConfiguration().smallestScreenWidthDp < 600;
+ recyclerView.setPadding(0, 0, 0, AndroidUtils.dpToPx(mapActivity, isSmartphone ? 72 : 108));
+ recyclerView.setClipToPadding(false);
+ recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
adapter = new MapMarkersActiveAdapter(mapActivity);
- final ItemTouchHelper touchHelper = new ItemTouchHelper(new MapMarkersItemTouchHelperCallback(adapter));
+ final ItemTouchHelper touchHelper = new ItemTouchHelper(new MapMarkersItemTouchHelperCallback(mapActivity, adapter));
touchHelper.attachToRecyclerView(recyclerView);
adapter.setAdapterListener(new MapMarkersActiveAdapterListener() {
@@ -60,22 +65,36 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
@Override
public void onDragStarted(RecyclerView.ViewHolder holder) {
+ compassUpdateAllowed = false;
fromPosition = holder.getAdapterPosition();
touchHelper.startDrag(holder);
}
@Override
- public void onDragEnded(RecyclerView.ViewHolder holder) {
+ public void onDragOrSwipeEnded(RecyclerView.ViewHolder holder) {
+ compassUpdateAllowed = true;
toPosition = holder.getAdapterPosition();
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
hideSnackbar();
mapActivity.getMyApplication().getMapMarkersHelper().checkAndFixActiveMarkersOrderIfNeeded();
adapter.notifyDataSetChanged();
+ mapActivity.getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM);
}
}
+
+ @Override
+ public void onSwipeStarted() {
+ compassUpdateAllowed = false;
+ }
});
recyclerView.setAdapter(adapter);
-
+ recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
+ super.onScrollStateChanged(recyclerView, newState);
+ compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE;
+ }
+ });
return recyclerView;
}
@@ -143,6 +162,9 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
}
private void updateLocationUi() {
+ if (!compassUpdateAllowed) {
+ return;
+ }
final MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null && adapter != null) {
mapActivity.getMyApplication().runInUIThread(new Runnable() {
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java
index e9dcb209fb..490c78da22 100644
--- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java
@@ -21,7 +21,7 @@ import java.util.Random;
public class MapMarkersDbHelper {
- private static final int DB_VERSION = 7;
+ private static final int DB_VERSION = 9;
public static final String DB_NAME = "map_markers_db";
private static final String MARKERS_TABLE_NAME = "map_markers";
@@ -36,6 +36,7 @@ public class MapMarkersDbHelper {
private static final String MARKERS_COL_GROUP_KEY = "group_key";
private static final String MARKERS_COL_COLOR = "marker_color";
private static final String MARKERS_COL_NEXT_KEY = "marker_next_key";
+ private static final String MARKERS_COL_DISABLED = "marker_disabled";
private static final String MARKERS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " +
MARKERS_TABLE_NAME + " (" +
@@ -49,7 +50,8 @@ public class MapMarkersDbHelper {
MARKERS_COL_GROUP_NAME + " TEXT, " +
MARKERS_COL_GROUP_KEY + " TEXT, " +
MARKERS_COL_COLOR + " int, " +
- MARKERS_COL_NEXT_KEY + " TEXT);";
+ MARKERS_COL_NEXT_KEY + " TEXT, " +
+ MARKERS_COL_DISABLED + " int);";
private static final String MARKERS_TABLE_SELECT = "SELECT " +
MARKERS_COL_ID + ", " +
@@ -62,19 +64,22 @@ public class MapMarkersDbHelper {
MARKERS_COL_GROUP_NAME + ", " +
MARKERS_COL_GROUP_KEY + ", " +
MARKERS_COL_COLOR + ", " +
- MARKERS_COL_NEXT_KEY +
+ MARKERS_COL_NEXT_KEY + ", " +
+ MARKERS_COL_DISABLED +
" FROM " + MARKERS_TABLE_NAME;
private static final String GROUPS_TABLE_NAME = "map_markers_groups";
private static final String GROUPS_COL_ID = "group_id";
private static final String GROUPS_COL_NAME = "group_name";
private static final String GROUPS_COL_TYPE = "group_type";
+ private static final String GROUPS_COL_DISABLED = "group_disabled";
private static final String GROUPS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " +
GROUPS_TABLE_NAME + " (" +
GROUPS_COL_ID + " TEXT PRIMARY KEY, " +
GROUPS_COL_NAME + " TEXT, " +
- GROUPS_COL_TYPE + " int);";
+ GROUPS_COL_TYPE + " int, " +
+ GROUPS_COL_DISABLED + " int);"; // 1 = true, 0 = false
private static final String GROUPS_TABLE_SELECT = "SELECT " +
GROUPS_COL_ID + ", " +
@@ -117,10 +122,18 @@ public class MapMarkersDbHelper {
}
private void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) {
- // When the DB_VERSION will increase from 7, DROP TABLE must be removed. Existing markers should not be deleted.
- db.execSQL("DROP TABLE IF EXISTS " + MARKERS_TABLE_NAME);
- db.execSQL("DROP TABLE IF EXISTS " + GROUPS_TABLE_NAME);
- onCreate(db);
+ if (oldVersion < 8) {
+ db.execSQL("ALTER TABLE " + MARKERS_TABLE_NAME + " ADD " + MARKERS_COL_DISABLED + " int");
+ db.execSQL("ALTER TABLE " + GROUPS_TABLE_NAME + " ADD " + GROUPS_COL_DISABLED + " int");
+ }
+ if (oldVersion < 9) {
+ db.execSQL("UPDATE " + GROUPS_TABLE_NAME +
+ " SET " + GROUPS_COL_DISABLED + " = ? " +
+ "WHERE " + GROUPS_COL_DISABLED + " IS NULL", new Object[]{0});
+ db.execSQL("UPDATE " + MARKERS_TABLE_NAME +
+ " SET " + MARKERS_COL_DISABLED + " = ? " +
+ "WHERE " + MARKERS_COL_DISABLED + " IS NULL", new Object[]{0});
+ }
}
private void saveExistingMarkersToDb() {
@@ -158,7 +171,7 @@ public class MapMarkersDbHelper {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
- db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?, ?)", new Object[]{id, name, type});
+ db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?, ?, ?)", new Object[]{id, name, type, 0});
} finally {
db.close();
}
@@ -235,6 +248,34 @@ public class MapMarkersDbHelper {
}
}
+ public void updateSyncGroupDisabled(String id, boolean disabled) {
+ SQLiteConnection db = openConnection(false);
+ if (db != null) {
+ try {
+ db.execSQL("UPDATE " + GROUPS_TABLE_NAME +
+ " SET " + GROUPS_COL_DISABLED + " = ? " +
+ "WHERE " + GROUPS_COL_ID + " = ?", new Object[]{disabled ? 1 : 0, id});
+ db.execSQL("UPDATE " + MARKERS_TABLE_NAME +
+ " SET " + MARKERS_COL_DISABLED + " = ? " +
+ "WHERE " + MARKERS_COL_GROUP_KEY + " = ?", new Object[]{disabled ? 1 : 0, id});
+ } finally {
+ db.close();
+ }
+ }
+ }
+
+ public void removeDisabledGroups() {
+ SQLiteConnection db = openConnection(false);
+ if (db != null) {
+ try {
+ db.execSQL("DELETE FROM " + GROUPS_TABLE_NAME + " WHERE " + GROUPS_COL_DISABLED + " = ? ", new Object[]{1});
+ db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_DISABLED + " = ? ", new Object[]{1});
+ } finally {
+ db.close();
+ }
+ }
+ }
+
public void addMarker(MapMarker marker) {
addMarker(marker, false);
}
@@ -278,10 +319,10 @@ public class MapMarkersDbHelper {
"WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.id, TAIL_NEXT_VALUE});
}
- db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
new Object[]{marker.id, marker.getLatitude(), marker.getLongitude(), descr, active,
currentTime, visited, marker.groupName, marker.groupKey, marker.colorIndex,
- marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE});
+ marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE, 0});
}
public List getMarkersFromGroup(MarkersSyncGroup group) {
@@ -328,8 +369,8 @@ public class MapMarkersDbHelper {
SQLiteConnection db = openConnection(true);
if (db != null) {
try {
- SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ?",
- new String[]{String.valueOf(1)});
+ SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ? " + "AND " + MARKERS_COL_DISABLED + " = ?",
+ new String[]{String.valueOf(1), String.valueOf(0)});
if (query.moveToFirst()) {
do {
MapMarker marker = readItem(query);
@@ -469,8 +510,8 @@ public class MapMarkersDbHelper {
SQLiteConnection db = openConnection(true);
if (db != null) {
try {
- SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ?",
- new String[]{String.valueOf(0)});
+ SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ACTIVE + " = ? " + "AND " + MARKERS_COL_DISABLED + " = ?",
+ new String[]{String.valueOf(0), String.valueOf(0)});
if (query.moveToFirst()) {
do {
markers.add(readItem(query));
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java
index 300df40f42..81985824b0 100644
--- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java
@@ -1,5 +1,6 @@
package net.osmand.plus.mapmarkers;
+import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -23,9 +24,10 @@ import net.osmand.plus.OsmandSettings;
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.activities.TrackActivity;
import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener;
import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment.OrderByFragmentListener;
+import net.osmand.plus.mapmarkers.SaveAsTrackBottomSheetDialogFragment.MarkerSaveAsTrackFragmentListener;
import net.osmand.plus.mapmarkers.ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener;
import java.util.ArrayList;
@@ -42,7 +44,6 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
private Snackbar snackbar;
private LockableViewPager viewPager;
- private TextView orderByModeTitle;
private boolean lightTheme;
@@ -93,6 +94,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
if (orderByFragment != null) {
((OrderByBottomSheetDialogFragment) orderByFragment).setListener(createOrderByFragmentListener());
}
+ Fragment saveAsTrackFragment = fragmentManager.findFragmentByTag(SaveAsTrackBottomSheetDialogFragment.TAG);
+ if (saveAsTrackFragment != null) {
+ ((SaveAsTrackBottomSheetDialogFragment) saveAsTrackFragment).setListener(createSaveAsTrackFragmentListener());
+ }
View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container);
@@ -100,7 +105,6 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
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());
toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back));
@@ -139,8 +143,8 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
if (viewPager.getCurrentItem() != 0) {
activeFragment.updateAdapter();
historyFragment.hideSnackbar();
+ groupsFragment.hideSnackbar();
}
- orderByModeTitle.setVisibility(View.VISIBLE);
viewPager.setCurrentItem(0);
optionsButton.setVisibility(View.VISIBLE);
return true;
@@ -151,7 +155,6 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
activeFragment.hideSnackbar();
historyFragment.hideSnackbar();
}
- orderByModeTitle.setVisibility(View.GONE);
viewPager.setCurrentItem(1);
optionsButton.setVisibility(View.GONE);
return true;
@@ -159,9 +162,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
activeFragment.stopLocationUpdate();
if (viewPager.getCurrentItem() != 2) {
historyFragment.updateAdapter();
+ groupsFragment.hideSnackbar();
activeFragment.hideSnackbar();
}
- orderByModeTitle.setVisibility(View.GONE);
viewPager.setCurrentItem(2);
optionsButton.setVisibility(View.GONE);
return true;
@@ -196,15 +199,22 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
fragment.show(mapActivity.getSupportFragmentManager(), ShowDirectionBottomSheetDialogFragment.TAG);
}
+ @Override
+ public void coordinateInputOnClick() {
+ CoordinateInputDialogFragment.showInstance(mapActivity);
+ }
+
@Override
public void buildRouteOnClick() {
- mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAP_MARKERS_SELECTION);
+ PlanRouteFragment.showInstance(mapActivity.getSupportFragmentManager());
dismiss();
}
@Override
public void saveAsNewTrackOnClick() {
- mapActivity.getMyApplication().getMapMarkersHelper().generateGpx();
+ SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment();
+ fragment.setListener(createSaveAsTrackFragmentListener());
+ fragment.show(mapActivity.getSupportFragmentManager(), SaveAsTrackBottomSheetDialogFragment.TAG);
}
@Override
@@ -243,6 +253,33 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
};
}
+ private MarkerSaveAsTrackFragmentListener createSaveAsTrackFragmentListener() {
+ return new MarkerSaveAsTrackFragmentListener() {
+
+ final MapActivity mapActivity = getMapActivity();
+
+ @Override
+ public void saveGpx(final String fileName) {
+ final String gpxPath = mapActivity.getMyApplication().getMapMarkersHelper().generateGpx(fileName);
+ snackbar = Snackbar.make(viewPager, fileName + " " + getString(R.string.is_saved) + ".", Snackbar.LENGTH_LONG)
+ .setAction(R.string.shared_string_show, new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent intent = new Intent(mapActivity, getMyApplication().getAppCustomization().getTrackActivity());
+ intent.putExtra(TrackActivity.TRACK_FILE_NAME, gpxPath);
+ intent.putExtra(TrackActivity.OPEN_POINTS_TAB, true);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ startActivity(intent);
+ }
+ });
+ View snackBarView = snackbar.getView();
+ TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action);
+ tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark));
+ snackbar.show();
+ }
+ };
+ }
+
private OrderByFragmentListener createOrderByFragmentListener() {
return new OrderByFragmentListener() {
@Override
@@ -253,21 +290,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
}
private void setOrderByMode(MapMarkersOrderByMode orderByMode) {
- String modeStr = "";
- if (orderByMode.isDistanceDescending()) {
- modeStr = getString(R.string.distance) + " (" + getString(R.string.descendingly) + ")";
- } else if (orderByMode.isDistanceAscending()) {
- modeStr = getString(R.string.distance) + " (" + getString(R.string.ascendingly) + ")";
- } else if (orderByMode.isName()) {
- modeStr = getString(R.string.shared_string_name);
- } else if (orderByMode.isDateAddedDescending()) {
- modeStr = getString(R.string.date_added) + " (" + getString(R.string.descendingly) + ")";
- } else {
- modeStr = getString(R.string.date_added) + " (" + getString(R.string.ascendingly) + ")";
+ if (orderByMode != MapMarkersOrderByMode.CUSTOM) {
+ getMyApplication().getMapMarkersHelper().orderMarkers(orderByMode);
+ activeFragment.updateAdapter();
}
- orderByModeTitle.setText(modeStr);
- getMyApplication().getMapMarkersHelper().orderMarkers(orderByMode);
- activeFragment.updateAdapter();
}
private MapActivity getMapActivity() {
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java
index c340f1dff7..2c3c93a870 100644
--- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java
@@ -1,22 +1,38 @@
package net.osmand.plus.mapmarkers;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
+import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.Nullable;
+import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
+import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.TextView;
+import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.data.LatLon;
+import net.osmand.plus.MapMarkersHelper;
+import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.dashboard.DashLocationFragment;
+import net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder;
import net.osmand.plus.mapmarkers.adapters.MapMarkersGroupsAdapter;
import net.osmand.util.MapUtils;
@@ -28,13 +44,158 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
private Float heading;
private Location location;
private boolean locationUpdateStarted;
+ private Paint backgroundPaint = new Paint();
+ private Paint iconPaint = new Paint();
+ private Paint textPaint = new Paint();
+ private Snackbar snackbar;
+ private boolean compassUpdateAllowed = true;
@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();
+ final boolean night = !mapActivity.getMyApplication().getSettings().isLightContent();
+ final RecyclerView recyclerView = new RecyclerView(getContext());
+ boolean isSmartphone = getResources().getConfiguration().smallestScreenWidthDp < 600;
+ recyclerView.setPadding(0, 0, 0, AndroidUtils.dpToPx(mapActivity, isSmartphone ? 72 : 108));
+ recyclerView.setClipToPadding(false);
+ recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
+
+ backgroundPaint.setColor(ContextCompat.getColor(getActivity(), night ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light));
+ backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE);
+ backgroundPaint.setAntiAlias(true);
+ iconPaint.setAntiAlias(true);
+ iconPaint.setFilterBitmap(true);
+ iconPaint.setDither(true);
+ textPaint.setTextSize(getResources().getDimension(R.dimen.default_desc_text_size));
+ textPaint.setFakeBoldText(true);
+ textPaint.setAntiAlias(true);
+
+ final String delStr = getString(R.string.shared_string_delete).toUpperCase();
+ final String moveToHistoryStr = getString(R.string.move_to_history).toUpperCase();
+ final Rect bounds = new Rect();
+
+ textPaint.getTextBounds(delStr, 0, delStr.length(), bounds);
+ final int delStrWidth = bounds.width();
+ final int textHeight = bounds.height();
+
+ ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
+ private float marginSides = getResources().getDimension(R.dimen.list_content_padding);
+ private Bitmap deleteBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_delete_dark);
+ private Bitmap historyBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_history);
+ private boolean iconHidden;
+
+ @Override
+ public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
+ boolean markerViewHolder = viewHolder instanceof MapMarkerItemViewHolder;
+ int pos = viewHolder.getAdapterPosition();
+ if (markerViewHolder && pos != -1) {
+ MapMarker marker = (MapMarker) adapter.getItem(pos);
+ if (marker.history) {
+ return ItemTouchHelper.LEFT;
+ } else {
+ return ItemTouchHelper.RIGHT;
+ }
+ } else {
+ return 0;
+ }
+ }
+
+ @Override
+ public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
+ return false;
+ }
+
+ @Override
+ public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
+ if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && viewHolder instanceof MapMarkerItemViewHolder) {
+ if (!iconHidden && isCurrentlyActive) {
+ ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.GONE);
+ compassUpdateAllowed = false;
+ iconHidden = true;
+ }
+ View itemView = viewHolder.itemView;
+ int colorIcon;
+ int colorText;
+ if (Math.abs(dX) > itemView.getWidth() / 2) {
+ colorIcon = R.color.map_widget_blue;
+ colorText = R.color.map_widget_blue;
+ } else {
+ colorIcon = night ? 0 : R.color.icon_color;
+ colorText = R.color.dashboard_subheader_text_light;
+ }
+ if (colorIcon != 0) {
+ iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getActivity(), colorIcon), PorterDuff.Mode.SRC_IN));
+ }
+ textPaint.setColor(ContextCompat.getColor(getActivity(), colorText));
+ float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2;
+ if (dX > 0) {
+ c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint);
+ float iconMarginTop = ((float) itemView.getHeight() - (float) historyBitmap.getHeight()) / 2;
+ c.drawBitmap(historyBitmap, itemView.getLeft() + marginSides, itemView.getTop() + iconMarginTop, iconPaint);
+ c.drawText(moveToHistoryStr, itemView.getLeft() + 2 * marginSides + historyBitmap.getWidth(),
+ itemView.getTop() + textMarginTop + textHeight, textPaint);
+ } else {
+ c.drawRect(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), backgroundPaint);
+ float iconMarginTop = ((float) itemView.getHeight() - (float) deleteBitmap.getHeight()) / 2;
+ c.drawBitmap(deleteBitmap, itemView.getRight() - deleteBitmap.getWidth() - marginSides, itemView.getTop() + iconMarginTop, iconPaint);
+ c.drawText(delStr, itemView.getRight() - deleteBitmap.getWidth() - 2 * marginSides - delStrWidth,
+ itemView.getTop() + textMarginTop + textHeight, textPaint);
+ }
+ }
+ super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
+ }
+
+ @Override
+ public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
+ if (viewHolder instanceof MapMarkerItemViewHolder) {
+ ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.VISIBLE);
+ iconHidden = false;
+ compassUpdateAllowed = true;
+ }
+ super.clearView(recyclerView, viewHolder);
+ }
+
+ @Override
+ public void onSwiped(RecyclerView.ViewHolder viewHolder, final int direction) {
+ final int pos = viewHolder.getAdapterPosition();
+ Object item = adapter.getItem(pos);
+ if (item instanceof MapMarker) {
+ final MapMarker marker = (MapMarker) item;
+ int snackbarStringRes;
+ if (direction == ItemTouchHelper.RIGHT) {
+ mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory((MapMarker) item);
+ MapMarkersHelper.MapMarkersGroup group = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkerGroupByName(marker.groupName);
+ if (group != null) {
+ mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
+ }
+ snackbarStringRes = R.string.marker_moved_to_history;
+ } else {
+ mapActivity.getMyApplication().getMapMarkersHelper().removeMarker((MapMarker) item);
+ snackbarStringRes = R.string.item_removed;
+ }
+ updateAdapter();
+ snackbar = Snackbar.make(viewHolder.itemView, snackbarStringRes, Snackbar.LENGTH_LONG)
+ .setAction(R.string.shared_string_undo, new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (direction == ItemTouchHelper.RIGHT) {
+ mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
+ } else {
+ mapActivity.getMyApplication().getMapMarkersHelper().addMarker(marker);
+ }
+ updateAdapter();
+ }
+ });
+ View snackBarView = snackbar.getView();
+ TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action);
+ tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark));
+ snackbar.show();
+ }
+ }
+ };
+ ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
+ itemTouchHelper.attachToRecyclerView(recyclerView);
adapter = new MapMarkersGroupsAdapter(mapActivity);
recyclerView.setAdapter(adapter);
@@ -83,6 +244,15 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
}
}
+ void hideSnackbar() {
+ if (adapter != null) {
+ adapter.hideSnackbar();
+ }
+ if (snackbar != null && snackbar.isShown()) {
+ snackbar.dismiss();
+ }
+ }
+
@Override
public void updateLocation(Location location) {
boolean newLocation = this.location == null && location != null;
@@ -116,6 +286,9 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
}
private void updateLocationUi() {
+ if (!compassUpdateAllowed) {
+ return;
+ }
final MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null && adapter != null) {
mapActivity.getMyApplication().runInUIThread(new Runnable() {
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java
index 37aaa9d326..686ef6e9c5 100644
--- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java
@@ -20,6 +20,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
+import net.osmand.AndroidUtils;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication;
@@ -74,6 +75,9 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
}
final RecyclerView recyclerView = new RecyclerView(getContext());
+ boolean isSmartphone = getResources().getConfiguration().smallestScreenWidthDp < 600;
+ recyclerView.setPadding(0, 0, 0, AndroidUtils.dpToPx(mapActivity, isSmartphone ? 72 : 108));
+ recyclerView.setClipToPadding(false);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
@@ -152,7 +156,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
app.getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0);
snackbarStringRes = R.string.marker_moved_to_active;
} else {
- app.getMapMarkersHelper().removeMarkerFromHistory((MapMarker) item);
+ app.getMapMarkersHelper().removeMarker((MapMarker) item);
snackbarStringRes = R.string.item_removed;
}
adapter.notifyItemRemoved(pos);
@@ -208,6 +212,9 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
if (snackbar != null && snackbar.isShown()) {
snackbar.dismiss();
}
+ if (adapter != null) {
+ adapter.hideSnackbar();
+ }
}
private HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener createHistoryMarkerMenuListener() {
@@ -225,7 +232,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
public void onDeleteMarker(int pos) {
Object item = adapter.getItem(pos);
if (item instanceof MapMarker) {
- app.getMapMarkersHelper().removeMarkerFromHistory((MapMarker) item);
+ app.getMapMarkersHelper().removeMarker((MapMarker) item);
adapter.notifyItemRemoved(pos);
}
}
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java
index 3e26135a91..6b7923a1cf 100644
--- a/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java
@@ -5,6 +5,7 @@ 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;
import android.view.LayoutInflater;
import android.view.View;
@@ -18,6 +19,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;
@@ -35,8 +37,9 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ MapActivity mapActivity = (MapActivity) getActivity();
portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
- boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
+ boolean nightMode = !getMyApplication().getSettings().isLightContent();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_options_bottom_sheet_dialog, container);
@@ -61,6 +64,8 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
if (imageResId != 0) {
showDirectionIcon.setImageDrawable(getIcon(imageResId, R.color.dashboard_blue));
}
+ ((ImageView) mainView.findViewById(R.id.coordinate_input_icon))
+ .setImageDrawable(getContentIcon(R.drawable.ic_action_coordinates_longitude));
((ImageView) mainView.findViewById(R.id.build_route_icon))
.setImageDrawable(getContentIcon(R.drawable.map_directions));
((ImageView) mainView.findViewById(R.id.save_as_new_track_icon))
@@ -68,6 +73,7 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
((ImageView) mainView.findViewById(R.id.move_all_to_history_icon))
.setImageDrawable(getContentIcon(R.drawable.ic_action_history2));
+ ((TextView) mainView.findViewById(R.id.show_direction_text_view)).setTextColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.color_dialog_buttons_dark : R.color.map_widget_blue_pressed));
((TextView) mainView.findViewById(R.id.show_direction_text_view)).setText(getMyApplication().getSettings().MAP_MARKERS_MODE.get().toHumanString(getActivity()));
mainView.findViewById(R.id.sort_by_row).setOnClickListener(new View.OnClickListener() {
@@ -88,6 +94,15 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
dismiss();
}
});
+ mainView.findViewById(R.id.coordinate_input_row).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (listener != null) {
+ listener.coordinateInputOnClick();
+ }
+ dismiss();
+ }
+ });
mainView.findViewById(R.id.build_route_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -184,6 +199,8 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
void showDirectionOnClick();
+ void coordinateInputOnClick();
+
void buildRouteOnClick();
void saveAsNewTrackOnClick();
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java
index cd044f5ff6..58b7a92e57 100644
--- a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java
@@ -58,12 +58,19 @@ public class OrderByBottomSheetDialogFragment extends BottomSheetDialogFragment
ImageView nameIcon = (ImageView) mainView.findViewById(R.id.name_icon);
nameIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_name));
- ImageView dateAddedIcon = (ImageView) mainView.findViewById(R.id.date_added_icon);
- dateAddedIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_date));
+ ImageView dateAddedAscIcon = (ImageView) mainView.findViewById(R.id.date_added_asc_icon);
+ dateAddedAscIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_date));
+
+ ImageView dateAddedDescIcon = (ImageView) mainView.findViewById(R.id.date_added_desc_icon);
+ dateAddedDescIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_date));
+
+ ((TextView) mainView.findViewById(R.id.date_added_asc_text)).setText(getString(R.string.date_added) + " (" + getString(R.string.ascendingly) + ")");
+ ((TextView) mainView.findViewById(R.id.date_added_desc_text)).setText(getString(R.string.date_added) + " (" + getString(R.string.descendingly) + ")");
mainView.findViewById(R.id.distance_row).setOnClickListener(orderByModeOnClickListener);
mainView.findViewById(R.id.name_row).setOnClickListener(orderByModeOnClickListener);
- mainView.findViewById(R.id.date_added_row).setOnClickListener(orderByModeOnClickListener);
+ mainView.findViewById(R.id.date_added_asc_row).setOnClickListener(orderByModeOnClickListener);
+ mainView.findViewById(R.id.date_added_desc_row).setOnClickListener(orderByModeOnClickListener);
mainView.findViewById(R.id.close_row).setOnClickListener(new View.OnClickListener() {
@Override
@@ -136,21 +143,20 @@ public class OrderByBottomSheetDialogFragment extends BottomSheetDialogFragment
MapMarkersOrderByMode modeToSet;
switch (view.getId()) {
case R.id.distance_row:
- if (currentOrderByMode == MapMarkersOrderByMode.DISTANCE_DESC) {
- modeToSet = MapMarkersOrderByMode.DISTANCE_ASC;
- } else {
+ if (currentOrderByMode == MapMarkersOrderByMode.DISTANCE_ASC) {
modeToSet = MapMarkersOrderByMode.DISTANCE_DESC;
+ } else {
+ modeToSet = MapMarkersOrderByMode.DISTANCE_ASC;
}
break;
case R.id.name_row:
modeToSet = MapMarkersOrderByMode.NAME;
break;
- case R.id.date_added_row:
- if (currentOrderByMode == MapMarkersOrderByMode.DATE_ADDED_DESC) {
- modeToSet = MapMarkersOrderByMode.DATE_ADDED_ASC;
- } else {
- modeToSet = MapMarkersOrderByMode.DATE_ADDED_DESC;
- }
+ case R.id.date_added_asc_row:
+ modeToSet = MapMarkersOrderByMode.DATE_ADDED_ASC;
+ break;
+ case R.id.date_added_desc_row:
+ modeToSet = MapMarkersOrderByMode.DATE_ADDED_DESC;
break;
default:
modeToSet = currentOrderByMode;
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java
new file mode 100644
index 0000000000..e571d25b4a
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java
@@ -0,0 +1,561 @@
+package net.osmand.plus.mapmarkers;
+
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.support.annotation.DrawableRes;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.content.ContextCompat;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.helper.ItemTouchHelper;
+import android.view.ContextThemeWrapper;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import net.osmand.AndroidUtils;
+import net.osmand.Location;
+import net.osmand.data.LatLon;
+import net.osmand.plus.ApplicationMode;
+import net.osmand.plus.IconsCache;
+import net.osmand.plus.MapMarkersHelper;
+import net.osmand.plus.MapMarkersHelper.MapMarker;
+import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
+import net.osmand.plus.R;
+import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.base.MapViewTrackingUtilities;
+import net.osmand.plus.helpers.AndroidUiHelper;
+import net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback;
+import net.osmand.plus.mapmarkers.adapters.MapMarkersListAdapter;
+import net.osmand.plus.measurementtool.RecyclerViewFragment;
+import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment;
+import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment.SnapToRoadFragmentListener;
+import net.osmand.plus.views.MapMarkersLayer;
+import net.osmand.plus.views.OsmandMapTileView;
+import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
+import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
+
+import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT;
+import static net.osmand.plus.OsmandSettings.MIDDLE_TOP_CONSTANT;
+
+public class PlanRouteFragment extends Fragment implements OsmAndLocationListener {
+
+ public static final String TAG = "PlanRouteFragment";
+
+ private MapMarkersHelper markersHelper;
+ private MapMarkersListAdapter adapter;
+ private IconsCache iconsCache;
+ private PlanRouteToolbarController toolbarController;
+ private ApplicationMode appMode;
+ private int previousMapPosition;
+ private int selectedCount = 0;
+
+ private Location location;
+ private boolean locationUpdateStarted;
+
+ private boolean nightMode;
+ private boolean portrait;
+ private boolean markersListOpened;
+ private boolean wasCollapseButtonVisible;
+
+ private View mainView;
+ private RecyclerView markersRv;
+ private ImageView upDownIconIv;
+ private TextView distanceTv;
+ private TextView timeTv;
+
+ @Nullable
+ @Override
+ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ final MapActivity mapActivity = getMapActivity();
+ markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
+
+ // Handling screen rotation
+ FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
+ Fragment snapToRoadFragment = fragmentManager.findFragmentByTag(SnapToRoadBottomSheetDialogFragment.TAG);
+ if (snapToRoadFragment != null) {
+ ((SnapToRoadBottomSheetDialogFragment) snapToRoadFragment).setListener(createSnapToRoadFragmentListener());
+ }
+ // If rotate the screen from landscape to portrait when the list of markers is displayed then
+ // the RecyclerViewFragment will exist without view. This is necessary to remove it.
+ if (!portrait) {
+ hideMarkersListFragment();
+ }
+
+ iconsCache = mapActivity.getMyApplication().getIconsCache();
+ nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
+ final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
+ final int backgroundColor = ContextCompat.getColor(mapActivity,
+ nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
+ portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
+
+ View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_plan_route, null);
+
+ mainView = view.findViewById(R.id.main_view);
+ AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
+
+ distanceTv = (TextView) mainView.findViewById(R.id.markers_distance_text_view);
+ timeTv = (TextView) mainView.findViewById(R.id.markers_time_text_view);
+
+ enterPlanRouteMode();
+
+ View markersListContainer = mainView.findViewById(R.id.markers_list_container);
+ if (portrait && markersListContainer != null) {
+ markersListContainer.setBackgroundColor(backgroundColor);
+ }
+
+ upDownIconIv = (ImageView) mainView.findViewById(R.id.up_down_icon);
+ upDownIconIv.setImageDrawable(getContentIcon(R.drawable.ic_action_arrow_up));
+ ((ImageView) mainView.findViewById(R.id.sort_icon)).setImageDrawable(getContentIcon(R.drawable.ic_sort_waypoint_dark));
+
+ mainView.findViewById(R.id.up_down_row).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (!markersListOpened) {
+ showMarkersList();
+ } else {
+ hideMarkersList();
+ }
+ }
+ });
+
+ mainView.findViewById(R.id.select_all_button).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ int activeMarkersCount = markersHelper.getMapMarkers().size();
+ if (selectedCount == activeMarkersCount) {
+ markersHelper.deselectAllActiveMarkers();
+ selectedCount = 0;
+ } else {
+ markersHelper.selectAllActiveMarkers();
+ selectedCount = activeMarkersCount;
+ }
+ adapter.notifyDataSetChanged();
+ updateSelectButton();
+ }
+ });
+
+ mainView.findViewById(R.id.sort_button).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Toast.makeText(mapActivity, "Sort", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Toast.makeText(mapActivity, "Save", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ toolbarController = new PlanRouteToolbarController();
+ toolbarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
+ toolbarController.setTitle(getString(R.string.plan_route));
+ toolbarController.setOnBackButtonClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ quit(false);
+ }
+ });
+ mapActivity.showTopToolbar(toolbarController);
+
+ if (portrait) {
+ markersRv = mainView.findViewById(R.id.markers_recycler_view);
+ } else {
+ markersRv = new RecyclerView(mapActivity);
+ }
+
+ adapter = new MapMarkersListAdapter(mapActivity);
+ final ItemTouchHelper touchHelper = new ItemTouchHelper(new MapMarkersItemTouchHelperCallback(adapter));
+ touchHelper.attachToRecyclerView(markersRv);
+ adapter.setAdapterListener(new MapMarkersListAdapter.MapMarkersListAdapterListener() {
+
+ private int fromPosition;
+ private int toPosition;
+
+ @Override
+ public void onItemClick(View view) {
+ int pos = markersRv.getChildAdapterPosition(view);
+ MapMarker marker = adapter.getItem(pos);
+ selectedCount = marker.selected ? selectedCount - 1 : selectedCount + 1;
+ marker.selected = !marker.selected;
+ adapter.notifyItemChanged(pos);
+ updateSelectButton();
+ }
+
+ @Override
+ public void onDragStarted(RecyclerView.ViewHolder holder) {
+ fromPosition = holder.getAdapterPosition();
+ touchHelper.startDrag(holder);
+ }
+
+ @Override
+ public void onDragEnded(RecyclerView.ViewHolder holder) {
+ toPosition = holder.getAdapterPosition();
+ if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
+ mapActivity.getMyApplication().getMapMarkersHelper().checkAndFixActiveMarkersOrderIfNeeded();
+ adapter.notifyDataSetChanged();
+ }
+ }
+ });
+ boolean isSmartphone = getResources().getConfiguration().smallestScreenWidthDp < 600;
+ markersRv.setPadding(0, 0, 0, AndroidUtils.dpToPx(mapActivity, isSmartphone ? 72 : 108));
+ markersRv.setClipToPadding(false);
+ markersRv.setLayoutManager(new LinearLayoutManager(getContext()));
+ markersRv.setAdapter(adapter);
+
+ return view;
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ startLocationUpdate();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ stopLocationUpdate();
+ }
+
+ @Override
+ public void onDestroyView() {
+ super.onDestroyView();
+ exitPlanRouteMode();
+ if (markersListOpened) {
+ hideMarkersList();
+ }
+ }
+
+ @Override
+ public void updateLocation(Location location) {
+ boolean newLocation = this.location == null && location != null;
+ boolean locationChanged = this.location != null && location != null
+ && this.location.getLatitude() != location.getLatitude()
+ && this.location.getLongitude() != location.getLongitude();
+ if (newLocation || locationChanged) {
+ this.location = location;
+ updateLocationUi();
+ }
+ }
+
+ private MapActivity getMapActivity() {
+ return (MapActivity) getActivity();
+ }
+
+ private MapMarkersLayer getMapMarkersLayer() {
+ MapActivity mapActivity = getMapActivity();
+ if (mapActivity != null) {
+ return mapActivity.getMapLayers().getMapMarkersLayer();
+ }
+ return null;
+ }
+
+ private Drawable getContentIcon(@DrawableRes int id) {
+ return iconsCache.getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.icon_color);
+ }
+
+ private Drawable getActiveIcon(@DrawableRes int id) {
+ return iconsCache.getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance);
+ }
+
+ private SnapToRoadFragmentListener createSnapToRoadFragmentListener() {
+ return new SnapToRoadFragmentListener() {
+ @Override
+ public void onDestroyView(boolean snapToRoadEnabled) {
+
+ }
+
+ @Override
+ public void onApplicationModeItemClick(ApplicationMode mode) {
+ appMode = mode;
+ setupAppModesBtn();
+ }
+ };
+ }
+
+ private void enterPlanRouteMode() {
+ final MapActivity mapActivity = getMapActivity();
+ MapMarkersLayer markersLayer = getMapMarkersLayer();
+ if (mapActivity != null && markersLayer != null) {
+ markersLayer.setInPlanRouteMode(true);
+ mapActivity.disableDrawer();
+
+ mark(portrait ? View.INVISIBLE : View.GONE,
+ R.id.map_left_widgets_panel,
+ R.id.map_right_widgets_panel,
+ R.id.map_center_info);
+ mark(View.GONE,
+ R.id.map_route_info_button,
+ R.id.map_menu_button,
+ R.id.map_compass_button,
+ R.id.map_layers_button,
+ R.id.map_search_button,
+ R.id.map_quick_actions_button);
+
+ View collapseButton = mapActivity.findViewById(R.id.map_collapse_button);
+ if (collapseButton != null && collapseButton.getVisibility() == View.VISIBLE) {
+ wasCollapseButtonVisible = true;
+ collapseButton.setVisibility(View.INVISIBLE);
+ } else {
+ wasCollapseButtonVisible = false;
+ }
+
+ if (appMode == null) {
+ appMode = mapActivity.getMyApplication().getSettings().getApplicationMode();
+ }
+ setupAppModesBtn();
+
+ mapActivity.refreshMap();
+ updateText();
+ updateSelectButton();
+ }
+ }
+
+ private void setupAppModesBtn() {
+ final MapActivity mapActivity = getMapActivity();
+ if (mapActivity != null && appMode != null) {
+ final ImageButton appModesBtn = (ImageButton) mapActivity.findViewById(R.id.snap_to_road_image_button);
+ appModesBtn.setBackgroundResource(nightMode ? R.drawable.btn_circle_night : R.drawable.btn_circle);
+ appModesBtn.setImageDrawable(getActiveIcon(appMode.getSmallIconDark()));
+ appModesBtn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ SnapToRoadBottomSheetDialogFragment fragment = new SnapToRoadBottomSheetDialogFragment();
+ fragment.setListener(createSnapToRoadFragmentListener());
+ fragment.show(mapActivity.getSupportFragmentManager(), SnapToRoadBottomSheetDialogFragment.TAG);
+ }
+ });
+ appModesBtn.setVisibility(View.VISIBLE);
+ }
+ }
+
+ private void exitPlanRouteMode() {
+ MapActivity mapActivity = getMapActivity();
+ MapMarkersLayer markersLayer = getMapMarkersLayer();
+ if (mapActivity != null && markersLayer != null) {
+ markersLayer.setInPlanRouteMode(false);
+ mapActivity.enableDrawer();
+ if (toolbarController != null) {
+ mapActivity.hideTopToolbar(toolbarController);
+ }
+
+ mark(View.VISIBLE,
+ R.id.map_left_widgets_panel,
+ R.id.map_right_widgets_panel,
+ R.id.map_center_info,
+ R.id.map_route_info_button,
+ R.id.map_menu_button,
+ R.id.map_compass_button,
+ R.id.map_layers_button,
+ R.id.map_search_button,
+ R.id.map_quick_actions_button);
+
+ View collapseButton = mapActivity.findViewById(R.id.map_collapse_button);
+ if (collapseButton != null && wasCollapseButtonVisible) {
+ collapseButton.setVisibility(View.VISIBLE);
+ }
+
+ mapActivity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.GONE);
+ mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE);
+
+ mapActivity.refreshMap();
+ }
+ }
+
+ private void updateText() {
+ distanceTv.setText("1.39 km,");
+ timeTv.setText("~ 45 min.");
+ }
+
+ private void updateSelectButton() {
+ if (selectedCount == markersHelper.getMapMarkers().size()) {
+ ((TextView) mainView.findViewById(R.id.select_all_button)).setText(getString(R.string.shared_string_deselect_all));
+ } else {
+ ((TextView) mainView.findViewById(R.id.select_all_button)).setText(getString(R.string.shared_string_select_all));
+ }
+ }
+
+
+ private void updateLocationUi() {
+ final MapActivity mapActivity = (MapActivity) getActivity();
+ if (mapActivity != null && adapter != null) {
+ mapActivity.getMyApplication().runInUIThread(new Runnable() {
+ @Override
+ public void run() {
+ if (location == null) {
+ location = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
+ }
+ MapViewTrackingUtilities utilities = mapActivity.getMapViewTrackingUtilities();
+ boolean useCenter = !(utilities.isMapLinkedToLocation() && location != null);
+
+ adapter.setUseCenter(useCenter);
+ adapter.setLocation(useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude()));
+ adapter.notifyDataSetChanged();
+ }
+ });
+ }
+ }
+
+ private void mark(int status, int... widgets) {
+ MapActivity mapActivity = getMapActivity();
+ if (mapActivity != null) {
+ for (int widget : widgets) {
+ View v = mapActivity.findViewById(widget);
+ if (v != null) {
+ v.setVisibility(status);
+ }
+ }
+ }
+ }
+
+ private void showMarkersList() {
+ MapActivity mapActivity = getMapActivity();
+ MapMarkersLayer markersLayer = getMapMarkersLayer();
+ if (mapActivity != null && markersLayer != null) {
+ markersListOpened = true;
+ markersLayer.setMarkersListOpened(true);
+ upDownIconIv.setImageDrawable(getContentIcon(R.drawable.ic_action_arrow_down));
+ View listContainer = mainView.findViewById(R.id.markers_list_container);
+ if (portrait && listContainer != null) {
+ listContainer.setVisibility(View.VISIBLE);
+ } else {
+ showMarkersListFragment();
+ }
+ OsmandMapTileView tileView = mapActivity.getMapView();
+ previousMapPosition = tileView.getMapPosition();
+ if (portrait) {
+ tileView.setMapPosition(MIDDLE_TOP_CONSTANT);
+ } else {
+ tileView.setMapPosition(LANDSCAPE_MIDDLE_RIGHT_CONSTANT);
+ }
+ mapActivity.refreshMap();
+ }
+ }
+
+ private void hideMarkersList() {
+ MapActivity mapActivity = getMapActivity();
+ MapMarkersLayer markersLayer = getMapMarkersLayer();
+ if (mapActivity != null && markersLayer != null) {
+ markersListOpened = false;
+ markersLayer.setMarkersListOpened(false);
+ upDownIconIv.setImageDrawable(getContentIcon(R.drawable.ic_action_arrow_up));
+ View listContainer = mainView.findViewById(R.id.markers_list_container);
+ if (portrait && listContainer != null) {
+ listContainer.setVisibility(View.GONE);
+ } else {
+ hideMarkersListFragment();
+ }
+ mapActivity.getMapView().setMapPosition(previousMapPosition);
+ mapActivity.refreshMap();
+ }
+ }
+
+ private void showMarkersListFragment() {
+ MapActivity mapActivity = getMapActivity();
+ if (mapActivity != null) {
+ View upDownRow = mainView.findViewById(R.id.up_down_row);
+ int screenHeight = AndroidUtils.getScreenHeight(mapActivity) - AndroidUtils.getStatusBarHeight(mapActivity);
+ RecyclerViewFragment fragment = new RecyclerViewFragment();
+ fragment.setRecyclerView(markersRv);
+ fragment.setWidth(upDownRow.getWidth());
+ fragment.setHeight(screenHeight - upDownRow.getHeight());
+ mapActivity.getSupportFragmentManager().beginTransaction()
+ .add(R.id.fragmentContainer, fragment, RecyclerViewFragment.TAG)
+ .commitAllowingStateLoss();
+ }
+ }
+
+ private void hideMarkersListFragment() {
+ MapActivity mapActivity = getMapActivity();
+ if (mapActivity != null) {
+ try {
+ FragmentManager manager = mapActivity.getSupportFragmentManager();
+ Fragment fragment = manager.findFragmentByTag(RecyclerViewFragment.TAG);
+ if (fragment != null) {
+ manager.beginTransaction().remove(fragment).commitNowAllowingStateLoss();
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+
+ private void startLocationUpdate() {
+ MapActivity mapActivity = getMapActivity();
+ if (mapActivity != null && !locationUpdateStarted) {
+ locationUpdateStarted = true;
+ mapActivity.getMyApplication().getLocationProvider().addLocationListener(this);
+ updateLocationUi();
+ }
+ }
+
+ private void stopLocationUpdate() {
+ MapActivity mapActivity = getMapActivity();
+ if (mapActivity != null && locationUpdateStarted) {
+ locationUpdateStarted = false;
+ mapActivity.getMyApplication().getLocationProvider().removeLocationListener(this);
+ }
+ }
+
+ public boolean quit(boolean hideMarkersListFirst) {
+ if (markersListOpened && hideMarkersListFirst) {
+ hideMarkersList();
+ return false;
+ } else {
+ dismiss(getMapActivity());
+ return true;
+ }
+ }
+
+ private void dismiss(MapActivity activity) {
+ if (markersListOpened) {
+ hideMarkersList();
+ }
+ markersHelper.deselectAllActiveMarkers();
+ activity.getSupportFragmentManager().beginTransaction().remove(this).commitAllowingStateLoss();
+ }
+
+ public static boolean showInstance(FragmentManager fragmentManager) {
+ try {
+ PlanRouteFragment fragment = new PlanRouteFragment();
+ fragment.setRetainInstance(true);
+ fragmentManager.beginTransaction()
+ .add(R.id.bottomFragmentContainer, fragment, PlanRouteFragment.TAG)
+ .commitAllowingStateLoss();
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ private class PlanRouteToolbarController extends TopToolbarController {
+
+ PlanRouteToolbarController() {
+ super(MapInfoWidgetsFactory.TopToolbarControllerType.MEASUREMENT_TOOL);
+ setBackBtnIconClrIds(0, 0);
+ setTitleTextClrIds(R.color.primary_text_dark, R.color.primary_text_dark);
+ setDescrTextClrIds(R.color.primary_text_dark, R.color.primary_text_dark);
+ setBgIds(R.drawable.gradient_toolbar, R.drawable.gradient_toolbar,
+ R.drawable.gradient_toolbar, R.drawable.gradient_toolbar);
+ setCloseBtnVisible(false);
+ }
+
+ @Override
+ public void updateToolbar(MapInfoWidgetsFactory.TopToolbarView view) {
+ super.updateToolbar(view);
+ View shadow = view.getShadowView();
+ if (shadow != null) {
+ shadow.setVisibility(View.GONE);
+ }
+ }
+ }
+}
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java
new file mode 100644
index 0000000000..f625f5b7e5
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java
@@ -0,0 +1,160 @@
+package net.osmand.plus.mapmarkers;
+
+import android.os.Build;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.text.format.DateFormat;
+import android.util.Log;
+import android.view.ContextThemeWrapper;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+
+import net.osmand.AndroidUtils;
+import net.osmand.IndexConstants;
+import net.osmand.plus.R;
+import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.base.BottomSheetDialogFragment;
+import net.osmand.plus.helpers.AndroidUiHelper;
+
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
+
+import static net.osmand.plus.helpers.GpxImportHelper.GPX_SUFFIX;
+
+public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragment {
+
+ public final static String TAG = "SaveAsTrackBottomSheetDialogFragment";
+
+ private boolean portrait;
+ private MarkerSaveAsTrackFragmentListener listener;
+
+ public void setListener(MarkerSaveAsTrackFragmentListener listener) {
+ this.listener = listener;
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ MapActivity mapActivity = (MapActivity) getActivity();
+ portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
+ boolean nightMode = !getMyApplication().getSettings().isLightContent();
+ final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
+
+ final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_save_as_track_bottom_sheet_dialog, container);
+ LinearLayout contentLayout = (LinearLayout) mainView.findViewById(R.id.content_linear_layout);
+ int layoutRes;
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+ layoutRes = R.layout.markers_track_name_text_field_box;
+ } else {
+ layoutRes = R.layout.markers_track_name_edit_text;
+ }
+ contentLayout.addView(getLayoutInflater().inflate(layoutRes, contentLayout, false), 2);
+ if (portrait) {
+ AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
+ }
+
+ final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers");
+ if (!dir.exists()) {
+ dir.mkdirs();
+ }
+ Date date = new Date();
+ final String suggestedName = mapActivity.getString(R.string.markers) + "_" + DateFormat.format("dd_MM_yyyy", date).toString();
+ String displayedName = suggestedName;
+ File fout = new File(dir, suggestedName + GPX_SUFFIX);
+ int ind = 1;
+ while (fout.exists()) {
+ displayedName = suggestedName + "_" + (++ind);
+ fout = new File(dir, displayedName + GPX_SUFFIX);
+ }
+ final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text);
+ nameEditText.setText(displayedName);
+ nameEditText.requestFocus();
+
+ mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (listener != null) {
+ listener.saveGpx(nameEditText.getText().toString());
+ }
+ dismiss();
+ }
+ });
+
+ mainView.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ dismiss();
+ }
+ });
+
+ final int screenHeight = AndroidUtils.getScreenHeight(getActivity());
+ final int statusBarHeight = AndroidUtils.getStatusBarHeight(getActivity());
+ final int navBarHeight = AndroidUtils.getNavBarHeight(getActivity());
+
+ mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+
+ boolean dimensSet;
+
+ @Override
+ public void onGlobalLayout() {
+ if (!dimensSet) {
+ final View scrollView = mainView.findViewById(R.id.marker_save_as_track_scroll_view);
+ int scrollViewHeight = scrollView.getHeight();
+ int dividerHeight = AndroidUtils.dpToPx(getContext(), 1);
+ int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height);
+ int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - cancelButtonHeight;
+ if (scrollViewHeight > spaceForScrollView) {
+ scrollView.getLayoutParams().height = spaceForScrollView;
+ scrollView.requestLayout();
+ }
+
+ if (!portrait) {
+ if (screenHeight - statusBarHeight - mainView.getHeight()
+ >= AndroidUtils.dpToPx(getActivity(), 8)) {
+ AndroidUtils.setBackground(getActivity(), mainView, false,
+ R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark);
+ } else {
+ AndroidUtils.setBackground(getActivity(), mainView, false,
+ R.drawable.bg_bottom_sheet_sides_landscape_light, R.drawable.bg_bottom_sheet_sides_landscape_dark);
+ }
+ }
+ dimensSet = true;
+ }
+
+ final Window window = getDialog().getWindow();
+ WindowManager.LayoutParams params = window.getAttributes();
+ params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ params.gravity = Gravity.BOTTOM;
+ window.setAttributes(params);
+ }
+ });
+
+ return mainView;
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ if (!portrait) {
+ final Window window = getDialog().getWindow();
+ WindowManager.LayoutParams params = window.getAttributes();
+ params.width = getActivity().getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width);
+ window.setAttributes(params);
+ }
+ }
+
+ interface MarkerSaveAsTrackFragmentListener {
+ void saveGpx(String fileName);
+ }
+}
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java
index a7d10456db..059dbc7557 100644
--- a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java
@@ -119,12 +119,12 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
});
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(getContentIcon(R.drawable.ic_action_device_topbar));
+ topBarIcon.setBackgroundDrawable(getContentIcon(R.drawable.ic_action_device_top));
+ topBarIcon.setImageDrawable(getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue));
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(getContentIcon(R.drawable.ic_action_device_widget));
+ widgetIcon.setBackgroundDrawable(getContentIcon(R.drawable.ic_action_device_top));
+ widgetIcon.setImageDrawable(getIcon(R.drawable.ic_action_device_widget, R.color.dashboard_blue));
ImageView noneIcon = (ImageView) mainView.findViewById(R.id.none_icon);
noneIcon.setBackgroundDrawable(getContentIcon(R.drawable.ic_action_device_top));
@@ -207,15 +207,15 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
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;
- int textColor = ContextCompat.getColor(getContext(), check ? R.color.dashboard_blue : night ? R.color.color_white : R.color.color_black);
+ int textColor = ContextCompat.getColor(getContext(), check ? (night ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue) : night ? R.color.color_white : R.color.color_black);
switch (mode) {
case TOOLBAR:
((RadioButton) mainView.findViewById(R.id.top_bar_radio_button)).setChecked(check);
ImageView topBarIcon = (ImageView) mainView.findViewById(R.id.top_bar_icon);
if (check) {
- mainView.findViewById(R.id.top_bar_row).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.show_direction_menu_selected_item_bg));
+ mainView.findViewById(R.id.top_bar_row_frame).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.show_direction_menu_selected_item_bg));
} else {
- mainView.findViewById(R.id.top_bar_row).setBackgroundResource(0);
+ mainView.findViewById(R.id.top_bar_row_frame).setBackgroundResource(0);
}
((TextView) mainView.findViewById(R.id.top_bar_text)).setTextColor(textColor);
topBarIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, iconBgColor));
@@ -225,9 +225,9 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
((RadioButton) mainView.findViewById(R.id.widget_radio_button)).setChecked(check);
ImageView widgetIcon = (ImageView) mainView.findViewById(R.id.widget_icon);
if (check) {
- mainView.findViewById(R.id.widget_row).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.show_direction_menu_selected_item_bg));
+ mainView.findViewById(R.id.widget_row_frame).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.show_direction_menu_selected_item_bg));
} else {
- mainView.findViewById(R.id.widget_row).setBackgroundResource(0);
+ mainView.findViewById(R.id.widget_row_frame).setBackgroundResource(0);
}
((TextView) mainView.findViewById(R.id.widget_text)).setTextColor(textColor);
widgetIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, iconBgColor));
@@ -237,9 +237,9 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
((RadioButton) mainView.findViewById(R.id.none_radio_button)).setChecked(check);
ImageView noneIcon = (ImageView) mainView.findViewById(R.id.none_icon);
if (check) {
- mainView.findViewById(R.id.none_row).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.show_direction_menu_selected_item_bg));
+ mainView.findViewById(R.id.none_row_frame).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.show_direction_menu_selected_item_bg));
} else {
- mainView.findViewById(R.id.none_row).setBackgroundResource(0);
+ mainView.findViewById(R.id.none_row_frame).setBackgroundResource(0);
}
((TextView) mainView.findViewById(R.id.none_text)).setTextColor(textColor);
noneIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, iconBgColor));
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java
index 8b41e6d81c..975b0ec541 100644
--- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java
@@ -2,6 +2,7 @@ package net.osmand.plus.mapmarkers.adapters;
import android.support.v7.widget.RecyclerView;
import android.view.View;
+import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
@@ -11,10 +12,12 @@ import net.osmand.plus.R;
public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
final View mainLayout;
+ final View topDivider;
final ImageView iconDirection;
final ImageView iconReorder;
final ImageView icon;
final TextView title;
+ final TextView firstDescription;
final TextView distance;
final View flagIconLeftSpace;
final View leftPointSpace;
@@ -22,16 +25,19 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
final View rightPointSpace;
final TextView description;
public final ImageButton optionsBtn;
+ final CheckBox checkBox;
final View divider;
final View bottomShadow;
public MapMarkerItemViewHolder(View view) {
super(view);
mainLayout = view.findViewById(R.id.main_layout);
+ topDivider = view.findViewById(R.id.top_divider);
iconDirection = (ImageView) view.findViewById(R.id.map_marker_direction_icon);
iconReorder = (ImageView) view.findViewById(R.id.map_marker_reorder_icon);
icon = (ImageView) view.findViewById(R.id.map_marker_icon);
title = (TextView) view.findViewById(R.id.map_marker_title);
+ firstDescription = (TextView) view.findViewById(R.id.map_marker_first_descr);
distance = (TextView) view.findViewById(R.id.map_marker_distance);
flagIconLeftSpace = view.findViewById(R.id.flag_icon_left_space);
leftPointSpace = view.findViewById(R.id.map_marker_left_point_space);
@@ -39,6 +45,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
rightPointSpace = view.findViewById(R.id.map_marker_right_point_space);
description = (TextView) view.findViewById(R.id.map_marker_description);
optionsBtn = (ImageButton) view.findViewById(R.id.map_marker_options_button);
+ checkBox = (CheckBox) view.findViewById(R.id.map_marker_check_box);
divider = view.findViewById(R.id.divider);
bottomShadow = view.findViewById(R.id.bottom_shadow);
}
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java
index de5e198d43..6f1f94162c 100644
--- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java
@@ -13,6 +13,7 @@ import android.widget.TextView;
import net.osmand.data.LatLon;
import net.osmand.plus.IconsCache;
+import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
@@ -112,8 +113,8 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter 1) {
+ month = Character.toUpperCase(month.charAt(0)) + month.substring(1);
+ }
+ String day = new SimpleDateFormat("dd", Locale.getDefault()).format(date);
+ descr = month + " " + day;
}
holder.description.setText(descr);
@@ -213,6 +222,11 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter 1) {
+ notifyItemChanged(1);
+ } else if (pos == getItemCount()) {
+ notifyItemChanged(pos - 1);
+ }
+ snackbar = Snackbar.make(holder.itemView, R.string.marker_moved_to_history, Snackbar.LENGTH_LONG)
+ .setAction(R.string.shared_string_undo, new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, pos);
+ notifyItemInserted(pos);
+ if (showDirectionEnabled && pos < 2 && getItemCount() > 2) {
+ notifyItemChanged(2);
+ } else if (pos == getItemCount() - 1) {
+ notifyItemChanged(pos - 1);
+ }
+ }
+ });
+ View snackBarView = snackbar.getView();
+ TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action);
+ tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark));
+ snackbar.show();
+ }
+
@Override
public void onItemDismiss(RecyclerView.ViewHolder holder) {
- listener.onDragEnded(holder);
+ listener.onDragOrSwipeEnded(holder);
}
public interface MapMarkersActiveAdapterListener {
@@ -231,6 +279,8 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter showDirectionMarkers;
+ private Snackbar snackbar;
public MapMarkersGroupsAdapter(MapActivity mapActivity) {
this.mapActivity = mapActivity;
@@ -147,6 +150,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter= 2 || currentYear != markerYear;
+ }
+ if (markerInHistory || createdEarly) {
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))));
+ Date date;
+ if (markerInHistory) {
+ date = new Date(marker.visitedDate);
+ } else {
+ date = new Date(marker.creationDate);
+ }
+ String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date);
+ if (month.length() > 1) {
+ month = Character.toUpperCase(month.charAt(0)) + month.substring(1);
+ }
+ String day = new SimpleDateFormat("dd", Locale.getDefault()).format(date);
+ itemViewHolder.description.setText(app.getString(R.string.passed, month + " " + day));
} else {
itemViewHolder.point.setVisibility(View.GONE);
itemViewHolder.description.setVisibility(View.GONE);
}
- String markerGroupName = marker.groupName;
+ final String markerGroupName = marker.groupName;
final MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupByName(markerGroupName);
itemViewHolder.optionsBtn.setOnClickListener(new View.OnClickListener() {
@Override
@@ -237,13 +270,21 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter 1) {
+ monthStr = Character.toUpperCase(monthStr.charAt(0)) + monthStr.substring(1);
+ }
+ return monthStr;
}
private int getLastDisplayItemIndexOfGroup(MapMarkersGroup group) {
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java
index 4941755174..06211e0253 100644
--- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java
@@ -1,9 +1,12 @@
package net.osmand.plus.mapmarkers.adapters;
+import android.support.design.widget.Snackbar;
+import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.TextView;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper.MapMarker;
@@ -30,9 +33,12 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter items = new ArrayList<>();
private MapMarkersHistoryAdapterListener listener;
+ private Snackbar snackbar;
+ private boolean night;
public MapMarkersHistoryAdapter(OsmandApplication app) {
this.app = app;
+ night = !app.getSettings().isLightContent();
createHeaders();
}
@@ -113,13 +119,20 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter 1) {
+ month = Character.toUpperCase(month.charAt(0)) + month.substring(1);
+ }
+ String day = new SimpleDateFormat("dd", Locale.getDefault()).format(date);
+ itemViewHolder.description.setText(app.getString(R.string.passed, month + " " + day));
+ itemViewHolder.optionsBtn.setBackgroundDrawable(app.getResources().getDrawable(night ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset));
itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reset_to_default_dark));
itemViewHolder.optionsBtn.setOnClickListener(new View.OnClickListener() {
@Override
@@ -130,19 +143,33 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter position + 1 && getItemViewType(position + 1) == HEADER_TYPE) || lastItem) {
itemViewHolder.divider.setVisibility(View.GONE);
} else {
- itemViewHolder.bottomShadow.setVisibility(View.GONE);
+ itemViewHolder.divider.setBackgroundColor(ContextCompat.getColor(app, night ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
itemViewHolder.divider.setVisibility(View.VISIBLE);
}
+ itemViewHolder.bottomShadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
} else if (holder instanceof MapMarkerHeaderViewHolder) {
final MapMarkerHeaderViewHolder dateViewHolder = (MapMarkerHeaderViewHolder) holder;
final Integer dateHeader = (Integer) getItem(position);
@@ -165,6 +192,12 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter 1) {
+ monthStr = Character.toUpperCase(monthStr.charAt(0)) + monthStr.substring(1);
+ }
+ return monthStr;
}
public interface MapMarkersHistoryAdapterListener {
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java
index 5c1684a0d3..f8829b793c 100644
--- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java
@@ -1,14 +1,72 @@
package net.osmand.plus.mapmarkers.adapters;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
+import android.graphics.Rect;
+import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
+import android.view.View;
+
+import net.osmand.plus.R;
+import net.osmand.plus.activities.MapActivity;
public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback {
private final ItemTouchHelperAdapter adapter;
+ private MapActivity mapActivity;
+ private boolean swipeEnabled = true;
+
+ private Paint backgroundPaint = new Paint();
+ private Paint iconPaint = new Paint();
+ private Paint textPaint = new Paint();
+
+ private float marginSides;
+ private Bitmap deleteBitmap;
+ private Bitmap historyBitmap;
+ private boolean iconHidden;
+ private boolean night;
+
+ private String delStr;
+ private String moveToHistoryStr;
+
+ private int delStrWidth;
+ private int textHeight;
public MapMarkersItemTouchHelperCallback(ItemTouchHelperAdapter adapter) {
this.adapter = adapter;
+ swipeEnabled = false;
+ }
+
+ public MapMarkersItemTouchHelperCallback(MapActivity mapActivity, ItemTouchHelperAdapter adapter) {
+ this.mapActivity = mapActivity;
+ this.adapter = adapter;
+ marginSides = mapActivity.getResources().getDimension(R.dimen.list_content_padding);
+ deleteBitmap = BitmapFactory.decodeResource(mapActivity.getResources(), R.drawable.ic_action_delete_dark);
+ historyBitmap = BitmapFactory.decodeResource(mapActivity.getResources(), R.drawable.ic_action_history);
+ night = !mapActivity.getMyApplication().getSettings().isLightContent();
+
+ backgroundPaint.setColor(ContextCompat.getColor(mapActivity, night ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light));
+ backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE);
+ backgroundPaint.setAntiAlias(true);
+ iconPaint.setAntiAlias(true);
+ iconPaint.setFilterBitmap(true);
+ iconPaint.setDither(true);
+ textPaint.setTextSize(mapActivity.getResources().getDimension(R.dimen.default_desc_text_size));
+ textPaint.setFakeBoldText(true);
+ textPaint.setAntiAlias(true);
+
+ delStr = mapActivity.getString(R.string.shared_string_delete).toUpperCase();
+ moveToHistoryStr = mapActivity.getString(R.string.move_to_history).toUpperCase();
+ Rect bounds = new Rect();
+
+ textPaint.getTextBounds(delStr, 0, delStr.length(), bounds);
+ delStrWidth = bounds.width();
+ textHeight = bounds.height();
}
@Override
@@ -18,13 +76,14 @@ public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback
@Override
public boolean isItemViewSwipeEnabled() {
- return false;
+ return swipeEnabled;
}
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
final int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
- return makeMovementFlags(dragFlags, 0);
+ final int moveFlags = ItemTouchHelper.RIGHT;
+ return makeMovementFlags(dragFlags, swipeEnabled ? moveFlags : 0);
}
@Override
@@ -33,20 +92,59 @@ public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback
}
@Override
- public void onSwiped(RecyclerView.ViewHolder viewHolder, int i) {
+ public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
+ if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && viewHolder instanceof MapMarkerItemViewHolder) {
+ if (!iconHidden && isCurrentlyActive) {
+ ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.GONE);
+ iconHidden = true;
+ adapter.onSwipeStarted();
+ }
+ View itemView = viewHolder.itemView;
+ int colorIcon;
+ int colorText;
+ if (Math.abs(dX) > itemView.getWidth() / 2) {
+ colorIcon = R.color.map_widget_blue;
+ colorText = R.color.map_widget_blue;
+ } else {
+ colorIcon = night ? 0 : R.color.icon_color;
+ colorText = R.color.dashboard_subheader_text_light;
+ }
+ if (colorIcon != 0) {
+ iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(mapActivity, colorIcon), PorterDuff.Mode.SRC_IN));
+ }
+ textPaint.setColor(ContextCompat.getColor(mapActivity, colorText));
+ float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2;
+ c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint);
+ float iconMarginTop = ((float) itemView.getHeight() - (float) historyBitmap.getHeight()) / 2;
+ c.drawBitmap(historyBitmap, itemView.getLeft() + marginSides, itemView.getTop() + iconMarginTop, iconPaint);
+ c.drawText(moveToHistoryStr, itemView.getLeft() + 2 * marginSides + historyBitmap.getWidth(),
+ itemView.getTop() + textMarginTop + textHeight, textPaint);
+ }
+ super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
+ }
+
+ @Override
+ public void onSwiped(RecyclerView.ViewHolder viewHolder, int i) {
+ adapter.onItemSwiped(viewHolder);
}
@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
super.clearView(recyclerView, viewHolder);
+ ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.VISIBLE);
+ iconHidden = false;
adapter.onItemDismiss(viewHolder);
}
interface ItemTouchHelperAdapter {
+ void onSwipeStarted();
+
boolean onItemMove(int from, int to);
+ void onItemSwiped(RecyclerView.ViewHolder holder);
+
void onItemDismiss(RecyclerView.ViewHolder holder);
}
}
diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java
new file mode 100644
index 0000000000..0648d29be4
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java
@@ -0,0 +1,186 @@
+package net.osmand.plus.mapmarkers.adapters;
+
+import android.support.v4.content.ContextCompat;
+import android.support.v4.view.MotionEventCompat;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+
+import net.osmand.data.LatLon;
+import net.osmand.plus.IconsCache;
+import net.osmand.plus.MapMarkersHelper.MapMarker;
+import net.osmand.plus.OsmAndFormatter;
+import net.osmand.plus.R;
+import net.osmand.plus.activities.MapActivity;
+import net.osmand.util.MapUtils;
+
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+
+public class MapMarkersListAdapter extends RecyclerView.Adapter
+ implements MapMarkersItemTouchHelperCallback.ItemTouchHelperAdapter {
+
+ private MapActivity mapActivity;
+ private List markers;
+ private MapMarkersListAdapterListener listener;
+
+ private LatLon location;
+ private boolean useCenter;
+
+ public void setAdapterListener(MapMarkersListAdapterListener listener) {
+ this.listener = listener;
+ }
+
+ public void setLocation(LatLon location) {
+ this.location = location;
+ }
+
+ public void setUseCenter(boolean useCenter) {
+ this.useCenter = useCenter;
+ }
+
+ public MapMarkersListAdapter(MapActivity mapActivity) {
+ this.mapActivity = mapActivity;
+ markers = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers();
+ }
+
+ @Override
+ public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
+ View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false);
+ view.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ listener.onItemClick(view);
+ }
+ });
+ return new MapMarkerItemViewHolder(view);
+ }
+
+ @Override
+ public void onBindViewHolder(final MapMarkerItemViewHolder holder, int pos) {
+ boolean night = !mapActivity.getMyApplication().getSettings().isLightContent();
+ IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
+ MapMarker marker = markers.get(pos);
+
+ holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(marker.colorIndex)));
+ holder.iconReorder.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reorder));
+ holder.iconDirection.setVisibility(View.GONE);
+ holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.bg_color_dark : R.color.bg_color_light));
+ holder.title.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.color_white : R.color.color_black));
+ holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
+ holder.optionsBtn.setVisibility(View.GONE);
+ holder.description.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.dash_search_icon_dark : R.color.icon_color));
+ holder.checkBox.setVisibility(View.VISIBLE);
+ holder.checkBox.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ listener.onItemClick(holder.itemView);
+ }
+ });
+ holder.checkBox.setChecked(marker.selected);
+
+ if (pos == 0 || pos == getItemCount() - 1) {
+ holder.firstDescription.setVisibility(View.VISIBLE);
+ if (pos == 0) {
+ holder.topDivider.setVisibility(View.VISIBLE);
+ holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_control_start) + " • ");
+ } else {
+ holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_finish) + " • ");
+ }
+ } else {
+ holder.firstDescription.setVisibility(View.GONE);
+ holder.topDivider.setVisibility(View.GONE);
+ }
+
+ if (pos == getItemCount() - 1) {
+ holder.bottomShadow.setVisibility(View.VISIBLE);
+ holder.divider.setVisibility(View.GONE);
+ } else {
+ holder.bottomShadow.setVisibility(View.GONE);
+ holder.divider.setVisibility(View.VISIBLE);
+ }
+
+ holder.point.setVisibility(View.VISIBLE);
+
+ holder.iconReorder.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View view, MotionEvent event) {
+ if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
+ listener.onDragStarted(holder);
+ }
+ return false;
+ }
+ });
+
+ holder.title.setText(marker.getName(mapActivity));
+
+ String descr;
+ if ((descr = marker.groupName) != null) {
+ if (descr.equals("")) {
+ descr = mapActivity.getString(R.string.shared_string_favorites);
+ }
+ } else {
+ Date date = new Date(marker.creationDate);
+ String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date);
+ if (month.length() > 1) {
+ month = Character.toUpperCase(month.charAt(0)) + month.substring(1);
+ }
+ String day = new SimpleDateFormat("dd", Locale.getDefault()).format(date);
+ descr = month + " " + day;
+ }
+ holder.description.setText(descr);
+
+ if (location != null) {
+ holder.distance.setTextColor(ContextCompat.getColor(mapActivity, useCenter
+ ? R.color.color_distance : R.color.color_myloc_distance));
+ float dist = (float) MapUtils.getDistance(location.getLatitude(), location.getLongitude(),
+ marker.getLatitude(), marker.getLongitude());
+ holder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
+ }
+ }
+
+ @Override
+ public int getItemCount() {
+ return markers.size();
+ }
+
+ public MapMarker getItem(int position) {
+ return markers.get(position);
+ }
+
+ @Override
+ public void onSwipeStarted() {
+
+ }
+
+ @Override
+ public boolean onItemMove(int from, int to) {
+ Collections.swap(markers, from, to);
+ notifyItemMoved(from, to);
+ return true;
+ }
+
+ @Override
+ public void onItemSwiped(RecyclerView.ViewHolder holder) {
+
+ }
+
+ @Override
+ public void onItemDismiss(RecyclerView.ViewHolder holder) {
+ listener.onDragEnded(holder);
+ }
+
+ public interface MapMarkersListAdapterListener {
+
+ void onItemClick(View view);
+
+ void onDragStarted(RecyclerView.ViewHolder holder);
+
+ void onDragEnded(RecyclerView.ViewHolder holder);
+ }
+}
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java
index c19dc9817d..3813c19899 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java
@@ -173,8 +173,8 @@ public class MeasurementToolFragment extends Fragment {
((SaveAsNewTrackBottomSheetDialogFragment) saveAsNewTrackFragment).setListener(createSaveAsNewTrackFragmentListener());
}
// If rotate the screen from landscape to portrait when the list of points is displayed then
- // the PointsListFragment will exist without view. This is necessary to remove it.
- if (portrait) {
+ // the RecyclerViewFragment will exist without view. This is necessary to remove it.
+ if (!portrait) {
hidePointsListFragment();
}
@@ -636,7 +636,7 @@ public class MeasurementToolFragment extends Fragment {
return new SnapToRoadFragmentListener() {
@Override
public void onDestroyView(boolean snapToRoadEnabled) {
- if (!snapToRoadEnabled) {
+ if (!snapToRoadEnabled && !editingCtx.isInSnapToRoadMode()) {
toolBarController.setTitle(previousToolBarTitle);
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
@@ -1029,12 +1029,12 @@ public class MeasurementToolFragment extends Fragment {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
int screenHeight = AndroidUtils.getScreenHeight(mapActivity) - AndroidUtils.getStatusBarHeight(mapActivity);
- MeasurePointsListFragment fragment = new MeasurePointsListFragment();
+ RecyclerViewFragment fragment = new RecyclerViewFragment();
fragment.setRecyclerView(pointsRv);
fragment.setWidth(upDownRow.getWidth());
fragment.setHeight(screenHeight - upDownRow.getHeight());
mapActivity.getSupportFragmentManager().beginTransaction()
- .add(R.id.fragmentContainer, fragment, MeasurePointsListFragment.TAG)
+ .add(R.id.fragmentContainer, fragment, RecyclerViewFragment.TAG)
.commitAllowingStateLoss();
}
}
@@ -1044,7 +1044,7 @@ public class MeasurementToolFragment extends Fragment {
if (mapActivity != null) {
try {
FragmentManager manager = mapActivity.getSupportFragmentManager();
- Fragment fragment = manager.findFragmentByTag(MeasurePointsListFragment.TAG);
+ Fragment fragment = manager.findFragmentByTag(RecyclerViewFragment.TAG);
if (fragment != null) {
manager.beginTransaction().remove(fragment).commitAllowingStateLoss();
}
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java
index 4eda865c08..b56959ea9d 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java
@@ -225,23 +225,19 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
WptPt pt = before.points.get(before.points.size() - 1);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
- path.moveTo(locX, locY);
tx.add(locX);
ty.add(locY);
- path.lineTo(tb.getCenterPixelX(), tb.getCenterPixelY());
tx.add(tb.getCenterPixelX());
ty.add(tb.getCenterPixelY());
}
if (after.points.size() > 0) {
if (before.points.size() == 0) {
- path.moveTo(tb.getCenterPixelX(), tb.getCenterPixelY());
tx.add(tb.getCenterPixelX());
ty.add(tb.getCenterPixelY());
}
WptPt pt = after.points.get(0);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
- path.lineTo(locX, locY);
tx.add(locX);
ty.add(locY);
}
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurePointsListFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/RecyclerViewFragment.java
similarity index 95%
rename from OsmAnd/src/net/osmand/plus/measurementtool/MeasurePointsListFragment.java
rename to OsmAnd/src/net/osmand/plus/measurementtool/RecyclerViewFragment.java
index 9cc331bf13..0160f67aaf 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurePointsListFragment.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/RecyclerViewFragment.java
@@ -18,9 +18,9 @@ import net.osmand.AndroidUtils;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
-public class MeasurePointsListFragment extends Fragment {
+public class RecyclerViewFragment extends Fragment {
- public static final String TAG = "MeasurePointsListFragment";
+ public static final String TAG = "RecyclerViewFragment";
private RecyclerView rv;
private int height;
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java
index 1ab369ba18..a9acf56f8f 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java
@@ -139,7 +139,7 @@ public class SnapToRoadBottomSheetDialogFragment extends android.support.design.
.getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color);
}
- interface SnapToRoadFragmentListener {
+ public interface SnapToRoadFragmentListener {
void onDestroyView(boolean snapToRoadEnabled);
diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java
index 88dd4bf182..e50ad180cb 100644
--- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java
+++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java
@@ -712,7 +712,7 @@ public class MapControlsLayer extends OsmandMapLayer {
((app.accessibilityEnabled() || (System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS)) && routeFollowingMode);
updateMyLocation(rh, routeDialogOpened || trackDialogOpened);
boolean showButtons = (showRouteCalculationControls || !routeFollowingMode)
- && !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode();
+ && !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode() && !isInPlanRouteMode();
//routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_gabout_dark : R.drawable.map_directions);
if (rh.isFollowingMode()) {
routePlanningBtn.setIconResId(R.drawable.map_start_navigation);
@@ -727,16 +727,16 @@ public class MapControlsLayer extends OsmandMapLayer {
routePlanningBtn.updateVisibility(showButtons);
menuControl.updateVisibility(showButtons);
- mapZoomIn.updateVisibility(!routeDialogOpened);
- mapZoomOut.updateVisibility(!routeDialogOpened);
- compassHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && shouldShowCompass() &&
- !isInMeasurementToolMode());
+ mapZoomIn.updateVisibility(!routeDialogOpened && !isInExpandedRouteMode());
+ mapZoomOut.updateVisibility(!routeDialogOpened && !isInExpandedRouteMode());
+ compassHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && shouldShowCompass()
+ && !isInMeasurementToolMode() && !isInPlanRouteMode());
if (layersHud.setIconResId(settings.getApplicationMode().getMapIconId())) {
layersHud.update(app, isNight);
}
- layersHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && !isInMeasurementToolMode());
- quickSearchHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && !isInMeasurementToolMode());
+ layersHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && !isInMeasurementToolMode() && !isInPlanRouteMode());
+ quickSearchHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && !isInMeasurementToolMode() && !isInPlanRouteMode());
if (!routePlanningMode && !routeFollowingMode) {
if (mapView.isZooming()) {
@@ -814,7 +814,7 @@ public class MapControlsLayer extends OsmandMapLayer {
backToLocationControl.iv.setContentDescription(mapActivity.getString(R.string.map_widget_back_to_loc));
}
boolean visible = !(tracked && rh.isFollowingMode());
- backToLocationControl.updateVisibility(visible && !dialogOpened);
+ backToLocationControl.updateVisibility(visible && !dialogOpened && !isInExpandedRouteMode());
if (app.accessibilityEnabled()) {
backToLocationControl.iv.setClickable(enabled && visible);
}
@@ -1132,6 +1132,14 @@ public class MapControlsLayer extends OsmandMapLayer {
return mapActivity.getMapLayers().getMeasurementToolLayer().isInMeasurementMode();
}
+ private boolean isInPlanRouteMode() {
+ return mapActivity.getMapLayers().getMapMarkersLayer().isInPlanRouteMode();
+ }
+
+ private boolean isInExpandedRouteMode() {
+ return mapActivity.getMapLayers().getMapMarkersLayer().isMarkersListOpened();
+ }
+
public static View.OnLongClickListener getOnClickMagnifierListener(final OsmandMapTileView view) {
return new View.OnLongClickListener() {
diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java
index 556e90c20f..15cdc2ec9c 100644
--- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java
+++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java
@@ -5,9 +5,11 @@ import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
+import android.graphics.PathMeasure;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
+import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
@@ -19,6 +21,7 @@ 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.OsmAndFormatter;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
@@ -27,6 +30,7 @@ import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProviderSelection;
import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory;
+import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.List;
@@ -37,6 +41,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider {
protected static final int DIST_TO_SHOW = 80;
+ private static final int TEXT_SIZE = 12;
+ private static final int VERTICAL_OFFSET = 10;
private final MapActivity map;
private OsmandMapTileView view;
@@ -63,6 +69,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
private float[] calculations = new float[2];
private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine");
+ private final RenderingLineAttributes textAttrs = new RenderingLineAttributes("rulerCircle");
private Paint paint;
private Path path;
private List route = new ArrayList<>();
@@ -70,9 +77,13 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
private TIntArrayList tx = new TIntArrayList();
private TIntArrayList ty = new TIntArrayList();
private Path linePath = new Path();
+ private String distanceText;
private ContextMenuLayer contextMenuLayer;
+ private boolean inPlanRouteMode;
+ private boolean markersListOpened;
+
public MapMarkersLayer(MapActivity map) {
this.map = map;
}
@@ -81,6 +92,22 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
return widgetsFactory;
}
+ public boolean isInPlanRouteMode() {
+ return inPlanRouteMode;
+ }
+
+ public void setInPlanRouteMode(boolean inPlanRouteMode) {
+ this.inPlanRouteMode = inPlanRouteMode;
+ }
+
+ public boolean isMarkersListOpened() {
+ return inPlanRouteMode && markersListOpened;
+ }
+
+ public void setMarkersListOpened(boolean markersListOpened) {
+ this.markersListOpened = markersListOpened;
+ }
+
private void initUI() {
bitmapPaint = new Paint();
bitmapPaint.setDither(true);
@@ -113,6 +140,10 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
paint.setColor(ContextCompat.getColor(map, R.color.marker_red));
paint.setAlpha(200);
+ float textSize = TEXT_SIZE * map.getResources().getDisplayMetrics().density;
+ textAttrs.paint2.setTextSize(textSize);
+ textAttrs.paint3.setTextSize(textSize);
+
widgetsFactory = new MapMarkersWidgetsFactory(map);
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
@@ -199,8 +230,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
return;
}
- lineAttrs.updatePaints(view, nightMode, tileBox);
-
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
if (route.size() > 0) {
path.reset();
@@ -228,25 +257,66 @@ 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());
+ lineAttrs.updatePaints(view, nightMode, tileBox);
+ textAttrs.updatePaints(view, nightMode, tileBox);
+ textAttrs.paint2.setStyle(Paint.Style.FILL);
+
+ int locX = (int) tileBox.getPixXFromLatLon(myLoc.getLatitude(), myLoc.getLongitude());
+ int locY = (int) tileBox.getPixYFromLatLon(myLoc.getLatitude(), myLoc.getLongitude());
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());
+ int markerX = (int) tileBox.getPixXFromLatLon(marker.getLatitude(), marker.getLongitude());
+ int markerY = (int) tileBox.getPixYFromLatLon(marker.getLatitude(), marker.getLongitude());
+
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);
+ PathMeasure pm = new PathMeasure(linePath, false);
+ float[] pos = new float[2];
+ pm.getPosTan(pm.getLength() / 2, pos, null);
+
+ float generalDist = (float) MapUtils.getDistance(myLoc.getLatitude(), myLoc.getLongitude(), marker.getLatitude(), marker.getLongitude());
+ String generalDistSt = OsmAndFormatter.getFormattedDistance(generalDist, view.getApplication());
+ boolean locationInvisible = locX < 0 || locX > tileBox.getPixWidth() || locY < 0 || locY > tileBox.getPixHeight();
+ if (locationInvisible) {
+ float centerToMarkerDist = (float) MapUtils.getDistance(tileBox.getLatLonFromPixel(pos[0], pos[1]), marker.getLatitude(), marker.getLongitude());
+ String centerToMarkerDistSt = OsmAndFormatter.getFormattedDistance(centerToMarkerDist, view.getApplication());
+ if (locX >= markerX) {
+ distanceText = centerToMarkerDistSt + " | " + generalDistSt;
+ } else {
+ distanceText = generalDistSt + " | " + centerToMarkerDistSt;
+ }
+ } else {
+ distanceText = generalDistSt;
+ }
+ Rect bounds = new Rect();
+ textAttrs.paint2.getTextBounds(distanceText, 0, distanceText.length(), bounds);
+ float hOffset = pm.getLength() / 2 - bounds.width() / 2;
lineAttrs.paint.setColor(colors[marker.colorIndex]);
+
+ canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
canvas.drawPath(linePath, lineAttrs.paint);
+ if (locationInvisible && !(pos[0] == 0 && pos[1] == 0)) {
+ canvas.drawCircle(pos[0], pos[1], 5, new Paint());
+ }
+ if (locX >= markerX) {
+ canvas.rotate(180, pos[0], pos[1]);
+ canvas.drawTextOnPath(distanceText, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint3);
+ canvas.drawTextOnPath(distanceText, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint2);
+ canvas.rotate(-180, pos[0], pos[1]);
+ } else {
+ canvas.drawTextOnPath(distanceText, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint3);
+ canvas.drawTextOnPath(distanceText, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint2);
+ }
+ canvas.rotate(tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
}
}
@@ -426,6 +496,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
public void setSelectedObject(Object o) {
if (o instanceof MapMarker) {
map.getMyApplication().getMapMarkersHelper().moveMarkerToTop((MapMarker) o);
+ map.getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM);
}
}
diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java
index 0c2592cd07..6ca48615f1 100644
--- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java
+++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java
@@ -138,50 +138,55 @@ public abstract class OsmandMapLayer {
return x >= lx && x <= rx && y >= ty && y <= by;
}
-
public int calculatePath(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys, Path path) {
- boolean start = false;
- int px = xs.get(0);
- int py = ys.get(0);
- int h = tb.getPixHeight();
- int w = tb.getPixWidth();
+ boolean segmentStarted = false;
+ int prevX = xs.get(0);
+ int prevY = ys.get(0);
+ int height = tb.getPixHeight();
+ int width = tb.getPixWidth();
int cnt = 0;
- boolean pin = isIn(px, py, 0, 0, w, h);
+ boolean prevIn = isIn(prevX, prevY, 0, 0, width, height);
for (int i = 1; i < xs.size(); i++) {
- int x = xs.get(i);
- int y = ys.get(i);
- boolean in = isIn(x, y, 0, 0, w, h);
+ int currX = xs.get(i);
+ int currY = ys.get(i);
+ boolean currIn = isIn(currX, currY, 0, 0, width, height);
boolean draw = false;
- if (pin && in) {
+ if (prevIn && currIn) {
draw = true;
} else {
- long intersection = MapAlgorithms.calculateIntersection(x, y,
- px, py, 0, w, h, 0);
+ long intersection = MapAlgorithms.calculateIntersection(currX, currY, prevX, prevY, 0, width, height, 0);
if (intersection != -1) {
- if (pin && (i == 1)) {
+ if (prevIn && (i == 1)) {
cnt++;
- path.moveTo(px, py);
- start = true;
+ path.moveTo(prevX, prevY);
+ segmentStarted = true;
}
- px = (int) (intersection >> 32);
- py = (int) (intersection & 0xffffffff);
+ prevX = (int) (intersection >> 32);
+ prevY = (int) (intersection & 0xffffffff);
draw = true;
}
+ if (i == xs.size() - 1 && !currIn) {
+ long inter = MapAlgorithms.calculateIntersection(prevX, prevY, currX, currY, 0, width, height, 0);
+ if (inter != -1) {
+ currX = (int) (inter >> 32);
+ currY = (int) (inter & 0xffffffff);
+ }
+ }
}
if (draw) {
- if (!start) {
+ if (!segmentStarted) {
cnt++;
- path.moveTo(px, py);
+ path.moveTo(prevX, prevY);
+ segmentStarted = true;
}
- path.lineTo(x, y);
- start = true;
+ path.lineTo(currX, currY);
} else {
- start = false;
+ segmentStarted = false;
}
- pin = in;
- px = x;
- py = y;
+ prevIn = currIn;
+ prevX = currX;
+ prevY = currY;
}
return cnt;
}
@@ -335,7 +340,7 @@ public abstract class OsmandMapLayer {
public boolean isPaint_1;
public int defaultWidth_1 = 0;
private String renderingAttribute;
-
+
public RenderingLineAttributes(String renderingAttribute) {
this.renderingAttribute = renderingAttribute;
paint = initPaint();
@@ -344,8 +349,8 @@ public abstract class OsmandMapLayer {
paint_1 = initPaint();
shadowPaint = initPaint();
}
-
-
+
+
private Paint initPaint() {
Paint paint = new Paint();
paint.setStyle(Style.STROKE);
@@ -407,15 +412,15 @@ public abstract class OsmandMapLayer {
private void updateDefaultColor(Paint paint, int defaultColor) {
- if((paint.getColor() == 0 || paint.getColor() == Color.BLACK) && defaultColor != 0) {
+ if ((paint.getColor() == 0 || paint.getColor() == Color.BLACK) && defaultColor != 0) {
paint.setColor(defaultColor);
}
}
-
+
private int calculateHash(Object... o) {
return Arrays.hashCode(o);
}
-
+
public void drawPath(Canvas canvas, Path path) {
if (isPaint_1) {
canvas.drawPath(path, paint_1);
diff --git a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java
index cbf374edf1..d605728a18 100644
--- a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java
+++ b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java
@@ -5,6 +5,8 @@ import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
+import android.graphics.Path;
+import android.graphics.PathMeasure;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Handler;
@@ -22,15 +24,19 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.RulerMode;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
+import net.osmand.util.MapUtils;
import java.util.ArrayList;
+import gnu.trove.list.array.TIntArrayList;
+
public class RulerControlLayer extends OsmandMapLayer {
+ private static final int VERTICAL_OFFSET = 15;
private static final long DRAW_TIME = 2000;
private static final long DELAY_BEFORE_DRAW = 500;
private static final int TEXT_SIZE = 14;
- private static final int MAX_ITERATIONS = 50;
+ private static final int DISTANCE_TEXT_SIZE = 16;
private final MapActivity mapActivity;
private OsmandApplication app;
@@ -62,12 +68,18 @@ public class RulerControlLayer extends OsmandMapLayer {
private boolean touched;
private boolean wasZoom;
+ private TIntArrayList tx = new TIntArrayList();
+ private TIntArrayList ty = new TIntArrayList();
+ private Path linePath = new Path();
+
private Bitmap centerIconDay;
private Bitmap centerIconNight;
private Paint bitmapPaint;
private RenderingLineAttributes lineAttrs;
private RenderingLineAttributes circleAttrs;
private RenderingLineAttributes circleAttrsAlt;
+ private float circleTextSize;
+ private float lineTextSize;
private Handler handler;
@@ -110,15 +122,16 @@ public class RulerControlLayer extends OsmandMapLayer {
lineAttrs = new RenderingLineAttributes("rulerLine");
- float textSize = TEXT_SIZE * mapActivity.getResources().getDisplayMetrics().density;
+ circleTextSize = TEXT_SIZE * mapActivity.getResources().getDisplayMetrics().density;
+ lineTextSize = DISTANCE_TEXT_SIZE * mapActivity.getResources().getDisplayMetrics().density;
circleAttrs = new RenderingLineAttributes("rulerCircle");
- circleAttrs.paint2.setTextSize(textSize);
- circleAttrs.paint3.setTextSize(textSize);
+ circleAttrs.paint2.setTextSize(circleTextSize);
+ circleAttrs.paint3.setTextSize(circleTextSize);
circleAttrsAlt = new RenderingLineAttributes("rulerCircleAlt");
- circleAttrsAlt.paint2.setTextSize(textSize);
- circleAttrsAlt.paint3.setTextSize(textSize);
+ circleAttrsAlt.paint2.setTextSize(circleTextSize);
+ circleAttrsAlt.paint3.setTextSize(circleTextSize);
handler = new Handler() {
@Override
@@ -202,22 +215,16 @@ public class RulerControlLayer extends OsmandMapLayer {
drawCenterIcon(canvas, tb, center, settings.isNightMode(), mode);
Location currentLoc = app.getLocationProvider().getLastKnownLocation();
if (showDistBetweenFingerAndLocation && currentLoc != null) {
- float x = tb.getPixXFromLatLon(touchPointLatLon.getLatitude(), touchPointLatLon.getLongitude());
- float y = tb.getPixYFromLatLon(touchPointLatLon.getLatitude(), touchPointLatLon.getLongitude());
- drawDistBetweenFingerAndLocation(canvas, tb, x, y, currentLoc, settings.isNightMode());
+ drawDistBetweenFingerAndLocation(canvas, tb, currentLoc, settings.isNightMode());
} else if (showTwoFingersDistance) {
- LatLon firstTouchPoint = view.getFirstTouchPointLatLon();
- LatLon secondTouchPoint = view.getSecondTouchPointLatLon();
- float x1 = tb.getPixXFromLonNoRot(firstTouchPoint.getLongitude());
- float y1 = tb.getPixYFromLatNoRot(firstTouchPoint.getLatitude());
- float x2 = tb.getPixXFromLonNoRot(secondTouchPoint.getLongitude());
- float y2 = tb.getPixYFromLatNoRot(secondTouchPoint.getLatitude());
- drawTwoFingersDistance(canvas, x1, y1, x2, y2, settings.isNightMode());
+ drawTwoFingersDistance(canvas, tb, view.getFirstTouchPointLatLon(), view.getSecondTouchPointLatLon(), settings.isNightMode());
}
if (mode == RulerMode.FIRST || mode == RulerMode.SECOND) {
updateData(tb, center);
RenderingLineAttributes attrs;
if (mode == RulerMode.FIRST) {
+ circleAttrs.paint2.setTextSize(circleTextSize);
+ circleAttrs.paint3.setTextSize(circleTextSize);
attrs = circleAttrs;
} else {
attrs = circleAttrsAlt;
@@ -238,10 +245,46 @@ public class RulerControlLayer extends OsmandMapLayer {
handler.sendEmptyMessageDelayed(0, DRAW_TIME + 50);
}
- private void drawTwoFingersDistance(Canvas canvas, float x1, float y1, float x2, float y2, boolean nightMode) {
- canvas.drawLine(x1, y1, x2, y2, lineAttrs.paint);
+ private void drawTwoFingersDistance(Canvas canvas, RotatedTileBox tb, LatLon firstTouch, LatLon secondTouch, boolean nightMode) {
+ float x1 = tb.getPixXFromLatLon(firstTouch.getLatitude(), firstTouch.getLongitude());
+ float y1 = tb.getPixYFromLatLon(firstTouch.getLatitude(), firstTouch.getLongitude());
+ float x2 = tb.getPixXFromLatLon(secondTouch.getLatitude(), secondTouch.getLongitude());
+ float y2 = tb.getPixYFromLatLon(secondTouch.getLatitude(), secondTouch.getLongitude());
+
+ Path path = new Path();
+ path.moveTo(x1, y1);
+ path.lineTo(x2, y2);
+
+ String text = OsmAndFormatter.getFormattedDistance((float) MapUtils.getDistance(firstTouch, secondTouch), app);
+
+ canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
+ canvas.drawPath(path, lineAttrs.paint);
drawFingerTouchIcon(canvas, x1, y1, nightMode);
drawFingerTouchIcon(canvas, x2, y2, nightMode);
+ drawTextOnCenterOfPath(canvas, x1, x2, path, text);
+ canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
+ }
+
+ private void drawTextOnCenterOfPath(Canvas canvas, float x1, float x2, Path path, String text) {
+ PathMeasure pm = new PathMeasure(path, false);
+ Rect bounds = new Rect();
+ circleAttrs.paint2.getTextBounds(text, 0, text.length(), bounds);
+ float hOffset = pm.getLength() / 2 - bounds.width() / 2;
+
+ circleAttrs.paint2.setTextSize(lineTextSize);
+ circleAttrs.paint3.setTextSize(lineTextSize);
+
+ if (x1 >= x2) {
+ float[] pos = new float[2];
+ pm.getPosTan(pm.getLength() / 2, pos, null);
+ canvas.rotate(180, pos[0], pos[1]);
+ canvas.drawTextOnPath(text, path, hOffset, bounds.height() + VERTICAL_OFFSET, circleAttrs.paint3);
+ canvas.drawTextOnPath(text, path, hOffset, bounds.height() + VERTICAL_OFFSET, circleAttrs.paint2);
+ canvas.rotate(-180, pos[0], pos[1]);
+ } else {
+ canvas.drawTextOnPath(text, path, hOffset, -VERTICAL_OFFSET, circleAttrs.paint3);
+ canvas.drawTextOnPath(text, path, hOffset, -VERTICAL_OFFSET, circleAttrs.paint2);
+ }
}
private void drawFingerTouchIcon(Canvas canvas, float x, float y, boolean nightMode) {
@@ -267,41 +310,31 @@ public class RulerControlLayer extends OsmandMapLayer {
canvas.rotate(tb.getRotate(), center.x, center.y);
}
- private void drawDistBetweenFingerAndLocation(Canvas canvas, RotatedTileBox tb, float x, float y,
- Location currentLoc, boolean nightMode) {
- int currX = (int) tb.getPixXFromLatLon(currentLoc.getLatitude(), currentLoc.getLongitude());
- int currY = (int) tb.getPixYFromLatLon(currentLoc.getLatitude(), currentLoc.getLongitude());
- int width = tb.getPixWidth();
- int height = tb.getPixHeight();
- boolean needDraw = true;
+ private void drawDistBetweenFingerAndLocation(Canvas canvas, RotatedTileBox tb, Location currLoc, boolean night) {
+ float x = tb.getPixXFromLatLon(touchPointLatLon.getLatitude(), touchPointLatLon.getLongitude());
+ float y = tb.getPixYFromLatLon(touchPointLatLon.getLatitude(), touchPointLatLon.getLongitude());
+ int currX = (int) tb.getPixXFromLatLon(currLoc.getLatitude(), currLoc.getLongitude());
+ int currY = (int) tb.getPixYFromLatLon(currLoc.getLatitude(), currLoc.getLongitude());
- if ((currX < 0 && x == 0) || (currY < 0 && y == 0)
- || (currX > width && x == width) || (currY > height && y == height)) {
- needDraw = false;
- } else if (currX < 0 || currY < 0 || currX > width || currY > height) {
- float xNew = (currX + x) / 2;
- float yNew = (currY + y) / 2;
- int count = 0;
+ linePath.reset();
+ tx.reset();
+ ty.reset();
- while (count < MAX_ITERATIONS) {
- count++;
- if (xNew < 0 || yNew < 0 || xNew > width || yNew > height) {
- currX = (int) xNew;
- currY = (int) yNew;
- } else {
- break;
- }
- xNew = (xNew + x) / 2;
- yNew = (yNew + y) / 2;
- }
- }
+ tx.add((int) x);
+ ty.add((int) y);
+ tx.add(currX);
+ ty.add(currY);
- if (needDraw) {
- canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
- canvas.drawLine(currX, currY, x, y, lineAttrs.paint);
- drawFingerTouchIcon(canvas, x, y, nightMode);
- canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
- }
+ calculatePath(tb, tx, ty, linePath);
+
+ float dist = (float) MapUtils.getDistance(touchPointLatLon, currLoc.getLatitude(), currLoc.getLongitude());
+ String text = OsmAndFormatter.getFormattedDistance(dist, app);
+
+ canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
+ canvas.drawPath(linePath, lineAttrs.paint);
+ drawFingerTouchIcon(canvas, x, y, night);
+ drawTextOnCenterOfPath(canvas, x, currX, linePath, text);
+ canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
}
private void updateData(RotatedTileBox tb, QuadPoint center) {