From 562e728c69e7fd5b8899952558dbe277a8dcc296 Mon Sep 17 00:00:00 2001 From: ottoptj Date: Fri, 30 Aug 2024 14:44:31 +0300 Subject: [PATCH] Added accessibility actions for choosing a shortcut, opening the app menu and closing the app menu --- .../eu/ottop/yamlauncher/AppMenuAdapter.kt | 5 +++ .../java/eu/ottop/yamlauncher/MainActivity.kt | 38 +++++++++++++++---- .../settings/SharedPreferenceManager.kt | 1 - 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt index a8b976d..c508807 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt @@ -14,6 +14,7 @@ import android.widget.FrameLayout import android.widget.LinearLayout import android.widget.TextView import androidx.core.content.res.ResourcesCompat +import androidx.core.view.ViewCompat import androidx.recyclerview.widget.RecyclerView import com.google.android.material.textfield.TextInputEditText import eu.ottop.yamlauncher.databinding.ActivityMainBinding @@ -181,6 +182,10 @@ class AppMenuAdapter( appActivity ) } + ViewCompat.addAccessibilityAction(holder.textView, "Close App Menu") { _, _ -> + activity.backToHome() + true + } } override fun getItemCount(): Int { diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index bc78ead..ed33920 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -207,6 +207,25 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh super.onTouchEvent(event) } + ViewCompat.addAccessibilityAction(textView, "Set Shortcut App") { _, _ -> + uiUtils.setMenuTitleAlignment(binding.menuTitle) + binding.menuTitle.visibility = View.VISIBLE + + adapter?.shortcutTextView = textView + toAppMenu() + true + } + + ViewCompat.addAccessibilityAction(textView, "Launcher Settings") { _, _ -> + startActivity(Intent(this@MainActivity, SettingsActivity::class.java)) + true + } + + ViewCompat.addAccessibilityAction(textView, "Open App Menu") { _, _ -> + openAppMenu() + true + } + textView.setOnLongClickListener { uiUtils.setMenuTitleAlignment(binding.menuTitle) binding.menuTitle.visibility = View.VISIBLE @@ -314,11 +333,16 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh true } - ViewCompat.addAccessibilityAction(binding.homeView, "Preferences") { _, _ -> + ViewCompat.addAccessibilityAction(binding.homeView, "Launcher Settings") { _, _ -> startActivity(Intent(this@MainActivity, SettingsActivity::class.java)) true } + ViewCompat.addAccessibilityAction(binding.homeView, "Open App Menu") { _, _ -> + openAppMenu() + true + } + // Return to home on back onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { @@ -341,6 +365,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } } + private fun openAppMenu() { + adapter?.shortcutTextView = null + binding.menuTitle.visibility = View.GONE + toAppMenu() + } + // Only reload items that have had preferences changed override fun onSharedPreferenceChanged(preferences: SharedPreferences?, key: String?) { if (preferences != null) { @@ -773,12 +803,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } - private fun openAppMenu() { - adapter?.shortcutTextView = null - binding.menuTitle.visibility = View.GONE - toAppMenu() - } - } inner class TextGestureListener : GestureListener() { diff --git a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt index 7f7c348..6b3a545 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt @@ -5,7 +5,6 @@ import android.graphics.Color import android.util.TypedValue import android.widget.TextView import androidx.preference.PreferenceManager -import eu.ottop.yamlauncher.R class SharedPreferenceManager (private val context: Context) {