aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java140
1 files changed, 71 insertions, 69 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java
index b1b82b64d..b02780bf6 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;
@@ -43,6 +43,7 @@ import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
+import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.TextView;
@@ -178,12 +179,13 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
private int mPopupLayout;
// Main keyboard
- private Keyboard mKeyboard;
+ private BaseKeyboard mKeyboard;
private Key[] mKeys;
// TODO this attribute should be gotten from Keyboard.
private int mKeyboardVerticalGap;
// Key preview popup
+ private boolean mInForeground;
private TextView mPreviewText;
private PopupWindow mPreviewPopup;
private int mPreviewTextSizeLarge;
@@ -224,7 +226,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
protected KeyDetector mKeyDetector = new ProximityKeyDetector();
// Swipe gesture detector
- private final GestureDetector mGestureDetector;
+ private GestureDetector mGestureDetector;
private final SwipeTracker mSwipeTracker = new SwipeTracker();
private final int mSwipeThreshold;
private final boolean mDisambiguateSwipe;
@@ -573,11 +575,11 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
/**
* Attaches a keyboard to this view. The keyboard can be switched at any time and the
* view will re-layout itself to accommodate the keyboard.
- * @see Keyboard
+ * @see BaseKeyboard
* @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();
}
@@ -590,7 +592,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
-getPaddingTop() + mVerticalCorrection);
mKeyboardVerticalGap = (int)getResources().getDimension(R.dimen.key_bottom_gap);
for (PointerTracker tracker : mPointerTrackers) {
- tracker.setKeyboard(mKeys, mKeyHysteresisDistance);
+ tracker.setKeyboard(keyboard, mKeys, mKeyHysteresisDistance);
}
requestLayout();
// Hint to reallocate the buffer if the size changed
@@ -603,9 +605,9 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
/**
* Returns the current keyboard being displayed by this view.
* @return the currently attached keyboard
- * @see #setKeyboard(Keyboard)
+ * @see #setKeyboard(BaseKeyboard)
*/
- public Keyboard getKeyboard() {
+ public BaseKeyboard getKeyboard() {
return mKeyboard;
}
@@ -725,7 +727,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;
@@ -814,8 +816,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.
final int labelSize;
if (label.length() > 1 && key.codes.length < 2) {
@@ -847,18 +860,19 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
canvas.drawText(label, centerX, baseline, 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 = isNonMicLatinF1KeyOrNumberAtEdgeOfPopupChars(key);
}
- if (key.icon != null && shouldDrawIcon) {
+ 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) {
// Special handing for the upper-right number hint icons
final int drawableWidth;
final int drawableHeight;
final int drawableX;
final int drawableY;
- if (isLatinF1KeyOrNumberAtEdgeOfPopupChars(key)) {
+ if (icon == key.hintIcon) {
drawableWidth = key.width;
drawableHeight = key.height;
drawableX = 0;
@@ -866,14 +880,12 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
} else {
drawableWidth = key.icon.getIntrinsicWidth();
drawableHeight = key.icon.getIntrinsicHeight();
- drawableX = (key.width - padding.left - padding.right - drawableWidth)
- / 2 + padding.left;
- drawableY = (key.height - padding.top - padding.bottom - drawableHeight)
- / 2 + padding.top;
+ drawableX = (key.width + padding.left - padding.right - drawableWidth) / 2;
+ drawableY = (key.height + padding.top - padding.bottom - drawableHeight) / 2;
}
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);
@@ -908,6 +920,10 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
mDirtyRect.setEmpty();
}
+ public void setForeground(boolean foreground) {
+ mInForeground = foreground;
+ }
+
// TODO: clean up this method.
private void dismissKeyPreview() {
for (PointerTracker tracker : mPointerTrackers)
@@ -938,16 +954,21 @@ 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)
+ // If keyIndex is invalid or IME is already closed, we must not show key preview.
+ // Trying to show preview PopupWindow while root window is closed causes
+ // WindowManager.BadTokenException.
+ if (key == null || !mInForeground)
return;
// Should not draw number hint icons
- if (key.icon != null && !isNonMicLatinF1KeyOrNumberAtEdgeOfPopupChars(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) {
@@ -1000,13 +1021,18 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
popupPreviewY += popupHeight;
}
- if (mPreviewPopup.isShowing()) {
- mPreviewPopup.update(popupPreviewX, popupPreviewY, popupWidth, popupHeight);
- } else {
- mPreviewPopup.setWidth(popupWidth);
- mPreviewPopup.setHeight(popupHeight);
- mPreviewPopup.showAtLocation(mMiniKeyboardParent, Gravity.NO_GRAVITY,
- popupPreviewX, popupPreviewY);
+ try {
+ if (mPreviewPopup.isShowing()) {
+ mPreviewPopup.update(popupPreviewX, popupPreviewY, popupWidth, popupHeight);
+ } else {
+ mPreviewPopup.setWidth(popupWidth);
+ mPreviewPopup.setHeight(popupHeight);
+ mPreviewPopup.showAtLocation(mMiniKeyboardParent, Gravity.NO_GRAVITY,
+ popupPreviewX, popupPreviewY);
+ }
+ } catch (WindowManager.BadTokenException e) {
+ // Swallow the exception which will be happened when IME is already closed.
+ Log.w(TAG, "LatinIME is already closed when tried showing key preview.");
}
// Record popup preview position to display mini-keyboard later at the same positon
mPopupPreviewDisplayedY = popupPreviewY;
@@ -1029,7 +1055,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) {
@@ -1106,13 +1132,15 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
});
// Override default ProximityKeyDetector.
miniKeyboard.mKeyDetector = new MiniKeyboardKeyDetector(mMiniKeyboardSlideAllowance);
+ // Remove gesture detector on mini-keyboard
+ miniKeyboard.mGestureDetector = null;
- 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);
@@ -1132,7 +1160,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;
}
/**
@@ -1226,27 +1255,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
return false;
}
- private boolean isLatinF1KeyOrNumberAtEdgeOfPopupChars(Key key) {
- return isNumberAtEdgeOfPopupChars(key) || isLatinF1Key(key);
- }
-
- private boolean isNonMicLatinF1KeyOrNumberAtEdgeOfPopupChars(Key key) {
- return isNumberAtEdgeOfPopupChars(key) || isNonMicLatinF1Key(key);
- }
-
- private boolean isLatinF1Key(Key key) {
- return (mKeyboard instanceof LatinKeyboard) && ((LatinKeyboard)mKeyboard).isF1Key(key);
- }
-
- private boolean isNonMicLatinF1Key(Key key) {
- return isLatinF1Key(key) && key.label != null;
- }
-
- 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;
@@ -1254,14 +1263,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);
}
@@ -1281,7 +1282,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);
@@ -1305,8 +1306,9 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
// Track the last few movements to look for spurious swipes.
mSwipeTracker.addMovement(me);
- // We must disable gesture detector while mini-keyboard is on the screen.
- if (mMiniKeyboard == null && mGestureDetector.onTouchEvent(me)) {
+ // Gesture detector must be enabled only when mini-keyboard is not on the screen.
+ if (mMiniKeyboard == null
+ && mGestureDetector != null && mGestureDetector.onTouchEvent(me)) {
dismissKeyPreview();
mHandler.cancelKeyTimers();
return true;