handle closing GIF view with down gesture

This commit is contained in:
tibbi 2019-01-16 22:00:28 +01:00
parent 95492d5e06
commit f495a0790e
2 changed files with 18 additions and 7 deletions

View file

@ -103,11 +103,6 @@ class PhotoFragment : ViewPagerFragment() {
}
if (context.config.allowDownGesture) {
gif_view.setOnTouchListener { v, event ->
handleEvent(event)
false
}
subsampling_view.setOnTouchListener { v, event ->
if (mView.subsampling_view.scale == mOriginalSubsamplingScale) {
handleEvent(event)
@ -311,7 +306,9 @@ class PhotoFragment : ViewPagerFragment() {
val resolution = mMedium.path.getImageResolution() ?: Point(0, 0)
mView.gif_view.apply {
setInputSource(source)
setupSizes(resolution.x, resolution.y, mScreenWidth, mScreenHeight)
setupGIFView(resolution.x, resolution.y, mScreenWidth, mScreenHeight) {
activity?.supportFinishAfterTransition()
}
}
} catch (e: Exception) {
loadBitmap()

View file

@ -8,6 +8,7 @@ import android.view.MotionEvent
import android.view.ScaleGestureDetector
import android.widget.ImageView
import com.simplemobiletools.commons.extensions.beVisible
import com.simplemobiletools.gallery.pro.extensions.config
import com.simplemobiletools.gallery.pro.helpers.*
import pl.droidsonroids.gif.GifTextureView
@ -25,18 +26,22 @@ class MyZoomableGifTextureView(context: Context, attrs: AttributeSet) : GifTextu
private var mScreenHeight = 0f
private var mLastFocusX = 0f
private var mLastFocusY = 0f
private var mCloseDownThreshold = 100f
private var mIgnoreCloseDown = false
private var mCurrZoomMode = ZOOM_MODE_NONE
private var mScaleDetector: ScaleGestureDetector? = null
private var mMatrices = FloatArray(9)
private val mMatrix = Matrix()
private var mCurrentViewport = RectF()
private var mCloseDownCallback: (() -> Unit)? = null
init {
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 (gifWidth == 0 || gifHeight == 0) {
scaleType = ImageView.ScaleType.FIT_CENTER
@ -81,10 +86,19 @@ class MyZoomableGifTextureView(context: Context, attrs: AttributeSet) : GifTextu
mTouchDownY = event.y
}
MotionEvent.ACTION_UP -> {
val diffX = mTouchDownX - event.x
val diffY = mTouchDownY - event.y
mCurrZoomMode = ZOOM_MODE_NONE
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) {
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 -> {
mLastTouchX = event.x