diff options
| author | 2024-11-18 12:01:52 +0000 | |
|---|---|---|
| committer | 2024-11-19 10:12:46 +0000 | |
| commit | 482cb781e73b3a960b12a06a716a8c2288cb9d78 (patch) | |
| tree | e3f7ef662d9ef12475da87ec406e83efedc21891 | |
| parent | 75e4420cd29f8f6140739ecde6b15772cc0cfdc7 (diff) | |
Minor UI Changes
+ UI Component showing selected key combination will now be focused by
default
+ Set shortcut button will be enabled when user presses some
keyCombination since we cannot yet validate key combination without
attempting to set shortcut
Test: Manual, open add shortcut dialog and ensure the changes above are
in effect.
Flag: com.android.systemui.keyboard_shortcut_helper_shortcut_customizer
Bug: 373638584
Change-Id: I79008ba1d1155e4a80772b4695c77849e5973a7f
4 files changed, 11 insertions, 7 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutCustomizer.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutCustomizer.kt index 955470f426ab..d7229336c0d7 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutCustomizer.kt +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutCustomizer.kt @@ -40,10 +40,13 @@ import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.input.key.onKeyEvent @@ -86,13 +89,13 @@ fun AssignNewShortcutDialog( pressedKeys = uiState.pressedKeys, ) KeyCombinationAlreadyInUseErrorMessage(uiState.shouldShowErrorMessage) - DialogButtons(onCancel, isValidKeyCombination = uiState.isValidKeyCombination) + DialogButtons(onCancel, isSetShortcutButtonEnabled = uiState.pressedKeys.isNotEmpty()) } } } @Composable -fun DialogButtons(onCancel: () -> Unit, isValidKeyCombination: Boolean) { +fun DialogButtons(onCancel: () -> Unit, isSetShortcutButtonEnabled: Boolean) { Row( modifier = Modifier.padding(top = 24.dp, start = 24.dp, end = 24.dp) @@ -116,7 +119,7 @@ fun DialogButtons(onCancel: () -> Unit, isValidKeyCombination: Boolean) { contentColor = MaterialTheme.colorScheme.onPrimary, text = stringResource(R.string.shortcut_helper_customize_dialog_set_shortcut_button_label), - enabled = isValidKeyCombination, + enabled = isSetShortcutButtonEnabled, ) } } @@ -150,6 +153,9 @@ fun SelectedKeyCombinationContainer( if (!isFocused) MaterialTheme.colorScheme.outline else if (shouldShowErrorMessage) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primary + val focusRequester = remember { FocusRequester() } + + LaunchedEffect(Unit) { focusRequester.requestFocus() } ClickableShortcutSurface( onClick = {}, @@ -159,7 +165,8 @@ fun SelectedKeyCombinationContainer( Modifier.padding(all = 16.dp) .sizeIn(minWidth = 332.dp, minHeight = 56.dp) .border(width = 2.dp, color = outlineColor, shape = RoundedCornerShape(50.dp)) - .onKeyEvent { onKeyPress(it) }, + .onKeyEvent { onKeyPress(it) } + .focusRequester(focusRequester), interactionSource = interactionSource, ) { Row( diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/model/ShortcutCustomizationUiState.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/model/ShortcutCustomizationUiState.kt index 0080afb7160d..552c53dff6a0 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/model/ShortcutCustomizationUiState.kt +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/model/ShortcutCustomizationUiState.kt @@ -22,7 +22,6 @@ sealed interface ShortcutCustomizationUiState { data class AddShortcutDialog( val shortcutLabel: String, val shouldShowErrorMessage: Boolean, - val isValidKeyCombination: Boolean, val defaultCustomShortcutModifierKey: ShortcutKey.Icon.ResIdIcon, val isDialogShowing: Boolean, val pressedKeys: List<ShortcutKey> = emptyList(), diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModel.kt index 9a46ae25cbcb..2455ce49033d 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModel.kt @@ -66,7 +66,6 @@ constructor(private val shortcutCustomizationInteractor: ShortcutCustomizationIn ShortcutCustomizationUiState.AddShortcutDialog( shortcutLabel = requestInfo.label, shouldShowErrorMessage = false, - isValidKeyCombination = false, defaultCustomShortcutModifierKey = shortcutCustomizationInteractor.getDefaultCustomShortcutModifierKey(), isDialogShowing = false, diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModelTest.kt index ef2597f7f96c..c6f01ea9af19 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModelTest.kt @@ -223,7 +223,6 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { ShortcutCustomizationUiState.AddShortcutDialog( shortcutLabel = "Standard shortcut", shouldShowErrorMessage = false, - isValidKeyCombination = false, defaultCustomShortcutModifierKey = ShortcutKey.Icon.ResIdIcon(R.drawable.ic_ksh_key_meta), isDialogShowing = false, |