[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{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user