summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2016-04-25 12:31:07 +0200
committerTobrun <tobrun@mapbox.com>2016-04-26 22:24:17 +0200
commite2510fce79d9a90bad71bcfc5a73c248a9c7c3d1 (patch)
tree92b6a4bba2516a4accf686b7f849b8905c30097d /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps
parentba9703351d6bfc9bfa9bcf54553d62961e42c723 (diff)
downloadqtlocation-mapboxgl-e2510fce79d9a90bad71bcfc5a73c248a9c7c3d1.tar.gz
[android] #4800 - default location view from start: introduced attributes, update MapboxMapOptions, added tests. updated MockParcel
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java61
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java259
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java4
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java19
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java (renamed from platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationView.java)79
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java32
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationViewDrawableHolder.java60
7 files changed, 353 insertions, 161 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index 113e45d038..734f3f8947 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
@@ -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
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java
index 764a901d8b..c6b9aa7bfc 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java
@@ -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;
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
index 8ff6ec8b06..30492bc421 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
@@ -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.
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java
index db59bdb544..3cd9efb13e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java
@@ -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;
- }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java
index 931c799d10..430ebfe443 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java
@@ -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();
}
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
index af9c82df80..c048d0f57e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
@@ -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);
}
-
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationViewDrawableHolder.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationViewDrawableHolder.java
deleted file mode 100644
index 131a0aecb3..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationViewDrawableHolder.java
+++ /dev/null
@@ -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();
- }
- }
-}