am fb523d7f: Move AbstractDrawingPreview objects to MainKeyboardView
* commit 'fb523d7f5d40123a49a9128c455815db320c90fc': Move AbstractDrawingPreview objects to MainKeyboardViewmain
commit
b9da0332e7
|
@ -50,9 +50,12 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
|
|||
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.GestureFloatingPreviewText;
|
||||
import com.android.inputmethod.keyboard.internal.GestureTrailsPreview;
|
||||
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.SlidingKeyInputPreview;
|
||||
import com.android.inputmethod.keyboard.internal.TouchScreenRegulator;
|
||||
import com.android.inputmethod.latin.CollectionUtils;
|
||||
import com.android.inputmethod.latin.Constants;
|
||||
|
@ -154,6 +157,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
// Preview placer view
|
||||
private final PreviewPlacerView mPreviewPlacerView;
|
||||
private final int[] mOriginCoords = CoordinateUtils.newInstance();
|
||||
private final GestureFloatingPreviewText mGestureFloatingPreviewText;
|
||||
private final GestureTrailsPreview mGestureTrailsPreview;
|
||||
private final SlidingKeyInputPreview mSlidingKeyInputPreview;
|
||||
|
||||
// Key preview
|
||||
private static final int PREVIEW_ALPHA = 240;
|
||||
|
@ -446,8 +452,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
}
|
||||
break;
|
||||
case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT:
|
||||
mainKeyboardView.mPreviewPlacerView.setGestureFloatingPreviewText(
|
||||
SuggestedWords.EMPTY);
|
||||
mainKeyboardView.showGestureFloatingPreviewText(SuggestedWords.EMPTY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -493,6 +498,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
ResourceUtils.getDeviceOverrideValue(
|
||||
res, R.array.phantom_sudden_move_event_device_list));
|
||||
PointerTracker.init(needsPhantomSuddenMoveEventHack);
|
||||
mPreviewPlacerView = new PreviewPlacerView(context, attrs);
|
||||
|
||||
final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes(
|
||||
attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
|
||||
|
@ -546,6 +552,18 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
mGestureFloatingPreviewTextLingerTimeout = mainKeyboardViewAttr.getInt(
|
||||
R.styleable.MainKeyboardView_gestureFloatingPreviewTextLingerTimeout, 0);
|
||||
PointerTracker.setParameters(mainKeyboardViewAttr);
|
||||
|
||||
mGestureFloatingPreviewText = new GestureFloatingPreviewText(
|
||||
mPreviewPlacerView, mainKeyboardViewAttr);
|
||||
mPreviewPlacerView.addPreview(mGestureFloatingPreviewText);
|
||||
|
||||
mGestureTrailsPreview = new GestureTrailsPreview(
|
||||
mPreviewPlacerView, mainKeyboardViewAttr);
|
||||
mPreviewPlacerView.addPreview(mGestureTrailsPreview);
|
||||
|
||||
mSlidingKeyInputPreview = new SlidingKeyInputPreview(
|
||||
mPreviewPlacerView, mainKeyboardViewAttr);
|
||||
mPreviewPlacerView.addPreview(mSlidingKeyInputPreview);
|
||||
mainKeyboardViewAttr.recycle();
|
||||
|
||||
mLanguageOnSpacebarFadeoutAnimator = loadObjectAnimator(
|
||||
|
@ -554,8 +572,6 @@ 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) {
|
||||
|
@ -864,23 +880,23 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
@Override
|
||||
public void showSlidingKeyInputPreview(final PointerTracker tracker) {
|
||||
locatePreviewPlacerView();
|
||||
mPreviewPlacerView.showSlidingKeyInputPreview(tracker);
|
||||
mSlidingKeyInputPreview.setPreviewPosition(tracker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismissSlidingKeyInputPreview() {
|
||||
mPreviewPlacerView.dismissSlidingKeyInputPreview();
|
||||
mSlidingKeyInputPreview.dismissSlidingKeyInputPreview();
|
||||
}
|
||||
|
||||
public void setGesturePreviewMode(final boolean drawsGesturePreviewTrail,
|
||||
final boolean drawsGestureFloatingPreviewText) {
|
||||
mPreviewPlacerView.setGesturePreviewMode(
|
||||
drawsGesturePreviewTrail, drawsGestureFloatingPreviewText);
|
||||
mGestureFloatingPreviewText.setPreviewEnabled(drawsGestureFloatingPreviewText);
|
||||
mGestureTrailsPreview.setPreviewEnabled(drawsGesturePreviewTrail);
|
||||
}
|
||||
|
||||
public void showGestureFloatingPreviewText(final SuggestedWords suggestedWords) {
|
||||
locatePreviewPlacerView();
|
||||
mPreviewPlacerView.setGestureFloatingPreviewText(suggestedWords);
|
||||
mGestureFloatingPreviewText.setSuggetedWords(suggestedWords);
|
||||
}
|
||||
|
||||
public void dismissGestureFloatingPreviewText() {
|
||||
|
@ -888,9 +904,11 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
|||
mDrawingHandler.dismissGestureFloatingPreviewText(mGestureFloatingPreviewTextLingerTimeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showGesturePreviewTrail(final PointerTracker tracker) {
|
||||
locatePreviewPlacerView();
|
||||
mPreviewPlacerView.invalidatePointer(tracker);
|
||||
mGestureFloatingPreviewText.setPreviewPosition(tracker);
|
||||
mGestureTrailsPreview.setPreviewPosition(tracker);
|
||||
}
|
||||
|
||||
// Note that this method is called from a non-UI thread.
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package com.android.inputmethod.keyboard.internal;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
|
@ -25,78 +24,45 @@ import android.graphics.PorterDuffXfermode;
|
|||
import android.util.AttributeSet;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.android.inputmethod.keyboard.PointerTracker;
|
||||
import com.android.inputmethod.latin.CollectionUtils;
|
||||
import com.android.inputmethod.latin.CoordinateUtils;
|
||||
import com.android.inputmethod.latin.R;
|
||||
import com.android.inputmethod.latin.SuggestedWords;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public final class PreviewPlacerView extends RelativeLayout {
|
||||
private final int[] mKeyboardViewOrigin = CoordinateUtils.newInstance();
|
||||
|
||||
// TODO: Move these AbstractDrawingPvreiew objects to MainKeyboardView.
|
||||
private final GestureFloatingPreviewText mGestureFloatingPreviewText;
|
||||
private final GestureTrailsPreview mGestureTrailsPreview;
|
||||
private final SlidingKeyInputPreview mSlidingKeyInputPreview;
|
||||
private final ArrayList<AbstractDrawingPreview> mPreviews = CollectionUtils.newArrayList();
|
||||
|
||||
public PreviewPlacerView(final Context context, final AttributeSet attrs) {
|
||||
this(context, attrs, R.attr.keyboardViewStyle);
|
||||
}
|
||||
|
||||
public PreviewPlacerView(final Context context, final AttributeSet attrs, final int defStyle) {
|
||||
super(context);
|
||||
super(context, attrs);
|
||||
setWillNotDraw(false);
|
||||
|
||||
final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes(
|
||||
attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
|
||||
// TODO: mGestureFloatingPreviewText could be an instance of GestureFloatingPreviewText or
|
||||
// MultiGesturePreviewText, depending on the user's choice in the settings.
|
||||
mGestureFloatingPreviewText = new GestureFloatingPreviewText(this, mainKeyboardViewAttr);
|
||||
mGestureTrailsPreview = new GestureTrailsPreview(this, mainKeyboardViewAttr);
|
||||
mSlidingKeyInputPreview = new SlidingKeyInputPreview(this, mainKeyboardViewAttr);
|
||||
mainKeyboardViewAttr.recycle();
|
||||
|
||||
final Paint layerPaint = new Paint();
|
||||
layerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
|
||||
setLayerType(LAYER_TYPE_HARDWARE, layerPaint);
|
||||
}
|
||||
|
||||
public void addPreview(final AbstractDrawingPreview preview) {
|
||||
mPreviews.add(preview);
|
||||
}
|
||||
|
||||
public void setKeyboardViewGeometry(final int[] originCoords, final int width,
|
||||
final int height) {
|
||||
CoordinateUtils.copy(mKeyboardViewOrigin, originCoords);
|
||||
mGestureFloatingPreviewText.setKeyboardGeometry(originCoords, width, height);
|
||||
mGestureTrailsPreview.setKeyboardGeometry(originCoords, width, height);
|
||||
mSlidingKeyInputPreview.setKeyboardGeometry(originCoords, width, height);
|
||||
final int count = mPreviews.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
mPreviews.get(i).setKeyboardGeometry(originCoords, width, height);
|
||||
}
|
||||
|
||||
// TODO: Move this method to MainKeyboardView
|
||||
public void setGesturePreviewMode(final boolean drawsGesturePreviewTrail,
|
||||
final boolean drawsGestureFloatingPreviewText) {
|
||||
mGestureFloatingPreviewText.setPreviewEnabled(drawsGestureFloatingPreviewText);
|
||||
mGestureTrailsPreview.setPreviewEnabled(drawsGesturePreviewTrail);
|
||||
}
|
||||
|
||||
// TODO: Move this method to MainKeyboardView
|
||||
public void invalidatePointer(final PointerTracker tracker) {
|
||||
mGestureFloatingPreviewText.setPreviewPosition(tracker);
|
||||
mGestureTrailsPreview.setPreviewPosition(tracker);
|
||||
}
|
||||
|
||||
// TODO: Move this method to MainKeyboardView
|
||||
public void showSlidingKeyInputPreview(final PointerTracker tracker) {
|
||||
mSlidingKeyInputPreview.setPreviewPosition(tracker);
|
||||
}
|
||||
|
||||
// TODO: Move this method to MainKeyboardView
|
||||
public void dismissSlidingKeyInputPreview() {
|
||||
mSlidingKeyInputPreview.dismissSlidingKeyInputPreview();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
mGestureFloatingPreviewText.onDetachFromWindow();
|
||||
mGestureTrailsPreview.onDetachFromWindow();
|
||||
mSlidingKeyInputPreview.onDetachFromWindow();
|
||||
final int count = mPreviews.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
mPreviews.get(i).onDetachFromWindow();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -105,14 +71,10 @@ public final class PreviewPlacerView extends RelativeLayout {
|
|||
final int originX = CoordinateUtils.x(mKeyboardViewOrigin);
|
||||
final int originY = CoordinateUtils.y(mKeyboardViewOrigin);
|
||||
canvas.translate(originX, originY);
|
||||
mGestureFloatingPreviewText.drawPreview(canvas);
|
||||
mGestureTrailsPreview.drawPreview(canvas);
|
||||
mSlidingKeyInputPreview.drawPreview(canvas);
|
||||
final int count = mPreviews.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
mPreviews.get(i).drawPreview(canvas);
|
||||
}
|
||||
canvas.translate(-originX, -originY);
|
||||
}
|
||||
|
||||
// TODO: Move this method to MainKeyboardView.
|
||||
public void setGestureFloatingPreviewText(final SuggestedWords suggestedWords) {
|
||||
mGestureFloatingPreviewText.setSuggetedWords(suggestedWords);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue