From ef51271909959899cc9fe8cc6f5cd25ae57ebfa1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 9 Feb 2018 18:40:40 +0100 Subject: [PATCH] properly scale drag_threshold based on device density --- .../com/simplemobiletools/gallery/helpers/Constants.kt | 2 +- .../com/simplemobiletools/gallery/helpers/MediaSideScroll.kt | 5 +++-- .../com/simplemobiletools/gallery/views/InstantItemSwitch.kt | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index ab16d130f..b4ecd1a6d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -65,7 +65,7 @@ const val NOMEDIA = ".nomedia" const val MAX_COLUMN_COUNT = 20 const val SHOW_TEMP_HIDDEN_DURATION = 600000L const val CLICK_MAX_DURATION = 150 -const val DRAG_THRESHOLD = 15 +const val DRAG_THRESHOLD = 8 const val DIRECTORY = "directory" const val MEDIUM = "medium" diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt index 0ac4801eb..eca4fb337 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt @@ -25,6 +25,7 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co private var mLastTouchY = 0f private var mIsBrightnessScroll = false private var mPassTouches = false + private var dragThreshold = DRAG_THRESHOLD * context.resources.displayMetrics.density private var mSlideInfoText = "" private var mSlideInfoFadeHandler = Handler() @@ -76,7 +77,7 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co val diffX = mTouchDownX - event.x val diffY = mTouchDownY - event.y - if (Math.abs(diffY) > DRAG_THRESHOLD && Math.abs(diffY) > Math.abs(diffX)) { + if (Math.abs(diffY) > dragThreshold && Math.abs(diffY) > Math.abs(diffX)) { var percent = ((diffY / ViewPagerActivity.screenHeight) * 100).toInt() * 3 percent = Math.min(100, Math.max(-100, percent)) @@ -86,7 +87,7 @@ class MediaSideScroll(context: Context, attrs: AttributeSet) : RelativeLayout(co } percentChanged(percent) - } else if (Math.abs(diffX) > DRAG_THRESHOLD || Math.abs(diffY) > DRAG_THRESHOLD) { + } else if (Math.abs(diffX) > dragThreshold || Math.abs(diffY) > dragThreshold) { if (!mPassTouches) { event.action = MotionEvent.ACTION_DOWN event.setLocation(event.rawX, event.y) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/views/InstantItemSwitch.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/views/InstantItemSwitch.kt index f0d642a85..bdfe1264a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/views/InstantItemSwitch.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/views/InstantItemSwitch.kt @@ -14,6 +14,7 @@ class InstantItemSwitch(context: Context, attrs: AttributeSet) : RelativeLayout( private var mTouchDownX = 0f private var mTouchDownY = 0f private var passTouches = false + private var dragThreshold = DRAG_THRESHOLD * context.resources.displayMetrics.density var parentView: ViewGroup? = null @@ -50,7 +51,7 @@ class InstantItemSwitch(context: Context, attrs: AttributeSet) : RelativeLayout( val diffX = mTouchDownX - event.x val diffY = mTouchDownY - event.y - if (Math.abs(diffX) > DRAG_THRESHOLD || Math.abs(diffY) > DRAG_THRESHOLD) { + if (Math.abs(diffX) > dragThreshold || Math.abs(diffY) > dragThreshold) { if (!passTouches) { event.action = MotionEvent.ACTION_DOWN event.setLocation(event.rawX, event.y)