From ad54f5dcd0ef39eb777dd81aacd1d50c619d32f1 Mon Sep 17 00:00:00 2001 From: Markus Ressel Date: Fri, 12 Jun 2020 17:40:12 +0200 Subject: [PATCH 1/2] added boolean return value to callback function for easier delegation --- .../main/java/com/otaliastudios/zoom/ZoomEngine.kt | 8 ++------ .../zoom/internal/matrix/MatrixController.kt | 12 ++++-------- 2 files changed, 6 insertions(+), 14 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..4bf9984 100644 --- a/library/src/main/java/com/otaliastudios/zoom/ZoomEngine.kt +++ b/library/src/main/java/com/otaliastudios/zoom/ZoomEngine.kt @@ -76,13 +76,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 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() } From 5e489d7b1cbcc8f2674e30e163c4830454aa960c Mon Sep 17 00:00:00 2001 From: Markus Ressel Date: Fri, 12 Jun 2020 17:40:52 +0200 Subject: [PATCH 2/2] respect realZoom when calculating transformationPan --- .../main/java/com/otaliastudios/zoom/ZoomEngine.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/library/src/main/java/com/otaliastudios/zoom/ZoomEngine.kt b/library/src/main/java/com/otaliastudios/zoom/ZoomEngine.kt index 4bf9984..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 @@ -603,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)