Skip to content

Commit

Permalink
Implement NumericKeyboard and SymbolicKeyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
bingzheung committed Aug 25, 2024
1 parent 98c127e commit dd48b1a
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ import org.jyutping.jyutping.keyboard.CantoneseNumericKeyboard
import org.jyutping.jyutping.keyboard.CantoneseSymbolicKeyboard
import org.jyutping.jyutping.keyboard.EditingPanel
import org.jyutping.jyutping.keyboard.EmojiBoard
import org.jyutping.jyutping.keyboard.NumericKeyboard
import org.jyutping.jyutping.keyboard.QwertyForm
import org.jyutping.jyutping.keyboard.SettingsScreen
import org.jyutping.jyutping.keyboard.StrokeKeyboard
import org.jyutping.jyutping.keyboard.SymbolicKeyboard
import org.jyutping.jyutping.presets.PresetConstant

class ComposeKeyboardView(context: Context) : AbstractComposeView(context) {

@Composable
override fun Content() {
val inputMethodMode = remember { (context as JyutpingInputMethodService).inputMethodMode }
val keyboardForm = remember { (context as JyutpingInputMethodService).keyboardForm }
val qwertyForm = remember { (context as JyutpingInputMethodService).qwertyForm }
when (keyboardForm.value) {
Expand All @@ -33,8 +36,8 @@ class ComposeKeyboardView(context: Context) : AbstractComposeView(context) {
else -> AlphabeticKeyboard(keyHeight = responsiveKeyHeight())
}
KeyboardForm.CandidateBoard -> CandidateBoard(height = keyboardHeight())
KeyboardForm.Numeric -> CantoneseNumericKeyboard(keyHeight = responsiveKeyHeight())
KeyboardForm.Symbolic -> CantoneseSymbolicKeyboard(keyHeight = responsiveKeyHeight())
KeyboardForm.Numeric -> if (inputMethodMode.value.isABC()) NumericKeyboard(keyHeight = responsiveKeyHeight()) else CantoneseNumericKeyboard(keyHeight = responsiveKeyHeight())
KeyboardForm.Symbolic -> if (inputMethodMode.value.isABC()) SymbolicKeyboard(keyHeight = responsiveKeyHeight()) else CantoneseSymbolicKeyboard(keyHeight = responsiveKeyHeight())
KeyboardForm.Settings -> SettingsScreen(height = keyboardHeight())
KeyboardForm.EmojiBoard -> EmojiBoard(height = keyboardHeight())
KeyboardForm.EditingPanel -> EditingPanel(height = keyboardHeight())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import org.jyutping.jyutping.keyboard.Segmentor
import org.jyutping.jyutping.keyboard.SpaceKeyForm
import org.jyutping.jyutping.keyboard.Stroke
import org.jyutping.jyutping.keyboard.Structure
import org.jyutping.jyutping.keyboard.isABC
import org.jyutping.jyutping.keyboard.length
import org.jyutping.jyutping.keyboard.transformed
import org.jyutping.jyutping.presets.PresetColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package org.jyutping.jyutping.keyboard

enum class InputMethodMode {
Cantonese,
ABC
ABC;
fun isCantonese(): Boolean = (this == Cantonese)
fun isABC(): Boolean = (this == ABC)
}

fun InputMethodMode.isCantonese(): Boolean = (this == InputMethodMode.Cantonese)
fun InputMethodMode.isABC(): Boolean = (this == InputMethodMode.ABC)
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package org.jyutping.jyutping.keyboard

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import org.jyutping.jyutping.JyutpingInputMethodService
import org.jyutping.jyutping.presets.PresetColor
import org.jyutping.jyutping.presets.PresetConstant

@Composable
fun NumericKeyboard(keyHeight: Dp) {
val context = LocalContext.current as JyutpingInputMethodService
val isDarkMode = remember { context.isDarkMode }
Column(
modifier = Modifier
.background(if (isDarkMode.value) PresetColor.keyboardDarkBackground else PresetColor.keyboardLightBackground)
.fillMaxWidth()
) {
Box(
modifier = Modifier
.height(PresetConstant.ToolBarHeight.dp)
.fillMaxWidth(),
contentAlignment = Alignment.Center
) {
if (isDarkMode.value) PresetColor.keyboardDarkBackground else PresetColor.keyboardLightBackground
ToolBar()
}
Row(
modifier = Modifier
.height(keyHeight)
.fillMaxWidth()
) {
SymbolKey(symbol = "1", modifier = Modifier.weight(1f))
SymbolKey(symbol = "2", modifier = Modifier.weight(1f))
SymbolKey(symbol = "3", modifier = Modifier.weight(1f))
SymbolKey(symbol = "4", modifier = Modifier.weight(1f))
SymbolKey(symbol = "5", modifier = Modifier.weight(1f))
SymbolKey(symbol = "6", modifier = Modifier.weight(1f))
SymbolKey(symbol = "7", modifier = Modifier.weight(1f))
SymbolKey(symbol = "8", modifier = Modifier.weight(1f))
SymbolKey(symbol = "9", modifier = Modifier.weight(1f))
SymbolKey(symbol = "0", modifier = Modifier.weight(1f))
}
Row(
modifier = Modifier
.height(keyHeight)
.fillMaxWidth()
) {
SymbolKey(symbol = "-", modifier = Modifier.weight(1f))
SymbolKey(symbol = "/", modifier = Modifier.weight(1f))
SymbolKey(symbol = ":", modifier = Modifier.weight(1f))
SymbolKey(symbol = ";", modifier = Modifier.weight(1f))
SymbolKey(symbol = "(", modifier = Modifier.weight(1f))
SymbolKey(symbol = ")", modifier = Modifier.weight(1f))
SymbolKey(symbol = "$", modifier = Modifier.weight(1f))
SymbolKey(symbol = "&", modifier = Modifier.weight(1f))
SymbolKey(symbol = "@", modifier = Modifier.weight(1f))
SymbolKey(symbol = "\"", modifier = Modifier.weight(1f))
}
Row(
modifier = Modifier
.height(keyHeight)
.fillMaxWidth()
) {
TransformKey(destination = KeyboardForm.Symbolic, modifier = Modifier.weight(1.3f))
Spacer(modifier = Modifier.weight(0.22f))
SymbolKey(symbol = ".", modifier = Modifier.weight(1.16f))
SymbolKey(symbol = ",", modifier = Modifier.weight(1.16f))
SymbolKey(symbol = "?", modifier = Modifier.weight(1.16f))
SymbolKey(symbol = "!", modifier = Modifier.weight(1.16f))
SymbolKey(symbol = "*", modifier = Modifier.weight(1.16f))
SymbolKey(symbol = "'", modifier = Modifier.weight(1.16f))
Spacer(modifier = Modifier.weight(0.22f))
BackspaceKey(modifier = Modifier.weight(1.3f))
}
Row(
modifier = Modifier
.height(keyHeight)
.fillMaxWidth()
) {
TransformKey(destination = KeyboardForm.Alphabetic, modifier = Modifier.weight(2f))
LeftKey(modifier = Modifier.weight(1f))
SpaceKey(modifier = Modifier.weight(4f))
RightKey(modifier = Modifier.weight(1f))
ReturnKey(modifier = Modifier.weight(2f))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package org.jyutping.jyutping.keyboard

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import org.jyutping.jyutping.JyutpingInputMethodService
import org.jyutping.jyutping.presets.PresetColor
import org.jyutping.jyutping.presets.PresetConstant

@Composable
fun SymbolicKeyboard(keyHeight: Dp) {
val context = LocalContext.current as JyutpingInputMethodService
val isDarkMode = remember { context.isDarkMode }
Column(
modifier = Modifier
.background(if (isDarkMode.value) PresetColor.keyboardDarkBackground else PresetColor.keyboardLightBackground)
.fillMaxWidth()
) {
Box(
modifier = Modifier
.height(PresetConstant.ToolBarHeight.dp)
.fillMaxWidth(),
contentAlignment = Alignment.Center
) {
if (isDarkMode.value) PresetColor.keyboardDarkBackground else PresetColor.keyboardLightBackground
ToolBar()
}
Row(
modifier = Modifier
.height(keyHeight)
.fillMaxWidth()
) {
SymbolKey(symbol = "[", modifier = Modifier.weight(1f))
SymbolKey(symbol = "]", modifier = Modifier.weight(1f))
SymbolKey(symbol = "{", modifier = Modifier.weight(1f))
SymbolKey(symbol = "}", modifier = Modifier.weight(1f))
SymbolKey(symbol = "#", modifier = Modifier.weight(1f))
SymbolKey(symbol = "%", modifier = Modifier.weight(1f))
SymbolKey(symbol = "^", modifier = Modifier.weight(1f))
SymbolKey(symbol = "*", modifier = Modifier.weight(1f))
SymbolKey(symbol = "+", modifier = Modifier.weight(1f))
SymbolKey(symbol = "=", modifier = Modifier.weight(1f))
}
Row(
modifier = Modifier
.height(keyHeight)
.fillMaxWidth()
) {
SymbolKey(symbol = "_", modifier = Modifier.weight(1f))
SymbolKey(symbol = "\\", modifier = Modifier.weight(1f))
SymbolKey(symbol = "|", modifier = Modifier.weight(1f))
SymbolKey(symbol = "~", modifier = Modifier.weight(1f))
SymbolKey(symbol = "<", modifier = Modifier.weight(1f))
SymbolKey(symbol = ">", modifier = Modifier.weight(1f))
SymbolKey(symbol = "", modifier = Modifier.weight(1f))
SymbolKey(symbol = "£", modifier = Modifier.weight(1f))
SymbolKey(symbol = "¥", modifier = Modifier.weight(1f))
SymbolKey(symbol = "", modifier = Modifier.weight(1f))
}
Row(
modifier = Modifier
.height(keyHeight)
.fillMaxWidth()
) {
TransformKey(destination = KeyboardForm.Numeric, modifier = Modifier.weight(1.3f))
Spacer(modifier = Modifier.weight(0.22f))
SymbolKey(symbol = ".", modifier = Modifier.weight(1.16f))
SymbolKey(symbol = ",", modifier = Modifier.weight(1.16f))
SymbolKey(symbol = "?", modifier = Modifier.weight(1.16f))
SymbolKey(symbol = "!", modifier = Modifier.weight(1.16f))
SymbolKey(symbol = "&", modifier = Modifier.weight(1.16f))
SymbolKey(symbol = "'", modifier = Modifier.weight(1.16f))
Spacer(modifier = Modifier.weight(0.22f))
BackspaceKey(modifier = Modifier.weight(1.3f))
}
Row(
modifier = Modifier
.height(keyHeight)
.fillMaxWidth()
) {
TransformKey(destination = KeyboardForm.Alphabetic, modifier = Modifier.weight(2f))
LeftKey(modifier = Modifier.weight(1f))
SpaceKey(modifier = Modifier.weight(4f))
RightKey(modifier = Modifier.weight(1f))
ReturnKey(modifier = Modifier.weight(2f))
}
}
}

0 comments on commit dd48b1a

Please sign in to comment.