aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java25
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java43
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java14
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java6
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java1
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java31
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java111
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java2
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java6
9 files changed, 163 insertions, 76 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 9c495fd5f..a2d379643 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -72,6 +72,8 @@ public class Key {
private static final int LABEL_FLAGS_WITH_ICON_RIGHT = 0x2000;
private static final int LABEL_FLAGS_AUTO_X_SCALE = 0x4000;
private static final int LABEL_FLAGS_PRESERVE_CASE = 0x8000;
+ private static final int LABEL_FLAGS_INACTIVATED_LABEL = 0x10000;
+ private static final int LABEL_FLAGS_INACTIVATED_UPPERCASE_LETTER = 0x20000;
/** Icon to display instead of a label. Icon takes precedence over a label */
private final int mIconAttrId;
@@ -283,22 +285,17 @@ public class Key {
mLabelFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags, 0);
final boolean preserveCase = (mLabelFlags & LABEL_FLAGS_PRESERVE_CASE) != 0;
- final String[] moreKeys = style.getStringArray(keyAttr, R.styleable.Keyboard_Key_moreKeys);
+ 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) {
for (int i = 0; i < moreKeys.length; i++) {
moreKeys[i] = adjustCaseOfStringForKeyboardId(
moreKeys[i], preserveCase, params.mId);
}
}
- // TODO: Add new key label flag to control this.
- // In Arabic symbol layouts, we'd like to keep digits in more keys regardless of
- // config_digit_more_keys_enabled.
- if (params.mId.isAlphabetKeyboard()
- && !res.getBoolean(R.bool.config_digit_more_keys_enabled)) {
- mMoreKeys = MoreKeySpecParser.filterOut(res, moreKeys, MoreKeySpecParser.DIGIT_FILTER);
- } else {
- mMoreKeys = moreKeys;
- }
+ mMoreKeys = moreKeys;
mMaxMoreKeysColumn = style.getInt(keyAttr,
R.styleable.Keyboard_Key_maxMoreKeysColumn, params.mMaxMiniKeyboardColumn);
@@ -509,6 +506,14 @@ public class Key {
return (mLabelFlags & LABEL_FLAGS_AUTO_X_SCALE) != 0;
}
+ public boolean isInactivatedLabel() {
+ return (mLabelFlags & LABEL_FLAGS_INACTIVATED_LABEL) != 0;
+ }
+
+ public boolean isInactivatedUppercaseLetter() {
+ return (mLabelFlags & LABEL_FLAGS_INACTIVATED_UPPERCASE_LETTER) != 0;
+ }
+
// TODO: Get rid of this method.
public Drawable getIcon(KeyboardIconsSet iconSet) {
return mEnabled ? mIcon : iconSet.getIconByAttrId(mDisabledIconAttrId);
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index abe5b62ee..dd882098d 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -21,6 +21,7 @@ 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;
import android.util.TypedValue;
@@ -571,7 +572,7 @@ public class Keyboard {
private final Params mParams;
/** Default width of a key in this row. */
- public final float mDefaultKeyWidth;
+ private float mDefaultKeyWidth;
/** Default height of a key in this row. */
public final int mRowHeight;
@@ -598,6 +599,14 @@ public class Keyboard {
mCurrentX = 0.0f;
}
+ public float getDefaultKeyWidth() {
+ return mDefaultKeyWidth;
+ }
+
+ public void setDefaultKeyWidth(float defaultKeyWidth) {
+ mDefaultKeyWidth = defaultKeyWidth;
+ }
+
public void setXPos(float keyXPos) {
mCurrentX = keyXPos;
}
@@ -638,6 +647,10 @@ public class Keyboard {
return mCurrentX;
}
+ public float getKeyWidth(TypedArray keyAttr) {
+ return getKeyWidth(keyAttr, mCurrentX);
+ }
+
public float getKeyWidth(TypedArray keyAttr, float keyXPos) {
final int widthType = Builder.getEnumValue(keyAttr,
R.styleable.Keyboard_Key_keyWidth, KEYWIDTH_NOT_ENUM);
@@ -937,17 +950,33 @@ public class Keyboard {
if (skip) {
XmlParseUtils.checkEndTag(TAG_INCLUDE, parser);
} else {
- final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
+ final AttributeSet attr = Xml.asAttributeSet(parser);
+ final TypedArray keyboardAttr = mResources.obtainAttributes(attr,
R.styleable.Keyboard_Include);
+ final TypedArray keyAttr = mResources.obtainAttributes(attr,
+ R.styleable.Keyboard_Key);
int keyboardLayout = 0;
+ float savedDefaultKeyWidth = 0;
try {
- XmlParseUtils.checkAttributeExists(a,
+ XmlParseUtils.checkAttributeExists(keyboardAttr,
R.styleable.Keyboard_Include_keyboardLayout, "keyboardLayout",
TAG_INCLUDE, parser);
- keyboardLayout = a.getResourceId(
+ keyboardLayout = keyboardAttr.getResourceId(
R.styleable.Keyboard_Include_keyboardLayout, 0);
+ if (row != null) {
+ savedDefaultKeyWidth = row.getDefaultKeyWidth();
+ if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyXPos)) {
+ // Override current x coordinate.
+ row.setXPos(row.getKeyX(keyAttr));
+ }
+ if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyWidth)) {
+ // Override default key width.
+ row.setDefaultKeyWidth(row.getKeyWidth(keyAttr));
+ }
+ }
} finally {
- a.recycle();
+ keyboardAttr.recycle();
+ keyAttr.recycle();
}
XmlParseUtils.checkEndTag(TAG_INCLUDE, parser);
@@ -957,6 +986,10 @@ public class Keyboard {
try {
parseMerge(parserForInclude, row, skip);
} finally {
+ if (row != null) {
+ // Restore default key width.
+ row.setDefaultKeyWidth(savedDefaultKeyWidth);
+ }
parserForInclude.close();
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 6f4ef2580..d977327a8 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -571,8 +571,11 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
Math.min(1.0f, (keyWidth * MAX_LABEL_RATIO) / getLabelWidth(label, paint)));
}
+ // TODO: Remove this first if-clause.
if (key.hasUppercaseLetter() && mKeyboard.isManualTemporaryUpperCase()) {
paint.setColor(params.mKeyTextInactivatedColor);
+ } else if (key.isInactivatedLabel()) {
+ paint.setColor(params.mKeyTextInactivatedColor);
} else {
paint.setColor(params.mKeyTextColor);
}
@@ -618,9 +621,14 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
hintSize = params.mKeyHintLabelSize;
paint.setTypeface(Typeface.DEFAULT);
} else if (key.hasUppercaseLetter()) {
- hintColor = mKeyboard.isManualTemporaryUpperCase()
- ? params.mKeyUppercaseLetterActivatedColor
- : params.mKeyUppercaseLetterInactivatedColor;
+ // TODO: Remove this first if-clause.
+ if (mKeyboard.isManualTemporaryUpperCase()) {
+ hintColor = params.mKeyUppercaseLetterActivatedColor;
+ } else if (!key.isInactivatedUppercaseLetter()) {
+ hintColor = params.mKeyUppercaseLetterActivatedColor;
+ } else {
+ hintColor = params.mKeyUppercaseLetterInactivatedColor;
+ }
hintSize = params.mKeyUppercaseLetterSize;
} else { // key.hasHintLetter()
hintColor = params.mKeyHintLetterColor;
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index aee356a0c..7e8a7180c 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -639,7 +639,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
}
if (!TextUtils.isEmpty(eventTag)) {
UsabilityStudyLogUtils.getInstance().write(
- eventTag + eventTime + "," + id + "," + x + "," + y + "\t\t");
+ eventTag + eventTime + "," + id + "," + x + "," + y + ","
+ + me.getSize(index) + "," + me.getPressure(index));
}
}
@@ -701,7 +702,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
tracker.onMoveEvent(px, py, eventTime);
if (ENABLE_USABILITY_STUDY_LOG) {
UsabilityStudyLogUtils.getInstance().write("[Move]" + eventTime + ","
- + me.getPointerId(i) + "," + px + "," + py + "\t\t");
+ + me.getPointerId(i) + "," + px + "," + py + ","
+ + me.getSize(i) + "," + me.getPressure(i));
}
}
} else {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
index b7215ec1b..1450192b2 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
@@ -173,6 +173,7 @@ public class KeyStyles {
readString(keyAttr, R.styleable.Keyboard_Key_keyOutputText);
readString(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
readStringArray(keyAttr, R.styleable.Keyboard_Key_moreKeys);
+ readStringArray(keyAttr, R.styleable.Keyboard_Key_additionalMoreKeys);
readFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags);
readInt(keyAttr, R.styleable.Keyboard_Key_keyIcon);
readInt(keyAttr, R.styleable.Keyboard_Key_keyIconDisabled);
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
index a89356c50..5542bd32a 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
@@ -216,10 +216,24 @@ public class KeyboardState {
}
private void toggleAlphabetAndSymbols() {
+ if (DEBUG_ACTION) {
+ Log.d(TAG, "toggleAlphabetAndSymbols: " + this);
+ }
if (mIsAlphabetMode) {
- setSymbolsKeyboard();
+ mPrevMainKeyboardWasShiftLocked = mAlphabetShiftState.isShiftLocked();
+ if (mPrevSymbolsKeyboardWasShifted) {
+ setSymbolsShiftedKeyboard();
+ } else {
+ setSymbolsKeyboard();
+ }
+ mPrevSymbolsKeyboardWasShifted = false;
} else {
+ mPrevSymbolsKeyboardWasShifted = mIsSymbolShifted;
setAlphabetKeyboard();
+ if (mPrevMainKeyboardWasShiftLocked) {
+ setShiftLocked(true);
+ }
+ mPrevMainKeyboardWasShiftLocked = false;
}
}
@@ -235,24 +249,15 @@ public class KeyboardState {
if (DEBUG_ACTION) {
Log.d(TAG, "setAlphabetKeyboard");
}
- mPrevSymbolsKeyboardWasShifted = mIsSymbolShifted;
mSwitchActions.setAlphabetKeyboard();
mIsAlphabetMode = true;
mIsSymbolShifted = false;
mSwitchState = SWITCH_STATE_ALPHA;
- setShiftLocked(mPrevMainKeyboardWasShiftLocked);
- mPrevMainKeyboardWasShiftLocked = false;
mSwitchActions.requestUpdatingShiftState();
}
// TODO: Make this method private
public void setSymbolsKeyboard() {
- mPrevMainKeyboardWasShiftLocked = mAlphabetShiftState.isShiftLocked();
- if (mPrevSymbolsKeyboardWasShifted) {
- setSymbolsShiftedKeyboard();
- return;
- }
-
if (DEBUG_ACTION) {
Log.d(TAG, "setSymbolsKeyboard");
}
@@ -261,7 +266,6 @@ public class KeyboardState {
mIsSymbolShifted = false;
// Reset alphabet shift state.
mAlphabetShiftState.setShiftLocked(false);
- mPrevSymbolsKeyboardWasShifted = false;
mSwitchState = SWITCH_STATE_SYMBOL_BEGIN;
}
@@ -274,7 +278,6 @@ public class KeyboardState {
mIsSymbolShifted = true;
// Reset alphabet shift state.
mAlphabetShiftState.setShiftLocked(false);
- mPrevSymbolsKeyboardWasShifted = false;
mSwitchState = SWITCH_STATE_SYMBOL_BEGIN;
}
@@ -495,14 +498,14 @@ public class KeyboardState {
}
// Switch back to alpha keyboard mode immediately if user types a quote character.
if (isLayoutSwitchBackCharacter(code)) {
- setAlphabetKeyboard();
+ toggleAlphabetAndSymbols();
}
break;
case SWITCH_STATE_SYMBOL:
// Switch back to alpha keyboard mode if user types one or more non-space/enter
// characters followed by a space/enter or a quote character.
if (isSpaceCharacter(code) || isLayoutSwitchBackCharacter(code)) {
- setAlphabetKeyboard();
+ toggleAlphabetAndSymbols();
}
break;
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java
index 16777733e..abebfec01 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpecParser.java
@@ -20,10 +20,12 @@ import android.content.res.Resources;
import android.text.TextUtils;
import com.android.inputmethod.keyboard.Keyboard;
+import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Utils;
import java.util.ArrayList;
+import java.util.Arrays;
/**
* String parser of moreKeys attribute of Key.
@@ -38,9 +40,11 @@ import java.util.ArrayList;
* See {@link KeyboardIconsSet} about icon_number.
*/
public class MoreKeySpecParser {
+ private static final boolean DEBUG = LatinImeLogger.sDBG;
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 ADDITIONAL_MORE_KEY_MARKER = "%";
private MoreKeySpecParser() {
// Intentional empty constructor for utility class.
@@ -173,51 +177,80 @@ public class MoreKeySpecParser {
return KeyboardIconsSet.ICON_UNDEFINED;
}
- @SuppressWarnings("serial")
- public static class MoreKeySpecParserError extends RuntimeException {
- public MoreKeySpecParserError(String message) {
- super(message);
- }
- }
-
- public interface CodeFilter {
- public boolean shouldFilterOut(int code);
- }
-
- public static final CodeFilter DIGIT_FILTER = new CodeFilter() {
- @Override
- public boolean shouldFilterOut(int code) {
- return Character.isDigit(code);
- }
- };
-
- public static String[] filterOut(Resources res, String[] moreKeys, CodeFilter filter) {
- if (moreKeys == null || moreKeys.length < 1) {
- return null;
- }
- if (moreKeys.length == 1 && filter.shouldFilterOut(getCode(res, moreKeys[0]))) {
- return null;
- }
- ArrayList<String> filtered = null;
- for (int i = 0; i < moreKeys.length; i++) {
- final String moreKeySpec = moreKeys[i];
- if (filter.shouldFilterOut(getCode(res, moreKeySpec))) {
- if (filtered == null) {
- filtered = new ArrayList<String>();
- for (int j = 0; j < i; j++) {
- filtered.add(moreKeys[j]);
+ public static String[] insertAddtionalMoreKeys(String[] moreKeys, String[] additionalMoreKeys) {
+ final int moreKeysCount = (moreKeys != null) ? moreKeys.length : 0;
+ final int additionalCount = (additionalMoreKeys != null) ? additionalMoreKeys.length : 0;
+ ArrayList<String> out = null;
+ int additionalIndex = 0;
+ for (int moreKeyIndex = 0; moreKeyIndex < moreKeysCount; moreKeyIndex++) {
+ final String moreKeySpec = moreKeys[moreKeyIndex];
+ if (moreKeySpec.equals(ADDITIONAL_MORE_KEY_MARKER)) {
+ if (additionalIndex < additionalCount) {
+ // Replace '%' marker with additional more key specification.
+ final String additionalMoreKey = additionalMoreKeys[additionalIndex];
+ if (out != null) {
+ out.add(additionalMoreKey);
+ } else {
+ moreKeys[moreKeyIndex] = additionalMoreKey;
+ }
+ additionalIndex++;
+ } else {
+ // Filter out excessive '%' marker.
+ if (out == null) {
+ out = new ArrayList<String>(moreKeyIndex);
+ for (int i = 0; i < moreKeyIndex; i++) {
+ out.add(moreKeys[i]);
+ }
}
}
- } else if (filtered != null) {
- filtered.add(moreKeySpec);
+ } else {
+ if (out != null) {
+ out.add(moreKeySpec);
+ }
+ }
+ }
+ if (additionalCount > 0 && additionalIndex == 0) {
+ // No '%' marker is found in more keys.
+ // Insert all additional more keys to the head of more keys.
+ if (DEBUG && out != null) {
+ throw new RuntimeException("Internal logic error:"
+ + " moreKeys=" + Arrays.toString(moreKeys)
+ + " additionalMoreKeys=" + Arrays.toString(additionalMoreKeys));
+ }
+ out = new ArrayList<String>(additionalCount + moreKeysCount);
+ for (int i = additionalIndex; i < additionalCount; i++) {
+ out.add(additionalMoreKeys[i]);
+ }
+ for (int i = 0; i < moreKeysCount; i++) {
+ out.add(moreKeys[i]);
+ }
+ } else if (additionalIndex < additionalCount) {
+ // The number of '%' markers are less than additional more keys.
+ // Append remained additional more keys to the tail of more keys.
+ if (DEBUG && out != null) {
+ throw new RuntimeException("Internal logic error:"
+ + " moreKeys=" + Arrays.toString(moreKeys)
+ + " additionalMoreKeys=" + Arrays.toString(additionalMoreKeys));
+ }
+ out = new ArrayList<String>(moreKeysCount);
+ for (int i = 0; i < moreKeysCount; i++) {
+ out.add(moreKeys[i]);
+ }
+ for (int i = additionalIndex; i < additionalCount; i++) {
+ out.add(additionalMoreKeys[additionalIndex]);
}
}
- if (filtered == null) {
+ if (out != null) {
+ return out.size() > 0 ? out.toArray(new String[out.size()]) : null;
+ } else {
return moreKeys;
}
- if (filtered.size() == 0) {
- return null;
+ }
+
+ @SuppressWarnings("serial")
+ public static class MoreKeySpecParserError extends RuntimeException {
+ public MoreKeySpecParserError(String message) {
+ super(message);
}
- return filtered.toArray(new String[filtered.size()]);
}
}
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index bc8a1301c..a70808741 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -369,7 +369,7 @@ public class Utils {
private UsabilityStudyLogUtils() {
mDate = new Date();
- mDateFormat = new SimpleDateFormat("dd MMM HH:mm:ss.SSS");
+ mDateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss.SSSZ");
HandlerThread handlerThread = new HandlerThread("UsabilityStudyLogUtils logging task",
Process.THREAD_PRIORITY_BACKGROUND);
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index b96b0842a..230c2916b 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -311,8 +311,10 @@ public class WordComposer {
// instead of only on cancel), and ultimately we want to figure it out even earlier anyway.
final LastComposedWord lastComposedWord = new LastComposedWord(mCodes,
mXCoordinates, mYCoordinates, mTypedWord.toString(),
- (type != LastComposedWord.COMMIT_TYPE_DECIDED_WORD) || (null == mAutoCorrection)
- ? null : mAutoCorrection.toString());
+ null == mAutoCorrection ? null : mAutoCorrection.toString());
+ if (type != LastComposedWord.COMMIT_TYPE_DECIDED_WORD) {
+ lastComposedWord.deactivate();
+ }
mCodes.clear();
mTypedWord.setLength(0);
mAutoCorrection = null;