diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-11-09 10:42:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-09 10:42:18 +0100 |
commit | 772324e8f2a316bf82774732dd60bb7af5acdb18 (patch) | |
tree | 34109021f9e7ae14a732c5f98627c892267e9d2d /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations | |
parent | efc427f9bbf7fb4b8d8895613dbb29716d5d7b11 (diff) | |
download | qtlocation-mapboxgl-772324e8f2a316bf82774732dd60bb7af5acdb18.tar.gz |
Cherry pick release v4.2.0 (#6944)
* [android] - MyLocationView should facing above when location and compass bearing tracking are enabled. (#6829)
* [android] - use current animated rotation value for calculating animated marker rotation difference (#6826)
fix unit tests, input limiting is not handled by animateRotationBy instead of MarkerView.
Changed test to validate if method was called with correct value.
* [android] - only calculated offset margins for InfoWindow if View is found in current viewport, added example to the test app to test for regressions (#6877)
* upgraded okhttp dependency to latest version (#6880)
* Cancelable callback invocation (#6891)
* [android] - allow onCancel to be invoked from camera cancel callbacks
* set to null after finish
* [android] - using bearing clockwise versus counterclockwise (#6917)
* [android] - using bearing clockwise versus counterclockwise
* fixup brackets
* [android] - convert bearing values from core to Android SDK equivalent.
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations')
3 files changed, 40 insertions, 35 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java index 2459f6e79a..b902a1b3bc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java @@ -136,33 +136,38 @@ public class InfoWindow { boolean outOfBoundsLeft = false; boolean outOfBoundsRight = false; - // if out of bounds right - if (rightSideInfowWindow > mapRight) { - outOfBoundsRight = true; - x -= rightSideInfowWindow - mapRight; - tipViewMarginLeft += rightSideInfowWindow - mapRight + tipViewOffset; - rightSideInfowWindow = x + view.getMeasuredWidth(); - } + // only optimise margins if view is inside current viewport + if (mCoordinates.x >= 0 && mCoordinates.x <= mapView.getWidth() + && mCoordinates.y >= 0 && mCoordinates.y <= mapView.getHeight()) { + + // if out of bounds right + if (rightSideInfowWindow > mapRight) { + outOfBoundsRight = true; + x -= rightSideInfowWindow - mapRight; + tipViewMarginLeft += rightSideInfowWindow - mapRight + tipViewOffset; + rightSideInfowWindow = x + view.getMeasuredWidth(); + } - // fit screen left - if (leftSideInfoWindow < mapLeft) { - outOfBoundsLeft = true; - x += mapLeft - leftSideInfoWindow; - tipViewMarginLeft -= mapLeft - leftSideInfoWindow + tipViewOffset; - leftSideInfoWindow = x; - } + // fit screen left + if (leftSideInfoWindow < mapLeft) { + outOfBoundsLeft = true; + x += mapLeft - leftSideInfoWindow; + tipViewMarginLeft -= mapLeft - leftSideInfoWindow + tipViewOffset; + leftSideInfoWindow = x; + } - // Add margin right - if (outOfBoundsRight && mapRight - rightSideInfowWindow < marginHorizontal) { - x -= marginHorizontal - (mapRight - rightSideInfowWindow); - tipViewMarginLeft += marginHorizontal - (mapRight - rightSideInfowWindow) - tipViewOffset; - leftSideInfoWindow = x; - } + // Add margin right + if (outOfBoundsRight && mapRight - rightSideInfowWindow < marginHorizontal) { + x -= marginHorizontal - (mapRight - rightSideInfowWindow); + tipViewMarginLeft += marginHorizontal - (mapRight - rightSideInfowWindow) - tipViewOffset; + leftSideInfoWindow = x; + } - // Add margin left - if (outOfBoundsLeft && leftSideInfoWindow - mapLeft < marginHorizontal) { - x += marginHorizontal - (leftSideInfoWindow - mapLeft); - tipViewMarginLeft -= (marginHorizontal - (leftSideInfoWindow - mapLeft)) - tipViewOffset; + // Add margin left + if (outOfBoundsLeft && leftSideInfoWindow - mapLeft < marginHorizontal) { + x += marginHorizontal - (leftSideInfoWindow - mapLeft); + tipViewMarginLeft -= (marginHorizontal - (leftSideInfoWindow - mapLeft)) - tipViewOffset; + } } // Adjust tipView diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java index 175fd57da4..72037c2565 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java @@ -265,17 +265,9 @@ public class MarkerView extends Marker { newRotation += 360; } - // calculate new direction - float diff = newRotation - this.rotation; - if (diff > 180.0f) { - diff -= 360.0f; - } else if (diff < -180.0f) { - diff += 360.f; - } - this.rotation = newRotation; if (markerViewManager != null) { - markerViewManager.animateRotationBy(this, diff); + markerViewManager.animateRotationBy(this, newRotation); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java index 36f43abb11..8d29bf2d2e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java @@ -74,12 +74,20 @@ public class MarkerViewManager { * Animate a MarkerView with a given rotation. * * @param marker the MarkerView to rotate by - * @param rotation the rotation by value + * @param rotation the rotation by value, limited to 0 - 360 degrees */ public void animateRotationBy(@NonNull MarkerView marker, float rotation) { View convertView = markerViewMap.get(marker); if (convertView != null) { - AnimatorUtils.rotateBy(convertView, rotation); + convertView.animate().cancel(); + // calculate new direction + float diff = rotation - convertView.getRotation(); + if (diff > 180.0f) { + diff -= 360.0f; + } else if (diff < -180.0f) { + diff += 360.f; + } + AnimatorUtils.rotateBy(convertView, diff); } } |