This commit is contained in:
Josia Pietsch 2024-09-25 21:52:42 +02:00
commit 68acb43426
Signed by: jrpie
GPG key ID: E70B571D66986A2D
10 changed files with 45 additions and 11 deletions

View file

@ -8,6 +8,7 @@ import android.content.SharedPreferences
import android.content.pm.LauncherApps
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.util.Log
import de.jrpie.android.launcher.R
import de.jrpie.android.launcher.apps.AppInfo
import de.jrpie.android.launcher.apps.AppInfo.Companion.INVALID_USER
@ -17,13 +18,13 @@ import de.jrpie.android.launcher.openAppSettings
class AppAction(private var appInfo: AppInfo) : Action {
override fun invoke(context: Context, rect: Rect?): Boolean {
val packageName = appInfo.packageName.toString()
if (appInfo.user != INVALID_USER) {
val launcherApps =
context.getSystemService(Service.LAUNCHER_APPS_SERVICE) as LauncherApps
appInfo.getLauncherActivityInfo(context)?.let { app ->
Log.i("Launcher", "Starting $appInfo")
launcherApps.startMainActivity(app.componentName, app.user, rect, null)
return true
}
@ -70,14 +71,20 @@ class AppAction(private var appInfo: AppInfo) : Action {
}
override fun bindToGesture(editor: SharedPreferences.Editor, id: String) {
val u = appInfo.user ?: INVALID_USER
val u = appInfo.user
// TODO: replace this by AppInfo#serialize (breaking change to SharedPreferences!)
var app = appInfo.packageName.toString()
if (appInfo.activityName != null) {
app += ";${appInfo.activityName}"
}
editor
.putString("$id.app", appInfo.packageName.toString())
.putString("$id.app", app)
.putInt("$id.user", u)
}
override fun writeToIntent(intent: Intent) {
intent.putExtra("action_id", "${appInfo.packageName};${appInfo.activityName}");
appInfo.user?.let { intent.putExtra("user", it) }
intent.putExtra("action_id", "${appInfo.packageName};${appInfo.activityName}")
intent.putExtra("user", appInfo.user)
}
}

View file

@ -12,6 +12,8 @@ import de.jrpie.android.launcher.getUserFromId
*/
class AppInfo(val packageName: CharSequence, val activityName: CharSequence?, val user: Int = INVALID_USER) {
// TODO: make activityName non nullable (breaking change to SharedPreferences!)
fun serialize(): String {
val u = user
var ret = "$packageName;$u"
@ -38,12 +40,16 @@ class AppInfo(val packageName: CharSequence, val activityName: CharSequence?, va
val launcherApps = context.getSystemService(Service.LAUNCHER_APPS_SERVICE) as LauncherApps
return getUserFromId(user, context)?.let { userHandle ->
launcherApps.getActivityList(packageName.toString(), userHandle).firstOrNull { app ->
activityName == null || app.name == activityName
app.name == activityName || activityName == null || activityName == ""
}
}
}
override fun toString(): String {
return "AppInfo {package=$packageName, activity=$activityName, user=$user}"
}
companion object {
const val INVALID_USER = -1

View file

@ -140,4 +140,4 @@
<string name="list_other_expand_notifications_panel">Benachrichtigungen</string>
<string name="alert_cant_expand_notifications_panel">Fehler: Die Funktion \"Benachrichtigungen\" wird von deinem Gerät leider nicht unterstützt.</string>
<string name="settings_clock_show_seconds">Sekunden anzeigen</string>
</resources>
</resources>

View file

@ -65,7 +65,6 @@
<string name="settings_launcher_section_display">Pantalla</string>
<string name="settings_display_screen_timeout_disabled">Mantener encendida</string>
<string name="settings_display_full_screen">Pantalla completa</string>
<string name="settings_launcher_section_functionality">Funciones</string>
<string name="settings_enabled_gestures_double_swipe">Deslizar con dos dedos</string>
<string name="settings_functionality_auto_launch">Auto-lanzar búsquedas</string>
@ -129,4 +128,4 @@
<string name="tutorial_finish_button">Iniciar</string>
<string name="settings">Configuración</string>
<string name="ic_menu_alt">Más opciones</string>
</resources>
</resources>

View file

@ -140,4 +140,4 @@
<string name="settings_clock_flip_date_time">Échanger la date et l\'heure</string>
<string name="settings_clock_date_visible">Afficher la date</string>
<string name="settings_clock_localized">Utiliser le format de date local</string>
</resources>
</resources>

View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<resources></resources>

View file

@ -103,4 +103,4 @@
<string name="settings_clock_time_visible">显示时间</string>
<string name="settings_clock_date_visible">显示日期</string>
<string name="settings_clock_flip_date_time">翻转日期和时间</string>
</resources>
</resources>