[android] improve scale inertia

This commit is contained in:
Łukasz Paczos
2019-07-12 15:29:30 +02:00
committed by Łukasz Paczos
parent 09fd9dace6
commit 18971395d6
3 changed files with 18 additions and 3 deletions

View File

@@ -78,6 +78,16 @@ public class MapboxConstants {
*/
public static final float ROTATION_THRESHOLD_INCREASE_WHEN_SCALING = 25f;
/**
* Maximum absolute zoom change for multi-pointer scale velocity animation
*/
public static final double MAX_ABSOLUTE_SCALE_VELOCITY_CHANGE = 2.5;
/**
* Scale velocity animation duration multiplier.
*/
public static final double SCALE_VELOCITY_ANIMATION_DURATION_MULTIPLIER = 150;
/**
* Time within which user needs to lift fingers for velocity animation to start.
*/

View File

@@ -30,6 +30,8 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import static com.mapbox.mapboxsdk.constants.MapboxConstants.MAX_ABSOLUTE_SCALE_VELOCITY_CHANGE;
import static com.mapbox.mapboxsdk.constants.MapboxConstants.SCALE_VELOCITY_ANIMATION_DURATION_MULTIPLIER;
import static com.mapbox.mapboxsdk.constants.MapboxConstants.ZOOM_RATE;
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE;
@@ -558,7 +560,9 @@ final class MapGestureDetector {
double zoomAddition = calculateScale(velocityXY, detector.isScalingOut());
double currentZoom = transform.getRawZoom();
PointF focalPoint = getScaleFocalPoint(detector);
long animationTime = (long) (Math.abs(zoomAddition) * 1000 / 4);
// (log(x + 1 / e^2) + 2) * 150, x=0 to 2.5 (MapboxConstants#MAX_ABSOLUTE_SCALE_VELOCITY_CHANGE)
long animationTime = (long) ((Math.log((Math.abs(zoomAddition)) + 1 / Math.pow(Math.E, 2)) + 2)
* SCALE_VELOCITY_ANIMATION_DURATION_MULTIPLIER);
scaleAnimator = createScaleAnimator(currentZoom, zoomAddition, focalPoint, animationTime);
scheduleAnimator(scaleAnimator);
}
@@ -578,7 +582,8 @@ final class MapGestureDetector {
}
private double calculateScale(double velocityXY, boolean isScalingOut) {
double zoomAddition = (float) Math.log(velocityXY / 1000 + 1);
double zoomAddition = velocityXY * MAX_ABSOLUTE_SCALE_VELOCITY_CHANGE * 1e-4;
zoomAddition = MathUtils.clamp(zoomAddition, 0, MAX_ABSOLUTE_SCALE_VELOCITY_CHANGE);
if (isScalingOut) {
zoomAddition = -zoomAddition;
}

View File

@@ -8,7 +8,7 @@
<dimen name="mapbox_my_locationview_outer_circle">18dp</dimen>
<!--Minimum scale velocity required to start animation-->
<dimen name="mapbox_minimum_scale_velocity">150dp</dimen>
<dimen name="mapbox_minimum_scale_velocity">225dp</dimen>
<!--Minimum scale span delta required to execute scale gesture when rotating-->
<dimen name="mapbox_minimum_scale_span_when_rotating">100dp</dimen>