aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/MainKeyboardView.java')
-rw-r--r--java/src/com/android/inputmethod/keyboard/MainKeyboardView.java451
1 files changed, 410 insertions, 41 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index 625575d53..83b37f1b1 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -32,13 +32,17 @@ import android.os.Message;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
+import android.util.DisplayMetrics;
import android.util.Log;
+import android.util.SparseArray;
+import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodSubtype;
+import android.widget.TextView;
import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
@@ -46,7 +50,10 @@ import com.android.inputmethod.annotations.ExternallyReferenced;
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
+import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams;
+import com.android.inputmethod.keyboard.internal.PreviewPlacerView;
import com.android.inputmethod.keyboard.internal.TouchScreenRegulator;
+import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.CoordinateUtils;
import com.android.inputmethod.latin.DebugSettings;
@@ -57,6 +64,7 @@ import com.android.inputmethod.latin.ResourceUtils;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
import com.android.inputmethod.latin.StringUtils;
import com.android.inputmethod.latin.SubtypeLocale;
+import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.research.ResearchLogger;
@@ -85,7 +93,13 @@ import java.util.WeakHashMap;
* @attr ref R.styleable#MainKeyboardView_longPressKeyTimeout
* @attr ref R.styleable#MainKeyboardView_longPressShiftKeyTimeout
* @attr ref R.styleable#MainKeyboardView_ignoreAltCodeKeyTimeout
+ * @attr ref R.styleable#MainKeyboardView_keyPreviewLayout
+ * @attr ref R.styleable#MainKeyboardView_keyPreviewOffset
+ * @attr ref R.styleable#MainKeyboardView_keyPreviewHeight
+ * @attr ref R.styleable#MainKeyboardView_keyPreviewLingerTimeout
+ * @attr ref R.styleable#MainKeyboardView_moreKeysKeyboardLayout
* @attr ref R.styleable#MainKeyboardView_showMoreKeysKeyboardAtTouchPoint
+ * @attr ref R.styleable#MainKeyboardView_gestureFloatingPreviewTextLingerTimeout
* @attr ref R.styleable#MainKeyboardView_gestureStaticTimeThresholdAfterFastTyping
* @attr ref R.styleable#MainKeyboardView_gestureDetectFastMoveSpeedThreshold
* @attr ref R.styleable#MainKeyboardView_gestureDynamicThresholdDecayDuration
@@ -99,6 +113,7 @@ import java.util.WeakHashMap;
* @attr ref R.styleable#MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration
*/
public final class MainKeyboardView extends KeyboardView implements PointerTracker.KeyEventHandler,
+ PointerTracker.DrawingProxy, MoreKeysPanel.Controller,
TouchScreenRegulator.ProcessMotionEvent {
private static final String TAG = MainKeyboardView.class.getSimpleName();
@@ -134,14 +149,36 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
private ObjectAnimator mAltCodeKeyWhileTypingFadeinAnimator;
private int mAltCodeKeyWhileTypingAnimAlpha = Constants.Color.ALPHA_OPAQUE;
+ // Preview placer view
+ private final PreviewPlacerView mPreviewPlacerView;
+ private final int[] mOriginCoords = CoordinateUtils.newInstance();
+
+ // Key preview
+ private static final int PREVIEW_ALPHA = 240;
+ private final int mKeyPreviewLayoutId;
+ private final int mKeyPreviewOffset;
+ private final int mKeyPreviewHeight;
+ private final SparseArray<TextView> mKeyPreviewTexts = CollectionUtils.newSparseArray();
+ private final KeyPreviewDrawParams mKeyPreviewDrawParams = new KeyPreviewDrawParams();
+ private boolean mShowKeyPreviewPopup = true;
+ private int mKeyPreviewLingerTimeout;
+
// More keys keyboard
private final WeakHashMap<Key, MoreKeysPanel> mMoreKeysPanelCache =
new WeakHashMap<Key, MoreKeysPanel>();
+ private final int mMoreKeysLayout;
private final boolean mConfigShowMoreKeysKeyboardAtTouchedPoint;
+ // More keys panel (used by both more keys keyboard and more suggestions view)
+ // TODO: Consider extending to support multiple more keys panels
+ private MoreKeysPanel mMoreKeysPanel;
+
+ // Gesture floating preview text
+ // TODO: Make this parameter customizable by user via settings.
+ private int mGestureFloatingPreviewTextLingerTimeout;
private final TouchScreenRegulator mTouchScreenRegulator;
- protected KeyDetector mKeyDetector;
+ private KeyDetector mKeyDetector;
private final boolean mHasDistinctMultitouch;
private int mOldPointerCount = 1;
private Key mOldKey;
@@ -381,6 +418,57 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
}
+ private final DrawingHandler mDrawingHandler = new DrawingHandler(this);
+
+ public static class DrawingHandler extends StaticInnerHandlerWrapper<MainKeyboardView> {
+ private static final int MSG_DISMISS_KEY_PREVIEW = 0;
+ private static final int MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;
+
+ public DrawingHandler(final MainKeyboardView outerInstance) {
+ super(outerInstance);
+ }
+
+ @Override
+ public void handleMessage(final Message msg) {
+ final MainKeyboardView mainKeyboardView = getOuterInstance();
+ if (mainKeyboardView == null) return;
+ final PointerTracker tracker = (PointerTracker) msg.obj;
+ switch (msg.what) {
+ case MSG_DISMISS_KEY_PREVIEW:
+ final TextView previewText = mainKeyboardView.mKeyPreviewTexts.get(
+ tracker.mPointerId);
+ if (previewText != null) {
+ previewText.setVisibility(INVISIBLE);
+ }
+ break;
+ case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT:
+ mainKeyboardView.mPreviewPlacerView.setGestureFloatingPreviewText(
+ SuggestedWords.EMPTY);
+ break;
+ }
+ }
+
+ public void dismissKeyPreview(final long delay, final PointerTracker tracker) {
+ sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, tracker), delay);
+ }
+
+ public void cancelDismissKeyPreview(final PointerTracker tracker) {
+ removeMessages(MSG_DISMISS_KEY_PREVIEW, tracker);
+ }
+
+ private void cancelAllDismissKeyPreviews() {
+ removeMessages(MSG_DISMISS_KEY_PREVIEW);
+ }
+
+ public void dismissGestureFloatingPreviewText(final long delay) {
+ sendMessageDelayed(obtainMessage(MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT), delay);
+ }
+
+ public void cancelAllMessages() {
+ cancelAllDismissKeyPreviews();
+ }
+ }
+
public MainKeyboardView(final Context context, final AttributeSet attrs) {
this(context, attrs, R.attr.mainKeyboardViewStyle);
}
@@ -402,38 +490,55 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
res, R.array.phantom_sudden_move_event_device_list));
PointerTracker.init(needsPhantomSuddenMoveEventHack);
- final TypedArray a = context.obtainStyledAttributes(
+ final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes(
attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
- mAutoCorrectionSpacebarLedEnabled = a.getBoolean(
+ mAutoCorrectionSpacebarLedEnabled = mainKeyboardViewAttr.getBoolean(
R.styleable.MainKeyboardView_autoCorrectionSpacebarLedEnabled, false);
- mAutoCorrectionSpacebarLedIcon = a.getDrawable(
+ mAutoCorrectionSpacebarLedIcon = mainKeyboardViewAttr.getDrawable(
R.styleable.MainKeyboardView_autoCorrectionSpacebarLedIcon);
- mSpacebarTextRatio = a.getFraction(
+ mSpacebarTextRatio = mainKeyboardViewAttr.getFraction(
R.styleable.MainKeyboardView_spacebarTextRatio, 1, 1, 1.0f);
- mSpacebarTextColor = a.getColor(R.styleable.MainKeyboardView_spacebarTextColor, 0);
- mSpacebarTextShadowColor = a.getColor(
+ mSpacebarTextColor = mainKeyboardViewAttr.getColor(
+ R.styleable.MainKeyboardView_spacebarTextColor, 0);
+ mSpacebarTextShadowColor = mainKeyboardViewAttr.getColor(
R.styleable.MainKeyboardView_spacebarTextShadowColor, 0);
- mLanguageOnSpacebarFinalAlpha = a.getInt(
+ mLanguageOnSpacebarFinalAlpha = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_languageOnSpacebarFinalAlpha,
Constants.Color.ALPHA_OPAQUE);
- final int languageOnSpacebarFadeoutAnimatorResId = a.getResourceId(
+ final int languageOnSpacebarFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId(
R.styleable.MainKeyboardView_languageOnSpacebarFadeoutAnimator, 0);
- final int altCodeKeyWhileTypingFadeoutAnimatorResId = a.getResourceId(
+ final int altCodeKeyWhileTypingFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId(
R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator, 0);
- final int altCodeKeyWhileTypingFadeinAnimatorResId = a.getResourceId(
+ final int altCodeKeyWhileTypingFadeinAnimatorResId = mainKeyboardViewAttr.getResourceId(
R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0);
- final float keyHysteresisDistance = a.getDimension(
+ final float keyHysteresisDistance = mainKeyboardViewAttr.getDimension(
R.styleable.MainKeyboardView_keyHysteresisDistance, 0);
- final float keyHysteresisDistanceForSlidingModifier = a.getDimension(
+ final float keyHysteresisDistanceForSlidingModifier = mainKeyboardViewAttr.getDimension(
R.styleable.MainKeyboardView_keyHysteresisDistanceForSlidingModifier, 0);
mKeyDetector = new KeyDetector(
keyHysteresisDistance, keyHysteresisDistanceForSlidingModifier);
- mKeyTimerHandler = new KeyTimerHandler(this, a);
- mConfigShowMoreKeysKeyboardAtTouchedPoint = a.getBoolean(
+ mKeyTimerHandler = new KeyTimerHandler(this, mainKeyboardViewAttr);
+ mKeyPreviewOffset = mainKeyboardViewAttr.getDimensionPixelOffset(
+ R.styleable.MainKeyboardView_keyPreviewOffset, 0);
+ mKeyPreviewHeight = mainKeyboardViewAttr.getDimensionPixelSize(
+ R.styleable.MainKeyboardView_keyPreviewHeight, 0);
+ mKeyPreviewLingerTimeout = mainKeyboardViewAttr.getInt(
+ R.styleable.MainKeyboardView_keyPreviewLingerTimeout, 0);
+ mKeyPreviewLayoutId = mainKeyboardViewAttr.getResourceId(
+ R.styleable.MainKeyboardView_keyPreviewLayout, 0);
+ if (mKeyPreviewLayoutId == 0) {
+ mShowKeyPreviewPopup = false;
+ }
+ mMoreKeysLayout = mainKeyboardViewAttr.getResourceId(
+ R.styleable.MainKeyboardView_moreKeysKeyboardLayout, 0);
+ mConfigShowMoreKeysKeyboardAtTouchedPoint = mainKeyboardViewAttr.getBoolean(
R.styleable.MainKeyboardView_showMoreKeysKeyboardAtTouchedPoint, false);
- PointerTracker.setParameters(a);
- a.recycle();
+
+ mGestureFloatingPreviewTextLingerTimeout = mainKeyboardViewAttr.getInt(
+ R.styleable.MainKeyboardView_gestureFloatingPreviewTextLingerTimeout, 0);
+ PointerTracker.setParameters(mainKeyboardViewAttr);
+ mainKeyboardViewAttr.recycle();
mLanguageOnSpacebarFadeoutAnimator = loadObjectAnimator(
languageOnSpacebarFadeoutAnimatorResId, this);
@@ -441,6 +546,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
altCodeKeyWhileTypingFadeoutAnimatorResId, this);
mAltCodeKeyWhileTypingFadeinAnimator = loadObjectAnimator(
altCodeKeyWhileTypingFadeinAnimatorResId, this);
+
+ mPreviewPlacerView = new PreviewPlacerView(context, attrs);
}
private ObjectAnimator loadObjectAnimator(final int resId, final Object target) {
@@ -538,6 +645,247 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
AccessibleKeyboardViewProxy.getInstance().setKeyboard();
}
+ /**
+ * Enables or disables the key feedback popup. This is a popup that shows a magnified
+ * version of the depressed key. By default the preview is enabled.
+ * @param previewEnabled whether or not to enable the key feedback preview
+ * @param delay the delay after which the preview is dismissed
+ * @see #isKeyPreviewPopupEnabled()
+ */
+ public void setKeyPreviewPopupEnabled(final boolean previewEnabled, final int delay) {
+ mShowKeyPreviewPopup = previewEnabled;
+ mKeyPreviewLingerTimeout = delay;
+ }
+
+
+ private void locatePreviewPlacerView() {
+ if (mPreviewPlacerView.getParent() != null) {
+ return;
+ }
+ final int width = getWidth();
+ final int height = getHeight();
+ if (width == 0 || height == 0) {
+ // In transient state.
+ return;
+ }
+ getLocationInWindow(mOriginCoords);
+ final DisplayMetrics dm = getResources().getDisplayMetrics();
+ if (CoordinateUtils.y(mOriginCoords) < dm.heightPixels / 4) {
+ // In transient state.
+ return;
+ }
+ final View rootView = getRootView();
+ if (rootView == null) {
+ Log.w(TAG, "Cannot find root view");
+ return;
+ }
+ final ViewGroup windowContentView = (ViewGroup)rootView.findViewById(android.R.id.content);
+ // Note: It'd be very weird if we get null by android.R.id.content.
+ if (windowContentView == null) {
+ Log.w(TAG, "Cannot find android.R.id.content view to add PreviewPlacerView");
+ } else {
+ windowContentView.addView(mPreviewPlacerView);
+ mPreviewPlacerView.setKeyboardViewGeometry(mOriginCoords, width, height);
+ }
+ }
+
+ /**
+ * Returns the enabled state of the key feedback preview
+ * @return whether or not the key feedback preview is enabled
+ * @see #setKeyPreviewPopupEnabled(boolean, int)
+ */
+ public boolean isKeyPreviewPopupEnabled() {
+ return mShowKeyPreviewPopup;
+ }
+
+ private void addKeyPreview(final TextView keyPreview) {
+ locatePreviewPlacerView();
+ mPreviewPlacerView.addView(
+ keyPreview, ViewLayoutUtils.newLayoutParam(mPreviewPlacerView, 0, 0));
+ }
+
+ private TextView getKeyPreviewText(final int pointerId) {
+ TextView previewText = mKeyPreviewTexts.get(pointerId);
+ if (previewText != null) {
+ return previewText;
+ }
+ final Context context = getContext();
+ if (mKeyPreviewLayoutId != 0) {
+ previewText = (TextView)LayoutInflater.from(context).inflate(mKeyPreviewLayoutId, null);
+ } else {
+ previewText = new TextView(context);
+ }
+ mKeyPreviewTexts.put(pointerId, previewText);
+ return previewText;
+ }
+
+ private void dismissAllKeyPreviews() {
+ final int pointerCount = mKeyPreviewTexts.size();
+ for (int id = 0; id < pointerCount; id++) {
+ final TextView previewText = mKeyPreviewTexts.get(id);
+ if (previewText != null) {
+ previewText.setVisibility(INVISIBLE);
+ }
+ }
+ PointerTracker.setReleasedKeyGraphicsToAllKeys();
+ }
+
+ // Background state set
+ private static final int[][][] KEY_PREVIEW_BACKGROUND_STATE_TABLE = {
+ { // STATE_MIDDLE
+ EMPTY_STATE_SET,
+ { R.attr.state_has_morekeys }
+ },
+ { // STATE_LEFT
+ { R.attr.state_left_edge },
+ { R.attr.state_left_edge, R.attr.state_has_morekeys }
+ },
+ { // STATE_RIGHT
+ { R.attr.state_right_edge },
+ { R.attr.state_right_edge, R.attr.state_has_morekeys }
+ }
+ };
+ private static final int STATE_MIDDLE = 0;
+ private static final int STATE_LEFT = 1;
+ private static final int STATE_RIGHT = 2;
+ private static final int STATE_NORMAL = 0;
+ private static final int STATE_HAS_MOREKEYS = 1;
+ private static final int[] KEY_PREVIEW_BACKGROUND_DEFAULT_STATE =
+ KEY_PREVIEW_BACKGROUND_STATE_TABLE[STATE_MIDDLE][STATE_NORMAL];
+
+ @Override
+ public void showKeyPreview(final PointerTracker tracker) {
+ final KeyPreviewDrawParams previewParams = mKeyPreviewDrawParams;
+ final Keyboard keyboard = getKeyboard();
+ if (!mShowKeyPreviewPopup) {
+ previewParams.mPreviewVisibleOffset = -keyboard.mVerticalGap;
+ return;
+ }
+
+ final TextView previewText = getKeyPreviewText(tracker.mPointerId);
+ // If the key preview has no parent view yet, add it to the ViewGroup which can place
+ // key preview absolutely in SoftInputWindow.
+ if (previewText.getParent() == null) {
+ addKeyPreview(previewText);
+ }
+
+ mDrawingHandler.cancelDismissKeyPreview(tracker);
+ final Key key = tracker.getKey();
+ // If key 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) {
+ return;
+ }
+
+ final KeyDrawParams drawParams = mKeyDrawParams;
+ previewText.setTextColor(drawParams.mPreviewTextColor);
+ final Drawable background = previewText.getBackground();
+ if (background != null) {
+ background.setState(KEY_PREVIEW_BACKGROUND_DEFAULT_STATE);
+ background.setAlpha(PREVIEW_ALPHA);
+ }
+ final String label = key.isShiftedLetterActivated() ? key.mHintLabel : key.mLabel;
+ // What we show as preview should match what we show on a key top in onDraw().
+ if (label != null) {
+ // TODO Should take care of temporaryShiftLabel here.
+ previewText.setCompoundDrawables(null, null, null, null);
+ if (StringUtils.codePointCount(label) > 1) {
+ previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, drawParams.mLetterSize);
+ previewText.setTypeface(Typeface.DEFAULT_BOLD);
+ } else {
+ previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, drawParams.mPreviewTextSize);
+ previewText.setTypeface(key.selectTypeface(drawParams));
+ }
+ previewText.setText(label);
+ } else {
+ previewText.setCompoundDrawables(null, null, null,
+ key.getPreviewIcon(keyboard.mIconsSet));
+ previewText.setText(null);
+ }
+
+ previewText.measure(
+ ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+ final int keyDrawWidth = key.getDrawWidth();
+ final int previewWidth = previewText.getMeasuredWidth();
+ final int previewHeight = mKeyPreviewHeight;
+ // The width and height of visible part of the key preview background. The content marker
+ // of the background 9-patch have to cover the visible part of the background.
+ previewParams.mPreviewVisibleWidth = previewWidth - previewText.getPaddingLeft()
+ - previewText.getPaddingRight();
+ previewParams.mPreviewVisibleHeight = previewHeight - previewText.getPaddingTop()
+ - previewText.getPaddingBottom();
+ // The distance between the top edge of the parent key and the bottom of the visible part
+ // of the key preview background.
+ previewParams.mPreviewVisibleOffset = mKeyPreviewOffset - previewText.getPaddingBottom();
+ getLocationInWindow(mOriginCoords);
+ // The key preview is horizontally aligned with the center of the visible part of the
+ // parent key. If it doesn't fit in this {@link KeyboardView}, it is moved inward to fit and
+ // the left/right background is used if such background is specified.
+ final int statePosition;
+ int previewX = key.getDrawX() - (previewWidth - keyDrawWidth) / 2
+ + CoordinateUtils.x(mOriginCoords);
+ if (previewX < 0) {
+ previewX = 0;
+ statePosition = STATE_LEFT;
+ } else if (previewX > getWidth() - previewWidth) {
+ previewX = getWidth() - previewWidth;
+ statePosition = STATE_RIGHT;
+ } else {
+ statePosition = STATE_MIDDLE;
+ }
+ // The key preview is placed vertically above the top edge of the parent key with an
+ // arbitrary offset.
+ final int previewY = key.mY - previewHeight + mKeyPreviewOffset
+ + CoordinateUtils.y(mOriginCoords);
+
+ if (background != null) {
+ final int hasMoreKeys = (key.mMoreKeys != null) ? STATE_HAS_MOREKEYS : STATE_NORMAL;
+ background.setState(KEY_PREVIEW_BACKGROUND_STATE_TABLE[statePosition][hasMoreKeys]);
+ }
+ ViewLayoutUtils.placeViewAt(
+ previewText, previewX, previewY, previewWidth, previewHeight);
+ previewText.setVisibility(VISIBLE);
+ }
+
+ @Override
+ public void dismissKeyPreview(final PointerTracker tracker) {
+ mDrawingHandler.dismissKeyPreview(mKeyPreviewLingerTimeout, tracker);
+ }
+
+ @Override
+ public void showSlidingKeyInputPreview(final PointerTracker tracker) {
+ locatePreviewPlacerView();
+ mPreviewPlacerView.showSlidingKeyInputPreview(tracker);
+ }
+
+ @Override
+ public void dismissSlidingKeyInputPreview() {
+ mPreviewPlacerView.dismissSlidingKeyInputPreview();
+ }
+
+ public void setGesturePreviewMode(final boolean drawsGesturePreviewTrail,
+ final boolean drawsGestureFloatingPreviewText) {
+ mPreviewPlacerView.setGesturePreviewMode(
+ drawsGesturePreviewTrail, drawsGestureFloatingPreviewText);
+ }
+
+ public void showGestureFloatingPreviewText(final SuggestedWords suggestedWords) {
+ locatePreviewPlacerView();
+ mPreviewPlacerView.setGestureFloatingPreviewText(suggestedWords);
+ }
+
+ public void dismissGestureFloatingPreviewText() {
+ locatePreviewPlacerView();
+ mDrawingHandler.dismissGestureFloatingPreviewText(mGestureFloatingPreviewTextLingerTimeout);
+ }
+
+ public void showGesturePreviewTrail(final PointerTracker tracker,
+ final boolean isOldestTracker) {
+ locatePreviewPlacerView();
+ mPreviewPlacerView.invalidatePointer(tracker, isOldestTracker);
+ }
+
// Note that this method is called from a non-UI thread.
public void setMainDictionaryAvailability(final boolean mainDictionaryAvailable) {
PointerTracker.setMainDictionaryAvailability(mainDictionaryAvailable);
@@ -561,6 +909,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
+ mPreviewPlacerView.removeAllViews();
// Notify the research logger that the keyboard view has been detached. This is needed
// to invalidate the reference of {@link MainKeyboardView} to null.
if (ProductionFlag.IS_EXPERIMENTAL) {
@@ -568,12 +917,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
}
- @Override
- public void cancelAllMessages() {
- mKeyTimerHandler.cancelAllMessages();
- super.cancelAllMessages();
- }
-
private boolean openMoreKeysKeyboardIfRequired(final Key parentKey,
final PointerTracker tracker) {
// Check if we have a popup layout specified first.
@@ -591,8 +934,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
return onLongPress(parentKey, tracker);
}
- // This default implementation returns a more keys panel.
- protected MoreKeysPanel onCreateMoreKeysPanel(final Key parentKey) {
+ private MoreKeysPanel onCreateMoreKeysPanel(final Key parentKey) {
if (parentKey.mMoreKeys == null) {
return null;
}
@@ -604,7 +946,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
final MoreKeysKeyboardView moreKeysKeyboardView =
(MoreKeysKeyboardView)container.findViewById(R.id.more_keys_keyboard_view);
- final Keyboard moreKeysKeyboard = new MoreKeysKeyboard.Builder(container, parentKey, this)
+ final Keyboard moreKeysKeyboard = new MoreKeysKeyboard.Builder(
+ container, parentKey, this, mKeyPreviewDrawParams)
.build();
moreKeysKeyboardView.setKeyboard(moreKeysKeyboard);
container.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
@@ -613,14 +956,13 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
/**
- * Called when a key is long pressed. By default this will open more keys keyboard associated
- * with this key.
+ * Called when a key is long pressed.
* @param parentKey the key that was long pressed
* @param tracker the pointer tracker which pressed the parent key
* @return true if the long press is handled, false otherwise. Subclasses should call the
* method on the base class if the subclass doesn't wish to handle the call.
*/
- protected boolean onLongPress(final Key parentKey, final PointerTracker tracker) {
+ private boolean onLongPress(final Key parentKey, final PointerTracker tracker) {
if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.mainKeyboardView_onLongPress();
}
@@ -697,6 +1039,38 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
return PointerTracker.isAnyInSlidingKeyInput();
}
+ @Override
+ public void onShowMoreKeysPanel(final MoreKeysPanel panel) {
+ if (isShowingMoreKeysPanel()) {
+ onDismissMoreKeysPanel();
+ }
+ mMoreKeysPanel = panel;
+ mPreviewPlacerView.addView(mMoreKeysPanel.getContainerView());
+ }
+
+ public boolean isShowingMoreKeysPanel() {
+ return (mMoreKeysPanel != null);
+ }
+
+ @Override
+ public void onCancelMoreKeysPanel() {
+ if (isShowingMoreKeysPanel()) {
+ mMoreKeysPanel.dismissMoreKeysPanel();
+ }
+ PointerTracker.dismissAllMoreKeysPanels();
+ }
+
+ @Override
+ public boolean onDismissMoreKeysPanel() {
+ dimEntireKeyboard(false /* dimmed */);
+ if (isShowingMoreKeysPanel()) {
+ mPreviewPlacerView.removeView(mMoreKeysPanel.getContainerView());
+ mMoreKeysPanel = null;
+ return true;
+ }
+ return false;
+ }
+
public int getPointerCount() {
return mOldPointerCount;
}
@@ -846,25 +1220,20 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
eventTag + eventTime + "," + id + "," + x + "," + y + "," + size + "," + pressure);
}
+ public void cancelAllMessages() {
+ mKeyTimerHandler.cancelAllMessages();
+ mDrawingHandler.cancelAllMessages();
+ }
+
@Override
public void closing() {
+ dismissAllKeyPreviews();
+ cancelAllMessages();
super.closing();
onCancelMoreKeysPanel();
mMoreKeysPanelCache.clear();
}
- @Override
- public void onCancelMoreKeysPanel() {
- super.onCancelMoreKeysPanel();
- PointerTracker.dismissAllMoreKeysPanels();
- }
-
- @Override
- public boolean onDismissMoreKeysPanel() {
- dimEntireKeyboard(false /* dimmed */);
- return super.onDismissMoreKeysPanel();
- }
-
/**
* Receives hover events from the input framework.
*