[android] #4929 - MyLocationView now requires less drawables to configure, reuses the foreground instead.

This commit is contained in:
Tobrun Van Nuland
2016-06-01 08:57:23 +02:00
committed by Brad Leege
parent 163ee916e5
commit 3d2cc05121
3 changed files with 25 additions and 2 deletions

View File

@@ -462,6 +462,16 @@ public class MapboxMapOptions implements Parcelable {
return this;
}
/**
*
* @param myLocationForegroundDrawable
* @return This
*/
public MapboxMapOptions myLocationForegroundDrawable(Drawable myLocationForegroundDrawable) {
this.myLocationForegroundDrawable = myLocationForegroundDrawable;
return this;
}
/**
* @param myLocationBackgroundDrawable
* @return This

View File

@@ -129,9 +129,22 @@ public class MyLocationView extends View {
}
public final void setForegroundDrawables(Drawable defaultDrawable, Drawable bearingDrawable) {
if (defaultDrawable == null || bearingDrawable == null) {
if (defaultDrawable == null) {
return;
}
if (bearingDrawable == null) {
// if user only provided one resource
// use same for bearing mode
bearingDrawable = defaultDrawable;
}
if (backgroundDrawable == null) {
// if the user didn't provide a background resource we will use the foreground resource instead,
// we need to create a new drawable to handle tinting correctly
backgroundDrawable = defaultDrawable.getConstantState().newDrawable();
}
if (defaultDrawable.getIntrinsicWidth() != bearingDrawable.getIntrinsicWidth() || defaultDrawable.getIntrinsicHeight() != bearingDrawable.getIntrinsicHeight()) {
throw new RuntimeException("The dimensions from location and bearing drawables should be match");
}