Skip to content

Commit

Permalink
feat: Configure max recent apps per orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
axel358 committed Oct 10, 2024
1 parent 2600176 commit f056a0a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 19 additions & 3 deletions app/src/main/java/cu/axel/smartdock/services/DockService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -155,6 +158,7 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On
private lateinit var pinnedApps: ArrayList<App>
private lateinit var dateTv: TextClock
private var maxApps = 0
private var maxAppsLandscape = 0
private lateinit var context: Context
private lateinit var tasks: ArrayList<AppTask>
private var lastUpdate: Long = 0
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@
<string name="pin_windowed">Anclar en aplicaciones de ventana</string>
<string name="unpin_fullscreen">Desanclar en aplicaciones de pantalla completa</string>
<string name="running_apps_number_title">Número de aplicaciones en ejecución/recientes para mostrar</string>
<string name="running_apps_number_summary">Esta configuración puede ayudar a los dispositivos con pantallas más pequeñas a evitar el desbordamiento de aplicaciones en el Dock</string>
<string name="max_running_apps_landscape">Máximo de apps (horizontal)</string>
<string name="max_running_apps_portrait">Máximo de apps (vertical)</string>
<string name="center_running_apps_title">Centrar de aplicaciones en ejecución</string>
<string name="dock_activation_area_title">Área de activación del dock</string>
<string name="dock_activation_area_summary">La altura del área de activación invisible en la parte inferior de la pantalla</string>
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values-pa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@
<string name="pin_windowed">ਵਿੰਡੋਡ ਐਪਸ \'ਤੇ ਪਿੰਨ ਕਰੋ</string>
<string name="unpin_fullscreen">ਪੂਰੀ ਸਕ੍ਰੀਨ ਐਪਾਂ \'ਤੇ ਅਨਪਿੰਨ ਕਰੋ</string>
<string name="running_apps_number_title">ਚੱਲ ਰਹੀਆਂ/ਹਾਲੀਆ ਐਪਾਂ ਦੀ ਦਿਖਾਉਣ ਲਈ ਸੰਖਿਆ</string>
<string name="running_apps_number_summary">ਇਹ ਸੈਟਿੰਗ ਛੋਟੀਆਂ ਸਕ੍ਰੀਨਾਂ ਵਾਲੇ ਡਿਵਾਈਸਾਂ ਨੂੰ ਡੌਕ \'ਤੇ ਐਪ ਓਵਰਫਲੋ ਤੋਂ ਬਚਣ ਵਿੱਚ ਮਦਦ ਕਰ ਸਕਦੀ ਹੈ</string>
<string name="max_running_apps_landscape">Max recent apps (landscape)</string>
<string name="max_running_apps_portrait">Max recent apps (portrait)</string>
<string name="center_running_apps_title">ਸੈਂਟਰ ਚੱਲ ਰਹੀਆਂ ਐਪਾਂ</string>
<string name="dock_activation_area_title">ਡੌਕ ਐਕਟੀਵੇਸ਼ਨ ਖੇਤਰ</string>
<string name="dock_activation_area_summary">ਸਕ੍ਰੀਨ ਦੇ ਹੇਠਾਂ ਇਨਵਿਜੀਵਲ ਐਕਟੀਵੇਸ਼ਨ ਖੇਤਰ ਦੀ ਉਚਾਈ</string>
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@
<string name="pin_windowed">Pin on windowed apps</string>
<string name="unpin_fullscreen">Unpin on full screen apps</string>
<string name="running_apps_number_title">Number of running/recent apps to show</string>
<string name="running_apps_number_summary">This setting can help devices with smaller screens avoid app overflow on the Dock</string>
<string name="max_running_apps_landscape">Max recent apps (landscape)</string>
<string name="max_running_apps_portrait">Max recent apps (portrait)</string>
<string name="center_running_apps_title">Center running apps</string>
<string name="dock_activation_area_title">Dock activation area</string>
<string name="dock_activation_area_summary">The height of the invisible activation area at the bottom of the screen</string>
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/res/xml/preferences_dock.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

<EditTextPreference
android:key="max_running_apps_landscape"
android:hint="10"
android:defaultValue="10"
android:title="@string/max_running_apps_landscape"
android:summary="@string/running_apps_number_title"/>

<SwitchPreferenceCompat
android:key="center_running_apps"
Expand Down

0 comments on commit f056a0a

Please sign in to comment.