mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-03-30 19:10:10 +02:00
adding some move threshold for easier long presses
This commit is contained in:
parent
aa97bb55df
commit
9c98afbd62
@ -51,6 +51,7 @@ import kotlinx.android.synthetic.main.widgets_fragment.view.*
|
|||||||
class MainActivity : SimpleActivity(), FlingListener {
|
class MainActivity : SimpleActivity(), FlingListener {
|
||||||
private val ANIMATION_DURATION = 150L
|
private val ANIMATION_DURATION = 150L
|
||||||
|
|
||||||
|
private var mTouchDownX = -1
|
||||||
private var mTouchDownY = -1
|
private var mTouchDownY = -1
|
||||||
private var mAllAppsFragmentY = 0
|
private var mAllAppsFragmentY = 0
|
||||||
private var mWidgetsFragmentY = 0
|
private var mWidgetsFragmentY = 0
|
||||||
@ -241,6 +242,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
mDetector.onTouchEvent(event)
|
mDetector.onTouchEvent(event)
|
||||||
when (event.actionMasked) {
|
when (event.actionMasked) {
|
||||||
MotionEvent.ACTION_DOWN -> {
|
MotionEvent.ACTION_DOWN -> {
|
||||||
|
mTouchDownX = event.x.toInt()
|
||||||
mTouchDownY = event.y.toInt()
|
mTouchDownY = event.y.toInt()
|
||||||
mAllAppsFragmentY = all_apps_fragment.y.toInt()
|
mAllAppsFragmentY = all_apps_fragment.y.toInt()
|
||||||
mWidgetsFragmentY = widgets_fragment.y.toInt()
|
mWidgetsFragmentY = widgets_fragment.y.toInt()
|
||||||
@ -248,14 +250,15 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MotionEvent.ACTION_MOVE -> {
|
MotionEvent.ACTION_MOVE -> {
|
||||||
if (mLongPressedIcon != null && mOpenPopupMenu != null && hasFingerMoved(event)) {
|
val hasFingerMoved = hasFingerMoved(event)
|
||||||
|
if (mLongPressedIcon != null && mOpenPopupMenu != null && hasFingerMoved) {
|
||||||
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 && hasFingerMoved(event)) {
|
if (mLongPressedIcon != null && hasFingerMoved) {
|
||||||
home_screen_grid.draggedItemMoved(event.x.toInt(), event.y.toInt())
|
home_screen_grid.draggedItemMoved(event.x.toInt(), event.y.toInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,6 +279,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
|
|
||||||
MotionEvent.ACTION_CANCEL,
|
MotionEvent.ACTION_CANCEL,
|
||||||
MotionEvent.ACTION_UP -> {
|
MotionEvent.ACTION_UP -> {
|
||||||
|
mTouchDownX = -1
|
||||||
mTouchDownY = -1
|
mTouchDownY = -1
|
||||||
mIgnoreMoveEvents = false
|
mIgnoreMoveEvents = false
|
||||||
mLongPressedIcon = null
|
mLongPressedIcon = null
|
||||||
@ -303,8 +307,8 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// some devices ACTION_MOVE keeps triggering for the whole long press duration, but we are interested in real moves only, when coords change
|
// 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 &&
|
private fun hasFingerMoved(event: MotionEvent) = mTouchDownX != -1 && mTouchDownY != -1 &&
|
||||||
(mLastTouchCoords.first != event.x || mLastTouchCoords.second != event.y)
|
(Math.abs(mTouchDownX - event.x) > MAX_ALLOWED_MOVE_PX) || (Math.abs(mTouchDownY - event.y) > MAX_ALLOWED_MOVE_PX)
|
||||||
|
|
||||||
private fun refetchLaunchers() {
|
private fun refetchLaunchers() {
|
||||||
val launchers = getAllAppLaunchers()
|
val launchers = getAllAppLaunchers()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user