aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java72
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java96
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyDetector.java41
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java46
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardId.java8
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSet.java23
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java25
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java3
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java125
-rw-r--r--java/src/com/android/inputmethod/keyboard/MiniKeyboard.java5
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java42
-rw-r--r--java/src/com/android/inputmethod/keyboard/ProximityInfo.java50
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java (renamed from java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java)148
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java62
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java26
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java70
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java42
-rw-r--r--java/src/com/android/inputmethod/latin/SettingsValues.java45
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java65
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java4
20 files changed, 569 insertions, 429 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
index 3b4149d7f..18a4bfbfc 100644
--- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
+++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
@@ -38,12 +38,6 @@ public class KeyCodeDescriptionMapper {
// Map of key codes to spoken description resource IDs
private final HashMap<Integer, Integer> mKeyCodeMap;
- // Map of shifted key codes to spoken description resource IDs
- private final HashMap<Integer, Integer> mShiftedKeyCodeMap;
-
- // Map of shift-locked key codes to spoken description resource IDs
- private final HashMap<Integer, Integer> mShiftLockedKeyCodeMap;
-
public static void init() {
sInstance.initInternal();
}
@@ -55,8 +49,6 @@ public class KeyCodeDescriptionMapper {
private KeyCodeDescriptionMapper() {
mKeyLabelMap = new HashMap<CharSequence, Integer>();
mKeyCodeMap = new HashMap<Integer, Integer>();
- mShiftedKeyCodeMap = new HashMap<Integer, Integer>();
- mShiftLockedKeyCodeMap = new HashMap<Integer, Integer>();
}
private void initInternal() {
@@ -64,31 +56,8 @@ public class KeyCodeDescriptionMapper {
mKeyLabelMap.put(":-)", R.string.spoken_description_smiley);
// Symbols that most TTS engines can't speak
- mKeyCodeMap.put((int) '.', R.string.spoken_description_period);
- mKeyCodeMap.put((int) ',', R.string.spoken_description_comma);
- mKeyCodeMap.put((int) '(', R.string.spoken_description_left_parenthesis);
- mKeyCodeMap.put((int) ')', R.string.spoken_description_right_parenthesis);
- mKeyCodeMap.put((int) ':', R.string.spoken_description_colon);
- mKeyCodeMap.put((int) ';', R.string.spoken_description_semicolon);
- mKeyCodeMap.put((int) '!', R.string.spoken_description_exclamation_mark);
- mKeyCodeMap.put((int) '?', R.string.spoken_description_question_mark);
- mKeyCodeMap.put((int) '\"', R.string.spoken_description_double_quote);
- mKeyCodeMap.put((int) '\'', R.string.spoken_description_single_quote);
- mKeyCodeMap.put((int) '*', R.string.spoken_description_star);
- mKeyCodeMap.put((int) '#', R.string.spoken_description_pound);
mKeyCodeMap.put((int) ' ', R.string.spoken_description_space);
- // Non-ASCII symbols (must use escape codes!)
- mKeyCodeMap.put((int) '\u2022', R.string.spoken_description_dot);
- mKeyCodeMap.put((int) '\u221A', R.string.spoken_description_square_root);
- mKeyCodeMap.put((int) '\u03C0', R.string.spoken_description_pi);
- mKeyCodeMap.put((int) '\u0394', R.string.spoken_description_delta);
- mKeyCodeMap.put((int) '\u2122', R.string.spoken_description_trademark);
- mKeyCodeMap.put((int) '\u2105', R.string.spoken_description_care_of);
- mKeyCodeMap.put((int) '\u2026', R.string.spoken_description_ellipsis);
- mKeyCodeMap.put((int) '\u201E', R.string.spoken_description_low_double_quote);
- mKeyCodeMap.put((int) '\uFF0A', R.string.spoken_description_star);
-
// Special non-character codes defined in Keyboard
mKeyCodeMap.put(Keyboard.CODE_DELETE, R.string.spoken_description_delete);
mKeyCodeMap.put(Keyboard.CODE_ENTER, R.string.spoken_description_return);
@@ -97,12 +66,6 @@ public class KeyCodeDescriptionMapper {
mKeyCodeMap.put(Keyboard.CODE_SHORTCUT, R.string.spoken_description_mic);
mKeyCodeMap.put(Keyboard.CODE_SWITCH_ALPHA_SYMBOL, R.string.spoken_description_to_symbol);
mKeyCodeMap.put(Keyboard.CODE_TAB, R.string.spoken_description_tab);
-
- // Shifted versions of non-character codes defined in Keyboard
- mShiftedKeyCodeMap.put(Keyboard.CODE_SHIFT, R.string.spoken_description_shift_shifted);
-
- // Shift-locked versions of non-character codes defined in Keyboard
- mShiftLockedKeyCodeMap.put(Keyboard.CODE_SHIFT, R.string.spoken_description_caps_lock);
}
/**
@@ -126,12 +89,18 @@ public class KeyCodeDescriptionMapper {
*/
public CharSequence getDescriptionForKey(Context context, Keyboard keyboard, Key key,
boolean shouldObscure) {
- if (key.mCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
+ final int code = key.mCode;
+
+ if (code == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
final CharSequence description = getDescriptionForSwitchAlphaSymbol(context, keyboard);
if (description != null)
return description;
}
+ if (code == Keyboard.CODE_SHIFT) {
+ return getDescriptionForShiftKey(context, keyboard);
+ }
+
if (!TextUtils.isEmpty(key.mLabel)) {
final String label = key.mLabel.toString().trim();
@@ -176,6 +145,27 @@ public class KeyCodeDescriptionMapper {
}
/**
+ * Returns a context-sensitive description of the "Shift" key.
+ *
+ * @param context The package's context.
+ * @param keyboard The keyboard on which the key resides.
+ * @return A context-sensitive description of the "Shift" key.
+ */
+ private CharSequence getDescriptionForShiftKey(Context context, Keyboard keyboard) {
+ final int resId;
+
+ if (keyboard.isShiftLocked()) {
+ resId = R.string.spoken_description_caps_lock;
+ } else if (keyboard.isShiftedOrShiftLocked()) {
+ resId = R.string.spoken_description_shift_shifted;
+ } else {
+ resId = R.string.spoken_description_shift;
+ }
+
+ return context.getString(resId);
+ }
+
+ /**
* Returns a localized character sequence describing what will happen when
* the specified key is pressed based on its key code.
* <p>
@@ -200,12 +190,6 @@ public class KeyCodeDescriptionMapper {
boolean shouldObscure) {
final int code = key.mCode;
- if (keyboard.isShiftLocked() && mShiftLockedKeyCodeMap.containsKey(code)) {
- return context.getString(mShiftLockedKeyCodeMap.get(code));
- } else if (keyboard.isShiftedOrShiftLocked() && mShiftedKeyCodeMap.containsKey(code)) {
- return context.getString(mShiftedKeyCodeMap.get(code));
- }
-
// If the key description should be obscured, now is the time to do it.
final boolean isDefinedNonCtrl = Character.isDefined(code) && !Character.isISOControl(code);
if (shouldObscure && isDefinedNonCtrl) {
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index d4419aeaf..a6c9fd485 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -28,16 +28,15 @@ import android.util.Xml;
import com.android.inputmethod.keyboard.internal.KeyStyles;
import com.android.inputmethod.keyboard.internal.KeyStyles.KeyStyle;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
-import com.android.inputmethod.keyboard.internal.MoreKeySpecParser;
+import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.XmlParseUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
/**
* Class for describing the position and characteristics of a single key in the keyboard.
@@ -120,6 +119,7 @@ public class Key {
private static final int ACTION_FLAGS_IS_REPEATABLE = 0x01;
private static final int ACTION_FLAGS_NO_KEY_PREVIEW = 0x02;
private static final int ACTION_FLAGS_ALT_CODE_WHILE_TYPING = 0x04;
+ private static final int ACTION_FLAGS_ENABLE_LONG_PRESS = 0x08;
private final int mHashCode;
@@ -128,47 +128,8 @@ public class Key {
/** Key is enabled and responds on press */
private boolean mEnabled = true;
- // RTL parenthesis character swapping map.
- private static final Map<Integer, Integer> sRtlParenthesisMap = new HashMap<Integer, Integer>();
-
- static {
- // The all letters need to be mirrored are found at
- // http://www.unicode.org/Public/6.0.0/ucd/extracted/DerivedBinaryProperties.txt
- addRtlParenthesisPair('(', ')');
- addRtlParenthesisPair('[', ']');
- addRtlParenthesisPair('{', '}');
- addRtlParenthesisPair('<', '>');
- // \u00ab: LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
- // \u00bb: RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
- addRtlParenthesisPair('\u00ab', '\u00bb');
- // \u2039: SINGLE LEFT-POINTING ANGLE QUOTATION MARK
- // \u203a: SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
- addRtlParenthesisPair('\u2039', '\u203a');
- // \u2264: LESS-THAN OR EQUAL TO
- // \u2265: GREATER-THAN OR EQUAL TO
- addRtlParenthesisPair('\u2264', '\u2265');
- }
-
- private static void addRtlParenthesisPair(int left, int right) {
- sRtlParenthesisMap.put(left, right);
- sRtlParenthesisMap.put(right, left);
- }
-
- public static int getRtlParenthesisCode(int code, boolean isRtl) {
- if (isRtl && sRtlParenthesisMap.containsKey(code)) {
- return sRtlParenthesisMap.get(code);
- } else {
- return code;
- }
- }
-
- private static int getCode(Resources res, Keyboard.Params params, String moreKeySpec) {
- return getRtlParenthesisCode(
- MoreKeySpecParser.getCode(res, moreKeySpec), params.mIsRtlKeyboard);
- }
-
private static Drawable getIcon(Keyboard.Params params, String moreKeySpec) {
- final int iconAttrId = MoreKeySpecParser.getIconAttrId(moreKeySpec);
+ final int iconAttrId = KeySpecParser.getIconAttrId(moreKeySpec);
if (iconAttrId == KeyboardIconsSet.ICON_UNDEFINED) {
return null;
} else {
@@ -181,8 +142,9 @@ public class Key {
*/
public Key(Resources res, Keyboard.Params params, String moreKeySpec,
int x, int y, int width, int height) {
- this(params, MoreKeySpecParser.getLabel(moreKeySpec), null, getIcon(params, moreKeySpec),
- getCode(res, params, moreKeySpec), MoreKeySpecParser.getOutputText(moreKeySpec),
+ this(params, KeySpecParser.getLabel(moreKeySpec), null, getIcon(params, moreKeySpec),
+ KeySpecParser.getCode(res, moreKeySpec),
+ KeySpecParser.getOutputText(moreKeySpec),
x, y, width, height);
}
@@ -265,7 +227,6 @@ public class Key {
mBackgroundType = style.getInt(keyAttr,
R.styleable.Keyboard_Key_backgroundType, BACKGROUND_TYPE_NORMAL);
- mActionFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyActionFlags, 0);
final KeyboardIconsSet iconsSet = params.mIconsSet;
mVisualInsetsLeft = (int) Keyboard.Builder.getDimensionOrFraction(keyAttr,
@@ -282,17 +243,19 @@ public class Key {
mLabelFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags, 0);
final boolean preserveCase = (mLabelFlags & LABEL_FLAGS_PRESERVE_CASE) != 0;
-
+ int actionFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyActionFlags, 0);
final String[] additionalMoreKeys = style.getStringArray(
keyAttr, R.styleable.Keyboard_Key_additionalMoreKeys);
- final String[] moreKeys = MoreKeySpecParser.insertAddtionalMoreKeys(style.getStringArray(
+ final String[] moreKeys = KeySpecParser.insertAddtionalMoreKeys(style.getStringArray(
keyAttr, R.styleable.Keyboard_Key_moreKeys), additionalMoreKeys);
if (moreKeys != null) {
+ actionFlags |= ACTION_FLAGS_ENABLE_LONG_PRESS;
for (int i = 0; i < moreKeys.length; i++) {
moreKeys[i] = adjustCaseOfStringForKeyboardId(
moreKeys[i], preserveCase, params.mId);
}
}
+ mActionFlags = actionFlags;
mMoreKeys = moreKeys;
mMaxMoreKeysColumn = style.getInt(keyAttr,
R.styleable.Keyboard_Key_maxMoreKeysColumn, params.mMaxMiniKeyboardColumn);
@@ -308,17 +271,15 @@ public class Key {
// Choose the first letter of the label as primary code if not specified.
if (code == Keyboard.CODE_UNSPECIFIED && TextUtils.isEmpty(outputText)
&& !TextUtils.isEmpty(mLabel)) {
- if (mLabel.codePointCount(0, mLabel.length()) == 1) {
- final int activatedCode;
+ if (Utils.codePointCount(mLabel) == 1) {
// Use the first letter of the hint label if shiftedLetterActivated flag is
// specified.
if (hasShiftedLetterHint() && isShiftedLetterActivated()
&& !TextUtils.isEmpty(mHintLabel)) {
- activatedCode = mHintLabel.codePointAt(0);
+ mCode = mHintLabel.codePointAt(0);
} else {
- activatedCode = mLabel.codePointAt(0);
+ mCode = mLabel.codePointAt(0);
}
- mCode = getRtlParenthesisCode(activatedCode, params.mIsRtlKeyboard);
} else {
// In some locale and case, the character might be represented by multiple code
// points, such as upper case Eszett of German alphabet.
@@ -348,7 +309,7 @@ public class Key {
if (!Keyboard.isLetterCode(code) || preserveCase) return code;
final String text = new String(new int[] { code } , 0, 1);
final String casedText = adjustCaseOfStringForKeyboardId(text, preserveCase, id);
- return casedText.codePointCount(0, casedText.length()) == 1
+ return Utils.codePointCount(casedText) == 1
? casedText.codePointAt(0) : Keyboard.CODE_UNSPECIFIED;
}
@@ -403,8 +364,8 @@ public class Key {
&& o.mCode == mCode
&& TextUtils.equals(o.mLabel, mLabel)
&& TextUtils.equals(o.mHintLabel, mHintLabel)
- && o.mIconAttrId != mIconAttrId
- && o.mBackgroundType != mBackgroundType;
+ && o.mIconAttrId == mIconAttrId
+ && o.mBackgroundType == mBackgroundType;
}
@Override
@@ -419,11 +380,20 @@ public class Key {
@Override
public String toString() {
- String top = Keyboard.printableCode(mCode);
- if (mLabel != null && mLabel.length() != 1) {
- top += "/\"" + mLabel + '"';
+ return String.format("%s/%s %d,%d %dx%d %s/%s/%s",
+ Keyboard.printableCode(mCode), mLabel, mX, mY, mWidth, mHeight, mHintLabel,
+ KeyboardIconsSet.getIconName(mIconAttrId), backgroundName(mBackgroundType));
+ }
+
+ private static String backgroundName(int backgroundType) {
+ switch (backgroundType) {
+ case BACKGROUND_TYPE_NORMAL: return "normal";
+ case BACKGROUND_TYPE_FUNCTIONAL: return "functional";
+ case BACKGROUND_TYPE_ACTION: return "action";
+ case BACKGROUND_TYPE_STICKY_OFF: return "stickyOff";
+ case BACKGROUND_TYPE_STICKY_ON: return "stickyOn";
+ default: return null;
}
- return String.format("%s %d,%d", top, mX, mY);
}
public void markAsLeftEdge(Keyboard.Params params) {
@@ -466,6 +436,12 @@ public class Key {
return (mActionFlags & ACTION_FLAGS_ALT_CODE_WHILE_TYPING) != 0;
}
+ public boolean isLongPressEnabled() {
+ // We need not start long press timer on the key which has activated shifted letter.
+ return (mActionFlags & ACTION_FLAGS_ENABLE_LONG_PRESS) != 0
+ && (mLabelFlags & LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED) == 0;
+ }
+
public Typeface selectTypeface(Typeface defaultTypeface) {
// TODO: Handle "bold" here too?
if ((mLabelFlags & LABEL_FLAGS_FONT_NORMAL) != 0) {
diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java
index 0d271625b..bff491ffd 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java
@@ -19,12 +19,14 @@ package com.android.inputmethod.keyboard;
import android.util.Log;
import java.util.Arrays;
+import java.util.List;
public class KeyDetector {
private static final String TAG = KeyDetector.class.getSimpleName();
private static final boolean DEBUG = false;
public static final int NOT_A_CODE = -1;
+ private static final int ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE = 2;
private final int mKeyHysteresisDistanceSquared;
@@ -154,8 +156,9 @@ public class KeyDetector {
return distances.length;
}
- private void getNearbyKeyCodes(final int[] allCodes) {
+ private void getNearbyKeyCodes(final int primaryCode, final int[] allCodes) {
final Key[] neighborKeys = mNeighborKeys;
+ final int maxCodesSize = allCodes.length;
// allCodes[0] should always have the key code even if it is a non-letter key.
if (neighborKeys[0] == null) {
@@ -164,7 +167,7 @@ public class KeyDetector {
}
int numCodes = 0;
- for (int j = 0; j < neighborKeys.length && numCodes < allCodes.length; j++) {
+ for (int j = 0; j < neighborKeys.length && numCodes < maxCodesSize; j++) {
final Key key = neighborKeys[j];
if (key == null)
break;
@@ -174,6 +177,38 @@ public class KeyDetector {
continue;
allCodes[numCodes++] = code;
}
+ if (maxCodesSize <= numCodes) {
+ return;
+ }
+ if (primaryCode != NOT_A_CODE) {
+ final List<Integer> additionalChars =
+ mKeyboard.getAdditionalProximityChars().get(primaryCode);
+ if (additionalChars == null || additionalChars.size() == 0) {
+ return;
+ }
+ int currentCodesSize = numCodes;
+ allCodes[numCodes++] = ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE;
+ if (maxCodesSize <= numCodes) {
+ return;
+ }
+ // TODO: This is O(N^2). Assuming additionalChars.size() is up to 4 or 5.
+ for (int i = 0; i < additionalChars.size(); ++i) {
+ final int additionalChar = additionalChars.get(i);
+ boolean contains = false;
+ for (int j = 0; j < currentCodesSize; ++j) {
+ if (additionalChar == allCodes[j]) {
+ contains = true;
+ break;
+ }
+ }
+ if (!contains) {
+ allCodes[numCodes++] = additionalChar;
+ if (maxCodesSize <= numCodes) {
+ return;
+ }
+ }
+ }
+ }
}
/**
@@ -205,7 +240,7 @@ public class KeyDetector {
}
if (allCodes != null && allCodes.length > 0) {
- getNearbyKeyCodes(allCodes);
+ getNearbyKeyCodes(primaryKey != null ? primaryKey.mCode : NOT_A_CODE, allCodes);
if (DEBUG) {
Log.d(TAG, "x=" + x + " y=" + y
+ " primary=" + printableCode(primaryKey)
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 8832d8fd1..10e0a5b01 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -20,6 +20,7 @@ import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
+import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -38,10 +39,12 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -92,7 +95,6 @@ public class Keyboard {
*/
public static final int CODE_SHIFT = -1;
public static final int CODE_SWITCH_ALPHA_SYMBOL = -2;
- public static final int CODE_CAPSLOCK = -3;
public static final int CODE_OUTPUT_TEXT = -4;
public static final int CODE_DELETE = -5;
public static final int CODE_SETTINGS = -6;
@@ -122,9 +124,6 @@ public class Keyboard {
/** Maximum column for mini keyboard */
public final int mMaxMiniKeyboardColumn;
- /** True if Right-To-Left keyboard */
- public final boolean mIsRtlKeyboard;
-
/** List of keys and icons in this keyboard */
public final Set<Key> mKeys;
public final Set<Key> mShiftKeys;
@@ -134,6 +133,8 @@ public class Keyboard {
private final ProximityInfo mProximityInfo;
+ public final Map<Integer, List<Integer>> mAdditionalProximityChars;
+
public Keyboard(Params params) {
mId = params.mId;
mThemeId = params.mThemeId;
@@ -141,7 +142,6 @@ public class Keyboard {
mOccupiedWidth = params.mOccupiedWidth;
mMostCommonKeyHeight = params.mMostCommonKeyHeight;
mMostCommonKeyWidth = params.mMostCommonKeyWidth;
- mIsRtlKeyboard = params.mIsRtlKeyboard;
mMoreKeysTemplate = params.mMoreKeysTemplate;
mMaxMiniKeyboardColumn = params.mMaxMiniKeyboardColumn;
@@ -151,10 +151,12 @@ public class Keyboard {
mKeys = Collections.unmodifiableSet(params.mKeys);
mShiftKeys = Collections.unmodifiableSet(params.mShiftKeys);
mIconsSet = params.mIconsSet;
+ mAdditionalProximityChars = params.mAdditionalProximityChars;
mProximityInfo = new ProximityInfo(
params.GRID_WIDTH, params.GRID_HEIGHT, mOccupiedWidth, mOccupiedHeight,
- mMostCommonKeyWidth, mMostCommonKeyHeight, mKeys, params.mTouchPositionCorrection);
+ mMostCommonKeyWidth, mMostCommonKeyHeight, mKeys, params.mTouchPositionCorrection,
+ params.mAdditionalProximityChars);
}
public ProximityInfo getProximityInfo() {
@@ -223,7 +225,6 @@ public class Keyboard {
public int mHorizontalGap;
public int mVerticalGap;
- public boolean mIsRtlKeyboard;
public int mMoreKeysTemplate;
public int mMaxMiniKeyboardColumn;
@@ -233,6 +234,9 @@ public class Keyboard {
public final Set<Key> mKeys = new HashSet<Key>();
public final Set<Key> mShiftKeys = new HashSet<Key>();
public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet();
+ // TODO: Should be in Key instead of Keyboard.Params?
+ public final Map<Integer, List<Integer>> mAdditionalProximityChars =
+ new HashMap<Integer, List<Integer>>();
public KeyboardSet.KeysCache mKeysCache;
@@ -364,13 +368,17 @@ public class Keyboard {
return mProximityInfo.getNearestKeys(adjustedX, adjustedY);
}
+ public Map<Integer, List<Integer>> getAdditionalProximityChars() {
+ return mAdditionalProximityChars;
+ }
+
public static String printableCode(int code) {
switch (code) {
case CODE_SHIFT: return "shift";
case CODE_SWITCH_ALPHA_SYMBOL: return "symbol";
- case CODE_CAPSLOCK: return "capslock";
case CODE_OUTPUT_TEXT: return "text";
case CODE_DELETE: return "delete";
+ case CODE_SETTINGS: return "settings";
case CODE_SHORTCUT: return "shortcut";
case CODE_UNSPECIFIED: return "unspec";
case CODE_TAB: return "tab";
@@ -620,6 +628,7 @@ public class Keyboard {
mParams = params;
setTouchPositionCorrectionData(context, params);
+ setAdditionalProximityChars(context, params);
params.GRID_WIDTH = res.getInteger(R.integer.config_keyboard_grid_width);
params.GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height);
@@ -642,6 +651,25 @@ public class Keyboard {
params.mTouchPositionCorrection.load(data);
}
+ private static void setAdditionalProximityChars(Context context, Params params) {
+ final String[] additionalChars =
+ context.getResources().getStringArray(R.array.additional_proximitychars);
+ int currentPrimaryIndex = 0;
+ for (int i = 0; i < additionalChars.length; ++i) {
+ final String additionalChar = additionalChars[i];
+ if (TextUtils.isEmpty(additionalChar)) {
+ currentPrimaryIndex = 0;
+ } else if (currentPrimaryIndex == 0) {
+ currentPrimaryIndex = additionalChar.charAt(0);
+ params.mAdditionalProximityChars.put(
+ currentPrimaryIndex, new ArrayList<Integer>());
+ } else if (currentPrimaryIndex != 0) {
+ final int c = additionalChar.charAt(0);
+ params.mAdditionalProximityChars.get(currentPrimaryIndex).add(c);
+ }
+ }
+ }
+
public void setAutoGenerate(KeyboardSet.KeysCache keysCache) {
mParams.mKeysCache = keysCache;
}
@@ -740,8 +768,6 @@ public class Keyboard {
R.styleable.Keyboard_rowHeight, params.mBaseHeight,
params.mBaseHeight / DEFAULT_KEYBOARD_ROWS);
- params.mIsRtlKeyboard = keyboardAttr.getBoolean(
- R.styleable.Keyboard_isRtlKeyboard, false);
params.mMoreKeysTemplate = keyboardAttr.getResourceId(
R.styleable.Keyboard_moreKeysTemplate, 0);
params.mMaxMiniKeyboardColumn = keyAttr.getInt(
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
index 997b952de..0837e17da 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
@@ -46,7 +46,7 @@ public class KeyboardId {
public static final int ELEMENT_SYMBOLS = 5;
public static final int ELEMENT_SYMBOLS_SHIFTED = 6;
public static final int ELEMENT_PHONE = 7;
- public static final int ELEMENT_PHONE_SHIFTED = 8;
+ public static final int ELEMENT_PHONE_SYMBOLS = 8;
public static final int ELEMENT_NUMBER = 9;
private static final int F2KEY_MODE_NONE = 0;
@@ -145,11 +145,11 @@ public class KeyboardId {
}
public boolean isPhoneKeyboard() {
- return mElementId == ELEMENT_PHONE || mElementId == ELEMENT_PHONE_SHIFTED;
+ return mElementId == ELEMENT_PHONE || mElementId == ELEMENT_PHONE_SYMBOLS;
}
public boolean isPhoneShiftKeyboard() {
- return mElementId == ELEMENT_PHONE_SHIFTED;
+ return mElementId == ELEMENT_PHONE_SYMBOLS;
}
public boolean navigateAction() {
@@ -237,7 +237,7 @@ public class KeyboardId {
case ELEMENT_SYMBOLS: return "symbols";
case ELEMENT_SYMBOLS_SHIFTED: return "symbolsShifted";
case ELEMENT_PHONE: return "phone";
- case ELEMENT_PHONE_SHIFTED: return "phoneShifted";
+ case ELEMENT_PHONE_SYMBOLS: return "phoneSymbols";
case ELEMENT_NUMBER: return "number";
default: return null;
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
index d35948bad..82eaa1d17 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
@@ -57,7 +57,10 @@ public class KeyboardSet {
private final Context mContext;
private final Params mParams;
- private final KeysCache mKeysCache = new KeysCache();
+
+ private static final HashMap<KeyboardId, SoftReference<Keyboard>> sKeyboardCache =
+ new HashMap<KeyboardId, SoftReference<Keyboard>>();
+ private static final KeysCache sKeysCache = new KeysCache();
public static class KeyboardSetException extends RuntimeException {
public final KeyboardId mKeyboardId;
@@ -74,6 +77,10 @@ public class KeyboardSet {
mMap = new HashMap<Key, Key>();
}
+ public void clear() {
+ mMap.clear();
+ }
+
public Key get(Key key) {
final Key existingKey = mMap.get(key);
if (existingKey != null) {
@@ -103,11 +110,9 @@ public class KeyboardSet {
Params() {}
}
- private static final HashMap<KeyboardId, SoftReference<Keyboard>> sKeyboardCache =
- new HashMap<KeyboardId, SoftReference<Keyboard>>();
-
public static void clearKeyboardCache() {
sKeyboardCache.clear();
+ sKeysCache.clear();
}
private KeyboardSet(Context context, Params params) {
@@ -119,9 +124,11 @@ public class KeyboardSet {
final int keyboardSetElementId;
switch (mParams.mMode) {
case KeyboardId.MODE_PHONE:
- keyboardSetElementId =
- (baseKeyboardSetElementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED)
- ? KeyboardId.ELEMENT_PHONE_SHIFTED : KeyboardId.ELEMENT_PHONE;
+ if (baseKeyboardSetElementId == KeyboardId.ELEMENT_SYMBOLS) {
+ keyboardSetElementId = KeyboardId.ELEMENT_PHONE_SYMBOLS;
+ } else {
+ keyboardSetElementId = KeyboardId.ELEMENT_PHONE;
+ }
break;
case KeyboardId.MODE_NUMBER:
keyboardSetElementId = KeyboardId.ELEMENT_NUMBER;
@@ -154,7 +161,7 @@ public class KeyboardSet {
final Keyboard.Builder<Keyboard.Params> builder =
new Keyboard.Builder<Keyboard.Params>(context, new Keyboard.Params());
if (id.isAlphabetKeyboard()) {
- builder.setAutoGenerate(mKeysCache);
+ builder.setAutoGenerate(sKeysCache);
}
builder.load(keyboardXmlId, id);
builder.setTouchPositionCorrectionEnabled(mParams.mTouchPositionCorrectionEnabled);
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 951bcdbfd..5ba560d72 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -194,6 +194,9 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
}
public void onPressKey(int code) {
+ if (isVibrateAndSoundFeedbackRequired()) {
+ mInputMethodService.hapticAndAudioFeedback(code);
+ }
mState.onPressKey(code);
}
@@ -271,11 +274,31 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
? keyboardView.getTimerProxy().isInDoubleTapTimeout() : false;
}
+ // Implements {@link KeyboardState.SwitchActions}.
+ @Override
+ public void startLongPressTimer(int code) {
+ final LatinKeyboardView keyboardView = getKeyboardView();
+ if (keyboardView != null) {
+ final TimerProxy timer = keyboardView.getTimerProxy();
+ timer.startLongPressTimer(code);
+ }
+ }
+
+ // Implements {@link KeyboardState.SwitchActions}.
+ @Override
+ public void hapticAndAudioFeedback(int code) {
+ mInputMethodService.hapticAndAudioFeedback(code);
+ }
+
+ public void onLongPressTimeout(int code) {
+ mState.onLongPressTimeout(code);
+ }
+
public boolean isInMomentarySwitchState() {
return mState.isInMomentarySwitchState();
}
- public boolean isVibrateAndSoundFeedbackRequired() {
+ private boolean isVibrateAndSoundFeedbackRequired() {
return mKeyboardView != null && !mKeyboardView.isInSlidingKeyInput();
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 2cbd132ca..c6fb75489 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -41,6 +41,7 @@ import com.android.inputmethod.compat.FrameLayoutCompatUtils;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
+import com.android.inputmethod.latin.Utils;
import java.util.HashMap;
@@ -851,7 +852,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
if (key.mLabel != null) {
// TODO Should take care of temporaryShiftLabel here.
previewText.setCompoundDrawables(null, null, null, null);
- if (key.mLabel.length() > 1) {
+ if (Utils.codePointCount(key.mLabel) > 1) {
previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, params.mKeyLetterSize);
previewText.setTypeface(Typeface.DEFAULT_BOLD);
} else {
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index 5aad67d49..f3583fefc 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -117,12 +117,12 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
private static final int MSG_DOUBLE_TAP = 3;
private static final int MSG_KEY_TYPED = 4;
- private final int mKeyRepeatInterval;
+ private final KeyTimerParams mParams;
private boolean mInKeyRepeat;
- public KeyTimerHandler(LatinKeyboardView outerInstance, int keyRepeatInterval) {
+ public KeyTimerHandler(LatinKeyboardView outerInstance, KeyTimerParams params) {
super(outerInstance);
- mKeyRepeatInterval = keyRepeatInterval;
+ mParams = params;
}
@Override
@@ -132,18 +132,23 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
switch (msg.what) {
case MSG_REPEAT_KEY:
tracker.onRepeatKey(tracker.getKey());
- startKeyRepeatTimer(mKeyRepeatInterval, tracker);
+ startKeyRepeatTimer(tracker);
break;
case MSG_LONGPRESS_KEY:
- keyboardView.openMiniKeyboardIfRequired(tracker.getKey(), tracker);
+ if (tracker != null) {
+ keyboardView.openMiniKeyboardIfRequired(tracker.getKey(), tracker);
+ } else {
+ KeyboardSwitcher.getInstance().onLongPressTimeout(msg.arg1);
+ }
break;
}
}
@Override
- public void startKeyRepeatTimer(long delay, PointerTracker tracker) {
+ public void startKeyRepeatTimer(PointerTracker tracker) {
mInKeyRepeat = true;
- sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY, tracker), delay);
+ sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY, tracker),
+ mParams.mKeyRepeatStartTimeout);
}
public void cancelKeyRepeatTimer() {
@@ -156,9 +161,49 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
}
@Override
- public void startLongPressTimer(long delay, PointerTracker tracker) {
+ public void startLongPressTimer(int code) {
+ cancelLongPressTimer();
+ final int delay;
+ switch (code) {
+ case Keyboard.CODE_SHIFT:
+ delay = mParams.mLongPressShiftKeyTimeout;
+ break;
+ default:
+ delay = 0;
+ break;
+ }
+ if (delay > 0) {
+ sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, code, 0), delay);
+ }
+ }
+
+ @Override
+ public void startLongPressTimer(PointerTracker tracker) {
cancelLongPressTimer();
- sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, tracker), delay);
+ if (tracker != null) {
+ final Key key = tracker.getKey();
+ final int delay;
+ switch (key.mCode) {
+ case Keyboard.CODE_SHIFT:
+ delay = mParams.mLongPressShiftKeyTimeout;
+ break;
+ case Keyboard.CODE_SPACE:
+ delay = mParams.mLongPressSpaceKeyTimeout;
+ break;
+ default:
+ if (KeyboardSwitcher.getInstance().isInMomentarySwitchState()) {
+ // We use longer timeout for sliding finger input started from the symbols
+ // mode key.
+ delay = mParams.mLongPressKeyTimeout * 3;
+ } else {
+ delay = mParams.mLongPressKeyTimeout;
+ }
+ break;
+ }
+ if (delay > 0) {
+ sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, tracker), delay);
+ }
+ }
}
@Override
@@ -167,9 +212,9 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
}
@Override
- public void startKeyTypedTimer(long delay) {
+ public void startKeyTypedTimer() {
removeMessages(MSG_KEY_TYPED);
- sendMessageDelayed(obtainMessage(MSG_KEY_TYPED), delay);
+ sendMessageDelayed(obtainMessage(MSG_KEY_TYPED), mParams.mIgnoreSpecialKeyTimeout);
}
@Override
@@ -201,11 +246,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
public static class PointerTrackerParams {
public final boolean mSlidingKeyInputEnabled;
- public final int mKeyRepeatStartTimeout;
- public final int mLongPressKeyTimeout;
- public final int mLongPressShiftKeyTimeout;
- public final int mLongPressSpaceKeyTimeout;
- public final int mIgnoreSpecialKeyTimeout;
public final int mTouchNoiseThresholdTime;
public final float mTouchNoiseThresholdDistance;
@@ -213,11 +253,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
private PointerTrackerParams() {
mSlidingKeyInputEnabled = false;
- mKeyRepeatStartTimeout = 0;
- mLongPressKeyTimeout = 0;
- mLongPressShiftKeyTimeout = 0;
- mLongPressSpaceKeyTimeout = 0;
- mIgnoreSpecialKeyTimeout = 0;
mTouchNoiseThresholdTime =0;
mTouchNoiseThresholdDistance = 0;
}
@@ -225,8 +260,35 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
public PointerTrackerParams(TypedArray latinKeyboardViewAttr) {
mSlidingKeyInputEnabled = latinKeyboardViewAttr.getBoolean(
R.styleable.LatinKeyboardView_slidingKeyInputEnable, false);
+ mTouchNoiseThresholdTime = latinKeyboardViewAttr.getInt(
+ R.styleable.LatinKeyboardView_touchNoiseThresholdTime, 0);
+ mTouchNoiseThresholdDistance = latinKeyboardViewAttr.getDimension(
+ R.styleable.LatinKeyboardView_touchNoiseThresholdDistance, 0);
+ }
+ }
+
+ static class KeyTimerParams {
+ public final int mKeyRepeatStartTimeout;
+ public final int mKeyRepeatInterval;
+ public final int mLongPressKeyTimeout;
+ public final int mLongPressShiftKeyTimeout;
+ public final int mLongPressSpaceKeyTimeout;
+ public final int mIgnoreSpecialKeyTimeout;
+
+ KeyTimerParams() {
+ mKeyRepeatStartTimeout = 0;
+ mKeyRepeatInterval = 0;
+ mLongPressKeyTimeout = 0;
+ mLongPressShiftKeyTimeout = 0;
+ mLongPressSpaceKeyTimeout = 0;
+ mIgnoreSpecialKeyTimeout = 0;
+ }
+
+ public KeyTimerParams(TypedArray latinKeyboardViewAttr) {
mKeyRepeatStartTimeout = latinKeyboardViewAttr.getInt(
R.styleable.LatinKeyboardView_keyRepeatStartTimeout, 0);
+ mKeyRepeatInterval = latinKeyboardViewAttr.getInt(
+ R.styleable.LatinKeyboardView_keyRepeatInterval, 0);
mLongPressKeyTimeout = latinKeyboardViewAttr.getInt(
R.styleable.LatinKeyboardView_longPressKeyTimeout, 0);
mLongPressShiftKeyTimeout = latinKeyboardViewAttr.getInt(
@@ -235,10 +297,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
R.styleable.LatinKeyboardView_longPressSpaceKeyTimeout, 0);
mIgnoreSpecialKeyTimeout = latinKeyboardViewAttr.getInt(
R.styleable.LatinKeyboardView_ignoreSpecialKeyTimeout, 0);
- mTouchNoiseThresholdTime = latinKeyboardViewAttr.getInt(
- R.styleable.LatinKeyboardView_touchNoiseThresholdTime, 0);
- mTouchNoiseThresholdDistance = latinKeyboardViewAttr.getDimension(
- R.styleable.LatinKeyboardView_touchNoiseThresholdDistance, 0);
}
}
@@ -254,7 +312,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
mHasDistinctMultitouch = context.getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT);
- PointerTracker.init(mHasDistinctMultitouch, getContext());
+ PointerTracker.init(mHasDistinctMultitouch);
final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.LatinKeyboardView, defStyle, R.style.LatinKeyboardView);
@@ -268,16 +326,14 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
mSpacebarTextShadowColor = a.getColor(
R.styleable.LatinKeyboardView_spacebarTextShadowColor, 0);
+ final KeyTimerParams keyTimerParams = new KeyTimerParams(a);
mPointerTrackerParams = new PointerTrackerParams(a);
- mIsSpacebarTriggeringPopupByLongPress = (
- mPointerTrackerParams.mLongPressSpaceKeyTimeout > 0);
+ mIsSpacebarTriggeringPopupByLongPress = (keyTimerParams.mLongPressSpaceKeyTimeout > 0);
final float keyHysteresisDistance = a.getDimension(
R.styleable.LatinKeyboardView_keyHysteresisDistance, 0);
mKeyDetector = new KeyDetector(keyHysteresisDistance);
- final int keyRepeatInterval = a.getInt(
- R.styleable.LatinKeyboardView_keyRepeatInterval, 0);
- mKeyTimerHandler = new KeyTimerHandler(this, keyRepeatInterval);
+ mKeyTimerHandler = new KeyTimerHandler(this, keyTimerParams);
mConfigShowMiniKeyboardAtTouchedPoint = a.getBoolean(
R.styleable.LatinKeyboardView_showMiniKeyboardAtTouchedPoint, false);
a.recycle();
@@ -425,12 +481,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
// Long pressing on 0 in phone number keypad gives you a '+'.
invokeCodeInput(Keyboard.CODE_PLUS);
invokeReleaseKey(primaryCode);
- return true;
- }
- if (primaryCode == Keyboard.CODE_SHIFT && keyboard.mId.isAlphabetKeyboard()) {
- tracker.onLongPressed();
- invokeCodeInput(Keyboard.CODE_CAPSLOCK);
- invokeReleaseKey(primaryCode);
+ KeyboardSwitcher.getInstance().hapticAndAudioFeedback(primaryCode);
return true;
}
if (primaryCode == Keyboard.CODE_SPACE) {
diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
index 974291373..4648da1c1 100644
--- a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
@@ -18,7 +18,7 @@ package com.android.inputmethod.keyboard;
import android.graphics.Paint;
-import com.android.inputmethod.keyboard.internal.MoreKeySpecParser;
+import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.latin.R;
public class MiniKeyboard extends Keyboard {
@@ -210,7 +210,6 @@ public class MiniKeyboard extends Keyboard {
// TODO: Mini keyboard's vertical gap is currently calculated heuristically.
// Should revise the algorithm.
mParams.mVerticalGap = parentKeyboard.mVerticalGap / 2;
- mParams.mIsRtlKeyboard = parentKeyboard.mIsRtlKeyboard;
mMoreKeys = parentKey.mMoreKeys;
final int previewWidth = view.mKeyPreviewDrawParams.mPreviewBackgroundWidth;
@@ -236,7 +235,7 @@ public class MiniKeyboard extends Keyboard {
Paint paint = null;
int maxWidth = minKeyWidth;
for (String moreKeySpec : moreKeys) {
- final String label = MoreKeySpecParser.getLabel(moreKeySpec);
+ final String label = KeySpecParser.getLabel(moreKeySpec);
// If the label is single letter, minKeyWidth is enough to hold the label.
if (label != null && label.length() > 1) {
if (paint == null) {
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index fc92a24a6..110f7f6ae 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -16,7 +16,6 @@
package com.android.inputmethod.keyboard;
-import android.content.Context;
import android.os.SystemClock;
import android.util.Log;
import android.view.MotionEvent;
@@ -71,10 +70,11 @@ public class PointerTracker {
}
public interface TimerProxy {
- public void startKeyTypedTimer(long delay);
+ public void startKeyTypedTimer();
public boolean isTyping();
- public void startKeyRepeatTimer(long delay, PointerTracker tracker);
- public void startLongPressTimer(long delay, PointerTracker tracker);
+ public void startKeyRepeatTimer(PointerTracker tracker);
+ public void startLongPressTimer(PointerTracker tracker);
+ public void startLongPressTimer(int code);
public void cancelLongPressTimer();
public void startDoubleTapTimer();
public boolean isInDoubleTapTimeout();
@@ -82,13 +82,15 @@ public class PointerTracker {
public static class Adapter implements TimerProxy {
@Override
- public void startKeyTypedTimer(long delay) {}
+ public void startKeyTypedTimer() {}
@Override
public boolean isTyping() { return false; }
@Override
- public void startKeyRepeatTimer(long delay, PointerTracker tracker) {}
+ public void startKeyRepeatTimer(PointerTracker tracker) {}
@Override
- public void startLongPressTimer(long delay, PointerTracker tracker) {}
+ public void startLongPressTimer(PointerTracker tracker) {}
+ @Override
+ public void startLongPressTimer(int code) {}
@Override
public void cancelLongPressTimer() {}
@Override
@@ -159,7 +161,7 @@ public class PointerTracker {
private static final KeyboardActionListener EMPTY_LISTENER =
new KeyboardActionListener.Adapter();
- public static void init(boolean hasDistinctMultitouch, Context context) {
+ public static void init(boolean hasDistinctMultitouch) {
if (hasDistinctMultitouch) {
sPointerTrackerQueue = new PointerTrackerQueue();
} else {
@@ -269,7 +271,7 @@ public class PointerTracker {
mListener.onCodeInput(code, keyCodes, x, y);
}
if (!key.altCodeWhileTyping() && !key.isModifier()) {
- mTimerProxy.startKeyTypedTimer(sParams.mIgnoreSpecialKeyTimeout);
+ mTimerProxy.startKeyTypedTimer();
}
}
}
@@ -674,7 +676,7 @@ public class PointerTracker {
private void startRepeatKey(Key key) {
if (key != null && key.isRepeatable()) {
onRepeatKey(key);
- mTimerProxy.startKeyRepeatTimer(sParams.mKeyRepeatStartTimeout, this);
+ mTimerProxy.startKeyRepeatTimer(this);
mIsRepeatableKey = true;
} else {
mIsRepeatableKey = false;
@@ -702,24 +704,8 @@ public class PointerTracker {
}
private void startLongPressTimer(Key key) {
- if (key == null) return;
- if (key.mCode == Keyboard.CODE_SHIFT) {
- if (sParams.mLongPressShiftKeyTimeout > 0) {
- mTimerProxy.startLongPressTimer(sParams.mLongPressShiftKeyTimeout, this);
- }
- } else if (key.mCode == Keyboard.CODE_SPACE) {
- if (sParams.mLongPressSpaceKeyTimeout > 0) {
- mTimerProxy.startLongPressTimer(sParams.mLongPressSpaceKeyTimeout, this);
- }
- } else if (key.hasShiftedLetterHint() && mKeyboard.isManualShifted()) {
- // We need not start long press timer on the key which has manual temporary upper case
- // code defined and the keyboard is in manual temporary upper case mode.
- return;
- } else if (sKeyboardSwitcher.isInMomentarySwitchState()) {
- // We use longer timeout for sliding finger input started from the symbols mode key.
- mTimerProxy.startLongPressTimer(sParams.mLongPressKeyTimeout * 3, this);
- } else {
- mTimerProxy.startLongPressTimer(sParams.mLongPressKeyTimeout, this);
+ if (key != null && key.isLongPressEnabled()) {
+ mTimerProxy.startLongPressTimer(this);
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
index c1dae0601..2d1a0083d 100644
--- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
+++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
@@ -24,6 +24,9 @@ import com.android.inputmethod.latin.spellcheck.SpellCheckerProximityInfo;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
public class ProximityInfo {
@@ -44,7 +47,8 @@ public class ProximityInfo {
private final Key[][] mGridNeighbors;
ProximityInfo(int gridWidth, int gridHeight, int minWidth, int height, int keyWidth,
- int keyHeight, Set<Key> keys, TouchPositionCorrection touchPositionCorrection) {
+ int keyHeight, Set<Key> keys, TouchPositionCorrection touchPositionCorrection,
+ Map<Integer, List<Integer>> additionalProximityChars) {
mGridWidth = gridWidth;
mGridHeight = gridHeight;
mGridSize = mGridWidth * mGridHeight;
@@ -58,20 +62,20 @@ public class ProximityInfo {
// No proximity required. Keyboard might be mini keyboard.
return;
}
- computeNearestNeighbors(keyWidth, keys, touchPositionCorrection);
+ computeNearestNeighbors(keyWidth, keys, touchPositionCorrection, additionalProximityChars);
}
public static ProximityInfo createDummyProximityInfo() {
- return new ProximityInfo(1, 1, 1, 1, 1, 1, Collections.<Key>emptySet(), null);
+ return new ProximityInfo(1, 1, 1, 1, 1, 1, Collections.<Key> emptySet(),
+ null, Collections.<Integer, List<Integer>> emptyMap());
}
public static ProximityInfo createSpellCheckerProximityInfo(final int[] proximity) {
final ProximityInfo spellCheckerProximityInfo = createDummyProximityInfo();
spellCheckerProximityInfo.mNativeProximityInfo =
spellCheckerProximityInfo.setProximityInfoNative(
- SpellCheckerProximityInfo.ROW_SIZE,
- 480, 300, 11, 3, proximity,
- 0, null, null, null, null, null, null, null, null);
+ SpellCheckerProximityInfo.ROW_SIZE, 480, 300, 11, 3, proximity, 0,
+ null, null, null, null, null, null, null, null);
return spellCheckerProximityInfo;
}
@@ -79,11 +83,13 @@ public class ProximityInfo {
static {
Utils.loadNativeLibrary();
}
+
private native long setProximityInfoNative(int maxProximityCharsSize, int displayWidth,
int displayHeight, int gridWidth, int gridHeight, int[] proximityCharsArray,
int keyCount, int[] keyXCoordinates, int[] keyYCoordinates,
int[] keyWidths, int[] keyHeights, int[] keyCharCodes,
float[] sweetSpotCenterX, float[] sweetSpotCenterY, float[] sweetSpotRadii);
+
private native void releaseProximityInfoNative(long nativeProximityInfo);
private final void setProximityInfo(Key[][] gridNeighborKeys, int keyboardWidth,
@@ -138,7 +144,7 @@ public class ProximityInfo {
final float radius = touchPositionCorrection.mRadii[row];
sweetSpotCenterXs[i] = hitBoxCenterX + x * hitBoxWidth;
sweetSpotCenterYs[i] = hitBoxCenterY + y * hitBoxHeight;
- sweetSpotRadii[i] = radius * (float)Math.sqrt(
+ sweetSpotRadii[i] = radius * (float) Math.sqrt(
hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
}
}
@@ -168,7 +174,12 @@ public class ProximityInfo {
}
private void computeNearestNeighbors(int defaultWidth, Set<Key> keys,
- TouchPositionCorrection touchPositionCorrection) {
+ TouchPositionCorrection touchPositionCorrection,
+ Map<Integer, List<Integer>> additionalProximityChars) {
+ final Map<Integer, Key> keyCodeMap = new HashMap<Integer, Key>();
+ for (final Key key : keys) {
+ keyCodeMap.put(key.mCode, key);
+ }
final int thresholdBase = (int) (defaultWidth * SEARCH_DISTANCE);
final int threshold = thresholdBase * thresholdBase;
// Round-up so we don't have any pixels outside the grid
@@ -186,6 +197,27 @@ public class ProximityInfo {
neighborKeys[count++] = key;
}
}
+ int currentCodesSize = count;
+ for (int i = 0; i < currentCodesSize; ++i) {
+ final int c = neighborKeys[i].mCode;
+ final List<Integer> additionalChars = additionalProximityChars.get(c);
+ if (additionalChars == null || additionalChars.size() == 0) {
+ continue;
+ }
+ for (int j = 0; j < additionalChars.size(); ++j) {
+ final int additionalChar = additionalChars.get(j);
+ boolean contains = false;
+ for (int k = 0; k < count; ++k) {
+ if(additionalChar == neighborKeys[k].mCode) {
+ contains = true;
+ break;
+ }
+ }
+ if (!contains) {
+ neighborKeys[count++] = keyCodeMap.get(additionalChar);
+ }
+ }
+ }
mGridNeighbors[(y / mCellHeight) * mGridWidth + (x / mCellWidth)] =
Arrays.copyOfRange(neighborKeys, 0, count);
}
@@ -199,7 +231,7 @@ public class ProximityInfo {
return EMPTY_KEY_ARRAY;
}
if (x >= 0 && x < mKeyboardMinWidth && y >= 0 && y < mKeyboardHeight) {
- int index = (y / mCellHeight) * mGridWidth + (x / mCellWidth);
+ int index = (y / mCellHeight) * mGridWidth + (x / mCellWidth);
if (index < mGridSize) {
return mGridNeighbors[index];
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java
index abebfec01..a84b469ea 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java
@@ -30,23 +30,31 @@ import java.util.Arrays;
/**
* String parser of moreKeys attribute of Key.
* The string is comma separated texts each of which represents one "more key".
+ * - String resource can be embedded into specification @string/name. This is done before parsing
+ * comma.
* Each "more key" specification is one of the following:
* - A single letter (Letter)
* - Label optionally followed by keyOutputText or code (keyLabel|keyOutputText).
* - Icon followed by keyOutputText or code (@icon/icon_name|@integer/key_code)
- * Special character, comma ',' backslash '\', and bar '|' can be escaped by '\'
- * character.
+ * Special character, comma ',' backslash '\', and bar '|' can be escaped by '\' character.
* Note that the character '@' and '\' are also parsed by XML parser and CSV parser as well.
- * See {@link KeyboardIconsSet} about icon_number.
+ * See {@link KeyboardIconsSet} about icon_name.
*/
-public class MoreKeySpecParser {
+public class KeySpecParser {
private static final boolean DEBUG = LatinImeLogger.sDBG;
+
+ // Constants for parsing.
+ private static int COMMA = ',';
+ private static final char ESCAPE_CHAR = '\\';
+ private static final char PREFIX_AT = '@';
+ private static final char SUFFIX_SLASH = '/';
+ private static final String PREFIX_STRING = PREFIX_AT + "string" + SUFFIX_SLASH;
private static final char LABEL_END = '|';
- private static final String PREFIX_ICON = Utils.PREFIX_AT + "icon" + Utils.SUFFIX_SLASH;
- private static final String PREFIX_CODE = Utils.PREFIX_AT + "integer" + Utils.SUFFIX_SLASH;
+ private static final String PREFIX_ICON = PREFIX_AT + "icon" + SUFFIX_SLASH;
+ private static final String PREFIX_CODE = PREFIX_AT + "integer" + SUFFIX_SLASH;
private static final String ADDITIONAL_MORE_KEY_MARKER = "%";
- private MoreKeySpecParser() {
+ private KeySpecParser() {
// Intentional empty constructor for utility class.
}
@@ -56,7 +64,7 @@ public class MoreKeySpecParser {
if (end > 0) {
return true;
}
- throw new MoreKeySpecParserError("outputText or code not specified: " + moreKeySpec);
+ throw new KeySpecParserError("outputText or code not specified: " + moreKeySpec);
}
return false;
}
@@ -71,15 +79,17 @@ public class MoreKeySpecParser {
}
private static String parseEscape(String text) {
- if (text.indexOf(Utils.ESCAPE_CHAR) < 0) {
+ if (text.indexOf(ESCAPE_CHAR) < 0) {
return text;
}
final int length = text.length();
final StringBuilder sb = new StringBuilder();
for (int pos = 0; pos < length; pos++) {
final char c = text.charAt(pos);
- if (c == Utils.ESCAPE_CHAR && pos + 1 < length) {
- sb.append(text.charAt(++pos));
+ if (c == ESCAPE_CHAR && pos + 1 < length) {
+ // Skip escape char
+ pos++;
+ sb.append(text.charAt(pos));
} else {
sb.append(c);
}
@@ -88,17 +98,18 @@ public class MoreKeySpecParser {
}
private static int indexOfLabelEnd(String moreKeySpec, int start) {
- if (moreKeySpec.indexOf(Utils.ESCAPE_CHAR, start) < 0) {
+ if (moreKeySpec.indexOf(ESCAPE_CHAR, start) < 0) {
final int end = moreKeySpec.indexOf(LABEL_END, start);
if (end == 0) {
- throw new MoreKeySpecParserError(LABEL_END + " at " + start + ": " + moreKeySpec);
+ throw new KeySpecParserError(LABEL_END + " at " + start + ": " + moreKeySpec);
}
return end;
}
final int length = moreKeySpec.length();
for (int pos = start; pos < length; pos++) {
final char c = moreKeySpec.charAt(pos);
- if (c == Utils.ESCAPE_CHAR && pos + 1 < length) {
+ if (c == ESCAPE_CHAR && pos + 1 < length) {
+ // Skip escape char
pos++;
} else if (c == LABEL_END) {
return pos;
@@ -115,7 +126,7 @@ public class MoreKeySpecParser {
final String label = (end > 0) ? parseEscape(moreKeySpec.substring(0, end))
: parseEscape(moreKeySpec);
if (TextUtils.isEmpty(label)) {
- throw new MoreKeySpecParserError("Empty label: " + moreKeySpec);
+ throw new KeySpecParserError("Empty label: " + moreKeySpec);
}
return label;
}
@@ -127,7 +138,7 @@ public class MoreKeySpecParser {
final int end = indexOfLabelEnd(moreKeySpec, 0);
if (end > 0) {
if (indexOfLabelEnd(moreKeySpec, end + 1) >= 0) {
- throw new MoreKeySpecParserError("Multiple " + LABEL_END + ": "
+ throw new KeySpecParserError("Multiple " + LABEL_END + ": "
+ moreKeySpec);
}
final String outputText = parseEscape(
@@ -135,23 +146,23 @@ public class MoreKeySpecParser {
if (!TextUtils.isEmpty(outputText)) {
return outputText;
}
- throw new MoreKeySpecParserError("Empty outputText: " + moreKeySpec);
+ throw new KeySpecParserError("Empty outputText: " + moreKeySpec);
}
final String label = getLabel(moreKeySpec);
if (label == null) {
- throw new MoreKeySpecParserError("Empty label: " + moreKeySpec);
+ throw new KeySpecParserError("Empty label: " + moreKeySpec);
}
// Code is automatically generated for one letter label. See {@link getCode()}.
- return (label.length() == 1) ? null : label;
+ return (Utils.codePointCount(label) == 1) ? null : label;
}
public static int getCode(Resources res, String moreKeySpec) {
if (hasCode(moreKeySpec)) {
final int end = indexOfLabelEnd(moreKeySpec, 0);
if (indexOfLabelEnd(moreKeySpec, end + 1) >= 0) {
- throw new MoreKeySpecParserError("Multiple " + LABEL_END + ": " + moreKeySpec);
+ throw new KeySpecParserError("Multiple " + LABEL_END + ": " + moreKeySpec);
}
- final int resId = Utils.getResourceId(res,
+ final int resId = getResourceId(res,
moreKeySpec.substring(end + /* LABEL_END */1 + /* PREFIX_AT */1),
R.string.english_ime_name);
final int code = res.getInteger(resId);
@@ -162,8 +173,8 @@ public class MoreKeySpecParser {
}
final String label = getLabel(moreKeySpec);
// Code is automatically generated for one letter label.
- if (label != null && label.length() == 1) {
- return label.charAt(0);
+ if (Utils.codePointCount(label) == 1) {
+ return label.codePointAt(0);
}
return Keyboard.CODE_OUTPUT_TEXT;
}
@@ -248,9 +259,96 @@ public class MoreKeySpecParser {
}
@SuppressWarnings("serial")
- public static class MoreKeySpecParserError extends RuntimeException {
- public MoreKeySpecParserError(String message) {
+ public static class KeySpecParserError extends RuntimeException {
+ public KeySpecParserError(String message) {
super(message);
}
}
+
+ private static int getResourceId(Resources res, String name, int packageNameResId) {
+ String packageName = res.getResourcePackageName(packageNameResId);
+ int resId = res.getIdentifier(name, null, packageName);
+ if (resId == 0) {
+ throw new RuntimeException("Unknown resource: " + name);
+ }
+ return resId;
+ }
+
+ private static String resolveStringResource(String text, Resources res, int packageNameResId) {
+ final int size = text.length();
+ if (size < PREFIX_STRING.length()) {
+ return text;
+ }
+
+ StringBuilder sb = null;
+ for (int pos = 0; pos < size; pos++) {
+ final char c = text.charAt(pos);
+ if (c == PREFIX_AT && text.startsWith(PREFIX_STRING, pos)) {
+ if (sb == null) {
+ sb = new StringBuilder(text.substring(0, pos));
+ }
+ final int end = searchResourceNameEnd(text, pos + PREFIX_STRING.length());
+ final String resName = text.substring(pos + 1, end);
+ final int resId = getResourceId(res, resName, packageNameResId);
+ sb.append(res.getString(resId));
+ pos = end - 1;
+ } else if (c == ESCAPE_CHAR) {
+ if (sb != null) {
+ // Append both escape character and escaped character.
+ sb.append(text.substring(pos, Math.min(pos + 2, size)));
+ }
+ pos++;
+ } else if (sb != null) {
+ sb.append(c);
+ }
+ }
+ return (sb == null) ? text : sb.toString();
+ }
+
+ private static int searchResourceNameEnd(String text, int start) {
+ final int size = text.length();
+ for (int pos = start; pos < size; pos++) {
+ final char c = text.charAt(pos);
+ // String resource name should be consisted of [a-z_0-9].
+ if ((c >= 'a' && c <= 'z') || c == '_' || (c >= '0' && c <= '9')) {
+ continue;
+ }
+ return pos;
+ }
+ return size;
+ }
+
+ public static String[] parseCsvString(String rawText, Resources res, int packageNameResId) {
+ final String text = resolveStringResource(rawText, res, packageNameResId);
+ final int size = text.length();
+ if (size == 0) {
+ return null;
+ }
+ if (Utils.codePointCount(text) == 1) {
+ return new String[] { text };
+ }
+
+ ArrayList<String> list = null;
+ int start = 0;
+ for (int pos = 0; pos < size; pos++) {
+ final char c = text.charAt(pos);
+ if (c == COMMA) {
+ if (list == null) {
+ list = new ArrayList<String>();
+ }
+ list.add(text.substring(start, pos));
+ // Skip comma
+ start = pos + 1;
+ } else if (c == ESCAPE_CHAR) {
+ // Skip escape character and escaped character.
+ pos++;
+ }
+ }
+ if (list == null) {
+ return new String[] { text.substring(start) };
+ } else {
+ list.add(text.substring(start));
+ return list.toArray(new String[list.size()]);
+ }
+ }
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
index 1450192b2..6ec56ca9f 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
@@ -16,19 +16,16 @@
package com.android.inputmethod.keyboard.internal;
-import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.Log;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.XmlParseUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
-import java.util.ArrayList;
import java.util.HashMap;
public class KeyStyles {
@@ -74,63 +71,8 @@ public class KeyStyles {
protected static String[] parseStringArray(TypedArray a, int index) {
if (!a.hasValue(index))
return null;
- return parseCsvString(a.getString(index), a.getResources(), R.string.english_ime_name);
- }
- }
-
- /* package for test */
- static String[] parseCsvString(String rawText, Resources res, int packageNameResId) {
- final String text = Utils.resolveStringResource(rawText, res, packageNameResId);
- final int size = text.length();
- if (size == 0) {
- return null;
- }
- if (size == 1) {
- return new String[] { text };
- }
-
- final StringBuilder sb = new StringBuilder();
- ArrayList<String> list = null;
- int start = 0;
- for (int pos = 0; pos < size; pos++) {
- final char c = text.charAt(pos);
- if (c == ',') {
- if (list == null) {
- list = new ArrayList<String>();
- }
- if (sb.length() == 0) {
- list.add(text.substring(start, pos));
- } else {
- list.add(sb.toString());
- sb.setLength(0);
- }
- start = pos + 1;
- continue;
- } else if (c == Utils.ESCAPE_CHAR) {
- if (start == pos) {
- // Skip escape character at the beginning of the value.
- start++;
- pos++;
- } else {
- if (start < pos && sb.length() == 0) {
- sb.append(text.subSequence(start, pos));
- }
- pos++;
- if (pos < size) {
- sb.append(text.charAt(pos));
- }
- }
- } else if (sb.length() > 0) {
- sb.append(c);
- }
- }
- if (list == null) {
- return new String[] {
- sb.length() > 0 ? sb.toString() : text.substring(start)
- };
- } else {
- list.add(sb.length() > 0 ? sb.toString() : text.substring(start));
- return list.toArray(new String[list.size()]);
+ return KeySpecParser.parseCsvString(
+ a.getString(index), a.getResources(), R.string.english_ime_name);
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java
index bec6ae1cc..31a7e8b8e 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java
@@ -36,8 +36,9 @@ public class KeyboardIconsSet {
private final Map<Integer, Drawable> mIcons = new HashMap<Integer, Drawable>();
// The key value should be aligned with the enum value of Keyboard.icon*.
- private static final Map<Integer, Integer> ICONS_TO_ATTRS_MAP = new HashMap<Integer, Integer>();
- private static final Map<String, Integer> NAME_TO_ATTRS_MAP = new HashMap<String, Integer>();
+ private static final Map<Integer, Integer> ID_TO_ATTR_MAP = new HashMap<Integer, Integer>();
+ private static final Map<String, Integer> NAME_TO_ATTR_MAP = new HashMap<String, Integer>();
+ private static final Map<Integer, String> ATTR_TO_NAME_MAP = new HashMap<Integer, String>();
private static final Collection<Integer> VALID_ATTRS;
static {
@@ -55,12 +56,13 @@ public class KeyboardIconsSet {
addIconIdMap(11, "shiftKeyShifted", R.styleable.Keyboard_iconShiftKeyShifted);
addIconIdMap(12, "disabledShortcurKey", R.styleable.Keyboard_iconDisabledShortcutKey);
addIconIdMap(13, "previewTabKey", R.styleable.Keyboard_iconPreviewTabKey);
- VALID_ATTRS = ICONS_TO_ATTRS_MAP.values();
+ VALID_ATTRS = ID_TO_ATTR_MAP.values();
}
private static void addIconIdMap(int iconId, String name, Integer attrId) {
- ICONS_TO_ATTRS_MAP.put(iconId, attrId);
- NAME_TO_ATTRS_MAP.put(name, attrId);
+ ID_TO_ATTR_MAP.put(iconId, attrId);
+ NAME_TO_ATTR_MAP.put(name, attrId);
+ ATTR_TO_NAME_MAP.put(attrId, name);
}
public void loadIcons(final TypedArray keyboardAttrs) {
@@ -82,7 +84,7 @@ public class KeyboardIconsSet {
if (iconId == ICON_UNDEFINED) {
return ATTR_UNDEFINED;
}
- final Integer attrId = ICONS_TO_ATTRS_MAP.get(iconId);
+ final Integer attrId = ID_TO_ATTR_MAP.get(iconId);
if (attrId == null) {
throw new IllegalArgumentException("icon id is out of range: " + iconId);
}
@@ -90,13 +92,23 @@ public class KeyboardIconsSet {
}
public static int getIconAttrId(final String iconName) {
- final Integer attrId = NAME_TO_ATTRS_MAP.get(iconName);
+ final Integer attrId = NAME_TO_ATTR_MAP.get(iconName);
if (attrId == null) {
throw new IllegalArgumentException("unknown icon name: " + iconName);
}
return attrId;
}
+ public static String getIconName(final int attrId) {
+ if (attrId == ATTR_UNDEFINED) {
+ return "null";
+ }
+ if (ATTR_TO_NAME_MAP.containsKey(attrId)) {
+ return ATTR_TO_NAME_MAP.get(attrId);
+ }
+ return String.format("unknown<0x%08x>", attrId);
+ }
+
public Drawable getIconByAttrId(final Integer attrId) {
if (attrId == ATTR_UNDEFINED) {
return null;
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
index 1de83866f..cb8b4f05c 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
@@ -29,7 +29,7 @@ import com.android.inputmethod.keyboard.Keyboard;
* The input events are {@link #onLoadKeyboard(String)}, {@link #onSaveKeyboardState()},
* {@link #onPressKey(int)}, {@link #onReleaseKey(int, boolean)},
* {@link #onCodeInput(int, boolean, boolean)}, {@link #onCancelInput(boolean)},
- * {@link #onUpdateShiftState(boolean)}.
+ * {@link #onUpdateShiftState(boolean)}, {@link #onLongPressTimeout(int)}.
*
* The actions are {@link SwitchActions}'s methods.
*/
@@ -54,6 +54,8 @@ public class KeyboardState {
public void startDoubleTapTimer();
public boolean isInDoubleTapTimeout();
+ public void startLongPressTimer(int code);
+ public void hapticAndAudioFeedback(int code);
}
private final SwitchActions mSwitchActions;
@@ -335,6 +337,24 @@ public class KeyboardState {
mSymbolKeyState.onRelease();
}
+ public void onLongPressTimeout(int code) {
+ if (DEBUG_EVENT) {
+ Log.d(TAG, "onLongPressTimeout: code=" + Keyboard.printableCode(code) + " " + this);
+ }
+ if (mIsAlphabetMode && code == Keyboard.CODE_SHIFT) {
+ if (mAlphabetShiftState.isShiftLocked()) {
+ setShiftLocked(false);
+ // Shift key is long pressed while shift locked state, we will toggle back to normal
+ // state. And mark as if shift key is released.
+ mShiftKeyState.onRelease();
+ } else {
+ // Shift key is long pressed while shift unloked state.
+ setShiftLocked(true);
+ }
+ mSwitchActions.hapticAndAudioFeedback(code);
+ }
+ }
+
public void onUpdateShiftState(boolean autoCaps) {
if (DEBUG_EVENT) {
Log.d(TAG, "onUpdateShiftState: autoCaps=" + autoCaps + " " + this);
@@ -370,23 +390,27 @@ public class KeyboardState {
// Shift key has been double tapped while in normal state. This is the second
// tap to disable shift locked state, so just ignore this.
}
- } else if (mAlphabetShiftState.isShiftLocked()) {
- // Shift key is pressed while shift locked state, we will treat this state as
- // shift lock shifted state and mark as if shift key pressed while normal state.
- setShifted(SHIFT_LOCK_SHIFTED);
- mShiftKeyState.onPress();
- } else if (mAlphabetShiftState.isAutomaticShifted()) {
- // Shift key is pressed while automatic shifted, we have to move to manual shifted.
- setShifted(MANUAL_SHIFT);
- mShiftKeyState.onPress();
- } else if (mAlphabetShiftState.isShiftedOrShiftLocked()) {
- // In manual shifted state, we just record shift key has been pressing while
- // shifted state.
- mShiftKeyState.onPressOnShifted();
} else {
- // In base layout, chording or manual shifted mode is started.
- setShifted(MANUAL_SHIFT);
- mShiftKeyState.onPress();
+ if (mAlphabetShiftState.isShiftLocked()) {
+ // Shift key is pressed while shift locked state, we will treat this state as
+ // shift lock shifted state and mark as if shift key pressed while normal state.
+ setShifted(SHIFT_LOCK_SHIFTED);
+ mShiftKeyState.onPress();
+ } else if (mAlphabetShiftState.isAutomaticShifted()) {
+ // Shift key is pressed while automatic shifted, we have to move to manual
+ // shifted.
+ setShifted(MANUAL_SHIFT);
+ mShiftKeyState.onPress();
+ } else if (mAlphabetShiftState.isShiftedOrShiftLocked()) {
+ // In manual shifted state, we just record shift key has been pressing while
+ // shifted state.
+ mShiftKeyState.onPressOnShifted();
+ } else {
+ // In base layout, chording or manual shifted mode is started.
+ setShifted(MANUAL_SHIFT);
+ mShiftKeyState.onPress();
+ }
+ mSwitchActions.startLongPressTimer(Keyboard.CODE_SHIFT);
}
} else {
// In symbol mode, just toggle symbol and symbol more keyboard.
@@ -480,18 +504,6 @@ public class KeyboardState {
+ " autoCaps=" + autoCaps + " " + this);
}
- if (mIsAlphabetMode && code == Keyboard.CODE_CAPSLOCK) {
- if (mAlphabetShiftState.isShiftLocked()) {
- setShiftLocked(false);
- // Shift key is long pressed while shift locked state, we will toggle back to normal
- // state. And mark as if shift key is released.
- mShiftKeyState.onRelease();
- } else {
- // Shift key is long pressed while shift unloked state.
- setShiftLocked(true);
- }
- }
-
switch (mSwitchState) {
case SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL:
if (code == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 1e7171406..1bc55a583 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -59,7 +59,6 @@ import com.android.inputmethod.compat.SuggestionSpanUtils;
import com.android.inputmethod.compat.VibratorCompatWrapper;
import com.android.inputmethod.deprecated.LanguageSwitcherProxy;
import com.android.inputmethod.deprecated.VoiceProxy;
-import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.KeyboardId;
@@ -873,13 +872,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// turn this flag on in succession and both onUpdateSelection() calls arrive after
// the second one - the first call successfully avoids this test, but the second one
// enters. For the moment we rely on candidatesCleared to further reduce the impact.
- if (SPACE_STATE_WEAK == mSpaceState) {
- // Test for no WEAK_SPACE action because there is a race condition that may end up
- // in coming here on a normal key press. We set this to NONE because after
- // a cursor move, we don't want the suggestion strip to swap the space with the
- // newly inserted punctuation.
- mSpaceState = SPACE_STATE_NONE;
- }
+
+ // We set this to NONE because after a cursor move, we don't want the space
+ // state-related special processing to kick in.
+ mSpaceState = SPACE_STATE_NONE;
+
if (((mWordComposer.isComposingWord())
|| mVoiceProxy.isVoiceInputHighlighted())
&& (selectionChanged || candidatesCleared)) {
@@ -1296,10 +1293,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
case Keyboard.CODE_SETTINGS:
onSettingsKeyPressed();
break;
- case Keyboard.CODE_CAPSLOCK:
- // Caps lock code is handled in KeyboardSwitcher.onCodeInput() below.
- hapticAndAudioFeedback(primaryCode);
- break;
case Keyboard.CODE_SHORTCUT:
mSubtypeSwitcher.switchToShortcutIME();
break;
@@ -1901,16 +1894,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// So, LatinImeLogger logs "" as a user's input.
LatinImeLogger.logOnManualSuggestion(
"", suggestion.toString(), index, suggestions.mWords);
+ final CharSequence outputText = mSettingsValues.mSuggestPuncOutputTextList
+ .getWord(index);
+ final int primaryCode = outputText.charAt(0);
// Find out whether the previous character is a space. If it is, as a special case
// for punctuation entered through the suggestion strip, it should be swapped
// if it was a magic or a weak space. This is meant to help in case the user
// pressed space on purpose of displaying the suggestion strip punctuation.
- final int rawPrimaryCode = suggestion.charAt(0);
- // Maybe apply the "bidi mirrored" conversions for parentheses
- final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
- final boolean isRtl = keyboard != null && keyboard.mIsRtlKeyboard;
- final int primaryCode = Key.getRtlParenthesisCode(rawPrimaryCode, isRtl);
-
insertPunctuationFromSuggestionStrip(ic, primaryCode);
// TODO: the following endBatchEdit seems useless, check
if (ic != null) {
@@ -2229,9 +2219,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// be needed, but it's there just in case something went wrong.
final CharSequence textBeforeCursor = ic.getTextBeforeCursor(2, 0);
if (!". ".equals(textBeforeCursor)) {
- // We should not have come here if we aren't just after a ". ".
- throw new RuntimeException("Tried to revert double-space combo but we didn't find "
+ // Theoretically we should not be coming here if there isn't ". " before the
+ // cursor, but the application may be changing the text while we are typing, so
+ // anything goes. We should not crash.
+ Log.d(TAG, "Tried to revert double-space combo but we didn't find "
+ "\". \" just before the cursor.");
+ return false;
}
ic.beginBatchEdit();
ic.deleteSurroundingText(2, 0);
@@ -2294,18 +2287,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
loadSettings();
}
- private void hapticAndAudioFeedback(int primaryCode) {
+ public void hapticAndAudioFeedback(int primaryCode) {
vibrate();
playKeyClick(primaryCode);
}
@Override
public void onPressKey(int primaryCode) {
- final KeyboardSwitcher switcher = mKeyboardSwitcher;
- if (switcher.isVibrateAndSoundFeedbackRequired()) {
- hapticAndAudioFeedback(primaryCode);
- }
- switcher.onPressKey(primaryCode);
+ mKeyboardSwitcher.onPressKey(primaryCode);
}
@Override
@@ -2313,7 +2302,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding);
}
-
// receive ringer mode change and network state change.
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index e6ef3962e..8e2f605c4 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -25,6 +25,7 @@ import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.compat.InputTypeCompatUtils;
import com.android.inputmethod.compat.VibratorCompatWrapper;
+import com.android.inputmethod.keyboard.internal.KeySpecParser;
import java.util.Arrays;
import java.util.Locale;
@@ -36,8 +37,9 @@ public class SettingsValues {
public final int mDelayUpdateOldSuggestions;
public final String mMagicSpaceStrippers;
public final String mMagicSpaceSwappers;
- public final String mSuggestPuncs;
+ private final String mSuggestPuncs;
public final SuggestedWords mSuggestPuncList;
+ public final SuggestedWords mSuggestPuncOutputTextList;
private final String mSymbolsExcludedFromWordSeparators;
public final String mWordSeparators;
public final CharSequence mHintToSaveText;
@@ -98,9 +100,11 @@ public class SettingsValues {
}
}
}
- mSuggestPuncs = res.getString(R.string.suggested_punctuations);
- // TODO: it would be nice not to recreate this each time we change the configuration
- mSuggestPuncList = createSuggestPuncList(mSuggestPuncs);
+ final String[] suggestPuncsSpec = KeySpecParser.parseCsvString(
+ res.getString(R.string.suggested_punctuations), res, R.string.english_ime_name);
+ mSuggestPuncs = createSuggestPuncs(suggestPuncsSpec);
+ mSuggestPuncList = createSuggestPuncList(suggestPuncsSpec);
+ mSuggestPuncOutputTextList = createSuggestPuncOutputTextList(suggestPuncsSpec);
mSymbolsExcludedFromWordSeparators =
res.getString(R.string.symbols_excluded_from_word_separators);
mWordSeparators = createWordSeparators(mMagicSpaceStrippers, mMagicSpaceSwappers,
@@ -150,11 +154,36 @@ public class SettingsValues {
}
// Helper functions to create member values.
- private static SuggestedWords createSuggestPuncList(final String puncs) {
- SuggestedWords.Builder builder = new SuggestedWords.Builder();
+ private static String createSuggestPuncs(final String[] puncs) {
+ final StringBuilder sb = new StringBuilder();
if (puncs != null) {
- for (int i = 0; i < puncs.length(); i++) {
- builder.addWord(puncs.subSequence(i, i + 1));
+ for (final String puncSpec : puncs) {
+ sb.append(KeySpecParser.getLabel(puncSpec));
+ }
+ }
+ return sb.toString();
+ }
+
+ private static SuggestedWords createSuggestPuncList(final String[] puncs) {
+ final SuggestedWords.Builder builder = new SuggestedWords.Builder();
+ if (puncs != null) {
+ for (final String puncSpec : puncs) {
+ builder.addWord(KeySpecParser.getLabel(puncSpec));
+ }
+ }
+ return builder.setIsPunctuationSuggestions().build();
+ }
+
+ private static SuggestedWords createSuggestPuncOutputTextList(final String[] puncs) {
+ final SuggestedWords.Builder builder = new SuggestedWords.Builder();
+ if (puncs != null) {
+ for (final String puncSpec : puncs) {
+ final String outputText = KeySpecParser.getOutputText(puncSpec);
+ if (outputText != null) {
+ builder.addWord(outputText);
+ } else {
+ builder.addWord(KeySpecParser.getLabel(puncSpec));
+ }
}
}
return builder.setIsPunctuationSuggestions().build();
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index a70808741..3975dddeb 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -62,12 +62,6 @@ public class Utils {
private static boolean DBG = LatinImeLogger.sDBG;
private static boolean DBG_EDIT_DISTANCE = false;
- // Constants for resource name parsing.
- public static final char ESCAPE_CHAR = '\\';
- public static final char PREFIX_AT = '@';
- public static final char SUFFIX_SLASH = '/';
- private static final String PREFIX_STRING = PREFIX_AT + "string";
-
private Utils() {
// Intentional empty constructor for utility class.
}
@@ -800,61 +794,8 @@ public class Utils {
}
}
- public static int getResourceId(Resources res, String name, int packageNameResId) {
- String packageName = res.getResourcePackageName(packageNameResId);
- int resId = res.getIdentifier(name, null, packageName);
- if (resId == 0) {
- throw new RuntimeException("Unknown resource: " + name);
- }
- return resId;
- }
-
- public static String resolveStringResource(String text, Resources res, int packageNameResId) {
- final int size = text.length();
- if (size < PREFIX_STRING.length()) {
- return text;
- }
-
- StringBuilder sb = null;
- for (int pos = 0; pos < size; pos++) {
- final char c = text.charAt(pos);
- if (c == PREFIX_AT && text.startsWith(PREFIX_STRING, pos)) {
- if (sb == null) {
- sb = new StringBuilder(text.substring(0, pos));
- }
- final int end = Utils.searchResourceNameEnd(text, pos + PREFIX_STRING.length());
- final String resName = text.substring(pos + 1, end);
- final int resId = getResourceId(res, resName, packageNameResId);
- sb.append(res.getString(resId));
- pos = end - 1;
- } else if (c == ESCAPE_CHAR) {
- pos++;
- if (sb != null) {
- sb.append(c);
- if (pos < size) {
- sb.append(text.charAt(pos));
- }
- }
- } else if (sb != null) {
- sb.append(c);
- }
- }
- return (sb == null) ? text : sb.toString();
- }
-
- private static int searchResourceNameEnd(String text, int start) {
- final int size = text.length();
- if (start >= size || text.charAt(start) != SUFFIX_SLASH) {
- throw new RuntimeException("Resource name not specified");
- }
- for (int pos = start + 1; pos < size; pos++) {
- final char c = text.charAt(pos);
- // String resource name should be consisted of [a-z_0-9].
- if ((c >= 'a' && c <= 'z') || c == '_' || (c >= '0' && c <= '9')) {
- continue;
- }
- return pos;
- }
- return size;
+ public static int codePointCount(String text) {
+ if (TextUtils.isEmpty(text)) return 0;
+ return text.codePointCount(0, text.length());
}
}
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 230c2916b..bd244b913 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -16,8 +16,6 @@
package com.android.inputmethod.latin;
-import android.text.TextUtils;
-
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.KeyDetector;
import com.android.inputmethod.keyboard.Keyboard;
@@ -33,7 +31,7 @@ public class WordComposer {
public static final int NOT_A_CODE = KeyDetector.NOT_A_CODE;
public static final int NOT_A_COORDINATE = -1;
- final int N = BinaryDictionary.MAX_WORD_LENGTH;
+ final static int N = BinaryDictionary.MAX_WORD_LENGTH;
private ArrayList<int[]> mCodes;
private int[] mXCoordinates;