From aca2ef85e1af82ccadbd0cbdd691a680a03a824d Mon Sep 17 00:00:00 2001 From: Jean Chalard <jchalard@google.com> Date: Thu, 26 Jun 2014 16:20:59 +0900 Subject: [PATCH] [SD2] Add support for a new tag Feature in KeyboardLayoutSet Bug: 15840116 Change-Id: I3abbe4ce1ae573e9c5f1a8a96dc0056e8889d507 --- java/res/values/attrs.xml | 11 +++++++++ java/res/xml/keyboard_layout_set_arabic.xml | 2 ++ .../keyboard/KeyboardLayoutSet.java | 24 +++++++++++++++++++ .../inputmethod/latin/utils/ScriptUtils.java | 3 +++ 4 files changed, 40 insertions(+) diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index fcb919d0b0..7dda0a652d 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -488,6 +488,17 @@ <attr name="enableProximityCharsCorrection" format="boolean" /> </declare-styleable> + <declare-styleable name="KeyboardLayoutSet_Feature"> + <!-- This should be aligned with ScriptUtils.SCRIPT_* --> + <attr name="supportedScript" format="enum"> + <enum name="latin" value="0" /> + <enum name="cyrillic" value="1" /> + <enum name="greek" value="2" /> + <enum name="arabic" value="3" /> + <enum name="hebrew" value="4" /> + </attr> + </declare-styleable> + <declare-styleable name="SeekBarDialogPreference"> <attr name="maxValue" format="integer" /> <attr name="minValue" format="integer" /> diff --git a/java/res/xml/keyboard_layout_set_arabic.xml b/java/res/xml/keyboard_layout_set_arabic.xml index 10e95bd30d..1bf8c6295d 100644 --- a/java/res/xml/keyboard_layout_set_arabic.xml +++ b/java/res/xml/keyboard_layout_set_arabic.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="arabic" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_arabic" diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java index 3e5cfc11a3..7ba3b3bd5d 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java @@ -40,6 +40,7 @@ import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.utils.InputTypeUtils; +import com.android.inputmethod.latin.utils.ScriptUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import com.android.inputmethod.latin.utils.XmlParseUtils; @@ -63,6 +64,7 @@ public final class KeyboardLayoutSet { private static final String TAG_KEYBOARD_SET = "KeyboardLayoutSet"; private static final String TAG_ELEMENT = "Element"; + private static final String TAG_FEATURE = "Feature"; private static final String KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX = "keyboard_layout_set_"; @@ -111,6 +113,7 @@ public final class KeyboardLayoutSet { boolean mIsSpellChecker; int mKeyboardWidth; int mKeyboardHeight; + int mScriptId; // Sparse array of KeyboardLayoutSet element parameters indexed by element's id. final SparseArray<ElementParams> mKeyboardLayoutSetElementIdToParamsMap = new SparseArray<>(); @@ -275,6 +278,10 @@ public final class KeyboardLayoutSet { mParams.mDisableTouchPositionCorrectionDataForTest = true; } + public void setScriptId(final int scriptId) { + mParams.mScriptId = scriptId; + } + public KeyboardLayoutSet build() { if (mParams.mSubtype == null) throw new RuntimeException("KeyboardLayoutSet subtype is not specified"); @@ -320,6 +327,8 @@ public final class KeyboardLayoutSet { final String tag = parser.getName(); if (TAG_ELEMENT.equals(tag)) { parseKeyboardLayoutSetElement(parser); + } else if (TAG_FEATURE.equals(tag)) { + parseKeyboardLayoutSetFeature(parser); } else { throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD_SET); } @@ -361,6 +370,21 @@ public final class KeyboardLayoutSet { } } + private void parseKeyboardLayoutSetFeature(final XmlPullParser parser) + throws XmlPullParserException, IOException { + final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.KeyboardLayoutSet_Feature); + try { + final int scriptId = a.getInt( + R.styleable.KeyboardLayoutSet_Feature_supportedScript, + ScriptUtils.SCRIPT_LATIN); + XmlParseUtils.checkEndTag(TAG_FEATURE, parser); + setScriptId(scriptId); + } 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/java/src/com/android/inputmethod/latin/utils/ScriptUtils.java b/java/src/com/android/inputmethod/latin/utils/ScriptUtils.java index 4dfb38d80f..00355c307f 100644 --- a/java/src/com/android/inputmethod/latin/utils/ScriptUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/ScriptUtils.java @@ -23,9 +23,12 @@ import java.util.TreeMap; * A class to help with handling different writing scripts. */ public class ScriptUtils { + // TODO: should we use ISO 15924 identifiers instead? public static final int SCRIPT_LATIN = 0; public static final int SCRIPT_CYRILLIC = 1; public static final int SCRIPT_GREEK = 2; + public static final int SCRIPT_ARABIC = 3; + public static final int SCRIPT_HEBREW = 4; public static final TreeMap<String, Integer> mLanguageToScript; static { // List of the supported languages and their associated script. We won't check -- GitLab