[android] #4800 - default location view from start: introduced attributes, update MapboxMapOptions, added tests. updated MockParcel
This commit is contained in:
@@ -3,7 +3,7 @@ package com.mapbox.mapboxsdk.constants;
|
||||
import android.support.annotation.IntDef;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.UserLocationView;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -12,7 +12,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
* MyBearingTracking exposes different types bearing tracking modes.
|
||||
*
|
||||
* @see MapView#setMyBearingTrackingMode(int)
|
||||
* @see UserLocationView#setMyBearingTrackingMode(int)
|
||||
* @see MyLocationView#setMyBearingTrackingMode(int)
|
||||
*/
|
||||
public class MyBearingTracking {
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.mapbox.mapboxsdk.constants;
|
||||
import android.support.annotation.IntDef;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.UserLocationView;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -12,7 +12,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
* MyLocationTracking exposes different types of locational tracking modes.
|
||||
*
|
||||
* @see MapView#setMyLocationTrackingMode(int)
|
||||
* @see UserLocationView#setMyLocationTrackingMode(int)
|
||||
* @see MyLocationView#setMyLocationTrackingMode(int)
|
||||
*/
|
||||
public class MyLocationTracking {
|
||||
|
||||
@@ -30,7 +30,7 @@ public class MyLocationTracking {
|
||||
public static final int TRACKING_NONE = 0x00000000;
|
||||
|
||||
/**
|
||||
* Tracking the location of the user, {@link MapView} will reposition to center of {@link UserLocationView}
|
||||
* Tracking the location of the user, {@link MapView} will reposition to center of {@link MyLocationView}
|
||||
*/
|
||||
public static final int TRACKING_FOLLOW = 0x00000004;
|
||||
|
||||
|
||||
@@ -82,7 +82,8 @@ 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.UserLocationView;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
|
||||
import com.mapbox.mapboxsdk.telemetry.MapboxEvent;
|
||||
import com.mapbox.mapboxsdk.telemetry.MapboxEventManager;
|
||||
import com.mapbox.mapboxsdk.utils.ColorUtils;
|
||||
@@ -127,7 +128,7 @@ public class MapView extends FrameLayout {
|
||||
private CompassView mCompassView;
|
||||
private ImageView mLogoView;
|
||||
private ImageView mAttributionsView;
|
||||
private UserLocationView mUserLocationView;
|
||||
private MyLocationView mMyLocationView;
|
||||
|
||||
private CopyOnWriteArrayList<OnMapChangedListener> mOnMapChangedListener;
|
||||
private ZoomButtonsController mZoomButtonsController;
|
||||
@@ -224,8 +225,8 @@ public class MapView extends FrameLayout {
|
||||
// Connectivity
|
||||
onConnectivityChanged(isConnected());
|
||||
|
||||
mUserLocationView = (UserLocationView) view.findViewById(R.id.userLocationView);
|
||||
mUserLocationView.setMapboxMap(mMapboxMap);
|
||||
mMyLocationView = (MyLocationView) view.findViewById(R.id.userLocationView);
|
||||
mMyLocationView.setMapboxMap(mMapboxMap);
|
||||
|
||||
mCompassView = (CompassView) view.findViewById(R.id.compassView);
|
||||
mCompassView.setMapboxMap(mMapboxMap);
|
||||
@@ -264,6 +265,22 @@ public class MapView extends FrameLayout {
|
||||
mMapboxMap.setStyleUrl(style);
|
||||
}
|
||||
|
||||
// MyLocationView
|
||||
MyLocationViewSettings myLocationViewSettings = mMapboxMap.getMyLocationViewSettings();
|
||||
myLocationViewSettings.setForegroundDrawable(options.getMyLocationForegroundDrawable(), options.getMyLocationForegroundBearingDrawable());
|
||||
myLocationViewSettings.setBackgroundDrawable(options.getMyLocationBackgroundDrawable());
|
||||
if(options.getMyLocationForegroundTintColor()!=-1) {
|
||||
myLocationViewSettings.setForegroundTintColor(options.getMyLocationForegroundTintColor());
|
||||
}
|
||||
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
|
||||
@@ -276,6 +293,8 @@ public class MapView extends FrameLayout {
|
||||
uiSettings.setRotateGestureChangeAllowed(options.getRotateGesturesEnabled());
|
||||
uiSettings.setTiltGesturesEnabled(options.getTiltGesturesEnabled());
|
||||
uiSettings.setTiltGestureChangeAllowed(options.getTiltGesturesEnabled());
|
||||
|
||||
// Ui Controls
|
||||
uiSettings.setZoomControlsEnabled(options.getZoomControlsEnabled());
|
||||
|
||||
// Zoom
|
||||
@@ -525,7 +544,7 @@ public class MapView extends FrameLayout {
|
||||
getContext().unregisterReceiver(mConnectivityReceiver);
|
||||
mConnectivityReceiver = null;
|
||||
|
||||
mUserLocationView.onPause();
|
||||
mMyLocationView.onPause();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -538,7 +557,7 @@ public class MapView extends FrameLayout {
|
||||
getContext().registerReceiver(mConnectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
||||
|
||||
mNativeMapView.update();
|
||||
mUserLocationView.onResume();
|
||||
mMyLocationView.onResume();
|
||||
|
||||
if (mStyleUrl == null) {
|
||||
// user has failed to supply a style url
|
||||
@@ -590,7 +609,7 @@ public class MapView extends FrameLayout {
|
||||
if (duration != null) {
|
||||
actualDuration = duration;
|
||||
}
|
||||
mUserLocationView.setTilt(pitch);
|
||||
mMyLocationView.setTilt(pitch);
|
||||
mNativeMapView.setPitch(pitch, actualDuration);
|
||||
}
|
||||
|
||||
@@ -1329,7 +1348,7 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
|
||||
mCompassView.update(getDirection());
|
||||
mUserLocationView.update();
|
||||
mMyLocationView.update();
|
||||
for (InfoWindow infoWindow : mMapboxMap.getInfoWindows()) {
|
||||
infoWindow.update();
|
||||
}
|
||||
@@ -1557,7 +1576,7 @@ public class MapView extends FrameLayout {
|
||||
zoom(true, e.getX(), e.getY());
|
||||
} else {
|
||||
// Zoom in on user location view
|
||||
zoom(true, mUserLocationView.getCenterX(), mUserLocationView.getCenterY());
|
||||
zoom(true, mMyLocationView.getCenterX(), mMyLocationView.getCenterY());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1790,8 +1809,8 @@ public class MapView extends FrameLayout {
|
||||
mNativeMapView.scaleBy(detector.getScaleFactor(), (getWidth() / 2) / mScreenDensity, (getHeight() / 2) / mScreenDensity);
|
||||
} else {
|
||||
// around user location view
|
||||
float x = mUserLocationView.getX() + mUserLocationView.getWidth() / 2;
|
||||
float y = mUserLocationView.getY() + mUserLocationView.getHeight() / 2;
|
||||
float x = mMyLocationView.getX() + mMyLocationView.getWidth() / 2;
|
||||
float y = mMyLocationView.getY() + mMyLocationView.getHeight() / 2;
|
||||
mNativeMapView.scaleBy(detector.getScaleFactor(), x / mScreenDensity, y / mScreenDensity);
|
||||
}
|
||||
}
|
||||
@@ -1871,8 +1890,8 @@ public class MapView extends FrameLayout {
|
||||
detector.getFocusY() / mScreenDensity);
|
||||
} else {
|
||||
// around center userlocation
|
||||
float x = mUserLocationView.getX() + mUserLocationView.getWidth() / 2;
|
||||
float y = mUserLocationView.getY() + mUserLocationView.getHeight() / 2;
|
||||
float x = mMyLocationView.getX() + mMyLocationView.getWidth() / 2;
|
||||
float y = mMyLocationView.getY() + mMyLocationView.getHeight() / 2;
|
||||
mNativeMapView.setBearing(bearing, x / mScreenDensity, y / mScreenDensity);
|
||||
}
|
||||
return true;
|
||||
@@ -2336,18 +2355,20 @@ public class MapView extends FrameLayout {
|
||||
//
|
||||
|
||||
void setMyLocationEnabled(boolean enabled) {
|
||||
mUserLocationView.setEnabled(enabled);
|
||||
mMyLocationView.setEnabled(enabled);
|
||||
}
|
||||
|
||||
Location getMyLocation() {
|
||||
return mUserLocationView.getLocation();
|
||||
return mMyLocationView.getLocation();
|
||||
}
|
||||
|
||||
void setOnMyLocationChangeListener(@Nullable final MapboxMap.OnMyLocationChangeListener listener) {
|
||||
LocationServices.getLocationServices(getContext()).addLocationListener(new LocationListener() {
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
listener.onMyLocationChange(location);
|
||||
if(listener!=null) {
|
||||
listener.onMyLocationChange(location);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -2356,7 +2377,7 @@ public class MapView extends FrameLayout {
|
||||
if (myLocationTrackingMode != MyLocationTracking.TRACKING_NONE && !mMapboxMap.isMyLocationEnabled()) {
|
||||
mMapboxMap.setMyLocationEnabled(true);
|
||||
}
|
||||
mUserLocationView.setMyLocationTrackingMode(myLocationTrackingMode);
|
||||
mMyLocationView.setMyLocationTrackingMode(myLocationTrackingMode);
|
||||
MapboxMap.OnMyLocationTrackingModeChangeListener listener = mMapboxMap.getOnMyLocationTrackingModeChangeListener();
|
||||
if (listener != null) {
|
||||
listener.onMyLocationTrackingModeChange(myLocationTrackingMode);
|
||||
@@ -2367,7 +2388,7 @@ public class MapView extends FrameLayout {
|
||||
if (myBearingTrackingMode != MyBearingTracking.NONE && !mMapboxMap.isMyLocationEnabled()) {
|
||||
mMapboxMap.setMyLocationEnabled(true);
|
||||
}
|
||||
mUserLocationView.setMyBearingTrackingMode(myBearingTrackingMode);
|
||||
mMyLocationView.setMyBearingTrackingMode(myBearingTrackingMode);
|
||||
MapboxMap.OnMyBearingTrackingModeChangeListener listener = mMapboxMap.getOnMyBearingTrackingModeChangeListener();
|
||||
if (listener != null) {
|
||||
listener.onMyBearingTrackingModeChange(myBearingTrackingMode);
|
||||
@@ -2512,8 +2533,8 @@ public class MapView extends FrameLayout {
|
||||
mMapboxMap = mapboxMap;
|
||||
}
|
||||
|
||||
UserLocationView getUserLocationView() {
|
||||
return mUserLocationView;
|
||||
MyLocationView getUserLocationView() {
|
||||
return mMyLocationView;
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
||||
@@ -2,17 +2,25 @@ 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;
|
||||
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;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.utils.ColorUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Defines configuration MapboxMapMapOptions for a MapboxMap. These options can be used when adding a
|
||||
@@ -56,7 +64,15 @@ public class MapboxMapOptions implements Parcelable {
|
||||
private boolean zoomGesturesEnabled = true;
|
||||
private boolean zoomControlsEnabled = false;
|
||||
|
||||
private boolean locationEnabled;
|
||||
private boolean myLocationEnabled;
|
||||
private Drawable myLocationForegroundDrawable;
|
||||
private Drawable myLocationForegroundBearingDrawable;
|
||||
private Drawable myLocationBackgroundDrawable;
|
||||
private int myLocationForegroundTintColor = -1;
|
||||
private int myLocationBackgroundTintColor = -1;
|
||||
private int[] myLocationBackgroundPadding;
|
||||
private int myLocationAccuracyTintColor;
|
||||
private int myLocationAccuracyAlpha;
|
||||
|
||||
private String style;
|
||||
private String accessToken;
|
||||
@@ -93,7 +109,15 @@ public class MapboxMapOptions implements Parcelable {
|
||||
zoomControlsEnabled = in.readByte() != 0;
|
||||
zoomGesturesEnabled = in.readByte() != 0;
|
||||
|
||||
locationEnabled = in.readByte() != 0;
|
||||
myLocationEnabled = in.readByte() != 0;
|
||||
//myLocationForegroundDrawable;
|
||||
//myLocationForegroundBearingDrawable;
|
||||
//myLocationBackgroundDrawable;
|
||||
myLocationForegroundTintColor = in.readInt();
|
||||
myLocationBackgroundTintColor = in.readInt();
|
||||
myLocationBackgroundPadding = in.createIntArray();
|
||||
myLocationAccuracyAlpha = in.readInt();
|
||||
myLocationAccuracyTintColor = in.readInt();
|
||||
|
||||
style = in.readString();
|
||||
accessToken = in.readString();
|
||||
@@ -150,6 +174,18 @@ 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.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)
|
||||
, (int) (typedArray.getDimension(R.styleable.MapView_my_location_background_top, 0) * screenDensity)
|
||||
, (int) (typedArray.getDimension(R.styleable.MapView_my_location_background_right, 0) * screenDensity)
|
||||
, (int) (typedArray.getDimension(R.styleable.MapView_my_location_background_bottom, 0) * screenDensity)});
|
||||
mapboxMapOptions.myLocationAccuracyAlpha(typedArray.getInt(R.styleable.MapView_my_location_accuracy_alpha, 100));
|
||||
mapboxMapOptions.myLocationAccuracyTint(typedArray.getColor(R.styleable.MapView_my_location_accuracy_tint, ColorUtils.getAccentColor(context)));
|
||||
} finally {
|
||||
typedArray.recycle();
|
||||
}
|
||||
@@ -394,7 +430,79 @@ public class MapboxMapOptions implements Parcelable {
|
||||
* @return This
|
||||
*/
|
||||
public MapboxMapOptions locationEnabled(boolean locationEnabled) {
|
||||
this.locationEnabled = locationEnabled;
|
||||
this.myLocationEnabled = locationEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param myLocationForegroundDrawable
|
||||
* @return This
|
||||
*/
|
||||
public MapboxMapOptions myLocationForegroundDrawable(Drawable myLocationForegroundDrawable) {
|
||||
this.myLocationForegroundDrawable = myLocationForegroundDrawable;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param myLocationBearingDrawable
|
||||
* @return This
|
||||
*/
|
||||
public MapboxMapOptions myLocationForegroundBearingDrawable(Drawable myLocationBearingDrawable) {
|
||||
this.myLocationForegroundBearingDrawable = myLocationBearingDrawable;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param myLocationBackgroundDrawable
|
||||
* @return This
|
||||
*/
|
||||
public MapboxMapOptions myLocationBackgroundDrawable(Drawable myLocationBackgroundDrawable) {
|
||||
this.myLocationBackgroundDrawable = myLocationBackgroundDrawable;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param myLocationForegroundTintColor
|
||||
* @return This
|
||||
*/
|
||||
public MapboxMapOptions myLocationForegroundTintColor(@ColorInt int myLocationForegroundTintColor) {
|
||||
this.myLocationForegroundTintColor = myLocationForegroundTintColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param myLocationBackgroundTintColor
|
||||
* @return This
|
||||
*/
|
||||
public MapboxMapOptions myLocationBackgroundTintColor(@ColorInt int myLocationBackgroundTintColor) {
|
||||
this.myLocationBackgroundTintColor = myLocationBackgroundTintColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param myLocationBackgroundPadding
|
||||
* @return This
|
||||
*/
|
||||
public MapboxMapOptions myLocationBackgroundPadding(int[] myLocationBackgroundPadding) {
|
||||
this.myLocationBackgroundPadding = myLocationBackgroundPadding;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param myLocationAccuracyTintColor
|
||||
* @return This
|
||||
*/
|
||||
public MapboxMapOptions myLocationAccuracyTint(@ColorInt int myLocationAccuracyTintColor) {
|
||||
this.myLocationAccuracyTintColor = myLocationAccuracyTintColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param alpha
|
||||
* @return This
|
||||
*/
|
||||
public MapboxMapOptions myLocationAccuracyAlpha(@IntRange(from = 0, to = 255) int alpha) {
|
||||
this.myLocationAccuracyAlpha = alpha;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -580,7 +688,63 @@ public class MapboxMapOptions implements Parcelable {
|
||||
* @return True and user location will be shown
|
||||
*/
|
||||
public boolean getLocationEnabled() {
|
||||
return locationEnabled;
|
||||
return myLocationEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Drawable getMyLocationForegroundDrawable() {
|
||||
return myLocationForegroundDrawable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Drawable getMyLocationForegroundBearingDrawable() {
|
||||
return myLocationForegroundBearingDrawable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Drawable getMyLocationBackgroundDrawable() {
|
||||
return myLocationBackgroundDrawable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getMyLocationForegroundTintColor() {
|
||||
return myLocationForegroundTintColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getMyLocationBackgroundTintColor() {
|
||||
return myLocationBackgroundTintColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int[] getMyLocationBackgroundPadding() {
|
||||
return myLocationBackgroundPadding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getMyLocationAccuracyTintColor() {
|
||||
return myLocationAccuracyTintColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getMyLocationAccuracyAlpha() {
|
||||
return myLocationAccuracyAlpha;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -635,9 +799,94 @@ public class MapboxMapOptions implements Parcelable {
|
||||
dest.writeByte((byte) (zoomControlsEnabled ? 1 : 0));
|
||||
dest.writeByte((byte) (zoomGesturesEnabled ? 1 : 0));
|
||||
|
||||
dest.writeByte((byte) (locationEnabled ? 1 : 0));
|
||||
dest.writeByte((byte) (myLocationEnabled ? 1 : 0));
|
||||
//myLocationForegroundDrawable;
|
||||
//myLocationForegroundBearingDrawable;
|
||||
//myLocationBackgroundDrawable;
|
||||
dest.writeInt(myLocationForegroundTintColor);
|
||||
dest.writeInt(myLocationBackgroundTintColor);
|
||||
dest.writeIntArray(myLocationBackgroundPadding);
|
||||
dest.writeInt(myLocationAccuracyAlpha);
|
||||
dest.writeInt(myLocationAccuracyTintColor);
|
||||
|
||||
dest.writeString(style);
|
||||
dest.writeString(accessToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
MapboxMapOptions options = (MapboxMapOptions) o;
|
||||
|
||||
if (debugActive != options.debugActive) return false;
|
||||
if (compassEnabled != options.compassEnabled) return false;
|
||||
if (compassGravity != options.compassGravity) return false;
|
||||
if (logoEnabled != options.logoEnabled) return false;
|
||||
if (logoGravity != options.logoGravity) return false;
|
||||
if (attributionEnabled != options.attributionEnabled) return false;
|
||||
if (attributionGravity != options.attributionGravity) return false;
|
||||
if (Float.compare(options.minZoom, minZoom) != 0) return false;
|
||||
if (Float.compare(options.maxZoom, maxZoom) != 0) return false;
|
||||
if (rotateGesturesEnabled != options.rotateGesturesEnabled) return false;
|
||||
if (scrollGesturesEnabled != options.scrollGesturesEnabled) return false;
|
||||
if (tiltGesturesEnabled != options.tiltGesturesEnabled) return false;
|
||||
if (zoomGesturesEnabled != options.zoomGesturesEnabled) return false;
|
||||
if (zoomControlsEnabled != options.zoomControlsEnabled) return false;
|
||||
if (myLocationEnabled != options.myLocationEnabled) return false;
|
||||
if (myLocationForegroundTintColor != options.myLocationForegroundTintColor) return false;
|
||||
if (myLocationBackgroundTintColor != options.myLocationBackgroundTintColor) return false;
|
||||
if (myLocationAccuracyTintColor != options.myLocationAccuracyTintColor) return false;
|
||||
if (myLocationAccuracyAlpha != options.myLocationAccuracyAlpha) return false;
|
||||
if (cameraPosition != null ? !cameraPosition.equals(options.cameraPosition) : options.cameraPosition != null)
|
||||
return false;
|
||||
if (!Arrays.equals(compassMargins, options.compassMargins)) return false;
|
||||
if (!Arrays.equals(logoMargins, options.logoMargins)) return false;
|
||||
if (!Arrays.equals(attributionMargins, options.attributionMargins)) return false;
|
||||
if (myLocationForegroundDrawable != null ? !myLocationForegroundDrawable.equals(options.myLocationForegroundDrawable) : options.myLocationForegroundDrawable != null)
|
||||
return false;
|
||||
if (myLocationForegroundBearingDrawable != null ? !myLocationForegroundBearingDrawable.equals(options.myLocationForegroundBearingDrawable) : options.myLocationForegroundBearingDrawable != null)
|
||||
return false;
|
||||
if (myLocationBackgroundDrawable != null ? !myLocationBackgroundDrawable.equals(options.myLocationBackgroundDrawable) : options.myLocationBackgroundDrawable != null)
|
||||
return false;
|
||||
if (!Arrays.equals(myLocationBackgroundPadding, options.myLocationBackgroundPadding))
|
||||
return false;
|
||||
if (style != null ? !style.equals(options.style) : options.style != null) return false;
|
||||
return accessToken != null ? accessToken.equals(options.accessToken) : options.accessToken == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = cameraPosition != null ? cameraPosition.hashCode() : 0;
|
||||
result = 31 * result + (debugActive ? 1 : 0);
|
||||
result = 31 * result + (compassEnabled ? 1 : 0);
|
||||
result = 31 * result + compassGravity;
|
||||
result = 31 * result + Arrays.hashCode(compassMargins);
|
||||
result = 31 * result + (logoEnabled ? 1 : 0);
|
||||
result = 31 * result + logoGravity;
|
||||
result = 31 * result + Arrays.hashCode(logoMargins);
|
||||
result = 31 * result + (attributionEnabled ? 1 : 0);
|
||||
result = 31 * result + attributionGravity;
|
||||
result = 31 * result + Arrays.hashCode(attributionMargins);
|
||||
result = 31 * result + (minZoom != +0.0f ? Float.floatToIntBits(minZoom) : 0);
|
||||
result = 31 * result + (maxZoom != +0.0f ? Float.floatToIntBits(maxZoom) : 0);
|
||||
result = 31 * result + (rotateGesturesEnabled ? 1 : 0);
|
||||
result = 31 * result + (scrollGesturesEnabled ? 1 : 0);
|
||||
result = 31 * result + (tiltGesturesEnabled ? 1 : 0);
|
||||
result = 31 * result + (zoomGesturesEnabled ? 1 : 0);
|
||||
result = 31 * result + (zoomControlsEnabled ? 1 : 0);
|
||||
result = 31 * result + (myLocationEnabled ? 1 : 0);
|
||||
result = 31 * result + (myLocationForegroundDrawable != null ? myLocationForegroundDrawable.hashCode() : 0);
|
||||
result = 31 * result + (myLocationForegroundBearingDrawable != null ? myLocationForegroundBearingDrawable.hashCode() : 0);
|
||||
result = 31 * result + (myLocationBackgroundDrawable != null ? myLocationBackgroundDrawable.hashCode() : 0);
|
||||
result = 31 * result + myLocationForegroundTintColor;
|
||||
result = 31 * result + myLocationBackgroundTintColor;
|
||||
result = 31 * result + Arrays.hashCode(myLocationBackgroundPadding);
|
||||
result = 31 * result + myLocationAccuracyTintColor;
|
||||
result = 31 * result + myLocationAccuracyAlpha;
|
||||
result = 31 * result + (style != null ? style.hashCode() : 0);
|
||||
result = 31 * result + (accessToken != null ? accessToken.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.support.annotation.UiThread;
|
||||
|
||||
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
|
||||
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.UserLocationView;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
|
||||
|
||||
/**
|
||||
* Settings for the user location and bearing tracking of a MapboxMap.
|
||||
@@ -67,7 +67,7 @@ public class TrackingSettings {
|
||||
* </p>
|
||||
* Shows the direction the user is heading.
|
||||
* <p>
|
||||
* When location tracking is disabled the direction of {@link UserLocationView} is rotated
|
||||
* When location tracking is disabled the direction of {@link MyLocationView} is rotated
|
||||
* When location tracking is enabled the {@link MapView} is rotated based on bearing value.
|
||||
* </p>
|
||||
* See {@link MyBearingTracking} for different values.
|
||||
|
||||
@@ -15,7 +15,6 @@ public class UiSettings {
|
||||
|
||||
private MapView mapView;
|
||||
|
||||
private MyLocationViewSettings myLocationViewSettings;
|
||||
private ViewSettings compassSettings;
|
||||
private ViewSettings logoSettings;
|
||||
private ViewSettings attributionSettings;
|
||||
@@ -568,22 +567,4 @@ public class UiSettings {
|
||||
mapView.setCompassMargins(getCompassMarginLeft(), getCompassMarginTop(), getCompassMarginRight(), getCompassMarginBottom());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.mapbox.mapboxsdk.maps.widgets;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.PorterDuff;
|
||||
@@ -29,6 +28,7 @@ import android.view.View;
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
|
||||
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
@@ -44,9 +44,9 @@ import java.lang.ref.WeakReference;
|
||||
/**
|
||||
* UI element overlaid on a map to show the user's location.
|
||||
*/
|
||||
public class UserLocationView extends View {
|
||||
public class MyLocationView extends View {
|
||||
|
||||
private UserLocationBehaviour userLocationBehaviour;
|
||||
private MyLocationBehaviour myLocationBehaviour;
|
||||
private MapboxMap mapboxMap;
|
||||
private Projection projection;
|
||||
private int maxSize;
|
||||
@@ -89,17 +89,17 @@ public class UserLocationView extends View {
|
||||
private GpsLocationListener userLocationListener;
|
||||
private CompassListener compassListener;
|
||||
|
||||
public UserLocationView(Context context) {
|
||||
public MyLocationView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public UserLocationView(Context context, AttributeSet attrs) {
|
||||
public MyLocationView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public UserLocationView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
public MyLocationView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
@@ -108,22 +108,22 @@ public class UserLocationView extends View {
|
||||
setEnabled(false);
|
||||
|
||||
// behavioural model
|
||||
userLocationBehaviour = new UserLocationBehaviourFactory().getBehaviouralModel(MyLocationTracking.TRACKING_NONE);
|
||||
myLocationBehaviour = new MyLocationBehaviourFactory().getBehaviouralModel(MyLocationTracking.TRACKING_NONE);
|
||||
compassListener = new CompassListener(context);
|
||||
maxSize = (int) context.getResources().getDimension(R.dimen.userlocationview_size);
|
||||
|
||||
// default implementation
|
||||
setShadowDrawable(ContextCompat.getDrawable(context, R.drawable.ic_userlocationview_shadow));
|
||||
setShadowDrawableTint(ColorUtils.getPrimaryDarkColor(context));
|
||||
|
||||
setForegroundDrawables(ContextCompat.getDrawable(context, R.drawable.ic_userlocationview_normal), ContextCompat.getDrawable(context, R.drawable.ic_userlocationview_bearing));
|
||||
setForegroundDrawableTint(ColorUtils.getPrimaryColor(context));
|
||||
|
||||
accuracyPaint.setColor(ColorUtils.getAccentColor(context));
|
||||
accuracyPaint.setAlpha(100);
|
||||
setAccuracyTint(ColorUtils.getAccentColor(context));
|
||||
setAccuracyAlpha(100);
|
||||
}
|
||||
|
||||
public final void setForegroundDrawables(Drawable defaultDrawable, Drawable bearingDrawable) {
|
||||
if (defaultDrawable == null || bearingDrawable == null) {
|
||||
Log.e(MapboxConstants.TAG, "Not setting foreground drawables MyLocationView: default = " + defaultDrawable + " bearing = " + bearingDrawable);
|
||||
return;
|
||||
}
|
||||
if (defaultDrawable.getIntrinsicWidth() != bearingDrawable.getIntrinsicWidth() || defaultDrawable.getIntrinsicHeight() != bearingDrawable.getIntrinsicHeight()) {
|
||||
throw new RuntimeException("The dimensions from location and bearing drawables should be match");
|
||||
}
|
||||
@@ -146,6 +146,9 @@ public class UserLocationView extends View {
|
||||
}
|
||||
|
||||
public final void setShadowDrawable(Drawable drawable, int left, int top, int right, int bottom) {
|
||||
if (drawable == null) {
|
||||
return;
|
||||
}
|
||||
backgroundDrawable = drawable;
|
||||
backgroundOffsetLeft = left;
|
||||
backgroundOffsetTop = top;
|
||||
@@ -163,7 +166,9 @@ public class UserLocationView extends View {
|
||||
}
|
||||
|
||||
public final void setAccuracyTint(@ColorInt int color) {
|
||||
int alpha = accuracyPaint.getAlpha();
|
||||
accuracyPaint.setColor(color);
|
||||
accuracyPaint.setAlpha(alpha);
|
||||
}
|
||||
|
||||
public final void setAccuracyAlpha(@IntRange(from = 0, to = 255) int alpha) {
|
||||
@@ -278,7 +283,7 @@ public class UserLocationView extends View {
|
||||
|
||||
public void update() {
|
||||
if (isEnabled()) {
|
||||
userLocationBehaviour.invalidate();
|
||||
myLocationBehaviour.invalidate();
|
||||
} else {
|
||||
setVisibility(View.INVISIBLE);
|
||||
}
|
||||
@@ -336,7 +341,7 @@ public class UserLocationView extends View {
|
||||
}
|
||||
|
||||
this.location = location;
|
||||
userLocationBehaviour.updateLatLng(location);
|
||||
myLocationBehaviour.updateLatLng(location);
|
||||
}
|
||||
|
||||
public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) {
|
||||
@@ -357,12 +362,12 @@ public class UserLocationView extends View {
|
||||
public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
|
||||
this.myLocationTrackingMode = myLocationTrackingMode;
|
||||
|
||||
UserLocationBehaviourFactory factory = new UserLocationBehaviourFactory();
|
||||
userLocationBehaviour = factory.getBehaviouralModel(myLocationTrackingMode);
|
||||
MyLocationBehaviourFactory factory = new MyLocationBehaviourFactory();
|
||||
myLocationBehaviour = factory.getBehaviouralModel(myLocationTrackingMode);
|
||||
|
||||
if (myLocationTrackingMode != MyLocationTracking.TRACKING_NONE && location != null) {
|
||||
// center map directly if we have a location fix
|
||||
userLocationBehaviour.updateLatLng(location);
|
||||
myLocationBehaviour.updateLatLng(location);
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(location)));
|
||||
}
|
||||
invalidate();
|
||||
@@ -400,10 +405,10 @@ public class UserLocationView extends View {
|
||||
|
||||
private static class GpsLocationListener implements LocationListener {
|
||||
|
||||
private WeakReference<UserLocationView> mUserLocationView;
|
||||
private WeakReference<MyLocationView> mUserLocationView;
|
||||
|
||||
public GpsLocationListener(UserLocationView userLocationView) {
|
||||
mUserLocationView = new WeakReference<>(userLocationView);
|
||||
public GpsLocationListener(MyLocationView myLocationView) {
|
||||
mUserLocationView = new WeakReference<>(myLocationView);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -413,7 +418,7 @@ public class UserLocationView extends View {
|
||||
*/
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
UserLocationView locationView = mUserLocationView.get();
|
||||
MyLocationView locationView = mUserLocationView.get();
|
||||
if (locationView != null) {
|
||||
locationView.setLocation(location);
|
||||
}
|
||||
@@ -511,14 +516,14 @@ public class UserLocationView extends View {
|
||||
|
||||
private class MarkerCoordinateAnimatorListener implements ValueAnimator.AnimatorUpdateListener {
|
||||
|
||||
private UserLocationBehaviour behaviour;
|
||||
private MyLocationBehaviour behaviour;
|
||||
private double fromLat;
|
||||
private double fromLng;
|
||||
private double toLat;
|
||||
private double toLng;
|
||||
|
||||
private MarkerCoordinateAnimatorListener(UserLocationBehaviour userLocationBehaviour, LatLng from, LatLng to) {
|
||||
behaviour = userLocationBehaviour;
|
||||
private MarkerCoordinateAnimatorListener(MyLocationBehaviour myLocationBehaviour, LatLng from, LatLng to) {
|
||||
behaviour = myLocationBehaviour;
|
||||
fromLat = from.getLatitude();
|
||||
fromLng = from.getLongitude();
|
||||
toLat = to.getLatitude();
|
||||
@@ -535,18 +540,18 @@ public class UserLocationView extends View {
|
||||
}
|
||||
}
|
||||
|
||||
private class UserLocationBehaviourFactory {
|
||||
private class MyLocationBehaviourFactory {
|
||||
|
||||
public UserLocationBehaviour getBehaviouralModel(@MyLocationTracking.Mode int mode) {
|
||||
public MyLocationBehaviour getBehaviouralModel(@MyLocationTracking.Mode int mode) {
|
||||
if (mode == MyLocationTracking.TRACKING_NONE) {
|
||||
return new UserLocationShowBehaviour();
|
||||
return new MyLocationShowBehaviour();
|
||||
} else {
|
||||
return new UserLocationTrackingBehaviour();
|
||||
return new MyLocationTrackingBehaviour();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private abstract class UserLocationBehaviour {
|
||||
private abstract class MyLocationBehaviour {
|
||||
|
||||
abstract void updateLatLng(@NonNull Location location);
|
||||
|
||||
@@ -564,7 +569,7 @@ public class UserLocationView extends View {
|
||||
accuracyAnimator.end();
|
||||
}
|
||||
|
||||
accuracyAnimator = ValueAnimator.ofFloat(accuracy, location.getAccuracy());
|
||||
accuracyAnimator = ValueAnimator.ofFloat(accuracy * 10, location.getAccuracy() * 10);
|
||||
accuracyAnimator.setDuration(750);
|
||||
accuracyAnimator.start();
|
||||
accuracy = location.getAccuracy();
|
||||
@@ -573,7 +578,7 @@ public class UserLocationView extends View {
|
||||
abstract void invalidate();
|
||||
}
|
||||
|
||||
private class UserLocationTrackingBehaviour extends UserLocationBehaviour {
|
||||
private class MyLocationTrackingBehaviour extends MyLocationBehaviour {
|
||||
|
||||
@Override
|
||||
void updateLatLng(@NonNull Location location) {
|
||||
@@ -581,7 +586,6 @@ public class UserLocationView extends View {
|
||||
// first location fix
|
||||
latLng = new LatLng(location);
|
||||
locationUpdateTimestamp = SystemClock.elapsedRealtime();
|
||||
return;
|
||||
}
|
||||
|
||||
// updateLatLng timestamp
|
||||
@@ -630,19 +634,18 @@ public class UserLocationView extends View {
|
||||
UiSettings uiSettings = mapboxMap.getUiSettings();
|
||||
setX((uiSettings.getWidth() - getWidth() + mapPadding[0] - mapPadding[2]) / 2 + (contentPadding[0] - contentPadding[2]) / 2);
|
||||
setY((uiSettings.getHeight() - getHeight() - mapPadding[3] + mapPadding[1]) / 2 + (contentPadding[1] - contentPadding[3]) / 2);
|
||||
UserLocationView.this.invalidate();
|
||||
MyLocationView.this.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private class UserLocationShowBehaviour extends UserLocationBehaviour {
|
||||
private class MyLocationShowBehaviour extends MyLocationBehaviour {
|
||||
|
||||
@Override
|
||||
void updateLatLng(@NonNull final Location location) {
|
||||
if (latLng == null) {
|
||||
// first location updateLatLng
|
||||
// first location update
|
||||
latLng = new LatLng(location);
|
||||
locationUpdateTimestamp = SystemClock.elapsedRealtime();
|
||||
return;
|
||||
}
|
||||
|
||||
// update LatLng location
|
||||
@@ -701,7 +704,7 @@ public class UserLocationView extends View {
|
||||
setX((screenLocation.x - getWidth() / 2));
|
||||
setY((screenLocation.y - getHeight() / 2));
|
||||
}
|
||||
UserLocationView.this.invalidate();
|
||||
MyLocationView.this.invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,12 @@ import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.IntRange;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
|
||||
public class MyLocationViewSettings {
|
||||
|
||||
private MapView mapView;
|
||||
private UserLocationView userLocationView;
|
||||
private MyLocationView myLocationView;
|
||||
|
||||
//
|
||||
// State
|
||||
@@ -42,7 +41,7 @@ public class MyLocationViewSettings {
|
||||
// Accuracy
|
||||
//
|
||||
|
||||
private int arruracyAlpha;
|
||||
private int accuracyAlpha;
|
||||
|
||||
@ColorInt
|
||||
private int accuracyTintColor;
|
||||
@@ -53,9 +52,9 @@ public class MyLocationViewSettings {
|
||||
|
||||
private int[] padding = new int[4];
|
||||
|
||||
public MyLocationViewSettings(MapView mapView, UserLocationView userLocationView) {
|
||||
public MyLocationViewSettings(MapView mapView, MyLocationView myLocationView) {
|
||||
this.mapView = mapView;
|
||||
this.userLocationView = userLocationView;
|
||||
this.myLocationView = myLocationView;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
@@ -64,13 +63,13 @@ public class MyLocationViewSettings {
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
userLocationView.setEnabled(enabled);
|
||||
myLocationView.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public void setForegroundDrawable(Drawable foregroundDrawable, Drawable foregroundBearingDrawable) {
|
||||
this.foregroundDrawable = foregroundDrawable;
|
||||
this.foregroundBearingDrawable = foregroundBearingDrawable;
|
||||
userLocationView.setForegroundDrawables(foregroundDrawable, foregroundBearingDrawable);
|
||||
myLocationView.setForegroundDrawables(foregroundDrawable, foregroundBearingDrawable);
|
||||
}
|
||||
|
||||
public Drawable getForegroundDrawable() {
|
||||
@@ -83,7 +82,7 @@ public class MyLocationViewSettings {
|
||||
|
||||
public void setForegroundTintColor(@ColorInt int foregroundTintColor) {
|
||||
this.foregroundTintColor = foregroundTintColor;
|
||||
userLocationView.setForegroundDrawableTint(foregroundTintColor);
|
||||
myLocationView.setForegroundDrawableTint(foregroundTintColor);
|
||||
}
|
||||
|
||||
public int getForegroundTintColor() {
|
||||
@@ -92,7 +91,7 @@ public class MyLocationViewSettings {
|
||||
|
||||
public void setBackgroundDrawable(Drawable backgroundDrawable) {
|
||||
this.backgroundDrawable = backgroundDrawable;
|
||||
userLocationView.setShadowDrawable(backgroundDrawable);
|
||||
myLocationView.setShadowDrawable(backgroundDrawable);
|
||||
}
|
||||
|
||||
public Drawable getBackgroundDrawable() {
|
||||
@@ -101,7 +100,7 @@ public class MyLocationViewSettings {
|
||||
|
||||
public void setBackgroundTintColor(@ColorInt int backgroundTintColor) {
|
||||
this.backgroundTintColor = backgroundTintColor;
|
||||
userLocationView.setShadowDrawableTint(backgroundTintColor);
|
||||
myLocationView.setShadowDrawableTint(backgroundTintColor);
|
||||
}
|
||||
|
||||
public int getBackgroundTintColor() {
|
||||
@@ -110,7 +109,7 @@ public class MyLocationViewSettings {
|
||||
|
||||
public void setBackgroundOffset(int left, int top, int right, int bottom) {
|
||||
backgroundOffset = new int[]{left, top, right, bottom};
|
||||
userLocationView.setShadowDrawable(backgroundDrawable, left, top, right, bottom);
|
||||
myLocationView.setShadowDrawable(backgroundDrawable, left, top, right, bottom);
|
||||
}
|
||||
|
||||
public int[] getBackgroundOffset() {
|
||||
@@ -119,7 +118,7 @@ public class MyLocationViewSettings {
|
||||
|
||||
public void setPadding(int left, int top, int right, int bottom) {
|
||||
padding = new int[]{left, top, right, bottom};
|
||||
userLocationView.setContentPadding(padding);
|
||||
myLocationView.setContentPadding(padding);
|
||||
mapView.invalidateContentPadding();
|
||||
}
|
||||
|
||||
@@ -128,12 +127,12 @@ public class MyLocationViewSettings {
|
||||
}
|
||||
|
||||
public int getAccuracyAlpha() {
|
||||
return arruracyAlpha;
|
||||
return accuracyAlpha;
|
||||
}
|
||||
|
||||
public void setAccuracyAlpha(@IntRange(from = 0, to = 255) int arruracyAlpha) {
|
||||
this.arruracyAlpha = arruracyAlpha;
|
||||
userLocationView.setAccuracyAlpha(arruracyAlpha);
|
||||
this.accuracyAlpha = arruracyAlpha;
|
||||
myLocationView.setAccuracyAlpha(arruracyAlpha);
|
||||
}
|
||||
|
||||
public int getAccuracyTintColor() {
|
||||
@@ -142,7 +141,6 @@ public class MyLocationViewSettings {
|
||||
|
||||
public void setAccuracyTintColor(@ColorInt int accuracyTintColor) {
|
||||
this.accuracyTintColor = accuracyTintColor;
|
||||
userLocationView.setAccuracyTint(accuracyTintColor);
|
||||
myLocationView.setAccuracyTint(accuracyTintColor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.maps.widgets;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Holder for the UserLocationView drawables.</p>
|
||||
* <p>Holds the drawable and its shadow if set, and manage their initialization.</p>
|
||||
*/
|
||||
class UserLocationViewDrawableHolder {
|
||||
Drawable mDrawable;
|
||||
Drawable mShadow;
|
||||
final RectF mBounds = new RectF();
|
||||
final RectF mShadowBounds = new RectF();
|
||||
|
||||
public UserLocationViewDrawableHolder() {
|
||||
}
|
||||
|
||||
public UserLocationViewDrawableHolder(Drawable drawable, Drawable shadow) {
|
||||
setDrawable(drawable);
|
||||
setShadow(shadow);
|
||||
}
|
||||
|
||||
void setDrawable(@NonNull Drawable drawable) {
|
||||
mDrawable = drawable;
|
||||
setDrawable(mDrawable, mBounds);
|
||||
}
|
||||
|
||||
void setShadow(@Nullable Drawable drawable) {
|
||||
mShadow = drawable;
|
||||
setDrawable(mShadow, mShadowBounds);
|
||||
}
|
||||
|
||||
boolean hasShadow() {
|
||||
return mShadow != null;
|
||||
}
|
||||
|
||||
private static void setDrawable(final @Nullable Drawable drawable, final @NonNull RectF bounds) {
|
||||
if (drawable != null) {
|
||||
int halfWidth = drawable.getIntrinsicWidth() / 2;
|
||||
int halfHeight = drawable.getIntrinsicHeight() / 2;
|
||||
bounds.set(
|
||||
-halfWidth,
|
||||
-halfHeight,
|
||||
halfWidth,
|
||||
halfHeight);
|
||||
drawable.setBounds(new Rect(
|
||||
-halfWidth,
|
||||
-halfHeight,
|
||||
halfWidth,
|
||||
halfHeight));
|
||||
} else {
|
||||
bounds.setEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@
|
||||
android:src="@drawable/ic_info_outline_24dp_selector"
|
||||
android:background="@drawable/bg_default_selector"/>
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.widgets.UserLocationView
|
||||
<com.mapbox.mapboxsdk.maps.widgets.MyLocationView
|
||||
android:id="@+id/userLocationView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
@@ -1,34 +1,47 @@
|
||||
<resources>
|
||||
<!-- these are public -->
|
||||
<declare-styleable name="MapView">
|
||||
|
||||
<!--Configuration-->
|
||||
<attr name="access_token" format="string" />
|
||||
<attr name="style_url" format="string" />
|
||||
|
||||
<!--Camera-->
|
||||
<attr name="center_longitude" format="float" />
|
||||
<attr name="center_latitude" format="float" />
|
||||
<attr name="zoom" format="float" />
|
||||
<attr name="zoom_max" format="float" />
|
||||
<attr name="zoom_min" format="float" />
|
||||
<attr name="direction" format="float" />
|
||||
<attr name="tilt" format="float" />
|
||||
|
||||
<!--Zoom-->
|
||||
<attr name="zoom_max" format="float" />
|
||||
<attr name="zoom_min" format="float" />
|
||||
|
||||
<!--Gestures-->
|
||||
<attr name="zoom_enabled" format="boolean" />
|
||||
<attr name="scroll_enabled" format="boolean" />
|
||||
<attr name="rotate_enabled" format="boolean" />
|
||||
<attr name="tilt_enabled" format="boolean" />
|
||||
<attr name="zoom_controls_enabled" format="boolean" />
|
||||
<attr name="debug_active" format="boolean" />
|
||||
<attr name="style_url" format="string" />
|
||||
<attr name="access_token" format="string" />
|
||||
<attr name="style_classes" format="string" />
|
||||
|
||||
<!-- My Location-->
|
||||
<!--UI-Controls-->
|
||||
<attr name="zoom_controls_enabled" format="boolean" />
|
||||
|
||||
<!--MyLocation-->
|
||||
<attr name="my_location_enabled" format="boolean" />
|
||||
<attr name="my_location_tint" format="color" />
|
||||
<attr name="my_location_foreground" format="reference" />
|
||||
<attr name="my_location_foreground_bearing" format="reference" />
|
||||
<attr name="my_location_foreground_tint" format="color" />
|
||||
<attr name="my_location_background" format="reference" />
|
||||
<attr name="my_location_background_left" format="integer" />
|
||||
<attr name="my_location_background_top" format="integer" />
|
||||
<attr name="my_location_background_right" format="integer" />
|
||||
<attr name="my_location_background_bottom" format="integer" />
|
||||
<attr name="my_location_background_tint" format="color" />
|
||||
<attr name="my_location_background_left" format="dimension" />
|
||||
<attr name="my_location_background_top" format="dimension" />
|
||||
<attr name="my_location_background_right" format="dimension" />
|
||||
<attr name="my_location_background_bottom" format="dimension" />
|
||||
<attr name="my_location_accuracy_tint" format="color" />
|
||||
<attr name="my_location_accuracy_alpha" format="integer" />
|
||||
|
||||
<!-- Compass -->
|
||||
<!--Compass-->
|
||||
<attr name="compass_enabled" format="boolean" />
|
||||
<attr name="compass_gravity">
|
||||
<flag name="top" value="0x30" />
|
||||
@@ -50,6 +63,8 @@
|
||||
<attr name="compass_margin_top" format="dimension" />
|
||||
<attr name="compass_margin_right" format="dimension" />
|
||||
<attr name="compass_margin_bottom" format="dimension" />
|
||||
|
||||
<!--Logo-->
|
||||
<attr name="logo_gravity">
|
||||
<flag name="top" value="0x30" />
|
||||
<flag name="bottom" value="0x50" />
|
||||
@@ -72,6 +87,7 @@
|
||||
<attr name="logo_margin_bottom" format="dimension" />
|
||||
<attr name="logo_enabled" format="boolean" />
|
||||
|
||||
<!--Attribution-->
|
||||
<attr name="attribution_gravity">
|
||||
<flag name="top" value="0x30" />
|
||||
<flag name="bottom" value="0x50" />
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
<activity
|
||||
android:name=".activity.userlocation.MyLocationCustomisationActivity"
|
||||
android:description="@string/description_user_location_customization"
|
||||
android:label="@string/activity_user_tracking_mode">
|
||||
android:label="@string/activity_user_tracking_customization">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_userlocation" />
|
||||
|
||||
@@ -4,17 +4,15 @@ import android.graphics.Color;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.location.LocationListener;
|
||||
@@ -23,16 +21,14 @@ import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
public class MyLocationCustomisationActivity extends AppCompatActivity implements LocationListener, OnMapReadyCallback {
|
||||
public class MyLocationCustomisationActivity extends AppCompatActivity implements LocationListener {
|
||||
|
||||
private MapView mMapView;
|
||||
private MapboxMap mMapboxMap;
|
||||
private Location mLocation;
|
||||
|
||||
private Bundle savedState;
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private Location location;
|
||||
private boolean firstRun;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@@ -47,114 +43,77 @@ public class MyLocationCustomisationActivity extends AppCompatActivity implement
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
savedState = savedInstanceState;
|
||||
findViewById(R.id.progress).setVisibility(View.GONE);
|
||||
location = LocationServices.getLocationServices(this).getLastLocation();
|
||||
|
||||
LocationServices locationServices = LocationServices.getLocationServices(this);
|
||||
locationServices.addLocationListener(this);
|
||||
locationServices.toggleGPS(true);
|
||||
MapboxMapOptions mapboxMapOptions = new MapboxMapOptions();
|
||||
mapboxMapOptions.accessToken(getString(R.string.mapbox_access_token));
|
||||
mapboxMapOptions.styleUrl(Style.MAPBOX_STREETS);
|
||||
mapboxMapOptions.locationEnabled(true);
|
||||
mapboxMapOptions.camera(new CameraPosition.Builder()
|
||||
.target(location != null ? new LatLng(location) : new LatLng(0, 0))
|
||||
.zoom(11)
|
||||
.tilt(25)
|
||||
.build());
|
||||
|
||||
mapboxMapOptions.myLocationForegroundTintColor(Color.GREEN);
|
||||
mapboxMapOptions.myLocationBackgroundTintColor(Color.YELLOW);
|
||||
// mapboxMapOptions.myLocationBackgroundPadding(new int[]{32, 32, 0, 0});
|
||||
|
||||
// mapboxMapOptions.myLocationAccuracyTint(Color.RED);
|
||||
// mapboxMapOptions.myLocationAccuracyAlpha(155);
|
||||
|
||||
mapView = new MapView(this, mapboxMapOptions);
|
||||
ViewGroup parent = (ViewGroup) findViewById(R.id.container);
|
||||
parent.addView(mapView);
|
||||
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
}
|
||||
});
|
||||
|
||||
LocationServices.getLocationServices(this).addLocationListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
if (location != null) {
|
||||
if (mMapView == null) {
|
||||
findViewById(R.id.progress).setVisibility(View.GONE);
|
||||
|
||||
MapboxMapOptions mapboxMapOptions = new MapboxMapOptions();
|
||||
mapboxMapOptions.accessToken(getString(R.string.mapbox_access_token));
|
||||
mapboxMapOptions.styleUrl(Style.MAPBOX_STREETS);
|
||||
mapboxMapOptions.locationEnabled(true);
|
||||
mapboxMapOptions.camera(new CameraPosition.Builder()
|
||||
.target(new LatLng(location))
|
||||
.zoom(11)
|
||||
.tilt(25)
|
||||
.build());
|
||||
|
||||
mMapView = new MapView(this, mapboxMapOptions);
|
||||
((ViewGroup) findViewById(R.id.container)).addView(mMapView);
|
||||
|
||||
mMapView.onCreate(savedState);
|
||||
mMapView.getMapAsync(this);
|
||||
mMapView.onResume();
|
||||
mLocation = location;
|
||||
}
|
||||
if (mapboxMap != null && firstRun) {
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location), 10));
|
||||
firstRun = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(MapboxMap mapboxMap) {
|
||||
MyLocationViewSettings locationViewSettings = mapboxMap.getMyLocationViewSettings();
|
||||
|
||||
locationViewSettings.setBackgroundTintColor(Color.YELLOW);
|
||||
locationViewSettings.setBackgroundOffset(32, 32, 0, 0);
|
||||
|
||||
locationViewSettings.setForegroundTintColor(Color.GREEN);
|
||||
|
||||
locationViewSettings.setAccuracyTintColor(Color.RED);
|
||||
locationViewSettings.setAccuracyAlpha(100);
|
||||
}
|
||||
|
||||
private void showSnackBar() {
|
||||
String desc = "Loc Chg: ";
|
||||
boolean noInfo = true;
|
||||
if (mLocation.hasSpeed()) {
|
||||
desc += String.format("Spd = %.1f km/h ", mLocation.getSpeed() * 3.6f);
|
||||
noInfo = false;
|
||||
}
|
||||
if (mLocation.hasAltitude()) {
|
||||
desc += String.format("Alt = %.0f m ", mLocation.getAltitude());
|
||||
noInfo = false;
|
||||
}
|
||||
if (noInfo) {
|
||||
desc += "No extra info";
|
||||
}
|
||||
Snackbar.make(findViewById(android.R.id.content), desc, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (mMapView != null) {
|
||||
mMapView.onResume();
|
||||
}
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if (mMapView != null) {
|
||||
mMapView.onPause();
|
||||
}
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
if (mMapView != null) {
|
||||
mMapView.onSaveInstanceState(outState);
|
||||
}
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mMapView != null) {
|
||||
mMapView.onDestroy();
|
||||
}
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
if (mMapView != null) {
|
||||
mMapView.onLowMemory();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_tracking, menu);
|
||||
return true;
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,12 +122,6 @@ public class MyLocationCustomisationActivity extends AppCompatActivity implement
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
case R.id.action_toggle_dismissible_tracking:
|
||||
boolean state = !item.isChecked();
|
||||
mMapboxMap.getTrackingSettings().setDismissTrackingOnGesture(state);
|
||||
Toast.makeText(this, "Dismiss tracking mode on gesture = " + state, Toast.LENGTH_SHORT).show();
|
||||
item.setChecked(state);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
|
||||
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.location.LocationServices;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
@@ -28,6 +29,8 @@ import com.mapbox.mapboxsdk.maps.TrackingSettings;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class MyLocationTrackingModeActivity extends AppCompatActivity implements MapboxMap.OnMyLocationChangeListener, AdapterView.OnItemSelectedListener {
|
||||
|
||||
private MapView mMapView;
|
||||
@@ -58,7 +61,7 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements
|
||||
mMapboxMap = mapboxMap;
|
||||
|
||||
// disable dismissal when a gesture occurs
|
||||
mMapboxMap.getTrackingSettings().setDismissTrackingOnGesture(false);
|
||||
mMapboxMap.getTrackingSettings().setDismissLocationTrackingOnGesture(false);
|
||||
mMapboxMap.getTrackingSettings().setDismissBearingTrackingOnGesture(false);
|
||||
|
||||
mapboxMap.setOnMyLocationChangeListener(MyLocationTrackingModeActivity.this);
|
||||
@@ -75,7 +78,6 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements
|
||||
mBearingSpinner.setAdapter(bearingTrackingAdapter);
|
||||
mBearingSpinner.setOnItemSelectedListener(MyLocationTrackingModeActivity.this);
|
||||
|
||||
|
||||
mapboxMap.setOnMyLocationTrackingModeChangeListener(new MapboxMap.OnMyLocationTrackingModeChangeListener() {
|
||||
@Override
|
||||
public void onMyLocationTrackingModeChange(@MyLocationTracking.Mode int myLocationTrackingMode) {
|
||||
@@ -97,19 +99,29 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
mLocation = LocationServices.getLocationServices(MyLocationTrackingModeActivity.this).getLastLocation();
|
||||
if(mLocation!=null){
|
||||
setInitialPosition(new LatLng(mLocation));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setInitialPosition(LatLng latLng){
|
||||
mMapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 14));
|
||||
mMapboxMap.setMyLocationEnabled(true);
|
||||
mLocationSpinner.setEnabled(true);
|
||||
mBearingSpinner.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMyLocationChange(@Nullable Location location) {
|
||||
if (location != null) {
|
||||
if (mLocation == null) {
|
||||
// initial location to reposition map
|
||||
mMapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 14));
|
||||
mMapboxMap.setMyLocationEnabled(true);
|
||||
mLocationSpinner.setEnabled(true);
|
||||
mBearingSpinner.setEnabled(true);
|
||||
setInitialPosition(new LatLng(location));
|
||||
}
|
||||
mLocation = location;
|
||||
showSnackBar();
|
||||
@@ -120,15 +132,15 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements
|
||||
String desc = "Loc Chg: ";
|
||||
boolean noInfo = true;
|
||||
if (mLocation.hasSpeed()) {
|
||||
desc += String.format("Spd = %.1f km/h ", mLocation.getSpeed() * 3.6f);
|
||||
desc += String.format(Locale.getDefault(), "Spd = %.1f km/h ", mLocation.getSpeed() * 3.6f);
|
||||
noInfo = false;
|
||||
}
|
||||
if (mLocation.hasAltitude()) {
|
||||
desc += String.format("Alt = %.0f m ", mLocation.getAltitude());
|
||||
desc += String.format(Locale.getDefault(), "Alt = %.0f m ", mLocation.getAltitude());
|
||||
noInfo = false;
|
||||
}
|
||||
if(mLocation.hasAccuracy()){
|
||||
desc += String.format("Acc = %.0f m",mLocation.getAccuracy());
|
||||
if (mLocation.hasAccuracy()) {
|
||||
desc += String.format(Locale.getDefault(), "Acc = %.0f m", mLocation.getAccuracy());
|
||||
}
|
||||
|
||||
if (noInfo) {
|
||||
|
||||
@@ -42,6 +42,9 @@
|
||||
android:id="@+id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:my_location_foreground_tint="@color/primary"
|
||||
app:my_location_background_tint="@android:color/white"
|
||||
app:my_location_accuracy_tint="@color/primary"
|
||||
app:access_token="@string/mapbox_access_token"
|
||||
app:style_url="@string/style_mapbox_streets"
|
||||
app:zoom="15" />
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -167,6 +168,23 @@ public class MapboxMapOptionsTest {
|
||||
assertNull(new MapboxMapOptions().getCamera());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMyLocationForegroundTint() {
|
||||
assertEquals(Color.BLUE, new MapboxMapOptions().myLocationForegroundTintColor(Color.BLUE).getMyLocationForegroundTintColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMyLocationBackgroundTint() {
|
||||
assertEquals(Color.BLUE, new MapboxMapOptions().myLocationBackgroundTintColor(Color.BLUE).getMyLocationBackgroundTintColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParceable() {
|
||||
MapboxMapOptions options = new MapboxMapOptions().camera(new CameraPosition.Builder().build()).styleUrl("s").accessToken("a").debugActive(true).compassMargins(new int[]{0, 1, 2, 3});
|
||||
MapboxMapOptions parceled = (MapboxMapOptions) MockParcel.obtain(options);
|
||||
assertEquals(options, parceled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccessToken() {
|
||||
assertNull(new MapboxMapOptions().getAccessToken());
|
||||
|
||||
@@ -23,13 +23,13 @@ public class MyLocationViewSettingsTest {
|
||||
MapView mMapView = mock(MapView.class);
|
||||
|
||||
@InjectMocks
|
||||
UserLocationView userLocationView = mock(UserLocationView.class);
|
||||
MyLocationView myLocationView = mock(MyLocationView.class);
|
||||
|
||||
MyLocationViewSettings locationViewSettings;
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
locationViewSettings = new MyLocationViewSettings(mMapView, userLocationView);
|
||||
locationViewSettings = new MyLocationViewSettings(mMapView, myLocationView);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,6 +18,7 @@ import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyByte;
|
||||
import static org.mockito.Matchers.anyDouble;
|
||||
import static org.mockito.Matchers.anyFloat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
@@ -51,9 +52,8 @@ public class MockParcel {
|
||||
Method myMethod = creatorClass.getDeclaredMethod("createFromParcel", Parcel.class);
|
||||
return (Parcelable) myMethod.invoke(fieldValue, parcel);
|
||||
} catch (Exception e) {
|
||||
assertNotNull("Exception occurred:" + e.getLocalizedMessage(), null);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void testParcelableArray(@NonNull Parcelable object) {
|
||||
@@ -139,15 +139,39 @@ public class MockParcel {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Answer<Void> writeIntArrayAnswer = new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
int[] parameters = (int[]) invocation.getArguments()[0];
|
||||
if (parameters != null) {
|
||||
objects.add(parameters.length);
|
||||
for (Object o : parameters) {
|
||||
objects.add(o);
|
||||
}
|
||||
} else {
|
||||
objects.add(-1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
doAnswer(writeValueAnswer).when(mockedParcel).writeByte(anyByte());
|
||||
doAnswer(writeValueAnswer).when(mockedParcel).writeLong(anyLong());
|
||||
doAnswer(writeValueAnswer).when(mockedParcel).writeString(anyString());
|
||||
doAnswer(writeValueAnswer).when(mockedParcel).writeInt(anyInt());
|
||||
doAnswer(writeIntArrayAnswer).when(mockedParcel).writeIntArray(any(int[].class));
|
||||
doAnswer(writeValueAnswer).when(mockedParcel).writeDouble(anyDouble());
|
||||
doAnswer(writeValueAnswer).when(mockedParcel).writeFloat(anyFloat());
|
||||
doAnswer(writeValueAnswer).when(mockedParcel).writeParcelable(any(Parcelable.class), eq(0));
|
||||
doAnswer(writeArrayAnswer).when(mockedParcel).writeParcelableArray(any(Parcelable[].class), eq(0));
|
||||
}
|
||||
|
||||
private void setupReads() {
|
||||
when(mockedParcel.readInt()).then(new Answer<Integer>() {
|
||||
@Override
|
||||
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
||||
return (Integer) objects.get(position++);
|
||||
}
|
||||
});
|
||||
when(mockedParcel.readByte()).thenAnswer(new Answer<Byte>() {
|
||||
@Override
|
||||
public Byte answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -172,6 +196,12 @@ public class MockParcel {
|
||||
return (Double) objects.get(position++);
|
||||
}
|
||||
});
|
||||
when(mockedParcel.readFloat()).thenAnswer(new Answer<Float>() {
|
||||
@Override
|
||||
public Float answer(InvocationOnMock invocation) throws Throwable {
|
||||
return (Float) objects.get(position++);
|
||||
}
|
||||
});
|
||||
when(mockedParcel.readParcelable(Parcelable.class.getClassLoader())).thenAnswer(new Answer<Parcelable>() {
|
||||
@Override
|
||||
public Parcelable answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -194,6 +224,22 @@ public class MockParcel {
|
||||
return array;
|
||||
}
|
||||
});
|
||||
when(mockedParcel.createIntArray()).then(new Answer<int[]>() {
|
||||
@Override
|
||||
public int[] answer(InvocationOnMock invocation) throws Throwable {
|
||||
int size = (Integer) objects.get(position++);
|
||||
if (size == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int[] array = new int[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
array[i] = (Integer) objects.get(position++);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupOthers() {
|
||||
|
||||
Reference in New Issue
Block a user