diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt
index fece46c..9725e4f 100644
--- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt
@@ -56,6 +56,7 @@ class MainActivity : SimpleActivity(), FlingListener {
private var mAllAppsFragmentY = 0
private var mWidgetsFragmentY = 0
private var mScreenHeight = 0
+ private var mMoveGestureThreshold = 0
private var mIgnoreUpEvent = false
private var mIgnoreMoveEvents = false
private var mLongPressedIcon: HomeScreenGridItem? = null
@@ -89,6 +90,7 @@ class MainActivity : SimpleActivity(), FlingListener {
mScreenHeight = realScreenSize.y
mAllAppsFragmentY = mScreenHeight
mWidgetsFragmentY = mScreenHeight
+ mMoveGestureThreshold = resources.getDimension(R.dimen.move_gesture_threshold).toInt()
arrayOf(all_apps_fragment as MyFragment, widgets_fragment as MyFragment).forEach { fragment ->
fragment.setupFragment(this)
@@ -239,7 +241,11 @@ class MainActivity : SimpleActivity(), FlingListener {
mLastUpEvent = System.currentTimeMillis()
}
- mDetector.onTouchEvent(event)
+ try {
+ mDetector.onTouchEvent(event)
+ } catch (ignored: Exception) {
+ }
+
when (event.actionMasked) {
MotionEvent.ACTION_DOWN -> {
mTouchDownX = event.x.toInt()
@@ -250,7 +256,15 @@ class MainActivity : SimpleActivity(), FlingListener {
}
MotionEvent.ACTION_MOVE -> {
- val hasFingerMoved = hasFingerMoved(event)
+ // if the initial gesture was handled by some other view, fix the Down values
+ val hasFingerMoved = if (mTouchDownX == -1 || mTouchDownY == -1) {
+ mTouchDownX = event.x.toInt()
+ mTouchDownY = event.y.toInt()
+ false
+ } else {
+ hasFingerMoved(event)
+ }
+
if (mLongPressedIcon != null && mOpenPopupMenu != null && hasFingerMoved) {
mOpenPopupMenu?.dismiss()
mOpenPopupMenu = null
@@ -308,7 +322,7 @@ 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
private fun hasFingerMoved(event: MotionEvent) = mTouchDownX != -1 && mTouchDownY != -1 &&
- (Math.abs(mTouchDownX - event.x) > MAX_ALLOWED_MOVE_PX) || (Math.abs(mTouchDownY - event.y) > MAX_ALLOWED_MOVE_PX)
+ (Math.abs(mTouchDownX - event.x) > mMoveGestureThreshold) || (Math.abs(mTouchDownY - event.y) > mMoveGestureThreshold)
private fun refetchLaunchers() {
val launchers = getAllAppLaunchers()
diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt
index a86f3b8..299c883 100644
--- a/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/launcher/helpers/Constants.kt
@@ -20,5 +20,4 @@ const val ITEM_TYPE_WIDGET = 1
const val ITEM_TYPE_SHORTCUT = 2
const val WIDGET_HOST_ID = 12345
-const val MAX_ALLOWED_MOVE_PX = 10
const val MAX_CLICK_DURATION = 150
diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt
index 939fd87..082cd49 100644
--- a/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/launcher/views/MyAppWidgetHostView.kt
@@ -6,14 +6,14 @@ import android.graphics.PointF
import android.os.Handler
import android.view.MotionEvent
import android.view.ViewConfiguration
-import com.simplemobiletools.commons.extensions.performHapticFeedback
-import com.simplemobiletools.launcher.helpers.MAX_ALLOWED_MOVE_PX
+import com.simplemobiletools.launcher.R
class MyAppWidgetHostView(context: Context) : AppWidgetHostView(context) {
private var longPressHandler = Handler()
private var actionDownCoords = PointF()
private var currentCoords = PointF()
private var actionDownMS = 0L
+ private val moveGestureThreshold = resources.getDimension(R.dimen.move_gesture_threshold).toInt()
var hasLongPressed = false
var ignoreTouches = false
var longPressListener: ((x: Float, y: Float) -> Unit)? = null
@@ -60,7 +60,7 @@ class MyAppWidgetHostView(context: Context) : AppWidgetHostView(context) {
}
private val longPressRunnable = Runnable {
- if (Math.abs(actionDownCoords.x - currentCoords.x) < MAX_ALLOWED_MOVE_PX && Math.abs(actionDownCoords.y - currentCoords.y) < MAX_ALLOWED_MOVE_PX) {
+ if (Math.abs(actionDownCoords.x - currentCoords.x) < moveGestureThreshold && Math.abs(actionDownCoords.y - currentCoords.y) < moveGestureThreshold) {
longPressHandler.removeCallbacksAndMessages(null)
hasLongPressed = true
longPressListener?.invoke(actionDownCoords.x, actionDownCoords.y)
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index 713f9f2..1b0c39a 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -5,4 +5,5 @@
140dp
10dp
8dp
+ 5dp