Skip to content

Commit

Permalink
use the normal way for parsing new keyboards
Browse files Browse the repository at this point in the history
  • Loading branch information
Helium314 committed Sep 1, 2024
1 parent 93bd2e7 commit 03ac9a5
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 26 deletions.
7 changes: 7 additions & 0 deletions app/src/main/assets/layouts/clip_bottom_row.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
[
{ "label": "alpha", "width": 0.15 },
{ "label": "space", "width": -1 },
{ "label": "delete", "width": 0.15 }
]
]
7 changes: 7 additions & 0 deletions app/src/main/assets/layouts/emoji_bottom_row.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
[
{ "label": "alpha", "width": 0.15 },
{ "label": "space", "width": -1 },
{ "label": "delete", "width": 0.15 }
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public final class KeyboardId {
public static final int ELEMENT_EMOJI_CATEGORY16 = 26;
public static final int ELEMENT_CLIPBOARD = 27;
public static final int ELEMENT_NUMPAD = 28;
public static final int ELEMENT_CLIP_EMOJI_BOTTOM_ROW = 29; // todo: maybe separate for customization
public static final int ELEMENT_EMOJI_BOTTOM_ROW = 29;
public static final int ELEMENT_CLIPBOARD_BOTTOM_ROW = 30;

public final RichInputMethodSubtype mSubtype;
public final int mWidth;
Expand Down Expand Up @@ -192,6 +193,10 @@ public boolean isEmojiKeyboard() {
return mElementId >= ELEMENT_EMOJI_RECENTS && mElementId <= ELEMENT_EMOJI_CATEGORY16;
}

public boolean isEmojiClipBottomRow() {
return mElementId == ELEMENT_CLIPBOARD_BOTTOM_ROW || mElementId == ELEMENT_EMOJI_BOTTOM_ROW;
}

public int imeAction() {
return InputTypeUtils.getImeOptionsActionIdFromEditorInfo(mEditorInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
PointerTracker.switchTo(keyboardView)
keyboardView.visibility = View.VISIBLE
val kls = KeyboardLayoutSet.Builder.buildEmojiClipBottomRow(context, editorInfo)
val keyboard = kls.getKeyboard(KeyboardId.ELEMENT_CLIP_EMOJI_BOTTOM_ROW)
val keyboard = kls.getKeyboard(KeyboardId.ELEMENT_CLIPBOARD_BOTTOM_ROW)
keyboardView.setKeyboard(keyboard)
clipboardLayoutParams.setActionBarProperties(keyboardView) // todo: rename to bottomRowKeyboard
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private void setupBottomRowKeyboard(final EditorInfo editorInfo) {
PointerTracker.switchTo(keyboardView);
keyboardView.setVisibility(View.VISIBLE);
final KeyboardLayoutSet kls = KeyboardLayoutSet.Builder.buildEmojiClipBottomRow(getContext(), editorInfo);
final Keyboard keyboard = kls.getKeyboard(KeyboardId.ELEMENT_CLIP_EMOJI_BOTTOM_ROW);
final Keyboard keyboard = kls.getKeyboard(KeyboardId.ELEMENT_EMOJI_BOTTOM_ROW);
keyboardView.setKeyboard(keyboard);
mEmojiLayoutParams.setActionBarProperties(keyboardView); // todo: rename to bottomRowKeyboard
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,6 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
mParams.mAllowRedundantPopupKeys = true
readAttributes(R.xml.kbd_emoji)
keysInRows = EmojiParser(mParams, mContext).parse()
} else if (id.mElementId == KeyboardId.ELEMENT_CLIP_EMOJI_BOTTOM_ROW) {
// try catch, single row check, customizable layout, maybe set up other stuff, ...
// possibly some things could be determined automatically and the parser used normally?
addLocaleKeyTextsToParams(mContext, mParams, Settings.getInstance().current.mShowMorePopupKeys)
mParams.readAttributes(mContext, null)
mParams.mTopPadding /= 4 // not perfect, may cause 1 pixel offsets because it's already been converted to int once
val baseKeys = RawKeyboardParser.parseJsonString("""
[
[
{ "label": "alpha", "width": 0.15 },
{ "label": "space", "width": -1 },
{ "label": "delete", "width": 0.15 }
]
]
""".trimIndent())
keysInRows = KeyboardParser(mParams, mContext).createRows(baseKeys.map { it.mapNotNull { it.compute(mParams) }.toMutableList() }
.take(1).toMutableList()) // we set the height for a single row only (in emoji and clipboard params), so we only use one!
if (Settings.getInstance().current.mShowsNumberRow)
keysInRows.first().forEach { it.mHeight *= 0.8f }
determineAbsoluteValues()
} else {
try {
setupParams()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co

val baseKeys = RawKeyboardParser.parseLayout(params, context)
val keysInRows = createRows(baseKeys)
// rescale height if we have anything but the usual 4 rows
val heightRescale = if (keysInRows.size != 4) 4f / keysInRows.size else 1f
val heightRescale: Float
if (params.mId.isEmojiClipBottomRow) {
// rescale height if number row is enabled
heightRescale = if (Settings.getInstance().current.mShowsNumberRow) 0.8f else 1f
params.mTopPadding /= 4 // not perfect, may cause 1 pixel offsets because it's already been converted to int once
} else {
// rescale height if we have anything but the usual 4 rows
heightRescale = if (keysInRows.size != 4) 4f / keysInRows.size else 1f
}
if (heightRescale != 1f) {
keysInRows.forEach { row -> row.forEach { it.mHeight *= heightRescale } }
}
Expand Down Expand Up @@ -314,3 +321,5 @@ const val LAYOUT_NUMBER = "number"
const val LAYOUT_PHONE = "phone"
const val LAYOUT_PHONE_SYMBOLS = "phone_symbols"
const val LAYOUT_NUMBER_ROW = "number_row"
const val LAYOUT_EMOJI_BOTTOM_ROW = "emoji_bottom_row"
const val LAYOUT_CLIPBOARD_BOTTOM_ROW = "clip_bottom_row"
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ object RawKeyboardParser {
KeyboardId.ELEMENT_NUMBER -> LAYOUT_NUMBER
KeyboardId.ELEMENT_PHONE -> LAYOUT_PHONE
KeyboardId.ELEMENT_PHONE_SYMBOLS -> LAYOUT_PHONE_SYMBOLS
KeyboardId.ELEMENT_EMOJI_BOTTOM_ROW -> LAYOUT_EMOJI_BOTTOM_ROW
KeyboardId.ELEMENT_CLIPBOARD_BOTTOM_ROW -> LAYOUT_CLIPBOARD_BOTTOM_ROW
else -> params.mId.mSubtype.keyboardLayoutSetName.substringBeforeLast("+")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ sealed interface KeyData : AbstractKeyData {
}

private fun getSpaceLabel(params: KeyboardParams): String =
if (params.mId.isAlphaOrSymbolKeyboard || params.mId.mElementId == KeyboardId.ELEMENT_CLIP_EMOJI_BOTTOM_ROW)
if (params.mId.isAlphaOrSymbolKeyboard || params.mId.isEmojiClipBottomRow)
"!icon/space_key|!code/key_space"
else "!icon/space_key_for_number_layout|!code/key_space"

Expand Down

0 comments on commit 03ac9a5

Please sign in to comment.