From 539f745d0ee30daf0ddcd330077bc8d8c5c4883a Mon Sep 17 00:00:00 2001 From: simonpoole Date: Tue, 5 Dec 2023 16:30:11 +0100 Subject: [PATCH] Restore zoom FABs elevation in onConfigurationChange Fixes https://github.com/MarcusWolschon/osmeditor4android/issues/965 --- .../de/blau/android/views/ZoomControls.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/blau/android/views/ZoomControls.java b/src/main/java/de/blau/android/views/ZoomControls.java index 20522bb80b..68e49d8ed1 100644 --- a/src/main/java/de/blau/android/views/ZoomControls.java +++ b/src/main/java/de/blau/android/views/ZoomControls.java @@ -5,8 +5,10 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.res.ColorStateList; +import android.content.res.Configuration; import android.os.Build; import android.util.AttributeSet; +import android.util.Log; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -22,11 +24,16 @@ public class ZoomControls extends LinearLayout { + private static final String DEBUG_TAG = ZoomControls.class.getSimpleName(); + private final FloatingActionButton zoomIn; private final FloatingActionButton zoomOut; private final Context context; + private float elevationIn = -1f; + private float elevationOut = -1f; + /** * Construct a new zoom control view * @@ -130,4 +137,21 @@ private void setEnabled(@NonNull FloatingActionButton fab, boolean isEnabled) { ThemeUtils.getStyleAttribColorValue(context, isEnabled ? R.attr.colorControlNormal : R.attr.colorPrimary, R.color.dark_grey)); } } -} + + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + if (elevationIn < 0f) { + elevationIn = zoomIn.getElevation(); + elevationOut = zoomOut.getElevation(); + } + } + + @Override + protected void onConfigurationChanged(Configuration newConfig) { + // this is a workaround for https://github.com/MarcusWolschon/osmeditor4android/issues/965 + Log.d(DEBUG_TAG, "onConfigurationChanged " + elevationIn + " " + elevationOut); + zoomIn.setElevation(elevationIn); + zoomOut.setElevation(elevationOut); + } +} \ No newline at end of file