-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NavigationCamera#update for MapboxMap animations
- Loading branch information
1 parent
b911e4e
commit a39cf73
Showing
11 changed files
with
325 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ain/java/com/mapbox/services/android/navigation/ui/v5/camera/CameraAnimationDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.mapbox.services.android.navigation.ui.v5.camera; | ||
|
||
import com.mapbox.mapboxsdk.camera.CameraUpdate; | ||
import com.mapbox.mapboxsdk.location.modes.CameraMode; | ||
import com.mapbox.mapboxsdk.maps.MapboxMap; | ||
|
||
class CameraAnimationDelegate { | ||
|
||
private final MapboxMap mapboxMap; | ||
|
||
CameraAnimationDelegate(MapboxMap mapboxMap) { | ||
this.mapboxMap = mapboxMap; | ||
} | ||
|
||
void render(NavigationCameraUpdate update, int durationMs, MapboxMap.CancelableCallback callback) { | ||
CameraUpdateMode mode = update.getMode(); | ||
CameraUpdate cameraUpdate = update.getCameraUpdate(); | ||
if (mode == CameraUpdateMode.OVERRIDE) { | ||
mapboxMap.getLocationComponent().setCameraMode(CameraMode.NONE); | ||
mapboxMap.animateCamera(cameraUpdate, durationMs, callback); | ||
} else if (!isTracking()) { | ||
mapboxMap.animateCamera(cameraUpdate, durationMs, callback); | ||
} | ||
} | ||
|
||
private boolean isTracking() { | ||
int cameraMode = mapboxMap.getLocationComponent().getCameraMode(); | ||
return cameraMode != CameraMode.NONE; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...i/src/main/java/com/mapbox/services/android/navigation/ui/v5/camera/CameraUpdateMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.mapbox.services.android.navigation.ui.v5.camera; | ||
|
||
/** | ||
* This class is passed to {@link NavigationCameraUpdate} to | ||
* determine the update's behavior when passed to {@link NavigationCamera}. | ||
*/ | ||
public enum CameraUpdateMode { | ||
|
||
/** | ||
* For a given {@link NavigationCameraUpdate}, this default mode means the | ||
* {@link NavigationCamera} will ignore the update when tracking is already | ||
* enabled. | ||
* <p> | ||
* If tracking is disabled, the update animation will execute. | ||
*/ | ||
DEFAULT, | ||
|
||
/** | ||
* For a given {@link NavigationCameraUpdate}, this override mode means the | ||
* {@link NavigationCamera} will stop tracking (if tracking) and execute the | ||
* given update animation. | ||
*/ | ||
OVERRIDE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...box/services/android/navigation/ui/v5/camera/NavigationCameraTrackingChangedListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.mapbox.services.android.navigation.ui.v5.camera; | ||
|
||
import com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener; | ||
|
||
class NavigationCameraTrackingChangedListener implements OnCameraTrackingChangedListener { | ||
|
||
private final NavigationCamera camera; | ||
|
||
NavigationCameraTrackingChangedListener(NavigationCamera camera) { | ||
this.camera = camera; | ||
} | ||
|
||
@Override | ||
public void onCameraTrackingDismissed() { | ||
camera.updateCameraTrackingMode(NavigationCamera.NAVIGATION_TRACKING_MODE_NONE); | ||
} | ||
|
||
@Override | ||
public void onCameraTrackingChanged(int currentMode) { | ||
Integer trackingMode = camera.findTrackingModeFor(currentMode); | ||
if (trackingMode != null) { | ||
camera.updateCameraTrackingMode(trackingMode); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...main/java/com/mapbox/services/android/navigation/ui/v5/camera/NavigationCameraUpdate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.mapbox.services.android.navigation.ui.v5.camera; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import com.mapbox.mapboxsdk.camera.CameraUpdate; | ||
|
||
/** | ||
* Used with {@link NavigationCamera#update(NavigationCameraUpdate)}. | ||
* <p> | ||
* This class wraps a Maps SDK {@link CameraUpdate}. It adds an option | ||
* for {@link CameraUpdateMode} that determine how the camera update behaves | ||
* with tracking modes. | ||
*/ | ||
public class NavigationCameraUpdate { | ||
|
||
private final CameraUpdate cameraUpdate; | ||
private CameraUpdateMode mode = CameraUpdateMode.DEFAULT; | ||
|
||
/** | ||
* Creates and instance of this class, taking a {@link CameraUpdate} | ||
* that has already been built. | ||
* | ||
* @param cameraUpdate with map camera parameters | ||
*/ | ||
public NavigationCameraUpdate(@NonNull CameraUpdate cameraUpdate) { | ||
this.cameraUpdate = cameraUpdate; | ||
} | ||
|
||
/** | ||
* Updates the {@link CameraUpdateMode} that will determine this updates | ||
* behavior based on the current tracking mode in {@link NavigationCamera}. | ||
* | ||
* @param mode either default or override | ||
*/ | ||
public void setMode(CameraUpdateMode mode) { | ||
this.mode = mode; | ||
} | ||
|
||
@NonNull | ||
CameraUpdate getCameraUpdate() { | ||
return cameraUpdate; | ||
} | ||
|
||
@NonNull | ||
CameraUpdateMode getMode() { | ||
return mode; | ||
} | ||
} |
Oops, something went wrong.