Merge "Fix auto correction spacebar LED"

This commit is contained in:
Tadashi G. Takaoka 2011-12-15 03:19:32 -08:00 committed by Android (Google) Code Review
commit c3ef86d861
8 changed files with 82 additions and 73 deletions

View file

@ -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 -->

View file

@ -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

View file

@ -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);

View file

@ -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;
}

View file

@ -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.

View file

@ -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(
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,
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,8 +370,8 @@ 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,
setSpacebarTextFadeFactor(inputView,
needsToDisplayLanguage ? 1.0f : mFinalFadeoutFactorOfLanguageOnSpacebar,
keyboard);
}
// The fadeout animation will start when the delay is positive.
@ -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;
}

View file

@ -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();
}
//////////////////////////////////

View file

@ -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