Skip to content

Commit 9c98afb

Browse files
committed
adding some move threshold for easier long presses
1 parent aa97bb5 commit 9c98afb

File tree

1 file changed

+8
-4
lines changed
  • app/src/main/kotlin/com/simplemobiletools/launcher/activities

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import kotlinx.android.synthetic.main.widgets_fragment.view.*
5151
class MainActivity : SimpleActivity(), FlingListener {
5252
private val ANIMATION_DURATION = 150L
5353

54+
private var mTouchDownX = -1
5455
private var mTouchDownY = -1
5556
private var mAllAppsFragmentY = 0
5657
private var mWidgetsFragmentY = 0
@@ -241,21 +242,23 @@ class MainActivity : SimpleActivity(), FlingListener {
241242
mDetector.onTouchEvent(event)
242243
when (event.actionMasked) {
243244
MotionEvent.ACTION_DOWN -> {
245+
mTouchDownX = event.x.toInt()
244246
mTouchDownY = event.y.toInt()
245247
mAllAppsFragmentY = all_apps_fragment.y.toInt()
246248
mWidgetsFragmentY = widgets_fragment.y.toInt()
247249
mIgnoreUpEvent = false
248250
}
249251

250252
MotionEvent.ACTION_MOVE -> {
251-
if (mLongPressedIcon != null && mOpenPopupMenu != null && hasFingerMoved(event)) {
253+
val hasFingerMoved = hasFingerMoved(event)
254+
if (mLongPressedIcon != null && mOpenPopupMenu != null && hasFingerMoved) {
252255
mOpenPopupMenu?.dismiss()
253256
mOpenPopupMenu = null
254257
home_screen_grid.itemDraggingStarted(mLongPressedIcon!!)
255258
hideFragment(all_apps_fragment)
256259
}
257260

258-
if (mLongPressedIcon != null && hasFingerMoved(event)) {
261+
if (mLongPressedIcon != null && hasFingerMoved) {
259262
home_screen_grid.draggedItemMoved(event.x.toInt(), event.y.toInt())
260263
}
261264

@@ -276,6 +279,7 @@ class MainActivity : SimpleActivity(), FlingListener {
276279

277280
MotionEvent.ACTION_CANCEL,
278281
MotionEvent.ACTION_UP -> {
282+
mTouchDownX = -1
279283
mTouchDownY = -1
280284
mIgnoreMoveEvents = false
281285
mLongPressedIcon = null
@@ -303,8 +307,8 @@ class MainActivity : SimpleActivity(), FlingListener {
303307
}
304308

305309
// some devices ACTION_MOVE keeps triggering for the whole long press duration, but we are interested in real moves only, when coords change
306-
private fun hasFingerMoved(event: MotionEvent) = mLastTouchCoords.first != -1f && mLastTouchCoords.second != -1f &&
307-
(mLastTouchCoords.first != event.x || mLastTouchCoords.second != event.y)
310+
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)
308312

309313
private fun refetchLaunchers() {
310314
val launchers = getAllAppLaunchers()

0 commit comments

Comments
 (0)