Separate vertical and horizontal swipes

This commit is contained in:
He4eT 2025-01-31 04:25:37 +01:00
commit 796417768d

View file

@ -1151,16 +1151,29 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
val deltaY = e2.y - e1.y val deltaY = e2.y - e1.y
val deltaX = e2.x - e1.x val deltaX = e2.x - e1.x
if (Math.abs(deltaX) > Math.abs(deltaY)) {
// Swipe right // Swipe right
if (deltaX > 0 && abs(deltaX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold && sharedPreferenceManager.isGestureEnabled("right")) { if (deltaX > 0 && abs(deltaX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold && sharedPreferenceManager.isGestureEnabled(
"right"
)
) {
if (rightSwipeActivity.first != null && rightSwipeActivity.second != null) { if (rightSwipeActivity.first != null && rightSwipeActivity.second != null) {
canLaunchShortcut = false canLaunchShortcut = false
appUtils.launchApp(rightSwipeActivity.first!!.componentName, launcherApps.profiles[rightSwipeActivity.second!!]) appUtils.launchApp(
rightSwipeActivity.first!!.componentName,
launcherApps.profiles[rightSwipeActivity.second!!]
)
} else { } else {
Toast.makeText(this@MainActivity, getString(R.string.launch_error), Toast.LENGTH_SHORT).show() Toast.makeText(
this@MainActivity,
getString(R.string.launch_error),
Toast.LENGTH_SHORT
).show()
} }
} } else if (deltaX > 0 && abs(deltaX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold && !sharedPreferenceManager.isGestureEnabled(
else if (deltaX > 0 && abs(deltaX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold && !sharedPreferenceManager.isGestureEnabled("right")) { "right"
)
) {
canLaunchShortcut = false canLaunchShortcut = false
if (gestureUtils.isAccessibilityServiceEnabled( if (gestureUtils.isAccessibilityServiceEnabled(
ScreenLockService::class.java ScreenLockService::class.java
@ -1174,9 +1187,30 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
gestureUtils.promptEnableAccessibility() gestureUtils.promptEnableAccessibility()
} }
} }
// Swipe left
else if (deltaX < 0 && abs(deltaX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold && sharedPreferenceManager.isGestureEnabled(
"left"
)
) {
println(leftSwipeActivity)
if (leftSwipeActivity.first != null && leftSwipeActivity.second != null) {
canLaunchShortcut = false
appUtils.launchApp(
leftSwipeActivity.first!!.componentName,
launcherApps.profiles[leftSwipeActivity.second!!]
)
} else {
Toast.makeText(
this@MainActivity,
getString(R.string.launch_error),
Toast.LENGTH_SHORT
).show()
}
}
} else {
// Swipe up // Swipe up
else if (deltaY < -swipeThreshold && abs(velocityY) > swipeVelocityThreshold) { if (deltaY < -swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
canLaunchShortcut = false canLaunchShortcut = false
openAppMenu() openAppMenu()
} }
@ -1184,20 +1218,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
// Swipe down // Swipe down
else if (deltaY > swipeThreshold && abs(velocityY) > swipeVelocityThreshold) { else if (deltaY > swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
val statusBarService = getSystemService(Context.STATUS_BAR_SERVICE) val statusBarService = getSystemService(Context.STATUS_BAR_SERVICE)
val statusBarManager: Class<*> = Class.forName("android.app.StatusBarManager") val statusBarManager: Class<*> =
val expandMethod: Method = statusBarManager.getMethod("expandNotificationsPanel") Class.forName("android.app.StatusBarManager")
val expandMethod: Method =
statusBarManager.getMethod("expandNotificationsPanel")
expandMethod.invoke(statusBarService) expandMethod.invoke(statusBarService)
} }
// Swipe left
else if (deltaX < 0 && abs(deltaX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold && sharedPreferenceManager.isGestureEnabled("left")){
println(leftSwipeActivity)
if (leftSwipeActivity.first != null && leftSwipeActivity.second != null) {
canLaunchShortcut = false
appUtils.launchApp(leftSwipeActivity.first!!.componentName, launcherApps.profiles[leftSwipeActivity.second!!])
} else {
Toast.makeText(this@MainActivity, getString(R.string.launch_error), Toast.LENGTH_SHORT).show()
}
} }
} }
return true return true