small fixes

This commit is contained in:
Vitaliy 2020-11-23 02:12:13 +02:00
parent 4c100c7366
commit c9b6baabfd

View file

@ -2,7 +2,6 @@ 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;
@ -15,14 +14,14 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.WptPt;
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.base.BottomSheetBehaviourDialogFragment;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BottomSheetBehaviourDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.util.MapUtils;
@ -31,10 +30,9 @@ 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.START;
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.END;
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.START;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.DEFAULT_APP_MODE;
import static net.osmand.plus.measurementtool.SelectFileBottomSheet.BOTTOM_SHEET_HEIGHT_DP;
@ -67,153 +65,6 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetBeha
ALL,
}
private String getButtonText(RouteBetweenPointsDialogMode dialogMode) {
switch (dialogType) {
case WHOLE_ROUTE_CALCULATION:
switch (dialogMode) {
case SINGLE:
return getString(R.string.next_segment);
case ALL:
return getString(R.string.whole_track);
}
break;
case NEXT_ROUTE_CALCULATION:
switch (dialogMode) {
case SINGLE:
return getString(R.string.next_segment) + " " + getDescription(false, true);
case ALL:
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) + " " + getDescription(true, true);
case ALL:
return getString(R.string.all_previous_segments) + " " + getDescription(true, false);
}
break;
}
return "";
}
private String getButtonDescr(RouteBetweenPointsDialogMode dialogMode) {
switch (dialogType) {
case WHOLE_ROUTE_CALCULATION:
switch (dialogMode) {
case SINGLE:
return getString(R.string.route_between_points_next_segment_button_desc);
case ALL:
return getString(R.string.route_between_points_whole_track_button_desc);
}
break;
case NEXT_ROUTE_CALCULATION:
switch (dialogMode) {
case SINGLE:
return getString(R.string.only_selected_segment_recalc);
case ALL:
return getString(R.string.all_next_segments_will_be_recalc);
}
break;
case PREV_ROUTE_CALCULATION:
switch (dialogMode) {
case SINGLE:
return getString(R.string.only_selected_segment_recalc);
case ALL:
return getString(R.string.all_previous_segments_will_be_recalc);
}
break;
}
return "";
}
@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 void addDelimiterView(LinearLayout container) {
View row = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.divider, container, false);
View divider = row.findViewById(R.id.divider);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) divider.getLayoutParams();
params.topMargin = row.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_title_padding_bottom);
params.bottomMargin = row.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_title_padding_bottom);
container.addView(row);
}
public void setDefaultDialogMode(RouteBetweenPointsDialogMode defaultDialogMode) {
this.defaultDialogMode = defaultDialogMode;
updateModeButtons();
}
public void updateModeButtons() {
UiUtilities.updateCustomRadioButtons(getMyApplication(), customRadioButton, nightMode,
defaultDialogMode == RouteBetweenPointsDialogMode.SINGLE ? START : END);
btnDescription.setText(getButtonDescr(defaultDialogMode));
}
private void addProfileView(LinearLayout container, View.OnClickListener onClickListener, Object tag,
Drawable icon, CharSequence title, boolean check) {
View row = UiUtilities.getInflater(getContext(), nightMode)
.inflate(R.layout.bottom_sheet_item_with_radio_btn, container, false);
((RadioButton) row.findViewById(R.id.compound_button)).setChecked(check);
ImageView imageView = row.findViewById(R.id.icon);
imageView.setImageDrawable(icon);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) imageView.getLayoutParams();
params.rightMargin = container.getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin_large);
((TextView) row.findViewById(R.id.title)).setText(title);
row.setOnClickListener(onClickListener);
row.setTag(tag);
container.addView(row);
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
Bundle args = getArguments();
@ -232,6 +83,7 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetBeha
.inflate(R.layout.fragment_route_between_points_bottom_sheet_dialog,
null, false);
customRadioButton = mainView.findViewById(R.id.custom_radio_buttons);
customRadioButton.setMinimumHeight(getResources().getDimensionPixelSize(R.dimen.route_info_control_buttons_height));
TextView singleModeButton = mainView.findViewById(R.id.left_button);
singleModeButton.setText(getButtonText(RouteBetweenPointsDialogMode.SINGLE));
TextView allModeButton = mainView.findViewById(R.id.right_button);
@ -312,6 +164,137 @@ public class RouteBetweenPointsBottomSheetDialogFragment extends BottomSheetBeha
super.onDestroyView();
}
private void addDelimiterView(LinearLayout container) {
View row = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.divider, container, false);
View divider = row.findViewById(R.id.divider);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) divider.getLayoutParams();
params.topMargin = row.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_title_padding_bottom);
params.bottomMargin = row.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_title_padding_bottom);
container.addView(row);
}
public void setDefaultDialogMode(RouteBetweenPointsDialogMode defaultDialogMode) {
this.defaultDialogMode = defaultDialogMode;
updateModeButtons();
}
public void updateModeButtons() {
UiUtilities.updateCustomRadioButtons(getMyApplication(), customRadioButton, nightMode,
defaultDialogMode == RouteBetweenPointsDialogMode.SINGLE ? START : END);
btnDescription.setText(getButtonDescr(defaultDialogMode));
}
private void addProfileView(LinearLayout container, View.OnClickListener onClickListener, Object tag,
Drawable icon, CharSequence title, boolean check) {
View row = UiUtilities.getInflater(getContext(), nightMode)
.inflate(R.layout.bottom_sheet_item_with_radio_btn, container, false);
((RadioButton) row.findViewById(R.id.compound_button)).setChecked(check);
ImageView imageView = row.findViewById(R.id.icon);
imageView.setImageDrawable(icon);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) imageView.getLayoutParams();
params.rightMargin = container.getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin_large);
((TextView) row.findViewById(R.id.title)).setText(title);
row.setOnClickListener(onClickListener);
row.setTag(tag);
container.addView(row);
}
private String getButtonText(RouteBetweenPointsDialogMode dialogMode) {
switch (dialogType) {
case WHOLE_ROUTE_CALCULATION:
switch (dialogMode) {
case SINGLE:
return getString(R.string.next_segment);
case ALL:
return getString(R.string.whole_track);
}
break;
case NEXT_ROUTE_CALCULATION:
String nextDescr = getDescription(false, dialogMode);
switch (dialogMode) {
case SINGLE:
return getString(R.string.ltr_or_rtl_combine_via_space, getString(R.string.next_segment), nextDescr);
case ALL:
return getString(R.string.ltr_or_rtl_combine_via_space, getString(R.string.all_next_segments), nextDescr);
}
break;
case PREV_ROUTE_CALCULATION:
String prevDescr = getDescription(true, dialogMode);
switch (dialogMode) {
case SINGLE:
return getString(R.string.ltr_or_rtl_combine_via_space, getString(R.string.previous_segment), prevDescr);
case ALL:
return getString(R.string.ltr_or_rtl_combine_via_space, getString(R.string.all_previous_segments), prevDescr);
}
break;
}
return "";
}
private String getButtonDescr(RouteBetweenPointsDialogMode dialogMode) {
switch (dialogType) {
case WHOLE_ROUTE_CALCULATION:
switch (dialogMode) {
case SINGLE:
return getString(R.string.route_between_points_next_segment_button_desc);
case ALL:
return getString(R.string.route_between_points_whole_track_button_desc);
}
break;
case NEXT_ROUTE_CALCULATION:
switch (dialogMode) {
case SINGLE:
return getString(R.string.only_selected_segment_recalc);
case ALL:
return getString(R.string.all_next_segments_will_be_recalc);
}
break;
case PREV_ROUTE_CALCULATION:
switch (dialogMode) {
case SINGLE:
return getString(R.string.only_selected_segment_recalc);
case ALL:
return getString(R.string.all_previous_segments_will_be_recalc);
}
break;
}
return "";
}
@NonNull
private String getDescription(boolean before, RouteBetweenPointsDialogMode dialogMode) {
MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity == null) {
return "";
}
MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx();
int pos = editingCtx.getSelectedPointPosition();
List<WptPt> points = editingCtx.getPoints();
float dist = 0;
if (dialogMode == RouteBetweenPointsDialogMode.SINGLE) {
WptPt selectedPoint = points.get(pos);
WptPt second = points.get(before ? pos - 1 : pos + 1);
dist += MapUtils.getDistance(selectedPoint.lat, selectedPoint.lon, second.lat, second.lon);
} else {
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);
}
}
return OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication());
}
public static void showInstance(FragmentManager fm, Fragment targetFragment,
RouteBetweenPointsDialogType dialogType,
RouteBetweenPointsDialogMode defaultDialogMode,