[android] #4396 - fixup mason build issue
This commit is contained in:
@@ -79,7 +79,10 @@ import com.mapbox.mapboxsdk.exceptions.TelemetryServiceNotConfiguredException;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
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.MyLocationViewSettings;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.UserLocationView;
|
||||
import com.mapbox.mapboxsdk.telemetry.MapboxEvent;
|
||||
import com.mapbox.mapboxsdk.telemetry.MapboxEventManager;
|
||||
@@ -261,6 +264,7 @@ public class MapView extends FrameLayout {
|
||||
mMapboxMap.setStyleUrl(style);
|
||||
}
|
||||
|
||||
|
||||
mMapboxMap.setMyLocationEnabled(options.getLocationEnabled());
|
||||
|
||||
// Enable gestures
|
||||
@@ -592,6 +596,7 @@ public class MapView extends FrameLayout {
|
||||
mNativeMapView.setPitch(pitch, actualDuration);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Direction
|
||||
//
|
||||
@@ -1104,18 +1109,28 @@ public class MapView extends FrameLayout {
|
||||
return;
|
||||
}
|
||||
|
||||
if (left == mContentPaddingLeft && top == mContentPaddingTop && right == mContentPaddingRight && bottom == mContentPaddingBottom) {
|
||||
return;
|
||||
}
|
||||
// if (left == mContentPaddingLeft && top == mContentPaddingTop && right == mContentPaddingRight && bottom == mContentPaddingBottom) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
mContentPaddingLeft = left;
|
||||
mContentPaddingTop = top;
|
||||
mContentPaddingRight = right;
|
||||
mContentPaddingBottom = bottom;
|
||||
|
||||
int[] userLocationViewPadding = mMapboxMap.getMyLocationViewSettings().getPadding();
|
||||
left += userLocationViewPadding[0];
|
||||
top += userLocationViewPadding[1];
|
||||
right += userLocationViewPadding[2];
|
||||
bottom += userLocationViewPadding[3];
|
||||
|
||||
mNativeMapView.setContentPadding(top / mScreenDensity, left / mScreenDensity, bottom / mScreenDensity, right / mScreenDensity);
|
||||
}
|
||||
|
||||
public void invalidateContentPadding() {
|
||||
setContentPadding(mContentPaddingLeft, mContentPaddingTop, mContentPaddingRight, mContentPaddingBottom);
|
||||
}
|
||||
|
||||
double getMetersPerPixelAtLatitude(@FloatRange(from = -180, to = 180) double latitude) {
|
||||
if (mDestroyed) {
|
||||
return 0;
|
||||
@@ -1544,11 +1559,7 @@ public class MapView extends FrameLayout {
|
||||
zoom(true, e.getX(), e.getY());
|
||||
} else {
|
||||
// Zoom in on user location view
|
||||
|
||||
// TODO fix padding issue
|
||||
// PointF centerPoint = mUserLocationView.getMarkerScreenPoint();
|
||||
// zoom(true, centerPoint.x, centerPoint.y);
|
||||
zoom(true, getWidth() / 2, getHeight() / 2);
|
||||
zoom(true, mUserLocationView.getCenterX(), mUserLocationView.getCenterY());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -2334,8 +2345,13 @@ public class MapView extends FrameLayout {
|
||||
return mUserLocationView.getLocation();
|
||||
}
|
||||
|
||||
void setOnMyLocationChangeListener(@Nullable MapboxMap.OnMyLocationChangeListener listener) {
|
||||
mUserLocationView.setOnMyLocationChangeListener(listener);
|
||||
void setOnMyLocationChangeListener(@Nullable final MapboxMap.OnMyLocationChangeListener listener) {
|
||||
LocationServices.getLocationServices(getContext()).addLocationListener(new LocationListener() {
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
listener.onMyLocationChange(location);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
|
||||
@@ -2491,6 +2507,10 @@ public class MapView extends FrameLayout {
|
||||
mMapboxMap = mapboxMap;
|
||||
}
|
||||
|
||||
UserLocationView getUserLocationView() {
|
||||
return mUserLocationView;
|
||||
}
|
||||
|
||||
@UiThread
|
||||
void snapshot(@NonNull final MapboxMap.SnapshotReadyCallback callback, @Nullable final Bitmap bitmap) {
|
||||
final TextureView textureView = (TextureView) findViewById(R.id.textureView);
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.mapbox.mapboxsdk.constants.MyLocationTracking;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.layers.CustomLayer;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -51,6 +52,7 @@ public class MapboxMap {
|
||||
private MapView mMapView;
|
||||
private UiSettings mUiSettings;
|
||||
private TrackingSettings mTrackingSettings;
|
||||
private MyLocationViewSettings myLocationViewSettings;
|
||||
private Projection mProjection;
|
||||
private CameraPosition mCameraPosition;
|
||||
private boolean mInvalidCameraPosition;
|
||||
@@ -187,6 +189,20 @@ public class MapboxMap {
|
||||
return mTrackingSettings;
|
||||
}
|
||||
|
||||
//
|
||||
// MyLocationViewSettings
|
||||
//
|
||||
|
||||
/**
|
||||
* Gets the settings of the user location for the map.
|
||||
*/
|
||||
public MyLocationViewSettings getMyLocationViewSettings() {
|
||||
if (myLocationViewSettings == null) {
|
||||
myLocationViewSettings = new MyLocationViewSettings(mMapView);
|
||||
}
|
||||
return myLocationViewSettings;
|
||||
}
|
||||
|
||||
//
|
||||
// Projection
|
||||
//
|
||||
@@ -727,7 +743,7 @@ public class MapboxMap {
|
||||
Polyline polyline;
|
||||
List<Polyline> polylines = new ArrayList<>(count);
|
||||
|
||||
if(count>0) {
|
||||
if (count > 0) {
|
||||
for (PolylineOptions options : polylineOptionsList) {
|
||||
polyline = options.getPolyline();
|
||||
if (!polyline.getPoints().isEmpty()) {
|
||||
@@ -791,7 +807,7 @@ public class MapboxMap {
|
||||
|
||||
Polygon polygon;
|
||||
List<Polygon> polygons = new ArrayList<>(count);
|
||||
if(count>0) {
|
||||
if (count > 0) {
|
||||
for (PolygonOptions polygonOptions : polygonOptionsList) {
|
||||
polygon = polygonOptions.getPolygon();
|
||||
if (!polygon.getPoints().isEmpty()) {
|
||||
@@ -802,7 +818,7 @@ public class MapboxMap {
|
||||
long[] ids = mMapView.addPolygons(polygons);
|
||||
|
||||
// if unit tests or polygons correcly added to map
|
||||
if(ids==null || ids.length==polygons.size()) {
|
||||
if (ids == null || ids.length == polygons.size()) {
|
||||
long id = 0;
|
||||
for (int i = 0; i < polygons.size(); i++) {
|
||||
polygon = polygons.get(i);
|
||||
@@ -931,7 +947,7 @@ public class MapboxMap {
|
||||
* Removes all markers, polylines, polygons, overlays, etc from the map.
|
||||
*/
|
||||
@UiThread
|
||||
public void clear(){
|
||||
public void clear() {
|
||||
removeAnnotations();
|
||||
}
|
||||
|
||||
@@ -1491,11 +1507,11 @@ public class MapboxMap {
|
||||
return mMapView;
|
||||
}
|
||||
|
||||
void setUiSettings(UiSettings uiSettings){
|
||||
void setUiSettings(UiSettings uiSettings) {
|
||||
mUiSettings = uiSettings;
|
||||
}
|
||||
|
||||
void setProjection(Projection projection){
|
||||
void setProjection(Projection projection) {
|
||||
mProjection = projection;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import android.support.annotation.UiThread;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
|
||||
|
||||
/**
|
||||
* Settings for the user interface of a MapboxMap. To obtain this interface, call getUiSettings().
|
||||
*/
|
||||
@@ -12,6 +14,7 @@ public class UiSettings {
|
||||
|
||||
private MapView mapView;
|
||||
|
||||
private MyLocationViewSettings myLocationViewSettings;
|
||||
private ViewSettings compassSettings;
|
||||
private ViewSettings logoSettings;
|
||||
private ViewSettings attributionSettings;
|
||||
@@ -544,4 +547,12 @@ public class UiSettings {
|
||||
mapView.setCompassMargins(getCompassMarginLeft(), getCompassMarginTop(), getCompassMarginRight(), getCompassMarginBottom());
|
||||
mapView.setAttributionMargins(getAttributionMarginLeft(), getAttributionMarginTop(), getAttributionMarginRight(), getAttributionMarginBottom());
|
||||
}
|
||||
|
||||
public MyLocationViewSettings getMyLocationViewSettings() {
|
||||
return myLocationViewSettings;
|
||||
}
|
||||
|
||||
public void setMyLocationViewSettings(MyLocationViewSettings myLocationViewSettings) {
|
||||
this.myLocationViewSettings = myLocationViewSettings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
package com.mapbox.mapboxsdk.maps.widgets;
|
||||
|
||||
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;
|
||||
|
||||
//
|
||||
// State
|
||||
//
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
//
|
||||
// Foreground
|
||||
//
|
||||
|
||||
private Drawable foregroundDrawable;
|
||||
private Drawable foregroundBearingDrawable;
|
||||
|
||||
@ColorInt
|
||||
private int foregroundTintColor;
|
||||
|
||||
//
|
||||
// Background
|
||||
//
|
||||
|
||||
private Drawable backgroundDrawable;
|
||||
private int[] backgroundOffset = new int[4];
|
||||
|
||||
@ColorInt
|
||||
private int backgroundTintColor;
|
||||
|
||||
//
|
||||
// Accuracy
|
||||
//
|
||||
|
||||
private int arruracyAlpha;
|
||||
|
||||
@ColorInt
|
||||
private int accuracyTintColor;
|
||||
|
||||
//
|
||||
// Padding
|
||||
//
|
||||
|
||||
private int[] padding = new int[4];
|
||||
|
||||
public MyLocationViewSettings(MapView mapView) {
|
||||
this.mapView = mapView;
|
||||
this.userLocationView = (UserLocationView) mapView.findViewById(R.id.userLocationView);
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
userLocationView.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public void setForegroundDrawable(Drawable foregroundDrawable, Drawable foregroundBearingDrawable) {
|
||||
this.foregroundDrawable = foregroundDrawable;
|
||||
this.foregroundBearingDrawable = foregroundBearingDrawable;
|
||||
userLocationView.setForegroundDrawables(foregroundDrawable, foregroundBearingDrawable);
|
||||
}
|
||||
|
||||
public Drawable getForegroundDrawable() {
|
||||
return foregroundDrawable;
|
||||
}
|
||||
|
||||
public Drawable getForegroundBearingDrawable() {
|
||||
return foregroundBearingDrawable;
|
||||
}
|
||||
|
||||
public void setForegroundTintColor(@ColorInt int foregroundTintColor) {
|
||||
this.foregroundTintColor = foregroundTintColor;
|
||||
userLocationView.setForegroundDrawableTint(foregroundTintColor);
|
||||
}
|
||||
|
||||
public int getForegroundTintColor() {
|
||||
return foregroundTintColor;
|
||||
}
|
||||
|
||||
public void setBackgroundDrawable(Drawable backgroundDrawable) {
|
||||
this.backgroundDrawable = backgroundDrawable;
|
||||
userLocationView.setShadowDrawable(backgroundDrawable);
|
||||
}
|
||||
|
||||
public Drawable getBackgroundDrawable() {
|
||||
return backgroundDrawable;
|
||||
}
|
||||
|
||||
public void setBackgroundTintColor(@ColorInt int backgroundTintColor) {
|
||||
this.backgroundTintColor = backgroundTintColor;
|
||||
userLocationView.setShadowDrawableTint(backgroundTintColor);
|
||||
}
|
||||
|
||||
public int getBackgroundTintColor() {
|
||||
return backgroundTintColor;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public int[] getBackgroundOffset() {
|
||||
return backgroundOffset;
|
||||
}
|
||||
|
||||
public void setPadding(int left, int top, int right, int bottom) {
|
||||
padding = new int[]{left, top, right, bottom};
|
||||
userLocationView.setContentPadding(padding);
|
||||
mapView.invalidateContentPadding();
|
||||
}
|
||||
|
||||
public int[] getPadding() {
|
||||
return padding;
|
||||
}
|
||||
|
||||
public int getAccuracyAlpha() {
|
||||
return arruracyAlpha;
|
||||
}
|
||||
|
||||
public void setAccuracyAlpha(@IntRange(from = 0, to = 255) int arruracyAlpha) {
|
||||
this.arruracyAlpha = arruracyAlpha;
|
||||
userLocationView.setAccuracyAlpha(arruracyAlpha);
|
||||
}
|
||||
|
||||
public int getAccuracyTintColor() {
|
||||
return accuracyTintColor;
|
||||
}
|
||||
|
||||
public void setAccuracyTintColor(@ColorInt int accuracyTintColor) {
|
||||
this.accuracyTintColor = accuracyTintColor;
|
||||
userLocationView.setAccuracyTint(accuracyTintColor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.mapbox.mapboxsdk.maps.widgets;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
@@ -19,10 +21,11 @@ import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.FloatRange;
|
||||
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.View;
|
||||
import android.view.animation.Animation;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
@@ -41,7 +44,7 @@ import java.lang.ref.WeakReference;
|
||||
/**
|
||||
* UI element overlaid on a map to show the user's location.
|
||||
*/
|
||||
public final class UserLocationView extends View {
|
||||
public class UserLocationView extends View {
|
||||
|
||||
private LatLng latLng;
|
||||
private float gpsDirection;
|
||||
@@ -51,6 +54,8 @@ public final class UserLocationView extends View {
|
||||
private Drawable foregroundBearingDrawable;
|
||||
private Drawable backgroundDrawable;
|
||||
|
||||
private int[] contentPadding = new int[4];
|
||||
|
||||
private MyBearingListener mBearingChangeListener;
|
||||
|
||||
// Accuracy
|
||||
@@ -80,7 +85,15 @@ public final class UserLocationView extends View {
|
||||
private Location location;
|
||||
private UserLocationListener userLocationListener;
|
||||
|
||||
private ValueAnimator LocationChangeAnimator;
|
||||
private ValueAnimator locationChangeAnimator;
|
||||
private MarkerCoordinateAnimatorListener markerCoordinateAnimatorListener;
|
||||
public LatLng interpolatedLocation;
|
||||
public LatLng previousLocation;
|
||||
|
||||
private float previousDirection;
|
||||
|
||||
private long locationUpdateTimestamp;
|
||||
private long locationUpdateDuration;
|
||||
|
||||
public UserLocationView(Context context) {
|
||||
super(context);
|
||||
@@ -101,13 +114,11 @@ public final class UserLocationView extends View {
|
||||
setEnabled(false);
|
||||
|
||||
userLocationBehaviour = new UserLocationBehaviourFactory().getBehaviouralModel(MyLocationTracking.TRACKING_NONE);
|
||||
|
||||
LocationChangeAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
|
||||
LocationChangeAnimator.setDuration(1000);
|
||||
markerCoordinateAnimatorListener = new MarkerCoordinateAnimatorListener(userLocationBehaviour);
|
||||
|
||||
accuracyPaint = new Paint();
|
||||
accuracyPaint.setColor(ContextCompat.getColor(context, R.color.mapbox_blue));
|
||||
accuracyPaint.setAlpha(80);
|
||||
accuracyPaint.setAlpha(100);
|
||||
|
||||
setShadowDrawable(ContextCompat.getDrawable(context, R.drawable.ic_userlocationview_shadow));
|
||||
setForegroundDrawables(ContextCompat.getDrawable(context, R.drawable.ic_userlocationview_normal), ContextCompat.getDrawable(context, R.drawable.ic_userlocationview_bearing));
|
||||
@@ -153,8 +164,11 @@ public final class UserLocationView extends View {
|
||||
backgroundDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
|
||||
public final void setAccurancyTint(@ColorInt int color, @IntRange(from = 0, to = 100) int alpha) {
|
||||
public final void setAccuracyTint(@ColorInt int color) {
|
||||
accuracyPaint.setColor(color);
|
||||
}
|
||||
|
||||
public final void setAccuracyAlpha(@IntRange(from = 0, to = 255) int alpha) {
|
||||
accuracyPaint.setAlpha(alpha);
|
||||
}
|
||||
|
||||
@@ -256,7 +270,7 @@ public final class UserLocationView extends View {
|
||||
}
|
||||
|
||||
void updateOnNextFrame() {
|
||||
// mapboxMap.invalidate();
|
||||
mapboxMap.invalidate();
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
@@ -299,12 +313,11 @@ public final class UserLocationView extends View {
|
||||
* @param enableGps true if GPS is to be enabled, false if GPS is to be disabled
|
||||
*/
|
||||
private void toggleGps(boolean enableGps) {
|
||||
|
||||
LocationServices locationServices = LocationServices.getLocationServices(getContext());
|
||||
|
||||
if (enableGps) {
|
||||
// Set an initial location if one available
|
||||
Location lastLocation = locationServices.getLastLocation();
|
||||
|
||||
if (lastLocation != null) {
|
||||
location = lastLocation;
|
||||
}
|
||||
@@ -313,13 +326,10 @@ public final class UserLocationView extends View {
|
||||
userLocationListener = new UserLocationListener(this);
|
||||
}
|
||||
|
||||
// Register for Location Updates
|
||||
locationServices.addLocationListener(userLocationListener);
|
||||
} else {
|
||||
// Disable location and user dot
|
||||
location = null;
|
||||
|
||||
// Deregister for Location Updates
|
||||
locationServices.removeLocationListener(userLocationListener);
|
||||
}
|
||||
|
||||
@@ -340,12 +350,6 @@ public final class UserLocationView extends View {
|
||||
userLocationBehaviour.update(location);
|
||||
}
|
||||
|
||||
public void setOnMyLocationChangeListener(@Nullable MapboxMap.OnMyLocationChangeListener listener) {
|
||||
// todo deprecate this
|
||||
// onMyLocationChangeListener = listener;
|
||||
}
|
||||
|
||||
|
||||
public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) {
|
||||
this.myBearingTrackingMode = myBearingTrackingMode;
|
||||
if (myBearingTrackingMode == MyBearingTracking.COMPASS) {
|
||||
@@ -377,8 +381,6 @@ public final class UserLocationView extends View {
|
||||
|
||||
private void setCompass(float bearing) {
|
||||
if (myLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
|
||||
// // animate marker
|
||||
//// showDirection = true;
|
||||
float oldDir = compassDirection;
|
||||
float newDir = bearing;
|
||||
float diff = oldDir - newDir;
|
||||
@@ -389,21 +391,21 @@ public final class UserLocationView extends View {
|
||||
}
|
||||
compassDirection = newDir;
|
||||
invalidate();
|
||||
|
||||
} else if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
|
||||
// cancelAnimations();
|
||||
// if (myBearingTrackingMode == MyBearingTracking.COMPASS) {
|
||||
// // always show north & change map gpsDirection
|
||||
// showDirection = true;
|
||||
// gpsDirection = 0;
|
||||
// compassDirection = 0;
|
||||
// update();
|
||||
// }
|
||||
} else {
|
||||
// showDirection = false;
|
||||
}
|
||||
}
|
||||
|
||||
public float getCenterX() {
|
||||
return getX() + getMeasuredWidth() / 2;
|
||||
}
|
||||
|
||||
public float getCenterY() {
|
||||
return getY() + getMeasuredHeight() / 2;
|
||||
}
|
||||
|
||||
public void setContentPadding(int[] padding) {
|
||||
contentPadding = padding;
|
||||
}
|
||||
|
||||
private static class UserLocationListener implements LocationListener {
|
||||
|
||||
private WeakReference<UserLocationView> mUserLocationView;
|
||||
@@ -466,10 +468,6 @@ public final class UserLocationView extends View {
|
||||
mSensorManager.unregisterListener(this, mMagnetometer);
|
||||
}
|
||||
|
||||
public float getCompassBearing() {
|
||||
return mCurrentDegree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
if (paused) {
|
||||
@@ -522,12 +520,11 @@ public final class UserLocationView extends View {
|
||||
private double mToLat;
|
||||
private double mToLng;
|
||||
|
||||
private MarkerCoordinateAnimatorListener(UserLocationBehaviour behaviour, LatLng from, LatLng to) {
|
||||
private double mCurrentLat;
|
||||
private double mCurrentLon;
|
||||
|
||||
private MarkerCoordinateAnimatorListener(UserLocationBehaviour behaviour) {
|
||||
this.behaviour = behaviour;
|
||||
mFromLat = from.getLatitude();
|
||||
mFromLng = from.getLongitude();
|
||||
mToLat = to.getLatitude();
|
||||
mToLng = to.getLongitude();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -536,8 +533,21 @@ public final class UserLocationView extends View {
|
||||
double latitude = mFromLat + (mToLat - mFromLat) * frac;
|
||||
double longitude = mFromLng + (mToLng - mFromLng) * frac;
|
||||
behaviour.update(latitude, longitude);
|
||||
mCurrentLat = latitude;
|
||||
mCurrentLon = longitude;
|
||||
updateOnNextFrame();
|
||||
}
|
||||
|
||||
public LatLng getLatLng() {
|
||||
return new LatLng(mCurrentLat, mCurrentLon);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
mFromLat = mCurrentLat;
|
||||
mFromLng = mCurrentLon;
|
||||
mToLat = interpolatedLocation.getLatitude();
|
||||
mToLng = interpolatedLocation.getLongitude();
|
||||
}
|
||||
}
|
||||
|
||||
private class UserLocationBehaviourFactory {
|
||||
@@ -556,52 +566,139 @@ public final class UserLocationView extends View {
|
||||
abstract void update(@NonNull Location location);
|
||||
|
||||
public void update(double lat, double lon) {
|
||||
latLng.setLatitude(lat);
|
||||
latLng.setLongitude(lon);
|
||||
if (latLng != null) {
|
||||
latLng.setLatitude(lat);
|
||||
latLng.setLongitude(lon);
|
||||
}
|
||||
}
|
||||
|
||||
abstract void invalidate();
|
||||
|
||||
}
|
||||
|
||||
private class UserLocationTrackingBehaviour extends UserLocationBehaviour {
|
||||
|
||||
@Override
|
||||
void update(@NonNull Location location) {
|
||||
if (latLng == null || !latLng.equals(new LatLng(location))) {
|
||||
if (latLng == null) {
|
||||
// first location fix
|
||||
latLng = new LatLng(location);
|
||||
CameraPosition.Builder builder = new CameraPosition.Builder().target(latLng);
|
||||
if (myBearingTrackingMode != MyBearingTracking.NONE && location.hasBearing()) {
|
||||
builder.bearing(location.getBearing());
|
||||
}
|
||||
|
||||
if (location.hasAccuracy()) {
|
||||
accuracy = location.getAccuracy();
|
||||
}
|
||||
|
||||
gpsDirection = 0;
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), 300, null);
|
||||
locationUpdateTimestamp = SystemClock.elapsedRealtime();
|
||||
return;
|
||||
}
|
||||
|
||||
// update timestamp
|
||||
long previousUpdateTimeStamp = locationUpdateTimestamp;
|
||||
locationUpdateTimestamp = SystemClock.elapsedRealtime();
|
||||
|
||||
// calculate animation duration
|
||||
long locationUpdateDuration;
|
||||
if (previousUpdateTimeStamp == 0) {
|
||||
locationUpdateDuration = 0;
|
||||
} else {
|
||||
// TODO remove 10 * hack to multiply duration to workaround easing interpolation (easeCamera)
|
||||
locationUpdateDuration = 10 * (locationUpdateTimestamp - previousUpdateTimeStamp);
|
||||
}
|
||||
|
||||
// calculate interpolated location
|
||||
previousLocation = latLng;
|
||||
latLng = new LatLng(location);
|
||||
interpolatedLocation = new LatLng((latLng.getLatitude() + previousLocation.getLatitude()) / 2, (latLng.getLongitude() + previousLocation.getLongitude()) / 2);
|
||||
|
||||
// build new camera
|
||||
CameraPosition.Builder builder = new CameraPosition.Builder().target(interpolatedLocation);
|
||||
|
||||
// add direction
|
||||
if (myBearingTrackingMode == MyBearingTracking.GPS){
|
||||
if(location.hasBearing()) {
|
||||
builder.bearing(location.getBearing());
|
||||
gpsDirection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// add accuracy
|
||||
if (location.hasAccuracy()) {
|
||||
accuracy = location.getAccuracy();
|
||||
}
|
||||
|
||||
// animate to new camera
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), (int) locationUpdateDuration, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
void invalidate() {
|
||||
int[] contentPadding = mapboxMap.getPadding();
|
||||
int[] mapPadding = mapboxMap.getPadding();
|
||||
UiSettings uiSettings = mapboxMap.getUiSettings();
|
||||
// screenLocation = new PointF(x, y);
|
||||
setX((uiSettings.getWidth() - getWidth() + contentPadding[0] - contentPadding[2]) / 2);
|
||||
setY((uiSettings.getHeight() - getHeight() - contentPadding[3] + contentPadding[1]) / 2);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private class UserLocationShowBehaviour extends UserLocationBehaviour {
|
||||
|
||||
private float previousDirection;
|
||||
|
||||
@Override
|
||||
void update(@NonNull Location location) {
|
||||
LatLng previousCoordinate = ((latLng == null) ? new LatLng(location) : latLng);
|
||||
void update(@NonNull final Location location) {
|
||||
|
||||
if (latLng == null) {
|
||||
// first location update
|
||||
latLng = new LatLng(location);
|
||||
locationUpdateTimestamp = SystemClock.elapsedRealtime();
|
||||
return;
|
||||
}
|
||||
|
||||
// update location
|
||||
previousLocation = latLng;
|
||||
latLng = new LatLng(location);
|
||||
|
||||
// calculate update time
|
||||
long previousUpdateTimeStamp = locationUpdateTimestamp;
|
||||
locationUpdateTimestamp = SystemClock.elapsedRealtime();
|
||||
locationUpdateDuration = locationUpdateTimestamp - previousUpdateTimeStamp;
|
||||
|
||||
// calculate interpolated entity
|
||||
interpolatedLocation = new LatLng((latLng.getLatitude() + previousLocation.getLatitude()) / 2, (latLng.getLongitude() + previousLocation.getLongitude()) / 2);
|
||||
|
||||
Log.v("TAG", "LOCATIONS " + previousLocation + " " + interpolatedLocation);
|
||||
|
||||
|
||||
if (locationChangeAnimator == null) {
|
||||
Log.v("TAG", "START");
|
||||
locationChangeAnimator = ValueAnimator.ofFloat(1.0f);
|
||||
// locationChangeAnimator.setRepeatMode(ValueAnimator.RESTART);
|
||||
// locationChangeAnimator.setRepeatCount(ValueAnimator.INFINITE);
|
||||
locationChangeAnimator.setDuration(locationUpdateDuration + 500);
|
||||
|
||||
markerCoordinateAnimatorListener = new MarkerCoordinateAnimatorListener(this);
|
||||
markerCoordinateAnimatorListener.update();
|
||||
locationChangeAnimator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
super.onAnimationEnd(animation);
|
||||
Log.v("TAG", "END");
|
||||
markerCoordinateAnimatorListener.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
super.onAnimationRepeat(animation);
|
||||
Log.v("TAG", "REPEAT@");
|
||||
markerCoordinateAnimatorListener.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
super.onAnimationStart(animation);
|
||||
Log.v("TAG","START");
|
||||
}
|
||||
});
|
||||
locationChangeAnimator.addUpdateListener(markerCoordinateAnimatorListener);
|
||||
} else {
|
||||
Log.v("TAG", "CONTINUE");
|
||||
markerCoordinateAnimatorListener.update();
|
||||
// long currentPlayTime = locationChangeAnimator.getCurrentPlayTime();
|
||||
// locationChangeAnimator.setDuration(locationChangeAnimator.getDuration()+locationUpdateTimestamp);
|
||||
// locationChangeAnimator.setCurrentPlayTime(currentPlayTime);
|
||||
}
|
||||
|
||||
if (location.hasBearing()) {
|
||||
gpsDirection = clamp(location.getBearing() - (float) mapboxMap.getCameraPosition().bearing);
|
||||
}
|
||||
@@ -610,8 +707,10 @@ public final class UserLocationView extends View {
|
||||
accuracy = location.getAccuracy();
|
||||
}
|
||||
|
||||
LocationChangeAnimator.addUpdateListener(new MarkerCoordinateAnimatorListener(this, previousCoordinate, latLng));
|
||||
LocationChangeAnimator.start();
|
||||
if (!locationChangeAnimator.isRunning()) {
|
||||
locationChangeAnimator.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private float clamp(float direction) {
|
||||
@@ -629,10 +728,13 @@ public final class UserLocationView extends View {
|
||||
void invalidate() {
|
||||
PointF screenLocation = projection.toScreenLocation(latLng);
|
||||
if (screenLocation != null) {
|
||||
setX(screenLocation.x - getWidth() / 2);
|
||||
setY(screenLocation.y - getHeight() / 2);
|
||||
setX((screenLocation.x - getWidth() / 2));
|
||||
setY((screenLocation.y - getHeight() / 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Anim extends Animation{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,18 @@
|
||||
<attr name="style_url" format="string" />
|
||||
<attr name="access_token" format="string" />
|
||||
<attr name="style_classes" format="string" />
|
||||
|
||||
<!-- My Location-->
|
||||
<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_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" />
|
||||
|
||||
<!-- Compass -->
|
||||
<attr name="compass_enabled" format="boolean" />
|
||||
<attr name="compass_gravity">
|
||||
<flag name="top" value="0x30" />
|
||||
|
||||
@@ -121,9 +121,10 @@
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_camera" />
|
||||
</activity>
|
||||
<activity android:name=".activity.customlayer.CustomLayerActivity"
|
||||
android:description="@string/description_custom_layer"
|
||||
android:label="@string/activity_custom_layer">
|
||||
<activity
|
||||
android:name=".activity.customlayer.CustomLayerActivity"
|
||||
android:description="@string/description_custom_layer"
|
||||
android:label="@string/activity_custom_layer">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_custom_layer" />
|
||||
@@ -136,6 +137,14 @@
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_userlocation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.userlocation.MyLocationCustomisationActivity"
|
||||
android:description="@string/description_user_location_customization"
|
||||
android:label="@string/activity_user_tracking_mode">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_userlocation" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.PolygonActivity"
|
||||
android:description="@string/description_polygon"
|
||||
@@ -192,7 +201,7 @@
|
||||
android:label="@string/activity_debug_mode">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_maplayout"/>
|
||||
android:value="@string/category_maplayout" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.offline.OfflineActivity"
|
||||
|
||||
@@ -6,8 +6,10 @@ import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
@@ -120,7 +122,7 @@ public class FeatureOverviewActivity extends AppCompatActivity {
|
||||
for (ActivityInfo info : app.activities) {
|
||||
if (info.name.startsWith(packageName) && !info.name.equals(FeatureOverviewActivity.class.getName())) {
|
||||
String label = getString(info.labelRes);
|
||||
String description = getString(info.descriptionRes);
|
||||
String description = resolveString(info.descriptionRes);
|
||||
String category = resolveMetaData(info.metaData, metaDataKey);
|
||||
features.add(new Feature(info.name, label, description, category));
|
||||
}
|
||||
@@ -147,6 +149,14 @@ public class FeatureOverviewActivity extends AppCompatActivity {
|
||||
return category;
|
||||
}
|
||||
|
||||
private String resolveString(@StringRes int stringRes){
|
||||
try{
|
||||
return getString(stringRes);
|
||||
}catch (Resources.NotFoundException e){
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<Feature> features) {
|
||||
super.onPostExecute(features);
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.userlocation;
|
||||
|
||||
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.constants.Style;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.location.LocationListener;
|
||||
import com.mapbox.mapboxsdk.location.LocationServices;
|
||||
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 {
|
||||
|
||||
private MapView mMapView;
|
||||
private MapboxMap mMapboxMap;
|
||||
private Location mLocation;
|
||||
|
||||
private Bundle savedState;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_my_location_customisation);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
savedState = savedInstanceState;
|
||||
|
||||
LocationServices locationServices = LocationServices.getLocationServices(this);
|
||||
locationServices.addLocationListener(this);
|
||||
locationServices.toggleGPS(true);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if (mMapView != null) {
|
||||
mMapView.onPause();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
if (mMapView != null) {
|
||||
mMapView.onSaveInstanceState(outState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mMapView != null) {
|
||||
mMapView.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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.TrackingSettings;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
public class MyLocationTrackingModeActivity extends AppCompatActivity implements MapboxMap.OnMyLocationChangeListener, AdapterView.OnItemSelectedListener {
|
||||
@@ -56,6 +57,9 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
mMapboxMap = mapboxMap;
|
||||
|
||||
MyLocationViewSettings locationViewSettings = mapboxMap.getMyLocationViewSettings();
|
||||
locationViewSettings.setPadding(0, (int) getResources().getDimension(R.dimen.locationview_padding_top), 0, 0);
|
||||
|
||||
mapboxMap.setOnMyLocationChangeListener(MyLocationTrackingModeActivity.this);
|
||||
|
||||
ArrayAdapter<CharSequence> locationTrackingAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(), R.array.user_tracking_mode, android.R.layout.simple_spinner_item);
|
||||
@@ -70,14 +74,6 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements
|
||||
mBearingSpinner.setAdapter(bearingTrackingAdapter);
|
||||
mBearingSpinner.setOnItemSelectedListener(MyLocationTrackingModeActivity.this);
|
||||
|
||||
try {
|
||||
mapboxMap.setMyLocationEnabled(true);
|
||||
} catch (SecurityException e) {
|
||||
//should not occur, permission was checked in FeatureOverviewActivity
|
||||
Toast.makeText(MyLocationTrackingModeActivity.this,
|
||||
"Location permission is not available", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
|
||||
mapboxMap.setOnMyLocationTrackingModeChangeListener(new MapboxMap.OnMyLocationTrackingModeChangeListener() {
|
||||
@Override
|
||||
@@ -110,6 +106,7 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="@color/primary"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@id/progress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v4.widget.ContentLoadingProgressBar
|
||||
style="?android:attr/progressBarStyleLarge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@@ -7,4 +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_padding_top">350dp</dimen>
|
||||
</resources>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<resources>
|
||||
<item name="mapView" type="id" />
|
||||
<item name="fab" type="id" />
|
||||
<item name="progress" type="id" />
|
||||
<item name="imageView" type="id" />
|
||||
<item name="toolbar" type="id" />
|
||||
<item name="container" type="id" />
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
<string name="activity_double_map">Double Map Activity</string>
|
||||
<string name="activity_snapshot">Snapshot Activity</string>
|
||||
<string name="activity_user_tracking_mode">User tracking mode</string>
|
||||
<string name="activity_user_tracking_customization">User location customization</string>
|
||||
<string name="activity_custom_layer">Custom Layer</string>
|
||||
<string name="activity_map_padding">Map Padding</string>
|
||||
<string name="activity_debug_mode">Debug Mode</string>
|
||||
@@ -44,6 +45,7 @@
|
||||
|
||||
<!-- Description -->
|
||||
<string name="description_user_location_tracking">Tracks the location of the user</string>
|
||||
<string name="description_user_location_customization">Customize the location of the user</string>
|
||||
<string name="description_custom_layer">Overlay a custom native layer on the map</string>
|
||||
<string name="description_info_window_adapter">Learn how to create a custom InfoWindow</string>
|
||||
<string name="description_cameraposition">CameraPosition capabilities</string>
|
||||
|
||||
@@ -166,5 +166,6 @@ public class MapboxMapOptionsTest {
|
||||
assertEquals("test", new MapboxMapOptions().accessToken("test").getAccessToken());
|
||||
assertNotEquals("nottest", new MapboxMapOptions().accessToken("test").getStyle());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.mapbox.mapboxsdk.maps.widgets;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class MyLocationViewSettingsTest {
|
||||
|
||||
@InjectMocks
|
||||
MapView mMapView = mock(MapView.class);
|
||||
|
||||
@InjectMocks
|
||||
UserLocationView userLocationView = mock(UserLocationView.class);
|
||||
|
||||
MyLocationViewSettings locationViewSettings;
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
locationViewSettings = new MyLocationViewSettings(mMapView, userLocationView);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
assertNotNull("should not be null", locationViewSettings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForegroundDrawables() {
|
||||
Drawable foregroundDrawable = mock(Drawable.class);
|
||||
Drawable foregroundBearingDrawable = mock(Drawable.class);
|
||||
locationViewSettings.setForegroundDrawable(foregroundDrawable, foregroundBearingDrawable);
|
||||
assertEquals("foreground should match", foregroundDrawable, locationViewSettings.getForegroundDrawable());
|
||||
assertEquals("foreground bearing should match", foregroundBearingDrawable, locationViewSettings.getForegroundBearingDrawable());
|
||||
}
|
||||
|
||||
@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);
|
||||
assertTrue("offsets should match", Arrays.equals(offset, locationViewSettings.getBackgroundOffset()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForegroundTint() {
|
||||
int color = Color.RED;
|
||||
locationViewSettings.setForegroundTintColor(Color.RED);
|
||||
assertEquals("color should match", color, locationViewSettings.getForegroundTintColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackgroundTint(){
|
||||
int color = Color.RED;
|
||||
locationViewSettings.setBackgroundTintColor(Color.RED);
|
||||
assertEquals("color should match", color, locationViewSettings.getBackgroundTintColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnabled() {
|
||||
assertFalse("initial state should be false", locationViewSettings.isEnabled());
|
||||
locationViewSettings.setEnabled(true);
|
||||
assertTrue("state should be true", locationViewSettings.isEnabled());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user