From e0c37b81fd1c5b369ed523b5c1b8558e65c43829 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Thu, 1 Feb 2024 17:01:41 +0100 Subject: [PATCH] remove unnecessary code/resources --- .../keyboard/keyboard/KeyboardLayoutSet.java | 88 +------------------ .../keyboard/internal/KeyboardBuilder.kt | 2 +- .../keyboard/latin/utils/XmlParseUtils.java | 61 ------------- app/src/main/res/values/attrs.xml | 48 ---------- .../{kbd_emoji_recents.xml => kbd_emoji.xml} | 4 - app/src/main/res/xml/kbd_emoji_category1.xml | 18 ---- app/src/main/res/xml/kbd_emoji_category10.xml | 18 ---- app/src/main/res/xml/kbd_emoji_category2.xml | 19 ---- app/src/main/res/xml/kbd_emoji_category3.xml | 18 ---- app/src/main/res/xml/kbd_emoji_category4.xml | 18 ---- app/src/main/res/xml/kbd_emoji_category5.xml | 18 ---- app/src/main/res/xml/kbd_emoji_category6.xml | 18 ---- app/src/main/res/xml/kbd_emoji_category7.xml | 18 ---- app/src/main/res/xml/kbd_emoji_category8.xml | 18 ---- app/src/main/res/xml/kbd_emoji_category9.xml | 18 ---- .../res/xml/keyboard_layout_set_default.xml | 24 ----- .../res/xml/keyboard_layout_set_emoji.xml | 42 --------- 17 files changed, 5 insertions(+), 445 deletions(-) delete mode 100644 app/src/main/java/helium314/keyboard/latin/utils/XmlParseUtils.java rename app/src/main/res/xml/{kbd_emoji_recents.xml => kbd_emoji.xml} (78%) delete mode 100644 app/src/main/res/xml/kbd_emoji_category1.xml delete mode 100644 app/src/main/res/xml/kbd_emoji_category10.xml delete mode 100644 app/src/main/res/xml/kbd_emoji_category2.xml delete mode 100644 app/src/main/res/xml/kbd_emoji_category3.xml delete mode 100644 app/src/main/res/xml/kbd_emoji_category4.xml delete mode 100644 app/src/main/res/xml/kbd_emoji_category5.xml delete mode 100644 app/src/main/res/xml/kbd_emoji_category6.xml delete mode 100644 app/src/main/res/xml/kbd_emoji_category7.xml delete mode 100644 app/src/main/res/xml/kbd_emoji_category8.xml delete mode 100644 app/src/main/res/xml/kbd_emoji_category9.xml delete mode 100644 app/src/main/res/xml/keyboard_layout_set_default.xml delete mode 100644 app/src/main/res/xml/keyboard_layout_set_emoji.xml diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java index a95896503..2dfdcc22a 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardLayoutSet.java @@ -9,29 +9,20 @@ package helium314.keyboard.keyboard; import android.app.KeyguardManager; import android.content.Context; import android.content.res.Resources; -import android.content.res.TypedArray; -import android.content.res.XmlResourceParser; import android.os.Build; import android.text.InputType; - -import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyTexts; -import helium314.keyboard.latin.utils.Log; -import android.util.Xml; import android.view.inputmethod.EditorInfo; import helium314.keyboard.keyboard.internal.KeyboardBuilder; import helium314.keyboard.keyboard.internal.KeyboardParams; import helium314.keyboard.keyboard.internal.UniqueKeysCache; +import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyTexts; import helium314.keyboard.keyboard.internal.keyboard_parser.LocaleKeyTextsKt; -import helium314.keyboard.latin.R; import helium314.keyboard.latin.RichInputMethodSubtype; import helium314.keyboard.latin.utils.InputTypeUtils; +import helium314.keyboard.latin.utils.Log; import helium314.keyboard.latin.utils.ScriptUtils; -import helium314.keyboard.latin.utils.XmlParseUtils; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; -import java.io.IOException; import java.lang.ref.SoftReference; import java.util.HashMap; @@ -49,9 +40,6 @@ public final class KeyboardLayoutSet { private static final String TAG = KeyboardLayoutSet.class.getSimpleName(); private static final boolean DEBUG_CACHE = false; - private static final String TAG_KEYBOARD_SET = "KeyboardLayoutSet"; - private static final String TAG_ELEMENT = "Element"; - private static final String KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX = "keyboard_layout_set_"; private final Context mContext; @@ -82,9 +70,9 @@ public final class KeyboardLayoutSet { } public static final class Params { - String mKeyboardLayoutSetName; + String mKeyboardLayoutSetName; // this is only for xml, can be removed together with xmls int mMode; - boolean mDisableTouchPositionCorrectionDataForTest; + boolean mDisableTouchPositionCorrectionDataForTest; // remove // TODO: Use {@link InputAttributes} instead of these variables. EditorInfo mEditorInfo; boolean mIsPasswordField; @@ -297,77 +285,9 @@ public final class KeyboardLayoutSet { if (mParams.mSubtype == null) throw new RuntimeException("KeyboardLayoutSet subtype is not specified"); mParams.mScript = ScriptUtils.script(mParams.mSubtype.getLocale()); - // todo: the whole parsing stuff below should be removed, but currently - // it simply breaks when it's not available - // for emojis, moreKeys and moreSuggestions there are relevant parameters included - int xmlId = getXmlId(mResources, mParams.mKeyboardLayoutSetName); - if (xmlId == 0) - xmlId = R.xml.keyboard_layout_set_default; - try { - parseKeyboardLayoutSet(mResources, xmlId); - } catch (final IOException | XmlPullParserException e) { - throw new RuntimeException(e.getMessage() + " in " + mParams.mKeyboardLayoutSetName, e); - } return new KeyboardLayoutSet(mContext, mParams); } - private static int getXmlId(final Resources resources, final String keyboardLayoutSetName) { - final String packageName = resources.getResourcePackageName(R.xml.keyboard_layout_set_default); - return resources.getIdentifier(keyboardLayoutSetName, "xml", packageName); - } - - private void parseKeyboardLayoutSet(final Resources res, final int resId) - throws XmlPullParserException, IOException { - try (XmlResourceParser parser = res.getXml(resId)) { - while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { - final int event = parser.next(); - if (event == XmlPullParser.START_TAG) { - final String tag = parser.getName(); - if (TAG_KEYBOARD_SET.equals(tag)) { - parseKeyboardLayoutSetContent(parser); - } else { - throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD_SET); - } - } - } - } - } - - private void parseKeyboardLayoutSetContent(final XmlPullParser parser) - throws XmlPullParserException, IOException { - while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { - final int event = parser.next(); - if (event == XmlPullParser.START_TAG) { - final String tag = parser.getName(); - if (TAG_ELEMENT.equals(tag)) { - parseKeyboardLayoutSetElement(parser); - } else { - throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD_SET); - } - } else if (event == XmlPullParser.END_TAG) { - final String tag = parser.getName(); - if (TAG_KEYBOARD_SET.equals(tag)) { - break; - } - throw new XmlParseUtils.IllegalEndTag(parser, tag, TAG_KEYBOARD_SET); - } - } - } - - private void parseKeyboardLayoutSetElement(final XmlPullParser parser) - throws XmlPullParserException, IOException { - final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.KeyboardLayoutSet_Element); - try { - XmlParseUtils.checkAttributeExists(a, - R.styleable.KeyboardLayoutSet_Element_elementName, "elementName", - TAG_ELEMENT, parser); - XmlParseUtils.checkEndTag(TAG_ELEMENT, parser); - } finally { - a.recycle(); - } - } - private static int getKeyboardMode(final EditorInfo editorInfo) { final int inputType = editorInfo.inputType; final int variation = inputType & InputType.TYPE_MASK_VARIATION; diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt index b2ea0ee5b..f7dad2868 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt @@ -51,7 +51,7 @@ open class KeyboardBuilder(protected val mContext: Context, mParams.mId = id if (id.isEmojiKeyboard) { setAllowRedundantMoreKeys(true) - readAttributes(R.xml.kbd_emoji_category1) // all the same anyway, gridRows are ignored + readAttributes(R.xml.kbd_emoji) keysInRows = EmojiParser(mParams, mContext).parse() } else { try { diff --git a/app/src/main/java/helium314/keyboard/latin/utils/XmlParseUtils.java b/app/src/main/java/helium314/keyboard/latin/utils/XmlParseUtils.java deleted file mode 100644 index 3cd71aa71..000000000 --- a/app/src/main/java/helium314/keyboard/latin/utils/XmlParseUtils.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * modified - * SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only - */ - -package helium314.keyboard.latin.utils; - -import android.content.res.TypedArray; - -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - -import java.io.IOException; - -public final class XmlParseUtils { - private XmlParseUtils() { - // This utility class is not publicly instantiable. - } - - public static class ParseException extends XmlPullParserException { - public ParseException(final String msg, final XmlPullParser parser) { - super(msg + " at " + parser.getPositionDescription()); - } - } - - public static final class IllegalStartTag extends ParseException { - public IllegalStartTag(final XmlPullParser parser, final String tag, final String parent) { - super("Illegal start tag " + tag + " in " + parent, parser); - } - } - - public static final class IllegalEndTag extends ParseException { - public IllegalEndTag(final XmlPullParser parser, final String tag, final String parent) { - super("Illegal end tag " + tag + " in " + parent, parser); - } - } - - public static final class NonEmptyTag extends ParseException{ - public NonEmptyTag(final XmlPullParser parser, final String tag) { - super(tag + " must be empty tag", parser); - } - } - - public static void checkEndTag(final String tag, final XmlPullParser parser) - throws XmlPullParserException, IOException { - if (parser.next() == XmlPullParser.END_TAG && tag.equals(parser.getName())) - return; - throw new NonEmptyTag(parser, tag); - } - - public static void checkAttributeExists(final TypedArray attr, final int attrId, - final String attrName, final String tag, final XmlPullParser parser) - throws XmlPullParserException { - if (attr.hasValue(attrId)) { - return; - } - throw new ParseException( - "No " + attrName + " attribute found in <" + tag + "/>", parser); - } -} diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 34b7bc7eb..2f1d1bb49 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -279,12 +279,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/xml/kbd_emoji_recents.xml b/app/src/main/res/xml/kbd_emoji.xml similarity index 78% rename from app/src/main/res/xml/kbd_emoji_recents.xml rename to app/src/main/res/xml/kbd_emoji.xml index 5662f1b1a..618bcb185 100644 --- a/app/src/main/res/xml/kbd_emoji_recents.xml +++ b/app/src/main/res/xml/kbd_emoji.xml @@ -11,8 +11,4 @@ latin:keyLabelSize="@fraction/config_emoji_keyboard_key_label_size" latin:rowHeight="@fraction/config_emoji_keyboard_row_height" > - diff --git a/app/src/main/res/xml/kbd_emoji_category1.xml b/app/src/main/res/xml/kbd_emoji_category1.xml deleted file mode 100644 index 87c902a06..000000000 --- a/app/src/main/res/xml/kbd_emoji_category1.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - diff --git a/app/src/main/res/xml/kbd_emoji_category10.xml b/app/src/main/res/xml/kbd_emoji_category10.xml deleted file mode 100644 index 5f366a78a..000000000 --- a/app/src/main/res/xml/kbd_emoji_category10.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - diff --git a/app/src/main/res/xml/kbd_emoji_category2.xml b/app/src/main/res/xml/kbd_emoji_category2.xml deleted file mode 100644 index 50e100950..000000000 --- a/app/src/main/res/xml/kbd_emoji_category2.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - diff --git a/app/src/main/res/xml/kbd_emoji_category3.xml b/app/src/main/res/xml/kbd_emoji_category3.xml deleted file mode 100644 index f61cd28da..000000000 --- a/app/src/main/res/xml/kbd_emoji_category3.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - diff --git a/app/src/main/res/xml/kbd_emoji_category4.xml b/app/src/main/res/xml/kbd_emoji_category4.xml deleted file mode 100644 index 8005e6654..000000000 --- a/app/src/main/res/xml/kbd_emoji_category4.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - diff --git a/app/src/main/res/xml/kbd_emoji_category5.xml b/app/src/main/res/xml/kbd_emoji_category5.xml deleted file mode 100644 index 0dcf5e0e4..000000000 --- a/app/src/main/res/xml/kbd_emoji_category5.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - diff --git a/app/src/main/res/xml/kbd_emoji_category6.xml b/app/src/main/res/xml/kbd_emoji_category6.xml deleted file mode 100644 index 3b201aaa9..000000000 --- a/app/src/main/res/xml/kbd_emoji_category6.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - diff --git a/app/src/main/res/xml/kbd_emoji_category7.xml b/app/src/main/res/xml/kbd_emoji_category7.xml deleted file mode 100644 index a5586765d..000000000 --- a/app/src/main/res/xml/kbd_emoji_category7.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - diff --git a/app/src/main/res/xml/kbd_emoji_category8.xml b/app/src/main/res/xml/kbd_emoji_category8.xml deleted file mode 100644 index ea8ef9500..000000000 --- a/app/src/main/res/xml/kbd_emoji_category8.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - diff --git a/app/src/main/res/xml/kbd_emoji_category9.xml b/app/src/main/res/xml/kbd_emoji_category9.xml deleted file mode 100644 index 80303434a..000000000 --- a/app/src/main/res/xml/kbd_emoji_category9.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - diff --git a/app/src/main/res/xml/keyboard_layout_set_default.xml b/app/src/main/res/xml/keyboard_layout_set_default.xml deleted file mode 100644 index 88702f8de..000000000 --- a/app/src/main/res/xml/keyboard_layout_set_default.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - diff --git a/app/src/main/res/xml/keyboard_layout_set_emoji.xml b/app/src/main/res/xml/keyboard_layout_set_emoji.xml deleted file mode 100644 index db5839791..000000000 --- a/app/src/main/res/xml/keyboard_layout_set_emoji.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - -