From 794d611f606fc3f24323c67dfc96ff2305d00236 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 16 Jul 2020 18:51:57 +0300 Subject: [PATCH] Fix straight line --- .../MeasurementToolFragment.java | 1 + .../SnapToRoadBottomSheetDialogFragment.java | 43 +++++++++++-------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 17eb772064..0e7c9c0012 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -571,6 +571,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { mapActivity.refreshMap(); SnapToRoadBottomSheetDialogFragment fragment = new SnapToRoadBottomSheetDialogFragment(); fragment.setListener(createSnapToRoadFragmentListener()); + fragment.setShowStraightLine(true); fragment.show(mapActivity.getSupportFragmentManager(), SnapToRoadBottomSheetDialogFragment.TAG); } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java index 37637c7a02..35f3bc47cd 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java @@ -2,6 +2,7 @@ package net.osmand.plus.measurementtool; import android.app.Dialog; import android.content.DialogInterface; +import android.graphics.drawable.Drawable; import android.view.ContextThemeWrapper; import android.view.View; import android.view.Window; @@ -18,6 +19,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import net.osmand.AndroidUtils; 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.helpers.AndroidUiHelper; import net.osmand.plus.settings.backend.ApplicationMode; @@ -35,6 +37,7 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme private boolean portrait; private boolean snapToRoadEnabled; private boolean removeDefaultMode = true; + private boolean showStraightLine = false; public void setListener(SnapToRoadFragmentListener listener) { this.listener = listener; @@ -44,6 +47,10 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme this.removeDefaultMode = removeDefaultMode; } + public void setShowStraightLine(boolean showStraightLine) { + this.showStraightLine = showStraightLine; + } + @Override public void setupDialog(Dialog dialog, int style) { super.setupDialog(dialog, style); @@ -78,10 +85,10 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View view) { - snapToRoadEnabled = true; + snapToRoadEnabled = false; if (listener != null) { - ApplicationMode mode=null; - if((int)view.getTag()!= STRAIGHT_LINE_TAG) { + ApplicationMode mode = null; + if ((int) view.getTag() != STRAIGHT_LINE_TAG) { mode = modes.get((int) view.getTag()); snapToRoadEnabled = true; } @@ -91,23 +98,16 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme } }; - View row = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.list_item_icon_and_title, null); - ((ImageView) row.findViewById(R.id.icon)).setImageDrawable( - app.getUIUtilities().getIcon(R.drawable.ic_action_split_interval, nightMode)); - ((TextView) row.findViewById(R.id.title)).setText(app.getText(R.string.routing_profile_straightline)); - row.setOnClickListener(onClickListener); - row.setTag(STRAIGHT_LINE_TAG); - container.addView(row); + if (showStraightLine) { + Drawable icon = app.getUIUtilities().getIcon(R.drawable.ic_action_split_interval, nightMode); + addProfileView(container, onClickListener, STRAIGHT_LINE_TAG, icon, + app.getText(R.string.routing_profile_straightline)); + } for (int i = 0; i < modes.size(); i++) { ApplicationMode mode = modes.get(i); - row = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.list_item_icon_and_title, null); - ((ImageView) row.findViewById(R.id.icon)).setImageDrawable( - app.getUIUtilities().getIcon(mode.getIconRes(), mode.getIconColorInfo().getColor(nightMode))); - ((TextView) row.findViewById(R.id.title)).setText(mode.toHumanString()); - row.setOnClickListener(onClickListener); - row.setTag(i); - container.addView(row); + Drawable icon = app.getUIUtilities().getIcon(mode.getIconRes(), mode.getIconColorInfo().getColor(nightMode)); + addProfileView(container, onClickListener, i, icon, mode.toHumanString()); } if (!portrait) { @@ -125,6 +125,15 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme ((View) mainView.getParent()).setBackgroundResource(0); } + private void addProfileView(LinearLayout container, View.OnClickListener onClickListener, Object tag, Drawable icon, CharSequence title) { + View row = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.list_item_icon_and_title, null); + ((ImageView) row.findViewById(R.id.icon)).setImageDrawable(icon); + ((TextView) row.findViewById(R.id.title)).setText(title); + row.setOnClickListener(onClickListener); + row.setTag(tag); + container.addView(row); + } + @Override public void onStart() { super.onStart();