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 deltaX = e2.x - e1.x
if (Math.abs(deltaX) > Math.abs(deltaY)) {
// 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) {
canLaunchShortcut = false
appUtils.launchApp(rightSwipeActivity.first!!.componentName, launcherApps.profiles[rightSwipeActivity.second!!])
appUtils.launchApp(
rightSwipeActivity.first!!.componentName,
launcherApps.profiles[rightSwipeActivity.second!!]
)
} 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("right")) {
} else if (deltaX > 0 && abs(deltaX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold && !sharedPreferenceManager.isGestureEnabled(
"right"
)
) {
canLaunchShortcut = false
if (gestureUtils.isAccessibilityServiceEnabled(
ScreenLockService::class.java
@ -1174,9 +1187,30 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
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
else if (deltaY < -swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
if (deltaY < -swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
canLaunchShortcut = false
openAppMenu()
}
@ -1184,20 +1218,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
// Swipe down
else if (deltaY > swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
val statusBarService = getSystemService(Context.STATUS_BAR_SERVICE)
val statusBarManager: Class<*> = Class.forName("android.app.StatusBarManager")
val expandMethod: Method = statusBarManager.getMethod("expandNotificationsPanel")
val statusBarManager: Class<*> =
Class.forName("android.app.StatusBarManager")
val expandMethod: Method =
statusBarManager.getMethod("expandNotificationsPanel")
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