Adjusted shortcut clicks to only happen if a swipe isn't detected and made swipe thresholds customizable

This commit is contained in:
ottoptj 2024-09-24 15:36:45 +03:00
commit db49cdf7c4
4 changed files with 55 additions and 6 deletions

View file

@ -105,9 +105,11 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
private var isBatteryReceiverRegistered = false private var isBatteryReceiverRegistered = false
private var isJobActive = true private var isJobActive = true
private var isInitialOpen = false
private var canLaunchShortcut = true
private val swipeThreshold = 100 private var swipeThreshold = 100
private val swipeVelocityThreshold = 100 private var swipeVelocityThreshold = 100
private lateinit var clockApp: Pair<LauncherActivityInfo?, Int?> private lateinit var clockApp: Pair<LauncherActivityInfo?, Int?>
private lateinit var dateApp: Pair<LauncherActivityInfo?, Int?> private lateinit var dateApp: Pair<LauncherActivityInfo?, Int?>
@ -120,8 +122,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
var returnAllowed = true var returnAllowed = true
private var isInitialOpen = false
private val handler = Handler(Looper.getMainLooper()) private val handler = Handler(Looper.getMainLooper())
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -295,9 +295,11 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
private fun unsetShortcutListeners(textView: TextView) { private fun unsetShortcutListeners(textView: TextView) {
textView.setOnClickListener { textView.setOnClickListener {
if (canLaunchShortcut) {
Toast.makeText(this, "Long click to select an app", Toast.LENGTH_SHORT).show() Toast.makeText(this, "Long click to select an app", Toast.LENGTH_SHORT).show()
} }
} }
}
private fun setShortcutSetup(textView: TextView, savedView: List<String>?) { private fun setShortcutSetup(textView: TextView, savedView: List<String>?) {
// Set the work profile drawable for work profile apps // Set the work profile drawable for work profile apps
@ -311,7 +313,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
private fun setShortcutListeners(textView: TextView, savedView: List<String>?) { private fun setShortcutListeners(textView: TextView, savedView: List<String>?) {
textView.setOnClickListener { textView.setOnClickListener {
if (savedView != null) { if (savedView != null && canLaunchShortcut) {
appUtils.launchApp(savedView[0], launcherApps.profiles[savedView[1].toInt()]) appUtils.launchApp(savedView[0], launcherApps.profiles[savedView[1].toInt()])
} }
} }
@ -353,6 +355,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
leftSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "left") leftSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "left")
rightSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "right") rightSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "right")
swipeThreshold = sharedPreferenceManager.getSwipeThreshold()
swipeVelocityThreshold = sharedPreferenceManager.getSwipeVelocity()
} }
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@ -583,6 +588,14 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
setShortcuts() setShortcuts()
} }
"swipeThreshold" -> {
swipeThreshold = sharedPreferenceManager.getSwipeThreshold()
}
"swipeVelocity" -> {
swipeVelocityThreshold = sharedPreferenceManager.getSwipeVelocity()
}
"isRestored" -> { "isRestored" -> {
preferences.edit().remove("isRestored").apply() preferences.edit().remove("isRestored").apply()
setPreferences() setPreferences()
@ -604,6 +617,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
} }
fun backToHome(animSpeed: Long = sharedPreferenceManager.getAnimationSpeed()) { fun backToHome(animSpeed: Long = sharedPreferenceManager.getAnimationSpeed()) {
canLaunchShortcut = true
closeKeyboard() closeKeyboard()
animations.showHome(binding.homeView, binding.appView, animSpeed) animations.showHome(binding.homeView, binding.appView, animSpeed)
animations.backgroundOut(this@MainActivity, animSpeed) animations.backgroundOut(this@MainActivity, animSpeed)
@ -1012,6 +1026,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
// Swipe up // Swipe up
if (deltaY < -swipeThreshold && abs(velocityY) > swipeVelocityThreshold) { if (deltaY < -swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
canLaunchShortcut = false
openAppMenu() openAppMenu()
} }

View file

@ -55,6 +55,14 @@ class SharedPreferenceManager (private val context: Context) {
return 200 return 200
} }
fun getSwipeThreshold(): Int {
return preferences.getString("swipeThreshold", "100")?.toInt() ?: 100
}
fun getSwipeVelocity(): Int {
return preferences.getString("swipeVelocity", "100")?.toInt() ?: 100
}
// Home Screen // Home Screen
fun isClockEnabled(): Boolean { fun isClockEnabled(): Boolean {
return preferences.getBoolean("clockEnabled", true) return preferences.getBoolean("clockEnabled", true)

View file

@ -99,6 +99,14 @@
<item>50</item> <item>50</item>
</string-array> </string-array>
<string-array name="swipe_values">
<item>25</item>
<item>50</item>
<item>100</item>
<item>200</item>
<item>400</item>
</string-array>
<!--Home and App Menu--> <!--Home and App Menu-->
<string-array name="shortcut_options"> <string-array name="shortcut_options">
<item>0</item> <item>0</item>

View file

@ -56,6 +56,24 @@
app:key="animationSpeed" app:key="animationSpeed"
app:title="Animation Speed" app:title="Animation Speed"
app:useSimpleSummaryProvider="true" /> app:useSimpleSummaryProvider="true" />
<eu.ottop.yamlauncher.settings.SpinnerPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="200"
android:entries="@array/animation_options"
android:entryValues="@array/swipe_values"
app:key="swipeThreshold"
app:title="Swipe Threshold"
app:useSimpleSummaryProvider="true" />
<eu.ottop.yamlauncher.settings.SpinnerPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="200"
android:entries="@array/animation_options"
android:entryValues="@array/swipe_values"
app:key="swipeVelocity"
app:title="Swipe Velocity Threshold"
app:useSimpleSummaryProvider="true" />
<SwitchPreference <SwitchPreference
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"