Decrease move gesture sensitivity

This commit is contained in:
Ensar Sarajčić 2023-07-20 12:40:28 +02:00
parent 35fe1da420
commit 8794f7ca23
3 changed files with 95 additions and 10 deletions

View File

@ -93,7 +93,7 @@ class MainActivity : SimpleActivity(), FlingListener {
mScreenHeight = realScreenSize.y mScreenHeight = realScreenSize.y
mAllAppsFragmentY = mScreenHeight mAllAppsFragmentY = mScreenHeight
mWidgetsFragmentY = mScreenHeight mWidgetsFragmentY = mScreenHeight
mMoveGestureThreshold = resources.getDimension(R.dimen.move_gesture_threshold).toInt() mMoveGestureThreshold = resources.getDimensionPixelSize(R.dimen.move_gesture_threshold)
arrayOf(all_apps_fragment as MyFragment, widgets_fragment as MyFragment).forEach { fragment -> arrayOf(all_apps_fragment as MyFragment, widgets_fragment as MyFragment).forEach { fragment ->
fragment.setupFragment(this) fragment.setupFragment(this)
@ -338,7 +338,7 @@ class MainActivity : SimpleActivity(), FlingListener {
home_screen_grid.draggedItemMoved(event.x.toInt(), event.y.toInt()) home_screen_grid.draggedItemMoved(event.x.toInt(), event.y.toInt())
} }
if (mTouchDownY != -1 && !mIgnoreMoveEvents) { if (hasFingerMoved && !mIgnoreMoveEvents) {
val diffY = mTouchDownY - event.y val diffY = mTouchDownY - event.y
if (isWidgetsFragmentExpanded()) { if (isWidgetsFragmentExpanded()) {
@ -384,7 +384,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 // 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 && private fun hasFingerMoved(event: MotionEvent) = mTouchDownX != -1 && mTouchDownY != -1 &&
(Math.abs(mTouchDownX - event.x) > mMoveGestureThreshold) || (Math.abs(mTouchDownY - event.y) > mMoveGestureThreshold) ((Math.abs(mTouchDownX - event.x) > mMoveGestureThreshold) || (Math.abs(mTouchDownY - event.y) > mMoveGestureThreshold))
private fun refetchLaunchers() { private fun refetchLaunchers() {
val launchers = getAllAppLaunchers() val launchers = getAllAppLaunchers()
@ -765,7 +765,24 @@ class MainActivity : SimpleActivity(), FlingListener {
val defaultDialerPackage = (getSystemService(Context.TELECOM_SERVICE) as TelecomManager).defaultDialerPackage val defaultDialerPackage = (getSystemService(Context.TELECOM_SERVICE) as TelecomManager).defaultDialerPackage
appLaunchers.firstOrNull { it.packageName == defaultDialerPackage }?.apply { appLaunchers.firstOrNull { it.packageName == defaultDialerPackage }?.apply {
val dialerIcon = val dialerIcon =
HomeScreenGridItem(null, 0, config.homeRowCount - 1, 0, config.homeRowCount - 1, 0, defaultDialerPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null, true) HomeScreenGridItem(
null,
0,
config.homeRowCount - 1,
0,
config.homeRowCount - 1,
0,
defaultDialerPackage,
"",
title,
ITEM_TYPE_ICON,
"",
-1,
"",
"",
null,
true
)
homeScreenGridItems.add(dialerIcon) homeScreenGridItems.add(dialerIcon)
} }
} catch (e: Exception) { } catch (e: Exception) {
@ -775,7 +792,24 @@ class MainActivity : SimpleActivity(), FlingListener {
val defaultSMSMessengerPackage = Telephony.Sms.getDefaultSmsPackage(this) val defaultSMSMessengerPackage = Telephony.Sms.getDefaultSmsPackage(this)
appLaunchers.firstOrNull { it.packageName == defaultSMSMessengerPackage }?.apply { appLaunchers.firstOrNull { it.packageName == defaultSMSMessengerPackage }?.apply {
val SMSMessengerIcon = val SMSMessengerIcon =
HomeScreenGridItem(null, 1, config.homeRowCount - 1, 1, config.homeRowCount - 1, 0, defaultSMSMessengerPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null, true) HomeScreenGridItem(
null,
1,
config.homeRowCount - 1,
1,
config.homeRowCount - 1,
0,
defaultSMSMessengerPackage,
"",
title,
ITEM_TYPE_ICON,
"",
-1,
"",
"",
null,
true
)
homeScreenGridItems.add(SMSMessengerIcon) homeScreenGridItems.add(SMSMessengerIcon)
} }
} catch (e: Exception) { } catch (e: Exception) {
@ -787,7 +821,24 @@ class MainActivity : SimpleActivity(), FlingListener {
val defaultBrowserPackage = resolveInfo!!.activityInfo.packageName val defaultBrowserPackage = resolveInfo!!.activityInfo.packageName
appLaunchers.firstOrNull { it.packageName == defaultBrowserPackage }?.apply { appLaunchers.firstOrNull { it.packageName == defaultBrowserPackage }?.apply {
val browserIcon = val browserIcon =
HomeScreenGridItem(null, 2, config.homeRowCount - 1, 2, config.homeRowCount - 1, 0, defaultBrowserPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null, true) HomeScreenGridItem(
null,
2,
config.homeRowCount - 1,
2,
config.homeRowCount - 1,
0,
defaultBrowserPackage,
"",
title,
ITEM_TYPE_ICON,
"",
-1,
"",
"",
null,
true
)
homeScreenGridItems.add(browserIcon) homeScreenGridItems.add(browserIcon)
} }
} catch (e: Exception) { } catch (e: Exception) {
@ -798,7 +849,24 @@ class MainActivity : SimpleActivity(), FlingListener {
val storePackage = potentialStores.firstOrNull { isPackageInstalled(it) && appLaunchers.map { it.packageName }.contains(it) } val storePackage = potentialStores.firstOrNull { isPackageInstalled(it) && appLaunchers.map { it.packageName }.contains(it) }
if (storePackage != null) { if (storePackage != null) {
appLaunchers.firstOrNull { it.packageName == storePackage }?.apply { appLaunchers.firstOrNull { it.packageName == storePackage }?.apply {
val storeIcon = HomeScreenGridItem(null, 3, config.homeRowCount - 1, 3, config.homeRowCount - 1, 0, storePackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null, true) val storeIcon = HomeScreenGridItem(
null,
3,
config.homeRowCount - 1,
3,
config.homeRowCount - 1,
0,
storePackage,
"",
title,
ITEM_TYPE_ICON,
"",
-1,
"",
"",
null,
true
)
homeScreenGridItems.add(storeIcon) homeScreenGridItems.add(storeIcon)
} }
} }
@ -811,7 +879,24 @@ class MainActivity : SimpleActivity(), FlingListener {
val defaultCameraPackage = resolveInfo!!.activityInfo.packageName val defaultCameraPackage = resolveInfo!!.activityInfo.packageName
appLaunchers.firstOrNull { it.packageName == defaultCameraPackage }?.apply { appLaunchers.firstOrNull { it.packageName == defaultCameraPackage }?.apply {
val cameraIcon = val cameraIcon =
HomeScreenGridItem(null, 4, config.homeRowCount - 1, 4, config.homeRowCount - 1, 0, defaultCameraPackage, "", title, ITEM_TYPE_ICON, "", -1, "", "", null, true) HomeScreenGridItem(
null,
4,
config.homeRowCount - 1,
4,
config.homeRowCount - 1,
0,
defaultCameraPackage,
"",
title,
ITEM_TYPE_ICON,
"",
-1,
"",
"",
null,
true
)
homeScreenGridItems.add(cameraIcon) homeScreenGridItems.add(cameraIcon)
} }
} catch (e: Exception) { } catch (e: Exception) {

View File

@ -1060,7 +1060,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
companion object { companion object {
private const val ANIMATION_DURATION = 700L private const val ANIMATION_DURATION = 700L
private const val PAGE_CHANGE_BLOCKING_DURATION = ANIMATION_DURATION + 200L private const val PAGE_CHANGE_BLOCKING_DURATION = ANIMATION_DURATION
private const val PAGE_CHANGE_HOLD_THRESHOLD = 500L private const val PAGE_CHANGE_HOLD_THRESHOLD = 500L
private enum class PageChangeArea { private enum class PageChangeArea {

View File

@ -5,7 +5,7 @@
<dimen name="widget_preview_size">140dp</dimen> <dimen name="widget_preview_size">140dp</dimen>
<dimen name="icon_side_margin">10dp</dimen> <dimen name="icon_side_margin">10dp</dimen>
<dimen name="resize_frame_dot_radius">8dp</dimen> <dimen name="resize_frame_dot_radius">8dp</dimen>
<dimen name="move_gesture_threshold">5dp</dimen> <dimen name="move_gesture_threshold">20dp</dimen>
<dimen name="page_indicator_dot_radius">4dp</dimen> <dimen name="page_indicator_dot_radius">4dp</dimen>
<dimen name="page_indicator_stroke_width">1dp</dimen> <dimen name="page_indicator_stroke_width">1dp</dimen>
<dimen name="page_indicator_margin">4dp</dimen> <dimen name="page_indicator_margin">4dp</dimen>