Skip to content

Commit

Permalink
call readAttributes in the right builders directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Helium314 committed Dec 10, 2023
1 parent 0d83ea4 commit 89f8c44
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ public Builder(final Context context, final Key key, final Keyboard keyboard,
final boolean isSingleMoreKeyWithPreview, final int keyPreviewVisibleWidth,
final int keyPreviewVisibleHeight, final Paint paintToMeasure) {
super(context, new MoreKeysKeyboardParams());
loadFromXml(keyboard.mMoreKeysTemplate, keyboard.mId);
mParams.mId = keyboard.mId;
readAttributes(keyboard.mMoreKeysTemplate);

// TODO: More keys keyboard's vertical gap is currently calculated heuristically.
// Should revise the algorithm.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,19 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
return this

// todo: further plan
// some keyboard_layout_set have supportedScript that is enum synced with script id in ScriptUtils
// that's one more reason for using language tags...
// currently it's still read from xml outside the keyboard parser, but should still go to some other place
// maybe use scriptUtils to determine, just make sure it's correct (also for hindi and serbian!)
// next release, and possibly don't continue working here for a while (should allow finding more regressions)
// remove the old parser
// then finally the spanish/german/swiss/nordic layouts can be removed and replaced by some hasExtraKeys parameter
// also the eo check could then be removed
// and maybe the language -> layout thing could be moved to assets? and maybe even here the extra keys could be defined...
// should be either both in method.xml, or both in assets (actually method might be more suitable)
// go through a lot of todos in parsers, key, keyboardlayoutset, ... as a lot of things should only change after old parser is removed
// also remove the keybpard_layout_set files?
// they are still in use e.g. for enableProximityCharsCorrection and supportedScript
// but ideally this should be replaced
// enableProximityCharsCorrection should be in LayoutInfos
// supportedScript could be determined using ScriptUtils, but first make sure that there is less latin fallback happening
// or use locale to store script, but that's only possible starting at api 21
// allow users to define their own layouts (maybe do everything else first?)
// need to solve the scaling issue with number row and 5 row keyboards
// write up how things work for users, also regarding language more keys
Expand Down Expand Up @@ -137,13 +140,6 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,

fun loadFromXml(xmlId: Int, id: KeyboardId): KeyboardBuilder<KP> {
if (Settings.getInstance().current.mUseNewKeyboardParsing) {
if (this::class != KeyboardBuilder::class) {
// for MoreSuggestions and MoreKeys we only need to read the attributes
// but not the default ones, do it like the old parser (for now)
mParams.mId = id
readAttributes(xmlId)
return this
}
if (id.mElementId >= KeyboardId.ELEMENT_EMOJI_RECENTS && id.mElementId <= KeyboardId.ELEMENT_EMOJI_CATEGORY16) {
mParams.mId = id
readAttributes(R.xml.kbd_emoji_category1) // all the same anyway, gridRows are ignored
Expand Down Expand Up @@ -176,8 +172,8 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
return this
}

// todo: remnant of old parser, replace it
private fun readAttributes(@XmlRes xmlId: Int) {
// todo: remnant of old parser, replace it if reasonably simple
protected fun readAttributes(@XmlRes xmlId: Int) {
val parser = mResources.getXml(xmlId)
while (parser.eventType != XmlPullParser.END_DOCUMENT) {
val event = parser.next()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ public Builder layout(final SuggestedWords suggestedWords, final int fromIndex,
final int maxWidth, final int minWidth, final int maxRow,
final Keyboard parentKeyboard) {
final int xmlId = R.xml.kbd_suggestions_pane_template;
loadFromXml(xmlId, parentKeyboard.mId);
mParams.mId = parentKeyboard.mId;
readAttributes(xmlId);
mParams.mVerticalGap = mParams.mTopPadding = parentKeyboard.mVerticalGap / 2;
mPaneView.updateKeyboardGeometry(mParams.mDefaultRowHeight);
final int count = mParams.layout(suggestedWords, fromIndex, maxWidth, minWidth, maxRow,
Expand Down

0 comments on commit 89f8c44

Please sign in to comment.