From adeed37b06c80c8955c80c4f1cb7ede181a8af37 Mon Sep 17 00:00:00 2001 From: Markus Ressel Date: Fri, 12 Jun 2020 20:34:47 +0200 Subject: [PATCH] Bugfix/#152 pan to center (#158) * added boolean return value to callback function for easier delegation * respect realZoom when calculating transformationPan --- .../java/com/otaliastudios/zoom/ZoomEngine.kt | 21 +++++++++---------- .../zoom/internal/matrix/MatrixController.kt | 12 ++++------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/library/src/main/java/com/otaliastudios/zoom/ZoomEngine.kt b/library/src/main/java/com/otaliastudios/zoom/ZoomEngine.kt index e0856c9..ee2fa90 100644 --- a/library/src/main/java/com/otaliastudios/zoom/ZoomEngine.kt +++ b/library/src/main/java/com/otaliastudios/zoom/ZoomEngine.kt @@ -4,13 +4,16 @@ import android.annotation.SuppressLint import android.content.Context import android.graphics.Matrix import android.graphics.RectF -import android.view.* +import android.view.Gravity +import android.view.MotionEvent +import android.view.View +import android.view.ViewTreeObserver import com.otaliastudios.zoom.ZoomApi.* -import com.otaliastudios.zoom.internal.UpdatesDispatcher -import com.otaliastudios.zoom.internal.matrix.MatrixController import com.otaliastudios.zoom.internal.StateController +import com.otaliastudios.zoom.internal.UpdatesDispatcher import com.otaliastudios.zoom.internal.gestures.PinchDetector import com.otaliastudios.zoom.internal.gestures.ScrollFlingDetector +import com.otaliastudios.zoom.internal.matrix.MatrixController import com.otaliastudios.zoom.internal.matrix.MatrixUpdate import com.otaliastudios.zoom.internal.movement.PanManager import com.otaliastudios.zoom.internal.movement.ZoomManager @@ -76,13 +79,9 @@ internal constructor(context: Context) : ZoomApi { // Post utilities - override fun post(action: Runnable) { - container.post(action) - } + override fun post(action: Runnable): Boolean = container.post(action) - override fun postOnAnimation(action: Runnable) { - container.postOnAnimation(action) - } + override fun postOnAnimation(action: Runnable) = container.postOnAnimation(action) // Matrix callbacks @@ -607,8 +606,8 @@ internal constructor(context: Context) : ZoomApi { * dimensions. This means applying the transformation gravity. */ private fun computeTransformationPan(): ScaledPoint { - val extraWidth = contentWidth - containerWidth - val extraHeight = contentHeight - containerHeight + val extraWidth = contentWidth * realZoom - containerWidth + val extraHeight = contentHeight * realZoom - containerHeight val gravity = computeTransformationGravity(transformationGravity) val x = -panManager.applyGravity(gravity, extraWidth, true) val y = -panManager.applyGravity(gravity, extraHeight, false) diff --git a/library/src/main/java/com/otaliastudios/zoom/internal/matrix/MatrixController.kt b/library/src/main/java/com/otaliastudios/zoom/internal/matrix/MatrixController.kt index 4138fab..74d96ca 100644 --- a/library/src/main/java/com/otaliastudios/zoom/internal/matrix/MatrixController.kt +++ b/library/src/main/java/com/otaliastudios/zoom/internal/matrix/MatrixController.kt @@ -26,7 +26,7 @@ internal class MatrixController( internal interface Callback { fun onMatrixUpdate() fun onMatrixSizeChanged(oldZoom: Float, firstTime: Boolean) - fun post(action: Runnable) + fun post(action: Runnable): Boolean fun postOnAnimation(action: Runnable) } @@ -151,13 +151,9 @@ internal class MatrixController( } - internal fun post(action: Runnable) { - callback.post(action) - } + internal fun post(action: Runnable) = callback.post(action) - internal fun postOnAnimation(action: Runnable) { - callback.postOnAnimation(action) - } + internal fun postOnAnimation(action: Runnable) = callback.postOnAnimation(action) /** * Clears our state. @@ -213,7 +209,7 @@ internal class MatrixController( private fun sync() { stub.mapRect(contentScaledRect, contentRect) } - + private fun dispatch() { callback.onMatrixUpdate() }