Skip to content

Commit

Permalink
Merge pull request #21590 from osmandapp/fix_#18357
Browse files Browse the repository at this point in the history
Fix rulerWidget position update in preview & copy/reset configure scr…
  • Loading branch information
Chumva authored Dec 19, 2024
2 parents 06579fd + a71c345 commit 81bbac2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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();
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 81bbac2

Please sign in to comment.