From 8cee888dc680d0516316fa32c64893cb6437bb66 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 15 Jan 2019 15:26:25 +0100 Subject: [PATCH] removing some redundant ScaleListener code --- .../pro/activities/VideoPlayerActivity.kt | 54 +++++++------------ .../gallery/pro/fragments/VideoFragment.kt | 54 +++++++------------ .../pro/views/MyZoomableGifTextureView.kt | 52 +++++++----------- 3 files changed, 56 insertions(+), 104 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt index 8ff3686ef..1e73437b6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt @@ -793,9 +793,13 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen } override fun onScale(detector: ScaleGestureDetector): Boolean { - var scaleFactor = detector.scaleFactor val width = video_surface.width val height = video_surface.height + if (width <= 0 || height <= 0) { + return true + } + + var scaleFactor = detector.scaleFactor val origScale = mSaveScale mSaveScale *= scaleFactor @@ -809,44 +813,24 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen mRight = width * mSaveScale - width mBottom = height * mSaveScale - height - if (0 <= width || 0 <= height) { - mMatrix.postScale(scaleFactor, scaleFactor, detector.focusX, detector.focusY) - if (scaleFactor < 1) { - mMatrix.getValues(mMatrices) - val x = mMatrices[Matrix.MTRANS_X] - val y = mMatrices[Matrix.MTRANS_Y] - if (scaleFactor < 1) { - if (0 < width) { - if (y < -mBottom) { - mMatrix.postTranslate(0f, -(y + mBottom)) - } else if (y > 0) { - mMatrix.postTranslate(0f, -y) - } - } else { - if (x < -mRight) { - mMatrix.postTranslate(-(x + mRight), 0f) - } else if (x > 0) { - mMatrix.postTranslate(-x, 0f) - } - } - } - } - } else { - mMatrix.postScale(scaleFactor, scaleFactor, detector.focusX, detector.focusY) + mMatrix.postScale(scaleFactor, scaleFactor, detector.focusX, detector.focusY) + if (scaleFactor < 1) { mMatrix.getValues(mMatrices) val x = mMatrices[Matrix.MTRANS_X] val y = mMatrices[Matrix.MTRANS_Y] if (scaleFactor < 1) { - if (x < -mRight) { - mMatrix.postTranslate(-(x + mRight), 0f) - } else if (x > 0) { - mMatrix.postTranslate(-x, 0f) - } - - if (y < -mBottom) { - mMatrix.postTranslate(0f, -(y + mBottom)) - } else if (y > 0) { - mMatrix.postTranslate(0f, -y) + if (width > 0) { + if (y < -mBottom) { + mMatrix.postTranslate(0f, -(y + mBottom)) + } else if (y > 0) { + mMatrix.postTranslate(0f, -y) + } + } else { + if (x < -mRight) { + mMatrix.postTranslate(-(x + mRight), 0f) + } else if (x > 0) { + mMatrix.postTranslate(-x, 0f) + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt index 01e626289..96bddc49a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/VideoFragment.kt @@ -777,9 +777,13 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S } override fun onScale(detector: ScaleGestureDetector): Boolean { - var scaleFactor = detector.scaleFactor val width = mTextureView.width val height = mTextureView.height + if (width <= 0 || height <= 0) { + return true + } + + var scaleFactor = detector.scaleFactor val origScale = mSaveScale mSaveScale *= scaleFactor @@ -793,44 +797,24 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S mRight = width * mSaveScale - width mBottom = height * mSaveScale - height - if (0 <= width || 0 <= height) { - mMatrix.postScale(scaleFactor, scaleFactor, detector.focusX, detector.focusY) - if (scaleFactor < 1) { - mMatrix.getValues(mMatrices) - val x = mMatrices[Matrix.MTRANS_X] - val y = mMatrices[Matrix.MTRANS_Y] - if (scaleFactor < 1) { - if (0 < width) { - if (y < -mBottom) { - mMatrix.postTranslate(0f, -(y + mBottom)) - } else if (y > 0) { - mMatrix.postTranslate(0f, -y) - } - } else { - if (x < -mRight) { - mMatrix.postTranslate(-(x + mRight), 0f) - } else if (x > 0) { - mMatrix.postTranslate(-x, 0f) - } - } - } - } - } else { - mMatrix.postScale(scaleFactor, scaleFactor, detector.focusX, detector.focusY) + mMatrix.postScale(scaleFactor, scaleFactor, detector.focusX, detector.focusY) + if (scaleFactor < 1) { mMatrix.getValues(mMatrices) val x = mMatrices[Matrix.MTRANS_X] val y = mMatrices[Matrix.MTRANS_Y] if (scaleFactor < 1) { - if (x < -mRight) { - mMatrix.postTranslate(-(x + mRight), 0f) - } else if (x > 0) { - mMatrix.postTranslate(-x, 0f) - } - - if (y < -mBottom) { - mMatrix.postTranslate(0f, -(y + mBottom)) - } else if (y > 0) { - mMatrix.postTranslate(0f, -y) + if (width > 0) { + if (y < -mBottom) { + mMatrix.postTranslate(0f, -(y + mBottom)) + } else if (y > 0) { + mMatrix.postTranslate(0f, -y) + } + } else { + if (x < -mRight) { + mMatrix.postTranslate(-(x + mRight), 0f) + } else if (x > 0) { + mMatrix.postTranslate(-x, 0f) + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MyZoomableGifTextureView.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MyZoomableGifTextureView.kt index 5d2819909..ec29309fe 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MyZoomableGifTextureView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MyZoomableGifTextureView.kt @@ -132,6 +132,10 @@ class MyZoomableGifTextureView(context: Context, attrs: AttributeSet) : GifTextu } override fun onScale(detector: ScaleGestureDetector): Boolean { + if (width <= 0 || height <= 0) { + return true + } + mLastFocusX = detector.focusX mLastFocusY = detector.focusY var scaleFactor = detector.scaleFactor @@ -148,44 +152,24 @@ class MyZoomableGifTextureView(context: Context, attrs: AttributeSet) : GifTextu mRight = width * mSaveScale - width mBottom = height * mSaveScale - height - if (0 <= width || 0 <= height) { - mMatrix.postScale(scaleFactor, scaleFactor, detector.focusX, detector.focusY) - if (scaleFactor < 1) { - mMatrix.getValues(mMatrices) - val x = mMatrices[Matrix.MTRANS_X] - val y = mMatrices[Matrix.MTRANS_Y] - if (scaleFactor < 1) { - if (0 < width) { - if (y < -mBottom) { - mMatrix.postTranslate(0f, -(y + mBottom)) - } else if (y > 0) { - mMatrix.postTranslate(0f, -y) - } - } else { - if (x < -mRight) { - mMatrix.postTranslate(-(x + mRight), 0f) - } else if (x > 0) { - mMatrix.postTranslate(-x, 0f) - } - } - } - } - } else { - mMatrix.postScale(scaleFactor, scaleFactor, detector.focusX, detector.focusY) + mMatrix.postScale(scaleFactor, scaleFactor, detector.focusX, detector.focusY) + if (scaleFactor < 1) { mMatrix.getValues(mMatrices) val x = mMatrices[Matrix.MTRANS_X] val y = mMatrices[Matrix.MTRANS_Y] if (scaleFactor < 1) { - if (x < -mRight) { - mMatrix.postTranslate(-(x + mRight), 0f) - } else if (x > 0) { - mMatrix.postTranslate(-x, 0f) - } - - if (y < -mBottom) { - mMatrix.postTranslate(0f, -(y + mBottom)) - } else if (y > 0) { - mMatrix.postTranslate(0f, -y) + if (width > 0) { + if (y < -mBottom) { + mMatrix.postTranslate(0f, -(y + mBottom)) + } else if (y > 0) { + mMatrix.postTranslate(0f, -y) + } + } else { + if (x < -mRight) { + mMatrix.postTranslate(-(x + mRight), 0f) + } else if (x > 0) { + mMatrix.postTranslate(-x, 0f) + } } } }