From f056a0abc0cb630a2611179e65019f0aa6dfea72 Mon Sep 17 00:00:00 2001 From: Axel358 Date: Thu, 10 Oct 2024 15:52:02 -0400 Subject: [PATCH] feat: Configure max recent apps per orientation --- .../smartdock/dialogs/DockLayoutDialog.kt | 8 +++++++ .../cu/axel/smartdock/services/DockService.kt | 22 ++++++++++++++++--- app/src/main/res/values-es/strings.xml | 3 ++- app/src/main/res/values-pa/strings.xml | 3 ++- app/src/main/res/values/strings.xml | 3 ++- app/src/main/res/xml/preferences_dock.xml | 11 ++++++++-- 6 files changed, 42 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/cu/axel/smartdock/dialogs/DockLayoutDialog.kt b/app/src/main/java/cu/axel/smartdock/dialogs/DockLayoutDialog.kt index 64f2bfbc..2d2dbde8 100644 --- a/app/src/main/java/cu/axel/smartdock/dialogs/DockLayoutDialog.kt +++ b/app/src/main/java/cu/axel/smartdock/dialogs/DockLayoutDialog.kt @@ -28,10 +28,18 @@ class DockLayoutDialog(context: Context) : MaterialAlertDialogBuilder(context) { else -> "15" } ) + editor.putString( + "max_running_apps_landscape", when (which) { + 0 -> "8" + 1 -> "10" + else -> "15" + } + ) editor.putString("dock_activation_area", if (which == 2) "5" else "25") editor.putInt("dock_layout", which) editor.putString("activation_method", if (which != 2) "handle" else "swipe") editor.putBoolean("show_notifications", which != 0) + editor.putBoolean("enable_qs_pin", which != 2) editor.apply() } setPositiveButton(R.string.ok, null) diff --git a/app/src/main/java/cu/axel/smartdock/services/DockService.kt b/app/src/main/java/cu/axel/smartdock/services/DockService.kt index fcba2d9f..472b9c1f 100644 --- a/app/src/main/java/cu/axel/smartdock/services/DockService.kt +++ b/app/src/main/java/cu/axel/smartdock/services/DockService.kt @@ -22,6 +22,7 @@ import android.content.pm.LauncherApps import android.content.pm.PackageManager import android.content.pm.ShortcutInfo import android.content.res.Configuration +import android.content.res.Resources import android.hardware.usb.UsbManager import android.media.AudioManager import android.net.Uri @@ -107,6 +108,8 @@ const val DOCK_SERVICE_ACTION = "dock_service_action" class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, OnTouchListener, OnAppClickListener, OnDockAppClickListener { + + private var orientation = -1 private lateinit var sharedPreferences: SharedPreferences private lateinit var activityManager: ActivityManager private lateinit var appsBtn: ImageView @@ -155,6 +158,7 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On private lateinit var pinnedApps: ArrayList private lateinit var dateTv: TextClock private var maxApps = 0 + private var maxAppsLandscape = 0 private lateinit var context: Context private lateinit var tasks: ArrayList private var lastUpdate: Long = 0 @@ -185,6 +189,8 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On Utils.startupTime = System.currentTimeMillis() systemApp = AppUtils.isSystemApp(context, packageName) maxApps = sharedPreferences.getString("max_running_apps", "10")!!.toInt() + maxAppsLandscape = sharedPreferences.getString("max_running_apps_landscape", "10")!!.toInt() + orientation = resources.configuration.orientation //Create the dock dock = LayoutInflater.from(context).inflate(R.layout.dock, null) as HoverInterceptorLayout @@ -1458,8 +1464,10 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On updateQuickSettings() } else if (preference == "round_dock") updateDockShape() - else if (preference == "max_running_apps") { + else if (preference.startsWith("max_running_apps")) { maxApps = sharedPreferences.getString("max_running_apps", "10")!!.toInt() + maxAppsLandscape = + sharedPreferences.getString("max_running_apps_landscape", "10")!!.toInt() updateRunningTasks() } else if (preference == "activation_method") { updateActivationMethod() @@ -1535,8 +1543,10 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On //TODO: We can eliminate another for //TODO: Don't do anything if tasks has not changed + val nApps = + if (orientation == Configuration.ORIENTATION_PORTRAIT) maxApps else maxAppsLandscape if (systemApp) { - tasks = AppUtils.getRunningTasks(activityManager, packageManager, maxApps) + tasks = AppUtils.getRunningTasks(activityManager, packageManager, nApps) for (j in 1..tasks.size) { val task = tasks[tasks.size - j] val index = AppUtils.containsTask(apps, task) @@ -1546,7 +1556,7 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On apps.add(DockApp(task)) } } else { - tasks = AppUtils.getRecentTasks(context, maxApps) + tasks = AppUtils.getRecentTasks(context, nApps) tasks.reversed().forEach { task -> val index = AppUtils.containsTask(apps, task) if (index == -1) @@ -1563,6 +1573,12 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On bluetoothBtn.setImageResource(if (bluetoothAdapter.isEnabled) R.drawable.ic_bluetooth else R.drawable.ic_bluetooth_off) } + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + orientation = newConfig.orientation + updateRunningTasks() + } + private fun updateDockShape() { dockLayout.setBackgroundResource( if (sharedPreferences.getBoolean( diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 74779d93..9cd0f773 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -122,7 +122,8 @@ Anclar en aplicaciones de ventana Desanclar en aplicaciones de pantalla completa Número de aplicaciones en ejecución/recientes para mostrar - Esta configuración puede ayudar a los dispositivos con pantallas más pequeñas a evitar el desbordamiento de aplicaciones en el Dock + Máximo de apps (horizontal) + Máximo de apps (vertical) Centrar de aplicaciones en ejecución Área de activación del dock La altura del área de activación invisible en la parte inferior de la pantalla diff --git a/app/src/main/res/values-pa/strings.xml b/app/src/main/res/values-pa/strings.xml index e74e90c5..823f6aa9 100644 --- a/app/src/main/res/values-pa/strings.xml +++ b/app/src/main/res/values-pa/strings.xml @@ -122,7 +122,8 @@ ਵਿੰਡੋਡ ਐਪਸ \'ਤੇ ਪਿੰਨ ਕਰੋ ਪੂਰੀ ਸਕ੍ਰੀਨ ਐਪਾਂ \'ਤੇ ਅਨਪਿੰਨ ਕਰੋ ਚੱਲ ਰਹੀਆਂ/ਹਾਲੀਆ ਐਪਾਂ ਦੀ ਦਿਖਾਉਣ ਲਈ ਸੰਖਿਆ - ਇਹ ਸੈਟਿੰਗ ਛੋਟੀਆਂ ਸਕ੍ਰੀਨਾਂ ਵਾਲੇ ਡਿਵਾਈਸਾਂ ਨੂੰ ਡੌਕ \'ਤੇ ਐਪ ਓਵਰਫਲੋ ਤੋਂ ਬਚਣ ਵਿੱਚ ਮਦਦ ਕਰ ਸਕਦੀ ਹੈ + Max recent apps (landscape) + Max recent apps (portrait) ਸੈਂਟਰ ਚੱਲ ਰਹੀਆਂ ਐਪਾਂ ਡੌਕ ਐਕਟੀਵੇਸ਼ਨ ਖੇਤਰ ਸਕ੍ਰੀਨ ਦੇ ਹੇਠਾਂ ਇਨਵਿਜੀਵਲ ਐਕਟੀਵੇਸ਼ਨ ਖੇਤਰ ਦੀ ਉਚਾਈ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c865db68..4a368699 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -122,7 +122,8 @@ Pin on windowed apps Unpin on full screen apps Number of running/recent apps to show - This setting can help devices with smaller screens avoid app overflow on the Dock + Max recent apps (landscape) + Max recent apps (portrait) Center running apps Dock activation area The height of the invisible activation area at the bottom of the screen diff --git a/app/src/main/res/xml/preferences_dock.xml b/app/src/main/res/xml/preferences_dock.xml index a24ef8d6..a46e0851 100644 --- a/app/src/main/res/xml/preferences_dock.xml +++ b/app/src/main/res/xml/preferences_dock.xml @@ -95,8 +95,15 @@ android:key="max_running_apps" android:hint="10" android:defaultValue="10" - android:summary="@string/running_apps_number_summary" - android:title="@string/running_apps_number_title"/> + android:title="@string/max_running_apps_portrait" + android:summary="@string/running_apps_number_title"/> + +