[android] #4800 - correct background offsets from attributes
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user