Merge pull request #9677 from osmandapp/plan_route_point_menu_trim
Plan route point menu trim
This commit is contained in:
commit
aeb10fa101
11 changed files with 491 additions and 167 deletions
|
@ -33,7 +33,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
style="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="Some title" />
|
||||
|
||||
<TextView
|
||||
|
@ -42,7 +42,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:textAppearance="@style/TextAppearance.ContextMenuSubtitle"
|
||||
style="@style/TextAppearance.ContextMenuSubtitle"
|
||||
tools:text="Some description" />
|
||||
</LinearLayout>
|
||||
|
||||
|
|
48
OsmAnd/res/layout/bottom_sheet_item_with_descr_pad_32dp.xml
Normal file
48
OsmAnd/res/layout/bottom_sheet_item_with_descr_pad_32dp.xml
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:minHeight="@dimen/measurement_tool_up_down_row_height"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="@dimen/standard_icon_size"
|
||||
android:layout_height="@dimen/standard_icon_size"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin_large"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin_large"
|
||||
tools:src="@drawable/list_destination" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
style="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="Some title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
style="@style/TextAppearance.ContextMenuSubtitle"
|
||||
tools:text="Some description" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -6,6 +6,10 @@
|
|||
android:orientation="vertical"
|
||||
tools:background="?attr/bg_color">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scroll_view"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -26,6 +30,15 @@
|
|||
android:orientation="vertical"
|
||||
android:visibility="gone" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/buttons_shadow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="10dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:visibility="gone"
|
||||
android:background="@drawable/bg_contextmenu_shadow_top_light" />
|
||||
</FrameLayout>
|
||||
|
||||
<include layout="@layout/bottom_buttons" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="plan_route_change_route_type_after">Change route type after</string>
|
||||
<string name="plan_route_change_route_type_before">Change route type before</string>
|
||||
<string name="plan_route_trim_after">Trim after</string>
|
||||
<string name="plan_route_trim_before">Trim before</string>
|
||||
<string name="access_hint_enter_address">Enter address</string>
|
||||
<string name="add_address">Add address</string>
|
||||
<string name="delete_address">Delete address</string>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -293,15 +293,43 @@ 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 (beforeCacheForSnap != null && afterCacheForSnap != null) {
|
||||
if (beforeCacheForSnap != null) {
|
||||
beforeCacheForSnap.points.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAfterSegments() {
|
||||
after.points.clear();
|
||||
if (afterCacheForSnap != null) {
|
||||
afterCacheForSnap.points.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFirstPointSelected() {
|
||||
return selectedPointPosition == 0;
|
||||
}
|
||||
|
||||
public boolean isLastPointSelected() {
|
||||
return selectedPointPosition == getPoints().size() - 1;
|
||||
}
|
||||
|
||||
public void scheduleRouteCalculateIfNotEmpty() {
|
||||
if (application == null || (before.points.size() == 0 && after.points.size() == 0)) {
|
||||
return;
|
||||
|
|
|
@ -100,9 +100,11 @@ 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 {
|
||||
OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener {
|
||||
|
||||
public static final String TAG = MeasurementToolFragment.class.getSimpleName();
|
||||
|
||||
|
@ -194,12 +196,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());
|
||||
|
@ -706,7 +702,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();
|
||||
|
@ -722,13 +718,9 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
|
||||
}
|
||||
|
||||
private SelectedPointFragmentListener createSelectedPointFragmentListener() {
|
||||
return new SelectedPointFragmentListener() {
|
||||
|
||||
final MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
|
||||
@Override
|
||||
public void moveOnClick() {
|
||||
public void onMovePoint() {
|
||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
if (measurementLayer != null) {
|
||||
measurementLayer.enterMovingPointMode();
|
||||
}
|
||||
|
@ -736,13 +728,17 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
}
|
||||
|
||||
@Override
|
||||
public void deleteOnClick() {
|
||||
public void onDeletePoint() {
|
||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
if (measurementLayer != null) {
|
||||
removePoint(measurementLayer, editingCtx.getSelectedPointPosition());
|
||||
}
|
||||
editingCtx.setSelectedPointPosition(-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPointAfterOnClick() {
|
||||
public void onAddPointAfter() {
|
||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
if (measurementLayer != null) {
|
||||
measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition());
|
||||
editingCtx.setInAddPointMode(true);
|
||||
|
@ -754,7 +750,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
}
|
||||
|
||||
@Override
|
||||
public void addPointBeforeOnClick() {
|
||||
public void onAddPointBefore() {
|
||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
if (measurementLayer != null) {
|
||||
measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition());
|
||||
editingCtx.setInAddPointMode(true);
|
||||
|
@ -765,6 +762,40 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
switchAddPointBeforeAfterMode(true);
|
||||
}
|
||||
|
||||
@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);
|
||||
updateUndoRedoButton(true, undoBtn);
|
||||
updateDistancePointsText();
|
||||
saved = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeRouteTypeBefore() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeRouteTypeAfter() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCloseMenu() {
|
||||
setDefaultMapPosition();
|
||||
|
@ -774,8 +805,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
public void onClearSelection() {
|
||||
editingCtx.setSelectedPointPosition(-1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCloseRouteDialog() {
|
||||
|
@ -981,7 +1010,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);
|
||||
|
@ -1005,17 +1033,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
}
|
||||
}
|
||||
|
||||
private void visibleSnapToRoadIcon(boolean show) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void displayRoutePoints() {
|
||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
|
||||
|
@ -1037,10 +1054,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) {
|
||||
|
|
|
@ -15,7 +15,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;
|
||||
|
@ -58,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) {
|
||||
|
@ -118,8 +119,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() {
|
||||
|
@ -138,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() {
|
||||
|
|
|
@ -2,45 +2,61 @@ 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 android.widget.TextView;
|
||||
|
||||
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.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.BottomSheetItemWithDescription;
|
||||
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.helpers.FontCache;
|
||||
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);
|
||||
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);
|
||||
TextView title = titleView.findViewById(R.id.title);
|
||||
title.setTypeface(FontCache.getRobotoMedium(getActivity()));
|
||||
|
||||
BaseBottomSheetItem titleItem = new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(getDescription())
|
||||
.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);
|
||||
|
||||
|
@ -49,12 +65,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 +79,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 +101,96 @@ 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 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_pad_32dp)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Fragment targetFragment = getTargetFragment();
|
||||
if (targetFragment instanceof SelectedPointFragmentListener) {
|
||||
((SelectedPointFragmentListener) targetFragment).onTrimRouteBefore();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.setDisabled(editingCtx.isFirstPointSelected())
|
||||
.create();
|
||||
items.add(trimRouteBefore);
|
||||
|
||||
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_pad_32dp)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Fragment targetFragment = getTargetFragment();
|
||||
if (targetFragment instanceof SelectedPointFragmentListener) {
|
||||
((SelectedPointFragmentListener) targetFragment).onTrimRouteAfter();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.setDisabled(editingCtx.isLastPointSelected())
|
||||
.create();
|
||||
items.add(trimRouteAfter);
|
||||
|
||||
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 +202,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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,56 +219,52 @@ 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);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String getDescription() {
|
||||
private String getDescription(boolean before) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
StringBuilder description = new StringBuilder();
|
||||
|
||||
MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx();
|
||||
int pos = editingCtx.getSelectedPointPosition();
|
||||
List<WptPt> 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;
|
||||
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);
|
||||
}
|
||||
description.append(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
|
||||
}
|
||||
|
||||
NewGpxData newGpxData = editingCtx.getNewGpxData();
|
||||
if (newGpxData != null && newGpxData.getActionType() == ActionType.EDIT_SEGMENT) {
|
||||
double elevation = pt.ele;
|
||||
|
@ -216,19 +278,52 @@ 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);
|
||||
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();
|
||||
|
||||
|
|
|
@ -9,23 +9,48 @@ import java.util.List;
|
|||
public class ClearPointsCommand extends MeasurementModeCommand {
|
||||
|
||||
private List<WptPt> 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<WptPt> pts = getEditingCtx().getPoints();
|
||||
points = new ArrayList<>(pts);
|
||||
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);
|
||||
getEditingCtx().updateCacheForSnap();
|
||||
refreshMap();
|
||||
|
@ -33,8 +58,7 @@ public class ClearPointsCommand extends MeasurementModeCommand {
|
|||
|
||||
@Override
|
||||
public void redo() {
|
||||
getEditingCtx().clearSegments();
|
||||
refreshMap();
|
||||
executeCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue