[android] #5279 - expose MarkerView alpha

This commit is contained in:
Tobrun Van Nuland
2016-06-13 13:05:25 +02:00
parent 4f622a75db
commit 7942ce9455
5 changed files with 37 additions and 3 deletions

View File

@@ -29,6 +29,7 @@ public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends Base
protected float rotation;
protected boolean visible = true;
protected boolean selected;
protected float alpha = 1.0f;
/**
* Default constructor
@@ -132,13 +133,24 @@ public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends Base
* Set the visibility state of the MarkerView.
*
* @param visible the visible state
* @return the object for which the method was calleds
* @return the object for which the method was called
*/
public T visible(boolean visible) {
this.visible = visible;
return getThis();
}
/**
* Set the alpha of the MarkerView.
*
* @param alpha the alpha value
* @return the object for which the method was called
*/
public T alpha(float alpha) {
this.alpha = alpha;
return getThis();
}
/**
* Get the geographical location of the MarkerView.
*
@@ -238,6 +250,15 @@ public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends Base
return visible;
}
/**
* Get the alpha of the MarkerView.
*
* @return the alpha value
*/
public float getAlpha() {
return alpha;
}
/**
* Get the instance of the object for which this method was called.
*

View File

@@ -30,6 +30,7 @@ public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerV
infoWindowAnchor(in.readFloat(), in.readFloat());
rotation(in.readFloat());
visible(in.readByte() != 0);
alpha(in.readFloat());
if (in.readByte() != 0) {
// this means we have an icon
String iconId = in.readString();
@@ -61,6 +62,7 @@ public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerV
out.writeFloat(getInfoWindowAnchorV());
out.writeFloat(getRotation());
out.writeByte((byte) (isVisible() ? 1 : 0));
out.writeFloat(alpha);
Icon icon = getIcon();
out.writeByte((byte) (icon != null ? 1 : 0));
if (icon != null) {
@@ -80,6 +82,7 @@ public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerV
marker.setInfoWindowAnchor(infoWindowAnchorU, infoWindowAnchorV);
marker.setRotation(rotation);
marker.setVisible(visible);
marker.setAlpha(alpha);
return marker;
}

View File

@@ -92,6 +92,7 @@ public class MarkerViewActivity extends AppCompatActivity {
mMapboxMap.addMarker(new MarkerViewOptions()
.position(LAT_LNGS[i])
.title(String.valueOf(i))
.alpha(0.5f)
.icon(usFlag)
);
}

View File

@@ -7,6 +7,7 @@ import android.os.Parcelable;
import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.MarkerView;
import com.mapbox.mapboxsdk.geometry.LatLng;
public class CountryMarkerViewOptions extends BaseMarkerViewOptions<CountryMarkerView, CountryMarkerViewOptions> {
@@ -23,8 +24,10 @@ public class CountryMarkerViewOptions extends BaseMarkerViewOptions<CountryMarke
title(in.readString());
flat(in.readByte() != 0);
anchor(in.readFloat(), in.readFloat());
selected = in.readByte() != 0;
infoWindowAnchor(in.readFloat(), in.readFloat());
rotation(in.readFloat());
visible(in.readByte() != 0);
alpha(in.readFloat());
if (in.readByte() != 0) {
// this means we have an icon
String iconId = in.readString();
@@ -56,8 +59,9 @@ public class CountryMarkerViewOptions extends BaseMarkerViewOptions<CountryMarke
out.writeFloat(getAnchorV());
out.writeFloat(getInfoWindowAnchorU());
out.writeFloat(getInfoWindowAnchorV());
out.writeByte((byte) (selected ? 1 : 0));
out.writeFloat(getRotation());
out.writeByte((byte) (isVisible() ? 1 : 0));
out.writeFloat(getAlpha());
Icon icon = getIcon();
out.writeByte((byte) (icon != null ? 1 : 0));
if (icon != null) {

View File

@@ -7,6 +7,7 @@ import android.os.Parcelable;
import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.MarkerView;
import com.mapbox.mapboxsdk.geometry.LatLng;
public class TextMarkerViewOptions extends BaseMarkerViewOptions<TextMarkerView, TextMarkerViewOptions> {
@@ -24,6 +25,8 @@ public class TextMarkerViewOptions extends BaseMarkerViewOptions<TextMarkerView,
anchor(in.readFloat(), in.readFloat());
infoWindowAnchor(in.readFloat(), in.readFloat());
rotation(in.readFloat());
visible(in.readByte() != 0);
alpha(in.readFloat());
if (in.readByte() != 0) {
// this means we have an icon
String iconId = in.readString();
@@ -55,6 +58,8 @@ public class TextMarkerViewOptions extends BaseMarkerViewOptions<TextMarkerView,
out.writeFloat(getInfoWindowAnchorU());
out.writeFloat(getInfoWindowAnchorV());
out.writeFloat(getRotation());
out.writeByte((byte) (isVisible() ? 1 : 0));
out.writeFloat(alpha);
Icon icon = getIcon();
out.writeByte((byte) (icon != null ? 1 : 0));
if (icon != null) {