From c7bc9167840d48852f87eb5d3c8b9cdb133effb4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 18 Feb 2020 12:09:23 +0100 Subject: [PATCH] simplify the brightness/volume area clicks, use a gesture detector --- .../gallery/pro/views/MediaSideScroll.kt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MediaSideScroll.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MediaSideScroll.kt index 50a338666..e21fce85b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MediaSideScroll.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/MediaSideScroll.kt @@ -6,6 +6,7 @@ import android.media.AudioManager import android.os.Handler import android.provider.Settings import android.util.AttributeSet +import android.view.GestureDetector import android.view.MotionEvent import android.view.ViewGroup import android.widget.RelativeLayout @@ -13,8 +14,6 @@ import android.widget.TextView import com.simplemobiletools.commons.extensions.onGlobalLayout import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.extensions.audioManager -import com.simplemobiletools.gallery.pro.helpers.CLICK_MAX_DISTANCE -import com.simplemobiletools.gallery.pro.helpers.CLICK_MAX_DURATION import com.simplemobiletools.gallery.pro.helpers.DRAG_THRESHOLD // allow horizontal swipes through the layout, else it can cause glitches at zoomed in images @@ -51,6 +50,15 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co } } + private val gestureDetector = GestureDetector(context, object : GestureDetector.SimpleOnGestureListener() { + override fun onSingleTapConfirmed(e: MotionEvent?): Boolean { + if (e != null) { + callback(e.rawX, e.rawY) + } + return true + } + }) + override fun dispatchTouchEvent(ev: MotionEvent): Boolean { if (mPassTouches) { if (ev.actionMasked == MotionEvent.ACTION_DOWN) { @@ -66,6 +74,7 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co return false } + gestureDetector.onTouchEvent(event) when (event.actionMasked) { MotionEvent.ACTION_DOWN -> { mTouchDownX = event.x @@ -107,12 +116,6 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co mLastTouchY = event.y } MotionEvent.ACTION_UP -> { - val diffX = mTouchDownX - event.x - val diffY = mTouchDownY - event.y - if (Math.abs(diffX) < CLICK_MAX_DISTANCE && Math.abs(diffY) < CLICK_MAX_DISTANCE && System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION) { - callback(event.rawX, event.rawY) - } - if (mIsBrightnessScroll) { mTouchDownValue = mTempBrightness }