Plan route point menu UI
This commit is contained in:
parent
7e2dfb4344
commit
d413591a0d
5 changed files with 377 additions and 128 deletions
|
@ -11,7 +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="rourte_between_points_add_track_desc">Select a track file for which a new segment will be added.</string>
|
||||
<string name="navigation_profile">Navigation profile</string>
|
||||
<string name="threshold_distance">Threshold distance</string>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue