Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Implement new bearingTrackingMode GPS_NORTH_FACING #11095

Merged
merged 1 commit into from
Feb 5, 2018
Merged
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 @@ -22,7 +22,7 @@
*/
public class MyBearingTracking {

@IntDef( {NONE, COMPASS, GPS})
@IntDef( {NONE, COMPASS, GPS, GPS_NORTH_FACING})
@Retention(RetentionPolicy.SOURCE)
public @interface Mode {
}
Expand All @@ -42,4 +42,9 @@ public class MyBearingTracking {
*/
public static final int GPS = 0x00000008;

/**
* Tracking the bearing of the user based on GPS data, but camera always faces north direction
*/
public static final int GPS_NORTH_FACING = 0x0000000B;

}
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ protected void onDraw(Canvas canvas) {
foregroundDrawable.draw(canvas);
}
} else if (foregroundBearingDrawable != null && foregroundBounds != null) {
if (myBearingTrackingMode == MyBearingTracking.GPS || compassListener.isSensorAvailable()) {
if (myBearingTrackingMode == MyBearingTracking.GPS
|| myBearingTrackingMode == MyBearingTracking.GPS_NORTH_FACING
|| compassListener.isSensorAvailable()) {
foregroundBearingDrawable.draw(canvas);
} else {
// We are tracking MyBearingTracking.COMPASS, but sensor is not available.
Expand All @@ -383,7 +385,8 @@ public void setTilt(@FloatRange(from = 0, to = 60.0f) double tilt) {
public void setBearing(double bearing) {
this.bearing = bearing;
if (myLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
if (myBearingTrackingMode == MyBearingTracking.GPS) {
if (myBearingTrackingMode == MyBearingTracking.GPS
|| myBearingTrackingMode == MyBearingTracking.GPS_NORTH_FACING) {
if (location != null) {
setCompass(location.getBearing() - bearing);
}
Expand Down Expand Up @@ -519,7 +522,8 @@ public void onRestoreInstanceState(Parcelable state) {
}

private void toggleGps(boolean enableGps) {
toggleGps(enableGps, mapboxMap != null && mapboxMap.getTrackingSettings().isCustomLocationSource());
toggleGps(enableGps, mapboxMap != null
&& mapboxMap.getTrackingSettings().isCustomLocationSource());
}

/**
Expand Down Expand Up @@ -580,7 +584,8 @@ public void setLocation(Location location) {
this.location = location;
myLocationBehavior.updateLatLng(location);

if (mapboxMap != null && myBearingTrackingMode == MyBearingTracking.GPS
if (mapboxMap != null && (myBearingTrackingMode == MyBearingTracking.GPS
|| myBearingTrackingMode == MyBearingTracking.GPS_NORTH_FACING)
&& myLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
setBearing(mapboxMap.getCameraPosition().bearing);
}
Expand Down Expand Up @@ -616,7 +621,8 @@ public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTracki
compassListener.onResume();
} else {
compassListener.onPause();
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW
&& myBearingTrackingMode == MyBearingTracking.GPS) {
// always face north
setCompass(0);
} else {
Expand Down Expand Up @@ -1017,6 +1023,13 @@ void updateLatLng(@NonNull Location location) {
setCompass(0, COMPASS_UPDATE_RATE_MS);
}

if (myBearingTrackingMode == MyBearingTracking.GPS_NORTH_FACING) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small note that this could've been an else-if object.

builder.bearing(0);
if (location.hasBearing()) {
setCompass(location.getBearing(), COMPASS_UPDATE_RATE_MS);
}
}

// accuracy
updateAccuracy(location);

Expand Down