Skip to content
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 41 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6f79da7
Add initial animators
danesfeder Feb 19, 2018
d25dafa
Add Camera and Tracking Modes (#294)
danesfeder Feb 21, 2018
5031e32
Update with Render / Camera Modes (#297)
danesfeder Feb 21, 2018
b66d653
Add animator class (#302)
danesfeder Feb 22, 2018
4588147
Cleanup stale runnable (#304)
Feb 23, 2018
612f227
only update the location layer accuracy when not in RenderMode.GPS (#…
tobrun Feb 23, 2018
44a6602
Improve enabling/disabling location layer plugin (#308)
Feb 27, 2018
ce02ede
LocationLayerPlugin Javadoc (#309)
danesfeder Feb 27, 2018
a5f2dc9
LocationEngine listening to updates after resetting (#307)
Feb 27, 2018
999d19d
Add max / min zoom and padding APIs (#313)
danesfeder Feb 27, 2018
62a0e1c
Gestures logic for camera tracking, new telemetry library (#327)
Mar 1, 2018
ca7b10a
Update dependencies
danesfeder Mar 6, 2018
1b0e98d
Add missing long click listener
danesfeder Mar 7, 2018
94520b5
[location-layer] - fix crash on startup
tobrun Mar 7, 2018
2d40ff2
Add initial animators
danesfeder Feb 19, 2018
b835ece
Add Camera and Tracking Modes (#294)
danesfeder Feb 21, 2018
5b6e458
Update with Render / Camera Modes (#297)
danesfeder Feb 21, 2018
3c80c7c
Add animator class (#302)
danesfeder Feb 22, 2018
c1ec59a
Cleanup stale runnable (#304)
Feb 23, 2018
76cb80c
only update the location layer accuracy when not in RenderMode.GPS (#…
tobrun Feb 23, 2018
c44a596
Improve enabling/disabling location layer plugin (#308)
Feb 27, 2018
9a28ae5
LocationLayerPlugin Javadoc (#309)
danesfeder Feb 27, 2018
5ad4a96
LocationEngine listening to updates after resetting (#307)
Feb 27, 2018
a29e25b
Add max / min zoom and padding APIs (#313)
danesfeder Feb 27, 2018
c149689
Gestures logic for camera tracking, new telemetry library (#327)
Mar 1, 2018
704c902
Update dependencies
danesfeder Mar 6, 2018
54100a9
Add missing long click listener
danesfeder Mar 7, 2018
697b524
[location-layer] - fix crash on startup
tobrun Mar 7, 2018
ace099b
updated branch to latest on master
Mar 12, 2018
bfe40e9
Fixed checkstyle error
Mar 12, 2018
a540a87
fixed up ui test
Mar 12, 2018
1ccb76c
use old mas lib for geojson plugin
Mar 12, 2018
cf665f1
Merge branch 'map-location-animators' of github.com:mapbox/mapbox-plu…
danesfeder Mar 21, 2018
e001cf4
Animator Updates (#349)
danesfeder Mar 28, 2018
a2ac807
Gestures thresholds adjustments (#386)
Mar 28, 2018
7bd0c88
Fix order of interpolator expression (#388)
tobrun Mar 28, 2018
34a88e1
Merge branch 'map-location-animators' of github.com:mapbox/mapbox-plu…
danesfeder Mar 28, 2018
77dd29a
Merge branch 'master' into map-location-animators
danesfeder Mar 28, 2018
10f2900
Update feature import
danesfeder Mar 28, 2018
f80d879
fixup geojson
tobrun Mar 28, 2018
ebab085
fixup checkstyle
tobrun Mar 28, 2018
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
@@ -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;
}
}
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;
}
}
}
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) {
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

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

awesome

double diff = currentBearing - targetBearing;
if (diff > 180.0f) {
targetBearing += 360.0f;
} else if (diff < -180.0f) {
targetBearing -= 360.f;
}
return targetBearing;
}
}
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;
}
}
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;
}
}