Use Compose padding for vertical offset

This commit is contained in:
Aleksandras Kostarevas 2024-05-07 12:11:07 -05:00
parent 233e850422
commit 173cf38710
4 changed files with 10 additions and 13 deletions

View File

@ -256,8 +256,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
try {
final KeyboardParams params = mParams;
final int offset = (int)mProvider.getKeyboardBottomOffset();
final int height = (int) (params.mId.mHeight * mProvider.getKeyboardHeightMultiplier() + offset);
final int height = (int) (params.mId.mHeight * mProvider.getKeyboardHeightMultiplier());
final int width = params.mId.mWidth;
params.mOccupiedHeight = height;
params.mOccupiedWidth = width;
@ -265,7 +264,6 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
R.styleable.Keyboard_keyboardTopPadding, height, height, 0);
params.mBottomPadding = (int)(keyboardAttr.getFraction(
R.styleable.Keyboard_keyboardBottomPadding, height, height, 0)
+ mProvider.getKeyboardBottomOffset()
);
params.mLeftPadding = (int)keyboardAttr.getFraction(
R.styleable.Keyboard_keyboardLeftPadding, width, width, 0);
@ -283,7 +281,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
// rows are determined based on the entire keyboard height including top and bottom
// paddings.
params.mVerticalGap = (int)keyboardAttr.getFraction(
R.styleable.Keyboard_verticalGap, height - offset, height - offset, 0);
R.styleable.Keyboard_verticalGap, height, height, 0);
final int baseHeight = params.mOccupiedHeight - params.mTopPadding
- params.mBottomPadding + params.mVerticalGap;
params.mBaseHeight = baseHeight;

View File

@ -14,10 +14,12 @@ import android.view.inputmethod.InlineSuggestionsRequest
import android.view.inputmethod.InlineSuggestionsResponse
import android.view.inputmethod.InputMethodSubtype
import androidx.annotation.RequiresApi
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.ColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.key
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clipToBounds
@ -54,6 +56,7 @@ import org.futo.inputmethod.latin.uix.EmojiTracker.useEmoji
import org.futo.inputmethod.latin.uix.HiddenKeysSetting
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.SUGGESTION_BLACKLIST
import org.futo.inputmethod.latin.uix.THEME_KEY
import org.futo.inputmethod.latin.uix.UixManager
@ -63,6 +66,7 @@ import org.futo.inputmethod.latin.uix.deferGetSetting
import org.futo.inputmethod.latin.uix.deferSetSetting
import org.futo.inputmethod.latin.uix.differsFrom
import org.futo.inputmethod.latin.uix.getSetting
import org.futo.inputmethod.latin.uix.getSettingFlow
import org.futo.inputmethod.latin.uix.setSetting
import org.futo.inputmethod.latin.uix.theme.DarkColorScheme
import org.futo.inputmethod.latin.uix.theme.ThemeOption
@ -336,10 +340,13 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
inputViewHeight = it.height
}
}
val padding = getSettingFlow(KeyboardBottomOffsetSetting).collectAsState(initial = 0.0f)
key(legacyInputView) {
AndroidView(factory = {
legacyInputView!!
}, modifier = modifier, onRelease = {
}, modifier = modifier.padding(0.dp, 0.dp, 0.dp, padding.value.dp), onRelease = {
val view = it as InputView
view.deallocateMemory()
view.removeAllViews()

View File

@ -85,10 +85,6 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
return keyboardHeight
}
override fun getKeyboardBottomOffset(): Float {
return dp(keyboardBottomOffsetValue.dp)
}
private fun dp(dp: Dp): Float {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
@ -136,7 +132,6 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
val showKeyHints: Boolean
val keyboardHeight: Float
val keyboardBottomOffsetValue: Float
fun hasUpdated(newPreferences: Preferences): Boolean {
return when {
@ -145,7 +140,6 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
newPreferences[KeyHintsSetting.key] != showKeyHints -> true
newPreferences[KeyboardHeightMultiplierSetting.key] != keyboardHeight -> true
newPreferences[KeyboardBottomOffsetSetting.key] != keyboardBottomOffsetValue -> true
else -> false
}
@ -167,7 +161,6 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch
showKeyHints = context.getSettingBlocking(KeyHintsSetting)
keyboardHeight = context.getSettingBlocking(KeyboardHeightMultiplierSetting.key, KeyboardHeightMultiplierSetting.default)
keyboardBottomOffsetValue = context.getSettingBlocking(KeyboardBottomOffsetSetting.key, KeyboardBottomOffsetSetting.default)
val primary = colorScheme.primary.toArgb()
val secondary = colorScheme.secondary.toArgb()

View File

@ -23,7 +23,6 @@ interface DynamicThemeProvider {
fun getDrawable(i: Int): Drawable?
fun getKeyboardHeightMultiplier(): Float
fun getKeyboardBottomOffset(): Float
companion object {
@ColorInt