remove unnecessary code/resources

This commit is contained in:
Helium314 2024-02-01 17:01:41 +01:00
parent 5e5f045495
commit e0c37b81fd
17 changed files with 5 additions and 445 deletions

View file

@ -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;

View file

@ -51,7 +51,7 @@ open class KeyboardBuilder<KP : KeyboardParams>(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 {

View file

@ -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);
}
}

View file

@ -279,12 +279,6 @@
<attr name="iconRedo" format="reference" />
</declare-styleable>
<declare-styleable name="Keyboard_GridRows">
<attr name="codesArray" format="reference" />
<attr name="textsArray" format="reference" />
<attr name="moreCodesArray" format="reference" />
</declare-styleable>
<declare-styleable name="Keyboard_Key">
<!-- The alternate unicode value that this key outputs while typing.
Code value represented in hexadecimal prefixed with "0x" or code value reference using
@ -522,48 +516,6 @@
<attr name="parentStyle" format="string" />
</declare-styleable>
<declare-styleable name="KeyboardLayoutSet_Element">
<!-- This should be aligned with
{@link helium314.keyboard.keyboard.KeyboardId#ELEMENT_ALPHABET} etc. -->
<attr name="elementName" format="enum">
<enum name="alphabet" value="0" />
<enum name="alphabetManualShifted" value="1" />
<enum name="alphabetAutomaticShifted" value="2" />
<enum name="alphabetShiftLocked" value="3" />
<enum name="alphabetShiftLockShifted" value="4" />
<enum name="symbols" value="5" />
<enum name="symbolsShifted" value="6" />
<enum name="phone" value="7" />
<enum name="phoneSymbols" value="8" />
<enum name="number" value="9" />
<enum name="emojiRecents" value="10" />
<enum name="emojiCategory1" value="11" />
<enum name="emojiCategory2" value="12" />
<enum name="emojiCategory3" value="13" />
<enum name="emojiCategory4" value="14" />
<enum name="emojiCategory5" value="15" />
<enum name="emojiCategory6" value="16" />
<enum name="emojiCategory7" value="17" />
<enum name="emojiCategory8" value="18" />
<enum name="emojiCategory9" value="19" />
<enum name="emojiCategory10" value="20" />
<enum name="emojiCategory11" value="21" />
<enum name="emojiCategory12" value="22" />
<enum name="emojiCategory13" value="23" />
<enum name="emojiCategory14" value="24" />
<enum name="emojiCategory15" value="25" />
<enum name="emojiCategory16" value="26" />
<enum name="numpad" value="28" />
</attr>
<attr name="elementKeyboard" format="reference"/>
<!-- Enable proximity characters correction. Disabled by default. -->
<attr name="enableProximityCharsCorrection" format="boolean" />
<!-- Indicates if the keyboard layout supports being split or not. false by default -->
<attr name="supportsSplitLayout" format="boolean" />
<!-- Allow redundant more keys when they are in the base layout. true by default. -->
<attr name="allowRedundantMoreKeys" format="boolean" />
</declare-styleable>
<declare-styleable name="SeekBarDialogPreference">
<attr name="maxValue" format="integer" />
<attr name="minValue" format="integer" />

View file

@ -11,8 +11,4 @@
latin:keyLabelSize="@fraction/config_emoji_keyboard_key_label_size"
latin:rowHeight="@fraction/config_emoji_keyboard_row_height"
>
<GridRows
latin:codesArray="@array/emoji_recents"
latin:keyLabelFlags="fontNormal"
latin:backgroundType="empty" />
</Keyboard>

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
-->
<Keyboard
xmlns:latin="http://schemas.android.com/apk/res-auto"
latin:keyWidth="@fraction/config_emoji_keyboard_key_width"
latin:keyLetterSize="@fraction/config_emoji_keyboard_key_letter_size"
latin:keyLabelSize="@fraction/config_emoji_keyboard_key_label_size"
latin:rowHeight="@fraction/config_emoji_keyboard_row_height"
>
<GridRows
latin:codesArray="@array/emoji_smileys_emotion"
latin:keyLabelFlags="fontNormal"
latin:backgroundType="empty" />
</Keyboard>

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
-->
<Keyboard
xmlns:latin="http://schemas.android.com/apk/res-auto"
latin:keyWidth="@fraction/config_emoji_keyboard_key_width"
latin:keyLetterSize="@fraction/config_emoji_keyboard_key_letter_size"
latin:keyLabelSize="@fraction/config_emoji_keyboard_key_label_size"
latin:rowHeight="@fraction/config_emoji_keyboard_row_height"
>
<GridRows
latin:textsArray="@array/emoji_emoticons"
latin:keyLabelFlags="fontNormal"
latin:backgroundType="empty" />
</Keyboard>

View file

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
-->
<Keyboard
xmlns:latin="http://schemas.android.com/apk/res-auto"
latin:keyWidth="@fraction/config_emoji_keyboard_key_width"
latin:keyLetterSize="@fraction/config_emoji_keyboard_key_letter_size"
latin:keyLabelSize="@fraction/config_emoji_keyboard_key_label_size"
latin:rowHeight="@fraction/config_emoji_keyboard_row_height"
>
<GridRows
latin:codesArray="@array/emoji_people_body"
latin:moreCodesArray="@array/emoji_people_body_more"
latin:keyLabelFlags="fontNormal"
latin:backgroundType="empty" />
</Keyboard>

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
-->
<Keyboard
xmlns:latin="http://schemas.android.com/apk/res-auto"
latin:keyWidth="@fraction/config_emoji_keyboard_key_width"
latin:keyLetterSize="@fraction/config_emoji_keyboard_key_letter_size"
latin:keyLabelSize="@fraction/config_emoji_keyboard_key_label_size"
latin:rowHeight="@fraction/config_emoji_keyboard_row_height"
>
<GridRows
latin:codesArray="@array/emoji_animals_nature"
latin:keyLabelFlags="fontNormal"
latin:backgroundType="empty" />
</Keyboard>

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
-->
<Keyboard
xmlns:latin="http://schemas.android.com/apk/res-auto"
latin:keyWidth="@fraction/config_emoji_keyboard_key_width"
latin:keyLetterSize="@fraction/config_emoji_keyboard_key_letter_size"
latin:keyLabelSize="@fraction/config_emoji_keyboard_key_label_size"
latin:rowHeight="@fraction/config_emoji_keyboard_row_height"
>
<GridRows
latin:codesArray="@array/emoji_food_drink"
latin:keyLabelFlags="fontNormal"
latin:backgroundType="empty" />
</Keyboard>

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
-->
<Keyboard
xmlns:latin="http://schemas.android.com/apk/res-auto"
latin:keyWidth="@fraction/config_emoji_keyboard_key_width"
latin:keyLetterSize="@fraction/config_emoji_keyboard_key_letter_size"
latin:keyLabelSize="@fraction/config_emoji_keyboard_key_label_size"
latin:rowHeight="@fraction/config_emoji_keyboard_row_height"
>
<GridRows
latin:codesArray="@array/emoji_travel_places"
latin:keyLabelFlags="fontNormal"
latin:backgroundType="empty" />
</Keyboard>

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
-->
<Keyboard
xmlns:latin="http://schemas.android.com/apk/res-auto"
latin:keyWidth="@fraction/config_emoji_keyboard_key_width"
latin:keyLetterSize="@fraction/config_emoji_keyboard_key_letter_size"
latin:keyLabelSize="@fraction/config_emoji_keyboard_key_label_size"
latin:rowHeight="@fraction/config_emoji_keyboard_row_height"
>
<GridRows
latin:codesArray="@array/emoji_activities"
latin:keyLabelFlags="fontNormal"
latin:backgroundType="empty" />
</Keyboard>

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
-->
<Keyboard
xmlns:latin="http://schemas.android.com/apk/res-auto"
latin:keyWidth="@fraction/config_emoji_keyboard_key_width"
latin:keyLetterSize="@fraction/config_emoji_keyboard_key_letter_size"
latin:keyLabelSize="@fraction/config_emoji_keyboard_key_label_size"
latin:rowHeight="@fraction/config_emoji_keyboard_row_height"
>
<GridRows
latin:codesArray="@array/emoji_objects"
latin:keyLabelFlags="fontNormal"
latin:backgroundType="empty" />
</Keyboard>

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
-->
<Keyboard
xmlns:latin="http://schemas.android.com/apk/res-auto"
latin:keyWidth="@fraction/config_emoji_keyboard_key_width"
latin:keyLetterSize="@fraction/config_emoji_keyboard_key_letter_size"
latin:keyLabelSize="@fraction/config_emoji_keyboard_key_label_size"
latin:rowHeight="@fraction/config_emoji_keyboard_row_height"
>
<GridRows
latin:codesArray="@array/emoji_symbols"
latin:keyLabelFlags="fontNormal"
latin:backgroundType="empty" />
</Keyboard>

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
-->
<Keyboard
xmlns:latin="http://schemas.android.com/apk/res-auto"
latin:keyWidth="@fraction/config_emoji_keyboard_key_width"
latin:keyLetterSize="@fraction/config_emoji_keyboard_key_letter_size"
latin:keyLabelSize="@fraction/config_emoji_keyboard_key_label_size"
latin:rowHeight="@fraction/config_emoji_keyboard_row_height"
>
<GridRows
latin:codesArray="@array/emoji_flags"
latin:keyLabelFlags="fontNormal"
latin:backgroundType="empty" />
</Keyboard>

View file

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2012 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
-->
<KeyboardLayoutSet
xmlns:latin="http://schemas.android.com/apk/res-auto">
<Element
latin:elementName="alphabet"
latin:enableProximityCharsCorrection="true" />
<Element
latin:elementName="symbols" />
<Element
latin:elementName="symbolsShifted" />
<Element
latin:elementName="phone" />
<Element
latin:elementName="phoneSymbols" />
<Element
latin:elementName="number" />
<Element
latin:elementName="numpad" />
</KeyboardLayoutSet>

View file

@ -1,42 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
modified
SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
-->
<KeyboardLayoutSet
xmlns:latin="http://schemas.android.com/apk/res-auto">
<Element
latin:elementName="emojiRecents"
latin:elementKeyboard="@xml/kbd_emoji_recents" />
<Element
latin:elementName="emojiCategory1"
latin:elementKeyboard="@xml/kbd_emoji_category1" />
<Element
latin:elementName="emojiCategory2"
latin:elementKeyboard="@xml/kbd_emoji_category2" />
<Element
latin:elementName="emojiCategory3"
latin:elementKeyboard="@xml/kbd_emoji_category3" />
<Element
latin:elementName="emojiCategory4"
latin:elementKeyboard="@xml/kbd_emoji_category4" />
<Element
latin:elementName="emojiCategory5"
latin:elementKeyboard="@xml/kbd_emoji_category5" />
<Element
latin:elementName="emojiCategory6"
latin:elementKeyboard="@xml/kbd_emoji_category6" />
<Element
latin:elementName="emojiCategory7"
latin:elementKeyboard="@xml/kbd_emoji_category7" />
<Element
latin:elementName="emojiCategory8"
latin:elementKeyboard="@xml/kbd_emoji_category8" />
<Element
latin:elementName="emojiCategory9"
latin:elementKeyboard="@xml/kbd_emoji_category9" />
<Element
latin:elementName="emojiCategory10"
latin:elementKeyboard="@xml/kbd_emoji_category10" />
</KeyboardLayoutSet>