work with ACTION_MOVE only if the finger really moved

This commit is contained in:
tibbi 2022-10-01 23:34:35 +02:00
parent 38f3e4034f
commit 2cf2918538
1 changed files with 9 additions and 3 deletions

View File

@ -47,7 +47,7 @@ class MainActivity : SimpleActivity(), FlingListener {
private var mLongPressedIcon: HomeScreenGridItem? = null private var mLongPressedIcon: HomeScreenGridItem? = null
private var mOpenPopupMenu: PopupMenu? = null private var mOpenPopupMenu: PopupMenu? = null
private var mCachedLaunchers = ArrayList<AppLauncher>() private var mCachedLaunchers = ArrayList<AppLauncher>()
private var mLastTouchCoords = Pair(0f, 0f) private var mLastTouchCoords = Pair(-1f, -1f)
private var mActionOnCanBindWidget: ((granted: Boolean) -> Unit)? = null private var mActionOnCanBindWidget: ((granted: Boolean) -> Unit)? = null
private var mActionOnWidgetConfiguredWidget: ((granted: Boolean) -> Unit)? = null private var mActionOnWidgetConfiguredWidget: ((granted: Boolean) -> Unit)? = null
@ -152,14 +152,14 @@ class MainActivity : SimpleActivity(), FlingListener {
} }
MotionEvent.ACTION_MOVE -> { MotionEvent.ACTION_MOVE -> {
if (mLongPressedIcon != null && mOpenPopupMenu != null && (mLastTouchCoords.first != event.x || mLastTouchCoords.second != event.y)) { if (mLongPressedIcon != null && mOpenPopupMenu != null && hasFingerMoved(event)) {
mOpenPopupMenu?.dismiss() mOpenPopupMenu?.dismiss()
mOpenPopupMenu = null mOpenPopupMenu = null
home_screen_grid.itemDraggingStarted(mLongPressedIcon!!) home_screen_grid.itemDraggingStarted(mLongPressedIcon!!)
hideFragment(all_apps_fragment) hideFragment(all_apps_fragment)
} }
if (mLongPressedIcon != null) { if (mLongPressedIcon != null && hasFingerMoved(event)) {
home_screen_grid.draggedItemMoved(event.x.toInt(), event.y.toInt()) home_screen_grid.draggedItemMoved(event.x.toInt(), event.y.toInt())
} }
@ -183,6 +183,7 @@ class MainActivity : SimpleActivity(), FlingListener {
mTouchDownY = -1 mTouchDownY = -1
mIgnoreMoveEvents = false mIgnoreMoveEvents = false
mLongPressedIcon = null mLongPressedIcon = null
mLastTouchCoords = Pair(-1f, -1f)
(widgets_fragment as WidgetsFragment).ignoreTouches = false (widgets_fragment as WidgetsFragment).ignoreTouches = false
(all_apps_fragment as AllAppsFragment).ignoreTouches = false (all_apps_fragment as AllAppsFragment).ignoreTouches = false
home_screen_grid.itemDraggingStopped() home_screen_grid.itemDraggingStopped()
@ -206,6 +207,11 @@ class MainActivity : SimpleActivity(), FlingListener {
return true return true
} }
// some devices ACTION_MOVE keeps triggering for the whole long press duration, but we are interested in real moves only, when coords change
private fun hasFingerMoved(event: MotionEvent) = mLastTouchCoords.first != -1f && mLastTouchCoords.second != -1f &&
(mLastTouchCoords.first != event.x || mLastTouchCoords.second != event.y)
private fun refetchLaunchers() { private fun refetchLaunchers() {
val launchers = getAllAppLaunchers() val launchers = getAllAppLaunchers()
(all_apps_fragment as AllAppsFragment).gotLaunchers(launchers) (all_apps_fragment as AllAppsFragment).gotLaunchers(launchers)