aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2011-12-15 16:09:42 +0900
committerTadashi G. Takaoka <takaoka@google.com>2011-12-15 17:34:14 +0900
commit23d27fefcbfe04df8f8762d5d50117a58fb011e9 (patch)
tree1733a84a3da89b9e41b0aeb7c03ac85ba7493575 /java/src
parent5a39e527dde07cc4360234553c9bb75694ece1ef (diff)
downloadlatinime-23d27fefcbfe04df8f8762d5d50117a58fb011e9.tar.gz
latinime-23d27fefcbfe04df8f8762d5d50117a58fb011e9.tar.xz
latinime-23d27fefcbfe04df8f8762d5d50117a58fb011e9.zip
Fix auto correction spacebar LED
Change-Id: I4894d188d5612380cc9f8eec7cb72544e37fb2b0
Diffstat (limited to 'java/src')
-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/LatinIME.java37
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java7
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java3
6 files changed, 80 insertions, 70 deletions
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 e56f2ea84..376f4c7c3 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -374,15 +374,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/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 98fea1b5b..a0c59671f 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/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index 64f4d058b..a134647f2 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