From 79e36db67009f5ba67122a116d70ffd7fbac3939 Mon Sep 17 00:00:00 2001 From: wittmane Date: Sun, 24 Jan 2021 03:46:30 -0600 Subject: [PATCH] Resize keyboard dimensions (#238) * support a switch tag around the root keyboard tag * make the number row the same height as the other rows (still need to add numbers to support large devices) * add numbers to support large devices * add extra characters to the number row * reduced some duplicate code and removed more keys on the number row * removed special characters on the number row --- .../inputmethod/keyboard/KeyboardId.java | 11 ++- .../keyboard/KeyboardLayoutSet.java | 6 ++ .../keyboard/KeyboardSwitcher.java | 1 + .../keyboard/internal/KeyboardBuilder.java | 81 +++++++++++++------ .../keyboard/internal/KeyboardParams.java | 1 - .../latin/utils/ResourceUtils.java | 2 - .../latin/utils/XmlParseUtils.java | 3 + app/src/main/res/values-land/config.xml | 10 +++ .../main/res/values-sw600dp-land/config.xml | 6 ++ app/src/main/res/values-sw600dp/config.xml | 5 ++ .../main/res/values-sw768dp-land/config.xml | 6 ++ app/src/main/res/values-sw768dp/config.xml | 5 ++ .../values-v28/themes-lxx-system-border.xml | 2 - .../main/res/values-v28/themes-lxx-system.xml | 2 - app/src/main/res/values/attrs.xml | 12 +-- app/src/main/res/values/config.xml | 13 ++- .../res/values/themes-lxx-dark-border.xml | 2 - app/src/main/res/values/themes-lxx-dark.xml | 2 - .../res/values/themes-lxx-light-border.xml | 2 - app/src/main/res/values/themes-lxx-light.xml | 2 - .../{rowkeys_qwerty0.xml => row_qwerty0.xml} | 22 +---- app/src/main/res/xml/kbd_abc.xml | 32 ++++---- app/src/main/res/xml/kbd_arabic.xml | 33 ++++---- app/src/main/res/xml/kbd_azerty.xml | 33 ++++---- app/src/main/res/xml/kbd_bulgarian.xml | 33 ++++---- app/src/main/res/xml/kbd_bulgarian_bds.xml | 33 ++++---- app/src/main/res/xml/kbd_colemak.xml | 33 ++++---- app/src/main/res/xml/kbd_dvorak.xml | 29 ++++--- app/src/main/res/xml/kbd_east_slavic.xml | 33 ++++---- app/src/main/res/xml/kbd_georgian.xml | 33 ++++---- app/src/main/res/xml/kbd_greek.xml | 33 ++++---- app/src/main/res/xml/kbd_hebrew.xml | 33 ++++---- app/src/main/res/xml/kbd_hindi.xml | 33 ++++---- app/src/main/res/xml/kbd_hindi_compact.xml | 33 ++++---- app/src/main/res/xml/kbd_kannada.xml | 33 ++++---- app/src/main/res/xml/kbd_malayalam.xml | 33 ++++---- app/src/main/res/xml/kbd_marathi.xml | 33 ++++---- app/src/main/res/xml/kbd_mongolian.xml | 33 ++++---- app/src/main/res/xml/kbd_nepali_romanized.xml | 33 ++++---- .../main/res/xml/kbd_nepali_traditional.xml | 33 ++++---- app/src/main/res/xml/kbd_nordic.xml | 32 ++++---- app/src/main/res/xml/kbd_qwerty.xml | 32 ++++---- app/src/main/res/xml/kbd_qwertz.xml | 34 ++++---- app/src/main/res/xml/kbd_serbian_qwertz.xml | 32 ++++---- app/src/main/res/xml/kbd_south_slavic.xml | 33 ++++---- app/src/main/res/xml/kbd_spanish.xml | 32 ++++---- app/src/main/res/xml/kbd_swiss.xml | 34 ++++---- app/src/main/res/xml/kbd_tamil.xml | 33 ++++---- app/src/main/res/xml/kbd_telugu.xml | 33 ++++---- app/src/main/res/xml/kbd_uzbek.xml | 32 ++++---- app/src/main/res/xml/row_qwerty0.xml | 25 ++++++ app/src/main/res/xml/rowkeys_qwerty0.xml | 49 +++++------ 52 files changed, 629 insertions(+), 590 deletions(-) rename app/src/main/res/xml-sw600dp/{rowkeys_qwerty0.xml => row_qwerty0.xml} (61%) create mode 100644 app/src/main/res/xml/row_qwerty0.xml diff --git a/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/KeyboardId.java b/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/KeyboardId.java index a65e0c558..170eadbfe 100644 --- a/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/KeyboardId.java +++ b/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/KeyboardId.java @@ -54,6 +54,7 @@ public final class KeyboardId { public static final int ELEMENT_NUMBER = 9; public final RichInputMethodSubtype mSubtype; + public final int mThemeId; public final int mWidth; public final int mHeight; public final int mMode; @@ -68,6 +69,7 @@ public final class KeyboardId { public KeyboardId(final int elementId, final KeyboardLayoutSet.Params params) { mSubtype = params.mSubtype; + mThemeId = params.mKeyboardThemeId; mWidth = params.mKeyboardWidth; mHeight = params.mKeyboardHeight; mMode = params.mMode; @@ -96,6 +98,7 @@ private static int computeHashCode(final KeyboardId id) { id.navigateNext(), id.navigatePrevious(), id.mSubtype, + id.mThemeId }); } @@ -113,7 +116,8 @@ private boolean equals(final KeyboardId other) { && TextUtils.equals(other.mCustomActionLabel, mCustomActionLabel) && other.navigateNext() == navigateNext() && other.navigatePrevious() == navigatePrevious() - && other.mSubtype.equals(mSubtype); + && other.mSubtype.equals(mSubtype) + && other.mThemeId == mThemeId; } private static boolean isAlphabetKeyboard(final int elementId) { @@ -164,7 +168,7 @@ public int hashCode() { @Override public String toString() { - return String.format(Locale.ROOT, "[%s %s:%s %dx%d %s %s%s%s%s%s%s%s%s%s]", + return String.format(Locale.ROOT, "[%s %s:%s %dx%d %s %s%s%s%s%s%s %s]", elementIdToName(mElementId), mSubtype.getLocale(), mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET), @@ -175,7 +179,8 @@ public String toString() { (navigatePrevious() ? " navigatePrevious" : ""), (passwordInput() ? " passwordInput" : ""), (mLanguageSwitchKeyEnabled ? " languageSwitchKeyEnabled" : ""), - (isMultiLine() ? " isMultiLine" : "") + (isMultiLine() ? " isMultiLine" : ""), + KeyboardTheme.getKeyboardThemeName(mThemeId) ); } diff --git a/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/KeyboardLayoutSet.java b/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/KeyboardLayoutSet.java index 5498f38f1..901723f3a 100644 --- a/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/KeyboardLayoutSet.java +++ b/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/KeyboardLayoutSet.java @@ -95,6 +95,7 @@ public static final class Params { EditorInfo mEditorInfo; boolean mLanguageSwitchKeyEnabled; RichInputMethodSubtype mSubtype; + int mKeyboardThemeId; int mKeyboardWidth; int mKeyboardHeight; boolean mShowMoreKeys; @@ -213,6 +214,11 @@ public Builder(final Context context, final EditorInfo ei) { params.mEditorInfo = editorInfo; } + public Builder setKeyboardTheme(final int themeId) { + mParams.mKeyboardThemeId = themeId; + return this; + } + public Builder setKeyboardGeometry(final int keyboardWidth, final int keyboardHeight) { mParams.mKeyboardWidth = keyboardWidth; mParams.mKeyboardHeight = keyboardHeight; diff --git a/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/KeyboardSwitcher.java b/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/KeyboardSwitcher.java index 0c1c32de2..01847b342 100644 --- a/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/KeyboardSwitcher.java +++ b/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/KeyboardSwitcher.java @@ -105,6 +105,7 @@ public void loadKeyboard(final EditorInfo editorInfo, final SettingsValues setti final Resources res = mThemeContext.getResources(); final int keyboardWidth = mLatinIME.getMaxWidth(); final int keyboardHeight = ResourceUtils.getKeyboardHeight(res, settingsValues); + builder.setKeyboardTheme(mKeyboardTheme.mThemeId); builder.setKeyboardGeometry(keyboardWidth, keyboardHeight); builder.setSubtype(mRichImm.getCurrentSubtype()); builder.setLanguageSwitchKeyEnabled(mLatinIME.shouldShowLanguageSwitchKey()); diff --git a/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/internal/KeyboardBuilder.java b/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/internal/KeyboardBuilder.java index e8816b2e5..6f59a24ab 100644 --- a/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/internal/KeyboardBuilder.java +++ b/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/internal/KeyboardBuilder.java @@ -140,6 +140,7 @@ public class KeyboardBuilder { private float mCurrentY = 0; private KeyboardRow mCurrentRow = null; private Key mPreviousKeyInRow = null; + private boolean mKeyboardDefined = false; public KeyboardBuilder(final Context context, final KP params) { mContext = context; @@ -160,7 +161,10 @@ public KeyboardBuilder load(final int xmlId, final KeyboardId id) { mParams.mId = id; final XmlResourceParser parser = mResources.getXml(xmlId); try { - parseKeyboard(parser); + parseKeyboard(parser, false); + if (!mKeyboardDefined) { + throw new XmlParseUtils.ParseException("No " + TAG_KEYBOARD + " tag was found"); + } } catch (XmlPullParserException e) { Log.w(BUILDER_TAG, "keyboard XML parse error", e); throw new IllegalArgumentException(e.getMessage(), e); @@ -197,20 +201,37 @@ private void startEndTag(final String format, final Object ... args) { mIndent--; } - private void parseKeyboard(final XmlPullParser parser) + private void parseKeyboard(final XmlPullParser parser, final boolean skip) throws XmlPullParserException, IOException { - if (DEBUG) startTag("<%s> %s", TAG_KEYBOARD, mParams.mId); while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { final int event = parser.next(); if (event == XmlPullParser.START_TAG) { final String tag = parser.getName(); if (TAG_KEYBOARD.equals(tag)) { - parseKeyboardAttributes(parser); - startKeyboard(); - parseKeyboardContent(parser, false); + if (DEBUG) startTag("<%s> %s%s", TAG_KEYBOARD, mParams.mId, + skip ? " skipped" : ""); + if (!skip) { + if (mKeyboardDefined) { + throw new XmlParseUtils.ParseException("Only one " + TAG_KEYBOARD + + " tag can be defined", parser); + } + mKeyboardDefined = true; + parseKeyboardAttributes(parser); + startKeyboard(); + } + parseKeyboardContent(parser, skip); + } else if (TAG_SWITCH.equals(tag)) { + parseSwitchKeyboard(parser, skip); + } else { + throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD); + } + } else if (event == XmlPullParser.END_TAG) { + final String tag = parser.getName(); + if (DEBUG) endTag("", tag); + if (TAG_CASE.equals(tag) || TAG_DEFAULT.equals(tag)) { return; } - throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD); + throw new XmlParseUtils.IllegalEndTag(parser, tag, TAG_ROW); } } } @@ -224,7 +245,11 @@ private void parseKeyboardAttributes(final XmlPullParser parser) { final KeyboardParams params = mParams; final int height = params.mId.mHeight; final int width = params.mId.mWidth; - params.mOccupiedHeight = height; + // The bonus height isn't used to determine the other dimensions (gap/padding) to allow + // those to stay consistent between layouts with and without the bonus height added. + final int bonusHeight = mParams.mId.mShowNumberRow ? Math.round(mResources.getFraction( + R.fraction.config_key_bonus_height_5row, height, height)) : 0; + params.mOccupiedHeight = height + bonusHeight; params.mOccupiedWidth = width; params.mTopPadding = ResourceUtils.getDimensionOrFraction(keyboardAttr, R.styleable.Keyboard_keyboardTopPadding, height, 0); @@ -261,7 +286,6 @@ private void parseKeyboardAttributes(final XmlPullParser parser) { params.mMaxMoreKeysKeyboardColumn = keyAttr.getInt( R.styleable.Keyboard_Key_maxMoreKeysColumn, 5); - params.mThemeId = keyboardAttr.getInt(R.styleable.Keyboard_themeId, 0); params.mIconsSet.loadIcons(keyboardAttr); params.mTextsSet.setLocale(params.mId.getLocale(), mContext); } finally { @@ -484,18 +508,23 @@ private void parseMerge(final XmlPullParser parser, final KeyboardRow row, final } } + private void parseSwitchKeyboard(final XmlPullParser parser, final boolean skip) + throws XmlPullParserException, IOException { + parseSwitchInternal(parser, true, null, skip); + } + private void parseSwitchKeyboardContent(final XmlPullParser parser, final boolean skip) throws XmlPullParserException, IOException { - parseSwitchInternal(parser, null, skip); + parseSwitchInternal(parser, false, null, skip); } private void parseSwitchRowContent(final XmlPullParser parser, final KeyboardRow row, final boolean skip) throws XmlPullParserException, IOException { - parseSwitchInternal(parser, row, skip); + parseSwitchInternal(parser, false, row, skip); } - private void parseSwitchInternal(final XmlPullParser parser, final KeyboardRow row, - final boolean skip) throws XmlPullParserException, IOException { + private void parseSwitchInternal(final XmlPullParser parser, final boolean parseKeyboard, + final KeyboardRow row, final boolean skip) throws XmlPullParserException, IOException { if (DEBUG) startTag("<%s> %s", TAG_SWITCH, mParams.mId); boolean selected = false; while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { @@ -503,9 +532,9 @@ private void parseSwitchInternal(final XmlPullParser parser, final KeyboardRow r if (event == XmlPullParser.START_TAG) { final String tag = parser.getName(); if (TAG_CASE.equals(tag)) { - selected |= parseCase(parser, row, selected || skip); + selected |= parseCase(parser, parseKeyboard, row, selected || skip); } else if (TAG_DEFAULT.equals(tag)) { - selected |= parseDefault(parser, row, selected || skip); + selected |= parseDefault(parser, parseKeyboard, row, selected || skip); } else { throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_SWITCH); } @@ -520,10 +549,13 @@ private void parseSwitchInternal(final XmlPullParser parser, final KeyboardRow r } } - private boolean parseCase(final XmlPullParser parser, final KeyboardRow row, final boolean skip) - throws XmlPullParserException, IOException { + private boolean parseCase(final XmlPullParser parser, final boolean parseKeyboard, + final KeyboardRow row, final boolean skip) throws XmlPullParserException, IOException { final boolean selected = parseCaseCondition(parser); - if (row == null) { + if (parseKeyboard) { + // Processing Keyboard root. + parseKeyboard(parser, !selected || skip); + } else if (row == null) { // Processing Rows. parseKeyboardContent(parser, !selected || skip); } else { @@ -540,6 +572,7 @@ private boolean parseCaseCondition(final XmlPullParser parser) { } final AttributeSet attr = Xml.asAttributeSet(parser); final TypedArray caseAttr = mResources.obtainAttributes(attr, R.styleable.Keyboard_Case); + if (DEBUG) startTag("<%s>", TAG_CASE); try { final boolean keyboardLayoutSetMatched = matchString(caseAttr, R.styleable.Keyboard_Case_keyboardLayoutSet, @@ -548,8 +581,8 @@ private boolean parseCaseCondition(final XmlPullParser parser) { R.styleable.Keyboard_Case_keyboardLayoutSetElement, id.mElementId, KeyboardId.elementIdToName(id.mElementId)); final boolean keyboardThemeMatched = matchTypedValue(caseAttr, - R.styleable.Keyboard_Case_keyboardTheme, mParams.mThemeId, - KeyboardTheme.getKeyboardThemeName(mParams.mThemeId)); + R.styleable.Keyboard_Case_keyboardTheme, id.mThemeId, + KeyboardTheme.getKeyboardThemeName(id.mThemeId)); final boolean modeMatched = matchTypedValue(caseAttr, R.styleable.Keyboard_Case_mode, id.mMode, KeyboardId.modeName(id.mMode)); final boolean navigateNextMatched = matchBoolean(caseAttr, @@ -647,10 +680,12 @@ private static boolean isIconDefined(final TypedArray a, final int index, return iconsSet.getIconDrawable(iconId) != null; } - private boolean parseDefault(final XmlPullParser parser, final KeyboardRow row, - final boolean skip) throws XmlPullParserException, IOException { + private boolean parseDefault(final XmlPullParser parser, final boolean parseKeyboard, + final KeyboardRow row, final boolean skip) throws XmlPullParserException, IOException { if (DEBUG) startTag("<%s>", TAG_DEFAULT); - if (row == null) { + if (parseKeyboard) { + parseKeyboard(parser, skip); + } else if (row == null) { parseKeyboardContent(parser, skip); } else { parseRowContent(parser, row, skip); diff --git a/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/internal/KeyboardParams.java b/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/internal/KeyboardParams.java index 7f33f554b..fed5ccfd7 100644 --- a/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/internal/KeyboardParams.java +++ b/app/src/main/java/rkr/simplekeyboard/inputmethod/keyboard/internal/KeyboardParams.java @@ -29,7 +29,6 @@ public class KeyboardParams { public KeyboardId mId; - public int mThemeId; /** Total height and width of the keyboard, including the paddings and keys */ public int mOccupiedHeight; diff --git a/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/utils/ResourceUtils.java b/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/utils/ResourceUtils.java index f23f2f584..abd19a243 100644 --- a/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/utils/ResourceUtils.java +++ b/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/utils/ResourceUtils.java @@ -183,8 +183,6 @@ private static boolean fulfillsCondition(final HashMap keyValuePa public static int getKeyboardHeight(final Resources res, final SettingsValues settingsValues) { final int defaultKeyboardHeight = getDefaultKeyboardHeight(res); float scale = settingsValues.mKeyboardHeightScale; - if (settingsValues.mShowNumberRow) - scale += 0.1; return (int)(defaultKeyboardHeight * scale); } diff --git a/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/utils/XmlParseUtils.java b/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/utils/XmlParseUtils.java index 0d77ac365..130acd5fb 100644 --- a/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/utils/XmlParseUtils.java +++ b/app/src/main/java/rkr/simplekeyboard/inputmethod/latin/utils/XmlParseUtils.java @@ -30,6 +30,9 @@ private XmlParseUtils() { @SuppressWarnings("serial") public static class ParseException extends XmlPullParserException { + public ParseException(final String msg) { + super(msg); + } public ParseException(final String msg, final XmlPullParser parser) { super(msg + " at " + parser.getPositionDescription()); } diff --git a/app/src/main/res/values-land/config.xml b/app/src/main/res/values-land/config.xml index b058f3bb4..e43a21851 100644 --- a/app/src/main/res/values-land/config.xml +++ b/app/src/main/res/values-land/config.xml @@ -54,4 +54,14 @@ 40.000% + + 3.864%p + + 10%p diff --git a/app/src/main/res/values-sw600dp-land/config.xml b/app/src/main/res/values-sw600dp-land/config.xml index 343bdd61d..c03693212 100644 --- a/app/src/main/res/values-sw600dp-land/config.xml +++ b/app/src/main/res/values-sw600dp-land/config.xml @@ -45,4 +45,10 @@ 4dp + + 4.5%p + + 15%p diff --git a/app/src/main/res/values-sw600dp/config.xml b/app/src/main/res/values-sw600dp/config.xml index 50093fdb0..c1e05f617 100644 --- a/app/src/main/res/values-sw600dp/config.xml +++ b/app/src/main/res/values-sw600dp/config.xml @@ -54,4 +54,9 @@ 3dp + + 4.5%p + + 25.096%p diff --git a/app/src/main/res/values-sw768dp-land/config.xml b/app/src/main/res/values-sw768dp-land/config.xml index fc0cdaaf7..304a4c684 100644 --- a/app/src/main/res/values-sw768dp-land/config.xml +++ b/app/src/main/res/values-sw768dp-land/config.xml @@ -45,4 +45,10 @@ 24.00% + + 3.690%p + + 15%p diff --git a/app/src/main/res/values-sw768dp/config.xml b/app/src/main/res/values-sw768dp/config.xml index e19c27f9a..c642defa5 100644 --- a/app/src/main/res/values-sw768dp/config.xml +++ b/app/src/main/res/values-sw768dp/config.xml @@ -53,4 +53,9 @@ 3dp + + 3.312%p + + 24.466%p diff --git a/app/src/main/res/values-v28/themes-lxx-system-border.xml b/app/src/main/res/values-v28/themes-lxx-system-border.xml index f3fbf83b6..86f45f776 100644 --- a/app/src/main/res/values-v28/themes-lxx-system-border.xml +++ b/app/src/main/res/values-v28/themes-lxx-system-border.xml @@ -31,8 +31,6 @@ name="Keyboard.LXX_SystemBorder" parent="Keyboard" > - - LXXSystemBorder