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/deprecated/languageswitcher/InputLanguageSelection.java4
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java46
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyDetector.java4
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java5
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java101
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java41
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboard.java4
-rw-r--r--java/src/com/android/inputmethod/keyboard/MiniKeyboard.java4
-rw-r--r--java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java4
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java (renamed from java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java)21
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java37
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java12
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/Row.java4
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java66
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java43
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java42
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java12
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java2
20 files changed, 316 insertions, 140 deletions
diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java
index cf6cd0f5e..e75559e62 100644
--- a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java
+++ b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java
@@ -16,7 +16,7 @@
package com.android.inputmethod.deprecated.languageswitcher;
-import com.android.inputmethod.keyboard.internal.KeyboardParser;
+import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
import com.android.inputmethod.latin.DictionaryFactory;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Settings;
@@ -162,7 +162,7 @@ public class InputLanguageSelection extends PreferenceActivity {
try {
final String localeStr = locale.toString();
- final String[] layoutCountryCodes = KeyboardParser.parseKeyboardLocale(
+ final String[] layoutCountryCodes = KeyboardBuilder.parseKeyboardLocale(
this, R.xml.kbd_qwerty).split(",", -1);
if (!TextUtils.isEmpty(localeStr) && layoutCountryCodes.length > 0) {
for (String s : layoutCountryCodes) {
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 8bc7e43b4..4cc0bba6a 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -28,8 +28,8 @@ 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.KeyboardParams;
-import com.android.inputmethod.keyboard.internal.KeyboardParser;
-import com.android.inputmethod.keyboard.internal.KeyboardParser.ParseException;
+import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
+import com.android.inputmethod.keyboard.internal.KeyboardBuilder.ParseException;
import com.android.inputmethod.keyboard.internal.PopupCharactersParser;
import com.android.inputmethod.keyboard.internal.Row;
import com.android.inputmethod.latin.R;
@@ -51,10 +51,10 @@ public class Key {
/** Hint label to display on the key in conjunction with the label */
public final CharSequence mHintLabel;
/** Option of the label */
- public final int mLabelOption;
- public static final int LABEL_OPTION_ALIGN_LEFT = 0x01;
- public static final int LABEL_OPTION_ALIGN_RIGHT = 0x02;
- public static final int LABEL_OPTION_ALIGN_LEFT_OF_CENTER = 0x08;
+ private final int mLabelOption;
+ private static final int LABEL_OPTION_ALIGN_LEFT = 0x01;
+ private static final int LABEL_OPTION_ALIGN_RIGHT = 0x02;
+ private static final int LABEL_OPTION_ALIGN_LEFT_OF_CENTER = 0x08;
private static final int LABEL_OPTION_LARGE_LETTER = 0x10;
private static final int LABEL_OPTION_FONT_NORMAL = 0x20;
private static final int LABEL_OPTION_FONT_MONO_SPACE = 0x40;
@@ -63,6 +63,8 @@ public class Key {
private static final int LABEL_OPTION_HAS_POPUP_HINT = 0x200;
private static final int LABEL_OPTION_HAS_UPPERCASE_LETTER = 0x400;
private static final int LABEL_OPTION_HAS_HINT_LABEL = 0x800;
+ private static final int LABEL_OPTION_WITH_ICON_LEFT = 0x1000;
+ private static final int LABEL_OPTION_WITH_ICON_RIGHT = 0x2000;
/** Icon to display instead of a label. Icon takes precedence over a label */
private Drawable mIcon;
@@ -235,14 +237,14 @@ public class Key {
R.styleable.Keyboard);
int keyWidth;
try {
- mHeight = KeyboardParser.getDimensionOrFraction(keyboardAttr,
+ mHeight = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_rowHeight,
params.mHeight, row.mRowHeight) - params.mVerticalGap;
- mHorizontalGap = KeyboardParser.getDimensionOrFraction(keyboardAttr,
+ mHorizontalGap = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_horizontalGap,
params.mWidth, params.mHorizontalGap);
mVerticalGap = params.mVerticalGap;
- keyWidth = KeyboardParser.getDimensionOrFraction(keyboardAttr,
+ keyWidth = KeyboardBuilder.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_keyWidth,
params.mWidth, row.mDefaultKeyWidth);
} finally {
@@ -263,7 +265,7 @@ public class Key {
}
final int keyboardWidth = params.mOccupiedWidth;
- int keyXPos = KeyboardParser.getDimensionOrFraction(keyAttr,
+ int keyXPos = KeyboardBuilder.getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_keyXPos, keyboardWidth, x);
if (keyXPos < 0) {
// If keyXPos is negative, the actual x-coordinate will be k + keyXPos.
@@ -317,9 +319,9 @@ public class Key {
mEdgeFlags = 0;
final KeyboardIconsSet iconsSet = params.mIconsSet;
- mVisualInsetsLeft = KeyboardParser.getDimensionOrFraction(keyAttr,
+ mVisualInsetsLeft = KeyboardBuilder.getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_visualInsetsLeft, keyboardWidth, 0);
- mVisualInsetsRight = KeyboardParser.getDimensionOrFraction(keyAttr,
+ mVisualInsetsRight = KeyboardBuilder.getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_visualInsetsRight, keyboardWidth, 0);
mPreviewIcon = iconsSet.getIcon(style.getInt(
keyAttr, R.styleable.Keyboard_Key_keyIconPreview,
@@ -384,6 +386,18 @@ public class Key {
}
}
+ public boolean isAlignLeft() {
+ return (mLabelOption & LABEL_OPTION_ALIGN_LEFT) != 0;
+ }
+
+ public boolean isAlignRight() {
+ return (mLabelOption & LABEL_OPTION_ALIGN_RIGHT) != 0;
+ }
+
+ public boolean isAlignLeftOfCenter() {
+ return (mLabelOption & LABEL_OPTION_ALIGN_LEFT_OF_CENTER) != 0;
+ }
+
public boolean hasPopupHint() {
return (mLabelOption & LABEL_OPTION_HAS_POPUP_HINT) != 0;
}
@@ -396,6 +410,14 @@ public class Key {
return (mLabelOption & LABEL_OPTION_HAS_HINT_LABEL) != 0;
}
+ public boolean hasLabelWithIconLeft() {
+ return (mLabelOption & LABEL_OPTION_WITH_ICON_LEFT) != 0;
+ }
+
+ public boolean hasLabelWithIconRight() {
+ return (mLabelOption & LABEL_OPTION_WITH_ICON_RIGHT) != 0;
+ }
+
public Drawable getIcon() {
return mIcon;
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java
index 53d46a344..0a3acb48b 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java
@@ -153,7 +153,7 @@ public class KeyDetector {
}
private void getNearbyKeyCodes(final int[] allCodes) {
- final List<Key> keys = getKeyboard().getKeys();
+ final List<Key> keys = getKeyboard().mKeys;
final int[] indices = mIndices;
// allCodes[0] should always have the key code even if it is a non-letter key.
@@ -187,7 +187,7 @@ public class KeyDetector {
* @return The nearest key index
*/
public int getKeyIndexAndNearbyCodes(int x, int y, final int[] allCodes) {
- final List<Key> keys = getKeyboard().getKeys();
+ final List<Key> keys = getKeyboard().mKeys;
final int touchX = getTouchX(x);
final int touchY = getTouchY(y);
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 809c949df..d5e75d01b 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -153,11 +153,6 @@ public class Keyboard {
return mProximityInfo.getNativeProximityInfo();
}
- // TODO: Access mKeys directly
- public List<Key> getKeys() {
- return mKeys;
- }
-
public boolean hasShiftLockKey() {
return !mShiftLockKeys.isEmpty();
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index f45e81090..2d08abc19 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -82,6 +82,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
// system navigation bar.
private WindowWidthCache mWindowWidthCache;
+ private KeyboardLayoutState mSavedKeyboardState = new KeyboardLayoutState();
+
/** mIsAutoCorrectionActive indicates that auto corrected word will be input instead of
* what user actually typed. */
private boolean mIsAutoCorrectionActive;
@@ -174,6 +176,51 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
}
}
+ public class KeyboardLayoutState {
+ private boolean mIsValid;
+ private boolean mIsAlphabetMode;
+ private boolean mIsShiftLocked;
+ private boolean mIsShifted;
+
+ public boolean isValid() {
+ return mIsValid;
+ }
+
+ public void save() {
+ mIsAlphabetMode = isAlphabetMode();
+ mIsShiftLocked = mIsAlphabetMode && isShiftLocked();
+ mIsShifted = !mIsShiftLocked && isShiftedOrShiftLocked();
+ mIsValid = true;
+ }
+
+ public KeyboardId getKeyboardId() {
+ if (!mIsValid) return mMainKeyboardId;
+
+ if (mIsAlphabetMode) {
+ return mMainKeyboardId;
+ } else {
+ return mIsShifted ? mSymbolsShiftedKeyboardId : mSymbolsKeyboardId;
+ }
+ }
+
+ public void restore() {
+ if (!mIsValid) return;
+ mIsValid = false;
+
+ if (mIsAlphabetMode) {
+ final boolean isAlphabetMode = isAlphabetMode();
+ final boolean isShiftLocked = isAlphabetMode && isShiftLocked();
+ final boolean isShifted = !isShiftLocked && isShiftedOrShiftLocked();
+ if (mIsShiftLocked != isShiftLocked) {
+ toggleCapsLock();
+ } else if (mIsShifted != isShifted) {
+ onPressShift(false);
+ onReleaseShift(false);
+ }
+ }
+ }
+ }
+
public static KeyboardSwitcher getInstance() {
return sInstance;
}
@@ -220,22 +267,34 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
}
public void loadKeyboard(EditorInfo editorInfo, Settings.Values settingsValues) {
- mSwitchState = SWITCH_STATE_ALPHA;
try {
mMainKeyboardId = getKeyboardId(editorInfo, false, false, settingsValues);
mSymbolsKeyboardId = getKeyboardId(editorInfo, true, false, settingsValues);
mSymbolsShiftedKeyboardId = getKeyboardId(editorInfo, true, true, settingsValues);
- setKeyboard(getKeyboard(mMainKeyboardId));
+ setKeyboard(getKeyboard(mSavedKeyboardState.getKeyboardId()));
+ updateShiftState();
} catch (RuntimeException e) {
Log.w(TAG, "loading keyboard failed: " + mMainKeyboardId, e);
LatinImeLogger.logOnException(mMainKeyboardId.toString(), e);
}
}
+ public KeyboardLayoutState getKeyboardState() {
+ return mSavedKeyboardState;
+ }
+
+ public void onFinishInputView() {
+ mIsAutoCorrectionActive = false;
+ }
+
public void onHideWindow() {
mIsAutoCorrectionActive = false;
}
+ public void registerWindowWidth() {
+ mWindowWidthCache.registerWidth();
+ }
+
@SuppressWarnings("unused")
public void onSizeChanged(int w, int h, int oldw, int oldh) {
// TODO: This hack should be removed when display metric returns a proper width.
@@ -248,21 +307,41 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
return;
// Reload keyboard with new width.
final KeyboardId newId = mCurrentId.cloneWithNewGeometry(conf.orientation, width);
+ mInputMethodService.mHandler.postRestoreKeyboardLayout();
setKeyboard(getKeyboard(newId));
}
- private void setKeyboard(final Keyboard newKeyboard) {
+ private void setKeyboard(final Keyboard keyboard) {
final Keyboard oldKeyboard = mKeyboardView.getKeyboard();
- mKeyboardView.setKeyboard(newKeyboard);
- mCurrentId = newKeyboard.mId;
+ mKeyboardView.setKeyboard(keyboard);
+ mCurrentId = keyboard.mId;
+ mSwitchState = getSwitchState(mCurrentId);
+ updateShiftLockState(keyboard);
mKeyboardView.setKeyPreviewPopupEnabled(
Settings.Values.isKeyPreviewPopupEnabled(mPrefs, mResources),
Settings.Values.getKeyPreviewPopupDismissDelay(mPrefs, mResources));
final boolean localeChanged = (oldKeyboard == null)
- || !newKeyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale);
+ || !keyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale);
mInputMethodService.mHandler.startDisplayLanguageOnSpacebar(localeChanged);
}
+ private int getSwitchState(KeyboardId id) {
+ return id.equals(mMainKeyboardId) ? SWITCH_STATE_ALPHA : SWITCH_STATE_SYMBOL_BEGIN;
+ }
+
+ private void updateShiftLockState(Keyboard keyboard) {
+ if (mCurrentId.equals(mSymbolsShiftedKeyboardId)) {
+ // Symbol keyboard may have an ALT key that has a caps lock style indicator (a.k.a.
+ // sticky shift key). To show or dismiss the indicator, we need to call setShiftLocked()
+ // that takes care of the current keyboard having such ALT key or not.
+ keyboard.setShiftLocked(keyboard.hasShiftLockKey());
+ } else if (mCurrentId.equals(mSymbolsKeyboardId)) {
+ // Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the
+ // indicator, we need to call setShiftLocked(false).
+ keyboard.setShiftLocked(false);
+ }
+ }
+
private LatinKeyboard getKeyboard(KeyboardId id) {
final SoftReference<LatinKeyboard> ref = mKeyboardCache.get(id);
LatinKeyboard keyboard = (ref == null) ? null : ref.get();
@@ -605,7 +684,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
+ " symbolKeyState=" + mSymbolKeyState);
mShiftKeyState.onOtherKeyPressed();
mSymbolKeyState.onOtherKeyPressed();
- mWindowWidthCache.registerWidth();
}
public void onCancelInput() {
@@ -626,15 +704,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
if (mCurrentId.equals(mSymbolsKeyboardId)
|| !mCurrentId.equals(mSymbolsShiftedKeyboardId)) {
keyboard = getKeyboard(mSymbolsShiftedKeyboardId);
- // Symbol keyboard may have an ALT key that has a caps lock style indicator (a.k.a.
- // sticky shift key). To show or dismiss the indicator, we need to call setShiftLocked()
- // that takes care of the current keyboard having such ALT key or not.
- keyboard.setShiftLocked(keyboard.hasShiftLockKey());
} else {
keyboard = getKeyboard(mSymbolsKeyboardId);
- // Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the
- // indicator, we need to call setShiftLocked(false).
- keyboard.setShiftLocked(false);
}
setKeyboard(keyboard);
}
@@ -655,10 +726,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
private void toggleKeyboardMode() {
if (mCurrentId.equals(mMainKeyboardId)) {
setKeyboard(getKeyboard(mSymbolsKeyboardId));
- mSwitchState = SWITCH_STATE_SYMBOL_BEGIN;
} else {
setKeyboard(getKeyboard(mMainKeyboardId));
- mSwitchState = SWITCH_STATE_ALPHA;
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 0fb510948..aab58b52c 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -448,7 +448,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
canvas.translate(-keyDrawX, -keyDrawY);
} else {
// Draw all keys.
- for (final Key key : mKeyboard.getKeys()) {
+ for (final Key key : mKeyboard.mKeys) {
final int keyDrawX = key.mX + key.mVisualInsetsLeft + getPaddingLeft();
final int keyDrawY = key.mY + getPaddingTop();
canvas.translate(keyDrawX, keyDrawY);
@@ -505,6 +505,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
// Draw key label.
+ final Drawable icon = key.getIcon();
float positionX = centerX;
if (key.mLabel != null) {
// Switch the character to uppercase if shift is pressed
@@ -521,16 +522,25 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
final float baseline = centerY + labelCharHeight / 2;
// Horizontal label text alignment
- if ((key.mLabelOption & Key.LABEL_OPTION_ALIGN_LEFT) != 0) {
+ float labelWidth = 0;
+ if (key.isAlignLeft()) {
positionX = (int)params.mKeyLabelHorizontalPadding;
paint.setTextAlign(Align.LEFT);
- } else if ((key.mLabelOption & Key.LABEL_OPTION_ALIGN_RIGHT) != 0) {
+ } else if (key.isAlignRight()) {
positionX = keyWidth - (int)params.mKeyLabelHorizontalPadding;
paint.setTextAlign(Align.RIGHT);
- } else if ((key.mLabelOption & Key.LABEL_OPTION_ALIGN_LEFT_OF_CENTER) != 0) {
+ } else if (key.isAlignLeftOfCenter()) {
// TODO: Parameterise this?
positionX = centerX - labelCharWidth * 7 / 4;
paint.setTextAlign(Align.LEFT);
+ } else if (key.hasLabelWithIconLeft() && icon != null) {
+ labelWidth = getLabelWidth(label, paint) + icon.getIntrinsicWidth();
+ positionX = centerX + labelWidth / 2;
+ paint.setTextAlign(Align.RIGHT);
+ } else if (key.hasLabelWithIconRight() && icon != null) {
+ labelWidth = getLabelWidth(label, paint) + icon.getIntrinsicWidth();
+ positionX = centerX - labelWidth / 2;
+ paint.setTextAlign(Align.LEFT);
} else {
positionX = centerX;
paint.setTextAlign(Align.CENTER);
@@ -552,6 +562,19 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
// Turn off drop shadow
paint.setShadowLayer(0, 0, 0, 0);
+ if (icon != null) {
+ final int iconWidth = icon.getIntrinsicWidth();
+ final int iconHeight = icon.getIntrinsicHeight();
+ final int iconY = (keyHeight - iconHeight) / 2;
+ if (key.hasLabelWithIconLeft()) {
+ final int iconX = (int)(centerX - labelWidth / 2);
+ drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight);
+ } else if (key.hasLabelWithIconRight()) {
+ final int iconX = (int)(centerX + labelWidth / 2 - iconWidth);
+ drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight);
+ }
+ }
+
if (debugShowAlign) {
final Paint line = new Paint();
drawHorizontalLine(canvas, baseline, keyWidth, 0xc0008000, line);
@@ -605,16 +628,15 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
// Draw key icon.
- final Drawable icon = key.getIcon();
if (key.mLabel == null && icon != null) {
final int iconWidth = icon.getIntrinsicWidth();
final int iconHeight = icon.getIntrinsicHeight();
final int iconX, alignX;
final int iconY = (keyHeight - iconHeight) / 2;
- if ((key.mLabelOption & Key.LABEL_OPTION_ALIGN_LEFT) != 0) {
+ if (key.isAlignLeft()) {
iconX = (int)params.mKeyLabelHorizontalPadding;
alignX = iconX;
- } else if ((key.mLabelOption & Key.LABEL_OPTION_ALIGN_RIGHT) != 0) {
+ } else if (key.isAlignRight()) {
iconX = keyWidth - (int)params.mKeyLabelHorizontalPadding - iconWidth;
alignX = iconX + iconWidth;
} else { // Align center
@@ -694,6 +716,11 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
return width;
}
+ private static float getLabelWidth(CharSequence label, Paint paint) {
+ paint.getTextBounds(label.toString(), 0, label.length(), sTextBounds);
+ return sTextBounds.width();
+ }
+
private static void drawIcon(Canvas canvas, Drawable icon, int x, int y, int width,
int height) {
canvas.translate(x, y);
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
index 9a13608fd..3cba5295e 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
@@ -31,8 +31,8 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
+import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
import com.android.inputmethod.keyboard.internal.KeyboardParams;
-import com.android.inputmethod.keyboard.internal.KeyboardParser;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SubtypeSwitcher;
@@ -118,7 +118,7 @@ public class LatinKeyboard extends Keyboard {
}
}
- public static class Builder extends KeyboardParser<LatinKeyboardParams> {
+ public static class Builder extends KeyboardBuilder<LatinKeyboardParams> {
public Builder(Context context) {
super(context, new LatinKeyboardParams());
}
diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
index 7f5339de5..08e7d7e19 100644
--- a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
@@ -16,12 +16,12 @@
package com.android.inputmethod.keyboard;
-import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder.MiniKeyboardLayoutParams;
+import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder.MiniKeyboardParams;
public class MiniKeyboard extends Keyboard {
private final int mDefaultKeyCoordX;
- public MiniKeyboard(MiniKeyboardLayoutParams params) {
+ public MiniKeyboard(MiniKeyboardParams params) {
super(params);
mDefaultKeyCoordX = params.getDefaultKeyCoordX() + params.mDefaultKeyWidth / 2;
}
diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java
index 1ec0dda15..84bd44c30 100644
--- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java
+++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboardKeyDetector.java
@@ -37,7 +37,7 @@ public class MiniKeyboardKeyDetector extends KeyDetector {
@Override
public int getKeyIndexAndNearbyCodes(int x, int y, final int[] allCodes) {
- final List<Key> keys = getKeyboard().getKeys();
+ final List<Key> keys = getKeyboard().mKeys;
final int touchX = getTouchX(x);
final int touchY = getTouchY(y);
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 3d8a9cfc6..dc2d6e4b0 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -285,7 +285,7 @@ public class PointerTracker {
public void setKeyDetectorInner(KeyDetector keyDetector) {
mKeyDetector = keyDetector;
mKeyboard = keyDetector.getKeyboard();
- mKeys = mKeyboard.getKeys();
+ mKeys = mKeyboard.mKeys;
final int keyQuarterWidth = mKeyboard.mMostCommonKeyWidth / 4;
mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth;
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
index 3f9f35993..c0dba4173 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java
@@ -20,7 +20,7 @@ import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.util.Log;
-import com.android.inputmethod.keyboard.internal.KeyboardParser.ParseException;
+import com.android.inputmethod.keyboard.internal.KeyboardBuilder.ParseException;
import com.android.inputmethod.latin.R;
import java.util.ArrayList;
@@ -214,7 +214,7 @@ public class KeyStyles {
XmlResourceParser parser) {
final String styleName = keyStyleAttr.getString(R.styleable.Keyboard_KeyStyle_styleName);
if (DEBUG) Log.d(TAG, String.format("<%s styleName=%s />",
- KeyboardParser.TAG_KEY_STYLE, styleName));
+ KeyboardBuilder.TAG_KEY_STYLE, styleName));
if (mStyles.containsKey(styleName))
throw new ParseException("duplicate key style declared: " + styleName, parser);
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index 42e290f8c..de04ecd6c 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -37,12 +37,11 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.Arrays;
-import java.util.List;
/**
- * Parser for BaseKeyboard.
+ * Keyboard Building helper.
*
- * This class parses Keyboard XML file and fill out keys in Keyboard.
+ * This class parses Keyboard XML file and eventually build a Keyboard.
* The Keyboard XML file looks like:
* <pre>
* &gt;!-- xml/keyboard.xml --&lt;
@@ -108,8 +107,8 @@ import java.util.List;
* </pre>
*/
-public class KeyboardParser<KP extends KeyboardParams> {
- private static final String TAG = KeyboardParser.class.getSimpleName();
+public class KeyboardBuilder<KP extends KeyboardParams> {
+ private static final String TAG = KeyboardBuilder.class.getSimpleName();
private static final boolean DEBUG = false;
// Keyboard XML Tags
@@ -136,7 +135,7 @@ public class KeyboardParser<KP extends KeyboardParams> {
private Key mRightEdgeKey = null;
private final KeyStyles mKeyStyles = new KeyStyles();
- public KeyboardParser(Context context, KP params) {
+ public KeyboardBuilder(Context context, KP params) {
mContext = context;
final Resources res = context.getResources();
mResources = res;
@@ -150,7 +149,7 @@ public class KeyboardParser<KP extends KeyboardParams> {
mParams.GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height);
}
- public KeyboardParser<KP> load(KeyboardId id) {
+ public KeyboardBuilder<KP> load(KeyboardId id) {
mParams.mId = id;
try {
parseKeyboard(id.getXmlId());
@@ -253,10 +252,12 @@ public class KeyboardParser<KP extends KeyboardParams> {
mParams.mVerticalGap = getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_verticalGap, height, 0);
- mParams.mIsRtlKeyboard = keyboardAttr.getBoolean(R.styleable.Keyboard_isRtlKeyboard, false);
+ mParams.mIsRtlKeyboard = keyboardAttr.getBoolean(
+ R.styleable.Keyboard_isRtlKeyboard, false);
mParams.mPopupKeyboardResId = keyboardAttr.getResourceId(
R.styleable.Keyboard_popupKeyboardTemplate, 0);
- mParams.mMaxPopupColumn = keyAttr.getInt(R.styleable.Keyboard_Key_maxPopupKeyboardColumn, 5);
+ mParams.mMaxPopupColumn = keyAttr.getInt(
+ R.styleable.Keyboard_Key_maxPopupKeyboardColumn, 5);
mParams.mIconsSet.loadIcons(keyboardAttr);
} finally {
@@ -389,7 +390,7 @@ public class KeyboardParser<KP extends KeyboardParams> {
final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard_Key);
- int keyXPos = KeyboardParser.getDimensionOrFraction(keyAttr,
+ int keyXPos = KeyboardBuilder.getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_keyXPos, keyboardWidth, mCurrentX);
if (keyXPos < 0) {
// If keyXPos is negative, the actual x-coordinate will be display_width + keyXPos.
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java
index ed4608bf6..2d8b7bf11 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java
@@ -30,23 +30,22 @@ public class KeyboardIconsSet {
// This should be aligned with Keyboard.keyIcon enum.
private static final int ICON_SHIFT_KEY = 1;
- private static final int ICON_TO_SYMBOL_KEY = 2;
- private static final int ICON_TO_SYMBOL_KEY_WITH_SHORTCUT = 3;
- private static final int ICON_DELETE_KEY = 4;
- private static final int ICON_SETTINGS_KEY = 5; // This is also represented as "@icon/5" in xml.
- private static final int ICON_SHORTCUT_KEY = 6;
- private static final int ICON_SPACE_KEY = 7;
- private static final int ICON_RETURN_KEY = 8;
- private static final int ICON_SEARCH_KEY = 9;
- private static final int ICON_TAB_KEY = 10;
+ private static final int ICON_DELETE_KEY = 2;
+ private static final int ICON_SETTINGS_KEY = 3; // This is also represented as "@icon/3" in XML.
+ private static final int ICON_SPACE_KEY = 4;
+ private static final int ICON_RETURN_KEY = 5;
+ private static final int ICON_SEARCH_KEY = 6;
+ private static final int ICON_TAB_KEY = 7; // This is also represented as "@icon/7" in XML.
+ private static final int ICON_SHORTCUT_KEY = 8;
+ private static final int ICON_SHORTCUT_FOR_LABEL = 9;
// This should be aligned with Keyboard.keyIconShifted enum.
- private static final int ICON_SHIFTED_SHIFT_KEY = 11;
+ private static final int ICON_SHIFTED_SHIFT_KEY = 10;
// This should be aligned with Keyboard.keyIconPreview enum.
- private static final int ICON_PREVIEW_TAB_KEY = 12;
- private static final int ICON_PREVIEW_SETTINGS_KEY = 13;
- private static final int ICON_PREVIEW_SHORTCUT_KEY = 14;
+ private static final int ICON_PREVIEW_TAB_KEY = 11;
+ private static final int ICON_PREVIEW_SETTINGS_KEY = 12;
+ private static final int ICON_PREVIEW_SHORTCUT_KEY = 13;
- private static final int ICON_LAST = 14;
+ private static final int ICON_LAST = 13;
private final Drawable mIcons[] = new Drawable[ICON_LAST + 1];
@@ -54,16 +53,10 @@ public class KeyboardIconsSet {
switch (attrIndex) {
case R.styleable.Keyboard_iconShiftKey:
return ICON_SHIFT_KEY;
- case R.styleable.Keyboard_iconToSymbolKey:
- return ICON_TO_SYMBOL_KEY;
- case R.styleable.Keyboard_iconToSymbolKeyWithShortcut:
- return ICON_TO_SYMBOL_KEY_WITH_SHORTCUT;
case R.styleable.Keyboard_iconDeleteKey:
return ICON_DELETE_KEY;
case R.styleable.Keyboard_iconSettingsKey:
return ICON_SETTINGS_KEY;
- case R.styleable.Keyboard_iconShortcutKey:
- return ICON_SHORTCUT_KEY;
case R.styleable.Keyboard_iconSpaceKey:
return ICON_SPACE_KEY;
case R.styleable.Keyboard_iconReturnKey:
@@ -72,6 +65,10 @@ public class KeyboardIconsSet {
return ICON_SEARCH_KEY;
case R.styleable.Keyboard_iconTabKey:
return ICON_TAB_KEY;
+ case R.styleable.Keyboard_iconShortcutKey:
+ return ICON_SHORTCUT_KEY;
+ case R.styleable.Keyboard_iconShortcutForLabel:
+ return ICON_SHORTCUT_FOR_LABEL;
case R.styleable.Keyboard_iconShiftedShiftKey:
return ICON_SHIFTED_SHIFT_KEY;
case R.styleable.Keyboard_iconPreviewTabKey:
diff --git a/java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java
index bad7a1772..31a291cef 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/MiniKeyboardBuilder.java
@@ -26,21 +26,21 @@ import com.android.inputmethod.keyboard.MiniKeyboard;
import com.android.inputmethod.latin.R;
public class MiniKeyboardBuilder extends
- KeyboardParser<MiniKeyboardBuilder.MiniKeyboardLayoutParams> {
+ KeyboardBuilder<MiniKeyboardBuilder.MiniKeyboardParams> {
private final CharSequence[] mPopupCharacters;
- public static class MiniKeyboardLayoutParams extends KeyboardParams {
+ public static class MiniKeyboardParams extends KeyboardParams {
/* package */ int mTopRowAdjustment;
public int mNumRows;
public int mNumColumns;
public int mLeftKeys;
public int mRightKeys; // includes default key.
- public MiniKeyboardLayoutParams() {
+ public MiniKeyboardParams() {
super();
}
- /* package for test */ MiniKeyboardLayoutParams(int numKeys, int maxColumns, int keyWidth,
+ /* package for test */ MiniKeyboardParams(int numKeys, int maxColumns, int keyWidth,
int rowHeight, int coordXInParent, int parentKeyboardWidth) {
super();
setParameters(
@@ -194,7 +194,7 @@ public class MiniKeyboardBuilder extends
public MiniKeyboardBuilder(KeyboardView view, int xmlId, Key parentKey,
Keyboard parentKeyboard) {
- super(view.getContext(), new MiniKeyboardLayoutParams());
+ super(view.getContext(), new MiniKeyboardParams());
load(parentKeyboard.mId.cloneWithNewXml(mResources.getResourceEntryName(xmlId), xmlId));
// HACK: Current mini keyboard design totally relies on the 9-patch padding about horizontal
@@ -246,7 +246,7 @@ public class MiniKeyboardBuilder extends
@Override
public MiniKeyboard build() {
- final MiniKeyboardLayoutParams params = mParams;
+ final MiniKeyboardParams params = mParams;
for (int n = 0; n < mPopupCharacters.length; n++) {
final CharSequence label = mPopupCharacters[n];
final int row = n / params.mNumColumns;
diff --git a/java/src/com/android/inputmethod/keyboard/internal/Row.java b/java/src/com/android/inputmethod/keyboard/internal/Row.java
index 9299cc261..d53fe12e2 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/Row.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/Row.java
@@ -40,9 +40,9 @@ public class Row {
final int keyboardHeight = params.mHeight;
TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard);
- mDefaultKeyWidth = KeyboardParser.getDimensionOrFraction(a,
+ mDefaultKeyWidth = KeyboardBuilder.getDimensionOrFraction(a,
R.styleable.Keyboard_keyWidth, keyboardWidth, params.mDefaultKeyWidth);
- mRowHeight = KeyboardParser.getDimensionOrFraction(a,
+ mRowHeight = KeyboardBuilder.getDimensionOrFraction(a,
R.styleable.Keyboard_rowHeight, keyboardHeight, params.mDefaultRowHeight);
a.recycle();
}
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
index 41b577cf3..1c7599442 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java
@@ -20,8 +20,10 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
+import android.database.Cursor;
import android.net.Uri;
import android.text.TextUtils;
+import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
@@ -29,7 +31,8 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Locale;
@@ -43,6 +46,8 @@ public class BinaryDictionaryFileDumper {
*/
static final int FILE_READ_BUFFER_SIZE = 1024;
+ private static final String DICTIONARY_PROJECTION[] = { "id" };
+
// Prevents this class to be accidentally instantiated.
private BinaryDictionaryFileDumper() {
}
@@ -75,6 +80,7 @@ public class BinaryDictionaryFileDumper {
/**
* Return for a given locale the provider URI to query to get the dictionary.
*/
+ // TODO: remove this
public static Uri getProviderUri(Locale locale) {
return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT)
.authority(BinaryDictionary.DICTIONARY_PACK_AUTHORITY).appendPath(
@@ -82,6 +88,40 @@ public class BinaryDictionaryFileDumper {
}
/**
+ * Return for a given locale or dictionary id the provider URI to get the dictionary.
+ */
+ private static Uri getProviderUri(String path) {
+ return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(BinaryDictionary.DICTIONARY_PACK_AUTHORITY).appendPath(
+ path).build();
+ }
+
+ /**
+ * Queries a content provider for the list of dictionaries for a specific locale
+ * available to copy into Latin IME.
+ */
+ private static List<String> getDictIdList(final Locale locale, final Context context) {
+ final ContentResolver resolver = context.getContentResolver();
+ final Uri dictionaryPackUri = getProviderUri(locale);
+
+ final Cursor c = resolver.query(dictionaryPackUri, DICTIONARY_PROJECTION, null, null, null);
+ if (null == c) return Collections.<String>emptyList();
+ if (c.getCount() <= 0 || !c.moveToFirst()) {
+ c.close();
+ return Collections.<String>emptyList();
+ }
+
+ final List<String> list = new ArrayList<String>();
+ do {
+ final String id = c.getString(0);
+ if (TextUtils.isEmpty(id)) continue;
+ list.add(id);
+ } while (c.moveToNext());
+ c.close();
+ return list;
+ }
+
+ /**
* Queries a content provider for dictionary data for some locale and returns the file addresses
*
* This will query a content provider for dictionary data for a given locale, and return
@@ -95,20 +135,26 @@ public class BinaryDictionaryFileDumper {
* @throw FileNotFoundException if the provider returns non-existent data.
* @throw IOException if the provider-returned data could not be read.
*/
- public static List<AssetFileAddress> getDictSetFromContentProvider(Locale locale,
- Context context) throws FileNotFoundException, IOException {
+ public static List<AssetFileAddress> getDictSetFromContentProvider(final Locale locale,
+ final Context context) throws FileNotFoundException, IOException {
// TODO: check whether the dictionary is the same or not and if it is, return the cached
// file.
// TODO: This should be able to read a number of files from the dictionary pack, copy
// them all and return them.
final ContentResolver resolver = context.getContentResolver();
- final Uri dictionaryPackUri = getProviderUri(locale);
- final AssetFileDescriptor afd = resolver.openAssetFileDescriptor(dictionaryPackUri, "r");
- if (null == afd) return null;
- final String fileName =
- copyFileTo(afd.createInputStream(), getCacheFileNameForLocale(locale, context));
- afd.close();
- return Arrays.asList(AssetFileAddress.makeFromFileName(fileName));
+ final List<String> idList = getDictIdList(locale, context);
+ final List<AssetFileAddress> fileAddressList = new ArrayList<AssetFileAddress>();
+ for (String id : idList) {
+ final Uri dictionaryPackUri = getProviderUri(id);
+ final AssetFileDescriptor afd =
+ resolver.openAssetFileDescriptor(dictionaryPackUri, "r");
+ if (null == afd) continue;
+ final String fileName =
+ copyFileTo(afd.createInputStream(), getCacheFileNameForLocale(locale, context));
+ afd.close();
+ fileAddressList.add(AssetFileAddress.makeFromFileName(fileName));
+ }
+ return fileAddressList;
}
/**
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index 989a0e9a0..4b1c05adf 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -63,9 +63,6 @@ class BinaryDictionaryGetter {
* Returns a list of file addresses for a given locale, trying relevant methods in order.
*
* Tries to get binary dictionaries from various sources, in order:
- * - Uses a private method of getting a private dictionaries, as implemented by the
- * PrivateBinaryDictionaryGetter class.
- * If that fails:
* - Uses a content provider to get a public dictionary set, as per the protocol described
* in BinaryDictionaryFileDumper.
* If that fails:
@@ -76,31 +73,23 @@ class BinaryDictionaryGetter {
*/
public static List<AssetFileAddress> getDictionaryFiles(Locale locale, Context context,
int fallbackResId) {
- // Try first to query a private package signed the same way for private files.
- final List<AssetFileAddress> privateFiles =
- PrivateBinaryDictionaryGetter.getDictionaryFiles(locale, context);
- if (null != privateFiles) {
- return privateFiles;
- } else {
- try {
- // If that was no-go, try to find a publicly exported dictionary.
- List<AssetFileAddress> listFromContentProvider =
- BinaryDictionaryFileDumper.getDictSetFromContentProvider(locale, context);
- if (null != listFromContentProvider) {
- return listFromContentProvider;
- }
- // If the list is null, fall through and return the fallback
- } catch (FileNotFoundException e) {
- Log.e(TAG, "Unable to create dictionary file from provider for locale "
- + locale.toString() + ": falling back to internal dictionary");
- } catch (IOException e) {
- Log.e(TAG, "Unable to read source data for locale "
- + locale.toString() + ": falling back to internal dictionary");
+ try {
+ List<AssetFileAddress> listFromContentProvider =
+ BinaryDictionaryFileDumper.getDictSetFromContentProvider(locale, context);
+ if (null != listFromContentProvider) {
+ return listFromContentProvider;
}
- final AssetFileAddress fallbackAsset = loadFallbackResource(context, fallbackResId,
- locale);
- if (null == fallbackAsset) return null;
- return Arrays.asList(fallbackAsset);
+ // If the list is null, fall through and return the fallback
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "Unable to create dictionary file from provider for locale "
+ + locale.toString() + ": falling back to internal dictionary");
+ } catch (IOException e) {
+ Log.e(TAG, "Unable to read source data for locale "
+ + locale.toString() + ": falling back to internal dictionary");
}
+ final AssetFileAddress fallbackAsset = loadFallbackResource(context, fallbackResId,
+ locale);
+ if (null == fallbackAsset) return null;
+ return Arrays.asList(fallbackAsset);
}
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index b2af6f9ee..d00ce78e1 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -64,6 +64,7 @@ import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
+import com.android.inputmethod.keyboard.KeyboardSwitcher.KeyboardLayoutState;
import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.LatinKeyboard;
import com.android.inputmethod.keyboard.LatinKeyboardView;
@@ -112,6 +113,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// Key events coming any faster than this are long-presses.
private static final int QUICK_PRESS = 200;
+ private static final int SCREEN_ORIENTATION_CHANGE_DETECTION_DELAY = 2;
+ private static final int ACCUMULATE_START_INPUT_VIEW_DELAY = 20;
+ private static final int RESTORE_KEYBOARD_STATE_DELAY = 200;
+
/**
* The name of the scheme used by the Package Manager to warn of a new package installation,
* replacement or removal.
@@ -218,6 +223,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private static final int MSG_SET_BIGRAM_PREDICTIONS = 7;
private static final int MSG_CONFIRM_ORIENTATION_CHANGE = 8;
private static final int MSG_START_INPUT_VIEW = 9;
+ private static final int MSG_RESTORE_KEYBOARD_LAYOUT = 10;
private static class OrientationChangeArgs {
public final int mOldWidth;
@@ -302,6 +308,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
case MSG_START_INPUT_VIEW:
latinIme.onStartInputView((EditorInfo)msg.obj, false);
break;
+ case MSG_RESTORE_KEYBOARD_LAYOUT:
+ removeMessages(MSG_UPDATE_SHIFT_STATE);
+ ((KeyboardLayoutState)msg.obj).restore();
+ break;
}
}
@@ -392,14 +402,29 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
return hasMessages(MSG_SPACE_TYPED);
}
+ public void postRestoreKeyboardLayout() {
+ final LatinIME latinIme = getOuterInstance();
+ final KeyboardLayoutState state = latinIme.mKeyboardSwitcher.getKeyboardState();
+ if (state.isValid()) {
+ removeMessages(MSG_RESTORE_KEYBOARD_LAYOUT);
+ sendMessageDelayed(
+ obtainMessage(MSG_RESTORE_KEYBOARD_LAYOUT, state),
+ RESTORE_KEYBOARD_STATE_DELAY);
+ }
+ }
+
private void postConfirmOrientationChange(OrientationChangeArgs args) {
removeMessages(MSG_CONFIRM_ORIENTATION_CHANGE);
- // Will confirm whether orientation change has finished or not after 2ms again.
- sendMessageDelayed(obtainMessage(MSG_CONFIRM_ORIENTATION_CHANGE, args), 2);
+ // Will confirm whether orientation change has finished or not again.
+ sendMessageDelayed(obtainMessage(MSG_CONFIRM_ORIENTATION_CHANGE, args),
+ SCREEN_ORIENTATION_CHANGE_DETECTION_DELAY);
}
public void startOrientationChanging(int oldw, int oldh) {
postConfirmOrientationChange(new OrientationChangeArgs(oldw, oldh));
+ final LatinIME latinIme = getOuterInstance();
+ latinIme.mKeyboardSwitcher.getKeyboardState().save();
+ postRestoreKeyboardLayout();
}
public boolean postStartInputView(EditorInfo attribute) {
@@ -407,7 +432,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
removeMessages(MSG_START_INPUT_VIEW);
// Postpone onStartInputView 20ms afterward and see if orientation change has
// finished.
- sendMessageDelayed(obtainMessage(MSG_START_INPUT_VIEW, attribute), 20);
+ sendMessageDelayed(obtainMessage(MSG_START_INPUT_VIEW, attribute),
+ ACCUMULATE_START_INPUT_VIEW_DELAY);
return true;
}
return false;
@@ -596,6 +622,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
@Override
public void onStartInputView(EditorInfo attribute, boolean restarting) {
+ mHandler.postRestoreKeyboardLayout();
if (mHandler.postStartInputView(attribute)) {
return;
}
@@ -649,7 +676,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (mSubtypeSwitcher.isKeyboardMode()) {
switcher.loadKeyboard(attribute, mSettingsValues);
- switcher.updateShiftState();
}
if (mCandidateView != null)
@@ -738,7 +764,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
super.onFinishInput();
LatinImeLogger.commit();
- mKeyboardSwitcher.onAutoCorrectionStateChanged(false);
mVoiceProxy.flushVoiceInputLogs(mConfigurationChanging);
@@ -751,6 +776,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
@Override
public void onFinishInputView(boolean finishingInput) {
super.onFinishInputView(finishingInput);
+ mKeyboardSwitcher.onFinishInputView();
KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
if (inputView != null) inputView.cancelAllMessages();
// Remove pending messages related to update suggestions
@@ -1962,16 +1988,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettingsValues);
initSuggest();
loadSettings();
- mKeyboardSwitcher.updateShiftState();
}
@Override
public void onPress(int primaryCode, boolean withSliding) {
- if (mKeyboardSwitcher.isVibrateAndSoundFeedbackRequired()) {
+ final KeyboardSwitcher switcher = mKeyboardSwitcher;
+ switcher.registerWindowWidth();
+ if (switcher.isVibrateAndSoundFeedbackRequired()) {
vibrate();
playKeyClick(primaryCode);
}
- KeyboardSwitcher switcher = mKeyboardSwitcher;
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) {
switcher.onPressShift(withSliding);
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index 35af91b0f..84751264a 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -176,7 +176,10 @@ public class Settings extends InputMethodSettingsActivity
&& isBigramPredictionEnabled(prefs, res);
mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res);
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
- mShowSettingsKey = prefs.getBoolean(Settings.PREF_SHOW_SETTINGS_KEY, false);
+ final boolean defaultShowSettingsKey = res.getBoolean(
+ R.bool.config_default_show_settings_key);
+ mShowSettingsKey = prefs.getBoolean(Settings.PREF_SHOW_SETTINGS_KEY,
+ defaultShowSettingsKey);
final String voiceModeMain = res.getString(R.string.voice_mode_main);
final String voiceModeOff = res.getString(R.string.voice_mode_off);
final String voiceMode = prefs.getString(PREF_VOICE_SETTINGS_KEY, voiceModeMain);
@@ -301,7 +304,7 @@ public class Settings extends InputMethodSettingsActivity
private ListPreference mVoicePreference;
private CheckBoxPreference mShowSettingsKeyPreference;
private ListPreference mShowCorrectionSuggestionsPreference;
- private ListPreference mAutoCorrectionThreshold;
+ private ListPreference mAutoCorrectionThresholdPreference;
private ListPreference mKeyPreviewPopupDismissDelay;
// Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary
private CheckBoxPreference mBigramSuggestion;
@@ -318,7 +321,7 @@ public class Settings extends InputMethodSettingsActivity
private void ensureConsistencyOfAutoCorrectionSettings() {
final String autoCorrectionOff = getResources().getString(
R.string.auto_correction_threshold_mode_index_off);
- final String currentSetting = mAutoCorrectionThreshold.getValue();
+ final String currentSetting = mAutoCorrectionThresholdPreference.getValue();
mBigramSuggestion.setEnabled(!currentSetting.equals(autoCorrectionOff));
mBigramPrediction.setEnabled(!currentSetting.equals(autoCorrectionOff));
}
@@ -356,7 +359,8 @@ public class Settings extends InputMethodSettingsActivity
mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff)
.equals(mVoiceModeOff));
- mAutoCorrectionThreshold = (ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD);
+ mAutoCorrectionThresholdPreference =
+ (ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD);
mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS);
mBigramPrediction = (CheckBoxPreference) findPreference(PREF_BIGRAM_PREDICTIONS);
mDebugSettingsPreference = findPreference(PREF_DEBUG_SETTINGS);
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index ae938aea8..4a822d7b0 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -39,7 +39,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
String[] candidates1 = new String[] {text, "candidateA", "candidateB"};
final int textLength = textInfo.getText().length() % 3;
if (textLength % 3 == 0) {
- return new SuggestionsInfo(SuggestionsInfo.RESULT_ATTR_LOOKS_TYPO
+ return new SuggestionsInfo(2
| SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY, candidates0);
} else if (textLength % 3 == 1) {
return new SuggestionsInfo(SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY, candidates1);