mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Fix keyboard height setting and add a test
This commit is contained in:
parent
778c973c60
commit
9e75e45056
@ -112,7 +112,7 @@ public final class KeyboardSwitcher implements SwitchActions {
|
|||||||
|| !mThemeContext.getResources().equals(context.getResources())) {
|
|| !mThemeContext.getResources().equals(context.getResources())) {
|
||||||
mKeyboardTheme = keyboardTheme;
|
mKeyboardTheme = keyboardTheme;
|
||||||
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
|
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
|
||||||
KeyboardLayoutSetV2.onKeyboardThemeChanged();
|
KeyboardLayoutSetV2.onKeyboardThemeChanged(context);
|
||||||
themeSwitchPending = false;
|
themeSwitchPending = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -41,11 +41,7 @@ import androidx.compose.ui.unit.Dp
|
|||||||
import androidx.compose.ui.unit.LayoutDirection
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import org.futo.inputmethod.latin.uix.KeyBordersSetting
|
import org.futo.inputmethod.latin.uix.KeyBordersSetting
|
||||||
import org.futo.inputmethod.latin.uix.KeyHintsSetting
|
|
||||||
import org.futo.inputmethod.latin.uix.KeyboardBottomOffsetSetting
|
|
||||||
import org.futo.inputmethod.latin.uix.KeyboardHeightMultiplierSetting
|
|
||||||
import org.futo.inputmethod.latin.uix.THEME_KEY
|
import org.futo.inputmethod.latin.uix.THEME_KEY
|
||||||
import org.futo.inputmethod.latin.uix.settings.SettingSlider
|
|
||||||
import org.futo.inputmethod.latin.uix.settings.SettingToggleDataStore
|
import org.futo.inputmethod.latin.uix.settings.SettingToggleDataStore
|
||||||
import org.futo.inputmethod.latin.uix.settings.useDataStore
|
import org.futo.inputmethod.latin.uix.settings.useDataStore
|
||||||
import org.futo.inputmethod.latin.uix.theme.ThemeOption
|
import org.futo.inputmethod.latin.uix.theme.ThemeOption
|
||||||
@ -59,7 +55,6 @@ import org.futo.inputmethod.latin.uix.theme.presets.DynamicDarkTheme
|
|||||||
import org.futo.inputmethod.latin.uix.theme.presets.DynamicLightTheme
|
import org.futo.inputmethod.latin.uix.theme.presets.DynamicLightTheme
|
||||||
import org.futo.inputmethod.latin.uix.theme.presets.DynamicSystemTheme
|
import org.futo.inputmethod.latin.uix.theme.presets.DynamicSystemTheme
|
||||||
import org.futo.inputmethod.latin.uix.theme.presets.VoiceInputTheme
|
import org.futo.inputmethod.latin.uix.theme.presets.VoiceInputTheme
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ThemePreview(theme: ThemeOption, isSelected: Boolean = false, overrideName: String? = null, modifier: Modifier = Modifier, onClick: () -> Unit = { }) {
|
fun ThemePreview(theme: ThemeOption, isSelected: Boolean = false, overrideName: String? = null, modifier: Modifier = Modifier, onClick: () -> Unit = { }) {
|
||||||
|
@ -180,17 +180,12 @@ class KeyboardLayoutSetV2 internal constructor(
|
|||||||
NumberRowMode.AlwaysDisabled -> false
|
NumberRowMode.AlwaysDisabled -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
private val keyboardHeightMultiplier = context.getSettingBlocking(KeyboardHeightMultiplierSetting)
|
|
||||||
|
|
||||||
private val singularRowHeight: Double
|
private val singularRowHeight: Double
|
||||||
get() = params.height?.let { it / 4.0 } ?: run {
|
get() = params.height?.let { it / 4.0 } ?: run {
|
||||||
(ResourceUtils.getDefaultKeyboardHeight(context.resources) / 4.0) *
|
(ResourceUtils.getDefaultKeyboardHeight(context.resources) / 4.0) *
|
||||||
keyboardHeightMultiplier
|
keyboardHeightMultiplier
|
||||||
}
|
}
|
||||||
|
|
||||||
// params.height?.let { it / 4.0 } ?: (50.0 * context.resources.displayMetrics.density * keyboardHeightMultiplier)
|
|
||||||
|
|
||||||
|
|
||||||
private fun getRecommendedKeyboardHeight(): Int {
|
private fun getRecommendedKeyboardHeight(): Int {
|
||||||
val numRows = 4.0 +
|
val numRows = 4.0 +
|
||||||
((mainLayout.effectiveRows.size - 5) / 2.0).coerceAtLeast(0.0) +
|
((mainLayout.effectiveRows.size - 5) / 2.0).coerceAtLeast(0.0) +
|
||||||
@ -263,14 +258,18 @@ Stack trace: ${e.stackTrace.map { it.toString() }}
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
var keyboardHeightMultiplier: Float = 1.0f
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun onSystemLocaleChanged() {
|
fun onSystemLocaleChanged() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun onKeyboardThemeChanged() {
|
fun onKeyboardThemeChanged(context: Context) {
|
||||||
|
keyboardHeightMultiplier = context.getSettingBlocking(KeyboardHeightMultiplierSetting)
|
||||||
|
|
||||||
|
// This is where we would clear all caches if we had any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
|||||||
|
|
||||||
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
|
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
|
||||||
setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId));
|
setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId));
|
||||||
KeyboardLayoutSetV2.onKeyboardThemeChanged();
|
KeyboardLayoutSetV2.onKeyboardThemeChanged(getContext());
|
||||||
|
|
||||||
mScreenMetrics = Settings.readScreenMetrics(res);
|
mScreenMetrics = Settings.readScreenMetrics(res);
|
||||||
|
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
package org.futo.inputmethod.keyboard.internal
|
||||||
|
|
||||||
|
import android.test.AndroidTestCase
|
||||||
|
import android.view.inputmethod.EditorInfo
|
||||||
|
import androidx.datastore.preferences.core.edit
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import org.futo.inputmethod.latin.uix.KeyboardHeightMultiplierSetting
|
||||||
|
import org.futo.inputmethod.latin.uix.dataStore
|
||||||
|
import org.futo.inputmethod.v2keyboard.KeyboardLayoutSetV2
|
||||||
|
import org.futo.inputmethod.v2keyboard.KeyboardLayoutSetV2Params
|
||||||
|
import java.util.Locale
|
||||||
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
|
class KeyboardLayoutSetV2Tests : AndroidTestCase() {
|
||||||
|
private val layoutParams = KeyboardLayoutSetV2Params(
|
||||||
|
width = 1024,
|
||||||
|
height = null,
|
||||||
|
keyboardLayoutSet = "qwerty",
|
||||||
|
locale = Locale.ENGLISH,
|
||||||
|
editorInfo = EditorInfo(),
|
||||||
|
numberRow = false,
|
||||||
|
useSplitLayout = false,
|
||||||
|
bottomActionKey = null
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun setHeight(to: Float) {
|
||||||
|
runBlocking {
|
||||||
|
context.dataStore.edit { it[KeyboardHeightMultiplierSetting.key] = to }
|
||||||
|
}
|
||||||
|
KeyboardLayoutSetV2.onKeyboardThemeChanged(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun resetHeight() {
|
||||||
|
runBlocking {
|
||||||
|
context.dataStore.edit { it.remove(KeyboardHeightMultiplierSetting.key) }
|
||||||
|
}
|
||||||
|
KeyboardLayoutSetV2.onKeyboardThemeChanged(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getActualHeight(layoutSet: KeyboardLayoutSetV2): Int {
|
||||||
|
return layoutSet.getKeyboard(
|
||||||
|
KeyboardLayoutElement(
|
||||||
|
kind = KeyboardLayoutKind.Alphabet,
|
||||||
|
page = KeyboardLayoutPage.Base
|
||||||
|
)
|
||||||
|
).mBaseHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testKeyboardHeightSettingAffectsHeight() {
|
||||||
|
try {
|
||||||
|
val layoutSet = KeyboardLayoutSetV2(context, layoutParams)
|
||||||
|
|
||||||
|
// Allow for 1px rounding error
|
||||||
|
val eps = 1.0f
|
||||||
|
|
||||||
|
setHeight(1.0f)
|
||||||
|
val baseHeight = getActualHeight(layoutSet)
|
||||||
|
|
||||||
|
setHeight(2.0f)
|
||||||
|
assert((2.0f * baseHeight - getActualHeight(layoutSet)).absoluteValue < eps)
|
||||||
|
|
||||||
|
setHeight(0.5f)
|
||||||
|
assert((0.5f * baseHeight - getActualHeight(layoutSet)).absoluteValue < eps)
|
||||||
|
} finally {
|
||||||
|
resetHeight()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user