From 3ab0dee4b036588e2ff43ea6af237d91b0c7861d Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 11 Aug 2017 15:21:58 +0300 Subject: [PATCH] Add options menu --- .../fragment_options_bottom_sheet_dialog.xml | 2 + .../MeasurementToolFragment.java | 49 ++++++++++- .../OptionsBottomSheetDialogFragment.java | 84 ++++++++++++++++++- 3 files changed, 132 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/layout/fragment_options_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_options_bottom_sheet_dialog.xml index 0211d2cec7..4467cc6df2 100644 --- a/OsmAnd/res/layout/fragment_options_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_options_bottom_sheet_dialog.xml @@ -17,6 +17,7 @@ android:textAppearance="@style/TextAppearance.ListItemTitle"/> 0) { + saveAsNewSegment(mapActivity); + } else { + Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void saveAsNewTrackOnClick() { + if (measurementLayer.getPointsCount() > 0) { + saveAsGpxOnClick(mapActivity); + } else { + Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void addToTheTrackOnClick() { + if (measurementLayer.getPointsCount() > 0) { +// showAddSegmentDialog(mapActivity); + } else { + Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void clearAllOnClick() { + commandManager.execute(new ClearPointsCommand(measurementLayer)); + if (pointsListOpened) { + hidePointsList(); + } + disable(redoBtn, upDownBtn); + updateText(); + saved = false; + } + }); + fragment.setAddLineMode(newGpxLine != null); + fragment.show(mapActivity.getSupportFragmentManager(), OptionsBottomSheetDialogFragment.TAG); } }); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java index fb2749fb6a..11b21dd59f 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java @@ -15,6 +15,17 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment public final static String TAG = "OptionsBottomSheetDialogFragment"; + private OptionsOnClickListener listener; + private boolean addLineMode; + + public void setOptionsOnClickListener(OptionsOnClickListener listener) { + this.listener = listener; + } + + public void setAddLineMode(boolean addLineMode) { + this.addLineMode = addLineMode; + } + @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -24,9 +35,65 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_options_bottom_sheet_dialog, null); ((ImageView) mainView.findViewById(R.id.snap_to_road_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_snap_to_road)); - ((ImageView) mainView.findViewById(R.id.save_as_new_track_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark)); - ((ImageView) mainView.findViewById(R.id.add_to_the_track_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_split_interval)); ((ImageView) mainView.findViewById(R.id.clear_all_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_reset_to_default_dark)); + if (!addLineMode) { + ((ImageView) mainView.findViewById(R.id.save_as_new_track_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark)); + ((ImageView) mainView.findViewById(R.id.add_to_the_track_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_split_interval)); + } else { + mainView.findViewById(R.id.save_as_new_track_row).setVisibility(View.GONE); + mainView.findViewById(R.id.add_to_the_track_row).setVisibility(View.GONE); + mainView.findViewById(R.id.save_as_new_segment_row).setVisibility(View.VISIBLE); + ((ImageView) mainView.findViewById(R.id.save_as_new_segment_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark)); + } + + mainView.findViewById(R.id.snap_to_road_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.snapToRoadOnCLick(); + } + dismiss(); + } + }); + mainView.findViewById(R.id.clear_all_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.clearAllOnClick(); + } + dismiss(); + } + }); + if (!addLineMode) { + mainView.findViewById(R.id.save_as_new_track_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.saveAsNewTrackOnClick(); + } + dismiss(); + } + }); + mainView.findViewById(R.id.add_to_the_track_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.addToTheTrackOnClick(); + } + dismiss(); + } + }); + } else { + mainView.findViewById(R.id.save_as_new_segment_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.saveAsNewSegmentOnClick(); + } + dismiss(); + } + }); + } mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -36,4 +103,17 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment return mainView; } + + interface OptionsOnClickListener { + + void snapToRoadOnCLick(); + + void saveAsNewSegmentOnClick(); + + void saveAsNewTrackOnClick(); + + void addToTheTrackOnClick(); + + void clearAllOnClick(); + } }