Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.graphics.PointF;
import android.graphics.RectF;
import android.graphics.SurfaceTexture;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
Expand Down Expand Up @@ -745,6 +746,67 @@ private void validateTelemetryServiceConfigured() {
throw new TelemetryServiceNotConfiguredException();
}

//
// User marker location drawable management
//

/**
* Set the user location view default drawable .
*/
void setUserLocationDrawable(Drawable drawable) {
mUserLocationView.setUserLocationDrawable(drawable);
}

/**
* Set the user location view default drawable and its shadow.
*/
void setUserLocationDrawable(Drawable drawable, Drawable shadowDrawable) {
mUserLocationView.setUserLocationDrawable(drawable, shadowDrawable);
}

/**
* Set the user location view bearing drawable.
*/
void setUserLocationBearingDrawable(Drawable drawable) {
mUserLocationView.setUserLocationBearingDrawable(drawable);
}

/**
* Set the user location view bearing drawable and its shadow.
*/
void setUserLocationBearingDrawable(Drawable drawable, Drawable shadowDrawable) {
mUserLocationView.setUserLocationBearingDrawable(drawable, shadowDrawable);
}

/**
* Set the stale user location view drawable.
*/
void setUserLocationStaleDrawable(Drawable drawable) {
mUserLocationView.setUserLocationStaleDrawable(drawable);
}

/**
* Set the stale user location view drawable and its shadow.
*/
void setUserLocationStaleDrawable(Drawable drawable, Drawable shadowDrawable) {
mUserLocationView.setUserLocationStaleDrawable(drawable, shadowDrawable);
}

/**
* Set the offset of the user location view shadow
*/
void setUserLocationShadowOffset(int x, int y) {
mUserLocationView.setUserLocationShadowOffset(x, y);
}

/**
* Change the accuracy color
* @param color int real color (not a @ColorRes)
*/
void setUserLocationAccuracyColor(int color) {
mUserLocationView.setUserLocationAccuracyColor(color);
}

//
// Projection
//
Expand Down Expand Up @@ -1435,9 +1497,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
}

// reset tracking modes if gesture occurs
if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
resetTrackingModes();
}
resetTrackingModesIfRequired();

// Fling the map
float ease = 0.25f;
Expand Down Expand Up @@ -1473,10 +1533,9 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
return false;
}

if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
// reset tracking modes if gesture occurs
resetTrackingModes();
}
// reset tracking modes if gesture occurs
resetTrackingModesIfRequired();


// Cancel any animation
mNativeMapView.cancelTransitions();
Expand Down Expand Up @@ -1505,10 +1564,8 @@ public boolean onScaleBegin(ScaleGestureDetector detector) {
return false;
}

if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
// reset tracking modes if gesture occurs
resetTrackingModes();
}
// reset tracking modes if gesture occurs
resetTrackingModesIfRequired();

mBeginTime = detector.getEventTime();
trackGestureEvent(MapboxEvent.GESTURE_PINCH_START, detector.getFocusX(), detector.getFocusY());
Expand Down Expand Up @@ -1590,10 +1647,8 @@ public boolean onRotateBegin(RotateGestureDetector detector) {
return false;
}

if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
// reset tracking modes if gesture occurs
resetTrackingModes();
}
// reset tracking modes if gesture occurs
resetTrackingModesIfRequired();

mBeginTime = detector.getEventTime();
trackGestureEvent(MapboxEvent.GESTURE_ROTATION_START, detector.getFocusX(), detector.getFocusY());
Expand Down Expand Up @@ -1671,10 +1726,8 @@ public boolean onShoveBegin(ShoveGestureDetector detector) {
return false;
}

if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) {
// reset tracking modes if gesture occurs
resetTrackingModes();
}
// reset tracking modes if gesture occurs
resetTrackingModesIfRequired();

mBeginTime = detector.getEventTime();
trackGestureEvent(MapboxEvent.GESTURE_PITCH_START, detector.getFocusX(), detector.getFocusY());
Expand Down Expand Up @@ -2146,11 +2199,28 @@ boolean isPermissionsAccepted() {
ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
}

private void resetTrackingModes() {
private void resetTrackingModesIfRequired() {
TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings();
if (trackingSettings.isDismissLocationTrackingOnGesture()) {
resetLocationTrackingMode();
}
if (trackingSettings.isDismissBearingTrackingOnGesture()) {
resetBearingTrackingMode();
}
}

private void resetLocationTrackingMode() {
try {
TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings();
trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
trackingSettings.setMyBearingTrackingMode(MyBearingTracking.NONE);
} catch (SecurityException ignore) {
// User did not accept location permissions
}
}

private void resetBearingTrackingMode() {
try {
setMyBearingTrackingMode(MyBearingTracking.NONE);
} catch (SecurityException ignore) {
// User did not accept location permissions
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.maps;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.os.Bundle;
import android.os.SystemClock;
Expand Down Expand Up @@ -481,6 +482,69 @@ public void setAccessToken(@NonNull String accessToken) {
mMapView.setAccessToken(accessToken);
}

/**
* Set the user location view default drawable .
*/
public void setUserLocationDrawable(Drawable drawable) {
mMapView.setUserLocationDrawable(drawable);
}

/**
* Set the user location view default drawable and its shadow.
*/
public void setUserLocationDrawable(Drawable drawable, Drawable shadowDrawable) {
mMapView.setUserLocationDrawable(drawable, shadowDrawable);
}

/**
* Set the user location view bearing drawable.
*/
public void setUserLocationBearingDrawable(Drawable drawable) {
mMapView.setUserLocationBearingDrawable(drawable);
}

/**
* Set the user location view bearing drawable and its shadow.
*/
public void setUserLocationBearingDrawable(Drawable drawable, Drawable shadowDrawable) {
mMapView.setUserLocationBearingDrawable(drawable, shadowDrawable);
}

/**
* Set the stale user location view drawable.
*/
public void setUserLocationStaleDrawable(Drawable drawable) {
mMapView.setUserLocationStaleDrawable(drawable);
}

/**
* Set the stale user location view drawable and its shadow.
*/
public void setUserLocationStaleDrawable(Drawable drawable, Drawable shadowDrawable) {
mMapView.setUserLocationStaleDrawable(drawable, shadowDrawable);
}


/**
* Set the offset of the user location view shadow.
*
* @param x int x offset in pixels
* @param y int y offset in pixels
*/
public void setUserLocationShadowOffset(int x, int y) {
mMapView.setUserLocationShadowOffset(x, y);
}

/**
* Change the accuracy circle (fill and stroke) color of the user location view
*
* @param color int real color (not a @ColorRes)
*/
public void setUserLocationAccuracyColor(int color) {
mMapView.setUserLocationAccuracyColor(color);
}


/**
* Returns the current Mapbox access token used to load map styles and tiles.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class TrackingSettings {

private MapView mapView;
private UiSettings uiSettings;
private boolean dismissTrackingOnGesture = true;
private boolean dismissLocationTrackingOnGesture = true;
private boolean dismissBearingTrackingOnGesture = true;

@MyLocationTracking.Mode
private int mMyLocationTrackingMode;
Expand Down Expand Up @@ -43,7 +44,7 @@ public class TrackingSettings {
public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
mMyLocationTrackingMode = myLocationTrackingMode;
mapView.setMyLocationTrackingMode(myLocationTrackingMode);
validateGesturesForTrackingModes();
validateGesturesForLocationTrackingMode();
}

/**
Expand Down Expand Up @@ -78,6 +79,7 @@ public int getMyLocationTrackingMode() {
public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) {
mMyBearingTrackingMode = myBearingTrackingMode;
mapView.setMyBearingTrackingMode(myBearingTrackingMode);
validateGesturesForBearingTrackingMode();
}

/**
Expand All @@ -88,36 +90,71 @@ public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTracki
* @see MyBearingTracking
*/
@UiThread
@MyLocationTracking.Mode
@MyBearingTracking.Mode
public int getMyBearingTrackingMode() {
return mMyBearingTrackingMode;
}

public boolean isDismissTrackingOnGesture() {
return dismissTrackingOnGesture;
return dismissLocationTrackingOnGesture && dismissBearingTrackingOnGesture;
}

public void setDismissTrackingOnGesture(boolean dismissTrackingOnGesture) {
this.dismissTrackingOnGesture = dismissTrackingOnGesture;
dismissLocationTrackingOnGesture = dismissTrackingOnGesture;
dismissBearingTrackingOnGesture = dismissTrackingOnGesture;
validateGesturesForTrackingModes();
}

private void validateGesturesForTrackingModes() {
if (!dismissTrackingOnGesture) {
int myLocationTrackingMode = getMyLocationTrackingMode();
int myBearingTrackingMode = getMyBearingTrackingMode();
validateGesturesForBearingTrackingMode();
validateGesturesForLocationTrackingMode();
}

private void validateGesturesForLocationTrackingMode() {
int myLocationTrackingMode = getMyLocationTrackingMode();

// Enable/disable gestures based on tracking mode
if (!dismissLocationTrackingOnGesture) {
if (myLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
uiSettings.setScrollGesturesEnabled(true);
uiSettings.setRotateGesturesEnabled(true);
} else {
uiSettings.setScrollGesturesEnabled(false);
uiSettings.setRotateGesturesEnabled((myBearingTrackingMode == MyBearingTracking.NONE));
}
} else {
uiSettings.setScrollGesturesEnabled(true);
}
}

private void validateGesturesForBearingTrackingMode() {
int myBearingTrackingMode = getMyBearingTrackingMode();
if (!dismissBearingTrackingOnGesture) {
if (myBearingTrackingMode == MyBearingTracking.NONE) {
uiSettings.setRotateGesturesEnabled(true);
} else {
uiSettings.setRotateGesturesEnabled(false);
}
} else {
uiSettings.setRotateGesturesEnabled(true);
}
}

public void setDismissLocationTrackingOnGesture(boolean dismissLocationTrackingOnGesture) {
this.dismissLocationTrackingOnGesture = dismissLocationTrackingOnGesture;
validateGesturesForLocationTrackingMode();
}

public boolean isDismissLocationTrackingOnGesture() {
return dismissLocationTrackingOnGesture;
}

public void setDismissBearingTrackingOnGesture(boolean dismissBearingTrackingOnGesture) {
this.dismissBearingTrackingOnGesture = dismissBearingTrackingOnGesture;
validateGesturesForBearingTrackingMode();
}

public boolean isDismissBearingTrackingOnGesture() {
return dismissBearingTrackingOnGesture;
}

public boolean isLocationTrackingDisabled(){
return mMyLocationTrackingMode == MyLocationTracking.TRACKING_NONE;
}
Expand Down
Loading