Point_menu
This commit is contained in:
parent
b5df0d9271
commit
dbaf1a5fd2
3 changed files with 67 additions and 7 deletions
|
@ -4,7 +4,8 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/custom_radio_buttons"
|
android:id="@+id/custom_radio_buttons"
|
||||||
android:layout_width="match_parent"
|
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_marginStart="@dimen/content_padding"
|
||||||
android:layout_marginEnd="@dimen/content_padding"
|
android:layout_marginEnd="@dimen/content_padding"
|
||||||
android:background="?attr/btn_bg_border_inactive"
|
android:background="?attr/btn_bg_border_inactive"
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.measurementtool;
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Pair;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
@ -13,25 +14,84 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
|
import net.osmand.GPXUtilities;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.LEFT;
|
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.LEFT;
|
||||||
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.RIGHT;
|
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.RIGHT;
|
||||||
import static net.osmand.plus.measurementtool.MeasurementEditingContext.DEFAULT_APP_MODE;
|
import static net.osmand.plus.measurementtool.MeasurementEditingContext.DEFAULT_APP_MODE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class RouteBetweenPointsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
|
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<GPXUtilities.WptPt> 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<GPXUtilities.WptPt> 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<GPXUtilities.WptPt> points, int startIdx, int endIdx) {
|
||||||
|
float dist = 0;
|
||||||
|
Map<Pair<GPXUtilities.WptPt, GPXUtilities.WptPt>, MeasurementEditingContext.RoadSegmentData> roadSegmentDataMap = editingCtx.getRoadSegmentData();
|
||||||
|
if (startIdx <= endIdx) {
|
||||||
|
Pair<GPXUtilities.WptPt, GPXUtilities.WptPt> 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);
|
private static final Log LOG = PlatformUtil.getLog(RouteBetweenPointsBottomSheetDialogFragment.class);
|
||||||
public static final String TAG = RouteBetweenPointsBottomSheetDialogFragment.class.getSimpleName();
|
public static final String TAG = RouteBetweenPointsBottomSheetDialogFragment.class.getSimpleName();
|
||||||
public static final int STRAIGHT_LINE_TAG = -1;
|
public static final int STRAIGHT_LINE_TAG = -1;
|
||||||
|
@ -71,23 +131,24 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends MenuBottomSheet
|
||||||
case NEXT_ROUTE_CALCULATION:
|
case NEXT_ROUTE_CALCULATION:
|
||||||
switch (dialogMode) {
|
switch (dialogMode) {
|
||||||
case SINGLE:
|
case SINGLE:
|
||||||
return getString(R.string.next_segment);
|
return getString(R.string.next_segment) + " " + getDescription(false, true);
|
||||||
case ALL:
|
case ALL:
|
||||||
return getString(R.string.all_next_segments);
|
return getString(R.string.all_next_segments) + " " + getDescription(false, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PREV_ROUTE_CALCULATION:
|
case PREV_ROUTE_CALCULATION:
|
||||||
switch (dialogMode) {
|
switch (dialogMode) {
|
||||||
case SINGLE:
|
case SINGLE:
|
||||||
return getString(R.string.previous_segment);
|
return getString(R.string.previous_segment) + " " + getDescription(true, true);
|
||||||
case ALL:
|
case ALL:
|
||||||
return getString(R.string.all_previous_segments);
|
return getString(R.string.all_previous_segments) + " " + getDescription(true, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String getButtonDescr(RouteBetweenPointsDialogMode dialogMode) {
|
private String getButtonDescr(RouteBetweenPointsDialogMode dialogMode) {
|
||||||
switch (dialogType) {
|
switch (dialogType) {
|
||||||
case WHOLE_ROUTE_CALCULATION:
|
case WHOLE_ROUTE_CALCULATION:
|
||||||
|
|
|
@ -158,7 +158,6 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
|
||||||
items.add(new OptionsDividerItem(getContext()));
|
items.add(new OptionsDividerItem(getContext()));
|
||||||
|
|
||||||
BaseBottomSheetItem changeRouteTypeBefore = new BottomSheetItemWithDescription.Builder()
|
BaseBottomSheetItem changeRouteTypeBefore = new BottomSheetItemWithDescription.Builder()
|
||||||
.setDescription(getDescription(true))
|
|
||||||
.setIcon(getRouteTypeIcon(true))
|
.setIcon(getRouteTypeIcon(true))
|
||||||
.setTitle(getString(R.string.plan_route_change_route_type_before))
|
.setTitle(getString(R.string.plan_route_change_route_type_before))
|
||||||
.setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp)
|
.setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp)
|
||||||
|
@ -177,7 +176,6 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo
|
||||||
items.add(changeRouteTypeBefore);
|
items.add(changeRouteTypeBefore);
|
||||||
|
|
||||||
BaseBottomSheetItem changeRouteTypeAfter = new BottomSheetItemWithDescription.Builder()
|
BaseBottomSheetItem changeRouteTypeAfter = new BottomSheetItemWithDescription.Builder()
|
||||||
.setDescription(getDescription(false))
|
|
||||||
.setIcon(getRouteTypeIcon(false))
|
.setIcon(getRouteTypeIcon(false))
|
||||||
.setTitle(getString(R.string.plan_route_change_route_type_after))
|
.setTitle(getString(R.string.plan_route_change_route_type_after))
|
||||||
.setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp)
|
.setLayoutId(R.layout.bottom_sheet_item_with_descr_pad_32dp)
|
||||||
|
|
Loading…
Reference in a new issue