From f836425be467ac9830d8f6b4caa98700ce87c19b Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 29 Jun 2017 13:36:59 +0200 Subject: [android] - keep state of initial overlain views margins (#9391) --- .../java/com/mapbox/mapboxsdk/maps/UiSettings.java | 45 ++++++++++++++-------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'platform/android') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java index 5f7b6c571b..285cd18089 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java @@ -37,8 +37,14 @@ public final class UiSettings { private final FocalPointChangeListener focalPointChangeListener; private final Projection projection; private final CompassView compassView; + private final int[] compassMargins = new int[4]; + private final ImageView attributionsView; + private final int[] attributionsMargins = new int[4]; + private final View logoView; + private final int[] logoMargins = new int[4]; + private float pixelRatio; private boolean rotateGesturesEnabled = true; @@ -370,7 +376,7 @@ public final class UiSettings { */ @UiThread public void setCompassMargins(int left, int top, int right, int bottom) { - setWidgetMargins(compassView, left, top, right, bottom); + setWidgetMargins(compassView, compassMargins, left, top, right, bottom); } /** @@ -379,7 +385,7 @@ public final class UiSettings { * @return The left margin in pixels */ public int getCompassMarginLeft() { - return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).leftMargin; + return compassMargins[0]; } /** @@ -388,7 +394,7 @@ public final class UiSettings { * @return The top margin in pixels */ public int getCompassMarginTop() { - return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).topMargin; + return compassMargins[1]; } /** @@ -397,7 +403,7 @@ public final class UiSettings { * @return The right margin in pixels */ public int getCompassMarginRight() { - return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).rightMargin; + return compassMargins[2]; } /** @@ -406,7 +412,7 @@ public final class UiSettings { * @return The bottom margin in pixels */ public int getCompassMarginBottom() { - return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).bottomMargin; + return compassMargins[3]; } /** @@ -480,7 +486,7 @@ public final class UiSettings { * @param bottom The bottom margin in pixels. */ public void setLogoMargins(int left, int top, int right, int bottom) { - setWidgetMargins(logoView, left, top, right, bottom); + setWidgetMargins(logoView, logoMargins, left, top, right, bottom); } /** @@ -489,7 +495,7 @@ public final class UiSettings { * @return The left margin in pixels */ public int getLogoMarginLeft() { - return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).leftMargin; + return logoMargins[0]; } /** @@ -498,7 +504,7 @@ public final class UiSettings { * @return The top margin in pixels */ public int getLogoMarginTop() { - return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).topMargin; + return logoMargins[1]; } /** @@ -507,7 +513,7 @@ public final class UiSettings { * @return The right margin in pixels */ public int getLogoMarginRight() { - return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).rightMargin; + return logoMargins[2]; } /** @@ -516,7 +522,7 @@ public final class UiSettings { * @return The bottom margin in pixels */ public int getLogoMarginBottom() { - return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).bottomMargin; + return logoMargins[3]; } /** @@ -571,7 +577,7 @@ public final class UiSettings { * @param bottom The bottom margin in pixels. */ public void setAttributionMargins(int left, int top, int right, int bottom) { - setWidgetMargins(attributionsView, left, top, right, bottom); + setWidgetMargins(attributionsView, attributionsMargins, left, top, right, bottom); } /** @@ -598,7 +604,7 @@ public final class UiSettings { * @return The left margin in pixels */ public int getAttributionMarginLeft() { - return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).leftMargin; + return attributionsMargins[0]; } /** @@ -607,7 +613,7 @@ public final class UiSettings { * @return The top margin in pixels */ public int getAttributionMarginTop() { - return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).topMargin; + return attributionsMargins[1]; } /** @@ -616,7 +622,7 @@ public final class UiSettings { * @return The right margin in pixels */ public int getAttributionMarginRight() { - return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).rightMargin; + return attributionsMargins[2]; } /** @@ -625,7 +631,7 @@ public final class UiSettings { * @return The bottom margin in pixels */ public int getAttributionMarginBottom() { - return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).bottomMargin; + return attributionsMargins[3]; } /** @@ -929,7 +935,14 @@ public final class UiSettings { view.setLayoutParams(layoutParams); } - private void setWidgetMargins(@NonNull final View view, int left, int top, int right, int bottom) { + private void setWidgetMargins(@NonNull final View view, int[] initMargins, int left, int top, int right, int bottom) { + // keep state of initially set margins + initMargins[0] = left; + initMargins[1] = top; + initMargins[2] = right; + initMargins[3] = bottom; + + // convert inital margins with padding int[] contentPadding = projection.getContentPadding(); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams(); left += contentPadding[0]; -- cgit v1.2.1