diff options
author | Tobrun <tobrun@mapbox.com> | 2017-05-26 10:32:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-26 10:32:11 +0200 |
commit | c392c678ab4ea560cefca59d14b215e2d4c79ecb (patch) | |
tree | 3fb85b62965bd81dab6b055803019187e72d865c | |
parent | 35f548a07d11a62fda91d0352650d25ee51b1381 (diff) | |
download | qtlocation-mapboxgl-c392c678ab4ea560cefca59d14b215e2d4c79ecb.tar.gz |
[android] - logo placement for creating a Mapview programatically (#9094)
* [android] - Correct logo placement for creating a Mapview programatically, fixup non default placements
* Fixed NIGHTY_TWO_DP typo to NINETY_TWO_DP
4 files changed, 24 insertions, 12 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java index 68603ab1a3..98f94ddb39 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java @@ -36,7 +36,7 @@ import java.util.Arrays; public class MapboxMapOptions implements Parcelable { private static final float FOUR_DP = 4f; - private static final float EIGHTY_NINE_DP = 92f; + private static final float NINETY_TWO_DP = 92f; private CameraPosition cameraPosition; @@ -241,7 +241,7 @@ public class MapboxMapOptions implements Parcelable { R.styleable.mapbox_MapView_mapbox_uiAttributionGravity, Gravity.BOTTOM)); mapboxMapOptions.attributionMargins(new int[] { (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginLeft, - EIGHTY_NINE_DP * pxlRatio)), + NINETY_TWO_DP * pxlRatio)), (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginTop, FOUR_DP * pxlRatio)), (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginRight, 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 1bcf8a70b9..accecf232b 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 @@ -193,12 +193,16 @@ public final class UiSettings { private void initialiseLogo(MapboxMapOptions options, Resources resources) { setLogoEnabled(options.getLogoEnabled()); setLogoGravity(options.getLogoGravity()); - int[] logoMargins = options.getLogoMargins(); + setLogoMargins(resources, options.getLogoMargins()); + } + + private void setLogoMargins(Resources resources, int[]logoMargins) { if (logoMargins != null) { setLogoMargins(logoMargins[0], logoMargins[1], logoMargins[2], logoMargins[3]); } else { - int twoDp = (int) resources.getDimension(R.dimen.mapbox_two_dp); - setLogoMargins(twoDp, twoDp, twoDp, twoDp); + // user did not specify margins when programmatically creating a map + int fourDp = (int) resources.getDimension(R.dimen.mapbox_four_dp); + setLogoMargins(fourDp, fourDp, fourDp, fourDp); } } @@ -223,15 +227,23 @@ public final class UiSettings { private void initialiseAttribution(Context context, MapboxMapOptions options) { setAttributionEnabled(options.getAttributionEnabled()); setAttributionGravity(options.getAttributionGravity()); - int[] attributionMargins = options.getAttributionMargins(); + setAttributionMargins(context, options.getAttributionMargins()); + int attributionTintColor = options.getAttributionTintColor(); + setAttributionTintColor(attributionTintColor != -1 + ? attributionTintColor : ColorUtils.getPrimaryColor(context)); + } + + private void setAttributionMargins(Context context, int[] attributionMargins) { if (attributionMargins != null) { setAttributionMargins(attributionMargins[0], attributionMargins[1], attributionMargins[2], attributionMargins[3]); + } else { + // user did not specify margins when programmatically creating a map + Resources resources = context.getResources(); + int margin = (int) resources.getDimension(R.dimen.mapbox_four_dp); + int leftMargin = (int) resources.getDimension(R.dimen.mapbox_ninety_two_dp); + setAttributionMargins(leftMargin, margin, margin, margin); } - - int attributionTintColor = options.getAttributionTintColor(); - setAttributionTintColor(attributionTintColor != -1 - ? attributionTintColor : ColorUtils.getPrimaryColor(context)); } private void saveAttribution(Bundle outState) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml index ce20cb9a8b..8edbd47c29 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml @@ -13,6 +13,6 @@ <dimen name="mapbox_eight_dp">8dp</dimen> <dimen name="mapbox_ten_dp">10dp</dimen> <dimen name="mapbox_sixteen_dp">16dp</dimen> - <dimen name="mapbox_ninety_five_dp">95dp</dimen> + <dimen name="mapbox_ninety_two_dp">92dp</dimen> <dimen name="mapbox_my_locationview_outer_circle">18dp</dimen> </resources> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_press_for_marker.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_press_for_marker.xml index 9932803907..c2098b0f5b 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_press_for_marker.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_press_for_marker.xml @@ -16,6 +16,6 @@ app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets" app:mapbox_uiAttributionGravity="top|end" app:mapbox_uiLogoGravity="top|end" - app:mapbox_uiLogoMarginRight="10dp"/> + app:mapbox_uiLogoMarginRight="28dp"/> </RelativeLayout> |