Get rid of Key.needsSpecialPopupHint and related

Change-Id: I28e87ea3af9581f12094770b42f113e9018886c4
main
Tadashi G. Takaoka 2011-12-18 03:06:20 +09:00
parent bc781e963f
commit 22b48de11c
6 changed files with 30 additions and 25 deletions

View File

@ -125,8 +125,6 @@ public class Key {
private boolean mHighlightOn; private boolean mHighlightOn;
/** Key is enabled and responds on press */ /** Key is enabled and responds on press */
private boolean mEnabled = true; private boolean mEnabled = true;
/** Whether this key needs to show the "..." popup hint for special purposes */
private boolean mNeedsSpecialPopupHint;
// RTL parenthesis character swapping map. // RTL parenthesis character swapping map.
private static final Map<Integer, Integer> sRtlParenthesisMap = new HashMap<Integer, Integer>(); private static final Map<Integer, Integer> sRtlParenthesisMap = new HashMap<Integer, Integer>();
@ -449,14 +447,6 @@ public class Key {
return (mLabelFlags & LABEL_FLAGS_HAS_POPUP_HINT) != 0; return (mLabelFlags & LABEL_FLAGS_HAS_POPUP_HINT) != 0;
} }
public void setNeedsSpecialPopupHint(boolean needsSpecialPopupHint) {
mNeedsSpecialPopupHint = needsSpecialPopupHint;
}
public boolean needsSpecialPopupHint() {
return mNeedsSpecialPopupHint;
}
public boolean hasUppercaseLetter() { public boolean hasUppercaseLetter() {
return (mLabelFlags & LABEL_FLAGS_HAS_UPPERCASE_LETTER) != 0; return (mLabelFlags & LABEL_FLAGS_HAS_UPPERCASE_LETTER) != 0;
} }

View File

@ -165,8 +165,8 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
// If the cached keyboard had been switched to another keyboard while the language was // 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 // 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. // case, we should reset the text fade factor. It is also applicable to shortcut key.
mKeyboardView.updateSpacebar();
latinKeyboard.updateSpacebarLanguage(0.0f, latinKeyboard.updateSpacebarLanguage(0.0f,
Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */),
mSubtypeSwitcher.needsToDisplayLanguage(latinKeyboard.mId.mLocale)); mSubtypeSwitcher.needsToDisplayLanguage(latinKeyboard.mId.mLocale));
latinKeyboard.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady()); latinKeyboard.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
} }

View File

@ -712,8 +712,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
} }
if ((key.hasPopupHint() && key.mMoreKeys != null && key.mMoreKeys.length > 0) if (key.hasPopupHint() && key.mMoreKeys != null && key.mMoreKeys.length > 0) {
|| key.needsSpecialPopupHint()) {
drawKeyPopupHint(key, canvas, paint, params); drawKeyPopupHint(key, canvas, paint, params);
} }
} }

View File

@ -55,10 +55,8 @@ public class LatinKeyboard extends Keyboard {
private final int mSpacebarTextShadowColor; private final int mSpacebarTextShadowColor;
private final HashMap<Integer, BitmapDrawable> mSpaceDrawableCache = private final HashMap<Integer, BitmapDrawable> mSpaceDrawableCache =
new HashMap<Integer, BitmapDrawable>(); new HashMap<Integer, BitmapDrawable>();
private final boolean mIsSpacebarTriggeringPopupByLongPress;
private boolean mAutoCorrectionSpacebarLedOn; private boolean mAutoCorrectionSpacebarLedOn;
private boolean mMultipleEnabledIMEsOrSubtypes;
private boolean mNeedsToDisplayLanguage; private boolean mNeedsToDisplayLanguage;
private float mSpacebarTextFadeFactor = 0.0f; private float mSpacebarTextFadeFactor = 0.0f;
@ -83,9 +81,6 @@ public class LatinKeyboard extends Keyboard {
mShortcutKey = getKey(CODE_SHORTCUT); mShortcutKey = getKey(CODE_SHORTCUT);
mEnabledShortcutIcon = (mShortcutKey != null) ? mShortcutKey.getIcon() : null; mEnabledShortcutIcon = (mShortcutKey != null) ? mShortcutKey.getIcon() : null;
final int longPressSpaceKeyTimeout =
mRes.getInteger(R.integer.config_long_press_space_key_timeout);
mIsSpacebarTriggeringPopupByLongPress = (longPressSpaceKeyTimeout > 0);
final TypedArray a = context.obtainStyledAttributes( final TypedArray a = context.obtainStyledAttributes(
null, R.styleable.LatinKeyboard, R.attr.latinKeyboardStyle, R.style.LatinKeyboard); null, R.styleable.LatinKeyboard, R.attr.latinKeyboardStyle, R.style.LatinKeyboard);
@ -123,10 +118,8 @@ public class LatinKeyboard extends Keyboard {
// TODO: Move this drawing method to LatinKeyboardView. // TODO: Move this drawing method to LatinKeyboardView.
// TODO: Use Key.keyLabel to draw language name of spacebar. // TODO: Use Key.keyLabel to draw language name of spacebar.
public Key updateSpacebarLanguage(float fadeFactor, boolean multipleEnabledIMEsOrSubtypes, public Key updateSpacebarLanguage(float fadeFactor, boolean needsToDisplayLanguage) {
boolean needsToDisplayLanguage) {
mSpacebarTextFadeFactor = fadeFactor; mSpacebarTextFadeFactor = fadeFactor;
mMultipleEnabledIMEsOrSubtypes = multipleEnabledIMEsOrSubtypes;
mNeedsToDisplayLanguage = needsToDisplayLanguage; mNeedsToDisplayLanguage = needsToDisplayLanguage;
updateSpacebarIcon(); updateSpacebarIcon();
return mSpaceKey; return mSpaceKey;
@ -173,9 +166,6 @@ public class LatinKeyboard extends Keyboard {
private void updateSpacebarIcon() { private void updateSpacebarIcon() {
if (mSpaceKey == null) return; if (mSpaceKey == null) return;
final boolean shouldShowInputMethodPicker = mIsSpacebarTriggeringPopupByLongPress
&& mMultipleEnabledIMEsOrSubtypes;
mSpaceKey.setNeedsSpecialPopupHint(shouldShowInputMethodPicker);
if (mNeedsToDisplayLanguage) { if (mNeedsToDisplayLanguage) {
mSpaceKey.setIcon(getSpaceDrawable(mId.mLocale)); mSpaceKey.setIcon(getSpaceDrawable(mId.mLocale));
} else if (mAutoCorrectionSpacebarLedOn) { } else if (mAutoCorrectionSpacebarLedOn) {

View File

@ -20,6 +20,7 @@ import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Message; import android.os.Message;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -60,6 +61,10 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
private static final boolean ENABLE_CAPSLOCK_BY_DOUBLETAP = true; private static final boolean ENABLE_CAPSLOCK_BY_DOUBLETAP = true;
// For drawing spacebar.
private final boolean mIsSpacebarTriggeringPopupByLongPress;
private boolean mMultipleEnabledIMEsOrSubtypes;
private final SuddenJumpingTouchEventHandler mTouchScreenRegulator; private final SuddenJumpingTouchEventHandler mTouchScreenRegulator;
// Timing constants // Timing constants
@ -247,6 +252,10 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
mKeyRepeatInterval = res.getInteger(R.integer.config_key_repeat_interval); mKeyRepeatInterval = res.getInteger(R.integer.config_key_repeat_interval);
PointerTracker.init(mHasDistinctMultitouch, getContext()); PointerTracker.init(mHasDistinctMultitouch, getContext());
final int longPressSpaceKeyTimeout =
res.getInteger(R.integer.config_long_press_space_key_timeout);
mIsSpacebarTriggeringPopupByLongPress = (longPressSpaceKeyTimeout > 0);
} }
public void startIgnoringDoubleTap() { public void startIgnoringDoubleTap() {
@ -685,4 +694,21 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
// Reflection doesn't support calling superclass methods. // Reflection doesn't support calling superclass methods.
return false; return false;
} }
public void updateSpacebar() {
mMultipleEnabledIMEsOrSubtypes = Utils.hasMultipleEnabledIMEsOrSubtypes(
true /* include aux subtypes */);
}
@Override
/* package */ void onDrawKeyTopVisuals(Key key, Canvas canvas, Paint paint,
KeyDrawParams params) {
super.onDrawKeyTopVisuals(key, canvas, paint, params);
// Whether space key needs to show the "..." popup hint for special purposes
if (key.mCode == Keyboard.CODE_SPACE && mIsSpacebarTriggeringPopupByLongPress
&& mMultipleEnabledIMEsOrSubtypes) {
super.drawKeyPopupHint(key, canvas, paint, params);
}
}
} }

View File

@ -344,9 +344,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (inputView == null) return; if (inputView == null) return;
final Keyboard keyboard = inputView.getKeyboard(); final Keyboard keyboard = inputView.getKeyboard();
if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) { if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) {
inputView.updateSpacebar();
final Key updatedKey = ((LatinKeyboard)keyboard).updateSpacebarLanguage( final Key updatedKey = ((LatinKeyboard)keyboard).updateSpacebarLanguage(
fadeFactor, fadeFactor,
Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */),
SubtypeSwitcher.getInstance().needsToDisplayLanguage(keyboard.mId.mLocale)); SubtypeSwitcher.getInstance().needsToDisplayLanguage(keyboard.mId.mLocale));
inputView.invalidateKey(updatedKey); inputView.invalidateKey(updatedKey);
} }