fix small almost-edge keys (#478)

This commit is contained in:
Helium314 2024-02-11 19:40:54 +01:00 committed by GitHub
parent f657ebad3d
commit 5ec55f3e0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 39 deletions

View file

@ -960,8 +960,6 @@ public class Key implements Comparable<Key> {
private final KeyboardParams mKeyboardParams; // for reading gaps and keyboard width / height
public float mRelativeWidth;
public float mRelativeHeight; // also should allow negative values, indicating absolute height is defined
public float mRelativeVisualInsetLeft;
public float mRelativeVisualInsetRight;
// params that may change
public float mFullWidth;
@ -980,7 +978,7 @@ public class Key implements Comparable<Key> {
public int mBackgroundType;
public final int mActionFlags;
@Nullable public final KeyVisualAttributes mKeyVisualAttributes;
@Nullable public OptionalAttributes mOptionalAttributes;
@Nullable public final OptionalAttributes mOptionalAttributes;
public final boolean mEnabled;
public static KeyParams newSpacer(final KeyboardParams params, final float relativeWidth) {
@ -1007,18 +1005,6 @@ public class Key implements Comparable<Key> {
yPos = newY;
mFullWidth = mRelativeWidth * mKeyboardParams.mBaseWidth;
mFullHeight = mRelativeHeight * mKeyboardParams.mBaseHeight;
// set visual insets if any
if (mRelativeVisualInsetRight != 0f || mRelativeVisualInsetLeft != 0f) {
final int insetLeft = (int) (mRelativeVisualInsetLeft * mKeyboardParams.mBaseWidth);
final int insetRight = (int) (mRelativeVisualInsetRight * mKeyboardParams.mBaseWidth);
if (mOptionalAttributes == null) {
mOptionalAttributes = OptionalAttributes.newInstance(null, CODE_UNSPECIFIED, ICON_UNDEFINED, insetLeft, insetRight);
} else {
mOptionalAttributes = OptionalAttributes
.newInstance(mOptionalAttributes.mOutputText, mOptionalAttributes.mAltCode, mOptionalAttributes.mDisabledIconId, insetLeft, insetRight);
}
}
}
private static int getPopupKeysColumnAndFlagsAndSetNullInArray(final KeyboardParams params, final String[] popupKeys) {
@ -1269,8 +1255,6 @@ public class Key implements Comparable<Key> {
mActionFlags = keyParams.mActionFlags;
mKeyVisualAttributes = keyParams.mKeyVisualAttributes;
mOptionalAttributes = keyParams.mOptionalAttributes;
mRelativeVisualInsetLeft = keyParams.mRelativeVisualInsetLeft;
mRelativeVisualInsetRight = keyParams.mRelativeVisualInsetRight;
}
}
}

View file

@ -248,14 +248,16 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
private fun endKey(key: Key) {
mParams.onAddKey(key)
if (mLeftEdge) {
if (mLeftEdge && !key.isSpacer) {
key.markAsLeftEdge(mParams)
mLeftEdge = false
}
if (mTopEdge) {
key.markAsTopEdge(mParams)
}
mRightEdgeKey = key
if (!key.isSpacer) {
mRightEdgeKey = key
}
}
private fun endKeyboard() {

View file

@ -122,8 +122,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
spacerWidth = 0f
keyWidth = availableWidth / row.size
}
if (spacerWidth != 0f && functionalKeysLeft.isNotEmpty()) {
// add a spacer between left functional key and keyboard key
if (spacerWidth != 0f) {
paramsRow.add(KeyParams.newSpacer(params, spacerWidth))
}
if (keyWidth < params.mDefaultRelativeKeyWidth * 0.82 && spacerWidth == 0f) {
@ -146,24 +145,7 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co
paramsRow.add(keyParams)
}
if (spacerWidth != 0f) {
if (functionalKeysLeft.isEmpty()) {
// we did not add a spacer above, but extend the key to the edge and set visual insets
paramsRow.first().mRelativeWidth += spacerWidth
paramsRow.first().mRelativeVisualInsetLeft = spacerWidth
}
if (functionalKeysRight.isEmpty()) {
// extend right key to the edge and set visual insets
paramsRow.last().mRelativeWidth += spacerWidth
paramsRow.last().mRelativeVisualInsetRight = spacerWidth
} else {
// add a spacer between keyboard key and right functional key (like for the left side)
// unless it's the enter key, in that case increase the key's width (to match original layout in tablet mode)
if (functionalKeysRight.singleOrNull()?.mBackgroundType == Key.BACKGROUND_TYPE_ACTION) {
functionalKeysRight.single().mRelativeWidth += spacerWidth
} else {
paramsRow.add(KeyParams.newSpacer(params, spacerWidth))
}
}
paramsRow.add(KeyParams.newSpacer(params, spacerWidth))
}
functionalKeysRight.forEach { paramsRow.add(it) }
keysInRows.add(paramsRow)