From 089e410ca63ac28095901413a14d3b630e704c06 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 29 Sep 2017 18:29:14 +0300 Subject: [PATCH 01/23] Add sort by menu; add small fixes in UI --- .../res/layout-land/fragment_plan_route.xml | 2 +- OsmAnd/res/layout/fragment_plan_route.xml | 2 +- ...plan_route_sort_by_bottom_sheet_dialog.xml | 117 +++++++++++++++ .../plus/mapmarkers/PlanRouteFragment.java | 32 +++- ...nRouteSortByBottomSheetDialogFragment.java | 142 ++++++++++++++++++ 5 files changed, 291 insertions(+), 4 deletions(-) create mode 100644 OsmAnd/res/layout/fragment_plan_route_sort_by_bottom_sheet_dialog.xml create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteSortByBottomSheetDialogFragment.java 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"/> + tools:src="@drawable/ic_action_list_sort"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index dd5c0206ed..c338c21cf8 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -36,6 +36,7 @@ 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; @@ -92,6 +93,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 +130,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 +167,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); } }); @@ -345,6 +352,27 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene }; } + private PlanRouteSortByFragmentListener createSortByFragmentListener() { + return new PlanRouteSortByFragmentListener() { + + private MapActivity mapActivity = getMapActivity(); + + @Override + public void doorByDoorOnClick() { + if (mapActivity != null) { + Toast.makeText(mapActivity, "Door to Door", Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void reverseOrderOnClick() { + if (mapActivity != null) { + Toast.makeText(mapActivity, "Reverse order", Toast.LENGTH_SHORT).show(); + } + } + }; + } + private void enterPlanRouteMode() { final MapActivity mapActivity = getMapActivity(); MapMarkersLayer markersLayer = getMapMarkersLayer(); 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..9008068b4f --- /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.doorByDoorOnClick(); + 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 doorByDoorOnClick(); + + void reverseOrderOnClick(); + } +} From 32986f1b648d48f23b7a431bc4e4ab20e4b096f2 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 29 Sep 2017 18:47:30 +0300 Subject: [PATCH 02/23] Add reverse order functionality --- OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java | 4 +++- .../plus/mapmarkers/adapters/MapMarkersListAdapter.java | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index c338c21cf8..466cfbd386 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -367,7 +367,9 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene @Override public void reverseOrderOnClick() { if (mapActivity != null) { - Toast.makeText(mapActivity, "Reverse order", Toast.LENGTH_SHORT).show(); + markersHelper.reverseActiveMarkersOrder(); + mapActivity.getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM); + adapter.reloadMarkers(); } } }; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java index 5ded437f6a..1cf3468c96 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java @@ -186,6 +186,11 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter Date: Fri, 29 Sep 2017 18:58:48 +0300 Subject: [PATCH 03/23] Fix #4417 --- .../src/net/osmand/plus/mapcontextmenu/MapContextMenu.java | 1 + .../osmand/plus/mapcontextmenu/MapContextMenuFragment.java | 7 +++++++ OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 34ff60c127..37aa6dca77 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -445,6 +445,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL if (fragmentRef != null) { fragmentRef.get().dismissMenu(); } + mapActivity.getMapLayers().getMapControlsLayer().changeMarkersAndWidgetsVisibility(true); } // timeout in msec diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 3e85f4a5c5..92036f1ca7 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -46,6 +46,7 @@ import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController; import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; import net.osmand.plus.views.AnimateDraggingMapThread; +import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.controls.HorizontalSwipeConfirm; import net.osmand.plus.views.controls.SingleTapConfirm; @@ -106,11 +107,15 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { private int screenOrientation; private boolean created; + private MapControlsLayer mapControlsLayer; + @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + mapControlsLayer = getMapActivity().getMapLayers().getMapControlsLayer(); + processScreenHeight(container); fabPaddingTopPx = dpToPx(FAB_PADDING_TOP_DP); @@ -528,6 +533,8 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { doBeforeMenuStateChange(oldMenuState, newMenuState); } + mapControlsLayer.changeMarkersAndWidgetsVisibility(newMenuState == MenuState.HEADER_ONLY); + applyPosY(currentY, needCloseMenu, needMapAdjust, oldMenuState, newMenuState); } diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index e50ad180cb..4565e7c740 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -1214,4 +1214,9 @@ public class MapControlsLayer extends OsmandMapLayer { addDestination(requestedLatLon); } } + + public void changeMarkersAndWidgetsVisibility(boolean visible) { + mapActivity.findViewById(R.id.map_markers_top_bar).setVisibility(visible ? View.VISIBLE : View.GONE); + mapActivity.findViewById(R.id.map_right_widgets_panel).setVisibility(visible ? View.VISIBLE : View.GONE); + } } From 50fcf38f00c326c36669ea0187aef96cbb3fb550 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Fri, 29 Sep 2017 21:02:21 +0300 Subject: [PATCH 04/23] Fix topbar --- .../plus/mapcontextmenu/MapContextMenu.java | 18 +++++++++++++++- .../MapContextMenuFragment.java | 21 ++++++++++++++----- .../osmand/plus/views/MapControlsLayer.java | 5 ----- .../net/osmand/plus/views/MapInfoLayer.java | 4 ++++ .../mapwidgets/MapMarkersWidgetsFactory.java | 7 ++++++- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 4824ea7102..0f0ea9aab5 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -47,9 +47,11 @@ import net.osmand.plus.mapcontextmenu.other.ShareMenu; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.ContextMenuLayer; +import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; +import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -63,6 +65,8 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL private MapActivity mapActivity; private OsmandSettings settings; private MapMultiSelectionMenu mapMultiSelectionMenu; + private MapInfoLayer mapInfoLayer; + private MapMarkersWidgetsFactory mapMarkersWidgetsFactory; private FavoritePointEditor favoritePointEditor; private WptPtEditor wptPtEditor; @@ -290,6 +294,9 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL myLocation = mapActivity.getMyApplication().getSettings().getLastKnownMapLocation(); } + mapInfoLayer = mapActivity.getMapLayers().getMapInfoLayer(); + mapMarkersWidgetsFactory = mapActivity.getMapLayers().getMapMarkersLayer().getWidgetsFactory(); + if (!update && isVisible()) { if (this.object == null || !this.object.equals(object)) { hide(); @@ -446,7 +453,16 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL if (fragmentRef != null) { fragmentRef.get().dismissMenu(); } - mapActivity.getMapLayers().getMapControlsLayer().changeMarkersAndWidgetsVisibility(true); + + makeTopbarAndRightStackVisible(); + } + + private void makeTopbarAndRightStackVisible() { + mapInfoLayer.updateRightStackVisibility(true); + if (getMapActivity().getMyApplication().getSettings().MAP_MARKERS_MODE.get() == OsmandSettings.MapMarkersMode.TOOLBAR) { + mapMarkersWidgetsFactory.lockTopBarVisibility(true); + mapMarkersWidgetsFactory.updateVisibility(true); + } } // timeout in msec diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 92036f1ca7..6193daef84 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -46,10 +46,11 @@ import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController; import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; import net.osmand.plus.views.AnimateDraggingMapThread; -import net.osmand.plus.views.MapControlsLayer; +import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.controls.HorizontalSwipeConfirm; import net.osmand.plus.views.controls.SingleTapConfirm; +import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory; import net.osmand.util.Algorithms; import static android.util.TypedValue.COMPLEX_UNIT_DIP; @@ -69,6 +70,9 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { private View mainView; ImageView fabView; + private MapInfoLayer mapInfoLayer; + private MapMarkersWidgetsFactory mapMarkersWidgetsFactory; + private MapContextMenu menu; private OnLayoutChangeListener containerLayoutListener; @@ -107,14 +111,13 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { private int screenOrientation; private boolean created; - private MapControlsLayer mapControlsLayer; - @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - mapControlsLayer = getMapActivity().getMapLayers().getMapControlsLayer(); + mapInfoLayer = getMapActivity().getMapLayers().getMapInfoLayer(); + mapMarkersWidgetsFactory = getMapActivity().getMapLayers().getMapMarkersLayer().getWidgetsFactory(); processScreenHeight(container); @@ -533,11 +536,19 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { doBeforeMenuStateChange(oldMenuState, newMenuState); } - mapControlsLayer.changeMarkersAndWidgetsVisibility(newMenuState == MenuState.HEADER_ONLY); + updateTopbarAndRightStackVisibility(newMenuState == MenuState.HEADER_ONLY); applyPosY(currentY, needCloseMenu, needMapAdjust, oldMenuState, newMenuState); } + private void updateTopbarAndRightStackVisibility(boolean visible) { + mapInfoLayer.updateRightStackVisibility(visible); + if (getMyApplication().getSettings().MAP_MARKERS_MODE.get() == OsmandSettings.MapMarkersMode.TOOLBAR) { + mapMarkersWidgetsFactory.lockTopBarVisibility(visible); + mapMarkersWidgetsFactory.updateVisibility(visible); + } + } + private void applyPosY(final int currentY, final boolean needCloseMenu, boolean needMapAdjust, final int previousMenuState, final int newMenuState) { final int posY = getPosY(needCloseMenu); diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index c605af3095..b78c7e2aa5 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -1210,9 +1210,4 @@ public class MapControlsLayer extends OsmandMapLayer { addDestination(requestedLatLon); } } - - public void changeMarkersAndWidgetsVisibility(boolean visible) { - mapActivity.findViewById(R.id.map_markers_top_bar).setVisibility(visible ? View.VISIBLE : View.GONE); - mapActivity.findViewById(R.id.map_right_widgets_panel).setVisibility(visible ? View.VISIBLE : View.GONE); - } } diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index 74e706bc96..29f01286d4 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -221,6 +221,10 @@ public class MapInfoLayer extends OsmandMapLayer { }); } + public void updateRightStackVisibility(boolean visible) { + rightStack.setVisibility(visible ? View.VISIBLE : View.GONE); + } + public void setTrackChartPoints(TrackChartPoints trackChartPoints) { this.trackChartPoints = trackChartPoints; routeLayer.setTrackChartPoints(trackChartPoints); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index c294f3d18b..494207e808 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -36,6 +36,7 @@ public class MapMarkersWidgetsFactory { private MapMarkersHelper helper; private int screenOrientation; private boolean portraitMode; + private boolean topBarCanBeShown = true; private View topBar; private View addressTopBar; @@ -148,8 +149,12 @@ public class MapMarkersWidgetsFactory { } } + public void lockTopBarVisibility(boolean visible) { + topBarCanBeShown = visible; + } + public boolean updateVisibility(boolean visible) { - return updateVisibility(topBar, visible); + return (topBarCanBeShown || !visible) && updateVisibility(topBar, visible); } public boolean updateVisibility(View v, boolean visible) { From 19f91cf13d98c8b5e38c3dd585eb502b9b6d207f Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 30 Sep 2017 15:43:53 +0300 Subject: [PATCH 05/23] Do not open keyboard in save as track dialog --- OsmAnd/res/layout/markers_track_name_edit_text.xml | 1 + OsmAnd/res/layout/markers_track_name_text_field_box.xml | 5 +++-- .../mapmarkers/SaveAsTrackBottomSheetDialogFragment.java | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) 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/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 From d5fc87fa4430db506ee28c3247d6c59131a82e5a Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 30 Sep 2017 15:59:35 +0300 Subject: [PATCH 06/23] Save as track dialog styling --- .../res/layout/fragment_marker_options_bottom_sheet_dialog.xml | 2 +- .../fragment_marker_save_as_track_bottom_sheet_dialog.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 eb047321cc..4c1fc387ae 100644 --- a/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml @@ -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"> Date: Sat, 30 Sep 2017 16:13:14 +0300 Subject: [PATCH 07/23] Fix groups when move all to history --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 8 ++++++++ .../osmand/plus/mapmarkers/MapMarkersDialogFragment.java | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 754822a9c9..bab63c02e3 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -517,6 +517,7 @@ public class MapMarkersHelper { } checkAndFixActiveMarkersOrderIfNeeded(); sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); + updateGroups(); refresh(); } } @@ -623,6 +624,7 @@ public class MapMarkersHelper { mapMarkersHistory.addAll(mapMarkers); mapMarkers.clear(); sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); + updateGroups(); refresh(); } @@ -897,6 +899,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); 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(); } From 0418b84022db3b86676d5c68a9b6d0ccc92d9b98 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 30 Sep 2017 16:34:56 +0300 Subject: [PATCH 08/23] Markers groups styling --- .../map_marker_item_show_hide_history.xml | 40 ++++++++++++------- .../src/net/osmand/plus/MapMarkersHelper.java | 2 +- .../adapters/MapMarkersGroupsAdapter.java | 5 +++ .../MapMarkersShowHideHistoryViewHolder.java | 3 ++ 4 files changed, 35 insertions(+), 15 deletions(-) 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/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index bab63c02e3..f43c332d12 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -965,7 +965,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/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 Date: Mon, 2 Oct 2017 11:34:13 +0300 Subject: [PATCH 09/23] Change logic --- OsmAnd/res/layout-land/map_hud_top.xml | 309 +++++++++--------- OsmAnd/res/layout/map_hud_top.xml | 287 ++++++++-------- .../osmand/plus/activities/MapActivity.java | 5 + .../plus/mapcontextmenu/MapContextMenu.java | 58 ++-- .../MapContextMenuFragment.java | 18 - .../net/osmand/plus/views/MapInfoLayer.java | 8 +- .../mapwidgets/MapMarkersWidgetsFactory.java | 7 +- 7 files changed, 348 insertions(+), 344 deletions(-) diff --git a/OsmAnd/res/layout-land/map_hud_top.xml b/OsmAnd/res/layout-land/map_hud_top.xml index 1772881368..01cb2124bb 100644 --- a/OsmAnd/res/layout-land/map_hud_top.xml +++ b/OsmAnd/res/layout-land/map_hud_top.xml @@ -7,184 +7,191 @@ android:orientation="vertical"> + android:layout_height="wrap_content"> - + 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"> + + + + + + + + + + - - + - + - + + + + + + + + + + + + + + + + + + + + + + + + - - - + diff --git a/OsmAnd/res/layout/map_hud_top.xml b/OsmAnd/res/layout/map_hud_top.xml index 6a4ad821e0..e92f9ce1a3 100644 --- a/OsmAnd/res/layout/map_hud_top.xml +++ b/OsmAnd/res/layout/map_hud_top.xml @@ -285,173 +285,180 @@ + android:layout_height="wrap_content"> - + 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/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index a20d730996..3662cd752a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1753,6 +1753,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return mapInfoLayer.getTopToolbarController(type); } + public TopToolbarController getTopToolbarController() { + MapInfoLayer mapInfoLayer = getMapLayers().getMapInfoLayer(); + return mapInfoLayer.getTopController(); + } + public void showTopToolbar(TopToolbarController controller) { MapInfoLayer mapInfoLayer = getMapLayers().getMapInfoLayer(); mapInfoLayer.addTopToolbarController(controller); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 0f0ea9aab5..1b3ecb0ec8 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -47,11 +47,9 @@ import net.osmand.plus.mapcontextmenu.other.ShareMenu; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.ContextMenuLayer; -import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; -import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -65,8 +63,6 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL private MapActivity mapActivity; private OsmandSettings settings; private MapMultiSelectionMenu mapMultiSelectionMenu; - private MapInfoLayer mapInfoLayer; - private MapMarkersWidgetsFactory mapMarkersWidgetsFactory; private FavoritePointEditor favoritePointEditor; private WptPtEditor wptPtEditor; @@ -294,9 +290,6 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL myLocation = mapActivity.getMyApplication().getSettings().getLastKnownMapLocation(); } - mapInfoLayer = mapActivity.getMapLayers().getMapInfoLayer(); - mapMarkersWidgetsFactory = mapActivity.getMapLayers().getMapMarkersLayer().getWidgetsFactory(); - if (!update && isVisible()) { if (this.object == null || !this.object.equals(object)) { hide(); @@ -375,6 +368,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL fragmentRef.get().centerMarkerLocation(); } } + updateWidgetsAndTopbarsVisibility(false); } public void show(@NonNull LatLon latLon, @@ -395,6 +389,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } centerMarker = false; autoHide = false; + updateWidgetsAndTopbarsVisibility(false); } public void update(LatLon latLon, PointDescription pointDescription, Object object) { @@ -453,16 +448,30 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL if (fragmentRef != null) { fragmentRef.get().dismissMenu(); } - - makeTopbarAndRightStackVisible(); + updateWidgetsAndTopbarsVisibility(true); } - private void makeTopbarAndRightStackVisible() { - mapInfoLayer.updateRightStackVisibility(true); - if (getMapActivity().getMyApplication().getSettings().MAP_MARKERS_MODE.get() == OsmandSettings.MapMarkersMode.TOOLBAR) { - mapMarkersWidgetsFactory.lockTopBarVisibility(true); - mapMarkersWidgetsFactory.updateVisibility(true); + private void updateWidgetsAndTopbarsVisibility(boolean visible) { + updateVisibility(mapActivity.findViewById(R.id.map_markers_top_bar_layout), visible); + TopToolbarController controller = mapActivity.getTopToolbarController(); + if (controller != null && controller.getType() != TopToolbarControllerType.CONTEXT_MENU) { + updateVisibility(mapActivity.findViewById(R.id.widget_top_bar), visible); } + updateVisibility(mapActivity.findViewById(R.id.map_left_widgets_panel), visible); + updateVisibility(mapActivity.findViewById(R.id.map_right_widgets_panel), visible); + } + + public boolean updateVisibility(View v, boolean visible) { + if (visible != (v.getVisibility() == View.VISIBLE)) { + if (visible) { + v.setVisibility(View.VISIBLE); + } else { + v.setVisibility(View.GONE); + } + v.invalidate(); + return true; + } + return false; } // timeout in msec @@ -655,15 +664,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; } @@ -730,7 +739,6 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } - public void buttonFavoritePressed() { if (object != null && object instanceof FavouritePoint) { getFavoritePointEditor().edit((FavouritePoint) object); @@ -832,7 +840,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(); @@ -850,7 +858,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/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 6193daef84..3e85f4a5c5 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -46,11 +46,9 @@ import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController; import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; import net.osmand.plus.views.AnimateDraggingMapThread; -import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.controls.HorizontalSwipeConfirm; import net.osmand.plus.views.controls.SingleTapConfirm; -import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory; import net.osmand.util.Algorithms; import static android.util.TypedValue.COMPLEX_UNIT_DIP; @@ -70,9 +68,6 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { private View mainView; ImageView fabView; - private MapInfoLayer mapInfoLayer; - private MapMarkersWidgetsFactory mapMarkersWidgetsFactory; - private MapContextMenu menu; private OnLayoutChangeListener containerLayoutListener; @@ -116,9 +111,6 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - mapInfoLayer = getMapActivity().getMapLayers().getMapInfoLayer(); - mapMarkersWidgetsFactory = getMapActivity().getMapLayers().getMapMarkersLayer().getWidgetsFactory(); - processScreenHeight(container); fabPaddingTopPx = dpToPx(FAB_PADDING_TOP_DP); @@ -536,19 +528,9 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { doBeforeMenuStateChange(oldMenuState, newMenuState); } - updateTopbarAndRightStackVisibility(newMenuState == MenuState.HEADER_ONLY); - applyPosY(currentY, needCloseMenu, needMapAdjust, oldMenuState, newMenuState); } - private void updateTopbarAndRightStackVisibility(boolean visible) { - mapInfoLayer.updateRightStackVisibility(visible); - if (getMyApplication().getSettings().MAP_MARKERS_MODE.get() == OsmandSettings.MapMarkersMode.TOOLBAR) { - mapMarkersWidgetsFactory.lockTopBarVisibility(visible); - mapMarkersWidgetsFactory.updateVisibility(visible); - } - } - private void applyPosY(final int currentY, final boolean needCloseMenu, boolean needMapAdjust, final int previousMenuState, final int newMenuState) { final int posY = getPosY(needCloseMenu); diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index 29f01286d4..7b50899170 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -126,6 +126,10 @@ public class MapInfoLayer extends OsmandMapLayer { return topToolbarView.getTopController() != null; } + public TopToolbarController getTopController() { + return topToolbarView.getTopController(); + } + public TopToolbarController getTopToolbarController(TopToolbarControllerType type) { return topToolbarView.getController(type); } @@ -221,10 +225,6 @@ public class MapInfoLayer extends OsmandMapLayer { }); } - public void updateRightStackVisibility(boolean visible) { - rightStack.setVisibility(visible ? View.VISIBLE : View.GONE); - } - public void setTrackChartPoints(TrackChartPoints trackChartPoints) { this.trackChartPoints = trackChartPoints; routeLayer.setTrackChartPoints(trackChartPoints); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index 494207e808..c294f3d18b 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -36,7 +36,6 @@ public class MapMarkersWidgetsFactory { private MapMarkersHelper helper; private int screenOrientation; private boolean portraitMode; - private boolean topBarCanBeShown = true; private View topBar; private View addressTopBar; @@ -149,12 +148,8 @@ public class MapMarkersWidgetsFactory { } } - public void lockTopBarVisibility(boolean visible) { - topBarCanBeShown = visible; - } - public boolean updateVisibility(boolean visible) { - return (topBarCanBeShown || !visible) && updateVisibility(topBar, visible); + return updateVisibility(topBar, visible); } public boolean updateVisibility(View v, boolean visible) { From 74572b3772140be47a7ad56a184a3efced048e2f Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 2 Oct 2017 11:45:11 +0300 Subject: [PATCH 10/23] Rename method; fix index out of bounds exception --- OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java | 5 ++++- .../mapmarkers/PlanRouteSortByBottomSheetDialogFragment.java | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index 466cfbd386..a2db9bbfae 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -210,6 +210,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 { @@ -358,7 +361,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene private MapActivity mapActivity = getMapActivity(); @Override - public void doorByDoorOnClick() { + public void doorToDoorOnClick() { if (mapActivity != null) { Toast.makeText(mapActivity, "Door to Door", Toast.LENGTH_SHORT).show(); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteSortByBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteSortByBottomSheetDialogFragment.java index 9008068b4f..016b76897f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteSortByBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteSortByBottomSheetDialogFragment.java @@ -56,7 +56,7 @@ public class PlanRouteSortByBottomSheetDialogFragment extends BottomSheetDialogF @Override public void onClick(View view) { if (listener != null) { - listener.doorByDoorOnClick(); + listener.doorToDoorOnClick(); dismiss(); } } @@ -135,7 +135,7 @@ public class PlanRouteSortByBottomSheetDialogFragment extends BottomSheetDialogF interface PlanRouteSortByFragmentListener { - void doorByDoorOnClick(); + void doorToDoorOnClick(); void reverseOrderOnClick(); } From 1ba54c3ba1a1f522a8741f2bc522015a5437c3f8 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 2 Oct 2017 12:04:06 +0300 Subject: [PATCH 11/23] Rename menu item; remove unnecessary string --- .../res/layout/fragment_marker_options_bottom_sheet_dialog.xml | 2 +- OsmAnd/res/values/strings.xml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) 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 4c1fc387ae..801970af34 100644 --- a/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml @@ -165,7 +165,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:maxLines="1" - android:text="@string/build_route" + android:text="@string/plan_route" android:textAppearance="@style/TextAppearance.ListItemTitle"/> 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 From 2ff00f51c198c9ea64562e0fe06fd9c6736a4d3d Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 2 Oct 2017 12:04:40 +0300 Subject: [PATCH 12/23] Fix #4465 --- OsmAnd/res/layout/first_usage_wizard_fragment.xml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/layout/first_usage_wizard_fragment.xml b/OsmAnd/res/layout/first_usage_wizard_fragment.xml index 9426561ba4..7aebca4265 100644 --- a/OsmAnd/res/layout/first_usage_wizard_fragment.xml +++ b/OsmAnd/res/layout/first_usage_wizard_fragment.xml @@ -530,7 +530,6 @@ Date: Mon, 2 Oct 2017 12:32:56 +0300 Subject: [PATCH 13/23] Fix #4493 --- .../DashAudioVideoNotesFragment.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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); From a539aae277af71aa2d01429a60a4b1bbc9294c87 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 2 Oct 2017 12:58:15 +0300 Subject: [PATCH 14/23] Remove unnecessary variable --- OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index d4132bc769..bc48cfbe6a 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -210,7 +210,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi @Override public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { - OsmandSettings settings = map.getMyApplication().getSettings(); Location myLoc = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation(); MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); List 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); From f426348a43226829e711bc18aba0e263e50b04b1 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 2 Oct 2017 13:00:15 +0300 Subject: [PATCH 15/23] Fix #4478 --- OsmAnd/src/net/osmand/plus/GPXUtilities.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index c11d56b723..87f13d56fe 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; @@ -1163,6 +1162,7 @@ public class GPXUtilities { } public static String writeGpxFile(File fout, GPXFile file, OsmandApplication ctx) { + file.removeGeneralTrackIfExists(); Writer output = null; try { output = new OutputStreamWriter(new FileOutputStream(fout), "UTF-8"); //$NON-NLS-1$ From f1c42f6d2be888c21d9d0823f0ef9a68ac61c825 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 2 Oct 2017 15:24:58 +0300 Subject: [PATCH 16/23] Hide topbar --- OsmAnd/res/layout-land/map_hud_top.xml | 231 ++++++++--------- OsmAnd/res/layout/map_hud_top.xml | 233 +++++++++--------- .../plus/mapcontextmenu/MapContextMenu.java | 24 +- 3 files changed, 246 insertions(+), 242 deletions(-) diff --git a/OsmAnd/res/layout-land/map_hud_top.xml b/OsmAnd/res/layout-land/map_hud_top.xml index 01cb2124bb..69d6a1b955 100644 --- a/OsmAnd/res/layout-land/map_hud_top.xml +++ b/OsmAnd/res/layout-land/map_hud_top.xml @@ -239,144 +239,151 @@ android:orientation="vertical"> + android:layout_height="wrap_content"> - - - - - - - - - - - + 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"> + + - + + + + + + + + + + + + + + + + + + + + + + + + + + - - + android:layout_height="wrap_content"> - - - - - - - - - - - - + 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"> + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + Date: Mon, 2 Oct 2017 16:02:02 +0300 Subject: [PATCH 17/23] Add door to door sort; add small improvements --- .../src/net/osmand/plus/MapMarkersHelper.java | 31 +++++++ .../plus/mapmarkers/PlanRouteFragment.java | 88 ++++++++++++++++++- .../adapters/MapMarkersListAdapter.java | 5 -- 3 files changed, 116 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index f43c332d12..6bcd3af9fd 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -580,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); + checkAndFixActiveMarkersOrderIfNeeded(); + ctx.getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM); + } + public List getActiveMarkersLatLon() { List list = new ArrayList<>(); for (MapMarker m : this.mapMarkers) { @@ -610,6 +640,7 @@ public class MapMarkersHelper { cancelAddressRequests(); Collections.reverse(mapMarkers); checkAndFixActiveMarkersOrderIfNeeded(); + ctx.getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM); } public void moveAllActiveMarkersToHistory() { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index a2db9bbfae..86421bd4a9 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,6 +34,7 @@ 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; @@ -48,7 +52,10 @@ 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.HashMap; import java.util.List; +import java.util.Map; import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT; @@ -363,7 +370,12 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene @Override public void doorToDoorOnClick() { if (mapActivity != null) { - Toast.makeText(mapActivity, "Door to Door", Toast.LENGTH_SHORT).show(); + 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); + } } } @@ -371,8 +383,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene public void reverseOrderOnClick() { if (mapActivity != null) { markersHelper.reverseActiveMarkersOrder(); - mapActivity.getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM); - adapter.reloadMarkers(); + adapter.notifyDataSetChanged(); } } }; @@ -410,6 +421,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene } setupAppModesBtn(); + selectedCount = mapActivity.getMyApplication().getMapMarkersHelper().getSelectedMarkersCount(); showMarkersRouteOnMap(); mapActivity.refreshMap(); updateText(); @@ -705,6 +717,76 @@ 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) { + List selectedMarkers = mapActivity.getMyApplication().getMapMarkersHelper().getSelectedMarkers(); + List selectedLatLon = new ArrayList<>(selectedMarkers.size()); + LatLon[] keys = new LatLon[selectedMarkers.size()]; + Map markersMap = new HashMap<>(selectedMarkers.size()); + + for (int i = 0; i < selectedMarkers.size(); i++) { + MapMarker m = selectedMarkers.get(i); + markersMap.put(m.point, m); + keys[i] = m.point; + selectedLatLon.add(m.point); + } + + 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(markersMap.get(keys[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/adapters/MapMarkersListAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java index 1cf3468c96..5ded437f6a 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java @@ -186,11 +186,6 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter Date: Mon, 2 Oct 2017 16:45:43 +0300 Subject: [PATCH 18/23] Rename method --- .../src/net/osmand/plus/MapMarkersHelper.java | 30 +++++++++---------- .../mapmarkers/MapMarkersActiveFragment.java | 2 +- .../plus/mapmarkers/PlanRouteFragment.java | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 6bcd3af9fd..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,7 +515,7 @@ public class MapMarkersHelper { marker.history = false; mapMarkers.add(marker); } - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC); updateGroups(); refresh(); @@ -606,7 +606,7 @@ public class MapMarkersHelper { mapMarkers.removeAll(markersToRemove); mapMarkers.addAll(0, markers); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); ctx.getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM); } @@ -639,7 +639,7 @@ public class MapMarkersHelper { public void reverseActiveMarkersOrder() { cancelAddressRequests(); Collections.reverse(mapMarkers); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); ctx.getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM); } @@ -708,7 +708,7 @@ public class MapMarkersHelper { iterator.remove(); } } - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); refresh(); } } @@ -760,7 +760,7 @@ public class MapMarkersHelper { markersDbHelper.addMarker(marker); mapMarkers.add(0, marker); addMarkerToGroup(marker); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); } } } @@ -783,7 +783,7 @@ public class MapMarkersHelper { } marker.point = point; markersDbHelper.updateMarker(marker); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); refresh(); lookupAddress(marker); } @@ -794,7 +794,7 @@ public class MapMarkersHelper { if (i != -1 && mapMarkers.size() > 1) { mapMarkers.remove(i); mapMarkers.add(0, marker); - checkAndFixActiveMarkersOrderIfNeeded(); + reorderActiveMarkersIfNeeded(); refresh(); } } 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/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index 86421bd4a9..904b97c337 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -244,7 +244,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 { From 76fd7ef90465efd541f8f1abe80acfb1bc2404d8 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 2 Oct 2017 17:00:23 +0300 Subject: [PATCH 19/23] Simplify the method --- .../plus/mapmarkers/PlanRouteFragment.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index 904b97c337..49fde71664 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -53,9 +53,7 @@ import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControll import net.osmand.util.MapUtils; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT; @@ -735,17 +733,9 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene @Override protected List doInBackground(Void... voids) { - List selectedMarkers = mapActivity.getMyApplication().getMapMarkersHelper().getSelectedMarkers(); - List selectedLatLon = new ArrayList<>(selectedMarkers.size()); - LatLon[] keys = new LatLon[selectedMarkers.size()]; - Map markersMap = new HashMap<>(selectedMarkers.size()); - - for (int i = 0; i < selectedMarkers.size(); i++) { - MapMarker m = selectedMarkers.get(i); - markersMap.put(m.point, m); - keys[i] = m.point; - selectedLatLon.add(m.point); - } + 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); @@ -758,7 +748,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene continue; } int index = sequence[startFromLoc ? i - 1 : i]; - res.add(markersMap.get(keys[index])); + res.add(selectedMarkers.get(index)); } return res; From 32f35e7ed6ff4c9613d405acb88fe1c0dbc2ebc1 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 2 Oct 2017 17:06:57 +0300 Subject: [PATCH 20/23] Change logic --- OsmAnd/res/layout-land/map_hud_top.xml | 14 -------------- OsmAnd/res/layout/map_hud_top.xml | 14 -------------- .../osmand/plus/activities/MapActivity.java | 5 ----- .../plus/mapcontextmenu/MapContextMenu.java | 7 +------ .../osmand/plus/views/MapControlsLayer.java | 19 ++++++++++--------- .../net/osmand/plus/views/MapInfoLayer.java | 4 ---- .../mapwidgets/MapInfoWidgetsFactory.java | 4 ++-- .../mapwidgets/MapMarkersWidgetsFactory.java | 3 ++- 8 files changed, 15 insertions(+), 55 deletions(-) diff --git a/OsmAnd/res/layout-land/map_hud_top.xml b/OsmAnd/res/layout-land/map_hud_top.xml index 69d6a1b955..f901e5444f 100644 --- a/OsmAnd/res/layout-land/map_hud_top.xml +++ b/OsmAnd/res/layout-land/map_hud_top.xml @@ -7,11 +7,6 @@ android:orientation="vertical"> - - - - - - - - - - - - - - - - Date: Mon, 2 Oct 2017 17:12:45 +0300 Subject: [PATCH 21/23] Don't remove general track --- OsmAnd/src/net/osmand/plus/GPXUtilities.java | 27 ++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index 87f13d56fe..8d96630b1c 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -1162,7 +1162,6 @@ public class GPXUtilities { } public static String writeGpxFile(File fout, GPXFile file, OsmandApplication ctx) { - file.removeGeneralTrackIfExists(); Writer output = null; try { output = new OutputStreamWriter(new FileOutputStream(fout), "UTF-8"); //$NON-NLS-1$ @@ -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) { From e27dc12e06305967767ac10c7f38a6bd6514768e Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 2 Oct 2017 17:18:03 +0300 Subject: [PATCH 22/23] Rename method --- .../net/osmand/plus/mapcontextmenu/MapContextMenu.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 0d2145acd8..3afdfbdf74 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -368,7 +368,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL fragmentRef.get().centerMarkerLocation(); } } - updateWidgetsAndTopbarsVisibility(false); + updateWidgetsVisibility(false); } public void show(@NonNull LatLon latLon, @@ -389,7 +389,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } centerMarker = false; autoHide = false; - updateWidgetsAndTopbarsVisibility(false); + updateWidgetsVisibility(false); } public void update(LatLon latLon, PointDescription pointDescription, Object object) { @@ -448,10 +448,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL if (fragmentRef != null) { fragmentRef.get().dismissMenu(); } - updateWidgetsAndTopbarsVisibility(true); + updateWidgetsVisibility(true); } - private void updateWidgetsAndTopbarsVisibility(boolean visible) { + 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); From cde412e9c5b311276d095e15046cfb7a6606eae9 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 2 Oct 2017 17:30:42 +0300 Subject: [PATCH 23/23] Remove unnecessary parameter --- OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 3d9010fc21..2f2eb8a3d2 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -711,7 +711,7 @@ public class MapControlsLayer extends OsmandMapLayer { boolean contextMenuOpened = mapActivity.getContextMenu().isVisible(); boolean showRouteCalculationControls = routePlanningMode || ((app.accessibilityEnabled() || (System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS)) && routeFollowingMode); - updateMyLocation(rh, routeDialogOpened || trackDialogOpened, contextMenuOpened); + updateMyLocation(rh, routeDialogOpened || trackDialogOpened || contextMenuOpened); boolean showButtons = (showRouteCalculationControls || !routeFollowingMode) && !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode() && !isInPlanRouteMode() && !contextMenuOpened; //routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_gabout_dark : R.drawable.map_directions); @@ -796,7 +796,7 @@ public class MapControlsLayer extends OsmandMapLayer { return new CompassDrawable(originalDrawable); } - private void updateMyLocation(RoutingHelper rh, boolean dialogOpened, boolean contextMenuOpened) { + private void updateMyLocation(RoutingHelper rh, boolean dialogOpened) { Location lastKnownLocation = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); boolean enabled = lastKnownLocation != null; boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation(); @@ -815,7 +815,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 && !contextMenuOpened); + backToLocationControl.updateVisibility(visible && !dialogOpened); if (app.accessibilityEnabled()) { backToLocationControl.iv.setClickable(enabled && visible); }