From 11b7febc0bea46a6afb30d7fa040b841eadd7410 Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Tue, 9 Aug 2011 19:50:21 +0900 Subject: [PATCH] Ellipsis for "Space" key for triggering the IME switcher bug:5136497 Change-Id: Iab7c68135500e9fed212521484090b52943550ca --- .../src/com/android/inputmethod/keyboard/Key.java | 10 ++++++++++ .../inputmethod/keyboard/KeyboardView.java | 3 ++- .../inputmethod/keyboard/LatinKeyboard.java | 15 +++++++++++++-- .../com/android/inputmethod/latin/LatinIME.java | 6 ++---- java/src/com/android/inputmethod/latin/Utils.java | 5 +++-- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 4cc0bba6a..397b7b16b 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -113,6 +113,8 @@ public class Key { private boolean mHighlightOn; /** Key is enabled and responds on press */ private boolean mEnabled = true; + /** Whether this key needs to show the "..." popup hint for special purposes */ + private boolean mNeedsSpecialPopupHint; // keyWidth constants private static final int KEYWIDTH_FILL_RIGHT = 0; @@ -402,6 +404,14 @@ public class Key { return (mLabelOption & LABEL_OPTION_HAS_POPUP_HINT) != 0; } + public void setNeedsSpecialPopupHint(boolean needsSpecialPopupHint) { + mNeedsSpecialPopupHint = needsSpecialPopupHint; + } + + public boolean needsSpecialPopupHint() { + return mNeedsSpecialPopupHint; + } + public boolean hasUppercaseLetter() { return (mLabelOption & LABEL_OPTION_HAS_UPPERCASE_LETTER) != 0; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index da3aa50c5..2df2994f6 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -657,7 +657,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } // Draw popup hint "..." at the bottom right corner of the key. - if (key.hasPopupHint() && key.mPopupCharacters != null && key.mPopupCharacters.length > 0) { + if ((key.hasPopupHint() && key.mPopupCharacters != null && key.mPopupCharacters.length > 0) + || key.needsSpecialPopupHint()) { paint.setTextSize(params.mKeyHintLetterSize); paint.setColor(params.mKeyHintLabelColor); paint.setTextAlign(Align.CENTER); diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 3cba5295e..1b6f57b92 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -31,10 +31,12 @@ 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.lang.ref.SoftReference; import java.util.Arrays; @@ -59,6 +61,7 @@ public class LatinKeyboard extends Keyboard { private float mSpacebarTextFadeFactor = 0.0f; private final HashMap> mSpaceDrawableCache = new HashMap>(); + private final boolean mIsSpacebarTriggeringPopupByLongPress; /* Shortcut key and its icons if available */ private final Key mShortcutKey; @@ -85,6 +88,9 @@ public class LatinKeyboard extends Keyboard { mShortcutKey = params.mShortcutKey; 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( null, R.styleable.LatinKeyboard, R.attr.latinKeyboardStyle, R.style.LatinKeyboard); @@ -179,8 +185,13 @@ public class LatinKeyboard extends Keyboard { } private void updateSpacebarForLocale(boolean isAutoCorrection) { - if (mSpaceKey == null) - return; + 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 */); + mSpaceKey.setNeedsSpecialPopupHint(shouldShowInputMethodPicker); // If application locales are explicitly selected. if (mSubtypeSwitcher.needsToDisplayLanguage()) { mSpaceKey.setIcon(getSpaceDrawable( diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index d74babf4f..c28e40d95 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1181,8 +1181,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 /* should exclude auxiliary subtypes */)) { + } else if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm, false /* exclude aux subtypes */)) { showOptionsMenu(); } else { launchSettings(); @@ -1197,8 +1196,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 /* should include auxiliary subtypes */)) { + if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm, true /* include aux subtypes */)) { mImm.showInputMethodPicker(); return true; } diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index c07793c33..1a6260a4e 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -111,8 +111,9 @@ public class Utils { } } - public static boolean hasMultipleEnabledIMEsOrSubtypes(InputMethodManagerCompatWrapper imm, - boolean shouldIncludeAuxiliarySubtypes) { + public static boolean hasMultipleEnabledIMEsOrSubtypes( + final InputMethodManagerCompatWrapper imm, + final boolean shouldIncludeAuxiliarySubtypes) { final List enabledImis = imm.getEnabledInputMethodList(); // Number of the filtered IMEs