From a71c345a8074b10271e6877aaf2abf5b589e99ef Mon Sep 17 00:00:00 2001 From: chumv Date: Thu, 19 Dec 2024 16:40:11 +0200 Subject: [PATCH] Fix rulerWidget position update in preview & copy/reset configure screen preferences --- .../configure/WidgetsSettingsHelper.java | 6 +++ .../configure/buttons/MapHudCard.java | 5 ++- .../views/mapwidgets/widgets/RulerWidget.java | 43 +++++++++++++++++-- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/configure/WidgetsSettingsHelper.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/configure/WidgetsSettingsHelper.java index 8f680e88bfd..6d6a88edd69 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/configure/WidgetsSettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/configure/WidgetsSettingsHelper.java @@ -71,6 +71,9 @@ public void resetConfigureScreenSettings() { mapButtonsHelper.getCompassButtonState().getVisibilityPref().resetModeToDefault(appMode); settings.SHOW_DISTANCE_RULER.resetModeToDefault(appMode); mapButtonsHelper.resetButtonStatesForMode(appMode, mapButtonsHelper.getAllButtonsStates()); + mapButtonsHelper.getDefaultSizePref().resetModeToDefault(appMode); + mapButtonsHelper.getDefaultOpacityPref().resetModeToDefault(appMode); + mapButtonsHelper.getDefaultCornerRadiusPref().resetModeToDefault(appMode); } public void copyConfigureScreenSettings(@NonNull ApplicationMode fromAppMode) { @@ -84,6 +87,9 @@ public void copyConfigureScreenSettings(@NonNull ApplicationMode fromAppMode) { copyPrefFromAppMode(settings.DISTANCE_BY_TAP_TEXT_SIZE, fromAppMode); copyPrefFromAppMode(settings.SHOW_SPEEDOMETER, fromAppMode); copyPrefFromAppMode(settings.SPEEDOMETER_SIZE, fromAppMode); + copyPrefFromAppMode(mapButtonsHelper.getDefaultSizePref(),fromAppMode); + copyPrefFromAppMode(mapButtonsHelper.getDefaultOpacityPref(),fromAppMode); + copyPrefFromAppMode(mapButtonsHelper.getDefaultCornerRadiusPref(),fromAppMode); mapButtonsHelper.copyButtonStatesFromMode(appMode, fromAppMode, mapButtonsHelper.getAllButtonsStates()); } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/configure/buttons/MapHudCard.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/configure/buttons/MapHudCard.java index 0ba4e4cbbb6..e1ab3cd0075 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/configure/buttons/MapHudCard.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/configure/buttons/MapHudCard.java @@ -17,6 +17,7 @@ import net.osmand.plus.views.mapwidgets.widgets.RulerWidget; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class MapHudCard extends MapBaseCard { @@ -83,10 +84,10 @@ private void addMapButton(@NonNull MapButton mapButton) { private void setupRulerWidget() { rulerWidget = (RulerWidget) themedInflater.inflate(R.layout.map_ruler, mapHudLayout, false); + mapHudLayout.addWidget(rulerWidget); MapLayers mapLayers = app.getOsmandMap().getMapLayers(); mapLayers.getMapInfoLayer().setupRulerWidget(rulerWidget); - mapHudLayout.addWidget(rulerWidget); } @Override @@ -105,6 +106,6 @@ private void updateButtons() { public void clearWidgets() { MapLayers mapLayers = app.getOsmandMap().getMapLayers(); - mapLayers.getMapInfoLayer().setupRulerWidget(rulerWidget); + mapLayers.getMapInfoLayer().removeRulerWidgets(Collections.singletonList(rulerWidget)); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/widgets/RulerWidget.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/widgets/RulerWidget.java index 6e2e3318e2c..4b3e5a64661 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/widgets/RulerWidget.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/widgets/RulerWidget.java @@ -18,8 +18,11 @@ import net.osmand.plus.utils.OsmAndFormatter; import net.osmand.plus.views.OsmandMap; import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.plus.views.controls.MapHudLayout.SizeChangeListener; +import net.osmand.plus.views.controls.MapHudLayout.ViewChangeProvider; +import net.osmand.plus.views.controls.MapHudLayout.VisibilityChangeListener; -public class RulerWidget extends FrameLayout { +public class RulerWidget extends FrameLayout implements ViewChangeProvider { private final OsmandApplication app; private final OsmandMap osmandMap; @@ -35,6 +38,9 @@ public class RulerWidget extends FrameLayout { private double cacheRulerTileX; private double cacheRulerTileY; + private SizeChangeListener sizeListener; + private VisibilityChangeListener visibilityListener; + public RulerWidget(@NonNull Context context) { this(context, null); } @@ -47,7 +53,8 @@ public RulerWidget(@NonNull Context context, @Nullable AttributeSet attrs, int d this(context, attrs, defStyleAttr, 0); } - public RulerWidget(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { + public RulerWidget(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, + int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); this.app = (OsmandApplication) context.getApplicationContext(); @@ -66,7 +73,8 @@ protected void onFinishInflate() { maxWidth = getResources().getDimensionPixelSize(R.dimen.map_ruler_width); } - public void updateTextSize(boolean isNight, int textColor, int textShadowColor, int shadowRadius) { + public void updateTextSize(boolean isNight, int textColor, int textShadowColor, + int shadowRadius) { TextInfoWidget.updateTextColor(text, textShadow, textColor, textShadowColor, false, shadowRadius); icon.setBackgroundResource(isNight ? R.drawable.ruler_night : R.drawable.ruler); } @@ -108,9 +116,36 @@ public void setVisibility(boolean visibility) { AndroidUiHelper.updateVisibility(layout, visibility); } - public static double getRulerDistance(@NonNull OsmandApplication app, @NonNull RotatedTileBox tileBox) { + public static double getRulerDistance(@NonNull OsmandApplication app, + @NonNull RotatedTileBox tileBox) { double pixDensity = tileBox.getPixDensity(); int maxWidth = app.getResources().getDimensionPixelSize(R.dimen.map_ruler_width); return OsmAndFormatter.calculateRoundedDist(maxWidth / pixDensity, app); } + + @Override + public void setSizeListener(@Nullable SizeChangeListener listener) { + this.sizeListener = listener; + } + + @Override + public void setVisibilityListener(@Nullable VisibilityChangeListener listener) { + this.visibilityListener = listener; + } + + @Override + protected void onSizeChanged(int w, int h, int oldWidth, int oldHeight) { + super.onSizeChanged(w, h, oldWidth, oldHeight); + if (sizeListener != null) { + sizeListener.onSizeChanged(this, w, h, oldWidth, oldHeight); + } + } + + @Override + protected void onVisibilityChanged(@NonNull View changedView, int visibility) { + super.onVisibilityChanged(changedView, visibility); + if (visibilityListener != null) { + visibilityListener.onVisibilityChanged(changedView, visibility); + } + } } \ No newline at end of file