From d413591a0dd205ab153494dcc1c83801bd6af00e Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 13 Aug 2020 15:00:46 +0300 Subject: [PATCH 1/7] Plan route point menu UI --- OsmAnd/res/values/strings.xml | 5 +- ...ttomSheetItemWithDescriptionDifHeight.java | 94 +++++++ .../MeasurementToolFragment.java | 158 ++++++------ .../OptionsBottomSheetDialogFragment.java | 4 +- ...electedPointBottomSheetDialogFragment.java | 244 ++++++++++++++---- 5 files changed, 377 insertions(+), 128 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescriptionDifHeight.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index f3a1ebf203..99d79a4ea0 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,7 +11,10 @@ Thx - Hardy --> - + Change route type after + Change route type before + Trim after + Trim before Select a track file for which a new segment will be added. Navigation profile Threshold distance diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescriptionDifHeight.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescriptionDifHeight.java new file mode 100644 index 0000000000..4ec0060f02 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/BottomSheetItemWithDescriptionDifHeight.java @@ -0,0 +1,94 @@ +package net.osmand.plus.base.bottomsheetmenu; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import androidx.annotation.ColorRes; +import androidx.annotation.LayoutRes; +import androidx.core.view.ViewCompat; + +public class BottomSheetItemWithDescriptionDifHeight extends BottomSheetItemWithDescription { + + private int minHeight; + + public BottomSheetItemWithDescriptionDifHeight(View customView, + @LayoutRes int layoutId, + Object tag, + boolean disabled, + View.OnClickListener onClickListener, + int position, + Drawable icon, + Drawable background, + CharSequence title, + @ColorRes int titleColorId, + boolean iconHidden, + CharSequence description, + @ColorRes int descriptionColorId, + int descriptionMaxLines, + boolean descriptionLinksClickable, + int minHeight) { + super(customView, + layoutId, + tag, + disabled, + onClickListener, + position, + icon, + background, + title, + titleColorId, + iconHidden, + description, + descriptionColorId, + descriptionMaxLines, + descriptionLinksClickable); + + this.minHeight = minHeight; + + } + + + @Override + public void inflate(Context context, ViewGroup container, boolean nightMode) { + super.inflate(context, container, nightMode); + if (minHeight == 0) { + minHeight = ViewCompat.getMinimumHeight(view); + } + LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); + params.height = minHeight; + view.setMinimumHeight(minHeight); + + } + + public static class Builder extends BottomSheetItemWithDescription.Builder { + + int minHeight; + + public Builder setMinHeight(int minHeight) { + this.minHeight = minHeight; + return this; + } + + public BottomSheetItemWithDescriptionDifHeight create() { + return new BottomSheetItemWithDescriptionDifHeight(customView, + layoutId, + tag, + disabled, + onClickListener, + position, + icon, + background, + title, + titleColorId, + iconHidden, + description, + descriptionColorId, + descriptionMaxLines, + descriptionLinksClickable, + minHeight); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 1b289e0149..03777815db 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -102,7 +102,7 @@ import static net.osmand.plus.measurementtool.SelectFileBottomSheet.SelectFileLi import static net.osmand.plus.measurementtool.StartPlanRouteBottomSheet.StartPlanRouteListener; public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener, - OptionsFragmentListener, GpxApproximationFragmentListener { + OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener { public static final String TAG = MeasurementToolFragment.class.getSimpleName(); @@ -191,12 +191,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route measurementLayer.setEditingCtx(editingCtx); // Handling screen rotation - FragmentManager fragmentManager = mapActivity.getSupportFragmentManager(); - Fragment selectedPointFragment = fragmentManager.findFragmentByTag(SelectedPointBottomSheetDialogFragment.TAG); - if (selectedPointFragment != null) { - SelectedPointBottomSheetDialogFragment fragment = (SelectedPointBottomSheetDialogFragment) selectedPointFragment; - fragment.setListener(createSelectedPointFragmentListener()); - } Fragment saveAsNewTrackFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(SaveAsNewTrackBottomSheetDialogFragment.TAG); if (saveAsNewTrackFragment != null) { ((SaveAsNewTrackBottomSheetDialogFragment) saveAsNewTrackFragment).setListener(createSaveAsNewTrackFragmentListener()); @@ -716,61 +710,78 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route } - private SelectedPointFragmentListener createSelectedPointFragmentListener() { - return new SelectedPointFragmentListener() { + @Override + public void onMovePoint() { + MeasurementToolLayer measurementLayer = getMeasurementLayer(); + if (measurementLayer != null) { + measurementLayer.enterMovingPointMode(); + } + switchMovePointMode(true); + } - final MeasurementToolLayer measurementLayer = getMeasurementLayer(); + @Override + public void onDeletePoint() { + MeasurementToolLayer measurementLayer = getMeasurementLayer(); + if (measurementLayer != null) { + removePoint(measurementLayer, editingCtx.getSelectedPointPosition()); + } + editingCtx.setSelectedPointPosition(-1); + } - @Override - public void moveOnClick() { - if (measurementLayer != null) { - measurementLayer.enterMovingPointMode(); - } - switchMovePointMode(true); - } + @Override + public void onAddPointAfter() { + MeasurementToolLayer measurementLayer = getMeasurementLayer(); + if (measurementLayer != null) { + measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition()); + editingCtx.setInAddPointMode(true); + editingCtx.splitSegments(editingCtx.getSelectedPointPosition() + 1); + } + ((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_after)); + mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_addpoint_above)); + switchAddPointBeforeAfterMode(true); + } - @Override - public void deleteOnClick() { - if (measurementLayer != null) { - removePoint(measurementLayer, editingCtx.getSelectedPointPosition()); - } - editingCtx.setSelectedPointPosition(-1); - } + @Override + public void onAddPointBefore() { + MeasurementToolLayer measurementLayer = getMeasurementLayer(); + if (measurementLayer != null) { + measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition()); + editingCtx.setInAddPointMode(true); + editingCtx.splitSegments(editingCtx.getSelectedPointPosition()); + } + ((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_before)); + mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_addpoint_below)); + switchAddPointBeforeAfterMode(true); + } - @Override - public void addPointAfterOnClick() { - if (measurementLayer != null) { - measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition()); - editingCtx.setInAddPointMode(true); - editingCtx.splitSegments(editingCtx.getSelectedPointPosition() + 1); - } - ((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_after)); - mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_addpoint_above)); - switchAddPointBeforeAfterMode(true); - } + @Override + public void onTrimRouteBefore() { - @Override - public void addPointBeforeOnClick() { - if (measurementLayer != null) { - measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition()); - editingCtx.setInAddPointMode(true); - editingCtx.splitSegments(editingCtx.getSelectedPointPosition()); - } - ((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_before)); - mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_addpoint_below)); - switchAddPointBeforeAfterMode(true); - } + } - @Override - public void onCloseMenu() { - setDefaultMapPosition(); - } + @Override + public void onTrimRouteAfter() { - @Override - public void onClearSelection() { - editingCtx.setSelectedPointPosition(-1); - } - }; + } + + @Override + public void onChangeRouteTypeBefore() { + + } + + @Override + public void onChangeRouteTypeAfter() { + + } + + @Override + public void onCloseMenu() { + setDefaultMapPosition(); + } + + @Override + public void onClearSelection() { + editingCtx.setSelectedPointPosition(-1); } @Override @@ -1067,10 +1078,9 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route } private void openSelectedPointMenu(MapActivity mapActivity) { - SelectedPointBottomSheetDialogFragment fragment = new SelectedPointBottomSheetDialogFragment(); - fragment.setUsedOnMap(true); - fragment.setListener(createSelectedPointFragmentListener()); - fragment.show(mapActivity.getSupportFragmentManager(), SelectedPointBottomSheetDialogFragment.TAG); + if (mapActivity != null) { + SelectedPointBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), this); + } } private void openSaveAsNewTrackMenu(MapActivity mapActivity) { @@ -1083,7 +1093,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route private void showAddToTrackDialog(final MapActivity mapActivity) { if (mapActivity != null) { SelectFileBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), - createAddToTrackFileListener(),ADD_TO_TRACK); + createAddToTrackFileListener(), ADD_TO_TRACK); } } @@ -1182,14 +1192,14 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark); } mapActivity.showTopToolbar(toolBarController); + markGeneralComponents(enable ? View.GONE : View.VISIBLE); + AndroidUiHelper.setVisibility(mapActivity, enable ? View.VISIBLE : View.GONE, + R.id.move_point_text, + R.id.move_point_controls); + mainIcon.setImageDrawable(getActiveIcon(enable + ? R.drawable.ic_action_move_point + : R.drawable.ic_action_ruler)); } - markGeneralComponents(enable ? View.GONE : View.VISIBLE); - AndroidUiHelper.setVisibility(mapActivity, enable ? View.VISIBLE : View.GONE, - R.id.move_point_text, - R.id.move_point_controls); - mainIcon.setImageDrawable(getActiveIcon(enable - ? R.drawable.ic_action_move_point - : R.drawable.ic_action_ruler)); } private void switchAddPointBeforeAfterMode(boolean enable) { @@ -1202,13 +1212,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark); } mapActivity.showTopToolbar(toolBarController); - } - markGeneralComponents(enable ? View.GONE : View.VISIBLE); - AndroidUiHelper.setVisibility(mapActivity,enable ? View.VISIBLE : View.GONE, - R.id.add_point_before_after_text, - R.id.add_point_before_after_controls); - if (!enable) { - mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler)); + markGeneralComponents(enable ? View.GONE : View.VISIBLE); + AndroidUiHelper.setVisibility(mapActivity, enable ? View.VISIBLE : View.GONE, + R.id.add_point_before_after_text, + R.id.add_point_before_after_controls); + if (!enable) { + mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler)); + } } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java index ad28e59754..0e5564778a 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java @@ -121,8 +121,8 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm items.add(new OptionsDividerItem(getContext())); BaseBottomSheetItem clearAllItem = new SimpleBottomSheetItem.Builder() - .setIcon(getIcon(R.drawable.ic_action_reset_to_default_dark, ( - nightMode ? R.color.color_osm_edit_delete : R.color.color_osm_edit_delete))) + .setIcon(getIcon(R.drawable.ic_action_reset_to_default_dark, + nightMode ? R.color.color_osm_edit_delete : R.color.color_osm_edit_delete)) .setTitle(getString(R.string.shared_string_clear_all)) .setLayoutId(R.layout.bottom_sheet_item_simple_pad_32dp) .setOnClickListener(new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java index 2ccda82c10..8b038e9334 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java @@ -2,42 +2,44 @@ package net.osmand.plus.measurementtool; import android.app.Activity; import android.content.DialogInterface; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; import net.osmand.GPXUtilities.WptPt; +import net.osmand.PlatformUtil; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; -import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescriptionDifHeight; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; -import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleDividerItem; import net.osmand.plus.measurementtool.NewGpxData.ActionType; +import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.util.MapUtils; +import org.apache.commons.logging.Log; + import java.util.List; public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { - public final static String TAG = "SelectedPointBottomSheetDialogFragment"; - - private SelectedPointFragmentListener listener; - - public void setListener(SelectedPointFragmentListener listener) { - this.listener = listener; - } + public static final String TAG = SelectedPointBottomSheetDialogFragment.class.getSimpleName(); + private static final Log LOG = PlatformUtil.getLog(SelectedPointBottomSheetDialogFragment.class); @Override public void createMenuItems(Bundle savedInstanceState) { - BaseBottomSheetItem titleItem = new BottomSheetItemWithDescription.Builder() - .setDescription(getDescription()) + BaseBottomSheetItem titleItem = new BottomSheetItemWithDescriptionDifHeight.Builder() + .setMinHeight(getResources().getDimensionPixelSize(R.dimen.measurement_tool_up_down_row_height)) + .setDescription(getDescription(true)) .setIcon(getActiveIcon(R.drawable.ic_action_measure_point)) .setTitle(getTitle()) .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) @@ -49,12 +51,13 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo BaseBottomSheetItem moveItem = new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon(R.drawable.ic_action_move_point)) .setTitle(getString(R.string.shared_string_move)) - .setLayoutId(R.layout.bottom_sheet_item_simple) + .setLayoutId(R.layout.bottom_sheet_item_simple_pad_32dp) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (listener != null) { - listener.moveOnClick(); + Fragment targetFragment = getTargetFragment(); + if (targetFragment instanceof SelectedPointFragmentListener) { + ((SelectedPointFragmentListener) targetFragment).onMovePoint(); } dismiss(); } @@ -62,33 +65,18 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo .create(); items.add(moveItem); - BaseBottomSheetItem deleteItem = new SimpleBottomSheetItem.Builder() - .setIcon(getContentIcon(R.drawable.ic_action_remove_dark)) - .setTitle(getString(R.string.shared_string_delete)) - .setLayoutId(R.layout.bottom_sheet_item_simple) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (listener != null) { - listener.deleteOnClick(); - } - dismiss(); - } - }) - .create(); - items.add(deleteItem); - - items.add(new DividerHalfItem(getContext())); + items.add(new OptionsDividerItem(getContext())); BaseBottomSheetItem addAfterItem = new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon(R.drawable.ic_action_addpoint_above)) .setTitle(getString(R.string.add_point_after)) - .setLayoutId(R.layout.bottom_sheet_item_simple) + .setLayoutId(R.layout.bottom_sheet_item_simple_pad_32dp) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (listener != null) { - listener.addPointAfterOnClick(); + Fragment targetFragment = getTargetFragment(); + if (targetFragment instanceof SelectedPointFragmentListener) { + ((SelectedPointFragmentListener) targetFragment).onAddPointAfter(); } dismiss(); } @@ -99,33 +87,136 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo BaseBottomSheetItem addBeforeItem = new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon(R.drawable.ic_action_addpoint_below)) .setTitle(getString(R.string.add_point_before)) - .setLayoutId(R.layout.bottom_sheet_item_simple) + .setLayoutId(R.layout.bottom_sheet_item_simple_pad_32dp) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (listener != null) { - listener.addPointBeforeOnClick(); + Fragment targetFragment = getTargetFragment(); + if (targetFragment instanceof SelectedPointFragmentListener) { + ((SelectedPointFragmentListener) targetFragment).onAddPointBefore(); } dismiss(); } }) .create(); items.add(addBeforeItem); + + items.add(new OptionsDividerItem(getContext())); + + BaseBottomSheetItem trimRouteBefore = new BottomSheetItemWithDescriptionDifHeight.Builder() + .setMinHeight(getResources().getDimensionPixelSize(R.dimen.measurement_tool_up_down_row_height)) + .setDescription(getDescription(true)) + .setIcon(getContentIcon(R.drawable.ic_action_trim_left)) + .setTitle(getString(R.string.plan_route_trim_before)) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Fragment targetFragment = getTargetFragment(); + if (targetFragment instanceof SelectedPointFragmentListener) { + ((SelectedPointFragmentListener) targetFragment).onTrimRouteBefore(); + } + dismiss(); + } + }) + .create(); + items.add(trimRouteBefore); + + BaseBottomSheetItem trimRouteAfter = new BottomSheetItemWithDescriptionDifHeight.Builder() + .setMinHeight(getResources().getDimensionPixelSize(R.dimen.measurement_tool_up_down_row_height)) + .setDescription(getDescription(false)) + .setIcon(getContentIcon(R.drawable.ic_action_trim_right)) + .setTitle(getString(R.string.plan_route_trim_after)) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Fragment targetFragment = getTargetFragment(); + if (targetFragment instanceof SelectedPointFragmentListener) { + ((SelectedPointFragmentListener) targetFragment).onTrimRouteAfter(); + } + dismiss(); + } + }) + .create(); + items.add(trimRouteAfter); + + items.add(new OptionsDividerItem(getContext())); + + BaseBottomSheetItem changeRouteTypeBefore = new BottomSheetItemWithDescriptionDifHeight.Builder() + .setMinHeight(getResources().getDimensionPixelSize(R.dimen.measurement_tool_up_down_row_height)) + .setDescription(getDescription(true)) + .setIcon(getRouteTypeIcon(true)) + .setTitle(getString(R.string.plan_route_change_route_type_before)) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Fragment targetFragment = getTargetFragment(); + if (targetFragment instanceof SelectedPointFragmentListener) { + ((SelectedPointFragmentListener) targetFragment).onChangeRouteTypeBefore(); + } + dismiss(); + } + }) + .create(); + items.add(changeRouteTypeBefore); + + BaseBottomSheetItem changeRouteTypeAfter = new BottomSheetItemWithDescriptionDifHeight.Builder() + .setMinHeight(getResources().getDimensionPixelSize(R.dimen.measurement_tool_up_down_row_height)) + .setDescription(getDescription(false)) + .setIcon(getRouteTypeIcon(false)) + .setTitle(getString(R.string.plan_route_change_route_type_after)) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Fragment targetFragment = getTargetFragment(); + if (targetFragment instanceof SelectedPointFragmentListener) { + ((SelectedPointFragmentListener) targetFragment).onChangeRouteTypeAfter(); + } + dismiss(); + } + }) + .create(); + items.add(changeRouteTypeAfter); + + items.add(new OptionsDividerItem(getContext())); + + BaseBottomSheetItem deleteItem = new SimpleBottomSheetItem.Builder() + .setIcon(getIcon(R.drawable.ic_action_delete_dark, + nightMode ? R.color.color_osm_edit_delete : R.color.color_osm_edit_delete)) + .setTitle(getString(R.string.shared_string_delete)) + .setLayoutId(R.layout.bottom_sheet_item_simple_pad_32dp) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Fragment targetFragment = getTargetFragment(); + if (targetFragment instanceof SelectedPointFragmentListener) { + ((SelectedPointFragmentListener) targetFragment).onDeletePoint(); + } + dismiss(); + } + }) + .create(); + items.add(deleteItem); } @Override public void dismiss() { - if (listener != null) { - listener.onCloseMenu(); + Fragment targetFragment = getTargetFragment(); + if (targetFragment instanceof SelectedPointFragmentListener) { + ((SelectedPointFragmentListener) targetFragment).onCloseMenu(); } super.dismiss(); } @Override - public void onCancel(DialogInterface dialog) { - if (listener != null) { - listener.onCloseMenu(); - listener.onClearSelection(); + public void onCancel(@NonNull DialogInterface dialog) { + Fragment targetFragment = getTargetFragment(); + if (targetFragment instanceof SelectedPointFragmentListener) { + ((SelectedPointFragmentListener) targetFragment).onCloseMenu(); + ((SelectedPointFragmentListener) targetFragment).onClearSelection(); } super.onCancel(dialog); } @@ -137,8 +228,9 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo @Override protected void onDismissButtonClickAction() { - if (listener != null) { - listener.onClearSelection(); + Fragment targetFragment = getTargetFragment(); + if (targetFragment instanceof SelectedPointFragmentListener) { + ((SelectedPointFragmentListener) targetFragment).onClearSelection(); } } @@ -175,7 +267,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo } @NonNull - private String getDescription() { + private String getDescription(boolean before) { MapActivity mapActivity = getMapActivity(); if (mapActivity == null) { return ""; @@ -195,7 +287,16 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo description.append(getString(R.string.shared_string_control_start)); } else { float dist = 0; - for (int i = 1; i <= pos; i++) { + int startIdx; + int endIdx; + if (before) { + startIdx = 1; + endIdx = pos; + } else { + startIdx = pos + 1; + endIdx = points.size() - 1; + } + for (int i = startIdx; i <= endIdx; i++) { WptPt first = points.get(i - 1); WptPt second = points.get(i); dist += MapUtils.getDistance(first.lat, first.lon, second.lat, second.lon); @@ -220,15 +321,56 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo return description.toString(); } + @Nullable + private Drawable getRouteTypeIcon(boolean before) { + Drawable icon = getContentIcon(R.drawable.ic_action_split_interval); + MapActivity mapActivity = getMapActivity(); + if (mapActivity == null) { + return icon; + } + + MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx(); + int pos = editingCtx.getSelectedPointPosition(); + pos = before ? pos : Math.max(pos - 1, 0); + + String profileType = editingCtx.getPoints().get(pos).getProfileType(); + ApplicationMode routeAppMode = ApplicationMode.valueOfStringKey(profileType, null); + if (routeAppMode != null) { + icon = getIcon(routeAppMode.getIconRes(), routeAppMode.getIconColorInfo().getColor(nightMode)); + } + return icon; + } + + public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment) { + try { + if (!fm.isStateSaved()) { + SelectedPointBottomSheetDialogFragment fragment = new SelectedPointBottomSheetDialogFragment(); + fragment.setRetainInstance(true); + fragment.setTargetFragment(targetFragment, 0); + fragment.show(fm, TAG); + } + } catch (RuntimeException e) { + LOG.error("showInstance", e); + } + } + interface SelectedPointFragmentListener { - void moveOnClick(); + void onMovePoint(); - void deleteOnClick(); + void onDeletePoint(); - void addPointAfterOnClick(); + void onAddPointAfter(); - void addPointBeforeOnClick(); + void onAddPointBefore(); + + void onTrimRouteBefore(); + + void onTrimRouteAfter(); + + void onChangeRouteTypeBefore(); + + void onChangeRouteTypeAfter(); void onCloseMenu(); From 200b6055b00ac446c9648ef5ca19ac6c4b2a52f4 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 13 Aug 2020 15:03:48 +0300 Subject: [PATCH 2/7] Bottom sheet menu buttons top shadow --- OsmAnd/res/layout/bottom_sheet_menu_base.xml | 37 +++++++++++++------ .../base/MenuBottomSheetDialogFragment.java | 1 + 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/OsmAnd/res/layout/bottom_sheet_menu_base.xml b/OsmAnd/res/layout/bottom_sheet_menu_base.xml index 323d5569e1..5110455a7c 100644 --- a/OsmAnd/res/layout/bottom_sheet_menu_base.xml +++ b/OsmAnd/res/layout/bottom_sheet_menu_base.xml @@ -6,25 +6,38 @@ android:orientation="vertical" tools:background="?attr/bg_color"> - + + + + + + + android:orientation="vertical" + android:visibility="gone" /> - - - + + diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index edadd807ec..ef5d5790c9 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -197,6 +197,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra if (contentView.getHeight() > contentHeight) { if (useScrollableItemsContainer() || useExpandableList()) { contentView.getLayoutParams().height = contentHeight; + mainView.findViewById(R.id.buttons_shadow).setVisibility(View.VISIBLE); } else { contentView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; } From a4817be53b9bb0cf2bdbbedf989e99eb3bfabb27 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 13 Aug 2020 17:21:26 +0300 Subject: [PATCH 3/7] Fix plan a route options and point UI --- .../bottom_sheet_item_with_descr_56dp.xml | 8 ++-- .../bottom_sheet_item_with_descr_pad_32dp.xml | 48 +++++++++++++++++++ .../OptionsBottomSheetDialogFragment.java | 20 ++------ ...electedPointBottomSheetDialogFragment.java | 36 +++++++------- 4 files changed, 77 insertions(+), 35 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_with_descr_pad_32dp.xml diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_descr_56dp.xml b/OsmAnd/res/layout/bottom_sheet_item_with_descr_56dp.xml index adb62373fa..2ba0589479 100644 --- a/OsmAnd/res/layout/bottom_sheet_item_with_descr_56dp.xml +++ b/OsmAnd/res/layout/bottom_sheet_item_with_descr_56dp.xml @@ -33,8 +33,8 @@ android:layout_height="wrap_content" android:ellipsize="end" android:maxLines="1" - android:textAppearance="@style/TextAppearance.ListItemTitle" - tools:text="Some title"/> + style="@style/TextAppearance.ListItemTitle" + tools:text="Some title" /> + style="@style/TextAppearance.ContextMenuSubtitle" + tools:text="Some description" /> diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_descr_pad_32dp.xml b/OsmAnd/res/layout/bottom_sheet_item_with_descr_pad_32dp.xml new file mode 100644 index 0000000000..dbf621062d --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_with_descr_pad_32dp.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java index 0e5564778a..718b7d2596 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java @@ -3,11 +3,8 @@ package net.osmand.plus.measurementtool; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -15,7 +12,7 @@ import net.osmand.PlatformUtil; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; -import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescriptionDifHeight; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.settings.backend.ApplicationMode; @@ -61,11 +58,12 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm icon = getContentIcon(R.drawable.ic_action_help); } - BaseBottomSheetItem snapToRoadItem = new BottomSheetItemWithDescription.Builder() + BaseBottomSheetItem snapToRoadItem = new BottomSheetItemWithDescriptionDifHeight.Builder() + .setMinHeight(getResources().getDimensionPixelSize(R.dimen.card_row_min_height)) .setDescription(description) .setIcon(icon) .setTitle(getString(R.string.route_between_points)) - .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -141,7 +139,7 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm private BaseBottomSheetItem getSaveAsNewTrackItem() { return new SimpleBottomSheetItem.Builder() - .setIcon(getContentIcon(R.drawable.ic_action_save_to_file)) + .setIcon(getContentIcon(R.drawable.ic_action_save_as_new_file)) .setTitle(getString(R.string.save_as_new_track)) .setLayoutId(R.layout.bottom_sheet_item_simple_pad_32dp) .setOnClickListener(new View.OnClickListener() { @@ -157,14 +155,6 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm .create(); } - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - ImageView icon = view.findViewById(R.id.icon); - ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) icon.getLayoutParams(); - params.rightMargin = view.getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin_large); - } - public static void showInstance(@NonNull FragmentManager fm, Fragment targetFragment, boolean trackSnappedToRoad, boolean snapToRoad, String routeAppModeStringKey) { try { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java index 8b038e9334..be6b587c82 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java @@ -6,6 +6,7 @@ import android.graphics.drawable.Drawable; import android.os.Bundle; import android.text.TextUtils; import android.view.View; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -16,12 +17,14 @@ import net.osmand.GPXUtilities.WptPt; import net.osmand.PlatformUtil; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; -import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescriptionDifHeight; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleDividerItem; +import net.osmand.plus.helpers.FontCache; import net.osmand.plus.measurementtool.NewGpxData.ActionType; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.util.MapUtils; @@ -37,12 +40,17 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo @Override public void createMenuItems(Bundle savedInstanceState) { - BaseBottomSheetItem titleItem = new BottomSheetItemWithDescriptionDifHeight.Builder() - .setMinHeight(getResources().getDimensionPixelSize(R.dimen.measurement_tool_up_down_row_height)) + + View titleView = UiUtilities.getInflater(getContext(), nightMode) + .inflate(R.layout.bottom_sheet_item_with_descr_pad_32dp, null, false); + TextView title = titleView.findViewById(R.id.title); + title.setTypeface(FontCache.getRobotoMedium(getActivity())); + + BaseBottomSheetItem titleItem = new BottomSheetItemWithDescription.Builder() .setDescription(getDescription(true)) .setIcon(getActiveIcon(R.drawable.ic_action_measure_point)) .setTitle(getTitle()) - .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .setCustomView(titleView) .create(); items.add(titleItem); @@ -103,12 +111,11 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo items.add(new OptionsDividerItem(getContext())); - BaseBottomSheetItem trimRouteBefore = new BottomSheetItemWithDescriptionDifHeight.Builder() - .setMinHeight(getResources().getDimensionPixelSize(R.dimen.measurement_tool_up_down_row_height)) + BaseBottomSheetItem trimRouteBefore = new BottomSheetItemWithDescription.Builder() .setDescription(getDescription(true)) .setIcon(getContentIcon(R.drawable.ic_action_trim_left)) .setTitle(getString(R.string.plan_route_trim_before)) - .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -122,12 +129,11 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo .create(); items.add(trimRouteBefore); - BaseBottomSheetItem trimRouteAfter = new BottomSheetItemWithDescriptionDifHeight.Builder() - .setMinHeight(getResources().getDimensionPixelSize(R.dimen.measurement_tool_up_down_row_height)) + BaseBottomSheetItem trimRouteAfter = new BottomSheetItemWithDescription.Builder() .setDescription(getDescription(false)) .setIcon(getContentIcon(R.drawable.ic_action_trim_right)) .setTitle(getString(R.string.plan_route_trim_after)) - .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -143,12 +149,11 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo items.add(new OptionsDividerItem(getContext())); - BaseBottomSheetItem changeRouteTypeBefore = new BottomSheetItemWithDescriptionDifHeight.Builder() - .setMinHeight(getResources().getDimensionPixelSize(R.dimen.measurement_tool_up_down_row_height)) + BaseBottomSheetItem changeRouteTypeBefore = new BottomSheetItemWithDescription.Builder() .setDescription(getDescription(true)) .setIcon(getRouteTypeIcon(true)) .setTitle(getString(R.string.plan_route_change_route_type_before)) - .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -162,12 +167,11 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo .create(); items.add(changeRouteTypeBefore); - BaseBottomSheetItem changeRouteTypeAfter = new BottomSheetItemWithDescriptionDifHeight.Builder() - .setMinHeight(getResources().getDimensionPixelSize(R.dimen.measurement_tool_up_down_row_height)) + BaseBottomSheetItem changeRouteTypeAfter = new BottomSheetItemWithDescription.Builder() .setDescription(getDescription(false)) .setIcon(getRouteTypeIcon(false)) .setTitle(getString(R.string.plan_route_change_route_type_after)) - .setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { From b3d0347dd289c8a8460a8fd4a513b2a7e940e06b Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 18 Aug 2020 00:15:11 +0300 Subject: [PATCH 4/7] Fix merge, straight line npe, dark theme --- .../MeasurementToolFragment.java | 59 ++++++++++--------- ...etweenPointsBottomSheetDialogFragment.java | 9 +-- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 933294c6a5..b534184a34 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -726,35 +726,40 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route switchMovePointMode(true); } - @Override - public void deleteOnClick() { - removePoint(measurementLayer, editingCtx.getSelectedPointPosition()); - editingCtx.setSelectedPointPosition(-1); - } + @Override + public void onDeletePoint() { + MeasurementToolLayer measurementLayer = getMeasurementLayer(); + if (measurementLayer != null) { + removePoint(measurementLayer, editingCtx.getSelectedPointPosition()); + } + editingCtx.setSelectedPointPosition(-1); + } - @Override - public void addPointAfterOnClick() { - if (measurementLayer != null) { - measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition()); - editingCtx.setInAddPointMode(true); - editingCtx.splitSegments(editingCtx.getSelectedPointPosition() + 1); - } - ((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_after)); - mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_addpoint_above)); - switchAddPointBeforeAfterMode(true); - } + @Override + public void onAddPointAfter() { + MeasurementToolLayer measurementLayer = getMeasurementLayer(); + if (measurementLayer != null) { + measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition()); + editingCtx.setInAddPointMode(true); + editingCtx.splitSegments(editingCtx.getSelectedPointPosition() + 1); + } + ((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_after)); + mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_addpoint_above)); + switchAddPointBeforeAfterMode(true); + } - @Override - public void addPointBeforeOnClick() { - if (measurementLayer != null) { - measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition()); - editingCtx.setInAddPointMode(true); - editingCtx.splitSegments(editingCtx.getSelectedPointPosition()); - } - ((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_before)); - mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_addpoint_below)); - switchAddPointBeforeAfterMode(true); - } + @Override + public void onAddPointBefore() { + MeasurementToolLayer measurementLayer = getMeasurementLayer(); + if (measurementLayer != null) { + measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition()); + editingCtx.setInAddPointMode(true); + editingCtx.splitSegments(editingCtx.getSelectedPointPosition()); + } + ((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_before)); + mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_addpoint_below)); + switchAddPointBeforeAfterMode(true); + } @Override public void onTrimRouteBefore() { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/RouteBetweenPointsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/RouteBetweenPointsBottomSheetDialogFragment.java index 8c43b02c0a..266fcdab02 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/RouteBetweenPointsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/RouteBetweenPointsBottomSheetDialogFragment.java @@ -37,6 +37,7 @@ import java.util.List; import static net.osmand.plus.UiUtilities.CustomRadioButtonType.*; import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode.NEXT_SEGMENT; import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode.WHOLE_TRACK; +import static net.osmand.plus.measurementtool.MeasurementEditingContext.DEFAULT_APP_MODE; public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetDialogFragment { @@ -70,8 +71,8 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetDial nightMode = app.getDaynightHelper().isNightModeForMapControls(); FragmentActivity activity = requireActivity(); portrait = AndroidUiHelper.isOrientationPortrait(activity); - final View mainView = inflater.inflate(R.layout.fragment_route_between_points_bottom_sheet_dialog, - container, false); + final View mainView = UiUtilities.getInflater(getContext(), nightMode) + .inflate(R.layout.fragment_route_between_points_bottom_sheet_dialog, container, false); AndroidUtils.setBackground(activity, mainView, nightMode, portrait ? R.drawable.bg_bottom_menu_light : R.drawable.bg_bottom_sheet_topsides_landscape_light, portrait ? R.drawable.bg_bottom_menu_dark : R.drawable.bg_bottom_sheet_topsides_landscape_dark); @@ -101,7 +102,7 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetDial @Override public void onClick(View view) { snapToRoadEnabled = false; - ApplicationMode mode = null; + ApplicationMode mode = DEFAULT_APP_MODE; if ((int) view.getTag() != STRAIGHT_LINE_TAG) { mode = modes.get((int) view.getTag()); snapToRoadEnabled = true; @@ -116,7 +117,7 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetDial Drawable icon = app.getUIUtilities().getIcon(R.drawable.ic_action_split_interval, nightMode); addProfileView(navigationType, onClickListener, STRAIGHT_LINE_TAG, icon, - app.getText(R.string.routing_profile_straightline), snapToRoadAppMode == null); + app.getText(R.string.routing_profile_straightline), snapToRoadAppMode == DEFAULT_APP_MODE); addDelimiterView(navigationType); for (int i = 0; i < modes.size(); i++) { From 82905381dc232a01495d5f421852aa3274192cdb Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 18 Aug 2020 14:41:36 +0300 Subject: [PATCH 5/7] Plan route point menu - Trim left/Trim right --- .../MeasurementEditingContext.java | 39 +++++++++++++++++-- .../MeasurementToolFragment.java | 31 +++++++++------ ...electedPointBottomSheetDialogFragment.java | 33 ++++++---------- .../command/ClearPointsCommand.java | 36 +++++++++++++---- 4 files changed, 96 insertions(+), 43 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index d83ce40f1b..da881c9d30 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -262,22 +262,55 @@ public class MeasurementEditingContext { return pt; } + public void trimBefore(int selectedPointPosition) { + splitSegments(selectedPointPosition); + clearBeforeSegments(); + } + + public void trimAfter(int selectedPointPosition) { + splitSegments(selectedPointPosition + 1); + clearAfterSegments(); + } + public void clearSegments() { + clearBeforeSegments(); + clearAfterSegments(); + } + + public void clearBeforeSegments() { before.points.clear(); - after.points.clear(); if (isInSnapToRoadMode()) { - if (beforeCacheForSnap != null && afterCacheForSnap != null) { + if (beforeCacheForSnap != null) { beforeCacheForSnap.points.clear(); - afterCacheForSnap.points.clear(); } needUpdateCacheForSnap = true; } else { beforeCacheForSnap = null; + needUpdateCacheForSnap = false; + } + } + + public void clearAfterSegments() { + after.points.clear(); + if (isInSnapToRoadMode()) { + if (afterCacheForSnap != null) { + afterCacheForSnap.points.clear(); + } + needUpdateCacheForSnap = true; + } else { afterCacheForSnap = null; needUpdateCacheForSnap = false; } } + public boolean isFirstPointSelected() { + return selectedPointPosition == 0; + } + + public boolean isLastPointSelected() { + return selectedPointPosition == getPoints().size() - 1; + } + public void scheduleRouteCalculateIfNotEmpty() { needUpdateCacheForSnap = true; if (application == null || (before.points.size() == 0 && after.points.size() == 0)) { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index b534184a34..f7fa333906 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -102,6 +102,8 @@ import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.ADD_TO_ import static net.osmand.plus.measurementtool.SelectFileBottomSheet.Mode.OPEN_TRACK; import static net.osmand.plus.measurementtool.SelectFileBottomSheet.SelectFileListener; import static net.osmand.plus.measurementtool.StartPlanRouteBottomSheet.StartPlanRouteListener; +import static net.osmand.plus.measurementtool.command.ClearPointsCommand.*; +import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCommandMode.*; public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener, OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener { @@ -701,7 +703,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public void clearAllOnClick() { MeasurementToolLayer measurementLayer = getMeasurementLayer(); - editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer)); + editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer, ALL)); editingCtx.cancelSnapToRoad(); if (pointsListOpened) { hidePointsList(); @@ -763,12 +765,25 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public void onTrimRouteBefore() { - + trimRoute(BEFORE); } @Override public void onTrimRouteAfter() { + trimRoute(AFTER); + } + private void trimRoute(ClearCommandMode before) { + MeasurementToolLayer measurementLayer = getMeasurementLayer(); + editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer, before)); + if (pointsListOpened) { + hidePointsList(); + } + editingCtx.setSelectedPointPosition(-1); + editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size()); + updateUndoRedoButton(false, redoBtn); + updateDistancePointsText(); + saved = false; } @Override @@ -1009,7 +1024,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler)); editingCtx.resetAppMode(); editingCtx.cancelSnapToRoad(); - visibleSnapToRoadIcon(false); MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE); @@ -1033,14 +1047,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route } } - private void visibleSnapToRoadIcon(boolean show) { + private void hideSnapToRoadIcon() { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { - if (show) { - mapActivity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.VISIBLE); - } else { - mapActivity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.GONE); - } + mapActivity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.GONE); } } @@ -1794,9 +1804,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route } if (editingCtx.isInSnapToRoadMode()) { resetSnapToRoadMode(); - } else { - visibleSnapToRoadIcon(false); } + hideSnapToRoadIcon(); if (!editingCtx.isNewData() && !planRouteMode) { GPXFile gpx = editingCtx.getNewGpxData().getGpxFile(); Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getTrackActivity()); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java index be6b587c82..bfa1e51df6 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java @@ -37,9 +37,15 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo public static final String TAG = SelectedPointBottomSheetDialogFragment.class.getSimpleName(); private static final Log LOG = PlatformUtil.getLog(SelectedPointBottomSheetDialogFragment.class); + private MeasurementEditingContext editingCtx; @Override public void createMenuItems(Bundle savedInstanceState) { + MapActivity mapActivity = getMapActivity(); + if (mapActivity == null) { + return; + } + editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx(); View titleView = UiUtilities.getInflater(getContext(), nightMode) .inflate(R.layout.bottom_sheet_item_with_descr_pad_32dp, null, false); @@ -126,6 +132,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo dismiss(); } }) + .setDisabled(editingCtx.isFirstPointSelected()) .create(); items.add(trimRouteBefore); @@ -144,6 +151,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo dismiss(); } }) + .setDisabled(editingCtx.isLastPointSelected()) .create(); items.add(trimRouteAfter); @@ -164,6 +172,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo dismiss(); } }) + .setDisabled(editingCtx.isFirstPointSelected()) .create(); items.add(changeRouteTypeBefore); @@ -182,6 +191,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo dismiss(); } }) + .setDisabled(editingCtx.isLastPointSelected()) .create(); items.add(changeRouteTypeAfter); @@ -249,24 +259,15 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo @NonNull private String getTitle() { - MapActivity mapActivity = getMapActivity(); - if (mapActivity == null) { - return ""; - } - - MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx(); int pos = editingCtx.getSelectedPointPosition(); - String pointName = editingCtx.getPoints().get(pos).name; if (!TextUtils.isEmpty(pointName)) { return pointName; } - NewGpxData newGpxData = editingCtx.getNewGpxData(); if (newGpxData != null && newGpxData.getActionType() == ActionType.ADD_ROUTE_POINTS) { return getString(R.string.route_point) + " - " + (pos + 1); } - return getString(R.string.plugin_distance_point) + " - " + (pos + 1); } @@ -276,18 +277,15 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo if (mapActivity == null) { return ""; } - StringBuilder description = new StringBuilder(); - MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx(); int pos = editingCtx.getSelectedPointPosition(); List points = editingCtx.getPoints(); WptPt pt = points.get(pos); - String pointDesc = pt.desc; if (!TextUtils.isEmpty(pointDesc)) { description.append(pointDesc); - } else if (pos < 1) { + } else if (pos < 1 && before) { description.append(getString(R.string.shared_string_control_start)); } else { float dist = 0; @@ -307,7 +305,6 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo } description.append(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication())); } - NewGpxData newGpxData = editingCtx.getNewGpxData(); if (newGpxData != null && newGpxData.getActionType() == ActionType.EDIT_SEGMENT) { double elevation = pt.ele; @@ -321,22 +318,14 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo description.append(OsmAndFormatter.getFormattedSpeed(speed, mapActivity.getMyApplication())); } } - return description.toString(); } @Nullable private Drawable getRouteTypeIcon(boolean before) { Drawable icon = getContentIcon(R.drawable.ic_action_split_interval); - MapActivity mapActivity = getMapActivity(); - if (mapActivity == null) { - return icon; - } - - MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx(); int pos = editingCtx.getSelectedPointPosition(); pos = before ? pos : Math.max(pos - 1, 0); - String profileType = editingCtx.getPoints().get(pos).getProfileType(); ApplicationMode routeAppMode = ApplicationMode.valueOfStringKey(profileType, null); if (routeAppMode != null) { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/command/ClearPointsCommand.java b/OsmAnd/src/net/osmand/plus/measurementtool/command/ClearPointsCommand.java index 9023675105..7748b435ea 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/command/ClearPointsCommand.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/command/ClearPointsCommand.java @@ -4,31 +4,54 @@ import net.osmand.GPXUtilities.WptPt; import net.osmand.plus.measurementtool.MeasurementToolLayer; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; public class ClearPointsCommand extends MeasurementModeCommand { private List points; private boolean needUpdateCache; + ClearCommandMode clearMode; + private int pointPosition; - public ClearPointsCommand(MeasurementToolLayer measurementLayer) { + public enum ClearCommandMode { + ALL, + BEFORE, + AFTER + } + + public ClearPointsCommand(MeasurementToolLayer measurementLayer, ClearCommandMode clearMode) { super(measurementLayer); + this.clearMode = clearMode; } @Override public boolean execute() { + pointPosition = getEditingCtx().getSelectedPointPosition(); + executeCommand(); + return true; + } + + private void executeCommand() { List pts = getEditingCtx().getPoints(); needUpdateCache = getEditingCtx().isNeedUpdateCacheForSnap(); points = new ArrayList<>(pts); - pts.clear(); - getEditingCtx().clearSegments(); + switch (clearMode) { + case ALL: + pts.clear(); + getEditingCtx().clearSegments(); + break; + case BEFORE: + getEditingCtx().trimBefore(pointPosition); + break; + case AFTER: + getEditingCtx().trimAfter(pointPosition); + } refreshMap(); - return true; } @Override public void undo() { + getEditingCtx().clearSegments(); getEditingCtx().addPoints(points); if (needUpdateCache) { getEditingCtx().setNeedUpdateCacheForSnap(true); @@ -38,8 +61,7 @@ public class ClearPointsCommand extends MeasurementModeCommand { @Override public void redo() { - getEditingCtx().clearSegments(); - refreshMap(); + executeCommand(); } @Override From ec690e15489a511c1e94754a877021ef18be1b58 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 21 Aug 2020 12:57:35 +0300 Subject: [PATCH 6/7] Remove Change route type --- .../MeasurementToolFragment.java | 1 + ...electedPointBottomSheetDialogFragment.java | 40 ------------------- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index f7fa333906..ebab5fe724 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -782,6 +782,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route editingCtx.setSelectedPointPosition(-1); editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size()); updateUndoRedoButton(false, redoBtn); + updateUndoRedoButton(true, undoBtn); updateDistancePointsText(); saved = false; } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java index bfa1e51df6..cbdbf126ca 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java @@ -157,46 +157,6 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo items.add(new OptionsDividerItem(getContext())); - BaseBottomSheetItem changeRouteTypeBefore = new BottomSheetItemWithDescription.Builder() - .setDescription(getDescription(true)) - .setIcon(getRouteTypeIcon(true)) - .setTitle(getString(R.string.plan_route_change_route_type_before)) - .setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Fragment targetFragment = getTargetFragment(); - if (targetFragment instanceof SelectedPointFragmentListener) { - ((SelectedPointFragmentListener) targetFragment).onChangeRouteTypeBefore(); - } - dismiss(); - } - }) - .setDisabled(editingCtx.isFirstPointSelected()) - .create(); - items.add(changeRouteTypeBefore); - - BaseBottomSheetItem changeRouteTypeAfter = new BottomSheetItemWithDescription.Builder() - .setDescription(getDescription(false)) - .setIcon(getRouteTypeIcon(false)) - .setTitle(getString(R.string.plan_route_change_route_type_after)) - .setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Fragment targetFragment = getTargetFragment(); - if (targetFragment instanceof SelectedPointFragmentListener) { - ((SelectedPointFragmentListener) targetFragment).onChangeRouteTypeAfter(); - } - dismiss(); - } - }) - .setDisabled(editingCtx.isLastPointSelected()) - .create(); - items.add(changeRouteTypeAfter); - - items.add(new OptionsDividerItem(getContext())); - BaseBottomSheetItem deleteItem = new SimpleBottomSheetItem.Builder() .setIcon(getIcon(R.drawable.ic_action_delete_dark, nightMode ? R.color.color_osm_edit_delete : R.color.color_osm_edit_delete)) From 872d7b5adf2955804317458b236775ee383d5058 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 21 Aug 2020 13:48:46 +0300 Subject: [PATCH 7/7] Fix merge --- .../plus/measurementtool/MeasurementToolFragment.java | 11 ----------- .../OptionsBottomSheetDialogFragment.java | 3 +++ 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 11900eec45..d25dc18c72 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -1033,13 +1033,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route } } - private void hideSnapToRoadIcon() { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - mapActivity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.GONE); - } - } - private void displayRoutePoints() { MeasurementToolLayer measurementLayer = getMeasurementLayer(); GPXFile gpx = editingCtx.getNewGpxData().getGpxFile(); @@ -1762,10 +1755,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route hidePointsList(); } resetAppMode(); - if (editingCtx.isInSnapToRoadMode()) { - resetSnapToRoadMode(); - } - hideSnapToRoadIcon(); if (!editingCtx.isNewData() && !planRouteMode) { GPXFile gpx = editingCtx.getNewGpxData().getGpxFile(); Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getTrackActivity()); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java index a9cf80ab2f..a4d2240725 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java @@ -3,8 +3,11 @@ package net.osmand.plus.measurementtool; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager;