summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Joshua Mokut <jmokut@google.com> 2024-07-11 16:45:30 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-07-11 16:45:30 +0000
commitc0ff9ea69bba7abb2318e67f670b8735955748ae (patch)
tree4e0aceadfc6a4ec5b95095804db9053514d8f9b4
parent732fe397113c3efc21bde99ccd027a7fd6ce9b35 (diff)
parente3081d3a708faf818ac2f958c7bfa5e712b78015 (diff)
Merge "Implemented Shortcut retrieval for current apps" into main
-rw-r--r--packages/SystemUI/res/values/strings.xml4
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt6
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperCategoriesRepository.kt50
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/CurrentAppShortcutsSource.kt34
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/InputShortcutsSource.kt2
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt1
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/qualifiers/CurrentAppShortcuts.kt21
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCategory.kt15
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt93
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/model/IconSource.kt22
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt6
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt18
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt5
13 files changed, 230 insertions, 47 deletions
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index c1e99db63e3a..a6dd14a98a7e 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -3597,6 +3597,10 @@
that shows the user which keyboard shortcuts they can use. The "App shortcuts" are
for example "Open browser" or "Open calculator". [CHAR LIMIT=NONE] -->
<string name="shortcut_helper_category_app_shortcuts">App shortcuts</string>
+ <!-- Default Title of the keyboard shortcut helper category for current app. The helper is a
+ component that shows the user which keyboard shortcuts they can use. The current app
+ shortcuts are shortcuts provided by the currently open app. [CHAR LIMIT=NONE] -->
+ <string name="shortcut_helper_category_current_app_shortcuts">Current App</string>
<!-- Title of the keyboard shortcut helper category "Accessibility". The helper is a component
that shows the user which keyboard shortcuts they can use. The "Accessibility" shortcuts
are for example "Turn on talkback". [CHAR LIMIT=NONE] -->
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt
index 1f0aef8ab977..906f600e3826 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt
@@ -21,11 +21,13 @@ import com.android.systemui.CoreStartable
import com.android.systemui.Flags.keyboardShortcutHelperRewrite
import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperStateRepository
import com.android.systemui.keyboard.shortcut.data.source.AppCategoriesShortcutsSource
+import com.android.systemui.keyboard.shortcut.data.source.CurrentAppShortcutsSource
import com.android.systemui.keyboard.shortcut.data.source.InputShortcutsSource
import com.android.systemui.keyboard.shortcut.data.source.KeyboardShortcutGroupsSource
import com.android.systemui.keyboard.shortcut.data.source.MultitaskingShortcutsSource
import com.android.systemui.keyboard.shortcut.data.source.SystemShortcutsSource
import com.android.systemui.keyboard.shortcut.qualifiers.AppCategoriesShortcuts
+import com.android.systemui.keyboard.shortcut.qualifiers.CurrentAppShortcuts
import com.android.systemui.keyboard.shortcut.qualifiers.InputShortcuts
import com.android.systemui.keyboard.shortcut.qualifiers.MultitaskingShortcuts
import com.android.systemui.keyboard.shortcut.qualifiers.SystemShortcuts
@@ -55,6 +57,10 @@ interface ShortcutHelperModule {
fun multitaskingShortcutsSource(impl: MultitaskingShortcutsSource): KeyboardShortcutGroupsSource
@Binds
+ @CurrentAppShortcuts
+ fun currentAppShortcutsSource(impl: CurrentAppShortcutsSource): KeyboardShortcutGroupsSource
+
+ @Binds
@InputShortcuts
fun inputShortcutsSources(impl: InputShortcutsSource): KeyboardShortcutGroupsSource
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperCategoriesRepository.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperCategoriesRepository.kt
index 7b0c25e8379d..9e5379283f49 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperCategoriesRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperCategoriesRepository.kt
@@ -28,16 +28,18 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.keyboard.shortcut.data.source.KeyboardShortcutGroupsSource
import com.android.systemui.keyboard.shortcut.qualifiers.AppCategoriesShortcuts
+import com.android.systemui.keyboard.shortcut.qualifiers.CurrentAppShortcuts
import com.android.systemui.keyboard.shortcut.qualifiers.InputShortcuts
import com.android.systemui.keyboard.shortcut.qualifiers.MultitaskingShortcuts
import com.android.systemui.keyboard.shortcut.qualifiers.SystemShortcuts
import com.android.systemui.keyboard.shortcut.shared.model.Shortcut
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategory
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType
-import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.APP_CATEGORIES
-import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.IME
-import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.MULTI_TASKING
-import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.SYSTEM
+import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.AppCategories
+import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.CurrentApp
+import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.InputMethodEditor
+import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.MultiTasking
+import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.System
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCommand
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState.Active
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutIcon
@@ -45,6 +47,7 @@ import com.android.systemui.keyboard.shortcut.shared.model.ShortcutKey
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutSubCategory
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
+import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.withContext
@@ -58,6 +61,7 @@ constructor(
@MultitaskingShortcuts private val multitaskingShortcutsSource: KeyboardShortcutGroupsSource,
@AppCategoriesShortcuts private val appCategoriesShortcutsSource: KeyboardShortcutGroupsSource,
@InputShortcuts private val inputShortcutsSource: KeyboardShortcutGroupsSource,
+ @CurrentAppShortcuts private val currentAppShortcutsSource: KeyboardShortcutGroupsSource,
private val inputManager: InputManager,
stateRepository: ShortcutHelperStateRepository
) {
@@ -76,7 +80,7 @@ constructor(
if (it != null) {
toShortcutCategory(
it.keyCharacterMap,
- SYSTEM,
+ System,
systemShortcutsSource.shortcutGroups(it.id),
keepIcons = true,
)
@@ -90,7 +94,7 @@ constructor(
if (it != null) {
toShortcutCategory(
it.keyCharacterMap,
- MULTI_TASKING,
+ MultiTasking,
multitaskingShortcutsSource.shortcutGroups(it.id),
keepIcons = true,
)
@@ -104,7 +108,7 @@ constructor(
if (it != null) {
toShortcutCategory(
it.keyCharacterMap,
- APP_CATEGORIES,
+ AppCategories,
appCategoriesShortcutsSource.shortcutGroups(it.id),
keepIcons = true,
)
@@ -118,7 +122,7 @@ constructor(
if (it != null) {
toShortcutCategory(
it.keyCharacterMap,
- IME,
+ InputMethodEditor,
inputShortcutsSource.shortcutGroups(it.id),
keepIcons = false,
)
@@ -127,6 +131,26 @@ constructor(
}
}
+ val currentAppShortcutsCategory: Flow<ShortcutCategory?> =
+ activeInputDevice.map {
+ if (it != null) {
+ val shortcutGroups = currentAppShortcutsSource.shortcutGroups(it.id)
+ val categoryType = getCurrentAppShortcutCategoryType(shortcutGroups)
+ if (categoryType == null) {
+ null
+ } else {
+ toShortcutCategory(
+ it.keyCharacterMap,
+ categoryType,
+ shortcutGroups,
+ keepIcons = false
+ )
+ }
+ } else {
+ null
+ }
+ }
+
private fun toShortcutCategory(
keyCharacterMap: KeyCharacterMap,
type: ShortcutCategoryType,
@@ -150,6 +174,16 @@ constructor(
}
}
+ private fun getCurrentAppShortcutCategoryType(
+ shortcutGroups: List<KeyboardShortcutGroup>
+ ): ShortcutCategoryType? {
+ return if (shortcutGroups.isEmpty()) {
+ null
+ } else {
+ CurrentApp(packageName = shortcutGroups[0].packageName.toString())
+ }
+ }
+
private fun toShortcuts(
keyCharacterMap: KeyCharacterMap,
infoList: List<KeyboardShortcutInfo>,
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/CurrentAppShortcutsSource.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/CurrentAppShortcutsSource.kt
new file mode 100644
index 000000000000..7e6ed19d6070
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/CurrentAppShortcutsSource.kt
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.keyboard.shortcut.data.source
+
+import android.view.KeyboardShortcutGroup
+import android.view.WindowManager
+import android.view.WindowManager.KeyboardShortcutsReceiver
+import javax.inject.Inject
+import kotlinx.coroutines.suspendCancellableCoroutine
+
+class CurrentAppShortcutsSource @Inject constructor(private val windowManager: WindowManager) :
+ KeyboardShortcutGroupsSource {
+ override suspend fun shortcutGroups(deviceId: Int): List<KeyboardShortcutGroup> =
+ suspendCancellableCoroutine { continuation ->
+ val shortcutsReceiver = KeyboardShortcutsReceiver {
+ continuation.resumeWith(Result.success(it ?: emptyList()))
+ }
+ windowManager.requestAppKeyboardShortcuts(shortcutsReceiver, deviceId)
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/InputShortcutsSource.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/InputShortcutsSource.kt
index aba441546e35..1b2098650278 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/InputShortcutsSource.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/InputShortcutsSource.kt
@@ -59,7 +59,7 @@ constructor(@Main private val resources: Resources, private val windowManager: W
private suspend fun getImeShortcutGroup(deviceId: Int): List<KeyboardShortcutGroup> =
suspendCancellableCoroutine { continuation ->
val shortcutsReceiver = KeyboardShortcutsReceiver {
- continuation.resumeWith(Result.success(it))
+ continuation.resumeWith(Result.success(it ?: emptyList()))
}
windowManager.requestImeKeyboardShortcuts(shortcutsReceiver, deviceId)
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt
index d41d21a3b4fb..f215c74b3255 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt
@@ -38,6 +38,7 @@ constructor(
categoriesRepository.multitaskingShortcutsCategory,
categoriesRepository.imeShortcutsCategory,
categoriesRepository.appCategoriesShortcutsCategory,
+ categoriesRepository.currentAppShortcutsCategory
) { shortcutCategories ->
shortcutCategories.filterNotNull().map { groupSubCategoriesInCategory(it) }
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/qualifiers/CurrentAppShortcuts.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/qualifiers/CurrentAppShortcuts.kt
new file mode 100644
index 000000000000..51631b11b27c
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/qualifiers/CurrentAppShortcuts.kt
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.keyboard.shortcut.qualifiers
+
+import javax.inject.Qualifier
+
+@Qualifier annotation class CurrentAppShortcuts
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCategory.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCategory.kt
index 63e167a376d1..4eabefcd2d41 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCategory.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCategory.kt
@@ -16,11 +16,16 @@
package com.android.systemui.keyboard.shortcut.shared.model
-enum class ShortcutCategoryType {
- SYSTEM,
- MULTI_TASKING,
- IME,
- APP_CATEGORIES,
+sealed interface ShortcutCategoryType {
+ data object System : ShortcutCategoryType
+
+ data object MultiTasking : ShortcutCategoryType
+
+ data object InputMethodEditor : ShortcutCategoryType
+
+ data object AppCategories : ShortcutCategoryType
+
+ data class CurrentApp(val packageName: String) : ShortcutCategoryType
}
data class ShortcutCategory(
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt
index 3b037bc17564..9e9368d3ffd3 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt
@@ -16,7 +16,10 @@
package com.android.systemui.keyboard.shortcut.ui.composable
+import android.content.Context
+import android.content.pm.PackageManager.NameNotFoundException
import android.graphics.drawable.Icon
+import android.util.Log
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.Image
@@ -55,6 +58,7 @@ import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
+import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationDrawerItemColors
import androidx.compose.material3.NavigationDrawerItemDefaults
@@ -76,7 +80,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.graphicsLayer
-import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
@@ -99,8 +102,10 @@ import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCommand
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutIcon
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutKey
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutSubCategory
+import com.android.systemui.keyboard.shortcut.ui.model.IconSource
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutsUiState
import com.android.systemui.res.R
+import com.android.systemui.statusbar.phone.CentralSurfaces
@Composable
fun ShortcutHelper(
@@ -210,9 +215,9 @@ private fun CategoryItemSinglePane(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().heightIn(min = 88.dp).padding(horizontal = 16.dp)
) {
- Icon(category.icon, contentDescription = null)
+ ShortcutCategoryIcon(category.icon)
Spacer(modifier = Modifier.width(16.dp))
- Text(stringResource(category.labelResId))
+ Text(category.label(LocalContext.current))
Spacer(modifier = Modifier.weight(1f))
RotatingExpandCollapseIcon(isExpanded)
}
@@ -221,23 +226,67 @@ private fun CategoryItemSinglePane(
}
}
-private val ShortcutCategory.icon: ImageVector
+private val ShortcutCategory.icon: IconSource
+ @Composable
get() =
when (type) {
- ShortcutCategoryType.SYSTEM -> Icons.Default.Tv
- ShortcutCategoryType.MULTI_TASKING -> Icons.Default.VerticalSplit
- ShortcutCategoryType.IME -> Icons.Default.Keyboard
- ShortcutCategoryType.APP_CATEGORIES -> Icons.Default.Apps
+ ShortcutCategoryType.System -> IconSource(imageVector = Icons.Default.Tv)
+ ShortcutCategoryType.MultiTasking ->
+ IconSource(imageVector = Icons.Default.VerticalSplit)
+ ShortcutCategoryType.InputMethodEditor ->
+ IconSource(imageVector = Icons.Default.Keyboard)
+ ShortcutCategoryType.AppCategories -> IconSource(imageVector = Icons.Default.Apps)
+ is ShortcutCategoryType.CurrentApp -> {
+ val context = LocalContext.current
+ val iconDrawable = context.packageManager.getApplicationIcon(type.packageName)
+ IconSource(painter = rememberDrawablePainter(drawable = iconDrawable))
+ }
}
-private val ShortcutCategory.labelResId: Int
- get() =
- when (type) {
- ShortcutCategoryType.SYSTEM -> R.string.shortcut_helper_category_system
- ShortcutCategoryType.MULTI_TASKING -> R.string.shortcut_helper_category_multitasking
- ShortcutCategoryType.IME -> R.string.shortcut_helper_category_input
- ShortcutCategoryType.APP_CATEGORIES -> R.string.shortcut_helper_category_app_shortcuts
- }
+@Composable
+fun ShortcutCategoryIcon(
+ source: IconSource,
+ contentDescription: String? = null,
+ modifier: Modifier = Modifier,
+ tint: Color = LocalContentColor.current
+) {
+ if (source.imageVector != null) {
+ Icon(source.imageVector, contentDescription, modifier, tint)
+ } else if (source.painter != null) {
+ Image(source.painter, contentDescription, modifier)
+ }
+}
+
+private fun ShortcutCategory.label(context: Context): String =
+ when (type) {
+ ShortcutCategoryType.System -> context.getString(R.string.shortcut_helper_category_system)
+ ShortcutCategoryType.MultiTasking ->
+ context.getString(R.string.shortcut_helper_category_multitasking)
+ ShortcutCategoryType.InputMethodEditor ->
+ context.getString(R.string.shortcut_helper_category_input)
+ ShortcutCategoryType.AppCategories ->
+ context.getString(R.string.shortcut_helper_category_app_shortcuts)
+ is ShortcutCategoryType.CurrentApp -> getApplicationLabelForCurrentApp(type, context)
+ }
+
+private fun getApplicationLabelForCurrentApp(
+ type: ShortcutCategoryType.CurrentApp,
+ context: Context
+): String {
+ val packageManagerForUser = CentralSurfaces.getPackageManagerForUser(context, context.userId)
+ return try {
+ val currentAppInfo =
+ packageManagerForUser.getApplicationInfoAsUser(
+ type.packageName,
+ /* flags = */ 0,
+ context.userId
+ )
+ packageManagerForUser.getApplicationLabel(currentAppInfo).toString()
+ } catch (e: NameNotFoundException) {
+ Log.wtf(ShortcutHelper.TAG, "Couldn't find app info by package name ${type.packageName}")
+ context.getString(R.string.shortcut_helper_category_current_app_shortcuts)
+ }
+}
@Composable
private fun RotatingExpandCollapseIcon(isExpanded: Boolean) {
@@ -525,8 +574,8 @@ private fun CategoriesPanelTwoPane(
Column {
categories.fastForEach {
CategoryItemTwoPane(
- label = stringResource(it.labelResId),
- icon = it.icon,
+ label = it.label(LocalContext.current),
+ iconSource = it.icon,
selected = selectedCategory == it.type,
onClick = { onCategoryClicked(it) }
)
@@ -537,7 +586,7 @@ private fun CategoriesPanelTwoPane(
@Composable
private fun CategoryItemTwoPane(
label: String,
- icon: ImageVector,
+ iconSource: IconSource,
selected: Boolean,
onClick: () -> Unit,
colors: NavigationDrawerItemColors =
@@ -551,9 +600,9 @@ private fun CategoryItemTwoPane(
color = colors.containerColor(selected).value,
) {
Row(Modifier.padding(horizontal = 24.dp), verticalAlignment = Alignment.CenterVertically) {
- Icon(
+ ShortcutCategoryIcon(
modifier = Modifier.size(24.dp),
- imageVector = icon,
+ source = iconSource,
contentDescription = null,
tint = colors.iconColor(selected).value
)
@@ -649,4 +698,6 @@ object ShortcutHelper {
object Dimensions {
val SinglePaneCategoryCornerRadius = 28.dp
}
+
+ internal const val TAG = "ShortcutHelperUI"
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/model/IconSource.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/model/IconSource.kt
new file mode 100644
index 000000000000..7fc0103d861f
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/model/IconSource.kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.keyboard.shortcut.ui.model
+
+import androidx.compose.ui.graphics.painter.Painter
+import androidx.compose.ui.graphics.vector.ImageVector
+
+data class IconSource(val imageVector: ImageVector? = null, val painter: Painter? = null)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt
index 765cd014864c..4fba7e355df8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt
@@ -220,7 +220,7 @@ object TestShortcuts {
val imeGroups = listOf(standardGroup1, standardGroup2, standardGroup3)
val imeCategory =
ShortcutCategory(
- type = ShortcutCategoryType.IME,
+ type = ShortcutCategoryType.InputMethodEditor,
subCategories =
listOf(
subCategoryForInputLanguageSwitchShortcuts,
@@ -233,14 +233,14 @@ object TestShortcuts {
val systemGroups = listOf(standardGroup3, standardGroup2, standardGroup1)
val systemCategory =
ShortcutCategory(
- type = ShortcutCategoryType.SYSTEM,
+ type = ShortcutCategoryType.System,
subCategories = listOf(standardSubCategory3, standardSubCategory2, standardSubCategory1)
)
val multitaskingGroups = listOf(standardGroup2, standardGroup1)
val multitaskingCategory =
ShortcutCategory(
- type = ShortcutCategoryType.MULTI_TASKING,
+ type = ShortcutCategoryType.MultiTasking,
subCategories = listOf(standardSubCategory2, standardSubCategory1)
)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt
index 4c1e8696cdc1..d20ce3f1f0e9 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt
@@ -23,9 +23,9 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyboard.shortcut.data.source.FakeKeyboardShortcutGroupsSource
import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategory
-import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.IME
-import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.MULTI_TASKING
-import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.SYSTEM
+import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.InputMethodEditor
+import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.MultiTasking
+import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.System
import com.android.systemui.keyboard.shortcut.shortcutHelperAppCategoriesShortcutsSource
import com.android.systemui.keyboard.shortcut.shortcutHelperCategoriesInteractor
import com.android.systemui.keyboard.shortcut.shortcutHelperMultiTaskingShortcutsSource
@@ -117,7 +117,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() {
TestShortcuts.systemCategory,
TestShortcuts.multitaskingCategory,
ShortcutCategory(
- type = IME,
+ type = InputMethodEditor,
subCategories =
TestShortcuts.imeSubCategoriesWithGroupedDuplicatedShortcutLabels
),
@@ -137,7 +137,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() {
assertThat(categories)
.containsExactly(
ShortcutCategory(
- type = SYSTEM,
+ type = System,
subCategories =
TestShortcuts.subCategoriesWithGroupedDuplicatedShortcutLabels
),
@@ -160,7 +160,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() {
.containsExactly(
TestShortcuts.systemCategory,
ShortcutCategory(
- type = MULTI_TASKING,
+ type = MultiTasking,
subCategories =
TestShortcuts.subCategoriesWithGroupedDuplicatedShortcutLabels
),
@@ -182,7 +182,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() {
TestShortcuts.systemCategory,
TestShortcuts.multitaskingCategory,
ShortcutCategory(
- type = IME,
+ type = InputMethodEditor,
subCategories =
TestShortcuts.imeSubCategoriesWithUnsupportedModifiersRemoved
),
@@ -201,7 +201,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() {
assertThat(categories)
.containsExactly(
ShortcutCategory(
- type = SYSTEM,
+ type = System,
subCategories = TestShortcuts.subCategoriesWithUnsupportedModifiersRemoved
),
TestShortcuts.multitaskingCategory,
@@ -222,7 +222,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() {
.containsExactly(
TestShortcuts.systemCategory,
ShortcutCategory(
- type = MULTI_TASKING,
+ type = MultiTasking,
subCategories = TestShortcuts.subCategoriesWithUnsupportedModifiersRemoved
),
TestShortcuts.imeCategory,
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt
index f436a68aa5be..530df8aca442 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt
@@ -25,6 +25,7 @@ import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperCate
import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperStateRepository
import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperTestHelper
import com.android.systemui.keyboard.shortcut.data.source.AppCategoriesShortcutsSource
+import com.android.systemui.keyboard.shortcut.data.source.CurrentAppShortcutsSource
import com.android.systemui.keyboard.shortcut.data.source.InputShortcutsSource
import com.android.systemui.keyboard.shortcut.data.source.KeyboardShortcutGroupsSource
import com.android.systemui.keyboard.shortcut.data.source.MultitaskingShortcutsSource
@@ -70,6 +71,9 @@ val Kosmos.shortcutHelperStateRepository by
val Kosmos.shortcutHelperInputShortcutsSource by
Kosmos.Fixture { InputShortcutsSource(mainResources, windowManager) }
+val Kosmos.shortcutHelperCurrentAppShortcutsSource by
+ Kosmos.Fixture { CurrentAppShortcutsSource(windowManager) }
+
val Kosmos.shortcutHelperCategoriesRepository by
Kosmos.Fixture {
ShortcutHelperCategoriesRepository(
@@ -79,6 +83,7 @@ val Kosmos.shortcutHelperCategoriesRepository by
shortcutHelperMultiTaskingShortcutsSource,
shortcutHelperAppCategoriesShortcutsSource,
shortcutHelperInputShortcutsSource,
+ shortcutHelperCurrentAppShortcutsSource,
fakeInputManager.inputManager,
shortcutHelperStateRepository,
)