mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Fix width too long in landscape mode
This commit is contained in:
parent
d692e7b96a
commit
f795a7228e
@ -22,7 +22,7 @@
|
||||
<resources>
|
||||
<!-- Preferable keyboard height in absolute scale: 58.0mm -->
|
||||
<!-- This config_default_keyboard_height value should match with keyboard-heights.xml -->
|
||||
<dimen name="config_default_keyboard_height">365.4dp</dimen>
|
||||
<dimen name="config_default_keyboard_height">302.4dp</dimen>
|
||||
<fraction name="config_min_keyboard_height">35%p</fraction>
|
||||
|
||||
<fraction name="config_keyboard_top_padding_holo">1.896%p</fraction>
|
@ -22,7 +22,7 @@
|
||||
<resources>
|
||||
<!-- Preferable keyboard height in absolute scale: 48.0mm -->
|
||||
<!-- This config_default_keyboard_height value should match with keyboard-heights.xml -->
|
||||
<dimen name="config_default_keyboard_height">302.4dp</dimen>
|
||||
<dimen name="config_default_keyboard_height">365.4dp</dimen>
|
||||
<fraction name="config_max_keyboard_height">46%p</fraction>
|
||||
<fraction name="config_min_keyboard_height">-35.0%p</fraction>
|
||||
|
||||
|
@ -23,6 +23,7 @@ import android.util.Log;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@ -149,13 +150,15 @@ public final class KeyboardSwitcher implements SwitchActions {
|
||||
|
||||
Rect padding = new Rect();
|
||||
|
||||
Window window = mLatinIMELegacy.getInputMethodService().getWindow().getWindow();
|
||||
|
||||
if(computedSize instanceof SplitKeyboardSize) {
|
||||
keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
|
||||
keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(window, res);
|
||||
keyboardHeight = ((SplitKeyboardSize) computedSize).getHeight();
|
||||
splitLayoutWidth = ((SplitKeyboardSize) computedSize).getSplitLayoutWidth();
|
||||
padding = ((SplitKeyboardSize) computedSize).getPadding();
|
||||
}else if(computedSize instanceof RegularKeyboardSize) {
|
||||
keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
|
||||
keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(window, res);
|
||||
keyboardHeight = ((RegularKeyboardSize) computedSize).getHeight();
|
||||
padding = ((RegularKeyboardSize) computedSize).getPadding();
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.futo.inputmethod.latin.uix
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.KeyguardManager
|
||||
import android.content.ClipDescription
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
@ -62,11 +61,15 @@ import androidx.compose.ui.unit.LayoutDirection
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.LifecycleCoroutineScope
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.window.layout.FoldingFeature
|
||||
import androidx.window.layout.WindowInfoTracker
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.futo.inputmethod.accessibility.AccessibilityUtils
|
||||
import org.futo.inputmethod.latin.AudioAndHapticFeedbackManager
|
||||
import org.futo.inputmethod.latin.BuildConfig
|
||||
import org.futo.inputmethod.latin.FoldingOptions
|
||||
import org.futo.inputmethod.latin.LanguageSwitcherDialog
|
||||
import org.futo.inputmethod.latin.LatinIME
|
||||
import org.futo.inputmethod.latin.R
|
||||
@ -103,6 +106,12 @@ val LocalThemeProvider = compositionLocalOf<DynamicThemeProvider> {
|
||||
error("No LocalThemeProvider provided")
|
||||
}
|
||||
|
||||
val LocalFoldingState = compositionLocalOf<FoldingOptions> {
|
||||
FoldingOptions(null)
|
||||
}
|
||||
|
||||
|
||||
|
||||
private class LatinIMEActionInputTransaction(
|
||||
private val inputLogic: InputLogic,
|
||||
shouldApplySpace: Boolean,
|
||||
@ -323,6 +332,8 @@ class UixManager(private val latinIME: LatinIME) {
|
||||
isShowingActionEditor.value = true
|
||||
}
|
||||
|
||||
val foldingOptions = mutableStateOf(FoldingOptions(null))
|
||||
|
||||
var isInputOverridden = mutableStateOf(false)
|
||||
|
||||
var currWindowActionWindow: ActionWindow? = null
|
||||
@ -622,6 +633,7 @@ class UixManager(private val latinIME: LatinIME) {
|
||||
CompositionLocalProvider(LocalManager provides keyboardManagerForAction) {
|
||||
CompositionLocalProvider(LocalThemeProvider provides latinIME.getDrawableProvider()) {
|
||||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
|
||||
CompositionLocalProvider(LocalFoldingState provides foldingOptions.value) {
|
||||
InputDarkener(isInputOverridden.value || isShowingActionEditor.value) {
|
||||
closeActionWindow()
|
||||
isShowingActionEditor.value = false
|
||||
@ -647,7 +659,9 @@ class UixManager(private val latinIME: LatinIME) {
|
||||
|
||||
ForgetWordDialog()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ActionEditorHost()
|
||||
@ -658,6 +672,7 @@ class UixManager(private val latinIME: LatinIME) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun showUpdateNoticeIfNeeded() {
|
||||
if(!BuildConfig.UPDATE_CHECKING) return
|
||||
@ -852,6 +867,13 @@ class UixManager(private val latinIME: LatinIME) {
|
||||
}
|
||||
|
||||
isActionsExpanded.value = latinIME.getSettingBlocking(ActionBarExpanded)
|
||||
|
||||
latinIME.lifecycleScope.launch(Dispatchers.Main) {
|
||||
WindowInfoTracker.getOrCreate(latinIME).windowLayoutInfo(latinIME).collect {
|
||||
foldingOptions.value = FoldingOptions(it.displayFeatures.filterIsInstance<FoldingFeature>().firstOrNull())
|
||||
latinIME.invalidateKeyboard(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onPersistentStatesUnlocked() {
|
||||
|
@ -18,11 +18,15 @@ package org.futo.inputmethod.latin.utils;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Insets;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Window;
|
||||
import android.view.WindowInsets;
|
||||
import android.view.WindowMetrics;
|
||||
|
||||
import org.futo.inputmethod.annotations.UsedForTesting;
|
||||
import org.futo.inputmethod.latin.R;
|
||||
@ -182,9 +186,14 @@ public final class ResourceUtils {
|
||||
return matchedAll;
|
||||
}
|
||||
|
||||
public static int getDefaultKeyboardWidth(final Resources res) {
|
||||
final DisplayMetrics dm = res.getDisplayMetrics();
|
||||
return dm.widthPixels;
|
||||
public static int getDefaultKeyboardWidth(final Window window, final Resources res) {
|
||||
if(window != null && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)) {
|
||||
WindowMetrics metrics = window.getWindowManager().getCurrentWindowMetrics();
|
||||
Insets insets = metrics.getWindowInsets().getInsetsIgnoringVisibility(WindowInsets.Type.navigationBars() | WindowInsets.Type.displayCutout());
|
||||
|
||||
return metrics.getBounds().width() - (insets.left + insets.right);
|
||||
}
|
||||
return (int)(res.getConfiguration().screenWidthDp * res.getDisplayMetrics().density);
|
||||
}
|
||||
|
||||
public static int getKeyboardHeight(final Resources res, final SettingsValues settingsValues) {
|
||||
|
@ -143,7 +143,7 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
||||
final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) {
|
||||
final Context context = getContext();
|
||||
final Resources res = context.getResources();
|
||||
final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
|
||||
final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(null, res);
|
||||
final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
|
||||
|
||||
final RichInputMethodSubtype richInputMethodSubtype = RichInputMethodSubtype.getRichInputMethodSubtype(subtype);
|
||||
|
Loading…
Reference in New Issue
Block a user