aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java64
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboard.java30
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java13
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java10
4 files changed, 67 insertions, 50 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 8ca6ade6c..52e2a6a6d 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -100,7 +100,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
// Miscellaneous constants
private static final int[] LONG_PRESSABLE_STATE_SET = { android.R.attr.state_long_pressable };
- private static final int HINT_ICON_VERTICAL_ADJUSTMENT_PIXEL = -1;
// XML attribute
private final int mKeyTextColor;
@@ -118,15 +117,21 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
private final float mBackgroundDimAmount;
private final float mKeyHysteresisDistance;
private final float mVerticalCorrection;
+ private final Drawable mPreviewBackground;
+ private final Drawable mPreviewSpacebarBackground;
+ private final int mPreviewTextColor;
+ private final float mPreviewTextRatio;
private final int mPreviewOffset;
private final int mPreviewHeight;
private final int mPopupLayout;
- private final Drawable mKeyPopupHintIcon;
private final int mKeyHintLetterColor;
private final int mKeyHintLabelColor;
private final int mKeyUppercaseLetterInactivatedColor;
private final int mKeyUppercaseLetterActivatedColor;
+ // HORIZONTAL ELLIPSIS "...", character for popup hint.
+ private static final String POPUP_HINT_CHAR = "\u2026";
+
// Main keyboard
private Keyboard mKeyboard;
private int mKeyLetterSize;
@@ -137,10 +142,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
private int mKeyHintLabelSize;
// Key preview
- private boolean mInForeground;
- private TextView mPreviewText;
- private Drawable mPreviewBackground;
- private float mPreviewTextRatio;
+ private final TextView mPreviewText;
private int mPreviewTextSize;
private boolean mShowKeyPreviewPopup = true;
private final int mDelayBeforePreview;
@@ -342,7 +344,18 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
R.styleable.KeyboardView_keyHysteresisDistance, 0);
mVerticalCorrection = a.getDimensionPixelOffset(
R.styleable.KeyboardView_verticalCorrection, 0);
+ mPreviewTextColor = a.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0);
final int previewLayout = a.getResourceId(R.styleable.KeyboardView_keyPreviewLayout, 0);
+ if (previewLayout != 0) {
+ mPreviewText = (TextView) LayoutInflater.from(context).inflate(previewLayout, null);
+ mPreviewText.setTextColor(mPreviewTextColor);
+ } else {
+ mPreviewText = null;
+ mShowKeyPreviewPopup = false;
+ }
+ mPreviewBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewBackground);
+ mPreviewSpacebarBackground = a.getDrawable(
+ R.styleable.KeyboardView_keyPreviewSpacebarBackground);
mPreviewOffset = a.getDimensionPixelOffset(R.styleable.KeyboardView_keyPreviewOffset, 0);
mPreviewHeight = a.getDimensionPixelSize(R.styleable.KeyboardView_keyPreviewHeight, 80);
mKeyLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLetterRatio);
@@ -356,7 +369,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
mKeyTextColor = a.getColor(R.styleable.KeyboardView_keyTextColor, 0xFF000000);
mKeyTextInactivatedColor = a.getColor(
R.styleable.KeyboardView_keyTextInactivatedColor, 0xFF000000);
- mKeyPopupHintIcon = a.getDrawable(R.styleable.KeyboardView_keyPopupHintIcon);
mKeyHintLetterColor = a.getColor(R.styleable.KeyboardView_keyHintLetterColor, 0);
mKeyHintLabelColor = a.getColor(R.styleable.KeyboardView_keyHintLabelColor, 0);
mKeyUppercaseLetterInactivatedColor = a.getColor(
@@ -374,12 +386,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
final Resources res = getResources();
- if (previewLayout != 0) {
- mPreviewText = (TextView) LayoutInflater.from(context).inflate(previewLayout, null);
- mPreviewBackground = mPreviewText.getBackground();
- } else {
- mShowKeyPreviewPopup = false;
- }
mDelayBeforePreview = res.getInteger(R.integer.config_delay_before_preview);
mDelayAfterPreview = res.getInteger(R.integer.config_delay_after_preview);
mKeyLabelHorizontalPadding = (int)res.getDimension(
@@ -831,19 +837,15 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
}
}
- // Draw popup hint icon "...".
- // TODO: Draw "..." by text.
+ // Draw popup hint "..." at the bottom right corner of the key.
if (key.hasPopupHint()) {
- final int drawableWidth = keyDrawWidth;
- final int drawableHeight = key.mHeight;
- final int drawableX = 0;
- final int drawableY = HINT_ICON_VERTICAL_ADJUSTMENT_PIXEL;
- final Drawable hintIcon = mKeyPopupHintIcon;
- drawIcon(canvas, hintIcon, drawableX, drawableY, drawableWidth, drawableHeight);
- if (DEBUG_SHOW_ALIGN) {
- drawRectangle(canvas, drawableX, drawableY, drawableWidth, drawableHeight,
- 0x80c0c000, new Paint());
- }
+ paint.setTextSize(mKeyHintLetterSize);
+ paint.setColor(mKeyHintLabelColor);
+ final int hintX = keyDrawWidth - getLabelCharWidth(paint);
+ // Using y-coordinate "key.mHeight - paint.descent()" draws "..." just on the bottom
+ // edge of the key. So we use slightly higher position by multiply descent length by 2.
+ final int hintY = key.mHeight - (int)paint.descent() * 2;
+ canvas.drawText(POPUP_HINT_CHAR, hintX, hintY, paint);
}
canvas.translate(-keyDrawX - kbdPaddingLeft, -key.mY - kbdPaddingTop);
@@ -928,10 +930,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
canvas.translate(-x, -y);
}
- public void setForeground(boolean foreground) {
- mInForeground = foreground;
- }
-
// TODO: clean up this method.
private void dismissAllKeyPreviews() {
for (PointerTracker tracker : mPointerTrackers) {
@@ -940,6 +938,10 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
}
}
+ public void cancelAllMessage() {
+ mHandler.cancelAllMessages();
+ }
+
@Override
public void showKeyPreview(int keyIndex, PointerTracker tracker) {
if (mShowKeyPreviewPopup) {
@@ -984,7 +986,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
// If keyIndex is invalid or IME is already closed, we must not show key preview.
// Trying to show key preview while root window is closed causes
// WindowManager.BadTokenException.
- if (key == null || !mInForeground)
+ if (key == null)
return;
mHandler.cancelAllDismissKeyPreviews();
@@ -1010,7 +1012,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
previewText.setText(null);
}
if (key.mCode == Keyboard.CODE_SPACE) {
- previewText.setBackgroundColor(Color.TRANSPARENT);
+ previewText.setBackgroundDrawable(mPreviewSpacebarBackground);
} else {
previewText.setBackgroundDrawable(mPreviewBackground);
}
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
index 00bf348f2..1966d2d65 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
@@ -216,8 +216,12 @@ public class LatinKeyboard extends Keyboard {
// Layout local language name and left and right arrow on spacebar.
private static String layoutSpacebar(Paint paint, Locale locale, Drawable icon, Drawable lArrow,
Drawable rArrow, int width, int height, float origTextSize) {
- final float arrowWidth = lArrow.getIntrinsicWidth();
- final float arrowHeight = lArrow.getIntrinsicHeight();
+ final float arrowWidth;
+ if (lArrow != null && rArrow != null) {
+ arrowWidth = lArrow.getIntrinsicWidth();
+ } else {
+ arrowWidth = 0;
+ }
final float maxTextWidth = width - (arrowWidth + arrowWidth);
final Rect bounds = new Rect();
@@ -251,14 +255,17 @@ public class LatinKeyboard extends Keyboard {
paint.setTextSize(textSize);
// Place left and right arrow just before and after language text.
- final float textHeight = -paint.ascent() + paint.descent();
- final float baseline = (icon != null) ? height * SPACEBAR_LANGUAGE_BASELINE
- : height / 2 + textHeight / 2;
- final int top = (int)(baseline - arrowHeight);
- final float remains = (width - textWidth) / 2;
- lArrow.setBounds((int)(remains - arrowWidth), top, (int)remains, (int)baseline);
- rArrow.setBounds((int)(remains + textWidth), top, (int)(remains + textWidth + arrowWidth),
- (int)baseline);
+ if (lArrow != null && rArrow != null) {
+ final float textHeight = -paint.ascent() + paint.descent();
+ final float baseline = (icon != null) ? height * SPACEBAR_LANGUAGE_BASELINE
+ : height / 2 + textHeight / 2;
+ final int arrowHeight = lArrow.getIntrinsicHeight();
+ final int top = (int)(baseline - arrowHeight);
+ final float remains = (width - textWidth) / 2;
+ lArrow.setBounds((int)(remains - arrowWidth), top, (int)remains, (int)baseline);
+ rArrow.setBounds((int)(remains + textWidth), top,
+ (int)(remains + textWidth + arrowWidth), (int)baseline);
+ }
return language;
}
@@ -323,7 +330,8 @@ public class LatinKeyboard extends Keyboard {
// Put arrows that are already laid out on either side of the text
// Because language switch is disabled on phone and number layouts, hide arrows.
// TODO: Sort out how to enable language switch on these layouts.
- if (mSubtypeSwitcher.useSpacebarLanguageSwitcher()
+ if (mSpacebarArrowLeftIcon != null && mSpacebarArrowRightIcon != null
+ && mSubtypeSwitcher.useSpacebarLanguageSwitcher()
&& mSubtypeSwitcher.getEnabledKeyboardLocaleCount() > 1
&& !(isPhoneKeyboard() || isNumberKeyboard())) {
mSpacebarArrowLeftIcon.setColorFilter(getSpacebarDrawableFilter(textFadeFactor));
diff --git a/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java b/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java
index f8c81adfb..78a3a7e9d 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java
@@ -70,12 +70,15 @@ public class SlidingLocaleDrawable extends Drawable {
mTextPaint = textPaint;
mMiddleX = (background != null) ? (mWidth - mBackground.getIntrinsicWidth()) / 2 : 0;
- final TypedArray a = context.obtainStyledAttributes(
+ final TypedArray lka = context.obtainStyledAttributes(
null, R.styleable.LatinKeyboard, R.attr.latinKeyboardStyle, R.style.LatinKeyboard);
- mSpacebarTextColor = a.getColor(R.styleable.LatinKeyboard_spacebarTextColor, 0);
- mLeftDrawable = a.getDrawable(R.styleable.LatinKeyboard_spacebarArrowPreviewLeftIcon);
- mRightDrawable = a.getDrawable(R.styleable.LatinKeyboard_spacebarArrowPreviewRightIcon);
- a.recycle();
+ mLeftDrawable = lka.getDrawable(R.styleable.LatinKeyboard_spacebarArrowPreviewLeftIcon);
+ mRightDrawable = lka.getDrawable(R.styleable.LatinKeyboard_spacebarArrowPreviewRightIcon);
+ lka.recycle();
+ final TypedArray kva = context.obtainStyledAttributes(
+ null, R.styleable.KeyboardView, R.attr.keyboardViewStyle, R.style.KeyboardView);
+ mSpacebarTextColor = kva.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0);
+ kva.recycle();
mThreshold = ViewConfiguration.get(context).getScaledTouchSlop();
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 3b840c8a1..874d77f19 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -591,7 +591,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
inputView.setProximityCorrectionEnabled(true);
// If we just entered a text field, maybe it has some old text that requires correction
mRecorrection.checkRecorrectionOnStart();
- inputView.setForeground(true);
voiceIme.onStartInputView(inputView.getWindowToken());
@@ -679,7 +678,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
public void onFinishInputView(boolean finishingInput) {
super.onFinishInputView(finishingInput);
KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
- if (inputView != null) inputView.setForeground(false);
+ if (inputView != null) inputView.cancelAllMessage();
// Remove pending messages related to update suggestions
mHandler.cancelUpdateSuggestions();
mHandler.cancelUpdateOldSuggestions();
@@ -843,7 +842,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private void setSuggestionStripShownInternal(boolean shown, boolean needsInputViewShown) {
// TODO: Modify this if we support candidates with hard keyboard
- if (onEvaluateInputViewShown()) {
+ if (onEvaluateInputViewShown() && mCandidateViewContainer != null) {
final boolean shouldShowCandidates = shown
&& (needsInputViewShown ? mKeyboardSwitcher.isInputViewShown() : true);
if (isExtractViewShown()) {
@@ -1870,6 +1869,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// Notify that language or mode have been changed and toggleLanguage will update KeyboardID
// according to new language or mode.
public void onRefreshKeyboard() {
+ if (!CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
+ // Before Honeycomb, Voice IME is in LatinIME and it changes the current input view,
+ // so that we need to re-create the keyboard input view here.
+ setInputView(mKeyboardSwitcher.onCreateInputView());
+ }
// Reload keyboard because the current language has been changed.
mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(),
mSubtypeSwitcher.isShortcutImeEnabled() && mVoiceProxy.isVoiceButtonEnabled(),