aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r--java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java50
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java64
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java10
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardId.java8
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSet.java8
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java25
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java125
-rw-r--r--java/src/com/android/inputmethod/keyboard/MiniKeyboard.java1
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java42
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java61
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java70
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java23
-rw-r--r--java/src/com/android/inputmethod/latin/SettingsValues.java45
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java55
14 files changed, 320 insertions, 267 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
index a715350c6..6ea926dc7 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() {
@@ -71,15 +63,10 @@ public class KeyCodeDescriptionMapper {
mKeyCodeMap.put(Keyboard.CODE_ENTER, R.string.spoken_description_return);
mKeyCodeMap.put(Keyboard.CODE_SETTINGS, R.string.spoken_description_settings);
mKeyCodeMap.put(Keyboard.CODE_SHIFT, R.string.spoken_description_shift);
+ mKeyCodeMap.put(Keyboard.CODE_CAPSLOCK, R.string.spoken_description_caps_lock);
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);
}
/**
@@ -103,12 +90,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();
@@ -153,6 +146,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>
@@ -177,12 +191,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..5e58821d0 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -36,8 +36,6 @@ 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 +118,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,45 +127,6 @@ 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);
if (iconAttrId == KeyboardIconsSet.ICON_UNDEFINED) {
@@ -182,7 +142,8 @@ 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),
+ MoreKeySpecParser.getCode(res, moreKeySpec),
+ MoreKeySpecParser.getOutputText(moreKeySpec),
x, y, width, height);
}
@@ -265,7 +226,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 +242,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(
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);
@@ -309,16 +271,14 @@ public class Key {
if (code == Keyboard.CODE_UNSPECIFIED && TextUtils.isEmpty(outputText)
&& !TextUtils.isEmpty(mLabel)) {
if (mLabel.codePointCount(0, mLabel.length()) == 1) {
- final int activatedCode;
// 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.
@@ -420,7 +380,7 @@ public class Key {
@Override
public String toString() {
String top = Keyboard.printableCode(mCode);
- if (mLabel != null && mLabel.length() != 1) {
+ if (mLabel != null && mLabel.codePointCount(0, mLabel.length()) != 1) {
top += "/\"" + mLabel + '"';
}
return String.format("%s %d,%d", top, mX, mY);
@@ -466,6 +426,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/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 8832d8fd1..6653dec4b 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -92,7 +92,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 +121,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;
@@ -141,7 +137,6 @@ public class Keyboard {
mOccupiedWidth = params.mOccupiedWidth;
mMostCommonKeyHeight = params.mMostCommonKeyHeight;
mMostCommonKeyWidth = params.mMostCommonKeyWidth;
- mIsRtlKeyboard = params.mIsRtlKeyboard;
mMoreKeysTemplate = params.mMoreKeysTemplate;
mMaxMiniKeyboardColumn = params.mMaxMiniKeyboardColumn;
@@ -223,7 +218,6 @@ public class Keyboard {
public int mHorizontalGap;
public int mVerticalGap;
- public boolean mIsRtlKeyboard;
public int mMoreKeysTemplate;
public int mMaxMiniKeyboardColumn;
@@ -368,9 +362,9 @@ public class Keyboard {
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";
@@ -740,8 +734,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..664e7656e 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
@@ -119,9 +119,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;
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/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..433bd0d75 100644
--- a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
@@ -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;
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/internal/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
index 1450192b2..25a2c23c4 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
@@ -16,7 +16,6 @@
package com.android.inputmethod.keyboard.internal;
-import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.Log;
@@ -28,7 +27,6 @@ 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 +72,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 Utils.parseCsvString(
+ a.getString(index), a.getResources(), R.string.english_ime_name);
}
}
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..19cd16ad2 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;
@@ -1296,10 +1295,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 +1896,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) {
@@ -2294,18 +2286,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 +2301,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..5f9cb8df6 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.MoreKeySpecParser;
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 = Utils.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(MoreKeySpecParser.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(MoreKeySpecParser.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 = MoreKeySpecParser.getOutputText(puncSpec);
+ if (outputText != null) {
+ builder.addWord(outputText);
+ } else {
+ builder.addWord(MoreKeySpecParser.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..d1b808fc8 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -857,4 +857,59 @@ public class Utils {
}
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 (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 == 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()]);
+ }
+ }
}