Skip to content

Commit c59bfc9

Browse files
committed
do not ignore density at setting move gesture threshold
1 parent 09d9a7d commit c59bfc9

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class MainActivity : SimpleActivity(), FlingListener {
5656
private var mAllAppsFragmentY = 0
5757
private var mWidgetsFragmentY = 0
5858
private var mScreenHeight = 0
59+
private var mMoveGestureThreshold = 0
5960
private var mIgnoreUpEvent = false
6061
private var mIgnoreMoveEvents = false
6162
private var mLongPressedIcon: HomeScreenGridItem? = null
@@ -89,6 +90,7 @@ class MainActivity : SimpleActivity(), FlingListener {
8990
mScreenHeight = realScreenSize.y
9091
mAllAppsFragmentY = mScreenHeight
9192
mWidgetsFragmentY = mScreenHeight
93+
mMoveGestureThreshold = resources.getDimension(R.dimen.move_gesture_threshold).toInt()
9294

9395
arrayOf(all_apps_fragment as MyFragment, widgets_fragment as MyFragment).forEach { fragment ->
9496
fragment.setupFragment(this)
@@ -239,7 +241,11 @@ class MainActivity : SimpleActivity(), FlingListener {
239241
mLastUpEvent = System.currentTimeMillis()
240242
}
241243

242-
mDetector.onTouchEvent(event)
244+
try {
245+
mDetector.onTouchEvent(event)
246+
} catch (ignored: Exception) {
247+
}
248+
243249
when (event.actionMasked) {
244250
MotionEvent.ACTION_DOWN -> {
245251
mTouchDownX = event.x.toInt()
@@ -250,7 +256,15 @@ class MainActivity : SimpleActivity(), FlingListener {
250256
}
251257

252258
MotionEvent.ACTION_MOVE -> {
253-
val hasFingerMoved = hasFingerMoved(event)
259+
// if the initial gesture was handled by some other view, fix the Down values
260+
val hasFingerMoved = if (mTouchDownX == -1 || mTouchDownY == -1) {
261+
mTouchDownX = event.x.toInt()
262+
mTouchDownY = event.y.toInt()
263+
false
264+
} else {
265+
hasFingerMoved(event)
266+
}
267+
254268
if (mLongPressedIcon != null && mOpenPopupMenu != null && hasFingerMoved) {
255269
mOpenPopupMenu?.dismiss()
256270
mOpenPopupMenu = null
@@ -308,7 +322,7 @@ class MainActivity : SimpleActivity(), FlingListener {
308322

309323
// some devices ACTION_MOVE keeps triggering for the whole long press duration, but we are interested in real moves only, when coords change
310324
private fun hasFingerMoved(event: MotionEvent) = mTouchDownX != -1 && mTouchDownY != -1 &&
311-
(Math.abs(mTouchDownX - event.x) > MAX_ALLOWED_MOVE_PX) || (Math.abs(mTouchDownY - event.y) > MAX_ALLOWED_MOVE_PX)
325+
(Math.abs(mTouchDownX - event.x) > mMoveGestureThreshold) || (Math.abs(mTouchDownY - event.y) > mMoveGestureThreshold)
312326

313327
private fun refetchLaunchers() {
314328
val launchers = getAllAppLaunchers()

app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ const val ITEM_TYPE_WIDGET = 1
2020
const val ITEM_TYPE_SHORTCUT = 2
2121

2222
const val WIDGET_HOST_ID = 12345
23-
const val MAX_ALLOWED_MOVE_PX = 10
2423
const val MAX_CLICK_DURATION = 150

app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import android.graphics.PointF
66
import android.os.Handler
77
import android.view.MotionEvent
88
import android.view.ViewConfiguration
9-
import com.simplemobiletools.commons.extensions.performHapticFeedback
10-
import com.simplemobiletools.launcher.helpers.MAX_ALLOWED_MOVE_PX
9+
import com.simplemobiletools.launcher.R
1110

1211
class MyAppWidgetHostView(context: Context) : AppWidgetHostView(context) {
1312
private var longPressHandler = Handler()
1413
private var actionDownCoords = PointF()
1514
private var currentCoords = PointF()
1615
private var actionDownMS = 0L
16+
private val moveGestureThreshold = resources.getDimension(R.dimen.move_gesture_threshold).toInt()
1717
var hasLongPressed = false
1818
var ignoreTouches = false
1919
var longPressListener: ((x: Float, y: Float) -> Unit)? = null
@@ -60,7 +60,7 @@ class MyAppWidgetHostView(context: Context) : AppWidgetHostView(context) {
6060
}
6161

6262
private val longPressRunnable = Runnable {
63-
if (Math.abs(actionDownCoords.x - currentCoords.x) < MAX_ALLOWED_MOVE_PX && Math.abs(actionDownCoords.y - currentCoords.y) < MAX_ALLOWED_MOVE_PX) {
63+
if (Math.abs(actionDownCoords.x - currentCoords.x) < moveGestureThreshold && Math.abs(actionDownCoords.y - currentCoords.y) < moveGestureThreshold) {
6464
longPressHandler.removeCallbacksAndMessages(null)
6565
hasLongPressed = true
6666
longPressListener?.invoke(actionDownCoords.x, actionDownCoords.y)

app/src/main/res/values/dimens.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
<dimen name="widget_preview_size">140dp</dimen>
66
<dimen name="icon_side_margin">10dp</dimen>
77
<dimen name="resize_frame_dot_radius">8dp</dimen>
8+
<dimen name="move_gesture_threshold">5dp</dimen>
89
</resources>

0 commit comments

Comments
 (0)