am 7c120ce4: am 3a2896c8: Fix issue space key preview remains on screen and would not dismiss

Merge commit '7c120ce4872398ea4f61a67aba1d069e45f1c012'

* commit '7c120ce4872398ea4f61a67aba1d069e45f1c012':
  Fix issue space key preview remains on screen and would not dismiss
main
Tadashi G. Takaoka 2010-09-22 00:10:16 -07:00 committed by Android Git Automerger
commit db6b897118
5 changed files with 48 additions and 30 deletions

View File

@ -16,7 +16,6 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
@ -87,7 +86,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
private static final int SYMBOLS_MODE_STATE_BEGIN = 1; private static final int SYMBOLS_MODE_STATE_BEGIN = 1;
private static final int SYMBOLS_MODE_STATE_SYMBOL = 2; private static final int SYMBOLS_MODE_STATE_SYMBOL = 2;
LatinKeyboardView mInputView; private LatinKeyboardView mInputView;
private static final int[] ALPHABET_MODES = { private static final int[] ALPHABET_MODES = {
KEYBOARDMODE_NORMAL, KEYBOARDMODE_NORMAL,
KEYBOARDMODE_URL, KEYBOARDMODE_URL,
@ -100,7 +99,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
KEYBOARDMODE_IM_WITH_SETTINGS_KEY, KEYBOARDMODE_IM_WITH_SETTINGS_KEY,
KEYBOARDMODE_WEB_WITH_SETTINGS_KEY }; KEYBOARDMODE_WEB_WITH_SETTINGS_KEY };
final LatinIME mInputMethodService; private final LatinIME mInputMethodService;
private KeyboardId mSymbolsId; private KeyboardId mSymbolsId;
private KeyboardId mSymbolsShiftedId; private KeyboardId mSymbolsShiftedId;
@ -120,7 +119,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
private int mSymbolsModeState = SYMBOLS_MODE_STATE_NONE; private int mSymbolsModeState = SYMBOLS_MODE_STATE_NONE;
// Indicates whether or not we have the settings key // Indicates whether or not we have the settings key
boolean mHasSettingsKey; private boolean mHasSettingsKey;
private static final int SETTINGS_KEY_MODE_AUTO = R.string.settings_key_mode_auto; private static final int SETTINGS_KEY_MODE_AUTO = R.string.settings_key_mode_auto;
private static final int SETTINGS_KEY_MODE_ALWAYS_SHOW = R.string.settings_key_mode_always_show; private static final int SETTINGS_KEY_MODE_ALWAYS_SHOW = R.string.settings_key_mode_always_show;
// NOTE: No need to have SETTINGS_KEY_MODE_ALWAYS_HIDE here because it's not being referred to // NOTE: No need to have SETTINGS_KEY_MODE_ALWAYS_HIDE here because it's not being referred to
@ -134,7 +133,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
private int mLayoutId; private int mLayoutId;
KeyboardSwitcher(LatinIME ims) { public KeyboardSwitcher(LatinIME ims) {
mInputMethodService = ims; mInputMethodService = ims;
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ims); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ims);
@ -153,15 +152,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
* @param locale the current input locale, or null for default locale with no locale * @param locale the current input locale, or null for default locale with no locale
* button. * button.
*/ */
void setLanguageSwitcher(LanguageSwitcher languageSwitcher) { public void setLanguageSwitcher(LanguageSwitcher languageSwitcher) {
mLanguageSwitcher = languageSwitcher; mLanguageSwitcher = languageSwitcher;
mInputLocale = mLanguageSwitcher.getInputLocale(); mInputLocale = mLanguageSwitcher.getInputLocale();
} }
void setInputView(LatinKeyboardView inputView) {
mInputView = inputView;
}
private KeyboardId makeSymbolsId(boolean hasVoice) { private KeyboardId makeSymbolsId(boolean hasVoice) {
return new KeyboardId(KBD_SYMBOLS[getCharColorId()], mHasSettingsKey ? return new KeyboardId(KBD_SYMBOLS[getCharColorId()], mHasSettingsKey ?
KEYBOARDMODE_SYMBOLS_WITH_SETTINGS_KEY : KEYBOARDMODE_SYMBOLS, KEYBOARDMODE_SYMBOLS_WITH_SETTINGS_KEY : KEYBOARDMODE_SYMBOLS,
@ -174,7 +169,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
false, hasVoice); false, hasVoice);
} }
void makeKeyboards(boolean forceCreate) { public void makeKeyboards(boolean forceCreate) {
mSymbolsId = makeSymbolsId(mHasVoice && !mVoiceOnPrimary); mSymbolsId = makeSymbolsId(mHasVoice && !mVoiceOnPrimary);
mSymbolsShiftedId = makeSymbolsShiftedId(mHasVoice && !mVoiceOnPrimary); mSymbolsShiftedId = makeSymbolsShiftedId(mHasVoice && !mVoiceOnPrimary);
@ -229,7 +224,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
} }
} }
void setVoiceMode(boolean enableVoice, boolean voiceOnPrimary) { public void setVoiceMode(boolean enableVoice, boolean voiceOnPrimary) {
if (enableVoice != mHasVoice || voiceOnPrimary != mVoiceOnPrimary) { if (enableVoice != mHasVoice || voiceOnPrimary != mVoiceOnPrimary) {
mKeyboards.clear(); mKeyboards.clear();
} }
@ -238,11 +233,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
setKeyboardMode(mMode, mImeOptions, mHasVoice, mIsSymbols); setKeyboardMode(mMode, mImeOptions, mHasVoice, mIsSymbols);
} }
boolean hasVoiceButton(boolean isSymbols) { private boolean hasVoiceButton(boolean isSymbols) {
return mHasVoice && (isSymbols != mVoiceOnPrimary); return mHasVoice && (isSymbols != mVoiceOnPrimary);
} }
void setKeyboardMode(int mode, int imeOptions, boolean enableVoice) { public void setKeyboardMode(int mode, int imeOptions, boolean enableVoice) {
mSymbolsModeState = SYMBOLS_MODE_STATE_NONE; mSymbolsModeState = SYMBOLS_MODE_STATE_NONE;
mPreferSymbols = mode == MODE_SYMBOLS; mPreferSymbols = mode == MODE_SYMBOLS;
if (mode == MODE_SYMBOLS) { if (mode == MODE_SYMBOLS) {
@ -255,7 +250,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
} }
} }
void setKeyboardMode(int mode, int imeOptions, boolean enableVoice, boolean isSymbols) { private void setKeyboardMode(int mode, int imeOptions, boolean enableVoice, boolean isSymbols) {
if (mInputView == null) return; if (mInputView == null) return;
mMode = mode; mMode = mode;
mImeOptions = imeOptions; mImeOptions = imeOptions;
@ -271,7 +266,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
if (mode == MODE_PHONE) { if (mode == MODE_PHONE) {
mInputView.setPhoneKeyboard(keyboard); mInputView.setPhoneKeyboard(keyboard);
mInputView.setPreviewEnabled(false);
} }
mCurrentId = id; mCurrentId = id;
@ -354,15 +348,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
return null; return null;
} }
int getKeyboardMode() { public int getKeyboardMode() {
return mMode; return mMode;
} }
boolean isTextMode() { public boolean isAlphabetMode() {
return mMode == MODE_TEXT;
}
boolean isAlphabetMode() {
if (mCurrentId == null) { if (mCurrentId == null) {
return false; return false;
} }
@ -375,19 +365,19 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
return false; return false;
} }
void setShifted(boolean shifted) { public void setShifted(boolean shifted) {
if (mInputView != null) { if (mInputView != null) {
mInputView.setShifted(shifted); mInputView.setShifted(shifted);
} }
} }
void setShiftLocked(boolean shiftLocked) { public void setShiftLocked(boolean shiftLocked) {
if (mInputView != null) { if (mInputView != null) {
mInputView.setShiftLocked(shiftLocked); mInputView.setShiftLocked(shiftLocked);
} }
} }
void toggleShift() { public void toggleShift() {
if (mCurrentId.equals(mSymbolsId)) { if (mCurrentId.equals(mSymbolsId)) {
LatinKeyboard symbolsShiftedKeyboard = getKeyboard(mSymbolsShiftedId); LatinKeyboard symbolsShiftedKeyboard = getKeyboard(mSymbolsShiftedId);
mCurrentId = mSymbolsShiftedId; mCurrentId = mSymbolsShiftedId;
@ -412,7 +402,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
} }
} }
void toggleSymbols() { public void toggleSymbols() {
setKeyboardMode(mMode, mImeOptions, mHasVoice, !mIsSymbols); setKeyboardMode(mMode, mImeOptions, mHasVoice, !mIsSymbols);
if (mIsSymbols && !mPreferSymbols) { if (mIsSymbols && !mPreferSymbols) {
mSymbolsModeState = SYMBOLS_MODE_STATE_BEGIN; mSymbolsModeState = SYMBOLS_MODE_STATE_BEGIN;
@ -429,7 +419,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
* Updates state machine to figure out when to automatically switch back to alpha mode. * Updates state machine to figure out when to automatically switch back to alpha mode.
* Returns true if the keyboard needs to switch back * Returns true if the keyboard needs to switch back
*/ */
boolean onKey(int key) { public boolean onKey(int key) {
// Switch back to alpha mode if user types one or more non-space/enter characters // Switch back to alpha mode if user types one or more non-space/enter characters
// followed by a space/enter // followed by a space/enter
switch (mSymbolsModeState) { switch (mSymbolsModeState) {

View File

@ -131,7 +131,7 @@ public class LatinKeyboard extends Keyboard {
R.dimen.spacebar_vertical_correction); R.dimen.spacebar_vertical_correction);
mIsAlphaKeyboard = xmlLayoutResId == R.xml.kbd_qwerty mIsAlphaKeyboard = xmlLayoutResId == R.xml.kbd_qwerty
|| xmlLayoutResId == R.xml.kbd_qwerty_black; || xmlLayoutResId == R.xml.kbd_qwerty_black;
mSpaceKeyIndex = indexOf(' '); mSpaceKeyIndex = indexOf(LatinIME.KEYCODE_SPACE);
initializeNumberHintResources(context); initializeNumberHintResources(context);
} }
@ -384,6 +384,10 @@ public class LatinKeyboard extends Keyboard {
} }
} }
public boolean isLanguageSwitchEnabled() {
return mLocale != null;
}
private void updateSpaceBarForLocale(boolean isAutoCompletion, boolean isBlack) { private void updateSpaceBarForLocale(boolean isAutoCompletion, boolean isBlack) {
// If application locales are explicitly selected. // If application locales are explicitly selected.
if (mLocale != null) { if (mLocale != null) {

View File

@ -881,8 +881,17 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
public void showPreview(int keyIndex, PointerTracker tracker) { public void showPreview(int keyIndex, PointerTracker tracker) {
int oldKeyIndex = mOldPreviewKeyIndex; int oldKeyIndex = mOldPreviewKeyIndex;
mOldPreviewKeyIndex = keyIndex; mOldPreviewKeyIndex = keyIndex;
// If key changed and preview is on ... final boolean isLanguageSwitchEnabled = (mKeyboard instanceof LatinKeyboard)
if (oldKeyIndex != keyIndex && mShowPreview) { && ((LatinKeyboard)mKeyboard).isLanguageSwitchEnabled();
// We should re-draw popup preview when 1) we need to hide the preview, 2) we will show
// the space key preview and 3) pointer moves off the space key to other letter key, we
// should hide the preview of the previous key.
final boolean hidePreviewOrShowSpaceKeyPreview = (tracker == null)
|| tracker.isSpaceKey(keyIndex) || tracker.isSpaceKey(oldKeyIndex);
// If key changed and preview is on or the key is space (language switch is enabled)
if (oldKeyIndex != keyIndex
&& (mShowPreview
|| (hidePreviewOrShowSpaceKeyPreview && isLanguageSwitchEnabled))) {
if (keyIndex == NOT_A_KEY) { if (keyIndex == NOT_A_KEY) {
mHandler.cancelPopupPreview(); mHandler.cancelPopupPreview();
mHandler.dismissPreview(DELAY_AFTER_PREVIEW); mHandler.dismissPreview(DELAY_AFTER_PREVIEW);

View File

@ -65,6 +65,16 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
mPhoneKeyboard = phoneKeyboard; mPhoneKeyboard = phoneKeyboard;
} }
@Override
public void setPreviewEnabled(boolean previewEnabled) {
if (getKeyboard() == mPhoneKeyboard) {
// Phone keyboard never shows popup preview (except language switch).
super.setPreviewEnabled(false);
} else {
super.setPreviewEnabled(previewEnabled);
}
}
@Override @Override
public void setKeyboard(Keyboard k) { public void setKeyboard(Keyboard k) {
super.setKeyboard(k); super.setKeyboard(k);

View File

@ -140,6 +140,11 @@ public class PointerTracker {
return isModifierInternal(mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null)); return isModifierInternal(mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null));
} }
public boolean isSpaceKey(int keyIndex) {
Key key = getKey(keyIndex);
return key != null && key.codes[0] == LatinIME.KEYCODE_SPACE;
}
public void updateKey(int keyIndex) { public void updateKey(int keyIndex) {
if (mKeyAlreadyProcessed) if (mKeyAlreadyProcessed)
return; return;