@@ -3,6 +3,9 @@ package com.peterlaurence.mapview.layout
33import android.content.Context
44import android.util.AttributeSet
55import android.view.*
6+ import android.view.animation.AccelerateDecelerateInterpolator
7+ import android.view.animation.DecelerateInterpolator
8+ import android.view.animation.Interpolator
69import android.widget.Scroller
710import androidx.core.view.ViewCompat
811import com.peterlaurence.mapview.layout.animators.ZoomPanAnimator
@@ -25,9 +28,11 @@ abstract class GestureLayout @JvmOverloads constructor(context: Context, attrs:
2528 TouchUpGestureDetector .OnTouchUpListener , RotationGestureDetector .OnRotationGestureListener ,
2629 GestureController .Controllable {
2730
28- /* Controllers */
2931 internal val gestureController: GestureController by lazy { GestureController (this ) }
3032
33+ private val defaultInterpolator: Interpolator = AccelerateDecelerateInterpolator ()
34+ private val fastInterpolator: Interpolator = DecelerateInterpolator (2f )
35+
3136 override fun onMinScaleUpdateRequest () {
3237 gestureController.calculateMinimumScaleToFit(width, height)
3338 }
@@ -220,20 +225,22 @@ abstract class GestureLayout @JvmOverloads constructor(context: Context, attrs:
220225 *
221226 * @param x Horizontal destination point.
222227 * @param y Vertical destination point.
228+ * @param interpolator The [Interpolator] the animation should use.
223229 */
224- fun slideTo (x : Int , y : Int ) {
225- animator.animatePan(x, y)
230+ fun slideTo (x : Int , y : Int , interpolator : Interpolator = defaultInterpolator ) {
231+ animator.animatePan(x, y, interpolator )
226232 }
227233
228234 /* *
229235 * Scrolls and centers the [GestureLayout] to the x and y values provided using scrolling animation.
230236 *
231237 * @param x Horizontal destination point.
232238 * @param y Vertical destination point.
239+ * @param interpolator The [Interpolator] the animation should use.
233240 */
234241 @Suppress(" unused" )
235- fun slideToAndCenter (x : Int , y : Int ) {
236- slideTo(x - halfWidth, y - halfHeight)
242+ fun slideToAndCenter (x : Int , y : Int , interpolator : Interpolator = defaultInterpolator ) {
243+ slideTo(x - halfWidth, y - halfHeight, interpolator )
237244 }
238245
239246 /* *
@@ -243,18 +250,21 @@ abstract class GestureLayout @JvmOverloads constructor(context: Context, attrs:
243250 * @param x Horizontal destination point.
244251 * @param y Vertical destination point.
245252 * @param scale The final scale value the layout should animate to.
253+ * @param interpolator The [Interpolator] the animation should use.
246254 */
247- fun slideToAndCenterWithScale (x : Int , y : Int , scale : Float ) {
248- animator.animateZoomPan(x - halfWidth, y - halfHeight, scale)
255+ fun slideToAndCenterWithScale (x : Int , y : Int , scale : Float , interpolator : Interpolator = defaultInterpolator ) {
256+ animator.animateZoomPan(x - halfWidth, y - halfHeight, scale, interpolator )
249257 }
250258
251259 /* *
252260 * Scales the [GestureLayout] with animated progress, without maintaining scroll position.
253261 *
254262 * @param destination The final scale value the layout should animate to.
263+ * @param interpolator The [Interpolator] the animation should use.
255264 */
256- fun smoothScaleTo (destination : Float ) {
257- animator.animateZoom(destination)
265+ @Suppress(" unused" )
266+ fun smoothScaleTo (destination : Float , interpolator : Interpolator = defaultInterpolator) {
267+ animator.animateZoom(destination, interpolator)
258268 }
259269
260270 /* *
@@ -264,22 +274,25 @@ abstract class GestureLayout @JvmOverloads constructor(context: Context, attrs:
264274 * @param focusX The horizontal focal point to maintain, relative to the screen (as supplied by MotionEvent.getX).
265275 * @param focusY The vertical focal point to maintain, relative to the screen (as supplied by MotionEvent.getY).
266276 * @param scale The final scale value the layout should animate to.
277+ * @param interpolator The [Interpolator] the animation should use.
267278 */
268- fun smoothScaleFromFocalPoint (focusX : Int , focusY : Int , scale : Float ) {
279+ fun smoothScaleFromFocalPoint (focusX : Int , focusY : Int , scale : Float , interpolator : Interpolator = defaultInterpolator ) {
269280 val (x, y, scaleCst) = gestureController.getOffsetDestination(focusX, focusY, scale)
270281 if (scaleCst == gestureController.scale) {
271282 return
272283 }
273- animator.animateZoomPan(x, y, scaleCst)
284+ animator.animateZoomPan(x, y, scaleCst, interpolator )
274285 }
275286
276287 /* *
277288 * Animate the scale of the [GestureLayout] while maintaining the current center point.
278289 *
279290 * @param scale The final scale value the layout should animate to.
291+ * @param interpolator The [Interpolator] the animation should use.
280292 */
281- fun smoothScaleFromCenter (scale : Float ) {
282- smoothScaleFromFocalPoint(halfWidth, halfHeight, scale)
293+ @Suppress(" unused" )
294+ fun smoothScaleFromCenter (scale : Float , interpolator : Interpolator = defaultInterpolator) {
295+ smoothScaleFromFocalPoint(halfWidth, halfHeight, scale, interpolator)
283296 }
284297
285298 override fun constrainScrollToLimits () {
@@ -404,14 +417,14 @@ abstract class GestureLayout @JvmOverloads constructor(context: Context, attrs:
404417 gestureController.scale)
405418
406419 if (gestureController.angle == 0f ) {
407- smoothScaleFromFocalPoint(event.x.toInt(), event.y.toInt(), scaleCst)
420+ smoothScaleFromFocalPoint(event.x.toInt(), event.y.toInt(), scaleCst, fastInterpolator )
408421 } else {
409422 val angleRad = - gestureController.angle.toRad()
410423 val eventRx = (height / 2 * sin(angleRad) + width / 2 * (1 - cos(angleRad)) +
411424 event.x * cos(angleRad) - event.y * sin(angleRad)).toInt()
412425 val eventRy = (height / 2 * (1 - cos(angleRad)) - width / 2 * sin(angleRad) +
413426 event.x * sin(angleRad) + event.y * cos(angleRad)).toInt()
414- smoothScaleFromFocalPoint(eventRx, eventRy, scaleCst)
427+ smoothScaleFromFocalPoint(eventRx, eventRy, scaleCst, fastInterpolator )
415428 }
416429
417430 return true
0 commit comments