diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index fa8337866..63c29bf29 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -51,8 +51,6 @@
-
-
@@ -71,8 +69,6 @@
-
-
@@ -117,6 +113,8 @@
+
+
@@ -127,6 +125,8 @@
+
+
diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml
index 5a50c1681..c398b5924 100644
--- a/java/res/values/styles.xml
+++ b/java/res/values/styles.xml
@@ -53,7 +53,6 @@
- @dimen/key_hint_letter_padding
- @dimen/key_popup_hint_letter_padding
- @dimen/key_uppercase_letter_padding
- - @layout/key_preview
- @color/key_text_color_default
- @fraction/key_preview_text_ratio
- @dimen/keyboard_vertical_correction
@@ -67,7 +66,6 @@
- @dimen/gesture_floating_preview_horizontal_padding
- @dimen/gesture_floating_preview_vertical_padding
- @dimen/gesture_floating_preview_round_radius
- - @integer/config_gesture_floating_preview_text_linger_timeout
- @integer/config_gesture_preview_trail_fadeout_start_delay
- @integer/config_gesture_preview_trail_fadeout_duration
- @integer/config_gesture_preview_trail_update_interval
@@ -85,6 +83,7 @@
- @integer/config_long_press_key_timeout
- @integer/config_long_press_shift_key_timeout
- @integer/config_ignore_alt_code_key_timeout
+ - @layout/key_preview
- @dimen/key_preview_offset
- @dimen/key_preview_height
- @integer/config_key_preview_linger_timeout
@@ -95,6 +94,7 @@
- @anim/alt_code_key_while_typing_fadeout
- @anim/alt_code_key_while_typing_fadein
+ - @integer/config_gesture_floating_preview_text_linger_timeout
- @integer/config_gesture_static_time_threshold_after_fast_typing
- @fraction/config_gesture_detect_fast_move_speed_threshold
- @integer/config_gesture_dynamic_threshold_decay_duration
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 068cfac4f..54c3e7c91 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -28,26 +28,16 @@ import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
-import android.os.Message;
import android.util.AttributeSet;
-import android.util.DisplayMetrics;
-import android.util.Log;
import android.util.SparseArray;
-import android.view.LayoutInflater;
import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
import com.android.inputmethod.keyboard.internal.KeyVisualAttributes;
-import com.android.inputmethod.keyboard.internal.PreviewPlacerView;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.Constants;
-import com.android.inputmethod.latin.CoordinateUtils;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
-import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.research.ResearchLogger;
@@ -57,26 +47,12 @@ import java.util.HashSet;
* A view that renders a virtual {@link Keyboard}.
*
* @attr ref R.styleable#KeyboardView_keyBackground
- * @attr ref R.styleable#KeyboardView_keyPreviewLayout
* @attr ref R.styleable#KeyboardView_keyLabelHorizontalPadding
* @attr ref R.styleable#KeyboardView_keyHintLetterPadding
* @attr ref R.styleable#KeyboardView_keyPopupHintLetterPadding
* @attr ref R.styleable#KeyboardView_keyShiftedLetterHintPadding
* @attr ref R.styleable#KeyboardView_keyTextShadowRadius
* @attr ref R.styleable#KeyboardView_backgroundDimAlpha
- * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextSize
- * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextColor
- * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextOffset
- * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewColor
- * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewHorizontalPadding
- * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewVerticalPadding
- * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewRoundRadius
- * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextLingerTimeout
- * @attr ref R.styleable#KeyboardView_gesturePreviewTrailFadeoutStartDelay
- * @attr ref R.styleable#KeyboardView_gesturePreviewTrailFadeoutDuration
- * @attr ref R.styleable#KeyboardView_gesturePreviewTrailUpdateInterval
- * @attr ref R.styleable#KeyboardView_gesturePreviewTrailColor
- * @attr ref R.styleable#KeyboardView_gesturePreviewTrailWidth
* @attr ref R.styleable#KeyboardView_verticalCorrection
* @attr ref R.styleable#Keyboard_Key_keyTypeface
* @attr ref R.styleable#Keyboard_Key_keyLetterSize
@@ -97,8 +73,6 @@ import java.util.HashSet;
* @attr ref R.styleable#Keyboard_Key_keyPreviewTextColor
*/
public class KeyboardView extends View {
- private static final String TAG = KeyboardView.class.getSimpleName();
-
// XML attributes
protected final KeyVisualAttributes mKeyVisualAttributes;
private final int mKeyLabelHorizontalPadding;
@@ -126,20 +100,6 @@ public class KeyboardView extends View {
private Keyboard mKeyboard;
protected final KeyDrawParams mKeyDrawParams = new KeyDrawParams();
- // Preview placer view
- // TODO: Move PreviewPlacerView to MainKeyboardView
- protected final PreviewPlacerView mPreviewPlacerView;
- private final int[] mOriginCoords = CoordinateUtils.newInstance();
-
- // Key preview
- // TODO: Move these variable to MainKeyboardView
- protected final int mKeyPreviewLayoutId;
- protected final SparseArray mKeyPreviewTexts = CollectionUtils.newSparseArray();
-
- // Gesture floating preview text
- // TODO: Make this parameter customizable by user via settings.
- private int mGestureFloatingPreviewTextLingerTimeout;
-
// Drawing
/** True if the entire keyboard needs to be dimmed. */
private boolean mNeedsToDimEntireKeyboard;
@@ -164,56 +124,6 @@ public class KeyboardView extends View {
private static final char[] KEY_LABEL_REFERENCE_CHAR = { 'M' };
private static final char[] KEY_NUMERIC_HINT_LABEL_REFERENCE_CHAR = { '8' };
- // TODO: Move this to MainKeyboardView
- protected final DrawingHandler mDrawingHandler = new DrawingHandler(this);
-
- public static class DrawingHandler extends StaticInnerHandlerWrapper {
- private static final int MSG_DISMISS_KEY_PREVIEW = 0;
- private static final int MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;
-
- public DrawingHandler(final KeyboardView outerInstance) {
- super(outerInstance);
- }
-
- @Override
- public void handleMessage(final Message msg) {
- final KeyboardView keyboardView = getOuterInstance();
- if (keyboardView == null) return;
- final PointerTracker tracker = (PointerTracker) msg.obj;
- switch (msg.what) {
- case MSG_DISMISS_KEY_PREVIEW:
- final TextView previewText = keyboardView.mKeyPreviewTexts.get(tracker.mPointerId);
- if (previewText != null) {
- previewText.setVisibility(INVISIBLE);
- }
- break;
- case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT:
- keyboardView.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 KeyboardView(final Context context, final AttributeSet attrs) {
this(context, attrs, R.attr.keyboardViewStyle);
}
@@ -235,14 +145,10 @@ public class KeyboardView extends View {
R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0);
mKeyTextShadowRadius = keyboardViewAttr.getFloat(
R.styleable.KeyboardView_keyTextShadowRadius, 0.0f);
- mKeyPreviewLayoutId = keyboardViewAttr.getResourceId(
- R.styleable.KeyboardView_keyPreviewLayout, 0);
mVerticalCorrection = keyboardViewAttr.getDimension(
R.styleable.KeyboardView_verticalCorrection, 0);
mBackgroundDimAlpha = keyboardViewAttr.getInt(
R.styleable.KeyboardView_backgroundDimAlpha, 0);
- mGestureFloatingPreviewTextLingerTimeout = keyboardViewAttr.getInt(
- R.styleable.KeyboardView_gestureFloatingPreviewTextLingerTimeout, 0);
keyboardViewAttr.recycle();
final TypedArray keyAttr = context.obtainStyledAttributes(attrs,
@@ -250,7 +156,6 @@ public class KeyboardView extends View {
mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr);
keyAttr.recycle();
- mPreviewPlacerView = new PreviewPlacerView(context, attrs);
mPaint.setAntiAlias(true);
}
@@ -286,13 +191,6 @@ public class KeyboardView extends View {
return mKeyboard;
}
- // TODO: Move this method to MainKeyboardView
- public void setGesturePreviewMode(final boolean drawsGesturePreviewTrail,
- final boolean drawsGestureFloatingPreviewText) {
- mPreviewPlacerView.setGesturePreviewMode(
- drawsGesturePreviewTrail, drawsGestureFloatingPreviewText);
- }
-
@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
if (mKeyboard != null) {
@@ -733,94 +631,6 @@ public class KeyboardView extends View {
return paint;
}
- public void cancelAllMessages() {
- mDrawingHandler.cancelAllMessages();
- }
-
- // TODO: Move this method to MainKeyboardView.
- protected 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;
- }
-
- // TODO: Move this method to MainKeyboardView.
- 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();
- }
-
- // TODO: Move this to MainKeyboardView
- protected void addKeyPreview(final TextView keyPreview) {
- locatePreviewPlacerView();
- mPreviewPlacerView.addView(
- keyPreview, ViewLayoutUtils.newLayoutParam(mPreviewPlacerView, 0, 0));
- }
-
- // TODO: Move this to MainKeyboardView
- protected 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);
- }
- }
-
- public void showGestureFloatingPreviewText(final SuggestedWords suggestedWords) {
- locatePreviewPlacerView();
- mPreviewPlacerView.setGestureFloatingPreviewText(suggestedWords);
- }
-
- public void dismissGestureFloatingPreviewText() {
- locatePreviewPlacerView();
- mDrawingHandler.dismissGestureFloatingPreviewText(mGestureFloatingPreviewTextLingerTimeout);
- }
-
- // TODO: Move This to MainKeyboardView
- public void showGesturePreviewTrail(final PointerTracker tracker,
- final boolean isOldestTracker) {
- locatePreviewPlacerView();
- mPreviewPlacerView.invalidatePointer(tracker, isOldestTracker);
- }
-
/**
* Requests a redraw of the entire keyboard. Calling {@link #invalidate} is not sufficient
* because the keyboard renders the keys to an off-screen buffer and an invalidate() only
@@ -850,8 +660,6 @@ public class KeyboardView extends View {
}
public void closing() {
- dismissAllKeyPreviews();
- cancelAllMessages();
mInvalidateAllKeys = true;
mKeyboard = null;
requestLayout();
@@ -861,7 +669,6 @@ public class KeyboardView extends View {
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
closing();
- mPreviewPlacerView.removeAllViews();
freeOffscreenBuffer();
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index 42021874c..83b37f1b1 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -32,7 +32,9 @@ 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;
@@ -49,7 +51,9 @@ 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;
@@ -60,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;
@@ -88,11 +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
@@ -142,14 +149,19 @@ 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 mKeyPreviewTexts = CollectionUtils.newSparseArray();
private final KeyPreviewDrawParams mKeyPreviewDrawParams = new KeyPreviewDrawParams();
private boolean mShowKeyPreviewPopup = true;
private int mKeyPreviewLingerTimeout;
- private final int[] mOriginCoords = CoordinateUtils.newInstance();
// More keys keyboard
private final WeakHashMap mMoreKeysPanelCache =
@@ -160,6 +172,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
// 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;
private KeyDetector mKeyDetector;
@@ -402,6 +418,57 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
}
+ private final DrawingHandler mDrawingHandler = new DrawingHandler(this);
+
+ public static class DrawingHandler extends StaticInnerHandlerWrapper {
+ 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);
}
@@ -458,6 +525,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
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;
}
@@ -465,6 +534,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
R.styleable.MainKeyboardView_moreKeysKeyboardLayout, 0);
mConfigShowMoreKeysKeyboardAtTouchedPoint = mainKeyboardViewAttr.getBoolean(
R.styleable.MainKeyboardView_showMoreKeysKeyboardAtTouchedPoint, false);
+
+ mGestureFloatingPreviewTextLingerTimeout = mainKeyboardViewAttr.getInt(
+ R.styleable.MainKeyboardView_gestureFloatingPreviewTextLingerTimeout, 0);
PointerTracker.setParameters(mainKeyboardViewAttr);
mainKeyboardViewAttr.recycle();
@@ -474,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) {
@@ -583,6 +657,38 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
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
@@ -592,6 +698,38 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
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
@@ -726,6 +864,28 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
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);
@@ -749,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) {
@@ -756,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.
@@ -1065,8 +1220,15 @@ 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();
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureFloatingPreviewText.java b/java/src/com/android/inputmethod/keyboard/internal/GestureFloatingPreviewText.java
index aed23a4db..a3f70ab24 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GestureFloatingPreviewText.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GestureFloatingPreviewText.java
@@ -34,6 +34,14 @@ import com.android.inputmethod.latin.SuggestedWords;
/**
* The class for single gesture preview text. The class for multiple gesture preview text will be
* derived from it.
+ *
+ * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextSize
+ * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextColor
+ * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextOffset
+ * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewColor
+ * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewHorizontalPadding
+ * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewVerticalPadding
+ * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewRoundRadius
*/
public class GestureFloatingPreviewText extends AbstractDrawingPreview {
private static final class GesturePreviewTextParams {
@@ -50,6 +58,7 @@ public class GestureFloatingPreviewText extends AbstractDrawingPreview {
private static final char[] TEXT_HEIGHT_REFERENCE_CHAR = { 'M' };
public GesturePreviewTextParams(final TypedArray keyboardViewAttr) {
+ // TODO: Move these XML attributes to MainKeyboardView
mGesturePreviewTextSize = keyboardViewAttr.getDimensionPixelSize(
R.styleable.KeyboardView_gestureFloatingPreviewTextSize, 0);
mGesturePreviewTextColor = keyboardViewAttr.getColor(
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java
index 9f6945da5..80780c69d 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java
@@ -25,6 +25,13 @@ import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.ResizableIntArray;
+/*
+ * @attr ref R.styleable#KeyboardView_gesturePreviewTrailFadeoutStartDelay
+ * @attr ref R.styleable#KeyboardView_gesturePreviewTrailFadeoutDuration
+ * @attr ref R.styleable#KeyboardView_gesturePreviewTrailUpdateInterval
+ * @attr ref R.styleable#KeyboardView_gesturePreviewTrailColor
+ * @attr ref R.styleable#KeyboardView_gesturePreviewTrailWidth
+ */
final class GesturePreviewTrail {
private static final int DEFAULT_CAPACITY = GestureStrokeWithPreviewPoints.PREVIEW_CAPACITY;
@@ -47,6 +54,7 @@ final class GesturePreviewTrail {
public final int mTrailLingerDuration;
public Params(final TypedArray keyboardViewAttr) {
+ // TODO: Move these XML attributes to MainKeyboardView
mTrailColor = keyboardViewAttr.getColor(
R.styleable.KeyboardView_gesturePreviewTrailColor, 0);
mTrailStartWidth = keyboardViewAttr.getDimension(
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index d9e63da1b..75bf3f29e 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1617,7 +1617,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private void showGesturePreviewAndSuggestionStrip(final SuggestedWords suggestedWords,
final boolean dismissGestureFloatingPreviewText) {
showSuggestionStrip(suggestedWords, null);
- final KeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
+ final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
mainKeyboardView.showGestureFloatingPreviewText(suggestedWords);
if (dismissGestureFloatingPreviewText) {
mainKeyboardView.dismissGestureFloatingPreviewText();