diff options
| author | 2024-11-27 19:49:28 +0000 | |
|---|---|---|
| committer | 2024-11-27 20:15:58 +0000 | |
| commit | d0aee4d9d1856004ae07f347d3249fb8fe88b746 (patch) | |
| tree | 2867b981f8bd12b06c4d50f13acea40cf016c32d | |
| parent | bb77d47c91b46494b1b1a63a5ca3bf56980a2442 (diff) | |
[Custom Key Glyph] Make display order of shortcuts the same before and after the flag is enabled
The order of shortcut is different because hardwareShortcuts is added before systemControlsShortcuts in SystemShortcutsSource.
Issue: https://screenshot.googleplex.com/6u66SMThR5DSG2B
Before and after fix: https://screenshot.googleplex.com/B39fjELbUfXPVeW
This fix also sorts the shortcuts by key size ascendingly to display the function row keys (e.g. Home,back,overview key) first, same as before the flag is enabled.
Bug: 376433516
Test: ShortcutHelperCategoriesInteractorTest
Flag: com.android.systemui.shortcut_helper_key_glyph
Change-Id: I851273a5433c2e5c3769e9c6d50a8f4d20e23e26
4 files changed, 47 insertions, 2 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt index 7855d4219788..6d3c983fcf7c 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt @@ -75,6 +75,27 @@ object TestShortcuts { /* modifiers = */ KeyEvent.META_SHIFT_ON, ) + private val ShortcutsWithDiffSizeOfKeys = + KeyboardShortcutInfo( + /* label = */ "Shortcuts with diff size of keys", + /* keycode = */ KeyEvent.KEYCODE_HOME, + /* modifiers = */ 0, + ) + + private val ShortcutsWithDiffSizeOfKeys2 = + KeyboardShortcutInfo( + /* label = */ ShortcutsWithDiffSizeOfKeys.label, + /* keycode = */ KeyEvent.KEYCODE_1, + /* modifiers = */ META_META_ON, + ) + + private val ShortcutsWithDiffSizeOfKeys3 = + KeyboardShortcutInfo( + /* label = */ ShortcutsWithDiffSizeOfKeys.label, + /* keycode = */ KeyEvent.KEYCODE_2, + /* modifiers = */ META_META_ON or META_FUNCTION_ON, + ) + private val shortcutWithGroupedRepeatedLabel = shortcut(shortcutInfoWithRepeatedLabel.label!!.toString()) { command { @@ -382,6 +403,16 @@ object TestShortcuts { groupWithSupportedAndUnsupportedModifierShortcut, ) + val groupWithDifferentSizeOfShortcutKeys = + KeyboardShortcutGroup( + "Group with different size of shortcut keys", + listOf( + ShortcutsWithDiffSizeOfKeys3, + ShortcutsWithDiffSizeOfKeys, + ShortcutsWithDiffSizeOfKeys2, + ), + ) + val subCategoriesWithUnsupportedModifiersRemoved = listOf(subCategoryWithStandardShortcut, subCategoryWithUnsupportedShortcutsRemoved) diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt index c3cedba65340..8f0bc640f0eb 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt @@ -369,6 +369,20 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { } } + @Test + fun categories_showShortcutsInAscendingOrderOfKeySize() = + testScope.runTest { + systemShortcutsSource.setGroups(TestShortcuts.groupWithDifferentSizeOfShortcutKeys) + val categories by collectLastValue(interactor.shortcutCategories) + + helper.showFromActivity() + + val systemCategoryShortcuts = categories?.get(0)?.subCategories?.get(0)?.shortcuts + val shortcutKeyCount = + systemCategoryShortcuts?.flatMap { it.commands }?.map { it.keys.size } + assertThat(shortcutKeyCount).containsExactly(1, 2, 3).inOrder() + } + private fun setCustomInputGestures(customInputGestures: List<InputGestureData>) { whenever(fakeInputManager.inputManager.getCustomInputGestures(/* filter= */ anyOrNull())) .thenReturn(customInputGestures) diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/SystemShortcutsSource.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/SystemShortcutsSource.kt index a650cd889381..b5b66e9b52e1 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/SystemShortcutsSource.kt +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/SystemShortcutsSource.kt @@ -54,7 +54,7 @@ constructor(@Main private val resources: Resources, private val inputManager: In listOf( KeyboardShortcutGroup( resources.getString(R.string.shortcut_helper_category_system_controls), - hardwareShortcuts(deviceId) + systemControlsShortcuts(), + systemControlsShortcuts() + hardwareShortcuts(deviceId), ), KeyboardShortcutGroup( resources.getString(R.string.shortcut_helper_category_system_apps), 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 2385cc6a4c47..d62584644743 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 @@ -95,7 +95,7 @@ constructor( Shortcut( label = commonLabel, icon = groupedShortcuts.firstOrNull()?.icon, - commands = groupedShortcuts.flatMap { it.commands }, + commands = groupedShortcuts.flatMap { it.commands }.sortedBy { it.keys.size }, contentDescription = toContentDescription(commonLabel, groupedShortcuts.flatMap { it.commands }), ) |