@@ -2,89 +2,88 @@ package com.peterlaurence.mapview.layout.animators
22
33import android.animation.Animator
44import android.animation.ValueAnimator
5- import android.view.animation.Interpolator
6- import kotlin.math.pow
5+ import android.view.animation.AccelerateInterpolator
76
87class ZoomPanAnimator (private val listener : OnZoomPanAnimationListener ) : ValueAnimator(),
98 ValueAnimator .AnimatorUpdateListener , Animator .AnimatorListener {
109
11- private val mStartState = ZoomPanState ()
12- private val mEndState = ZoomPanState ()
13- private var mHasPendingZoomUpdates : Boolean = false
14- private var mHasPendingPanUpdates : Boolean = false
10+ private val startState = ZoomPanState ()
11+ private val endState = ZoomPanState ()
12+ private var hasPendingZoomUpdates : Boolean = false
13+ private var hasPendingPanUpdates : Boolean = false
1514
1615 init {
1716 addUpdateListener(this )
1817 addListener(this )
1918 setFloatValues(0f , 1f )
20- interpolator = FastEaseInInterpolator ()
19+ interpolator = AccelerateInterpolator ()
2120 }
2221
2322 private fun setupPanAnimation (x : Int , y : Int ): Boolean {
24- mStartState .x = listener.getScrollX()
25- mStartState .y = listener.getScrollY()
26- mEndState .x = x
27- mEndState .y = y
28- return mStartState .x != mEndState .x || mStartState .y != mEndState .y
23+ startState .x = listener.getScrollX()
24+ startState .y = listener.getScrollY()
25+ endState .x = x
26+ endState .y = y
27+ return startState .x != endState .x || startState .y != endState .y
2928 }
3029
3130 private fun setupZoomAnimation (scale : Float ): Boolean {
32- mStartState .scale = listener.getScale()
33- mEndState .scale = scale
34- return mStartState .scale != mEndState .scale
31+ startState .scale = listener.getScale()
32+ endState .scale = scale
33+ return startState .scale != endState .scale
3534 }
3635
3736 fun animateZoomPan (x : Int , y : Int , scale : Float ) {
38- mHasPendingZoomUpdates = setupZoomAnimation(scale)
39- mHasPendingPanUpdates = setupPanAnimation(x, y)
40- if (mHasPendingPanUpdates || mHasPendingZoomUpdates ) {
37+ hasPendingZoomUpdates = setupZoomAnimation(scale)
38+ hasPendingPanUpdates = setupPanAnimation(x, y)
39+ if (hasPendingPanUpdates || hasPendingZoomUpdates ) {
4140 start()
4241 }
4342 }
4443
4544 fun animateZoom (scale : Float ) {
46- mHasPendingZoomUpdates = setupZoomAnimation(scale)
47- if (mHasPendingZoomUpdates ) {
45+ hasPendingZoomUpdates = setupZoomAnimation(scale)
46+ if (hasPendingZoomUpdates ) {
4847 start()
4948 }
5049 }
5150
5251 fun animatePan (x : Int , y : Int ) {
53- mHasPendingPanUpdates = setupPanAnimation(x, y)
54- if (mHasPendingPanUpdates ) {
52+ hasPendingPanUpdates = setupPanAnimation(x, y)
53+ if (hasPendingPanUpdates ) {
5554 start()
5655 }
5756 }
5857
5958 override fun onAnimationUpdate (animation : ValueAnimator ) {
6059 val progress = animation.animatedValue as Float
61- if (mHasPendingZoomUpdates ) {
62- val scale = mStartState .scale + (mEndState .scale - mStartState .scale) * progress
60+ if (hasPendingZoomUpdates ) {
61+ val scale = startState .scale + (endState .scale - startState .scale) * progress
6362 listener.setScale(scale)
6463 }
65- if (mHasPendingPanUpdates ) {
66- val x = (mStartState .x + (mEndState .x - mStartState .x) * progress).toInt()
67- val y = (mStartState .y + (mEndState .y - mStartState .y) * progress).toInt()
64+ if (hasPendingPanUpdates ) {
65+ val x = (startState .x + (endState .x - startState .x) * progress).toInt()
66+ val y = (startState .y + (endState .y - startState .y) * progress).toInt()
6867 listener.scrollTo(x, y)
6968 }
7069 }
7170
7271 override fun onAnimationStart (animator : Animator ) {
73- if (mHasPendingZoomUpdates ) {
72+ if (hasPendingZoomUpdates ) {
7473 listener.setIsScaling(true )
7574 }
76- if (mHasPendingPanUpdates ) {
75+ if (hasPendingPanUpdates ) {
7776 listener.setIsSliding(true )
7877 }
7978 }
8079
8180 override fun onAnimationEnd (animator : Animator ) {
82- if (mHasPendingZoomUpdates ) {
83- mHasPendingZoomUpdates = false
81+ if (hasPendingZoomUpdates ) {
82+ hasPendingZoomUpdates = false
8483 listener.setIsScaling(false )
8584 }
86- if (mHasPendingPanUpdates ) {
87- mHasPendingPanUpdates = false
85+ if (hasPendingPanUpdates ) {
86+ hasPendingPanUpdates = false
8887 listener.setIsSliding(false )
8988 }
9089 }
@@ -103,12 +102,6 @@ class ZoomPanAnimator(private val listener: OnZoomPanAnimationListener) : ValueA
103102 var scale: Float = 0 .toFloat()
104103 }
105104
106- private class FastEaseInInterpolator : Interpolator {
107- override fun getInterpolation (input : Float ): Float {
108- return (1 - (1 - input).toDouble().pow(8.0 )).toFloat()
109- }
110- }
111-
112105 interface OnZoomPanAnimationListener {
113106 fun setIsScaling (isScaling : Boolean )
114107 fun setIsSliding (isSliding : Boolean )
0 commit comments