From e1086074c5d370adfe19241a6440ff7f3103ab08 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Mon, 28 Sep 2020 18:10:15 +0300 Subject: [PATCH] Fix #9902 --- OsmAnd/res/values/strings.xml | 1 + .../plus/dialogs/GpxAppearanceAdapter.java | 46 ++++++++++----- .../net/osmand/plus/helpers/GpxUiHelper.java | 16 +++-- .../plus/settings/backend/OsmandSettings.java | 2 + .../plus/track/ShowStartFinishCard.java | 59 +++++++++++++++++++ .../plus/track/TrackAppearanceFragment.java | 21 ++++++- .../osmand/plus/track/TrackColoringCard.java | 5 +- .../net/osmand/plus/track/TrackDrawInfo.java | 3 +- .../osmand/plus/views/layers/GPXLayer.java | 29 +++++---- 9 files changed, 145 insertions(+), 37 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/track/ShowStartFinishCard.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 14e08c0176..086a7470d5 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + Start/finish icons Name: A – Z Name: Z – A Last modified diff --git a/OsmAnd/src/net/osmand/plus/dialogs/GpxAppearanceAdapter.java b/OsmAnd/src/net/osmand/plus/dialogs/GpxAppearanceAdapter.java index 1a1e873b95..87af46891a 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/GpxAppearanceAdapter.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/GpxAppearanceAdapter.java @@ -25,10 +25,13 @@ public class GpxAppearanceAdapter extends ArrayAdapter getAppearanceItems(OsmandApplication app, GpxAppearanceAdapterType adapterType) { + return getAppearanceItems(app, adapterType, false); + } + + public static List getAppearanceItems(OsmandApplication app, GpxAppearanceAdapterType adapterType, + boolean showStartFinishIcons) { List items = new ArrayList<>(); RenderingRuleProperty trackWidthProp = null; RenderingRuleProperty trackColorProp = null; @@ -118,11 +126,19 @@ public class GpxAppearanceAdapter extends ArrayAdapter 0) { for (Map.Entry entry : gpxAppearanceParams.entrySet()) { - final OsmandSettings.CommonPreference pref - = app.getSettings().getCustomRenderProperty(entry.getKey()); - pref.set(entry.getValue()); + if (SHOW_START_FINISH_ATTR.equals(entry.getKey())) { + app.getSettings().SHOW_START_FINISH_ICONS.set("true".equals(entry.getValue())); + } else { + final OsmandSettings.CommonPreference pref + = app.getSettings().getCustomRenderProperty(entry.getKey()); + pref.set(entry.getValue()); + } } if (activity instanceof MapActivity) { ConfigureMapMenu.refreshMapComplete((MapActivity) activity); diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index e41c7d58df..efa7147e6c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -2214,6 +2214,8 @@ public class OsmandSettings { } }.makeProfile().cache(); + public final OsmandPreference SHOW_START_FINISH_ICONS = new BooleanPreference("show_start_finish_icons", true).makeGlobal().cache(); + public final OsmandPreference GPX_ROUTE_CALC_OSMAND_PARTS = new BooleanPreference("gpx_routing_calculate_osmand_route", true).makeGlobal().cache(); // public final OsmandPreference GPX_CALCULATE_RTEPT = new BooleanPreference("gpx_routing_calculate_rtept", true).makeGlobal().cache(); public final OsmandPreference GPX_ROUTE_CALC = new BooleanPreference("calc_gpx_route", false).makeGlobal().cache(); diff --git a/OsmAnd/src/net/osmand/plus/track/ShowStartFinishCard.java b/OsmAnd/src/net/osmand/plus/track/ShowStartFinishCard.java new file mode 100644 index 0000000000..3941bdbb15 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/track/ShowStartFinishCard.java @@ -0,0 +1,59 @@ +package net.osmand.plus.track; + +import android.view.View; +import android.widget.CompoundButton; +import android.widget.TextView; + +import androidx.annotation.NonNull; + +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.routepreparationmenu.cards.BaseCard; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference; + +class ShowStartFinishCard extends BaseCard { + + private TrackDrawInfo trackDrawInfo; + private OsmandPreference showStartFinishPreference; + + public ShowStartFinishCard(@NonNull MapActivity mapActivity, @NonNull TrackDrawInfo trackDrawInfo) { + super(mapActivity); + this.showStartFinishPreference = app.getSettings().SHOW_START_FINISH_ICONS; + this.trackDrawInfo = trackDrawInfo; + } + + @Override + public int getCardLayoutId() { + return R.layout.bottom_sheet_item_with_switch; + } + + @Override + protected void updateContent() { + AndroidUiHelper.updateVisibility(view.findViewById(R.id.icon), false); + + TextView titleView = view.findViewById(R.id.title); + titleView.setText(R.string.track_show_start_finish_icons); + + final CompoundButton compoundButton = view.findViewById(R.id.compound_button); + //compoundButton.setChecked(trackDrawInfo.isShowStartFinish()); + compoundButton.setChecked(showStartFinishPreference.get()); + + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + boolean checked = !compoundButton.isChecked(); + compoundButton.setChecked(checked); + //trackDrawInfo.setShowStartFinish(checked); + showStartFinishPreference.set(checked); + mapActivity.refreshMap(); + + CardListener listener = getListener(); + if (listener != null) { + listener.onCardPressed(ShowStartFinishCard.this); + } + } + }); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index 4381dd61f6..81a43da20f 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -62,9 +62,10 @@ import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_MEDIUM; public class TrackAppearanceFragment extends ContextMenuScrollFragment implements CardListener, ColorPickerListener { public static final String TAG = TrackAppearanceFragment.class.getName(); - private static final Log log = PlatformUtil.getLog(TrackAppearanceFragment.class); + private static final String SHOW_START_FINISH_ICONS_INITIAL_VALUE_KEY = "showStartFinishIconsInitialValueKey"; + private OsmandApplication app; @Nullable @@ -79,6 +80,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement private TrackWidthCard trackWidthCard; private SplitIntervalCard splitIntervalCard; private TrackColoringCard trackColoringCard; + private boolean showStartFinishIconsInitialValue; private ImageView trackIcon; private View buttonsShadow; @@ -134,9 +136,12 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement if (!selectedGpxFile.isShowCurrentTrack()) { gpxDataItem = app.getGpxDbHelper().getItem(new File(trackDrawInfo.getFilePath())); } + showStartFinishIconsInitialValue = savedInstanceState.getBoolean(SHOW_START_FINISH_ICONS_INITIAL_VALUE_KEY, + app.getSettings().SHOW_START_FINISH_ICONS.get()); } else if (arguments != null) { String gpxFilePath = arguments.getString(TRACK_FILE_NAME); boolean currentRecording = arguments.getBoolean(CURRENT_RECORDING, false); + showStartFinishIconsInitialValue = app.getSettings().SHOW_START_FINISH_ICONS.get(); if (gpxFilePath == null && !currentRecording) { log.error("Required extra '" + TRACK_FILE_NAME + "' is missing"); @@ -152,7 +157,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack(); } else { gpxDataItem = app.getGpxDbHelper().getItem(new File(gpxFilePath)); - trackDrawInfo = new TrackDrawInfo(gpxDataItem, false); + trackDrawInfo = new TrackDrawInfo(app, gpxDataItem, false); selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath); } updateTrackColor(); @@ -294,6 +299,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); trackDrawInfo.saveToBundle(outState); + outState.putBoolean(SHOW_START_FINISH_ICONS_INITIAL_VALUE_KEY, showStartFinishIconsInitialValue); } @Override @@ -455,6 +461,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement @Override public void onClick(View v) { discardSplitChanges(); + discardShowStartFinishChanges(); FragmentActivity activity = getActivity(); if (activity != null) { activity.onBackPressed(); @@ -520,7 +527,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement gpxFile.setSplitInterval(trackDrawInfo.getSplitInterval()); gpxFile.setShowArrows(trackDrawInfo.isShowArrows()); - gpxFile.setShowStartFinish(trackDrawInfo.isShowStartFinish()); + //gpxFile.setShowStartFinish(trackDrawInfo.isShowStartFinish()); if (gpxFile.showCurrentTrack) { app.getSettings().CURRENT_TRACK_COLOR.set(trackDrawInfo.getColor()); @@ -551,6 +558,10 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement } } + private void discardShowStartFinishChanges() { + app.getSettings().SHOW_START_FINISH_ICONS.set(showStartFinishIconsInitialValue); + } + void applySplit(GpxSplitType splitType, int timeSplit, double distanceSplit) { if (splitIntervalCard != null) { splitIntervalCard.updateContent(); @@ -599,6 +610,10 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement directionArrowsCard.setListener(this); cardsContainer.addView(directionArrowsCard.build(mapActivity)); + ShowStartFinishCard showStartFinishCard = new ShowStartFinishCard(mapActivity, trackDrawInfo); + showStartFinishCard.setListener(this); + cardsContainer.addView(showStartFinishCard.build(mapActivity)); + trackColoringCard = new TrackColoringCard(mapActivity, trackDrawInfo, this); trackColoringCard.setListener(this); cardsContainer.addView(trackColoringCard.build(mapActivity)); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java index e8ab755507..99571dad6c 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java @@ -29,6 +29,7 @@ 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.dialogs.GpxAppearanceAdapter; import net.osmand.plus.dialogs.GpxAppearanceAdapter.AppearanceListItem; import net.osmand.plus.dialogs.GpxAppearanceAdapter.GpxAppearanceAdapterType; import net.osmand.plus.helpers.AndroidUiHelper; @@ -41,8 +42,6 @@ import org.apache.commons.logging.Log; import java.util.ArrayList; import java.util.List; -import static net.osmand.plus.dialogs.GpxAppearanceAdapter.getAppearanceItems; - public class TrackColoringCard extends BaseCard implements ColorPickerListener { private static final int MINIMUM_CONTRAST_RATIO = 3; @@ -131,7 +130,7 @@ public class TrackColoringCard extends BaseCard implements ColorPickerListener { selectColor.addView(createDividerView(selectColor)); List colors = new ArrayList<>(); - for (AppearanceListItem appearanceListItem : getAppearanceItems(app, GpxAppearanceAdapterType.TRACK_COLOR)) { + for (AppearanceListItem appearanceListItem : GpxAppearanceAdapter.getAppearanceItems(app, GpxAppearanceAdapterType.TRACK_COLOR)) { if (!colors.contains(appearanceListItem.getColor())) { colors.add(appearanceListItem.getColor()); } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java index 3dbacb7b56..18d1c30775 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java @@ -5,6 +5,7 @@ import android.os.Bundle; import androidx.annotation.NonNull; import net.osmand.plus.GPXDatabase.GpxDataItem; +import net.osmand.plus.OsmandApplication; import net.osmand.util.Algorithms; import static net.osmand.plus.activities.TrackActivity.CURRENT_RECORDING; @@ -40,7 +41,7 @@ public class TrackDrawInfo { readBundle(bundle); } - public TrackDrawInfo(GpxDataItem gpxDataItem, boolean currentRecording) { + public TrackDrawInfo(@NonNull OsmandApplication app, @NonNull GpxDataItem gpxDataItem, boolean currentRecording) { filePath = gpxDataItem.getFile().getPath(); width = gpxDataItem.getWidth(); gradientScaleType = gpxDataItem.getGradientScaleType(); diff --git a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java index 3bb49859be..641944ce21 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java @@ -453,7 +453,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM if (segment.points.size() >= 2) { WptPt start = segment.points.get(0); WptPt end = segment.points.get(segment.points.size() - 1); - drawStartEndPoints(canvas, tileBox, start, end); + drawStartEndPoints(canvas, tileBox, start, selectedGpxFile.isShowCurrentTrack() ? null : end); } } } @@ -461,24 +461,28 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } } - private void drawStartEndPoints(Canvas canvas, RotatedTileBox tileBox, WptPt start, WptPt end) { - int startX = (int) tileBox.getPixXFromLatLon(start.lat, start.lon); - int startY = (int) tileBox.getPixYFromLatLon(start.lat, start.lon); - int endX = (int) tileBox.getPixXFromLatLon(end.lat, end.lon); - int endY = (int) tileBox.getPixYFromLatLon(end.lat, end.lon); + private void drawStartEndPoints(@NonNull Canvas canvas, @NonNull RotatedTileBox tileBox, @Nullable WptPt start, @Nullable WptPt end) { + int startX = start != null ? (int) tileBox.getPixXFromLatLon(start.lat, start.lon) : 0; + int startY = start != null ? (int) tileBox.getPixYFromLatLon(start.lat, start.lon) : 0; + int endX = end != null ? (int) tileBox.getPixXFromLatLon(end.lat, end.lon) : 0; + int endY = end != null ? (int) tileBox.getPixYFromLatLon(end.lat, end.lon) : 0; int iconSize = AndroidUtils.dpToPx(view.getContext(), 14); QuadRect startRectWithoutShadow = calculateRect(startX, startY, iconSize, iconSize); QuadRect endRectWithoutShadow = calculateRect(endX, endY, iconSize, iconSize); - if (QuadRect.intersects(startRectWithoutShadow, endRectWithoutShadow)) { + if (start != null && end != null && QuadRect.intersects(startRectWithoutShadow, endRectWithoutShadow)) { QuadRect startAndFinishRect = calculateRect(startX, startY, startAndFinishIcon.getIntrinsicWidth(), startAndFinishIcon.getIntrinsicHeight()); drawPoint(canvas, startAndFinishRect, startAndFinishIcon); } else { - QuadRect startRect = calculateRect(startX, startY, startPointIcon.getIntrinsicWidth(), startPointIcon.getIntrinsicHeight()); - QuadRect endRect = calculateRect(endX, endY, finishPointIcon.getIntrinsicWidth(), finishPointIcon.getIntrinsicHeight()); - drawPoint(canvas, startRect, startPointIcon); - drawPoint(canvas, endRect, finishPointIcon); + if (start != null) { + QuadRect startRect = calculateRect(startX, startY, startPointIcon.getIntrinsicWidth(), startPointIcon.getIntrinsicHeight()); + drawPoint(canvas, startRect, startPointIcon); + } + if (end != null) { + QuadRect endRect = calculateRect(endX, endY, finishPointIcon.getIntrinsicWidth(), finishPointIcon.getIntrinsicHeight()); + drawPoint(canvas, endRect, finishPointIcon); + } } } @@ -711,6 +715,8 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } private boolean isShowStartFinishForTrack(GPXFile gpxFile) { + return view.getApplication().getSettings().SHOW_START_FINISH_ICONS.get(); + /* if (hasTrackDrawInfoForTrack(gpxFile)) { return trackDrawInfo.isShowStartFinish(); } else if (gpxFile.showCurrentTrack) { @@ -718,6 +724,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } else { return gpxFile.isShowStartFinish(); } + */ } private boolean hasTrackDrawInfoForTrack(GPXFile gpxFile) {