summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2016-04-26 20:54:57 +0200
committerTobrun <tobrun@mapbox.com>2016-04-26 22:24:18 +0200
commitbf493f96cddc9c85400d845f1a899b274f200edd (patch)
tree1663c4519532acff058d37260680021b01dab76f
parente2510fce79d9a90bad71bcfc5a73c248a9c7c3d1 (diff)
downloadqtlocation-mapboxgl-bf493f96cddc9c85400d845f1a899b274f200edd.tar.gz
[android] #4800 - correct background offsets from attributes
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java14
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java19
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java7
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java14
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationCustomisationActivity.java13
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/dimens.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java11
7 files changed, 34 insertions, 46 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 734f3f8947..f5e9a74415 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
@@ -268,19 +268,15 @@ public class MapView extends FrameLayout {
// MyLocationView
MyLocationViewSettings myLocationViewSettings = mMapboxMap.getMyLocationViewSettings();
myLocationViewSettings.setForegroundDrawable(options.getMyLocationForegroundDrawable(), options.getMyLocationForegroundBearingDrawable());
- myLocationViewSettings.setBackgroundDrawable(options.getMyLocationBackgroundDrawable());
- if(options.getMyLocationForegroundTintColor()!=-1) {
+ myLocationViewSettings.setBackgroundDrawable(options.getMyLocationBackgroundDrawable(), options.getMyLocationBackgroundPadding());
+ if (options.getMyLocationForegroundTintColor() != -1) {
myLocationViewSettings.setForegroundTintColor(options.getMyLocationForegroundTintColor());
}
- if(options.getMyLocationBackgroundTintColor()!=-1) {
+ if (options.getMyLocationBackgroundTintColor() != -1) {
myLocationViewSettings.setBackgroundTintColor(options.getMyLocationBackgroundTintColor());
}
myLocationViewSettings.setAccuracyAlpha(options.getMyLocationAccuracyAlpha());
myLocationViewSettings.setAccuracyTintColor(options.getMyLocationAccuracyTintColor());
- int[] myLocationPadding = options.getMyLocationBackgroundPadding();
- if (myLocationPadding != null) {
- myLocationViewSettings.setPadding(myLocationPadding[0], myLocationPadding[1], myLocationPadding[2], myLocationPadding[3]);
- }
mMapboxMap.setMyLocationEnabled(options.getLocationEnabled());
// Enable gestures
@@ -2366,7 +2362,7 @@ public class MapView extends FrameLayout {
LocationServices.getLocationServices(getContext()).addLocationListener(new LocationListener() {
@Override
public void onLocationChanged(Location location) {
- if(listener!=null) {
+ if (listener != null) {
listener.onMyLocationChange(location);
}
}
@@ -2479,7 +2475,7 @@ public class MapView extends FrameLayout {
ColorUtils.setTintList(mAttributionsView, tintColor);
}
- int getAttributionTintColor(){
+ int getAttributionTintColor() {
return mMapboxMap.getUiSettings().getAttributionTintColor();
}
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 c6b9aa7bfc..c5040f40dc 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
@@ -2,7 +2,6 @@ package com.mapbox.mapboxsdk.maps;
import android.content.Context;
import android.content.res.TypedArray;
-import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
@@ -10,9 +9,7 @@ import android.support.annotation.ColorInt;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
-import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
-import android.util.Log;
import android.view.Gravity;
import com.mapbox.mapboxsdk.R;
@@ -174,10 +171,8 @@ public class MapboxMapOptions implements Parcelable {
, (int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_bottom, DIMENSION_SEVEN_DP) * screenDensity)});
mapboxMapOptions.locationEnabled(typedArray.getBoolean(R.styleable.MapView_my_location_enabled, false));
- mapboxMapOptions.myLocationForegroundDrawable(typedArray.getDrawable(R.styleable.MapView_my_location_foreground));
- mapboxMapOptions.myLocationForegroundBearingDrawable(typedArray.getDrawable(R.styleable.MapView_my_location_foreground_bearing));
+ mapboxMapOptions.myLocationForegroundDrawables(typedArray.getDrawable(R.styleable.MapView_my_location_foreground), typedArray.getDrawable(R.styleable.MapView_my_location_foreground_bearing));
mapboxMapOptions.myLocationBackgroundDrawable(typedArray.getDrawable(R.styleable.MapView_my_location_background));
- mapboxMapOptions.myLocationForegroundDrawable(typedArray.getDrawable(R.styleable.MapView_my_location_foreground));
mapboxMapOptions.myLocationForegroundTintColor(typedArray.getColor(R.styleable.MapView_my_location_foreground_tint, -1));
mapboxMapOptions.myLocationBackgroundTintColor(typedArray.getColor(R.styleable.MapView_my_location_background_tint, -1));
mapboxMapOptions.myLocationBackgroundPadding(new int[]{(int) (typedArray.getDimension(R.styleable.MapView_my_location_background_left, 0) * screenDensity)
@@ -435,19 +430,13 @@ public class MapboxMapOptions implements Parcelable {
}
/**
+ *
* @param myLocationForegroundDrawable
- * @return This
- */
- public MapboxMapOptions myLocationForegroundDrawable(Drawable myLocationForegroundDrawable) {
- this.myLocationForegroundDrawable = myLocationForegroundDrawable;
- return this;
- }
-
- /**
* @param myLocationBearingDrawable
* @return This
*/
- public MapboxMapOptions myLocationForegroundBearingDrawable(Drawable myLocationBearingDrawable) {
+ public MapboxMapOptions myLocationForegroundDrawables(Drawable myLocationForegroundDrawable, Drawable myLocationBearingDrawable ) {
+ this.myLocationForegroundDrawable = myLocationForegroundDrawable;
this.myLocationForegroundBearingDrawable = myLocationBearingDrawable;
return this;
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java
index 430ebfe443..21a981bb24 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java
@@ -146,14 +146,15 @@ public class MyLocationView extends View {
}
public final void setShadowDrawable(Drawable drawable, int left, int top, int right, int bottom) {
- if (drawable == null) {
- return;
+ if (drawable != null) {
+ backgroundDrawable = drawable;
}
- backgroundDrawable = drawable;
+
backgroundOffsetLeft = left;
backgroundOffsetTop = top;
backgroundOffsetRight = right;
backgroundOffsetBottom = bottom;
+
invalidateBounds();
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
index c048d0f57e..9ae96ebf7b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
@@ -89,9 +89,14 @@ public class MyLocationViewSettings {
return foregroundTintColor;
}
- public void setBackgroundDrawable(Drawable backgroundDrawable) {
+ public void setBackgroundDrawable(Drawable backgroundDrawable, int[] padding) {
this.backgroundDrawable = backgroundDrawable;
- myLocationView.setShadowDrawable(backgroundDrawable);
+ this.backgroundOffset = padding;
+ if (padding != null && padding.length == 4) {
+ myLocationView.setShadowDrawable(backgroundDrawable, padding[0], padding[1], padding[2], padding[3]);
+ } else {
+ myLocationView.setShadowDrawable(backgroundDrawable);
+ }
}
public Drawable getBackgroundDrawable() {
@@ -107,11 +112,6 @@ public class MyLocationViewSettings {
return backgroundTintColor;
}
- public void setBackgroundOffset(int left, int top, int right, int bottom) {
- backgroundOffset = new int[]{left, top, right, bottom};
- myLocationView.setShadowDrawable(backgroundDrawable, left, top, right, bottom);
- }
-
public int[] getBackgroundOffset() {
return backgroundOffset;
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationCustomisationActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationCustomisationActivity.java
index 2d7df6f1db..6de2056faf 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationCustomisationActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationCustomisationActivity.java
@@ -1,9 +1,11 @@
package com.mapbox.mapboxsdk.testapp.activity.userlocation;
+import android.content.res.Resources;
import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.Nullable;
+import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -56,12 +58,17 @@ public class MyLocationCustomisationActivity extends AppCompatActivity implement
.tilt(25)
.build());
+ mapboxMapOptions.myLocationForegroundDrawables(ContextCompat.getDrawable(this, R.drawable.ic_chelsea),
+ ContextCompat.getDrawable(this, R.drawable.ic_chelsea));
+ mapboxMapOptions.myLocationBackgroundDrawable(ContextCompat.getDrawable(this, R.drawable.ic_arsenal));
mapboxMapOptions.myLocationForegroundTintColor(Color.GREEN);
mapboxMapOptions.myLocationBackgroundTintColor(Color.YELLOW);
-// mapboxMapOptions.myLocationBackgroundPadding(new int[]{32, 32, 0, 0});
+ mapboxMapOptions.myLocationBackgroundPadding(new int[]{0, 0,
+ (int) getResources().getDimension(R.dimen.locationview_background_drawable_padding),
+ (int) getResources().getDimension(R.dimen.locationview_background_drawable_padding)});
-// mapboxMapOptions.myLocationAccuracyTint(Color.RED);
-// mapboxMapOptions.myLocationAccuracyAlpha(155);
+ mapboxMapOptions.myLocationAccuracyTint(Color.RED);
+ mapboxMapOptions.myLocationAccuracyAlpha(155);
mapView = new MapView(this, mapboxMapOptions);
ViewGroup parent = (ViewGroup) findViewById(R.id.container);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/dimens.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/dimens.xml
index 80cb7ae79f..98ec90c6fd 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/dimens.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/dimens.xml
@@ -7,6 +7,6 @@
<dimen name="map_padding_bottom">256dp</dimen>
<dimen name="map_padding_right">32dp</dimen>
<dimen name="toolbar_shadow">4dp</dimen>
-
+ <dimen name="locationview_background_drawable_padding">2dp</dimen>
<dimen name="locationview_padding_top">350dp</dimen>
</resources>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java
index d38814222e..a03eb6acae 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettingsTest.java
@@ -49,14 +49,9 @@ public class MyLocationViewSettingsTest {
@Test
public void testBackgroundDrawable() {
Drawable backgroundDrawable = mock(Drawable.class);
- locationViewSettings.setBackgroundDrawable(backgroundDrawable);
- assertEquals("foreground should match", backgroundDrawable, locationViewSettings.getBackgroundDrawable());
- }
-
- @Test
- public void testBackgroundOffset() {
int[] offset = new int[]{1, 2, 3, 4};
- locationViewSettings.setBackgroundOffset(1, 2, 3, 4);
+ locationViewSettings.setBackgroundDrawable(backgroundDrawable, offset);
+ assertEquals("foreground should match", backgroundDrawable, locationViewSettings.getBackgroundDrawable());
assertTrue("offsets should match", Arrays.equals(offset, locationViewSettings.getBackgroundOffset()));
}
@@ -68,7 +63,7 @@ public class MyLocationViewSettingsTest {
}
@Test
- public void testBackgroundTint(){
+ public void testBackgroundTint() {
int color = Color.RED;
locationViewSettings.setBackgroundTintColor(Color.RED);
assertEquals("color should match", color, locationViewSettings.getBackgroundTintColor());