@@ -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()
0 commit comments