From 4e1dab8cfaad891fe041ed8d71893186c05cef71 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Sun, 18 Dec 2011 19:54:08 +0900 Subject: Move KeyboardBuilder and KeyboardParams classes into Keyboard class This change also moves XmlParseUtils to com.android.inputmethod.latin package. Bug: 5778201 Change-Id: I7d9faa344460753ce178ad4048e0fadb65c75614 --- .../android/inputmethod/latin/XmlParseUtils.java | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 java/src/com/android/inputmethod/latin/XmlParseUtils.java (limited to 'java/src/com/android/inputmethod/latin/XmlParseUtils.java') diff --git a/java/src/com/android/inputmethod/latin/XmlParseUtils.java b/java/src/com/android/inputmethod/latin/XmlParseUtils.java new file mode 100644 index 000000000..d747a024c --- /dev/null +++ b/java/src/com/android/inputmethod/latin/XmlParseUtils.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.android.inputmethod.latin; + +import android.content.res.TypedArray; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +import java.io.IOException; + +public class XmlParseUtils { + @SuppressWarnings("serial") + public static class ParseException extends XmlPullParserException { + public ParseException(String msg, XmlPullParser parser) { + super(msg + " at line " + parser.getLineNumber() + + ", column " + parser.getColumnNumber()); + } + } + + @SuppressWarnings("serial") + public static class IllegalStartTag extends ParseException { + public IllegalStartTag(XmlPullParser parser, String parent) { + super("Illegal start tag " + parser.getName() + " in " + parent, parser); + } + } + + @SuppressWarnings("serial") + public static class IllegalEndTag extends ParseException { + public IllegalEndTag(XmlPullParser parser, String parent) { + super("Illegal end tag " + parser.getName() + " in " + parent, parser); + } + } + + @SuppressWarnings("serial") + public static class IllegalAttribute extends ParseException { + public IllegalAttribute(XmlPullParser parser, String attribute) { + super("Tag " + parser.getName() + " has illegal attribute " + attribute, parser); + } + } + + @SuppressWarnings("serial") + public static class NonEmptyTag extends ParseException{ + public NonEmptyTag(String tag, XmlPullParser parser) { + super(tag + " must be empty tag", parser); + } + } + + public static void checkEndTag(String tag, XmlPullParser parser) + throws XmlPullParserException, IOException { + if (parser.next() == XmlPullParser.END_TAG && tag.equals(parser.getName())) + return; + throw new NonEmptyTag(tag, parser); + } + + public static void checkAttributeExists(TypedArray attr, int attrId, String attrName, + String tag, XmlPullParser parser) throws XmlPullParserException { + if (attr.hasValue(attrId)) + return; + throw new ParseException( + "No " + attrName + " attribute found in <" + tag + "/>", parser); + } +} -- cgit v1.2.3-83-g751a From 05bfd189a88be79ddfc74d0ea21792e2fb78f2aa Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 16 Feb 2012 23:14:14 -0800 Subject: Add next/prev navigate action more keys and remove tab key Bug: 6037537 Bug: 5961814 Change-Id: I9c6dedf953452a180fcd5bce7bfadfd3c821f224 --- java/res/values/attrs.xml | 3 +- java/res/values/donottranslate-more-keys.xml | 2 + java/res/values/keycodes.xml | 4 +- java/res/xml-sw600dp/key_styles_common.xml | 29 +++- java/res/xml-sw768dp/key_styles_common.xml | 29 +++- java/res/xml/key_f1.xml | 97 ------------ java/res/xml/key_navigation_tab.xml | 37 ----- java/res/xml/key_styles_common.xml | 23 ++- java/res/xml/key_styles_enter.xml | 166 +++++++++++++++++++++ java/res/xml/key_styles_enter_phone.xml | 123 --------------- java/res/xml/key_styles_enter_tablet.xml | 111 -------------- java/res/xml/key_symbols_f1.xml | 67 --------- java/res/xml/row_qwerty4.xml | 58 +++---- java/res/xml/row_symbols4.xml | 67 --------- java/res/xml/row_symbols_shift4.xml | 84 ----------- java/res/xml/rows_symbols.xml | 33 +++- java/res/xml/rows_symbols_shift.xml | 27 +++- .../inputmethod/compat/EditorInfoCompatUtils.java | 10 +- .../com/android/inputmethod/keyboard/Keyboard.java | 30 ++-- .../android/inputmethod/keyboard/KeyboardId.java | 34 +++-- .../inputmethod/keyboard/internal/KeyStyles.java | 8 +- .../com/android/inputmethod/latin/LatinIME.java | 48 +----- .../android/inputmethod/latin/XmlParseUtils.java | 3 +- 23 files changed, 381 insertions(+), 712 deletions(-) delete mode 100644 java/res/xml/key_f1.xml delete mode 100644 java/res/xml/key_navigation_tab.xml create mode 100644 java/res/xml/key_styles_enter.xml delete mode 100644 java/res/xml/key_styles_enter_phone.xml delete mode 100644 java/res/xml/key_styles_enter_tablet.xml delete mode 100644 java/res/xml/key_symbols_f1.xml delete mode 100644 java/res/xml/row_symbols4.xml delete mode 100644 java/res/xml/row_symbols_shift4.xml (limited to 'java/src/com/android/inputmethod/latin/XmlParseUtils.java') diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index f91b0a3db..a5d590e04 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -355,7 +355,8 @@ - + + diff --git a/java/res/values/donottranslate-more-keys.xml b/java/res/values/donottranslate-more-keys.xml index f1c2d2bfc..02fd20015 100644 --- a/java/res/values/donottranslate-more-keys.xml +++ b/java/res/values/donottranslate-more-keys.xml @@ -118,6 +118,8 @@ \@icon/settingsKey|\@integer/key_settings , + \@string/label_next_key|\@integer/key_action_next + \@string/label_previous_key|\@integer/key_action_previous \? ; % diff --git a/java/res/values/keycodes.xml b/java/res/values/keycodes.xml index c85c02263..7f9e4bda4 100644 --- a/java/res/values/keycodes.xml +++ b/java/res/values/keycodes.xml @@ -30,5 +30,7 @@ -5 -6 -7 - -9 + -8 + -9 + -10 diff --git a/java/res/xml-sw600dp/key_styles_common.xml b/java/res/xml-sw600dp/key_styles_common.xml index bb75b1c82..2fa8b3812 100644 --- a/java/res/xml-sw600dp/key_styles_common.xml +++ b/java/res/xml-sw600dp/key_styles_common.xml @@ -73,7 +73,7 @@ latin:keyActionFlags="isRepeatable|noKeyPreview" latin:backgroundType="functional" /> + latin:keyboardLayout="@xml/key_styles_enter" /> - + + + + + + + + + latin:keyboardLayout="@xml/key_styles_enter" /> - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/res/xml/key_navigation_tab.xml b/java/res/xml/key_navigation_tab.xml deleted file mode 100644 index c77189fda..000000000 --- a/java/res/xml/key_navigation_tab.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - diff --git a/java/res/xml/key_styles_common.xml b/java/res/xml/key_styles_common.xml index eabbdb399..f0ea8ce5a 100644 --- a/java/res/xml/key_styles_common.xml +++ b/java/res/xml/key_styles_common.xml @@ -27,13 +27,13 @@ latin:clobberSettingsKey="true" > @@ -77,7 +77,22 @@ latin:keyActionFlags="isRepeatable|noKeyPreview" latin:backgroundType="functional" /> + latin:keyboardLayout="@xml/key_styles_enter" /> + + + + + + + latin:parentStyle="f1MoreKeysStyle" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/res/xml/key_styles_enter_phone.xml b/java/res/xml/key_styles_enter_phone.xml deleted file mode 100644 index af34cb858..000000000 --- a/java/res/xml/key_styles_enter_phone.xml +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/res/xml/key_styles_enter_tablet.xml b/java/res/xml/key_styles_enter_tablet.xml deleted file mode 100644 index 702089181..000000000 --- a/java/res/xml/key_styles_enter_tablet.xml +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/res/xml/key_symbols_f1.xml b/java/res/xml/key_symbols_f1.xml deleted file mode 100644 index ac4031fcc..000000000 --- a/java/res/xml/key_symbols_f1.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/res/xml/row_qwerty4.xml b/java/res/xml/row_qwerty4.xml index 2f8b82c3a..df9c8fe3f 100644 --- a/java/res/xml/row_qwerty4.xml +++ b/java/res/xml/row_qwerty4.xml @@ -24,44 +24,46 @@ + - - + latin:keyLabel="/" + latin:keyStyle="f1MoreKeysStyle" /> + + + latin:keyLabel="\@" + latin:keyStyle="f1MoreKeysStyle" /> + + + latin:keyStyle="shortcutKeyStyle" /> - - + - - - - - + latin:keyLabel="@string/keylabel_for_comma" + latin:keyLabelFlags="hasPopupHint" + latin:additionalMoreKeys="@string/more_keys_for_comma" + latin:keyStyle="f1MoreKeysStyle" /> + + + diff --git a/java/res/xml/row_symbols4.xml b/java/res/xml/row_symbols4.xml deleted file mode 100644 index ef77bc3cd..000000000 --- a/java/res/xml/row_symbols4.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/res/xml/row_symbols_shift4.xml b/java/res/xml/row_symbols_shift4.xml deleted file mode 100644 index 632aafc74..000000000 --- a/java/res/xml/row_symbols_shift4.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/res/xml/rows_symbols.xml b/java/res/xml/rows_symbols.xml index 27f75b564..21f7d1d27 100644 --- a/java/res/xml/rows_symbols.xml +++ b/java/res/xml/rows_symbols.xml @@ -128,6 +128,35 @@ latin:keyWidth="fillRight" latin:visualInsetsLeft="1%p" /> - + + + + + + + + + + + + + + + diff --git a/java/res/xml/rows_symbols_shift.xml b/java/res/xml/rows_symbols_shift.xml index 3fb821486..a7d0499e1 100644 --- a/java/res/xml/rows_symbols_shift.xml +++ b/java/res/xml/rows_symbols_shift.xml @@ -119,6 +119,29 @@ latin:keyWidth="fillRight" latin:visualInsetsLeft="1%p" /> - + + + + + + + + + + + + + diff --git a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java index 3247997f6..938388d6c 100644 --- a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java @@ -39,30 +39,30 @@ public class EditorInfoCompatUtils { private static final Integer OBJ_IME_ACTION_PREVIOUS = (Integer) CompatUtils .getFieldValue(null, null, FIELD_IME_ACTION_PREVIOUS); + // EditorInfo.IME_FLAG_NAVIGATE_NEXT has been introduced since API#11 (Honeycomb). public static boolean hasFlagNavigateNext(int imeOptions) { if (OBJ_IME_FLAG_NAVIGATE_NEXT == null) return false; return (imeOptions & OBJ_IME_FLAG_NAVIGATE_NEXT) != 0; } + // EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS has been introduced since API#11 (Honeycomb). public static boolean hasFlagNavigatePrevious(int imeOptions) { if (OBJ_IME_FLAG_NAVIGATE_PREVIOUS == null) return false; return (imeOptions & OBJ_IME_FLAG_NAVIGATE_PREVIOUS) != 0; } + // EditorInfo.IME_FLAG_FORCE_ASCII has been introduced since API#16 (JellyBean). public static boolean hasFlagForceAscii(int imeOptions) { if (OBJ_IME_FLAG_FORCE_ASCII == null) return false; return (imeOptions & OBJ_IME_FLAG_FORCE_ASCII) != 0; } - public static void performEditorActionNext(InputConnection ic) { - ic.performEditorAction(EditorInfo.IME_ACTION_NEXT); - } - + // EditorInfo.IME_ACTION_PREVIOUS has been introduced since API#11 (Honeycomb). public static void performEditorActionPrevious(InputConnection ic) { - if (OBJ_IME_ACTION_PREVIOUS == null) + if (OBJ_IME_ACTION_PREVIOUS == null || ic == null) return; ic.performEditorAction(OBJ_IME_ACTION_PREVIOUS); } diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 60e506914..30ed59e18 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -99,8 +99,10 @@ public class Keyboard { public static final int CODE_SETTINGS = -5; public static final int CODE_SHORTCUT = -6; public static final int CODE_ACTION_ENTER = -7; + public static final int CODE_ACTION_NEXT = -8; + public static final int CODE_ACTION_PREVIOUS = -9; // Code value representing the code is not specified. - public static final int CODE_UNSPECIFIED = -9; + public static final int CODE_UNSPECIFIED = -10; public final KeyboardId mId; public final int mThemeId; @@ -381,6 +383,8 @@ public class Keyboard { case CODE_SETTINGS: return "settings"; case CODE_SHORTCUT: return "shortcut"; case CODE_ACTION_ENTER: return "actionEnter"; + case CODE_ACTION_NEXT: return "actionNext"; + case CODE_ACTION_PREVIOUS: return "actionPrevious"; case CODE_UNSPECIFIED: return "unspec"; case CODE_TAB: return "tab"; case CODE_ENTER: return "enter"; @@ -1069,8 +1073,10 @@ public class Keyboard { KeyboardId.elementIdToName(id.mElementId)); final boolean modeMatched = matchTypedValue(a, R.styleable.Keyboard_Case_mode, id.mMode, KeyboardId.modeName(id.mMode)); - final boolean navigateActionMatched = matchBoolean(a, - R.styleable.Keyboard_Case_navigateAction, id.navigateAction()); + final boolean navigateNextMatched = matchBoolean(a, + R.styleable.Keyboard_Case_navigateNext, id.navigateNext()); + final boolean navigatePreviousMatched = matchBoolean(a, + R.styleable.Keyboard_Case_navigatePrevious, id.navigatePrevious()); final boolean passwordInputMatched = matchBoolean(a, R.styleable.Keyboard_Case_passwordInput, id.passwordInput()); final boolean clobberSettingsKeyMatched = matchBoolean(a, @@ -1090,30 +1096,32 @@ public class Keyboard { final boolean countryCodeMatched = matchString(a, R.styleable.Keyboard_Case_countryCode, id.mLocale.getCountry()); final boolean selected = keyboardSetElementMatched && modeMatched - && navigateActionMatched && passwordInputMatched + && navigateNextMatched && navigatePreviousMatched && passwordInputMatched && clobberSettingsKeyMatched && shortcutKeyEnabledMatched && hasShortcutKeyMatched && isMultiLineMatched && imeActionMatched && localeCodeMatched && languageCodeMatched && countryCodeMatched; if (DEBUG) { - startTag("<%s%s%s%s%s%s%s%s%s%s%s%s%s>%s", TAG_CASE, + startTag("<%s%s%s%s%s%s%s%s%s%s%s%s%s%s>%s", TAG_CASE, textAttr(a.getString(R.styleable.Keyboard_Case_keyboardSetElement), "keyboardSetElement"), textAttr(a.getString(R.styleable.Keyboard_Case_mode), "mode"), - booleanAttr(a, R.styleable.Keyboard_Case_navigateAction, - "navigateAction"), - booleanAttr(a, R.styleable.Keyboard_Case_passwordInput, - "passwordInput"), + textAttr(a.getString(R.styleable.Keyboard_Case_imeAction), + "imeAction"), + booleanAttr(a, R.styleable.Keyboard_Case_navigateNext, + "navigateNext"), + booleanAttr(a, R.styleable.Keyboard_Case_navigatePrevious, + "navigatePrevious"), booleanAttr(a, R.styleable.Keyboard_Case_clobberSettingsKey, "clobberSettingsKey"), + booleanAttr(a, R.styleable.Keyboard_Case_passwordInput, + "passwordInput"), booleanAttr(a, R.styleable.Keyboard_Case_shortcutKeyEnabled, "shortcutKeyEnabled"), booleanAttr(a, R.styleable.Keyboard_Case_hasShortcutKey, "hasShortcutKey"), booleanAttr(a, R.styleable.Keyboard_Case_isMultiLine, "isMultiLine"), - textAttr(a.getString(R.styleable.Keyboard_Case_imeAction), - "imeAction"), textAttr(a.getString(R.styleable.Keyboard_Case_localeCode), "localeCode"), textAttr(a.getString(R.styleable.Keyboard_Case_languageCode), diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java index a75caf262..ed4a89e0f 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java @@ -87,7 +87,6 @@ public class KeyboardId { id.mElementId, id.mMode, id.mWidth, - id.navigateAction(), id.passwordInput(), id.mClobberSettingsKey, id.mShortcutKeyEnabled, @@ -95,6 +94,8 @@ public class KeyboardId { id.isMultiLine(), id.imeAction(), id.mCustomActionLabel, + id.navigateNext(), + id.navigatePrevious(), id.mLocale }); } @@ -106,7 +107,6 @@ public class KeyboardId { && other.mElementId == this.mElementId && other.mMode == this.mMode && other.mWidth == this.mWidth - && other.navigateAction() == this.navigateAction() && other.passwordInput() == this.passwordInput() && other.mClobberSettingsKey == this.mClobberSettingsKey && other.mShortcutKeyEnabled == this.mShortcutKeyEnabled @@ -114,6 +114,8 @@ public class KeyboardId { && other.isMultiLine() == this.isMultiLine() && other.imeAction() == this.imeAction() && TextUtils.equals(other.mCustomActionLabel, this.mCustomActionLabel) + && other.navigateNext() == this.navigateNext() + && other.navigatePrevious() == this.navigatePrevious() && other.mLocale.equals(this.mLocale); } @@ -146,12 +148,12 @@ public class KeyboardId { return mElementId == ELEMENT_PHONE_SYMBOLS; } - public boolean navigateAction() { - // Note: Turn off checking navigation flag to show TAB key for now. - boolean navigateAction = InputTypeCompatUtils.isWebInputType(mEditorInfo.inputType); -// || EditorInfoCompatUtils.hasFlagNavigateNext(mImeOptions) -// || EditorInfoCompatUtils.hasFlagNavigatePrevious(mImeOptions); - return navigateAction; + public boolean navigateNext() { + return EditorInfoCompatUtils.hasFlagNavigateNext(mEditorInfo.imeOptions); + } + + public boolean navigatePrevious() { + return EditorInfoCompatUtils.hasFlagNavigatePrevious(mEditorInfo.imeOptions); } public boolean passwordInput() { @@ -165,15 +167,21 @@ public class KeyboardId { } public int imeAction() { + final int actionId = mEditorInfo.imeOptions & EditorInfo.IME_MASK_ACTION; if ((mEditorInfo.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) { return EditorInfo.IME_ACTION_NONE; } else if (mEditorInfo.actionLabel != null) { return IME_ACTION_CUSTOM_LABEL; } else { - return mEditorInfo.imeOptions & EditorInfo.IME_MASK_ACTION; + return actionId; } } + public int imeActionId() { + final int actionId = imeAction(); + return actionId == IME_ACTION_CUSTOM_LABEL ? mEditorInfo.actionId : actionId; + } + @Override public boolean equals(Object other) { return other instanceof KeyboardId && equals((KeyboardId) other); @@ -186,17 +194,19 @@ public class KeyboardId { @Override public String toString() { - return String.format("[%s %s %s%d %s %s %s%s%s%s%s]", + return String.format("[%s %s %s%d %s %s %s%s%s%s%s%s%s]", elementIdToName(mElementId), mLocale, (mOrientation == 1 ? "port" : "land"), mWidth, modeName(mMode), imeAction(), + (navigateNext() ? "navigateNext" : ""), + (navigatePrevious() ? "navigatePrevious" : ""), (mClobberSettingsKey ? " clobberSettingsKey" : ""), - (navigateAction() ? " navigateAction" : ""), (passwordInput() ? " passwordInput" : ""), (mShortcutKeyEnabled ? " shortcutKeyEnabled" : ""), - (mHasShortcutKey ? " hasShortcutKey" : "") + (mHasShortcutKey ? " hasShortcutKey" : ""), + (isMultiLine() ? "isMultiLine" : "") ); } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java index 12a9c51f2..9e5c227eb 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java @@ -163,10 +163,10 @@ public class KeyStyles { if (DEBUG) { Log.d(TAG, String.format("<%s styleName=%s />", Keyboard.Builder.TAG_KEY_STYLE, styleName)); - } - if (mStyles.containsKey(styleName)) { - throw new XmlParseUtils.ParseException( - "duplicate key style declared: " + styleName, parser); + if (mStyles.containsKey(styleName)) { + Log.d(TAG, "key-style " + styleName + " is overridden at " + + parser.getPositionDescription()); + } } final DeclaredKeyStyle style = new DeclaredKeyStyle(); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 730992b13..aef248e19 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1232,11 +1232,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar KeyboardActionListener.SUGGESTION_STRIP_COORDINATE); } - private static int getEditorActionId(EditorInfo editorInfo) { - if (editorInfo == null) return 0; - return (editorInfo.actionLabel != null) - ? editorInfo.actionId - : (editorInfo.imeOptions & EditorInfo.IME_MASK_ACTION); + private static int getActionId(Keyboard keyboard) { + return keyboard != null ? keyboard.mId.imeActionId() : EditorInfo.IME_ACTION_NONE; } private void performeEditorAction(int actionId) { @@ -1302,18 +1299,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mSubtypeSwitcher.switchToShortcutIME(); break; case Keyboard.CODE_ACTION_ENTER: - performeEditorAction(getEditorActionId(getCurrentInputEditorInfo())); + performeEditorAction(getActionId(switcher.getKeyboard())); break; - case Keyboard.CODE_TAB: - handleTab(); - // There are two cases for tab. Either we send a "next" event, that may change the - // focus but will never move the cursor. Or, we send a real tab keycode, which some - // applications may accept or ignore, and we don't know whether this will move the - // cursor or not. So actually, we don't really know. - // So to go with the safer option, we'd rather behave as if the user moved the - // cursor when they didn't than the opposite. We also expect that most applications - // will actually use tab only for focus movement. - // To sum it up: do not update mExpectingUpdateSelection here. + case Keyboard.CODE_ACTION_NEXT: + performeEditorAction(EditorInfo.IME_ACTION_NEXT); + break; + case Keyboard.CODE_ACTION_PREVIOUS: + EditorInfoCompatUtils.performEditorActionPrevious(getCurrentInputConnection()); break; default: mSpaceState = SPACE_STATE_NONE; @@ -1488,30 +1480,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } } - // TODO: Implement next and previous actions using other key code than tab's code. - private void handleTab() { - final int imeOptions = getCurrentInputEditorInfo().imeOptions; - if (!EditorInfoCompatUtils.hasFlagNavigateNext(imeOptions) - && !EditorInfoCompatUtils.hasFlagNavigatePrevious(imeOptions)) { - // TODO: This should be {@link #sendKeyCodePoint(int)}. - sendDownUpKeyEvents(KeyEvent.KEYCODE_TAB); - return; - } - - final InputConnection ic = getCurrentInputConnection(); - if (ic == null) - return; - - final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); - // True if keyboard is in either shift chording or manual shifted state. - final boolean isManualShifted = (keyboard != null && keyboard.isManualShifted()); - if (EditorInfoCompatUtils.hasFlagNavigateNext(imeOptions) && !isManualShifted) { - EditorInfoCompatUtils.performEditorActionNext(ic); - } else if (EditorInfoCompatUtils.hasFlagNavigatePrevious(imeOptions) && isManualShifted) { - EditorInfoCompatUtils.performEditorActionPrevious(ic); - } - } - // ic may be null private boolean maybeStripSpaceWhileInBatchEdit(final InputConnection ic, final int code, final int spaceState, final boolean isFromSuggestionStrip) { diff --git a/java/src/com/android/inputmethod/latin/XmlParseUtils.java b/java/src/com/android/inputmethod/latin/XmlParseUtils.java index d747a024c..e14c71cb5 100644 --- a/java/src/com/android/inputmethod/latin/XmlParseUtils.java +++ b/java/src/com/android/inputmethod/latin/XmlParseUtils.java @@ -27,8 +27,7 @@ public class XmlParseUtils { @SuppressWarnings("serial") public static class ParseException extends XmlPullParserException { public ParseException(String msg, XmlPullParser parser) { - super(msg + " at line " + parser.getLineNumber() - + ", column " + parser.getColumnNumber()); + super(msg + " at " + parser.getPositionDescription()); } } -- cgit v1.2.3-83-g751a From 660776e09b9a3b321074a94721d901a035ca1b9f Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Sat, 17 Mar 2012 00:50:51 +0900 Subject: Small performance improvement by removing interface accesses. Change-Id: I6d91f3b086470b79306dbe2874db9748b9e0eb5f --- .../src/com/android/inputmethod/keyboard/KeyboardSet.java | 5 ++--- .../src/com/android/inputmethod/latin/AutoCorrection.java | 14 +++++++------- .../android/inputmethod/latin/BinaryDictionaryGetter.java | 5 ++--- .../android/inputmethod/latin/DictionaryCollection.java | 3 +-- .../com/android/inputmethod/latin/DictionaryFactory.java | 6 +++--- java/src/com/android/inputmethod/latin/LatinIME.java | 3 +-- .../src/com/android/inputmethod/latin/LatinImeLogger.java | 2 -- .../src/com/android/inputmethod/latin/SettingsValues.java | 2 -- java/src/com/android/inputmethod/latin/Suggest.java | 15 +++++++-------- .../src/com/android/inputmethod/latin/SuggestedWords.java | 12 +++++------- java/src/com/android/inputmethod/latin/XmlParseUtils.java | 4 ++++ .../inputmethod/latin/suggestions/SuggestionsView.java | 9 ++++----- 12 files changed, 36 insertions(+), 44 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/XmlParseUtils.java') diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java index 680ff0d25..52096c843 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java @@ -42,7 +42,6 @@ import java.io.IOException; import java.lang.ref.SoftReference; import java.util.HashMap; import java.util.Locale; -import java.util.Map; /** * This class represents a set of keyboards. Each of them represents a different keyboard @@ -75,7 +74,7 @@ public class KeyboardSet { } public static class KeysCache { - private final Map mMap; + private final HashMap mMap; public KeysCache() { mMap = new HashMap(); @@ -108,7 +107,7 @@ public class KeyboardSet { int mOrientation; int mWidth; // KeyboardSet element id to keyboard layout XML id map. - final Map mKeyboardSetElementIdToXmlIdMap = + final HashMap mKeyboardSetElementIdToXmlIdMap = new HashMap(); Params() {} } diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/AutoCorrection.java index 9c35f8f6f..ef88f9906 100644 --- a/java/src/com/android/inputmethod/latin/AutoCorrection.java +++ b/java/src/com/android/inputmethod/latin/AutoCorrection.java @@ -20,7 +20,7 @@ import android.text.TextUtils; import android.util.Log; import java.util.ArrayList; -import java.util.Map; +import java.util.HashMap; public class AutoCorrection { private static final boolean DBG = LatinImeLogger.sDBG; @@ -30,7 +30,7 @@ public class AutoCorrection { // Purely static class: can't instantiate. } - public static CharSequence computeAutoCorrectionWord(Map dictionaries, + public static CharSequence computeAutoCorrectionWord(HashMap dictionaries, WordComposer wordComposer, ArrayList suggestions, int[] sortedScores, CharSequence consideredWord, double autoCorrectionThreshold, CharSequence whitelistedWord) { @@ -47,7 +47,7 @@ public class AutoCorrection { } public static boolean isValidWord( - Map dictionaries, CharSequence word, boolean ignoreCase) { + HashMap dictionaries, CharSequence word, boolean ignoreCase) { if (TextUtils.isEmpty(word)) { return false; } @@ -72,7 +72,7 @@ public class AutoCorrection { } public static boolean allowsToBeAutoCorrected( - Map dictionaries, CharSequence word, boolean ignoreCase) { + HashMap dictionaries, CharSequence word, boolean ignoreCase) { final WhitelistDictionary whitelistDictionary = (WhitelistDictionary)dictionaries.get(Suggest.DICT_KEY_WHITELIST); // If "word" is in the whitelist dictionary, it should not be auto corrected. @@ -87,9 +87,9 @@ public class AutoCorrection { return whiteListedWord != null; } - private static boolean hasAutoCorrectionForConsideredWord(Map dictionaries, - WordComposer wordComposer, ArrayList suggestions, - CharSequence consideredWord) { + private static boolean hasAutoCorrectionForConsideredWord( + HashMap dictionaries, WordComposer wordComposer, + ArrayList suggestions, CharSequence consideredWord) { if (TextUtils.isEmpty(consideredWord)) return false; return wordComposer.size() > 1 && suggestions.size() > 0 && !allowsToBeAutoCorrected(dictionaries, consideredWord, false); diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index 79441c557..1c24cd11d 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -25,7 +25,6 @@ import android.util.Log; import java.io.File; import java.util.ArrayList; -import java.util.List; import java.util.Locale; /** @@ -264,9 +263,9 @@ class BinaryDictionaryGetter { * - Gets a file name from the fallback resource passed as an argument. * If that fails: * - Returns null. - * @return The address of a valid file, or null. + * @return The list of addresses of valid dictionary files, or null. */ - public static List getDictionaryFiles(final Locale locale, + public static ArrayList getDictionaryFiles(final Locale locale, final Context context, final int fallbackResId) { // cacheWordListsFromContentProvider returns the list of files it copied to local diff --git a/java/src/com/android/inputmethod/latin/DictionaryCollection.java b/java/src/com/android/inputmethod/latin/DictionaryCollection.java index c19a5a718..5de770a4a 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryCollection.java +++ b/java/src/com/android/inputmethod/latin/DictionaryCollection.java @@ -22,7 +22,6 @@ import android.util.Log; import java.util.Collection; import java.util.Collections; -import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; /** @@ -30,7 +29,7 @@ import java.util.concurrent.CopyOnWriteArrayList; */ public class DictionaryCollection extends Dictionary { private final String TAG = DictionaryCollection.class.getSimpleName(); - protected final List mDictionaries; + protected final CopyOnWriteArrayList mDictionaries; public DictionaryCollection() { mDictionaries = new CopyOnWriteArrayList(); diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java index 7a81f7bd5..77c685c50 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java @@ -22,8 +22,8 @@ import android.content.res.Resources; import android.util.Log; import java.io.File; +import java.util.ArrayList; import java.util.LinkedList; -import java.util.List; import java.util.Locale; /** @@ -52,8 +52,8 @@ public class DictionaryFactory { return new DictionaryCollection(createBinaryDictionary(context, fallbackResId, locale)); } - final List dictList = new LinkedList(); - final List assetFileList = + final LinkedList dictList = new LinkedList(); + final ArrayList assetFileList = BinaryDictionaryGetter.getDictionaryFiles(locale, context, fallbackResId); if (null != assetFileList) { for (final AssetFileAddress f : assetFileList) { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 234a501de..d5cd35db6 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -73,7 +73,6 @@ import com.android.inputmethod.latin.suggestions.SuggestionsView; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; -import java.util.List; import java.util.Locale; /** @@ -919,7 +918,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return; } - final List applicationSuggestedWords = + final ArrayList applicationSuggestedWords = SuggestedWords.getFromApplicationSpecifiedCompletions( applicationSpecifiedCompletions); final SuggestedWords suggestedWords = new SuggestedWords( diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java index 5390ee39e..683dafa86 100644 --- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java +++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java @@ -22,8 +22,6 @@ import android.view.inputmethod.EditorInfo; import com.android.inputmethod.keyboard.Keyboard; -import java.util.List; - public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChangeListener { public static boolean sDBG = false; diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 4346a3671..020b57caf 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -30,8 +30,6 @@ import com.android.inputmethod.keyboard.internal.KeySpecParser; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.List; import java.util.Locale; public class SettingsValues { diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 69754d769..08f0e425b 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -30,15 +30,12 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Locale; -import java.util.Map; -import java.util.Set; /** * This class loads a dictionary and provides a list of suggestions for a given sequence of * characters. This includes corrections and completions. */ public class Suggest implements Dictionary.WordCallback { - public static final String TAG = Suggest.class.getSimpleName(); public static final int APPROX_MAX_WORD_LENGTH = 32; @@ -87,8 +84,10 @@ public class Suggest implements Dictionary.WordCallback { private Dictionary mMainDict; private ContactsDictionary mContactsDict; private WhitelistDictionary mWhiteListDictionary; - private final Map mUnigramDictionaries = new HashMap(); - private final Map mBigramDictionaries = new HashMap(); + private final HashMap mUnigramDictionaries = + new HashMap(); + private final HashMap mBigramDictionaries = + new HashMap(); private int mPrefMaxSuggestions = 18; @@ -142,7 +141,7 @@ public class Suggest implements Dictionary.WordCallback { initWhitelistAndAutocorrectAndPool(context, locale); } - private static void addOrReplaceDictionary(Map dictionaries, String key, + private static void addOrReplaceDictionary(HashMap dictionaries, String key, Dictionary dict) { final Dictionary oldDict = (dict == null) ? dictionaries.remove(key) @@ -177,7 +176,7 @@ public class Suggest implements Dictionary.WordCallback { return mContactsDict; } - public Map getUnigramDictionaries() { + public HashMap getUnigramDictionaries() { return mUnigramDictionaries; } @@ -563,7 +562,7 @@ public class Suggest implements Dictionary.WordCallback { } public void close() { - final Set dictionaries = new HashSet(); + final HashSet dictionaries = new HashSet(); dictionaries.addAll(mUnigramDictionaries.values()); dictionaries.addAll(mBigramDictionaries.values()); for (final Dictionary dictionary : dictionaries) { diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index b63bc6c29..ef8e58e0c 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -21,22 +21,20 @@ import android.view.inputmethod.CompletionInfo; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashSet; -import java.util.List; public class SuggestedWords { public static final SuggestedWords EMPTY = new SuggestedWords( - Collections.emptyList(), false, false, false, false, false); + new ArrayList(0), false, false, false, false, false); public final boolean mTypedWordValid; public final boolean mHasAutoCorrectionCandidate; public final boolean mIsPunctuationSuggestions; public final boolean mAllowsToBeAutoCorrected; public final boolean mIsObsoleteSuggestions; - private final List mSuggestedWordInfoList; + private final ArrayList mSuggestedWordInfoList; - public SuggestedWords(final List suggestedWordInfoList, + public SuggestedWords(final ArrayList suggestedWordInfoList, final boolean typedWordValid, final boolean hasAutoCorrectionCandidate, final boolean allowsToBeAutoCorrected, @@ -82,7 +80,7 @@ public class SuggestedWords { } public static ArrayList getFromCharSequenceList( - final List wordList) { + final ArrayList wordList) { final ArrayList result = new ArrayList(); for (CharSequence word : wordList) { if (null != word) result.add(new SuggestedWordInfo(word)); @@ -90,7 +88,7 @@ public class SuggestedWords { return result; } - public static List getFromApplicationSpecifiedCompletions( + public static ArrayList getFromApplicationSpecifiedCompletions( final CompletionInfo[] infos) { final ArrayList result = new ArrayList(); for (CompletionInfo info : infos) { diff --git a/java/src/com/android/inputmethod/latin/XmlParseUtils.java b/java/src/com/android/inputmethod/latin/XmlParseUtils.java index e14c71cb5..481cdfa47 100644 --- a/java/src/com/android/inputmethod/latin/XmlParseUtils.java +++ b/java/src/com/android/inputmethod/latin/XmlParseUtils.java @@ -24,6 +24,10 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; public class XmlParseUtils { + private XmlParseUtils() { + // This utility class is not publicly instantiable. + } + @SuppressWarnings("serial") public static class ParseException extends XmlPullParserException { public ParseException(String msg, XmlPullParser parser) { diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java index d3c3afb73..286bf0aea 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java @@ -66,7 +66,6 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.Utils; import java.util.ArrayList; -import java.util.List; public class SuggestionsView extends RelativeLayout implements OnClickListener, OnLongClickListener { @@ -144,9 +143,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, public final float mMinMoreSuggestionsWidth; public final int mMoreSuggestionsBottomGap; - private final List mWords; - private final List mDividers; - private final List mInfos; + private final ArrayList mWords; + private final ArrayList mDividers; + private final ArrayList mInfos; private final int mColorValidTypedWord; private final int mColorTypedWord; @@ -174,7 +173,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, private final TextView mHintToSaveView; public SuggestionsViewParams(Context context, AttributeSet attrs, int defStyle, - List words, List dividers, List infos) { + ArrayList words, ArrayList dividers, ArrayList infos) { mWords = words; mDividers = dividers; mInfos = infos; -- cgit v1.2.3-83-g751a