handle closing GIF view with down gesture
This commit is contained in:
parent
95492d5e06
commit
f495a0790e
2 changed files with 18 additions and 7 deletions
|
@ -103,11 +103,6 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.config.allowDownGesture) {
|
if (context.config.allowDownGesture) {
|
||||||
gif_view.setOnTouchListener { v, event ->
|
|
||||||
handleEvent(event)
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
subsampling_view.setOnTouchListener { v, event ->
|
subsampling_view.setOnTouchListener { v, event ->
|
||||||
if (mView.subsampling_view.scale == mOriginalSubsamplingScale) {
|
if (mView.subsampling_view.scale == mOriginalSubsamplingScale) {
|
||||||
handleEvent(event)
|
handleEvent(event)
|
||||||
|
@ -311,7 +306,9 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
val resolution = mMedium.path.getImageResolution() ?: Point(0, 0)
|
val resolution = mMedium.path.getImageResolution() ?: Point(0, 0)
|
||||||
mView.gif_view.apply {
|
mView.gif_view.apply {
|
||||||
setInputSource(source)
|
setInputSource(source)
|
||||||
setupSizes(resolution.x, resolution.y, mScreenWidth, mScreenHeight)
|
setupGIFView(resolution.x, resolution.y, mScreenWidth, mScreenHeight) {
|
||||||
|
activity?.supportFinishAfterTransition()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
loadBitmap()
|
loadBitmap()
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.view.MotionEvent
|
||||||
import android.view.ScaleGestureDetector
|
import android.view.ScaleGestureDetector
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import com.simplemobiletools.commons.extensions.beVisible
|
import com.simplemobiletools.commons.extensions.beVisible
|
||||||
|
import com.simplemobiletools.gallery.pro.extensions.config
|
||||||
import com.simplemobiletools.gallery.pro.helpers.*
|
import com.simplemobiletools.gallery.pro.helpers.*
|
||||||
import pl.droidsonroids.gif.GifTextureView
|
import pl.droidsonroids.gif.GifTextureView
|
||||||
|
|
||||||
|
@ -25,18 +26,22 @@ class MyZoomableGifTextureView(context: Context, attrs: AttributeSet) : GifTextu
|
||||||
private var mScreenHeight = 0f
|
private var mScreenHeight = 0f
|
||||||
private var mLastFocusX = 0f
|
private var mLastFocusX = 0f
|
||||||
private var mLastFocusY = 0f
|
private var mLastFocusY = 0f
|
||||||
|
private var mCloseDownThreshold = 100f
|
||||||
|
private var mIgnoreCloseDown = false
|
||||||
private var mCurrZoomMode = ZOOM_MODE_NONE
|
private var mCurrZoomMode = ZOOM_MODE_NONE
|
||||||
|
|
||||||
private var mScaleDetector: ScaleGestureDetector? = null
|
private var mScaleDetector: ScaleGestureDetector? = null
|
||||||
private var mMatrices = FloatArray(9)
|
private var mMatrices = FloatArray(9)
|
||||||
private val mMatrix = Matrix()
|
private val mMatrix = Matrix()
|
||||||
private var mCurrentViewport = RectF()
|
private var mCurrentViewport = RectF()
|
||||||
|
private var mCloseDownCallback: (() -> Unit)? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
mScaleDetector = ScaleGestureDetector(context, ScaleListener())
|
mScaleDetector = ScaleGestureDetector(context, ScaleListener())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setupSizes(gifWidth: Int, gifHeight: Int, screenWidth: Int, screenHeight: Int) {
|
fun setupGIFView(gifWidth: Int, gifHeight: Int, screenWidth: Int, screenHeight: Int, callback: () -> Unit) {
|
||||||
|
mCloseDownCallback = callback
|
||||||
// if we don't know the gifs' resolution, just display it and disable zooming
|
// if we don't know the gifs' resolution, just display it and disable zooming
|
||||||
if (gifWidth == 0 || gifHeight == 0) {
|
if (gifWidth == 0 || gifHeight == 0) {
|
||||||
scaleType = ImageView.ScaleType.FIT_CENTER
|
scaleType = ImageView.ScaleType.FIT_CENTER
|
||||||
|
@ -81,10 +86,19 @@ class MyZoomableGifTextureView(context: Context, attrs: AttributeSet) : GifTextu
|
||||||
mTouchDownY = event.y
|
mTouchDownY = event.y
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_UP -> {
|
MotionEvent.ACTION_UP -> {
|
||||||
|
val diffX = mTouchDownX - event.x
|
||||||
|
val diffY = mTouchDownY - event.y
|
||||||
mCurrZoomMode = ZOOM_MODE_NONE
|
mCurrZoomMode = ZOOM_MODE_NONE
|
||||||
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
|
||||||
performClick()
|
performClick()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val downGestureDuration = System.currentTimeMillis() - mTouchDownTime
|
||||||
|
val areDiffsOK = Math.abs(diffY) > Math.abs(diffX) && diffY < -mCloseDownThreshold
|
||||||
|
if (mSaveScale == 1f && !mIgnoreCloseDown && areDiffsOK && context.config.allowDownGesture && downGestureDuration < MAX_CLOSE_DOWN_GESTURE_DURATION) {
|
||||||
|
mCloseDownCallback?.invoke()
|
||||||
|
}
|
||||||
|
mIgnoreCloseDown = false
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_POINTER_DOWN -> {
|
MotionEvent.ACTION_POINTER_DOWN -> {
|
||||||
mLastTouchX = event.x
|
mLastTouchX = event.x
|
||||||
|
|
Loading…
Reference in a new issue