-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map + Location Animators #293
Merged
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
6f79da7
Add initial animators
danesfeder d25dafa
Add Camera and Tracking Modes (#294)
danesfeder 5031e32
Update with Render / Camera Modes (#297)
danesfeder b66d653
Add animator class (#302)
danesfeder 4588147
Cleanup stale runnable (#304)
612f227
only update the location layer accuracy when not in RenderMode.GPS (#…
tobrun 44a6602
Improve enabling/disabling location layer plugin (#308)
ce02ede
LocationLayerPlugin Javadoc (#309)
danesfeder a5f2dc9
LocationEngine listening to updates after resetting (#307)
999d19d
Add max / min zoom and padding APIs (#313)
danesfeder 62a0e1c
Gestures logic for camera tracking, new telemetry library (#327)
ca7b10a
Update dependencies
danesfeder 1b0e98d
Add missing long click listener
danesfeder 94520b5
[location-layer] - fix crash on startup
tobrun 2d40ff2
Add initial animators
danesfeder b835ece
Add Camera and Tracking Modes (#294)
danesfeder 5b6e458
Update with Render / Camera Modes (#297)
danesfeder 3c80c7c
Add animator class (#302)
danesfeder c1ec59a
Cleanup stale runnable (#304)
76cb80c
only update the location layer accuracy when not in RenderMode.GPS (#…
tobrun c44a596
Improve enabling/disabling location layer plugin (#308)
9a28ae5
LocationLayerPlugin Javadoc (#309)
danesfeder 5ad4a96
LocationEngine listening to updates after resetting (#307)
a29e25b
Add max / min zoom and padding APIs (#313)
danesfeder c149689
Gestures logic for camera tracking, new telemetry library (#327)
704c902
Update dependencies
danesfeder 54100a9
Add missing long click listener
danesfeder 697b524
[location-layer] - fix crash on startup
tobrun ace099b
updated branch to latest on master
bfe40e9
Fixed checkstyle error
a540a87
fixed up ui test
1ccb76c
use old mas lib for geojson plugin
cf665f1
Merge branch 'map-location-animators' of github.com:mapbox/mapbox-plu…
danesfeder e001cf4
Animator Updates (#349)
danesfeder a2ac807
Gestures thresholds adjustments (#386)
7bd0c88
Fix order of interpolator expression (#388)
tobrun 34a88e1
Merge branch 'map-location-animators' of github.com:mapbox/mapbox-plu…
danesfeder 77dd29a
Merge branch 'master' into map-location-animators
danesfeder 10f2900
Update feature import
danesfeder f80d879
fixup geojson
tobrun ebab085
fixup checkstyle
tobrun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...ayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/camera/BearingAnimator.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,19 @@ | ||
package com.mapbox.mapboxsdk.plugins.locationlayer.camera; | ||
|
||
import android.animation.FloatEvaluator; | ||
import android.animation.ValueAnimator; | ||
|
||
public class BearingAnimator extends ValueAnimator { | ||
|
||
private float targetBearing; | ||
|
||
public BearingAnimator(double targetBearing, long duration) { | ||
setEvaluator(new FloatEvaluator()); | ||
setDuration(duration); | ||
this.targetBearing = (float) targetBearing; | ||
} | ||
|
||
public float getTargetBearing() { | ||
return targetBearing; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...layer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/camera/LatLngAnimator.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,41 @@ | ||
package com.mapbox.mapboxsdk.plugins.locationlayer.camera; | ||
|
||
import android.animation.TypeEvaluator; | ||
import android.animation.ValueAnimator; | ||
import android.support.annotation.NonNull; | ||
|
||
import com.mapbox.mapboxsdk.geometry.LatLng; | ||
|
||
public class LatLngAnimator extends ValueAnimator { | ||
|
||
private LatLng target; | ||
|
||
public LatLngAnimator(@NonNull LatLng target, long duration) { | ||
setDuration(duration); | ||
this.target = target; | ||
} | ||
|
||
@Override | ||
public void setObjectValues(Object... values) { | ||
super.setObjectValues(values); | ||
setEvaluator(new LatLngEvaluator()); | ||
} | ||
|
||
public LatLng getTarget() { | ||
return target; | ||
} | ||
|
||
private static class LatLngEvaluator implements TypeEvaluator<LatLng> { | ||
|
||
private final LatLng latLng = new LatLng(); | ||
|
||
@Override | ||
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) { | ||
latLng.setLatitude(startValue.getLatitude() | ||
+ ((endValue.getLatitude() - startValue.getLatitude()) * fraction)); | ||
latLng.setLongitude(startValue.getLongitude() | ||
+ ((endValue.getLongitude() - startValue.getLongitude()) * fraction)); | ||
return latLng; | ||
} | ||
} | ||
} |
160 changes: 160 additions & 0 deletions
160
...ionlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/camera/MapAnimator.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,160 @@ | ||
package com.mapbox.mapboxsdk.plugins.locationlayer.camera; | ||
|
||
import android.animation.Animator; | ||
import android.animation.AnimatorSet; | ||
import android.animation.ValueAnimator; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
|
||
import com.mapbox.mapboxsdk.camera.CameraPosition; | ||
import com.mapbox.mapboxsdk.geometry.LatLng; | ||
import com.mapbox.mapboxsdk.maps.MapboxMap; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class MapAnimator { | ||
|
||
private List<Animator> animators; | ||
private AnimatorSet animatorSet; | ||
|
||
private MapAnimator(List<Animator> animators) { | ||
this.animators = animators; | ||
animatorSet = new AnimatorSet(); | ||
} | ||
|
||
public void playTogether() { | ||
animatorSet.playTogether(animators); | ||
animatorSet.start(); | ||
} | ||
|
||
public void playTogether(@Nullable Animator.AnimatorListener listener) { | ||
animatorSet.addListener(listener); | ||
playTogether(); | ||
} | ||
|
||
public void playSequentially() { | ||
animatorSet.playSequentially(animators); | ||
animatorSet.start(); | ||
} | ||
|
||
public void playSequentially(@Nullable Animator.AnimatorListener listener) { | ||
animatorSet.addListener(listener); | ||
playSequentially(); | ||
} | ||
|
||
public void cancel() { | ||
animatorSet.cancel(); | ||
} | ||
|
||
public static Builder builder(MapboxMap mapboxMap) { | ||
return new Builder(mapboxMap); | ||
} | ||
|
||
public static final class Builder { | ||
|
||
private final MapboxMap mapboxMap; | ||
private List<Animator> animators; | ||
private CameraPosition currentPosition; | ||
|
||
private Builder(MapboxMap mapboxMap) { | ||
this.mapboxMap = mapboxMap; | ||
this.animators = new ArrayList<>(); | ||
// Get the current target from the current map camera position | ||
currentPosition = mapboxMap.getCameraPosition(); | ||
} | ||
|
||
public Builder addLatLngAnimator(@NonNull LatLngAnimator latLngAnimator) { | ||
|
||
LatLng currentTarget = currentPosition.target; | ||
if (currentTarget == latLngAnimator.getTarget()) { | ||
return this; | ||
} | ||
|
||
latLngAnimator.setObjectValues(currentTarget, latLngAnimator.getTarget()); | ||
latLngAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | ||
@Override | ||
public void onAnimationUpdate(ValueAnimator animation) { | ||
mapboxMap.setLatLng((LatLng) animation.getAnimatedValue()); | ||
} | ||
}); | ||
|
||
animators.add(latLngAnimator); | ||
return this; | ||
} | ||
|
||
public Builder addZoomAnimator(@NonNull ZoomAnimator zoomAnimator) { | ||
|
||
float currentZoom = (float) currentPosition.zoom; | ||
if (currentZoom == zoomAnimator.getTargetZoom()) { | ||
return this; | ||
} | ||
|
||
zoomAnimator.setFloatValues(currentZoom, zoomAnimator.getTargetZoom()); | ||
zoomAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | ||
@Override | ||
public void onAnimationUpdate(ValueAnimator animation) { | ||
mapboxMap.setZoom((Float) animation.getAnimatedValue()); | ||
} | ||
}); | ||
|
||
animators.add(zoomAnimator); | ||
return this; | ||
} | ||
|
||
public Builder addBearingAnimator(@NonNull BearingAnimator bearingAnimator) { | ||
|
||
float currentBearing = (float) currentPosition.bearing; | ||
float normalizedTargetBearing = normalizeBearing(currentBearing, bearingAnimator.getTargetBearing()); | ||
if (currentBearing == normalizedTargetBearing) { | ||
return this; | ||
} | ||
|
||
bearingAnimator.setFloatValues(currentBearing, normalizedTargetBearing); | ||
bearingAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | ||
@Override | ||
public void onAnimationUpdate(ValueAnimator animation) { | ||
mapboxMap.setBearing((Float) animation.getAnimatedValue()); | ||
} | ||
}); | ||
|
||
animators.add(bearingAnimator); | ||
return this; | ||
} | ||
|
||
public Builder addTiltAnimator(@NonNull TiltAnimator tiltAnimator) { | ||
|
||
float currentTilt = (float) currentPosition.tilt; | ||
if (currentTilt == tiltAnimator.getTargetTilt()) { | ||
return this; | ||
} | ||
|
||
tiltAnimator.setFloatValues(currentTilt, tiltAnimator.getTargetTilt()); | ||
tiltAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | ||
@Override | ||
public void onAnimationUpdate(ValueAnimator animation) { | ||
mapboxMap.setTilt((Float) animation.getAnimatedValue()); | ||
} | ||
}); | ||
|
||
animators.add(tiltAnimator); | ||
return this; | ||
} | ||
|
||
|
||
|
||
public MapAnimator build() { | ||
return new MapAnimator(animators); | ||
} | ||
} | ||
|
||
private static float normalizeBearing(float currentBearing, float targetBearing) { | ||
double diff = currentBearing - targetBearing; | ||
if (diff > 180.0f) { | ||
targetBearing += 360.0f; | ||
} else if (diff < -180.0f) { | ||
targetBearing -= 360.f; | ||
} | ||
return targetBearing; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...onlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/camera/TiltAnimator.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,19 @@ | ||
package com.mapbox.mapboxsdk.plugins.locationlayer.camera; | ||
|
||
import android.animation.FloatEvaluator; | ||
import android.animation.ValueAnimator; | ||
|
||
public class TiltAnimator extends ValueAnimator { | ||
|
||
private float targetTilt; | ||
|
||
public TiltAnimator(double targetTilt, long duration) { | ||
setEvaluator(new FloatEvaluator()); | ||
setDuration(duration); | ||
this.targetTilt = (float) targetTilt; | ||
} | ||
|
||
public float getTargetTilt() { | ||
return targetTilt; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...onlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/camera/ZoomAnimator.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,19 @@ | ||
package com.mapbox.mapboxsdk.plugins.locationlayer.camera; | ||
|
||
import android.animation.FloatEvaluator; | ||
import android.animation.ValueAnimator; | ||
|
||
public class ZoomAnimator extends ValueAnimator { | ||
|
||
private float targetZoom; | ||
|
||
public ZoomAnimator(double targetZoom, long duration) { | ||
setEvaluator(new FloatEvaluator()); | ||
setDuration(duration); | ||
this.targetZoom = (float) targetZoom; | ||
} | ||
|
||
public float getTargetZoom() { | ||
return targetZoom; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should just extract this method into the Utils class since I already use the same logic in
LocationLayerPlugin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cammace Sure thing. Just porting this code from mapbox/mapbox-navigation-android#679 - will look to clean up and remove duplicate code as the PR progresses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome