Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement non-square keys #692

Merged
merged 3 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion app/src/main/java/com/dessalines/thumbkey/db/AppDb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ data class AppSettings(
defaultValue = DEFAULT_KEY_SIZE.toString(),
)
val keySize: Int,
@ColumnInfo(
name = "key_width",
)
val keyWidth: Int?,
@ColumnInfo(
name = "animation_speed",
defaultValue = DEFAULT_ANIMATION_SPEED.toString(),
Expand Down Expand Up @@ -217,6 +221,10 @@ data class LookAndFeelUpdate(
name = "key_size",
)
val keySize: Int,
@ColumnInfo(
name = "key_width",
)
val keyWidth: Int?,
@ColumnInfo(
name = "animation_speed",
)
Expand Down Expand Up @@ -494,8 +502,17 @@ val MIGRATION_12_13 =
}
}

val MIGRATION_13_14 =
object : Migration(13, 14) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL(
"alter table AppSettings add column key_width INTEGER",
)
}
}

@Database(
version = 13,
version = 14,
entities = [AppSettings::class],
exportSchema = true,
)
Expand Down Expand Up @@ -530,6 +547,7 @@ abstract class AppDB : RoomDatabase() {
MIGRATION_10_11,
MIGRATION_11_12,
MIGRATION_12_13,
MIGRATION_13_14,
)
// Necessary because it can't insert data on creation
.addCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ fun KeyboardKey(
hideLetters: Boolean,
hideSymbols: Boolean,
capsLock: Boolean,
legendSize: Int,
legendHeight: Int,
legendWidth: Int,
keyPadding: Int,
keyBorderWidth: Float,
keyRadius: Float,
Expand All @@ -105,7 +106,7 @@ fun KeyboardKey(
// Necessary for swipe settings to get updated correctly
val id =
key.toString() + animationHelperSpeed + animationSpeed + autoCapitalize +
vibrateOnTap + soundOnTap + legendSize + minSwipeLength + slideSensitivity +
vibrateOnTap + soundOnTap + legendHeight + legendWidth + minSwipeLength + slideSensitivity +
slideEnabled + slideCursorMovementMode + slideSpacebarDeadzoneEnabled +
slideBackspaceDeadzoneEnabled

Expand Down Expand Up @@ -142,7 +143,10 @@ fun KeyboardKey(
}

val keyBorderColour = MaterialTheme.colorScheme.outline
val keySize = legendSize + (keyPadding * 2.0) + (keyBorderWidth * 2.0)
val keyHeight = legendHeight + (keyPadding * 2.0) + (keyBorderWidth * 2.0)
val keyWidth = legendWidth + (keyPadding * 2.0) + (keyBorderWidth * 2.0)
val keySize = (keyHeight + keyWidth) / 2.0
val legendSize = (legendHeight + legendWidth) / 2
val legendPadding = 4.dp + keyBorderWidth.dp

val haptic = LocalHapticFeedback.current
Expand All @@ -161,8 +165,8 @@ fun KeyboardKey(

val keyboardKeyModifier =
Modifier
.height(keySize.dp)
.width(keySize.dp * key.widthMultiplier)
.height(keyHeight.dp)
.width(keyWidth.dp * key.widthMultiplier)
.padding(keyPadding.dp)
.clip(RoundedCornerShape(keyRadius.dp))
.then(
Expand Down Expand Up @@ -652,7 +656,7 @@ fun KeyboardKey(
val fontSize =
fontSizeVariantToFontSize(
fontSizeVariant = FontSizeVariant.LARGE,
keySize = legendSize.dp,
keySize = (legendHeight * legendWidth / 2.0).dp,
isUpperCase = false,
)
releasedKey.value?.let { text ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,19 @@ fun KeyboardScreen(
val backdropColor = MaterialTheme.colorScheme.background
val backdropPadding = 6.dp
val keyPadding = settings?.keyPadding ?: DEFAULT_KEY_PADDING
val legendSize = settings?.keySize ?: DEFAULT_KEY_SIZE
val legendHeight = settings?.keySize ?: DEFAULT_KEY_SIZE
val legendWidth = settings?.keyWidth ?: legendHeight
val keyRadius = settings?.keyRadius ?: DEFAULT_KEY_RADIUS

val keyBorderWidthFloat = keyBorderWidth / 10.0f
val keyBorderColour = MaterialTheme.colorScheme.outline
val keySize = legendSize + (keyPadding * 2.0f) + (keyBorderWidthFloat * 2.0f)
val cornerRadius = (keyRadius / 100.0f) * (keySize / 2.0f)
val keyHeight = legendHeight + (keyPadding * 2.0f) + (keyBorderWidthFloat * 2.0f)
val keyWidth = legendWidth + (keyPadding * 2.0f) + (keyBorderWidthFloat * 2.0f)
val cornerRadius = (keyRadius / 100.0f) * ((keyWidth + keyHeight) / 4.0f)

if (mode == KeyboardMode.EMOJI) {
val controllerKeys = listOf(EMOJI_BACK_KEY_ITEM, NUMERIC_KEY_ITEM, BACKSPACE_KEY_ITEM, RETURN_KEY_ITEM)
val keyboardHeight = Dp((keySize * controllerKeys.size) - (keyPadding * 2))
val keyboardHeight = Dp((keyHeight * controllerKeys.size) - (keyPadding * 2))

ctx.currentInputConnection.requestCursorUpdates(0)

Expand Down Expand Up @@ -230,7 +232,8 @@ fun KeyboardScreen(
KeyboardKey(
key = key,
lastAction = lastAction,
legendSize = legendSize,
legendHeight = legendHeight,
legendWidth = legendWidth,
keyPadding = keyPadding,
keyBorderWidth = keyBorderWidthFloat,
keyRadius = cornerRadius,
Expand Down Expand Up @@ -347,7 +350,8 @@ fun KeyboardScreen(
KeyboardKey(
key = key,
lastAction = lastAction,
legendSize = legendSize,
legendHeight = legendHeight,
legendWidth = legendWidth,
keyPadding = keyPadding,
keyBorderWidth = keyBorderWidthFloat,
keyRadius = cornerRadius,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ private fun resetAppSettingsToDefault(
hideSymbols = DEFAULT_HIDE_SYMBOLS,
keyBorders = DEFAULT_KEY_BORDERS,
keySize = DEFAULT_KEY_SIZE,
keyWidth = null,
spacebarMultiTaps = DEFAULT_SPACEBAR_MULTITAPS,
theme = DEFAULT_THEME,
themeColor = DEFAULT_THEME_COLOR,
Expand Down
Loading