Made the context menu customizable

This commit is contained in:
ottoptj 2024-12-22 03:13:49 +02:00
commit bafd446229
12 changed files with 260 additions and 56 deletions

View file

@ -52,4 +52,5 @@ dependencies {
implementation("androidx.preference:preference-ktx:1.2.1") implementation("androidx.preference:preference-ktx:1.2.1")
implementation("androidx.activity:activity-ktx:1.9.3") implementation("androidx.activity:activity-ktx:1.9.3")
implementation("androidx.constraintlayout:constraintlayout:2.2.0") implementation("androidx.constraintlayout:constraintlayout:2.2.0")
implementation("androidx.preference:preference:1.2.1")
} }

View file

@ -38,76 +38,134 @@ class AppActionMenu(private val activity: MainActivity, private val binding: Act
userHandle: UserHandle, userHandle: UserHandle,
workProfile: Int workProfile: Int
){ ){
ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_info)) { _, _ -> val pinButton = actionMenu.findViewById<TextView>(R.id.pin)
val infoButton = actionMenu.findViewById<TextView>(R.id.info)
val uninstallButton = actionMenu.findViewById<TextView>(R.id.uninstall)
val renameButton = actionMenu.findViewById<TextView>(R.id.rename)
val hideButton = actionMenu.findViewById<TextView>(R.id.hide)
val closeButton = actionMenu.findViewById<TextView>(R.id.close)
val enablePin = sharedPreferenceManager.isPinEnabled()
val enableInfo = sharedPreferenceManager.isInfoEnabled()
val enableUninstall = sharedPreferenceManager.isUninstallEnabled()
val enableRename = sharedPreferenceManager.isRenameEnabled()
val enableHide = sharedPreferenceManager.isHideEnabled()
val enableClose = sharedPreferenceManager.isCloseEnabled()
if (enablePin) {
pinButton.visibility = View.VISIBLE
setPinState(pinButton, appActivity, workProfile)
ViewCompat.addAccessibilityAction(
textView,
activity.getString(R.string.accessibility_pin)
) { _, _ ->
pinApp(appActivity, workProfile)
true
}
pinButton.setOnClickListener {
pinApp(appActivity, workProfile)
animations.fadeViewOut(actionMenu)
textView.visibility = View.VISIBLE
}
} else {pinButton.visibility = View.GONE}
if (enableInfo) {
infoButton.visibility = View.VISIBLE
ViewCompat.addAccessibilityAction(
textView,
activity.getString(R.string.accessibility_info)
) { _, _ ->
appInfo(appActivity, userHandle) appInfo(appActivity, userHandle)
true true
} }
infoButton.setOnClickListener {
appInfo(appActivity, userHandle)
animations.fadeViewOut(actionMenu)
textView.visibility = View.VISIBLE
}
} else {infoButton.visibility = View.GONE}
if (enableUninstall) {
if (appActivity.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM == 0) {
uninstallButton.visibility = View.VISIBLE
}
ViewCompat.addAccessibilityAction(
textView,
activity.getString(R.string.accessibility_uninstall)
) { _, _ ->
uninstallApp(appActivity.applicationInfo, userHandle)
true
}
uninstallButton.setOnClickListener {
uninstallApp(appActivity.applicationInfo, userHandle)
animations.fadeViewOut(actionMenu)
textView.visibility = View.VISIBLE
}
} else {uninstallButton.visibility = View.GONE}
if (enableRename) {
renameButton.visibility = View.VISIBLE
ViewCompat.addAccessibilityAction(
textView,
activity.getString(R.string.accessibility_rename)
) { _, _ ->
renameApp(textView, editLayout, actionMenu, appActivity, userHandle, workProfile)
true
}
renameButton.setOnClickListener {
renameApp(textView, editLayout, actionMenu, appActivity, userHandle, workProfile)
}
} else {renameButton.visibility = View.GONE}
if (enableHide) {
hideButton.visibility = View.VISIBLE
ViewCompat.addAccessibilityAction(
textView,
activity.getString(R.string.accessibility_hide)
) { _, _ ->
hideApp(editLayout, textView, actionMenu, appActivity, workProfile)
true
}
hideButton.setOnClickListener {
hideApp(editLayout, textView, actionMenu, appActivity, workProfile)
}
} else {hideButton.visibility = View.GONE}
if (enableClose) {
closeButton.visibility = View.VISIBLE
closeButton.setOnClickListener {
animations.fadeViewOut(actionMenu)
textView.visibility = View.VISIBLE
}
} else {closeButton.visibility = View.GONE}
}
private fun setPinState(button: TextView, appActivity: LauncherActivityInfo, workProfile: Int) {
val isPinned = sharedPreferenceManager.isAppPinned(appActivity.componentName.flattenToString(), workProfile) val isPinned = sharedPreferenceManager.isAppPinned(appActivity.componentName.flattenToString(), workProfile)
val topDrawable = when (isPinned) { val topDrawable = when (isPinned) {
true -> getDrawable(activity, R.drawable.keep_off_24px) true -> getDrawable(activity, R.drawable.keep_off_24px)
false -> getDrawable(activity,R.drawable.keep_24px) false -> getDrawable(activity,R.drawable.keep_24px)
} }
actionMenu.findViewById<TextView>(R.id.pin).setCompoundDrawablesWithIntrinsicBounds(null, topDrawable, null, null) button.setCompoundDrawablesWithIntrinsicBounds(null, topDrawable, null, null)
val pinLabel = when (isPinned) { val pinLabel = when (isPinned) {
true -> "Unpin" true -> "Unpin"
false -> "Pin" false -> "Pin"
} }
actionMenu.findViewById<TextView>(R.id.pin).text = pinLabel button.text = pinLabel
actionMenu.findViewById<TextView>(R.id.pin).setOnClickListener {
pinApp(appActivity, workProfile)
animations.fadeViewOut(actionMenu)
textView.visibility = View.VISIBLE
}
ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_info)) { _, _ ->
appInfo(appActivity, userHandle)
true
}
actionMenu.findViewById<TextView>(R.id.info).setOnClickListener {
appInfo(appActivity, userHandle)
animations.fadeViewOut(actionMenu)
textView.visibility = View.VISIBLE
}
ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_uninstall)) { _, _ ->
uninstallApp(appActivity.applicationInfo, userHandle)
true
}
actionMenu.findViewById<TextView>(R.id.uninstall).setOnClickListener {
uninstallApp(appActivity.applicationInfo, userHandle)
animations.fadeViewOut(actionMenu)
textView.visibility = View.VISIBLE
}
ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_rename)) { _, _ ->
renameApp(textView, editLayout, actionMenu, appActivity, userHandle, workProfile)
true
}
actionMenu.findViewById<TextView>(R.id.rename).setOnClickListener {
renameApp(textView, editLayout, actionMenu, appActivity, userHandle, workProfile)
}
ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_hide)) { _, _ ->
hideApp(editLayout, textView, actionMenu, appActivity, workProfile)
true
}
actionMenu.findViewById<TextView>(R.id.hide).setOnClickListener {
hideApp(editLayout, textView, actionMenu, appActivity, workProfile)
}
actionMenu.findViewById<TextView>(R.id.close).setOnClickListener {
animations.fadeViewOut(actionMenu)
textView.visibility = View.VISIBLE
}
} }
private fun pinApp(appActivity: LauncherActivityInfo, workProfile: Int) { private fun pinApp(appActivity: LauncherActivityInfo, workProfile: Int) {

View file

@ -7,6 +7,7 @@ import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference import androidx.preference.SwitchPreference
import eu.ottop.yamlauncher.R import eu.ottop.yamlauncher.R
import eu.ottop.yamlauncher.utils.PermissionUtils import eu.ottop.yamlauncher.utils.PermissionUtils
import eu.ottop.yamlauncher.utils.UIUtils
class AppMenuSettingsFragment : PreferenceFragmentCompat(), TitleProvider { private val permissionUtils = PermissionUtils() class AppMenuSettingsFragment : PreferenceFragmentCompat(), TitleProvider { private val permissionUtils = PermissionUtils()
private var contactPref: SwitchPreference? = null private var contactPref: SwitchPreference? = null
@ -15,6 +16,10 @@ class AppMenuSettingsFragment : PreferenceFragmentCompat(), TitleProvider { priv
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.app_menu_preferences, rootKey) setPreferencesFromResource(R.xml.app_menu_preferences, rootKey)
val uiUtils = UIUtils(requireContext())
val contextMenuSettings = findPreference<Preference>("contextMenuSettings")
contactPref = findPreference("contactsEnabled") contactPref = findPreference("contactsEnabled")
webSearchPref = findPreference("webSearchEnabled") webSearchPref = findPreference("webSearchEnabled")
autoLaunchPref = findPreference("autoLaunch") autoLaunchPref = findPreference("autoLaunch")
@ -41,6 +46,11 @@ class AppMenuSettingsFragment : PreferenceFragmentCompat(), TitleProvider { priv
return@OnPreferenceChangeListener true return@OnPreferenceChangeListener true
} }
} }
contextMenuSettings?.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
uiUtils.switchFragment(requireActivity(), ContextMenuSettingsFragment())
true }
} }
override fun getTitle(): String { override fun getTitle(): String {

View file

@ -0,0 +1,16 @@
package eu.ottop.yamlauncher.settings
import android.os.Bundle
import androidx.preference.PreferenceFragmentCompat
import eu.ottop.yamlauncher.R
class ContextMenuSettingsFragment : PreferenceFragmentCompat(), TitleProvider {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.context_menu_preferences, rootKey)
}
override fun getTitle(): String {
return getString(R.string.context_menu_settings_title)
}
}

View file

@ -243,6 +243,30 @@ class SharedPreferenceManager (private val context: Context) {
return preferences.getString("appMenuSize", "medium") return preferences.getString("appMenuSize", "medium")
} }
fun isPinEnabled(): Boolean {
return preferences.getBoolean("pinEnabled", true)
}
fun isInfoEnabled(): Boolean {
return preferences.getBoolean("infoEnabled", false)
}
fun isUninstallEnabled(): Boolean {
return preferences.getBoolean("uninstallEnabled", true)
}
fun isRenameEnabled(): Boolean {
return preferences.getBoolean("renameEnabled", true)
}
fun isHideEnabled(): Boolean {
return preferences.getBoolean("hideEnabled", true)
}
fun isCloseEnabled(): Boolean {
return preferences.getBoolean("closeEnabled", true)
}
fun isSearchEnabled(): Boolean { fun isSearchEnabled(): Boolean {
return preferences.getBoolean("searchEnabled", true) return preferences.getBoolean("searchEnabled", true)
} }

View file

@ -42,6 +42,7 @@
<string name="rename">Umbenennen</string> <string name="rename">Umbenennen</string>
<string name="hide">Verstecken</string> <string name="hide">Verstecken</string>
<string name="close">Schließen</string> <string name="close">Schließen</string>
<string name="accessibility_pin">Pin app</string>
<string name="accessibility_info">App-Info</string> <string name="accessibility_info">App-Info</string>
<string name="accessibility_uninstall">App deinstallieren</string> <string name="accessibility_uninstall">App deinstallieren</string>
<string name="accessibility_rename">App umbenennen</string> <string name="accessibility_rename">App umbenennen</string>
@ -125,6 +126,17 @@
<string name="permission_denied">Berechtigung verweigert</string> <string name="permission_denied">Berechtigung verweigert</string>
<string name="internet_search">Web Search Button</string> <string name="internet_search">Web Search Button</string>
<string name="context_menu_settings_title">Context Menu Settings</string>
<string name="context_menu_settings_text">Context Menu</string>
<string name="context_menu_settings_summary">Enable/disable context menu items</string>
<string name="enable_pin">Pin App</string>
<string name="enable_info">App Info</string>
<string name="enable_uninstall">Uninstall App</string>
<string name="enable_rename">Rename App</string>
<string name="enable_hide">Hide App</string>
<string name="enable_close">Close Menu</string>
<string name="search_text">Suche</string> <string name="search_text">Suche</string>
<string name="enable_search">Suche aktivieren</string> <string name="enable_search">Suche aktivieren</string>
<string name="search_alignment">Ausrichtung der Suche</string> <string name="search_alignment">Ausrichtung der Suche</string>

View file

@ -40,6 +40,7 @@
<string name="rename">Nimeä</string> <string name="rename">Nimeä</string>
<string name="hide">Piilota</string> <string name="hide">Piilota</string>
<string name="close">Sulje</string> <string name="close">Sulje</string>
<string name="accessibility_pin">Pin app</string>
<string name="accessibility_info">Sovellustiedot</string> <string name="accessibility_info">Sovellustiedot</string>
<string name="accessibility_uninstall">Poista sovellus</string> <string name="accessibility_uninstall">Poista sovellus</string>
<string name="accessibility_rename">Uudelleen-nimeä sovellus</string> <string name="accessibility_rename">Uudelleen-nimeä sovellus</string>
@ -123,6 +124,17 @@
<string name="permission_denied">Tarvittavat Luvat Kielletty</string> <string name="permission_denied">Tarvittavat Luvat Kielletty</string>
<string name="internet_search">Verkkohaku Nappi</string> <string name="internet_search">Verkkohaku Nappi</string>
<string name="context_menu_settings_title">Context Menu Settings</string>
<string name="context_menu_settings_text">Context Menu</string>
<string name="context_menu_settings_summary">Enable/disable context menu items</string>
<string name="enable_pin">Pin App</string>
<string name="enable_info">App Info</string>
<string name="enable_uninstall">Uninstall App</string>
<string name="enable_rename">Rename App</string>
<string name="enable_hide">Hide App</string>
<string name="enable_close">Close Menu</string>
<string name="search_text">Hakupalkki</string> <string name="search_text">Hakupalkki</string>
<string name="enable_search">Näytä Hakupalkki</string> <string name="enable_search">Näytä Hakupalkki</string>
<string name="search_alignment">Hakupalkin Sijainti</string> <string name="search_alignment">Hakupalkin Sijainti</string>

View file

@ -81,4 +81,14 @@
<item>Extra Large</item> <item>Extra Large</item>
<item>Huge</item> <item>Huge</item>
</string-array> </string-array>
<!-- Reply Preference -->
<string-array name="reply_entries">
<item>Reply</item>
<item>Reply to all</item>
</string-array>
<string-array name="reply_values">
<item>reply</item>
<item>reply_all</item>
</string-array>
</resources> </resources>

View file

@ -42,6 +42,7 @@
<string name="rename">Rename</string> <string name="rename">Rename</string>
<string name="hide">Hide</string> <string name="hide">Hide</string>
<string name="close">Close</string> <string name="close">Close</string>
<string name="accessibility_pin">Pin app</string>
<string name="accessibility_info">App info</string> <string name="accessibility_info">App info</string>
<string name="accessibility_uninstall">Uninstall app</string> <string name="accessibility_uninstall">Uninstall app</string>
<string name="accessibility_rename">Rename app</string> <string name="accessibility_rename">Rename app</string>
@ -125,6 +126,17 @@
<string name="permission_denied">Permission Denied</string> <string name="permission_denied">Permission Denied</string>
<string name="internet_search">Web Search Button</string> <string name="internet_search">Web Search Button</string>
<string name="context_menu_settings_title">Context Menu Settings</string>
<string name="context_menu_settings_text">Context Menu</string>
<string name="context_menu_settings_summary">Enable/disable context menu items</string>
<string name="enable_pin">Pin App</string>
<string name="enable_info">App Info</string>
<string name="enable_uninstall">Uninstall App</string>
<string name="enable_rename">Rename App</string>
<string name="enable_hide">Hide App</string>
<string name="enable_close">Close Menu</string>
<string name="search_text">Search</string> <string name="search_text">Search</string>
<string name="enable_search">Enable Search</string> <string name="enable_search">Enable Search</string>
<string name="search_alignment">Search Alignment</string> <string name="search_alignment">Search Alignment</string>
@ -183,5 +195,4 @@
<!--Double tap to lock--> <!--Double tap to lock-->
<string name="screenlock_confirmation">To lock with double tap, enable YAM Launcher in accessibility settings.</string> <string name="screenlock_confirmation">To lock with double tap, enable YAM Launcher in accessibility settings.</string>
<string name="accessibility_service_description">The permission is required for double tap to work for locking the screen.\n\nIt is only needed if you want to use the double tap to lock screen feature in YAM Launcher.</string> <string name="accessibility_service_description">The permission is required for double tap to work for locking the screen.\n\nIt is only needed if you want to use the double tap to lock screen feature in YAM Launcher.</string>
</resources> </resources>

View file

@ -46,6 +46,14 @@
app:dependency="searchEnabled" app:dependency="searchEnabled"
app:key="webSearchEnabled" /> app:key="webSearchEnabled" />
<Preference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:key="contextMenuSettings"
app:selectable="true"
app:summary="@string/context_menu_settings_summary"
app:title="@string/context_menu_settings_text" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
app:allowDividerAbove="false" app:allowDividerAbove="false"

View file

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<SwitchPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="true"
android:title="@string/enable_pin"
app:key="pinEnabled" />
<SwitchPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="false"
android:title="@string/enable_info"
app:key="infoEnabled" />
<SwitchPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="true"
android:title="@string/enable_uninstall"
app:key="uninstallEnabled" />
<SwitchPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="true"
android:title="@string/enable_rename"
app:key="renameEnabled" />
<SwitchPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="true"
android:title="@string/enable_hide"
app:key="hideEnabled" />
<SwitchPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="true"
android:title="@string/enable_close"
app:key="closeEnabled" />
</PreferenceScreen>

View file

@ -13,7 +13,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:allowDividerAbove="false" app:allowDividerAbove="false"
app:title="@string/customization" > app:title="@string/customization">
<Preference <Preference
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"