mirror of
				https://github.com/SimpleMobileTools/Simple-Launcher.git
				synced 2025-06-05 21:59:15 +02:00 
			
		
		
		
	do not ignore density at setting move gesture threshold
This commit is contained in:
		| @@ -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() | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -5,4 +5,5 @@ | ||||
|     <dimen name="widget_preview_size">140dp</dimen> | ||||
|     <dimen name="icon_side_margin">10dp</dimen> | ||||
|     <dimen name="resize_frame_dot_radius">8dp</dimen> | ||||
|     <dimen name="move_gesture_threshold">5dp</dimen> | ||||
| </resources> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user