diff options
9 files changed, 106 insertions, 44 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index e0bd4eef38..113e45d038 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -20,7 +20,6 @@ import android.graphics.PointF; import android.graphics.RectF; import android.graphics.SurfaceTexture; import android.graphics.drawable.ColorDrawable; -import android.graphics.drawable.Drawable; import android.location.Location; import android.net.ConnectivityManager; import android.net.NetworkInfo; @@ -83,7 +82,6 @@ import com.mapbox.mapboxsdk.layers.CustomLayer; import com.mapbox.mapboxsdk.location.LocationListener; import com.mapbox.mapboxsdk.location.LocationServices; import com.mapbox.mapboxsdk.maps.widgets.CompassView; -import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings; import com.mapbox.mapboxsdk.maps.widgets.UserLocationView; import com.mapbox.mapboxsdk.telemetry.MapboxEvent; import com.mapbox.mapboxsdk.telemetry.MapboxEventManager; @@ -266,24 +264,18 @@ public class MapView extends FrameLayout { mMapboxMap.setStyleUrl(style); } - mMapboxMap.setMyLocationEnabled(options.getLocationEnabled()); // Enable gestures UiSettings uiSettings = mMapboxMap.getUiSettings(); - uiSettings.setZoomGesturesEnabled(options.getZoomGesturesEnabled()); uiSettings.setZoomGestureChangeAllowed(options.getZoomGesturesEnabled()); - uiSettings.setScrollGesturesEnabled(options.getScrollGesturesEnabled()); uiSettings.setScrollGestureChangeAllowed(options.getScrollGesturesEnabled()); - uiSettings.setRotateGesturesEnabled(options.getRotateGesturesEnabled()); uiSettings.setRotateGestureChangeAllowed(options.getRotateGesturesEnabled()); - uiSettings.setTiltGesturesEnabled(options.getTiltGesturesEnabled()); uiSettings.setTiltGestureChangeAllowed(options.getTiltGesturesEnabled()); - uiSettings.setZoomControlsEnabled(options.getZoomControlsEnabled()); // Zoom @@ -313,7 +305,6 @@ public class MapView extends FrameLayout { } // Attribution - ColorUtils.setTintList(mAttributionsView); uiSettings.setAttributionEnabled(options.getAttributionEnabled()); uiSettings.setAttributionGravity(options.getAttributionGravity()); int[] attributionMargins = options.getAttributionMargins(); @@ -325,6 +316,10 @@ public class MapView extends FrameLayout { int seventySixDp = (int) resources.getDimension(R.dimen.seventy_six_dp); uiSettings.setAttributionMargins(seventySixDp, sevenDp, sevenDp, sevenDp); } + + int attributionTintColor = options.getAttributionTintColor(); + uiSettings.setAttributionTintColor(attributionTintColor != -1 ? + attributionTintColor : ColorUtils.getPrimaryColor(getContext())); } // @@ -906,7 +901,7 @@ public class MapView extends FrameLayout { if (mDestroyed || location == null) { return new PointF(); } - PointF pointF = mNativeMapView.pixelForLatLng(location); + PointF pointF = mNativeMapView.pixelForLatLng(location); pointF.set(pointF.x * mScreenDensity, pointF.y * mScreenDensity); return pointF; } @@ -2459,6 +2454,13 @@ public class MapView extends FrameLayout { mAttributionsView.setVisibility(visibility); } + void setAtttibutionTintColor(int tintColor) { + ColorUtils.setTintList(mAttributionsView, tintColor); + } + + int getAttributionTintColor(){ + return mMapboxMap.getUiSettings().getAttributionTintColor(); + } // // Custom layer @@ -2565,7 +2567,7 @@ public class MapView extends FrameLayout { builder.setTitle(R.string.attributionsDialogTitle); builder.setAdapter(new ArrayAdapter<>(context, R.layout.attribution_list_item, items), this); AlertDialog dialog = builder.show(); - dialog.getWindow().setBackgroundDrawable(new ColorDrawable(ColorUtils.getPrimaryColor(context))); + dialog.getWindow().setBackgroundDrawable(new ColorDrawable(mMapView.getAttributionTintColor())); } // Called when someone selects an attribution, 'Improve this map' adds location data to the url 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 6b7a0db8bd..764a901d8b 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 @@ -4,6 +4,7 @@ import android.content.Context; import android.content.res.TypedArray; import android.os.Parcel; import android.os.Parcelable; +import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.AttributeSet; @@ -40,6 +41,8 @@ public class MapboxMapOptions implements Parcelable { private int logoGravity = Gravity.BOTTOM | Gravity.START; private int logoMargins[]; + @ColorInt + private int attributionTintColor = -1; private boolean attributionEnabled = true; private int attributionGravity = Gravity.BOTTOM; private int attributionMargins[]; @@ -79,6 +82,7 @@ public class MapboxMapOptions implements Parcelable { attributionEnabled = in.readByte() != 0; attributionGravity = in.readInt(); attributionMargins = in.createIntArray(); + attributionTintColor = in.readInt(); minZoom = in.readFloat(); maxZoom = in.readFloat(); @@ -137,6 +141,7 @@ public class MapboxMapOptions implements Parcelable { , (int) (typedArray.getDimension(R.styleable.MapView_logo_margin_right, DIMENSION_SIXTEEN_DP) * screenDensity) , (int) (typedArray.getDimension(R.styleable.MapView_logo_margin_bottom, DIMENSION_SIXTEEN_DP) * screenDensity)}); + mapboxMapOptions.attributionTintColor(typedArray.getColor(R.styleable.MapView_attribution_tint, -1)); mapboxMapOptions.attributionEnabled(typedArray.getBoolean(R.styleable.MapView_attribution_enabled, true)); mapboxMapOptions.attributionGravity(typedArray.getInt(R.styleable.MapView_attribution_gravity, Gravity.BOTTOM)); mapboxMapOptions.attributionMargins(new int[]{(int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_left, DIMENSION_SEVENTY_SIX_DP) * screenDensity) @@ -317,6 +322,17 @@ public class MapboxMapOptions implements Parcelable { } /** + * Specifies the tint color of the attribution for a map view + * + * @param color integer resembling a color + * @return This + */ + public MapboxMapOptions attributionTintColor(@ColorInt int color) { + attributionTintColor = color; + return this; + } + + /** * Specifies if the rotate gesture is enabled for a map view. * * @param enabled True and gesture will be enabled @@ -553,6 +569,11 @@ public class MapboxMapOptions implements Parcelable { return attributionMargins; } + @ColorInt + public int getAttributionTintColor() { + return attributionTintColor; + } + /** * Get the current configured user location view state for a map view. * @@ -603,6 +624,7 @@ public class MapboxMapOptions implements Parcelable { dest.writeByte((byte) (attributionEnabled ? 1 : 0)); dest.writeInt(attributionGravity); dest.writeIntArray(attributionMargins); + dest.writeInt(attributionTintColor); dest.writeFloat(minZoom); dest.writeFloat(maxZoom); 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 8bd4112434..db59bdb544 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 @@ -1,5 +1,6 @@ package com.mapbox.mapboxsdk.maps; +import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.UiThread; import android.view.Gravity; @@ -239,11 +240,11 @@ public class UiSettings { /** * <p> - * Enables or disables the Mapbox logo. + * Enables or disables the attribution. * </p> - * By default, the compass is enabled. + * By default, the attribution is enabled. * - * @param enabled True to enable the logo; false to disable the logo. + * @param enabled True to enable the attribution; false to disable the attribution. */ public void setAttributionEnabled(boolean enabled) { attributionSettings.setEnabled(enabled); @@ -251,9 +252,9 @@ public class UiSettings { } /** - * Returns whether the logo is enabled. + * Returns whether the attribution is enabled. * - * @return True if the logo is enabled; false if the logo is disabled. + * @return True if the attribution is enabled; false if the attribution is disabled. */ public boolean isAttributionEnabled() { return attributionSettings.isEnabled(); @@ -261,10 +262,9 @@ public class UiSettings { /** * <p> - * Sets the gravity of the logo view. Use this to change the corner of the map view that the - * Mapbox logo is displayed in. + * Sets the gravity of the attribution. * </p> - * By default, the logo is in the bottom left corner. + * By default, the attribution is in the bottom left corner next to the Mapbox logo. * * @param gravity One of the values from {@link Gravity}. * @see Gravity @@ -284,8 +284,7 @@ public class UiSettings { } /** - * Sets the margins of the logo view. Use this to change the distance of the Mapbox logo from the - * map view edge. + * Sets the margins of the attribution view. * * @param left The left margin in pixels. * @param top The top margin in pixels. @@ -298,7 +297,29 @@ public class UiSettings { } /** - * Returns the left side margin of the logo + * <p> + * Sets the tint of the attribution view. Use this to change the color of the attribution. + * </p> + * By default, the logo is tinted with the primary color of your theme. + * + * @param tintColor Color to tint the attribution. + */ + public void setAttributionTintColor(@ColorInt int tintColor) { + attributionSettings.setTintColor(tintColor); + mapView.setAtttibutionTintColor(tintColor); + } + + /** + * Returns the tint color value of the attribution view. + * + * @return The tint color + */ + public int getAttributionTintColor() { + return attributionSettings.getTintColor(); + } + + /** + * Returns the left side margin of the attribution view. * * @return The left margin in pixels */ @@ -307,7 +328,7 @@ public class UiSettings { } /** - * Returns the top side margin of the logo + * Returns the top side margin of the attribution view. * * @return The top margin in pixels */ @@ -316,7 +337,7 @@ public class UiSettings { } /** - * Returns the right side margin of the logo + * Returns the right side margin of the attribution view. * * @return The right margin in pixels */ @@ -548,10 +569,20 @@ public class UiSettings { mapView.setAttributionMargins(getAttributionMarginLeft(), getAttributionMarginTop(), getAttributionMarginRight(), getAttributionMarginBottom()); } + /** + * Returns the view settings related to the My Location View + * + * @return viewSettings used for My Location view. + */ public MyLocationViewSettings getMyLocationViewSettings() { return myLocationViewSettings; } + /** + * Replaces the currenlty used view settings related to the My Location View. + * + * @param myLocationViewSettings The settings to be used. + */ public void setMyLocationViewSettings(MyLocationViewSettings myLocationViewSettings) { this.myLocationViewSettings = myLocationViewSettings; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ViewSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ViewSettings.java index 0726b7bbbf..f08a1bdeb4 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ViewSettings.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ViewSettings.java @@ -8,6 +8,7 @@ class ViewSettings { private boolean enabled; private int gravity; private int[]margins; + private int tintColor; public ViewSettings() { margins = new int[4]; @@ -36,4 +37,12 @@ class ViewSettings { public void setMargins(int[] margins) { this.margins = margins; } + + public int getTintColor() { + return tintColor; + } + + public void setTintColor(int tintColor) { + this.tintColor = tintColor; + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java index 972011b7f9..a0de07c5f1 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java @@ -59,43 +59,32 @@ public class ColorUtils { /** * Returns a color state list associated with a theme based on a {@link Context} * - * @param context The context used to style the color attributes. + * @param color The color used for tinting. * @return A ColorStateList object containing the primary color of a theme */ @NonNull - public static ColorStateList getSelector(@NonNull Context context) { + public static ColorStateList getSelector(@ColorInt int color) { return new ColorStateList( new int[][]{ new int[]{android.R.attr.state_pressed}, new int[]{} }, new int[]{ - getPrimaryColor(context), - getPrimaryColor(context) + color, + color } ); } /** - * Set a primary color tint list to the {@link Drawable} of an {@link ImageView}. + * Set a color tint list to the {@link Drawable} of an {@link ImageView}. * * @param imageView The view to set the default tint list. + * @param tintColor The color to tint. */ - public static void setTintList(@NonNull ImageView imageView) { + public static void setTintList(@NonNull ImageView imageView, @ColorInt int tintColor) { Drawable originalDrawable = imageView.getDrawable(); Drawable wrappedDrawable = DrawableCompat.wrap(originalDrawable); - DrawableCompat.setTintList(wrappedDrawable, getSelector(imageView.getContext())); + DrawableCompat.setTintList(wrappedDrawable, getSelector(tintColor)); } - - /** - * Set a primary color tint to a {@link Drawable}. - * - * @param context The context used to style the color attributes. - * @param drawable The drawable to tint. - */ - public static void setTint(@NonNull Context context, @NonNull Drawable drawable) { - Drawable wrappedDrawable = DrawableCompat.wrap(drawable); - DrawableCompat.setTint(wrappedDrawable, ColorUtils.getPrimaryColor(context)); - } - }
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml index f5bb81be27..5860131b64 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml @@ -93,5 +93,6 @@ <attr name="attribution_margin_right" format="dimension" /> <attr name="attribution_margin_bottom" format="dimension" /> <attr name="attribution_enabled" format="boolean" /> + <attr name="attribution_tint" format="color" /> </declare-styleable> </resources> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java index 0b373c86f8..d7f25d5881 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java @@ -41,6 +41,7 @@ public class PolygonActivity extends AppCompatActivity { // configure inital map state MapboxMapOptions options = new MapboxMapOptions() + .attributionTintColor(Color.RED) .accessToken(getString(R.string.mapbox_access_token)) .styleUrl(Style.MAPBOX_STREETS) .camera(new CameraPosition.Builder() diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_polyline.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_polyline.xml index 7875fc2021..8ff9f82b09 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_polyline.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_polyline.xml @@ -19,6 +19,7 @@ android:layout_below="@+id/toolbar" app:center_latitude="47.798202" app:center_longitude="7.573781" + app:attribution_tint="@android:color/holo_green_dark" app:style_url="@string/style_mapbox_streets" app:zoom="4" /> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java index 50f5842db6..6d8bc8d741 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java @@ -1,5 +1,6 @@ package com.mapbox.mapboxsdk.maps; +import android.graphics.Color; import android.view.Gravity; import com.mapbox.mapboxsdk.camera.CameraPosition; @@ -71,6 +72,12 @@ public class MapboxMapOptionsTest { } @Test + public void testAttributionTintColor() { + assertEquals(-1, new MapboxMapOptions().getAttributionTintColor()); + assertEquals(Color.RED, new MapboxMapOptions().attributionTintColor(Color.RED).getAttributionTintColor()); + } + + @Test public void testAttributionEnabled() { assertTrue(new MapboxMapOptions().attributionEnabled(true).getAttributionEnabled()); assertFalse(new MapboxMapOptions().attributionEnabled(false).getAttributionEnabled()); @@ -166,6 +173,5 @@ public class MapboxMapOptionsTest { assertEquals("test", new MapboxMapOptions().accessToken("test").getAccessToken()); assertNotEquals("nottest", new MapboxMapOptions().accessToken("test").getStyle()); } - } |