diff --git a/OsmAnd/res/layout/custom_radio_buttons.xml b/OsmAnd/res/layout/custom_radio_buttons.xml index a5ec943f6a..d768e58004 100644 --- a/OsmAnd/res/layout/custom_radio_buttons.xml +++ b/OsmAnd/res/layout/custom_radio_buttons.xml @@ -4,7 +4,8 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/custom_radio_buttons" android:layout_width="match_parent" - android:layout_height="@dimen/dialog_button_height" + android:minHeight="@dimen/dialog_button_height" + android:layout_height="wrap_content" android:layout_marginStart="@dimen/content_padding" android:layout_marginEnd="@dimen/content_padding" android:background="?attr/btn_bg_border_inactive" diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/RouteBetweenPointsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/RouteBetweenPointsBottomSheetDialogFragment.java index f57cbd4e04..ebe9bfeb9c 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/RouteBetweenPointsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/RouteBetweenPointsBottomSheetDialogFragment.java @@ -2,6 +2,7 @@ package net.osmand.plus.measurementtool; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.util.Pair; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; @@ -13,25 +14,84 @@ import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; +import net.osmand.GPXUtilities; import net.osmand.PlatformUtil; +import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; 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.settings.backend.ApplicationMode; +import net.osmand.util.MapUtils; import org.apache.commons.logging.Log; import java.util.ArrayList; import java.util.List; +import java.util.Map; import static net.osmand.plus.UiUtilities.CustomRadioButtonType.LEFT; import static net.osmand.plus.UiUtilities.CustomRadioButtonType.RIGHT; import static net.osmand.plus.measurementtool.MeasurementEditingContext.DEFAULT_APP_MODE; + + public class RouteBetweenPointsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { + @NonNull + private String getDescription(boolean before, boolean single) { + MapActivity mapActivity = (MapActivity) getActivity(); + if (mapActivity == null) { + return ""; + } + + MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx(); + int pos = editingCtx.getSelectedPointPosition(); + List points = editingCtx.getPoints(); + + int startIdx; + int endIdx; + if (before) { + startIdx = 1; + endIdx = pos; + } else { + startIdx = pos + 1; + endIdx = points.size() - 1; + } + + float dist = !single ? getDistForAllSegments(points, startIdx, endIdx) : getDistForSingleSegment(editingCtx, points, startIdx, endIdx); + + return OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()); + } + + private float getDistForAllSegments(List points, int startIdx, int endIdx) { + float dist = 0; + for (int i = startIdx; i <= endIdx; i++) { + GPXUtilities.WptPt first = points.get(i - 1); + GPXUtilities.WptPt second = points.get(i); + dist += MapUtils.getDistance(first.lat, first.lon, second.lat, second.lon); + } + return dist; + } + + private float getDistForSingleSegment(MeasurementEditingContext editingCtx, List points, int startIdx, int endIdx) { + float dist = 0; + Map, MeasurementEditingContext.RoadSegmentData> roadSegmentDataMap = editingCtx.getRoadSegmentData(); + if (startIdx <= endIdx) { + Pair pair = new Pair<>(points.get(startIdx), points.get(startIdx - 1)); + MeasurementEditingContext.RoadSegmentData data = roadSegmentDataMap.get(pair); + if (data == null) { + dist += MapUtils.getDistance(pair.first.getLatitude(), pair.first.getLongitude(), + pair.second.getLatitude(), pair.second.getLongitude()); + } else { + dist += data.getDistance(); + } + } + return dist; + } + private static final Log LOG = PlatformUtil.getLog(RouteBetweenPointsBottomSheetDialogFragment.class); public static final String TAG = RouteBetweenPointsBottomSheetDialogFragment.class.getSimpleName(); public static final int STRAIGHT_LINE_TAG = -1; @@ -71,23 +131,24 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends MenuBottomSheet case NEXT_ROUTE_CALCULATION: switch (dialogMode) { case SINGLE: - return getString(R.string.next_segment); + return getString(R.string.next_segment) + " " + getDescription(false, true); case ALL: - return getString(R.string.all_next_segments); + return getString(R.string.all_next_segments) + " " + getDescription(false, false); } break; case PREV_ROUTE_CALCULATION: switch (dialogMode) { case SINGLE: - return getString(R.string.previous_segment); + return getString(R.string.previous_segment) + " " + getDescription(true, true); case ALL: - return getString(R.string.all_previous_segments); + return getString(R.string.all_previous_segments) + " " + getDescription(true, false); } break; } return ""; } + private String getButtonDescr(RouteBetweenPointsDialogMode dialogMode) { switch (dialogType) { case WHOLE_ROUTE_CALCULATION: diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java index 9fac103fc5..f3dde5d561 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java @@ -158,7 +158,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) @@ -177,7 +176,6 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo 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)