diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index 0989dbdd3..3d107198e 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -16,6 +16,8 @@ package com.android.inputmethod.latin; +import com.android.inputmethod.latin.BaseKeyboard.Key; + import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; @@ -29,8 +31,6 @@ import android.graphics.Rect; import android.graphics.Region.Op; import android.graphics.Typeface; import android.graphics.drawable.Drawable; -import android.inputmethodservice.Keyboard; -import android.inputmethodservice.Keyboard.Key; import android.os.Handler; import android.os.Message; import android.os.SystemClock; @@ -176,7 +176,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx private int mPopupLayout; // Main keyboard - private Keyboard mKeyboard; + private BaseKeyboard mKeyboard; private Key[] mKeys; // Key preview popup @@ -565,7 +565,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx * @see #getKeyboard() * @param keyboard the keyboard to display in this view */ - public void setKeyboard(Keyboard keyboard) { + public void setKeyboard(BaseKeyboard keyboard) { if (mKeyboard != null) { dismissKeyPreview(); } @@ -577,7 +577,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx mKeys = mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); for (PointerTracker tracker : mPointerTrackers) { - tracker.setKeyboard(mKeys, mKeyHysteresisDistance); + tracker.setKeyboard(keyboard, mKeys, mKeyHysteresisDistance); } requestLayout(); // Hint to reallocate the buffer if the size changed @@ -592,7 +592,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx * @return the currently attached keyboard * @see #setKeyboard(Keyboard) */ - public Keyboard getKeyboard() { + public BaseKeyboard getKeyboard() { return mKeyboard; } @@ -712,7 +712,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx * the touch distance from a key's center to avoid taking a square root. * @param keyboard */ - private void computeProximityThreshold(Keyboard keyboard) { + private void computeProximityThreshold(BaseKeyboard keyboard) { if (keyboard == null) return; final Key[] keys = mKeys; if (keys == null) return; @@ -801,8 +801,19 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop); keyBackground.draw(canvas); - boolean shouldDrawIcon = true; + boolean drawHintIcon = true; if (label != null) { + // If keyboard is multi-touch capable and in temporary upper case state and key has + // tempoarary shift label, label should be hint character and hint icon should not + // be drawn. + if (mHasDistinctMultitouch + && mKeyboard instanceof LatinKeyboard + && ((LatinKeyboard)mKeyboard).isTemporaryUpperCase() + && key.temporaryShiftLabel != null) { + label = key.temporaryShiftLabel.toString(); + drawHintIcon = false; + } + // For characters, use large font. For labels like "Done", use small font. if (label.length() > 1 && key.codes.length < 2) { paint.setTextSize(mLabelTextSize); @@ -822,25 +833,26 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx paint); // Turn off drop shadow paint.setShadowLayer(0, 0, 0, 0); - - // Usually don't draw icon if label is not null, but we draw icon for the number - // hint. - shouldDrawIcon = isNumberAtEdgeOfPopupChars(key); } - if (key.icon != null && shouldDrawIcon) { - // Special handing for the upper-right number hint icons - final int drawableWidth = isNumberAtEdgeOfPopupChars(key) ? - key.width : key.icon.getIntrinsicWidth(); - final int drawableHeight = isNumberAtEdgeOfPopupChars(key) ? - key.height : key.icon.getIntrinsicHeight(); + Drawable icon = null; + if (key.label == null && key.icon != null) + icon = key.icon; + if (icon == null && key.hintIcon != null && drawHintIcon) + icon = key.hintIcon; + if (icon != null) { + // Hack for key hint icon displaying at the top right corner of the key. + final int drawableWidth = icon == key.hintIcon + ? key.width : icon.getIntrinsicWidth(); + final int drawableHeight = icon == key.hintIcon + ? key.height : icon.getIntrinsicHeight(); final int drawableX = (key.width - padding.left - padding.right - drawableWidth) / 2 + padding.left; final int drawableY = (key.height - padding.top - padding.bottom - drawableHeight) / 2 + padding.top; canvas.translate(drawableX, drawableY); - key.icon.setBounds(0, 0, drawableWidth, drawableHeight); - key.icon.draw(canvas); + icon.setBounds(0, 0, drawableWidth, drawableHeight); + icon.draw(canvas); canvas.translate(-drawableX, -drawableY); } canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop); @@ -905,16 +917,18 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx } } + // TODO Must fix popup preview on xlarge layout private void showKey(final int keyIndex, PointerTracker tracker) { Key key = tracker.getKey(keyIndex); if (key == null) return; // Should not draw number hint icons - if (key.icon != null && !isNumberAtEdgeOfPopupChars(key)) { + if (key.icon != null && key.label == null) { mPreviewText.setCompoundDrawables(null, null, null, key.iconPreview != null ? key.iconPreview : key.icon); mPreviewText.setText(null); } else { + // TODO Should take care of temporaryShiftLabel here. mPreviewText.setCompoundDrawables(null, null, null, null); mPreviewText.setText(adjustCase(tracker.getPreviewText(key))); if (key.label.length() > 1 && key.codes.length < 2) { @@ -996,7 +1010,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx * Invalidates a key so that it will be redrawn on the next repaint. Use this method if only * one key is changing it's content. Any changes that affect the position or size of the key * may not be honored. - * @param key key in the attached {@link Keyboard}. + * @param key key in the attached {@link BaseKeyboard}. * @see #invalidateAllKeys */ public void invalidateKey(Key key) { @@ -1071,12 +1085,12 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx // Override default ProximityKeyDetector. miniKeyboard.mKeyDetector = new MiniKeyboardKeyDetector(mMiniKeyboardSlideAllowance); - Keyboard keyboard; + BaseKeyboard keyboard; if (popupKey.popupCharacters != null) { - keyboard = new Keyboard(getContext(), popupKeyboardId, popupKey.popupCharacters, + keyboard = new BaseKeyboard(getContext(), popupKeyboardId, popupKey.popupCharacters, -1, getPaddingLeft() + getPaddingRight()); } else { - keyboard = new Keyboard(getContext(), popupKeyboardId); + keyboard = new BaseKeyboard(getContext(), popupKeyboardId); } miniKeyboard.setKeyboard(keyboard); miniKeyboard.setPopupParent(this); @@ -1096,7 +1110,8 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx // and bottom edge flags on. // When you want to use one row mini-keyboard from xml file, make sure that the row has // both top and bottom edge flags set. - return (edgeFlags & Keyboard.EDGE_TOP) != 0 && (edgeFlags & Keyboard.EDGE_BOTTOM) != 0; + return (edgeFlags & BaseKeyboard.EDGE_TOP) != 0 + && (edgeFlags & BaseKeyboard.EDGE_BOTTOM) != 0; } /** @@ -1190,11 +1205,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx return false; } - private static boolean isNumberAtEdgeOfPopupChars(Key key) { - return isNumberAtLeftmostPopupChar(key) || isNumberAtRightmostPopupChar(key); - } - - /* package */ static boolean isNumberAtLeftmostPopupChar(Key key) { + private static boolean isNumberAtLeftmostPopupChar(Key key) { if (key.popupCharacters != null && key.popupCharacters.length() > 0 && isAsciiDigit(key.popupCharacters.charAt(0))) { return true; @@ -1202,14 +1213,6 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx return false; } - /* package */ static boolean isNumberAtRightmostPopupChar(Key key) { - if (key.popupCharacters != null && key.popupCharacters.length() > 0 - && isAsciiDigit(key.popupCharacters.charAt(key.popupCharacters.length() - 1))) { - return true; - } - return false; - } - private static boolean isAsciiDigit(char c) { return (c < 0x80) && Character.isDigit(c); } @@ -1229,7 +1232,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx final PointerTracker tracker = new PointerTracker(i, mHandler, mKeyDetector, this, getResources()); if (keys != null) - tracker.setKeyboard(keys, mKeyHysteresisDistance); + tracker.setKeyboard(mKeyboard, keys, mKeyHysteresisDistance); if (listener != null) tracker.setOnKeyboardActionListener(listener); pointers.add(tracker); |