[android] normalize previous rotation values of the location animator

This commit is contained in:
Łukasz Paczos
2019-05-09 19:11:10 +02:00
committed by Łukasz Paczos
parent b1c1471713
commit 9fb41a74bc
3 changed files with 115 additions and 0 deletions

View File

@@ -196,6 +196,9 @@ final class LocationAnimatorCoordinator {
float previousBearing, float targetBearing) {
createNewLatLngAnimator(ANIMATOR_LAYER_LATLNG, previousLatLng, targetLatLng);
// Because Location bearing values are normalized to [0, 360]
// we need to do the same for the previous bearing value to determine the shortest path
previousBearing = Utils.normalize(previousBearing);
float normalizedLayerBearing = Utils.shortestRotation(targetBearing, previousBearing);
createNewFloatAnimator(ANIMATOR_LAYER_GPS_BEARING, previousBearing, normalizedLayerBearing);
}

View File

@@ -36,6 +36,16 @@ public final class Utils {
return heading;
}
/**
* Normalizes an angle to be in the [0, 360] range.
*
* @param angle the provided angle
* @return the normalized angle
*/
public static float normalize(float angle) {
return (angle % 360 + 360) % 360;
}
static Bitmap generateShadow(Drawable drawable, float elevation) {
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();