aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/res/values/config.xml1
-rw-r--r--java/res/values/styles.xml4
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java41
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboard.java53
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java9
-rw-r--r--java/src/com/android/inputmethod/latin/ExpandableDictionary.java2
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java37
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java7
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestionsView.java169
-rw-r--r--java/src/com/android/inputmethod/latin/UserDictionary.java3
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java15
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java83
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java12
13 files changed, 231 insertions, 205 deletions
diff --git a/java/res/values/config.xml b/java/res/values/config.xml
index bad4bc625..8b99a1fcb 100644
--- a/java/res/values/config.xml
+++ b/java/res/values/config.xml
@@ -38,7 +38,6 @@
<bool name="config_default_bigram_prediction">false</bool>
<bool name="config_default_sound_enabled">false</bool>
<bool name="config_default_vibration_enabled">true</bool>
- <bool name="config_auto_correction_spacebar_led_enabled">false</bool>
<!-- Showing mini keyboard, just above the touched point if true, aligned to the key if false -->
<bool name="config_show_mini_keyboard_at_touched_point">false</bool>
<!-- The language is never displayed if == 0, always displayed if < 0 -->
diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml
index 43aa58388..2b5fb08e5 100644
--- a/java/res/values/styles.xml
+++ b/java/res/values/styles.xml
@@ -32,8 +32,7 @@
<item name="maxMoreKeysColumn">@integer/config_max_more_keys_column</item>
</style>
<style name="LatinKeyboard">
- <item name="autoCorrectionSpacebarLedEnabled">@bool/config_auto_correction_spacebar_led_enabled
- </item>
+ <item name="autoCorrectionSpacebarLedEnabled">true</item>
<item name="spacebarTextColor">#FFC0C0C0</item>
<item name="spacebarTextShadowColor">#80000000</item>
</style>
@@ -242,6 +241,7 @@
name="LatinKeyboard.IceCreamSandwich"
parent="LatinKeyboard"
>
+ <item name="autoCorrectionSpacebarLedEnabled">false</item>
<item name="disabledShortcutIcon">@drawable/sym_keyboard_voice_off_holo</item>
</style>
<style
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 1f3006d9f..3d4a6efcd 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -166,18 +166,29 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
SettingsValues.getKeyPreviewPopupDismissDelay(mPrefs, mResources));
final boolean localeChanged = (oldKeyboard == null)
|| !keyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale);
- mInputMethodService.mHandler.startDisplayLanguageOnSpacebar(localeChanged);
+ if (keyboard instanceof LatinKeyboard) {
+ final LatinKeyboard latinKeyboard = (LatinKeyboard)keyboard;
+ latinKeyboard.updateAutoCorrectionState(mIsAutoCorrectionActive);
+ // If the cached keyboard had been switched to another keyboard while the language was
+ // displayed on its spacebar, it might have had arbitrary text fade factor. In such
+ // case, we should reset the text fade factor. It is also applicable to shortcut key.
+ latinKeyboard.updateSpacebarLanguage(0.0f,
+ Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */),
+ mSubtypeSwitcher.needsToDisplayLanguage(latinKeyboard.mId.mLocale));
+ latinKeyboard.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
+ }
updateShiftState();
+ mInputMethodService.mHandler.startDisplayLanguageOnSpacebar(localeChanged);
}
// TODO: Move this method to KeyboardSet.
- private LatinKeyboard getKeyboard(KeyboardId id) {
+ private LatinKeyboard getKeyboard(Context context, KeyboardId id) {
final SoftReference<LatinKeyboard> ref = mKeyboardCache.get(id);
LatinKeyboard keyboard = (ref == null) ? null : ref.get();
if (keyboard == null) {
final Locale savedLocale = LocaleUtils.setSystemLocale(mResources, id.mLocale);
try {
- final LatinKeyboard.Builder builder = new LatinKeyboard.Builder(mThemeContext);
+ final LatinKeyboard.Builder builder = new LatinKeyboard.Builder(context);
builder.load(id);
builder.setTouchPositionCorrectionEnabled(
mSubtypeSwitcher.currentSubtypeContainsExtraValueKey(
@@ -198,14 +209,8 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
+ " theme=" + themeName(keyboard.mThemeId));
}
- keyboard.onAutoCorrectionStateChanged(mIsAutoCorrectionActive);
keyboard.setShiftLocked(false);
keyboard.setShifted(false);
- // If the cached keyboard had been switched to another keyboard while the language was
- // displayed on its spacebar, it might have had arbitrary text fade factor. In such case,
- // we should reset the text fade factor. It is also applicable to shortcut key.
- keyboard.setSpacebarTextFadeFactor(0.0f, null);
- keyboard.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady(), null);
return keyboard;
}
@@ -338,19 +343,19 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
// Implements {@link KeyboardState.SwitchActions}.
@Override
public void setSymbolsKeyboard() {
- setKeyboard(getKeyboard(mKeyboardSet.mSymbolsId));
+ setKeyboard(getKeyboard(mThemeContext, mKeyboardSet.mSymbolsId));
}
// Implements {@link KeyboardState.SwitchActions}.
@Override
public void setAlphabetKeyboard() {
- setKeyboard(getKeyboard(mKeyboardSet.mAlphabetId));
+ setKeyboard(getKeyboard(mThemeContext, mKeyboardSet.mAlphabetId));
}
// Implements {@link KeyboardState.SwitchActions}.
@Override
public void setSymbolsShiftedKeyboard() {
- final Keyboard keyboard = getKeyboard(mKeyboardSet.mSymbolsShiftedId);
+ final Keyboard keyboard = getKeyboard(mThemeContext, mKeyboardSet.mSymbolsShiftedId);
setKeyboard(keyboard);
// TODO: Remove this logic once we introduce initial keyboard shift state attribute.
// Symbol shift keyboard may have a shift key that has a caps lock style indicator (a.k.a.
@@ -451,12 +456,22 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
}
}
+ public void onNetworkStateChanged() {
+ final LatinKeyboard keyboard = getLatinKeyboard();
+ if (keyboard == null) return;
+ final Key updatedKey = keyboard.updateShortcutKey(
+ SubtypeSwitcher.getInstance().isShortcutImeReady());
+ if (updatedKey != null && mKeyboardView != null) {
+ mKeyboardView.invalidateKey(updatedKey);
+ }
+ }
+
public void onAutoCorrectionStateChanged(boolean isAutoCorrection) {
if (mIsAutoCorrectionActive != isAutoCorrection) {
mIsAutoCorrectionActive = isAutoCorrection;
final LatinKeyboard keyboard = getLatinKeyboard();
if (keyboard != null && keyboard.needsAutoCorrectionSpacebarLed()) {
- final Key invalidatedKey = keyboard.onAutoCorrectionStateChanged(isAutoCorrection);
+ final Key invalidatedKey = keyboard.updateAutoCorrectionState(isAutoCorrection);
final LatinKeyboardView keyboardView = getKeyboardView();
if (keyboardView != null)
keyboardView.invalidateKey(invalidatedKey);
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
index a9fcd9ac4..abb96f0bb 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
@@ -31,11 +31,9 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
-import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
import com.android.inputmethod.keyboard.internal.KeyboardParams;
import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.Utils;
import java.util.Arrays;
@@ -48,7 +46,6 @@ public class LatinKeyboard extends Keyboard {
private final Resources mRes;
private final Theme mTheme;
- private final SubtypeSwitcher mSubtypeSwitcher = SubtypeSwitcher.getInstance();
/* Space key and its icons, drawables and colors. */
private final Key mSpaceKey;
@@ -57,11 +54,15 @@ public class LatinKeyboard extends Keyboard {
private final Drawable mAutoCorrectionSpacebarLedIcon;
private final int mSpacebarTextColor;
private final int mSpacebarTextShadowColor;
- private float mSpacebarTextFadeFactor = 0.0f;
private final HashMap<Integer, BitmapDrawable> mSpaceDrawableCache =
new HashMap<Integer, BitmapDrawable>();
private final boolean mIsSpacebarTriggeringPopupByLongPress;
+ private boolean mAutoCorrectionSpacebarLedOn;
+ private boolean mMultipleEnabledIMEsOrSubtypes;
+ private boolean mNeedsToDisplayLanguage;
+ private float mSpacebarTextFadeFactor = 0.0f;
+
/* Shortcut key and its icons if available */
private final Key mShortcutKey;
private final Drawable mEnabledShortcutIcon;
@@ -140,11 +141,13 @@ public class LatinKeyboard extends Keyboard {
}
}
- public void setSpacebarTextFadeFactor(float fadeFactor, KeyboardView view) {
+ public Key updateSpacebarLanguage(float fadeFactor, boolean multipleEnabledIMEsOrSubtypes,
+ boolean needsToDisplayLanguage) {
mSpacebarTextFadeFactor = fadeFactor;
- updateSpacebarForLocale(false);
- if (view != null)
- view.invalidateKey(mSpaceKey);
+ mMultipleEnabledIMEsOrSubtypes = multipleEnabledIMEsOrSubtypes;
+ mNeedsToDisplayLanguage = needsToDisplayLanguage;
+ updateSpacebarIcon();
+ return mSpaceKey;
}
private static int getSpacebarTextColor(int color, float fadeFactor) {
@@ -153,13 +156,12 @@ public class LatinKeyboard extends Keyboard {
return newColor;
}
- public void updateShortcutKey(boolean available, KeyboardView view) {
+ public Key updateShortcutKey(boolean available) {
if (mShortcutKey == null)
- return;
+ return null;
mShortcutKey.setEnabled(available);
mShortcutKey.setIcon(available ? mEnabledShortcutIcon : mDisabledShortcutIcon);
- if (view != null)
- view.invalidateKey(mShortcutKey);
+ return mShortcutKey;
}
public boolean needsAutoCorrectionSpacebarLed() {
@@ -169,8 +171,9 @@ public class LatinKeyboard extends Keyboard {
/**
* @return a key which should be invalidated.
*/
- public Key onAutoCorrectionStateChanged(boolean isAutoCorrection) {
- updateSpacebarForLocale(isAutoCorrection);
+ public Key updateAutoCorrectionState(boolean isAutoCorrection) {
+ mAutoCorrectionSpacebarLedOn = isAutoCorrection;
+ updateSpacebarIcon();
return mSpaceKey;
}
@@ -183,19 +186,15 @@ public class LatinKeyboard extends Keyboard {
return label;
}
- private void updateSpacebarForLocale(boolean isAutoCorrection) {
+ private void updateSpacebarIcon() {
if (mSpaceKey == null) return;
- final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance();
- if (imm == null) return;
- // The "..." popup hint for triggering something by a long-pressing the spacebar
final boolean shouldShowInputMethodPicker = mIsSpacebarTriggeringPopupByLongPress
- && Utils.hasMultipleEnabledIMEsOrSubtypes(imm, true /* include aux subtypes */);
+ && mMultipleEnabledIMEsOrSubtypes;
mSpaceKey.setNeedsSpecialPopupHint(shouldShowInputMethodPicker);
- // If application locales are explicitly selected.
- if (mSubtypeSwitcher.needsToDisplayLanguage(mId.mLocale)) {
- mSpaceKey.setIcon(getSpaceDrawable(mId.mLocale, isAutoCorrection));
- } else if (isAutoCorrection) {
- mSpaceKey.setIcon(getSpaceDrawable(null, true));
+ if (mNeedsToDisplayLanguage) {
+ mSpaceKey.setIcon(getSpaceDrawable(mId.mLocale));
+ } else if (mAutoCorrectionSpacebarLedOn) {
+ mSpaceKey.setIcon(getSpaceDrawable(null));
} else {
mSpaceKey.setIcon(mSpaceIcon);
}
@@ -245,15 +244,15 @@ public class LatinKeyboard extends Keyboard {
return language;
}
- private BitmapDrawable getSpaceDrawable(Locale locale, boolean isAutoCorrection) {
+ private BitmapDrawable getSpaceDrawable(Locale locale) {
final Integer hashCode = Arrays.hashCode(
- new Object[] { locale, isAutoCorrection, mSpacebarTextFadeFactor });
+ new Object[] { locale, mAutoCorrectionSpacebarLedOn, mSpacebarTextFadeFactor });
final BitmapDrawable cached = mSpaceDrawableCache.get(hashCode);
if (cached != null) {
return cached;
}
final BitmapDrawable drawable = new BitmapDrawable(mRes, drawSpacebar(
- locale, isAutoCorrection, mSpacebarTextFadeFactor));
+ locale, mAutoCorrectionSpacebarLedOn, mSpacebarTextFadeFactor));
mSpaceDrawableCache.put(hashCode, drawable);
return drawable;
}
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index 7f2c6c501..49b8ce76f 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -373,15 +373,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
return miniKeyboardView;
}
- public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboard oldKeyboard) {
- final Keyboard keyboard = getKeyboard();
- // We should not set text fade factor to the keyboard which does not display the language on
- // its spacebar.
- if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) {
- ((LatinKeyboard)keyboard).setSpacebarTextFadeFactor(fadeFactor, this);
- }
- }
-
/**
* Called when a key is long pressed. By default this will open mini keyboard associated
* with this key.
diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
index cad69bb0e..7eec8e2ca 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
@@ -51,6 +51,7 @@ public class ExpandableDictionary extends Dictionary {
private Object mUpdatingLock = new Object();
private static class Node {
+ Node() {}
char mCode;
int mFrequency;
boolean mTerminal;
@@ -547,6 +548,7 @@ public class ExpandableDictionary extends Dictionary {
}
private class LoadDictionaryTask extends Thread {
+ LoadDictionaryTask() {}
@Override
public void run() {
loadDictionaryAsync();
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 943361c73..20c87ad13 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -297,19 +297,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|| (switcher.isAlphabetMode() && switcher.isShiftedOrShiftLocked()));
break;
case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR:
- if (inputView != null) {
- inputView.setSpacebarTextFadeFactor(
- (1.0f + mFinalFadeoutFactorOfLanguageOnSpacebar) / 2,
- (LatinKeyboard)msg.obj);
- }
+ setSpacebarTextFadeFactor(inputView,
+ (1.0f + mFinalFadeoutFactorOfLanguageOnSpacebar) / 2,
+ (LatinKeyboard)msg.obj);
sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj),
mDurationOfFadeoutLanguageOnSpacebar);
break;
case MSG_DISMISS_LANGUAGE_ON_SPACEBAR:
- if (inputView != null) {
- inputView.setSpacebarTextFadeFactor(mFinalFadeoutFactorOfLanguageOnSpacebar,
- (LatinKeyboard)msg.obj);
- }
+ setSpacebarTextFadeFactor(inputView, mFinalFadeoutFactorOfLanguageOnSpacebar,
+ (LatinKeyboard)msg.obj);
break;
}
}
@@ -349,6 +345,19 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
sendMessage(obtainMessage(MSG_VOICE_RESULTS));
}
+ private static void setSpacebarTextFadeFactor(LatinKeyboardView inputView,
+ float fadeFactor, LatinKeyboard oldKeyboard) {
+ if (inputView == null) return;
+ final Keyboard keyboard = inputView.getKeyboard();
+ if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) {
+ final Key updatedKey = ((LatinKeyboard)keyboard).updateSpacebarLanguage(
+ fadeFactor,
+ Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */),
+ SubtypeSwitcher.getInstance().needsToDisplayLanguage(keyboard.mId.mLocale));
+ inputView.invalidateKey(updatedKey);
+ }
+ }
+
public void startDisplayLanguageOnSpacebar(boolean localeChanged) {
final LatinIME latinIme = getOuterInstance();
removeMessages(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR);
@@ -361,9 +370,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|| mDelayBeforeFadeoutLanguageOnSpacebar < 0;
// The language is never displayed when the delay is zero.
if (mDelayBeforeFadeoutLanguageOnSpacebar != 0) {
- inputView.setSpacebarTextFadeFactor(needsToDisplayLanguage ? 1.0f
- : mFinalFadeoutFactorOfLanguageOnSpacebar,
- keyboard);
+ setSpacebarTextFadeFactor(inputView,
+ needsToDisplayLanguage ? 1.0f : mFinalFadeoutFactorOfLanguageOnSpacebar,
+ keyboard);
}
// The fadeout animation will start when the delay is positive.
if (localeChanged && mDelayBeforeFadeoutLanguageOnSpacebar > 0) {
@@ -1229,7 +1238,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (isShowingOptionDialog()) return;
if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
showSubtypeSelectorAndSettings();
- } else if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm, false /* exclude aux subtypes */)) {
+ } else if (Utils.hasMultipleEnabledIMEsOrSubtypes(false /* exclude aux subtypes */)) {
showOptionsMenu();
} else {
launchSettings();
@@ -1245,7 +1254,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (isShowingOptionDialog()) return false;
switch (requestCode) {
case CODE_SHOW_INPUT_METHOD_PICKER:
- if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm, true /* include aux subtypes */)) {
+ if (Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) {
mImm.showInputMethodPicker();
return true;
}
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index 8a4862094..42111822d 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -35,7 +35,6 @@ import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
-import com.android.inputmethod.keyboard.LatinKeyboard;
import java.util.ArrayList;
import java.util.Arrays;
@@ -421,11 +420,7 @@ public class SubtypeSwitcher {
ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
mIsNetworkConnected = !noConnection;
- final KeyboardSwitcher switcher = KeyboardSwitcher.getInstance();
- final LatinKeyboard keyboard = switcher.getLatinKeyboard();
- if (keyboard != null) {
- keyboard.updateShortcutKey(isShortcutImeReady(), switcher.getKeyboardView());
- }
+ KeyboardSwitcher.getInstance().onNetworkStateChanged();
}
//////////////////////////////////
diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java
index 883bb57f0..47c790093 100644
--- a/java/src/com/android/inputmethod/latin/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java
@@ -461,6 +461,91 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
setLayoutWeight(
hintView, 1.0f - mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT);
}
+
+ private static CharSequence getDebugInfo(SuggestedWords suggestions, int pos) {
+ if (DBG && pos < suggestions.size()) {
+ final SuggestedWordInfo wordInfo = suggestions.getInfo(pos);
+ if (wordInfo != null) {
+ final CharSequence debugInfo = wordInfo.getDebugString();
+ if (!TextUtils.isEmpty(debugInfo)) {
+ return debugInfo;
+ }
+ }
+ }
+ return null;
+ }
+
+ private static void setLayoutWeight(View v, float weight, int height) {
+ final ViewGroup.LayoutParams lp = v.getLayoutParams();
+ if (lp instanceof LinearLayout.LayoutParams) {
+ final LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams)lp;
+ llp.weight = weight;
+ llp.width = 0;
+ llp.height = height;
+ }
+ }
+
+ private static float getTextScaleX(CharSequence text, int maxWidth, TextPaint paint) {
+ paint.setTextScaleX(1.0f);
+ final int width = getTextWidth(text, paint);
+ if (width <= maxWidth) {
+ return 1.0f;
+ }
+ return maxWidth / (float)width;
+ }
+
+ private static CharSequence getEllipsizedText(CharSequence text, int maxWidth,
+ TextPaint paint) {
+ if (text == null) return null;
+ paint.setTextScaleX(1.0f);
+ final int width = getTextWidth(text, paint);
+ if (width <= maxWidth) {
+ return text;
+ }
+ final float scaleX = maxWidth / (float)width;
+ if (scaleX >= MIN_TEXT_XSCALE) {
+ paint.setTextScaleX(scaleX);
+ return text;
+ }
+
+ // Note that TextUtils.ellipsize() use text-x-scale as 1.0 if ellipsize is needed. To
+ // get squeezed and ellipsized text, passes enlarged width (maxWidth / MIN_TEXT_XSCALE).
+ final CharSequence ellipsized = TextUtils.ellipsize(
+ text, paint, maxWidth / MIN_TEXT_XSCALE, TextUtils.TruncateAt.MIDDLE);
+ paint.setTextScaleX(MIN_TEXT_XSCALE);
+ return ellipsized;
+ }
+
+ private static int getTextWidth(CharSequence text, TextPaint paint) {
+ if (TextUtils.isEmpty(text)) return 0;
+ final Typeface savedTypeface = paint.getTypeface();
+ paint.setTypeface(getTextTypeface(text));
+ final int len = text.length();
+ final float[] widths = new float[len];
+ final int count = paint.getTextWidths(text, 0, len, widths);
+ int width = 0;
+ for (int i = 0; i < count; i++) {
+ width += Math.round(widths[i] + 0.5f);
+ }
+ paint.setTypeface(savedTypeface);
+ return width;
+ }
+
+ private static Typeface getTextTypeface(CharSequence text) {
+ if (!(text instanceof SpannableString))
+ return Typeface.DEFAULT;
+
+ final SpannableString ss = (SpannableString)text;
+ final StyleSpan[] styles = ss.getSpans(0, text.length(), StyleSpan.class);
+ if (styles.length == 0)
+ return Typeface.DEFAULT;
+
+ switch (styles[0].getStyle()) {
+ case Typeface.BOLD: return Typeface.DEFAULT_BOLD;
+ // TODO: BOLD_ITALIC, ITALIC case?
+ default: return Typeface.DEFAULT;
+ }
+ }
}
/**
@@ -547,90 +632,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mParams.layout(mSuggestions, mSuggestionsStrip, this, getWidth());
}
- private static CharSequence getDebugInfo(SuggestedWords suggestions, int pos) {
- if (DBG && pos < suggestions.size()) {
- final SuggestedWordInfo wordInfo = suggestions.getInfo(pos);
- if (wordInfo != null) {
- final CharSequence debugInfo = wordInfo.getDebugString();
- if (!TextUtils.isEmpty(debugInfo)) {
- return debugInfo;
- }
- }
- }
- return null;
- }
-
- private static void setLayoutWeight(View v, float weight, int height) {
- final ViewGroup.LayoutParams lp = v.getLayoutParams();
- if (lp instanceof LinearLayout.LayoutParams) {
- final LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams)lp;
- llp.weight = weight;
- llp.width = 0;
- llp.height = height;
- }
- }
-
- private static float getTextScaleX(CharSequence text, int maxWidth, TextPaint paint) {
- paint.setTextScaleX(1.0f);
- final int width = getTextWidth(text, paint);
- if (width <= maxWidth) {
- return 1.0f;
- }
- return maxWidth / (float)width;
- }
-
- private static CharSequence getEllipsizedText(CharSequence text, int maxWidth,
- TextPaint paint) {
- if (text == null) return null;
- paint.setTextScaleX(1.0f);
- final int width = getTextWidth(text, paint);
- if (width <= maxWidth) {
- return text;
- }
- final float scaleX = maxWidth / (float)width;
- if (scaleX >= MIN_TEXT_XSCALE) {
- paint.setTextScaleX(scaleX);
- return text;
- }
-
- // Note that TextUtils.ellipsize() use text-x-scale as 1.0 if ellipsize is needed. To get
- // squeezed and ellipsized text, passes enlarged width (maxWidth / MIN_TEXT_XSCALE).
- final CharSequence ellipsized = TextUtils.ellipsize(
- text, paint, maxWidth / MIN_TEXT_XSCALE, TextUtils.TruncateAt.MIDDLE);
- paint.setTextScaleX(MIN_TEXT_XSCALE);
- return ellipsized;
- }
-
- private static int getTextWidth(CharSequence text, TextPaint paint) {
- if (TextUtils.isEmpty(text)) return 0;
- final Typeface savedTypeface = paint.getTypeface();
- paint.setTypeface(getTextTypeface(text));
- final int len = text.length();
- final float[] widths = new float[len];
- final int count = paint.getTextWidths(text, 0, len, widths);
- int width = 0;
- for (int i = 0; i < count; i++) {
- width += Math.round(widths[i] + 0.5f);
- }
- paint.setTypeface(savedTypeface);
- return width;
- }
-
- private static Typeface getTextTypeface(CharSequence text) {
- if (!(text instanceof SpannableString))
- return Typeface.DEFAULT;
-
- final SpannableString ss = (SpannableString)text;
- final StyleSpan[] styles = ss.getSpans(0, text.length(), StyleSpan.class);
- if (styles.length == 0)
- return Typeface.DEFAULT;
-
- switch (styles[0].getStyle()) {
- case Typeface.BOLD: return Typeface.DEFAULT_BOLD;
- // TODO: BOLD_ITALIC, ITALIC case?
- default: return Typeface.DEFAULT;
- }
- }
public boolean isShowingAddToDictionaryHint() {
return mSuggestionsStrip.getChildCount() > 0
diff --git a/java/src/com/android/inputmethod/latin/UserDictionary.java b/java/src/com/android/inputmethod/latin/UserDictionary.java
index 8c28324d8..6d6296e10 100644
--- a/java/src/com/android/inputmethod/latin/UserDictionary.java
+++ b/java/src/com/android/inputmethod/latin/UserDictionary.java
@@ -18,13 +18,10 @@ package com.android.inputmethod.latin;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
-import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.ContentObserver;
import android.database.Cursor;
-import android.net.Uri;
-import android.os.RemoteException;
import android.provider.UserDictionary.Words;
import android.text.TextUtils;
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index 64f4d058b..bfa51897e 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -118,8 +118,9 @@ public class Utils {
}
public static boolean hasMultipleEnabledIMEsOrSubtypes(
- final InputMethodManagerCompatWrapper imm,
final boolean shouldIncludeAuxiliarySubtypes) {
+ final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance();
+ if (imm == null) return false;
final List<InputMethodInfoCompatWrapper> enabledImis = imm.getEnabledInputMethodList();
// Number of the filtered IMEs
@@ -543,13 +544,13 @@ public class Utils {
final String currentDateTimeString =
new SimpleDateFormat("yyyyMMdd-HHmmssZ").format(date);
if (mFile == null) {
- Log.w(TAG, "No internal log file found.");
+ Log.w(USABILITY_TAG, "No internal log file found.");
return;
}
if (mIms.checkCallingOrSelfPermission(
android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
- Log.w(TAG, "Doesn't have the permission WRITE_EXTERNAL_STORAGE");
+ Log.w(USABILITY_TAG, "Doesn't have the permission WRITE_EXTERNAL_STORAGE");
return;
}
mWriter.flush();
@@ -563,20 +564,20 @@ public class Utils {
src.close();
dest.close();
} catch (FileNotFoundException e1) {
- Log.w(TAG, e1);
+ Log.w(USABILITY_TAG, e1);
return;
} catch (IOException e2) {
- Log.w(TAG, e2);
+ Log.w(USABILITY_TAG, e2);
return;
}
if (destFile == null || !destFile.exists()) {
- Log.w(TAG, "Dest file doesn't exist.");
+ Log.w(USABILITY_TAG, "Dest file doesn't exist.");
return;
}
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (LatinImeLogger.sDBG) {
- Log.d(TAG, "Destination file URI is " + destFile.toURI());
+ Log.d(USABILITY_TAG, "Destination file URI is " + destFile.toURI());
}
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + destPath));
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 8bbcff758..60a9685bc 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -32,15 +32,40 @@ public class WordComposer {
public static final int NOT_A_CODE = KeyDetector.NOT_A_CODE;
public static final int NOT_A_COORDINATE = -1;
- /**
- * The list of unicode values for each keystroke (including surrounding keys)
- */
- private ArrayList<int[]> mCodes;
-
- private int[] mXCoordinates;
- private int[] mYCoordinates;
+ // Storage for all the info about the current input.
+ private static class CharacterStore {
+ /**
+ * The list of unicode values for each keystroke (including surrounding keys)
+ */
+ ArrayList<int[]> mCodes;
+ int[] mXCoordinates;
+ int[] mYCoordinates;
+ StringBuilder mTypedWord;
+ CharacterStore() {
+ final int N = BinaryDictionary.MAX_WORD_LENGTH;
+ mCodes = new ArrayList<int[]>(N);
+ mTypedWord = new StringBuilder(N);
+ mXCoordinates = new int[N];
+ mYCoordinates = new int[N];
+ }
+ CharacterStore(final CharacterStore that) {
+ mCodes = new ArrayList<int[]>(that.mCodes);
+ mTypedWord = new StringBuilder(that.mTypedWord);
+ mXCoordinates = Arrays.copyOf(that.mXCoordinates, that.mXCoordinates.length);
+ mYCoordinates = Arrays.copyOf(that.mYCoordinates, that.mYCoordinates.length);
+ }
+ void reset() {
+ // For better performance than creating a new character store.
+ mCodes.clear();
+ mTypedWord.setLength(0);
+ }
+ }
- private StringBuilder mTypedWord;
+ // The currently typing word.
+ // NOTE: this is not reset as soon as the word is committed because it may be needed again
+ // to resume suggestion if backspaced. TODO: separate cleanly what is actually being
+ // composed and what is kept for possible resuming.
+ private CharacterStore mCurrentWord;
// An auto-correction for this word out of the dictionary.
private CharSequence mAutoCorrection;
@@ -56,11 +81,7 @@ public class WordComposer {
private boolean mIsFirstCharCapitalized;
public WordComposer() {
- final int N = BinaryDictionary.MAX_WORD_LENGTH;
- mCodes = new ArrayList<int[]>(N);
- mTypedWord = new StringBuilder(N);
- mXCoordinates = new int[N];
- mYCoordinates = new int[N];
+ mCurrentWord = new CharacterStore();
mTrailingSingleQuotesCount = 0;
mAutoCorrection = null;
}
@@ -70,10 +91,7 @@ public class WordComposer {
}
public void init(WordComposer source) {
- mCodes = new ArrayList<int[]>(source.mCodes);
- mTypedWord = new StringBuilder(source.mTypedWord);
- mXCoordinates = Arrays.copyOf(source.mXCoordinates, source.mXCoordinates.length);
- mYCoordinates = Arrays.copyOf(source.mYCoordinates, source.mYCoordinates.length);
+ mCurrentWord = new CharacterStore(source.mCurrentWord);
mCapsCount = source.mCapsCount;
mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
mAutoCapitalized = source.mAutoCapitalized;
@@ -85,8 +103,7 @@ public class WordComposer {
* Clear out the keys registered so far.
*/
public void reset() {
- mCodes.clear();
- mTypedWord.setLength(0);
+ mCurrentWord.reset();
mCapsCount = 0;
mIsFirstCharCapitalized = false;
mTrailingSingleQuotesCount = 0;
@@ -98,7 +115,7 @@ public class WordComposer {
* @return the number of keystrokes
*/
public final int size() {
- return mTypedWord.length();
+ return mCurrentWord.mTypedWord.length();
}
/**
@@ -107,15 +124,15 @@ public class WordComposer {
* @return the unicode for the pressed and surrounding keys
*/
public int[] getCodesAt(int index) {
- return mCodes.get(index);
+ return mCurrentWord.mCodes.get(index);
}
public int[] getXCoordinates() {
- return mXCoordinates;
+ return mCurrentWord.mXCoordinates;
}
public int[] getYCoordinates() {
- return mYCoordinates;
+ return mCurrentWord.mYCoordinates;
}
private static boolean isFirstCharCapitalized(int index, int codePoint, boolean previous) {
@@ -130,12 +147,12 @@ public class WordComposer {
*/
public void add(int primaryCode, int[] codes, int x, int y) {
final int newIndex = size();
- mTypedWord.append((char) primaryCode);
+ mCurrentWord.mTypedWord.append((char) primaryCode);
correctPrimaryJuxtapos(primaryCode, codes);
- mCodes.add(codes);
+ mCurrentWord.mCodes.add(codes);
if (newIndex < BinaryDictionary.MAX_WORD_LENGTH) {
- mXCoordinates[newIndex] = x;
- mYCoordinates[newIndex] = y;
+ mCurrentWord.mXCoordinates[newIndex] = x;
+ mCurrentWord.mYCoordinates[newIndex] = y;
}
mIsFirstCharCapitalized = isFirstCharCapitalized(
newIndex, primaryCode, mIsFirstCharCapitalized);
@@ -215,9 +232,9 @@ public class WordComposer {
final int size = size();
if (size > 0) {
final int lastPos = size - 1;
- char lastChar = mTypedWord.charAt(lastPos);
- mCodes.remove(lastPos);
- mTypedWord.deleteCharAt(lastPos);
+ char lastChar = mCurrentWord.mTypedWord.charAt(lastPos);
+ mCurrentWord.mCodes.remove(lastPos);
+ mCurrentWord.mTypedWord.deleteCharAt(lastPos);
if (Character.isUpperCase(lastChar)) mCapsCount--;
}
if (size() == 0) {
@@ -226,8 +243,8 @@ public class WordComposer {
if (mTrailingSingleQuotesCount > 0) {
--mTrailingSingleQuotesCount;
} else {
- for (int i = mTypedWord.length() - 1; i >= 0; --i) {
- if (Keyboard.CODE_SINGLE_QUOTE != mTypedWord.codePointAt(i)) break;
+ for (int i = mCurrentWord.mTypedWord.length() - 1; i >= 0; --i) {
+ if (Keyboard.CODE_SINGLE_QUOTE != mCurrentWord.mTypedWord.codePointAt(i)) break;
++mTrailingSingleQuotesCount;
}
}
@@ -239,7 +256,7 @@ public class WordComposer {
* @return the word that was typed so far. Never returns null.
*/
public String getTypedWord() {
- return mTypedWord.toString();
+ return mCurrentWord.mTypedWord.toString();
}
/**
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java b/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java
index 9a2bebfdf..2bc2cfdf6 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java
@@ -43,7 +43,7 @@ public class SpellCheckerProximityInfo {
return result;
}
- static class Latin {
+ private static class Latin {
// This is a map from the code point to the index in the PROXIMITY array.
// At the time the native code to read the binary dictionary needs the proximity info be
// passed as a flat array spaced by MAX_PROXIMITY_CHARS_SIZE columns, one for each input
@@ -62,7 +62,7 @@ public class SpellCheckerProximityInfo {
// to spell check has been entered with one of the keyboards above. Also, specifically
// to English, many spelling errors consist of the last vowel of the word being wrong
// because in English vowels tend to merge with each other in pronunciation.
- final private static int[] PROXIMITY = {
+ final static int[] PROXIMITY = {
'q', 'w', 's', 'a', 'z', NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
'w', 'q', 'a', 's', 'd', 'e', 'x', NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
'e', 'w', 's', 'd', 'f', 'r', 'a', 'i', 'o', 'u', NUL, NUL, NUL, NUL, NUL, NUL,
@@ -101,14 +101,14 @@ public class SpellCheckerProximityInfo {
static {
buildProximityIndices(PROXIMITY, INDICES);
}
- private static int getIndexOf(int characterCode) {
+ static int getIndexOf(int characterCode) {
return computeIndex(characterCode, INDICES);
}
}
- static class Cyrillic {
+ private static class Cyrillic {
final private static TreeMap<Integer, Integer> INDICES = new TreeMap<Integer, Integer>();
- final private static int[] PROXIMITY = {
+ final static int[] PROXIMITY = {
// TODO: This table is solely based on the keyboard layout. Consult with Russian
// speakers on commonly misspelled words/letters.
'ะน', 'ั†', 'ั„', 'ั‹', NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL,
@@ -150,7 +150,7 @@ public class SpellCheckerProximityInfo {
static {
buildProximityIndices(PROXIMITY, INDICES);
}
- private static int getIndexOf(int characterCode) {
+ static int getIndexOf(int characterCode) {
return computeIndex(characterCode, INDICES);
}
}