From cb1352328b439e33bcda0683b86e25590ffe40f4 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 16 Aug 2017 14:55:46 +0300 Subject: [PATCH] Change action bar title in snap to road mode --- .../MeasurementToolFragment.java | 28 +++++++++++++++ .../SnapToRoadBottomSheetDialogFragment.java | 36 ++++++++++++++++++- .../mapwidgets/MapInfoWidgetsFactory.java | 4 +++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 748fda3df2..4bcc340cb0 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -31,6 +31,7 @@ import android.widget.Toast; import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; import net.osmand.IndexConstants; +import net.osmand.plus.ApplicationMode; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.Route; import net.osmand.plus.GPXUtilities.WptPt; @@ -44,6 +45,7 @@ import net.osmand.plus.activities.TrackActivity.NewGpxLine.LineType; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.measurementtool.SelectedPointMenuBottomSheetDialogFragment.SelectedPointOptionOnClickListener; +import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment.SnapToRoadListener; import net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter; import net.osmand.plus.measurementtool.adapter.MeasurementToolItemTouchHelperCallback; import net.osmand.plus.measurementtool.command.AddPointCommand; @@ -77,6 +79,7 @@ public class MeasurementToolFragment extends Fragment { private List measurementPoints = new LinkedList<>(); private IconsCache iconsCache; private RecyclerView pointsRv; + private String previousToolBarTitle = ""; private MeasurementToolBarController toolBarController; private MeasurementToolAdapter adapter; private TextView distanceTv; @@ -209,7 +212,11 @@ public class MeasurementToolFragment extends Fragment { fragment.setOptionsOnClickListener(new OptionsBottomSheetDialogFragment.OptionsOnClickListener() { @Override public void snapToRoadOnCLick() { + previousToolBarTitle = toolBarController.getTitle(); + toolBarController.setTitle(getString(R.string.snap_to_road)); + mapActivity.refreshMap(); SnapToRoadBottomSheetDialogFragment fragment = new SnapToRoadBottomSheetDialogFragment(); + fragment.setListener(createSnapToRoadListener()); fragment.show(mapActivity.getSupportFragmentManager(), SnapToRoadBottomSheetDialogFragment.TAG); } @@ -533,6 +540,27 @@ public class MeasurementToolFragment extends Fragment { }; } + private SnapToRoadListener createSnapToRoadListener() { + return new SnapToRoadListener() { + + @Override + public void onDestroyView(boolean snapToRoadEnabled) { + if (!snapToRoadEnabled) { + toolBarController.setTitle(previousToolBarTitle); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.refreshMap(); + } + } + } + + @Override + public void onApplicationModeItemClick(ApplicationMode mode) { + Toast.makeText(getActivity(), mode.toHumanString(getActivity()), Toast.LENGTH_SHORT).show(); + } + }; + } + private void displayRoutePoints(MapActivity mapActivity) { final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java index bb97ef348f..8366249b1a 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java @@ -30,8 +30,14 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme public static final String TAG = "SnapToRoadBottomSheetDialogFragment"; + private SnapToRoadListener listener; private boolean nightMode; private boolean portrait; + private boolean snapToRoadEnabled; + + public void setListener(SnapToRoadListener listener) { + this.listener = listener; + } @Nullable @Override @@ -56,10 +62,23 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme LinearLayout navContainer = (LinearLayout) mainView.findViewById(R.id.navigation_types_container); final List modes = new ArrayList<>(ApplicationMode.values(settings)); modes.remove(ApplicationMode.DEFAULT); - for (ApplicationMode mode : modes) { + View.OnClickListener onClickListener = new View.OnClickListener() { + @Override + public void onClick(View view) { + snapToRoadEnabled = true; + if (listener != null) { + listener.onApplicationModeItemClick(modes.get((int) view.getTag())); + } + dismiss(); + } + }; + for (int i = 0; i < modes.size(); i++) { + ApplicationMode mode = modes.get(i); View row = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.list_item_icon_and_title, null); ((ImageView) row.findViewById(R.id.icon)).setImageDrawable(getContentIcon(mode.getSmallIconDark())); ((TextView) row.findViewById(R.id.title)).setText(mode.toHumanString(getContext())); + row.setOnClickListener(onClickListener); + row.setTag(i); navContainer.addView(row); } @@ -114,8 +133,23 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme } } + @Override + public void onDestroyView() { + if (listener != null) { + listener.onDestroyView(snapToRoadEnabled); + } + super.onDestroyView(); + } + @Override protected Drawable getContentIcon(@DrawableRes int id) { return getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); } + + interface SnapToRoadListener { + + void onDestroyView(boolean snapToRoadEnabled); + + void onApplicationModeItemClick(ApplicationMode mode); + } } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index 97be2765e4..9d71526d83 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -266,6 +266,10 @@ public class MapInfoWidgetsFactory { this.title = title; } + public String getTitle() { + return title; + } + public void setBottomView(View bottomView) { this.bottomView = bottomView; }