From a8c9fea44e1ed5730bbbdb2e0b49db5d398b8632 Mon Sep 17 00:00:00 2001 From: Elliot Date: Thu, 18 Jul 2024 16:57:54 +0800 Subject: [PATCH 1/3] feat: redesign keyboard theme --- .../com/elliot00/liushu/input/InputView.kt | 2 +- .../input/keyboard/key/preset/AlphabetKey.kt | 18 ++++++++++++------ .../input/keyboard/key/preset/BackspaceKey.kt | 1 - .../input/keyboard/key/preset/EnterKey.kt | 3 +-- .../input/keyboard/key/preset/LanguageKey.kt | 4 ++-- .../keyboard/key/preset/LayoutSwitchKey.kt | 3 +-- .../keyboard/key/preset/PunctuationKey.kt | 5 +++-- .../input/keyboard/key/preset/ShiftKey.kt | 1 - .../input/keyboard/key/preset/SpaceKey.kt | 7 ++++--- 9 files changed, 24 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/elliot00/liushu/input/InputView.kt b/app/src/main/java/com/elliot00/liushu/input/InputView.kt index 9be8834..920f176 100644 --- a/app/src/main/java/com/elliot00/liushu/input/InputView.kt +++ b/app/src/main/java/com/elliot00/liushu/input/InputView.kt @@ -63,7 +63,7 @@ private fun InputScreen( ) { val screenHeight = LocalConfiguration.current.screenHeightDp.dp - Surface(tonalElevation = 5.dp, modifier = Modifier.height(screenHeight / 3)) { + Surface(modifier = Modifier.height(screenHeight / 3)) { InputTokensPopup(state.segmentedTokens.joinToString(separator = " ")) Column( diff --git a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/AlphabetKey.kt b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/AlphabetKey.kt index 0dc06d1..535396b 100644 --- a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/AlphabetKey.kt +++ b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/AlphabetKey.kt @@ -34,6 +34,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.sp import com.elliot00.liushu.input.keyboard.key.VariantKeyLabel @@ -59,10 +60,10 @@ fun RowScope.AlphabetKey( Box( modifier = Modifier .background( - color = MaterialTheme.colorScheme.surface, - shape = MaterialTheme.shapes.medium + color = MaterialTheme.colorScheme.surfaceContainerLowest, + shape = MaterialTheme.shapes.small ) - .clip(shape = MaterialTheme.shapes.medium) + .clip(shape = MaterialTheme.shapes.small) .weight(1f) .fillMaxHeight() .pointerInput(Unit) { @@ -114,11 +115,16 @@ fun RowScope.AlphabetKey( }, contentAlignment = Alignment.Center ) { - Text(text = swipeUpText, fontSize = 8.sp, modifier = Modifier.align(Alignment.TopEnd)) + Text( + text = swipeUpText, + fontSize = 12.sp, + fontFamily = FontFamily.Monospace, + modifier = Modifier.align(Alignment.TopEnd) + ) Text( text = text, - color = MaterialTheme.colorScheme.onSurface, - fontSize = 28.sp, + fontSize = 26.sp, + fontFamily = FontFamily.Monospace, textAlign = TextAlign.Center ) } diff --git a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/BackspaceKey.kt b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/BackspaceKey.kt index 73c18bd..580ab12 100644 --- a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/BackspaceKey.kt +++ b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/BackspaceKey.kt @@ -46,7 +46,6 @@ fun RowScope.BackspaceKey( Icon( painter = painterResource(id = R.drawable.ic_outline_backspace_24), contentDescription = "Backspace key", - tint = MaterialTheme.colorScheme.onSecondaryContainer ) } } \ No newline at end of file diff --git a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/EnterKey.kt b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/EnterKey.kt index a7da6a5..3be68e5 100644 --- a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/EnterKey.kt +++ b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/EnterKey.kt @@ -37,7 +37,7 @@ fun RowScope.EnterKey( onClick = onClick, modifier = Modifier .background( - color = MaterialTheme.colorScheme.primaryContainer, + color = MaterialTheme.colorScheme.inversePrimary, shape = MaterialTheme.shapes.extraLarge ) .clip(shape = MaterialTheme.shapes.extraLarge) @@ -46,7 +46,6 @@ fun RowScope.EnterKey( Icon( painter = painterResource(id = R.drawable.ic_baseline_keyboard_return_24), contentDescription = "Enter key", - tint = MaterialTheme.colorScheme.onPrimaryContainer ) } } \ No newline at end of file diff --git a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/LanguageKey.kt b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/LanguageKey.kt index 79d67a2..34b5fc4 100644 --- a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/LanguageKey.kt +++ b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/LanguageKey.kt @@ -38,7 +38,8 @@ fun RowScope.LanguageKey( onLongClick = null, modifier = Modifier .background( - color = MaterialTheme.colorScheme.surface, shape = MaterialTheme.shapes.medium + color = MaterialTheme.colorScheme.surfaceContainerLowest, + shape = MaterialTheme.shapes.medium ) .clip(shape = MaterialTheme.shapes.medium) .weight(1f), @@ -46,7 +47,6 @@ fun RowScope.LanguageKey( Icon( painter = painterResource(id = R.drawable.ic_baseline_language_24), contentDescription = "Enter key", - tint = MaterialTheme.colorScheme.onSurface ) } } \ No newline at end of file diff --git a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/LayoutSwitchKey.kt b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/LayoutSwitchKey.kt index 86214ba..d6c2892 100644 --- a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/LayoutSwitchKey.kt +++ b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/LayoutSwitchKey.kt @@ -38,7 +38,7 @@ fun RowScope.LayoutSwitchKey( onClick = onClick, modifier = Modifier .background( - color = MaterialTheme.colorScheme.tertiaryContainer, + color = MaterialTheme.colorScheme.outlineVariant, shape = MaterialTheme.shapes.extraLarge ) .clip(shape = MaterialTheme.shapes.extraLarge) @@ -46,7 +46,6 @@ fun RowScope.LayoutSwitchKey( ) { Text( text = label, - color = MaterialTheme.colorScheme.onTertiaryContainer, fontSize = 18.sp, textAlign = TextAlign.Center ) diff --git a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/PunctuationKey.kt b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/PunctuationKey.kt index 908e355..f139eba 100644 --- a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/PunctuationKey.kt +++ b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/PunctuationKey.kt @@ -24,6 +24,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.sp import com.elliot00.liushu.input.keyboard.key.Key @@ -50,8 +51,8 @@ fun RowScope.PunctuationKey( ) { Text( text = text, - color = MaterialTheme.colorScheme.onSecondaryContainer, - fontSize = 28.sp, + fontSize = 26.sp, + fontFamily = FontFamily.Monospace, textAlign = TextAlign.Center ) } diff --git a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/ShiftKey.kt b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/ShiftKey.kt index ce51dec..a21a188 100644 --- a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/ShiftKey.kt +++ b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/ShiftKey.kt @@ -46,7 +46,6 @@ fun RowScope.ShiftKey( Icon( painter = painterResource(id = R.drawable.ic_capslock_none), contentDescription = "Shift key", - tint = MaterialTheme.colorScheme.onSecondaryContainer ) } } \ No newline at end of file diff --git a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/SpaceKey.kt b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/SpaceKey.kt index 6898bf1..c33991b 100644 --- a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/SpaceKey.kt +++ b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/SpaceKey.kt @@ -24,6 +24,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.sp import com.elliot00.liushu.input.keyboard.key.BaseKey @@ -37,7 +38,7 @@ fun RowScope.SpaceKey( onClick = onClick, modifier = Modifier .background( - color = MaterialTheme.colorScheme.surface, + color = MaterialTheme.colorScheme.surfaceContainerLowest, shape = MaterialTheme.shapes.medium ) .clip(shape = MaterialTheme.shapes.medium) @@ -45,8 +46,8 @@ fun RowScope.SpaceKey( ) { Text( text = "⎵", - color = MaterialTheme.colorScheme.onSurface, - fontSize = 28.sp, + fontSize = 26.sp, + fontFamily = FontFamily.Monospace, textAlign = TextAlign.Center ) } From 853ef41edc1e04fe64650c53b9c1e8c5fa85fc19 Mon Sep 17 00:00:00 2001 From: Elliot Date: Fri, 19 Jul 2024 11:18:10 +0800 Subject: [PATCH 2/3] fix: press enter not clear input state --- .../liushu/input/service/LiushuInputMethodService.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/com/elliot00/liushu/input/service/LiushuInputMethodService.kt b/app/src/main/java/com/elliot00/liushu/input/service/LiushuInputMethodService.kt index d89f625..f8cbd1b 100644 --- a/app/src/main/java/com/elliot00/liushu/input/service/LiushuInputMethodService.kt +++ b/app/src/main/java/com/elliot00/liushu/input/service/LiushuInputMethodService.kt @@ -215,6 +215,13 @@ class LiushuInputMethodService : LifecycleInputMethodService(), SavedStateRegist private fun handleEnter() { if (_state.value.input.isNotEmpty()) { commitText(_state.value.input) + _state.update { + it.copy( + input = "", + segmentedTokens = emptyList(), + candidates = emptyList() + ) + } } else { val inputType = currentInputEditorInfo.inputType if ((inputType and InputType.TYPE_TEXT_FLAG_MULTI_LINE) != 0) { From 178724dfcecce419ce5931c303816570189658bf Mon Sep 17 00:00:00 2001 From: Elliot Date: Tue, 23 Jul 2024 15:37:44 +0800 Subject: [PATCH 3/3] feat: support caps lock --- .../com/elliot00/liushu/input/keyboard/key/preset/ShiftKey.kt | 4 +++- .../input/keyboard/layout/preset/QwertyKeyboardLayout.kt | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/ShiftKey.kt b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/ShiftKey.kt index a21a188..50ae16b 100644 --- a/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/ShiftKey.kt +++ b/app/src/main/java/com/elliot00/liushu/input/keyboard/key/preset/ShiftKey.kt @@ -30,11 +30,13 @@ import com.elliot00.liushu.input.keyboard.key.BaseKey @Composable fun RowScope.ShiftKey( - onClick: () -> Unit + onClick: () -> Unit, + onLongClick: () -> Unit, ) { BaseKey( onClick = onClick, + onLongClick = onLongClick, modifier = Modifier .background( color = MaterialTheme.colorScheme.secondaryContainer, diff --git a/app/src/main/java/com/elliot00/liushu/input/keyboard/layout/preset/QwertyKeyboardLayout.kt b/app/src/main/java/com/elliot00/liushu/input/keyboard/layout/preset/QwertyKeyboardLayout.kt index ba2909b..976ca0d 100644 --- a/app/src/main/java/com/elliot00/liushu/input/keyboard/layout/preset/QwertyKeyboardLayout.kt +++ b/app/src/main/java/com/elliot00/liushu/input/keyboard/layout/preset/QwertyKeyboardLayout.kt @@ -218,7 +218,9 @@ fun QwertyKeyboardLayout( Box(modifier = Modifier.weight(0.5f)) } KeyboardRow { - ShiftKey(onClick = { onAction(InputMethodAction.Shift) }) + ShiftKey( + onClick = { onAction(InputMethodAction.Shift) }, + onLongClick = { onAction(InputMethodAction.CapsLock) }) AlphabetKey( label = VariantKeyLabel(text = "z", textInCapsLock = "Z"), isAsciiMode = isAsciiMode,