diff --git a/OsmAnd/res/layout-land/fragment_plan_route.xml b/OsmAnd/res/layout-land/fragment_plan_route.xml index 7123151125..ff21237f2e 100644 --- a/OsmAnd/res/layout-land/fragment_plan_route.xml +++ b/OsmAnd/res/layout-land/fragment_plan_route.xml @@ -143,7 +143,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:background="@null" - tools:src="@drawable/ic_sort_waypoint_dark"/> + tools:src="@drawable/ic_action_list_sort"/> - - + android:clickable="true" + android:minHeight="@dimen/map_address_height" + android:visibility="gone" + tools:visibility="visible"> + android:orientation="vertical"> - + android:orientation="horizontal"> - - - + android:layout_weight="1" + android:background="@color/markers_top_bar_background" + android:minHeight="50dp"> - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="horizontal"> - + - + android:layout_marginBottom="6dp" + android:layout_marginTop="6dp" + android:layout_weight="1" + android:orientation="vertical"> + + + + + + + + + + - - + - + - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + - - - - - - - - - - - - - + android:background="@drawable/btn_round" + android:minHeight="@dimen/map_address_height"> - - - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + > - - - - - - - - - + android:textSize="@dimen/map_widget_text_size" + tools:text="Long Street Name"> + + android:textSize="@dimen/map_widget_text_size" + tools:text="Long Street Name"> + + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -194,7 +194,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:maxLines="1" - android:text="@string/shared_string_save_as_gpx" + android:text="@string/marker_save_as_track" android:textAppearance="@style/TextAppearance.ListItemTitle"/> 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 index 099da8e742..5d8c993755 100644 --- 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 @@ -17,7 +17,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:paddingBottom="@dimen/bottom_sheet_content_padding_small"> + android:paddingBottom="@dimen/dialog_content_margin"> + tools:src="@drawable/ic_action_list_sort"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/map_hud_top.xml b/OsmAnd/res/layout/map_hud_top.xml index 6a4ad821e0..02c3dd2d76 100644 --- a/OsmAnd/res/layout/map_hud_top.xml +++ b/OsmAnd/res/layout/map_hud_top.xml @@ -9,145 +9,145 @@ - - - - - - - - - - - - - - + android:background="@drawable/btn_flat" + android:minHeight="@dimen/map_address_height"> - - - + + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp"> + - - - - - - - - + android:textSize="@dimen/map_widget_text_size" + tools:text="Long Street Name"> + - + android:textSize="@dimen/map_widget_text_size" + tools:text="Long Street Name"> + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - + android:clickable="true" + android:minHeight="@dimen/map_address_height" + android:visibility="gone" + tools:visibility="visible"> - + android:orientation="vertical"> - - - + android:minHeight="60dp" + android:background="@color/markers_top_bar_background"> + android:background="?attr/selectableItemBackground" + android:layout_gravity="center_vertical" + android:gravity="center_vertical" + android:layout_marginTop="5dp" + android:layout_marginBottom="5dp" + android:orientation="horizontal"> - + - + android:layout_weight="1" + android:orientation="vertical"> + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - + diff --git a/OsmAnd/res/layout/map_marker_item_show_hide_history.xml b/OsmAnd/res/layout/map_marker_item_show_hide_history.xml index 2454538048..908b633e61 100644 --- a/OsmAnd/res/layout/map_marker_item_show_hide_history.xml +++ b/OsmAnd/res/layout/map_marker_item_show_hide_history.xml @@ -1,25 +1,37 @@ - + android:layout_height="48dp"> + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/markers_track_name_edit_text.xml b/OsmAnd/res/layout/markers_track_name_edit_text.xml index 336170833b..d21a7056bc 100644 --- a/OsmAnd/res/layout/markers_track_name_edit_text.xml +++ b/OsmAnd/res/layout/markers_track_name_edit_text.xml @@ -4,6 +4,7 @@ android:layout_height="wrap_content"> - - + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a90cd5f178..ef9b0dbba2 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -54,7 +54,6 @@ Move all to history - Build route Distance indication Sort by Do not use animations diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index c11d56b723..8d96630b1c 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -1012,7 +1012,6 @@ public class GPXUtilities { } private void removeGeneralTrackIfExists() { - Track generalTrack = getGeneralTrack(); if (generalTrack != null) { tracks.remove(generalTrack); this.generalTrack = null; @@ -1202,20 +1201,22 @@ public class GPXUtilities { "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"); for (Track track : file.tracks) { - serializer.startTag(null, "trk"); //$NON-NLS-1$ - writeNotNullText(serializer, "name", track.name); - writeNotNullText(serializer, "desc", track.desc); - for (TrkSegment segment : track.segments) { - serializer.startTag(null, "trkseg"); //$NON-NLS-1$ - for (WptPt p : segment.points) { - serializer.startTag(null, "trkpt"); //$NON-NLS-1$ - writeWpt(format, serializer, p); - serializer.endTag(null, "trkpt"); //$NON-NLS-1$ + if (!track.generalTrack) { + serializer.startTag(null, "trk"); //$NON-NLS-1$ + writeNotNullText(serializer, "name", track.name); + writeNotNullText(serializer, "desc", track.desc); + for (TrkSegment segment : track.segments) { + serializer.startTag(null, "trkseg"); //$NON-NLS-1$ + for (WptPt p : segment.points) { + serializer.startTag(null, "trkpt"); //$NON-NLS-1$ + writeWpt(format, serializer, p); + serializer.endTag(null, "trkpt"); //$NON-NLS-1$ + } + serializer.endTag(null, "trkseg"); //$NON-NLS-1$ } - serializer.endTag(null, "trkseg"); //$NON-NLS-1$ + writeExtensions(serializer, track); + serializer.endTag(null, "trk"); //$NON-NLS-1$ } - writeExtensions(serializer, track); - serializer.endTag(null, "trk"); //$NON-NLS-1$ } for (Route track : file.routes) { diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 754822a9c9..9bfb1469c1 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -255,7 +255,7 @@ public class MapMarkersHelper { List activeMarkers = markersDbHelper.getActiveMarkers(); mapMarkers.addAll(activeMarkers); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); List markersHistory = markersDbHelper.getMarkersHistory(); sortMarkers(markersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); @@ -266,7 +266,7 @@ public class MapMarkersHelper { } } - public void checkAndFixActiveMarkersOrderIfNeeded() { + public void reorderActiveMarkersIfNeeded() { if (!mapMarkers.isEmpty()) { if (mapMarkers.size() > 1) { for (int i = 0; i < mapMarkers.size() - 1; i++) { @@ -322,7 +322,7 @@ public class MapMarkersHelper { public void orderMarkers(OsmandSettings.MapMarkersOrderByMode orderByMode) { sortMarkers(getMapMarkers(), false, orderByMode); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); } private void lookupAddress(final MapMarker mapMarker) { @@ -445,7 +445,7 @@ public class MapMarkersHelper { } } if (needRefresh) { - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); refresh(); } } @@ -459,7 +459,7 @@ public class MapMarkersHelper { marker.history = true; marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE; mapMarkersHistory.add(marker); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); refresh(); } @@ -473,7 +473,7 @@ public class MapMarkersHelper { sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); } else { mapMarkers.add(marker); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); } addMarkerToGroup(marker); refresh(); @@ -488,7 +488,7 @@ public class MapMarkersHelper { sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); } else { mapMarkers.add(position, marker); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); } addMarkerToGroup(marker); refresh(); @@ -501,7 +501,7 @@ public class MapMarkersHelper { mapMarkersHistory.remove(marker); marker.history = false; mapMarkers.add(position, marker); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); refresh(); } @@ -515,8 +515,9 @@ public class MapMarkersHelper { marker.history = false; mapMarkers.add(marker); } - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); + updateGroups(); refresh(); } } @@ -579,6 +580,36 @@ public class MapMarkersHelper { return list; } + public int getSelectedMarkersCount() { + int res = 0; + for (MapMarker m : this.mapMarkers) { + if (m.selected) { + res++; + } + } + return res; + } + + public void addSelectedMarkersToTop(@NonNull List markers) { + List markersToRemove = new LinkedList<>(); + for (MapMarker m : mapMarkers) { + if (m.selected) { + if (!markers.contains(m)) { + return; + } + markersToRemove.add(m); + } + } + if (markersToRemove.size() != markers.size()) { + return; + } + + mapMarkers.removeAll(markersToRemove); + mapMarkers.addAll(0, markers); + reorderActiveMarkersIfNeeded(); + ctx.getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM); + } + public List getActiveMarkersLatLon() { List list = new ArrayList<>(); for (MapMarker m : this.mapMarkers) { @@ -608,7 +639,8 @@ public class MapMarkersHelper { public void reverseActiveMarkersOrder() { cancelAddressRequests(); Collections.reverse(mapMarkers); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); + ctx.getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM); } public void moveAllActiveMarkersToHistory() { @@ -623,6 +655,7 @@ public class MapMarkersHelper { mapMarkersHistory.addAll(mapMarkers); mapMarkers.clear(); sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); + updateGroups(); refresh(); } @@ -675,7 +708,7 @@ public class MapMarkersHelper { iterator.remove(); } } - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); refresh(); } } @@ -727,7 +760,7 @@ public class MapMarkersHelper { markersDbHelper.addMarker(marker); mapMarkers.add(0, marker); addMarkerToGroup(marker); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); } } } @@ -750,7 +783,7 @@ public class MapMarkersHelper { } marker.point = point; markersDbHelper.updateMarker(marker); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); refresh(); lookupAddress(marker); } @@ -761,7 +794,7 @@ public class MapMarkersHelper { if (i != -1 && mapMarkers.size() > 1) { mapMarkers.remove(i); mapMarkers.add(0, marker); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); refresh(); } } @@ -897,6 +930,12 @@ public class MapMarkersHelper { } } + public void updateGroups() { + for (MapMarkersGroup group : mapMarkersGroups) { + updateGroup(group); + } + } + public void updateGroup(MapMarkersGroup mapMarkersGroup) { if (mapMarkersGroup.getMarkers().size() == 0) { mapMarkersGroups.remove(mapMarkersGroup); @@ -957,7 +996,7 @@ public class MapMarkersHelper { 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.setIconRes(type == MapMarkersHelper.MarkersSyncGroup.FAVORITES_TYPE ? R.drawable.ic_action_fav_dark : R.drawable.ic_action_polygom_dark); } header.setGroup(group); group.setGroupHeader(header); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java index f60fb6941e..c1248da2a0 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java @@ -20,6 +20,8 @@ import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dashboard.tools.DashFragmentData; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; /** @@ -80,6 +82,7 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment { return; } else { mainView.setVisibility(View.VISIBLE); + sortItemsDescending(notes); } LinearLayout notesLayout = (LinearLayout) mainView.findViewById(R.id.items); @@ -115,6 +118,23 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment { } } + private void sortItemsDescending(List items) { + Collections.sort(items, new Comparator() { + @Override + public int compare(AudioVideoNotesPlugin.Recording first, AudioVideoNotesPlugin.Recording second) { + long firstTime = first.getLastModified(); + long secondTime = second.getLastModified(); + if (firstTime < secondTime) { + return 1; + } else if (firstTime == secondTime) { + return 0; + } else { + return -1; + } + } + }); + } + public static Drawable getNoteView(final AudioVideoNotesPlugin.Recording recording, View view, final OsmandApplication ctx) { String name = recording.getName(ctx, true); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 86e41c349e..3afdfbdf74 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -368,6 +368,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL fragmentRef.get().centerMarkerLocation(); } } + updateWidgetsVisibility(false); } public void show(@NonNull LatLon latLon, @@ -388,6 +389,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } centerMarker = false; autoHide = false; + updateWidgetsVisibility(false); } public void update(LatLon latLon, PointDescription pointDescription, Object object) { @@ -446,6 +448,15 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL if (fragmentRef != null) { fragmentRef.get().dismissMenu(); } + updateWidgetsVisibility(true); + } + + private void updateWidgetsVisibility(boolean visible) { + int visibility = visible ? View.VISIBLE : View.GONE; + mapActivity.findViewById(R.id.map_center_info).setVisibility(visibility); + mapActivity.findViewById(R.id.map_left_widgets_panel).setVisibility(visibility); + mapActivity.findViewById(R.id.map_right_widgets_panel).setVisibility(visibility); + mapActivity.refreshMap(); } // timeout in msec @@ -638,15 +649,15 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } if (searchDoneAction != null) { - if (searchDoneAction.dlg != null) { - try { - searchDoneAction.dlg.dismiss(); - } catch (Exception e) { - // ignore - } finally { - searchDoneAction.dlg = null; - } + if (searchDoneAction.dlg != null) { + try { + searchDoneAction.dlg.dismiss(); + } catch (Exception e) { + // ignore + } finally { + searchDoneAction.dlg = null; } + } searchDoneAction.run(); searchDoneAction = null; } @@ -713,7 +724,6 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } - public void buttonFavoritePressed() { if (object != null && object instanceof FavouritePoint) { getFavoritePointEditor().edit((FavouritePoint) object); @@ -815,7 +825,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } } - public void addWptPt(LatLon latLon, String title, String categoryName, int categoryColor, boolean skipDialog){ + public void addWptPt(LatLon latLon, String title, String categoryName, int categoryColor, boolean skipDialog) { final List list = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles(); @@ -833,7 +843,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } } - public AlertDialog addNewWptToGPXFile(final LatLon latLon, final String title, + public AlertDialog addNewWptToGPXFile(final LatLon latLon, final String title, final String categoryName, final int categoryColor, final boolean skipDialog) { CallbackWithObject callbackWithObject = new CallbackWithObject() { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 82fdef7d74..f23e3f003f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -76,7 +76,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL toPosition = holder.getAdapterPosition(); if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) { hideSnackbar(); - mapActivity.getMyApplication().getMapMarkersHelper().checkAndFixActiveMarkersOrderIfNeeded(); + mapActivity.getMyApplication().getMapMarkersHelper().reorderActiveMarkersIfNeeded(); adapter.notifyDataSetChanged(); mapActivity.getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 81985824b0..b1c17d407d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -141,6 +141,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm case R.id.action_active: activeFragment.startLocationUpdate(); if (viewPager.getCurrentItem() != 0) { + hideSnackbar(); activeFragment.updateAdapter(); historyFragment.hideSnackbar(); groupsFragment.hideSnackbar(); @@ -151,6 +152,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm case R.id.action_groups: activeFragment.stopLocationUpdate(); if (viewPager.getCurrentItem() != 1) { + hideSnackbar(); groupsFragment.updateAdapter(); activeFragment.hideSnackbar(); historyFragment.hideSnackbar(); @@ -161,6 +163,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm case R.id.action_history: activeFragment.stopLocationUpdate(); if (viewPager.getCurrentItem() != 2) { + hideSnackbar(); historyFragment.updateAdapter(); groupsFragment.hideSnackbar(); activeFragment.hideSnackbar(); @@ -296,6 +299,12 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm } } + private void hideSnackbar() { + if (snackbar != null && snackbar.isShown()) { + snackbar.dismiss(); + } + } + private MapActivity getMapActivity() { return (MapActivity) getActivity(); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index dd5c0206ed..49fde71664 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -1,6 +1,8 @@ package net.osmand.plus.mapmarkers; +import android.app.ProgressDialog; import android.graphics.drawable.Drawable; +import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.support.annotation.DrawableRes; @@ -23,6 +25,7 @@ import android.widget.Toast; import net.osmand.AndroidUtils; import net.osmand.Location; +import net.osmand.TspAnt; import net.osmand.data.LatLon; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ApplicationMode; @@ -31,11 +34,13 @@ import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; 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.PlanRouteSortByBottomSheetDialogFragment.PlanRouteSortByFragmentListener; import net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback; import net.osmand.plus.mapmarkers.adapters.MapMarkersListAdapter; import net.osmand.plus.measurementtool.RecyclerViewFragment; @@ -47,6 +52,7 @@ import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.util.MapUtils; +import java.util.ArrayList; import java.util.List; import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT; @@ -92,6 +98,10 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene if (snapToRoadFragment != null) { ((SnapToRoadBottomSheetDialogFragment) snapToRoadFragment).setListener(createSnapToRoadFragmentListener()); } + Fragment sortByFragment = fragmentManager.findFragmentByTag(PlanRouteSortByBottomSheetDialogFragment.TAG); + if (sortByFragment != null) { + ((PlanRouteSortByBottomSheetDialogFragment) sortByFragment).setListener(createSortByFragmentListener()); + } // 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) { @@ -125,7 +135,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene 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)); + ((ImageView) mainView.findViewById(R.id.sort_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_list_sort)); mainView.findViewById(R.id.up_down_row).setOnClickListener(new View.OnClickListener() { @Override @@ -162,7 +172,9 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene mainView.findViewById(R.id.sort_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Toast.makeText(mapActivity, "Sort", Toast.LENGTH_SHORT).show(); + PlanRouteSortByBottomSheetDialogFragment fragment = new PlanRouteSortByBottomSheetDialogFragment(); + fragment.setListener(createSortByFragmentListener()); + fragment.show(mapActivity.getSupportFragmentManager(), PlanRouteSortByBottomSheetDialogFragment.TAG); } }); @@ -203,6 +215,9 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene @Override public void onItemClick(View view) { int pos = markersRv.getChildAdapterPosition(view); + if (pos == RecyclerView.NO_POSITION) { + return; + } if (pos == 0) { markersHelper.setStartFromMyLocation(!mapActivity.getMyApplication().getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.get()); } else { @@ -227,7 +242,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene public void onDragEnded(RecyclerView.ViewHolder holder) { toPosition = holder.getAdapterPosition(); if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) { - mapActivity.getMyApplication().getMapMarkersHelper().checkAndFixActiveMarkersOrderIfNeeded(); + mapActivity.getMyApplication().getMapMarkersHelper().reorderActiveMarkersIfNeeded(); mapActivity.getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM); mapActivity.refreshMap(); try { @@ -345,6 +360,33 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene }; } + private PlanRouteSortByFragmentListener createSortByFragmentListener() { + return new PlanRouteSortByFragmentListener() { + + private MapActivity mapActivity = getMapActivity(); + + @Override + public void doorToDoorOnClick() { + if (mapActivity != null) { + OsmandApplication app = mapActivity.getMyApplication(); + Location myLoc = app.getLocationProvider().getLastStaleKnownLocation(); + boolean startFromLocation = app.getMapMarkersHelper().isStartFromMyLocation() && myLoc != null; + if (selectedCount > (startFromLocation ? 0 : 1)) { + sortSelectedMarkersDoorToDoor(mapActivity, startFromLocation, myLoc); + } + } + } + + @Override + public void reverseOrderOnClick() { + if (mapActivity != null) { + markersHelper.reverseActiveMarkersOrder(); + adapter.notifyDataSetChanged(); + } + } + }; + } + private void enterPlanRouteMode() { final MapActivity mapActivity = getMapActivity(); MapMarkersLayer markersLayer = getMapMarkersLayer(); @@ -377,6 +419,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene } setupAppModesBtn(); + selectedCount = mapActivity.getMyApplication().getMapMarkersHelper().getSelectedMarkersCount(); showMarkersRouteOnMap(); mapActivity.refreshMap(); updateText(); @@ -672,6 +715,68 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene } } + private void sortSelectedMarkersDoorToDoor(final MapActivity mapActivity, final boolean startFromLoc, final Location myLoc) { + new AsyncTask>() { + + private ProgressDialog dialog; + private long startDialogTime; + + @Override + protected void onPreExecute() { + startDialogTime = System.currentTimeMillis(); + dialog = new ProgressDialog(mapActivity); + dialog.setTitle(""); + dialog.setMessage(mapActivity.getString(R.string.intermediate_items_sort_by_distance)); + dialog.setCancelable(false); + dialog.show(); + } + + @Override + protected List doInBackground(Void... voids) { + MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper(); + List selectedMarkers = markersHelper.getSelectedMarkers(); + List selectedLatLon = markersHelper.getSelectedMarkersLatLon(); + + LatLon start = startFromLoc ? new LatLon(myLoc.getLatitude(), myLoc.getLongitude()) : selectedLatLon.remove(0); + LatLon end = selectedLatLon.remove(selectedLatLon.size() - 1); + + int[] sequence = new TspAnt().readGraph(selectedLatLon, start, end).solve(); + + List res = new ArrayList<>(); + for (int i = 0; i < sequence.length; i++) { + if (i == 0 && startFromLoc) { + continue; + } + int index = sequence[startFromLoc ? i - 1 : i]; + res.add(selectedMarkers.get(index)); + } + + return res; + } + + @Override + protected void onPostExecute(List res) { + if (dialog != null) { + long t = System.currentTimeMillis(); + if (t - startDialogTime < 500) { + mapActivity.getMyApplication().runInUIThread(new Runnable() { + @Override + public void run() { + dialog.dismiss(); + } + }, 500 - (t - startDialogTime)); + } else { + dialog.dismiss(); + } + } + + mapActivity.getMyApplication().getMapMarkersHelper().addSelectedMarkersToTop(res); + + adapter.notifyDataSetChanged(); + } + }.execute(); + } + private class PlanRouteToolbarController extends TopToolbarController { PlanRouteToolbarController() { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteSortByBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteSortByBottomSheetDialogFragment.java new file mode 100644 index 0000000000..016b76897f --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteSortByBottomSheetDialogFragment.java @@ -0,0 +1,142 @@ +package net.osmand.plus.mapmarkers; + +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.DrawableRes; +import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; +import android.view.ContextThemeWrapper; +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.ImageView; +import android.widget.TextView; + +import net.osmand.AndroidUtils; +import net.osmand.plus.R; +import net.osmand.plus.base.BottomSheetDialogFragment; +import net.osmand.plus.helpers.AndroidUiHelper; + +public class PlanRouteSortByBottomSheetDialogFragment extends BottomSheetDialogFragment { + + public final static String TAG = "PlanRouteSortByBottomSheetDialogFragment"; + + private boolean portrait; + private boolean night; + private PlanRouteSortByFragmentListener listener; + + public void setListener(PlanRouteSortByFragmentListener listener) { + this.listener = listener; + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); + night = getMyApplication().getDaynightHelper().isNightModeForMapControls(); + final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + + final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_plan_route_sort_by_bottom_sheet_dialog, container); + if (portrait) { + AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); + } + + if (night) { + ((TextView) mainView.findViewById(R.id.title)).setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark)); + } + + ((ImageView) mainView.findViewById(R.id.door_to_door_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_door_to_door)); + ((ImageView) mainView.findViewById(R.id.reverse_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_reverse_order)); + + mainView.findViewById(R.id.door_to_door_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.doorToDoorOnClick(); + dismiss(); + } + } + }); + mainView.findViewById(R.id.reverse_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.reverseOrderOnClick(); + dismiss(); + } + } + }); + + mainView.findViewById(R.id.cancel_row).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() { + @Override + public void onGlobalLayout() { + final View scrollView = mainView.findViewById(R.id.sort_by_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); + } + } + + ViewTreeObserver obs = mainView.getViewTreeObserver(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + obs.removeOnGlobalLayoutListener(this); + } else { + obs.removeGlobalOnLayoutListener(this); + } + } + }); + + 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); + } + } + + @Override + protected Drawable getContentIcon(@DrawableRes int id) { + return getIcon(id, night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); + } + + interface PlanRouteSortByFragmentListener { + + void doorToDoorOnClick(); + + void reverseOrderOnClick(); + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java index 0b918466ba..b1aa3d0c3a 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java @@ -18,6 +18,7 @@ import android.widget.LinearLayout; import net.osmand.AndroidUtils; import net.osmand.IndexConstants; +import net.osmand.plus.OsmandTextFieldBoxes; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BottomSheetDialogFragment; @@ -79,7 +80,10 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm } final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text); nameEditText.setText(displayedName); - nameEditText.requestFocus(); + View textBox = mainView.findViewById(R.id.name_text_box); + if (textBox instanceof OsmandTextFieldBoxes) { + ((OsmandTextFieldBoxes) textBox).activate(true); + } mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index ee065546e5..5ed5300f12 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -394,6 +394,11 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter activeMapMarkers = markersHelper.getMapMarkers(); @@ -237,7 +236,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi canvas.drawPath(path, paint); } - if (settings.SHOW_LINES_TO_FIRST_MARKERS.get() && myLoc != null) { + if (markersHelper.isStartFromMyLocation() && myLoc != null) { lineAttrs.updatePaints(view, nightMode, tileBox); textAttrs.updatePaints(view, nightMode, tileBox); textAttrs.paint.setStyle(Paint.Style.FILL); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index b811242940..05b85c3296 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -577,7 +577,7 @@ public class MapInfoWidgetsFactory { initToolbar(defaultController); defaultController.updateToolbar(this); } - updateVisibility(controller != null); + updateVisibility(controller != null && (!map.getContextMenu().isVisible() || controller.getType() == TopToolbarControllerType.CONTEXT_MENU)); } public void updateColors(TopToolbarController controller) { @@ -801,7 +801,7 @@ public class MapInfoWidgetsFactory { } } } - if (map.isTopToolbarActive()) { + if (map.isTopToolbarActive() || map.getContextMenu().isVisible()) { updateVisibility(false); } else if (!showNextTurn && updateWaypoint()) { updateVisibility(true); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index c294f3d18b..c8d4602d85 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -197,7 +197,8 @@ public class MapMarkersWidgetsFactory { || map.getMyApplication().getRoutingHelper().isRoutePlanningMode() || MapRouteInfoMenu.isVisible() || addressTopBar.getVisibility() == View.VISIBLE - || map.isTopToolbarActive()) { + || map.isTopToolbarActive() + || map.getContextMenu().isVisible()) { updateVisibility(false); return; }