am fb523d7f: Move AbstractDrawingPreview objects to MainKeyboardView

* commit 'fb523d7f5d40123a49a9128c455815db320c90fc':
  Move AbstractDrawingPreview objects to MainKeyboardView
main
Tadashi G. Takaoka 2013-01-21 06:45:34 -08:00 committed by Android Git Automerger
commit b9da0332e7
2 changed files with 49 additions and 69 deletions

View File

@ -50,9 +50,12 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.annotations.ExternallyReferenced; import com.android.inputmethod.annotations.ExternallyReferenced;
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; 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.KeyDrawParams;
import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams; import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams;
import com.android.inputmethod.keyboard.internal.PreviewPlacerView; 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.keyboard.internal.TouchScreenRegulator;
import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
@ -154,6 +157,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
// Preview placer view // Preview placer view
private final PreviewPlacerView mPreviewPlacerView; private final PreviewPlacerView mPreviewPlacerView;
private final int[] mOriginCoords = CoordinateUtils.newInstance(); private final int[] mOriginCoords = CoordinateUtils.newInstance();
private final GestureFloatingPreviewText mGestureFloatingPreviewText;
private final GestureTrailsPreview mGestureTrailsPreview;
private final SlidingKeyInputPreview mSlidingKeyInputPreview;
// Key preview // Key preview
private static final int PREVIEW_ALPHA = 240; private static final int PREVIEW_ALPHA = 240;
@ -446,8 +452,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
} }
break; break;
case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT: case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT:
mainKeyboardView.mPreviewPlacerView.setGestureFloatingPreviewText( mainKeyboardView.showGestureFloatingPreviewText(SuggestedWords.EMPTY);
SuggestedWords.EMPTY);
break; break;
} }
} }
@ -493,6 +498,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
ResourceUtils.getDeviceOverrideValue( ResourceUtils.getDeviceOverrideValue(
res, R.array.phantom_sudden_move_event_device_list)); res, R.array.phantom_sudden_move_event_device_list));
PointerTracker.init(needsPhantomSuddenMoveEventHack); PointerTracker.init(needsPhantomSuddenMoveEventHack);
mPreviewPlacerView = new PreviewPlacerView(context, attrs);
final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes( final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes(
attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView); attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
@ -546,6 +552,18 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mGestureFloatingPreviewTextLingerTimeout = mainKeyboardViewAttr.getInt( mGestureFloatingPreviewTextLingerTimeout = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_gestureFloatingPreviewTextLingerTimeout, 0); R.styleable.MainKeyboardView_gestureFloatingPreviewTextLingerTimeout, 0);
PointerTracker.setParameters(mainKeyboardViewAttr); 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(); mainKeyboardViewAttr.recycle();
mLanguageOnSpacebarFadeoutAnimator = loadObjectAnimator( mLanguageOnSpacebarFadeoutAnimator = loadObjectAnimator(
@ -554,8 +572,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
altCodeKeyWhileTypingFadeoutAnimatorResId, this); altCodeKeyWhileTypingFadeoutAnimatorResId, this);
mAltCodeKeyWhileTypingFadeinAnimator = loadObjectAnimator( mAltCodeKeyWhileTypingFadeinAnimator = loadObjectAnimator(
altCodeKeyWhileTypingFadeinAnimatorResId, this); altCodeKeyWhileTypingFadeinAnimatorResId, this);
mPreviewPlacerView = new PreviewPlacerView(context, attrs);
} }
private ObjectAnimator loadObjectAnimator(final int resId, final Object target) { private ObjectAnimator loadObjectAnimator(final int resId, final Object target) {
@ -864,23 +880,23 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override @Override
public void showSlidingKeyInputPreview(final PointerTracker tracker) { public void showSlidingKeyInputPreview(final PointerTracker tracker) {
locatePreviewPlacerView(); locatePreviewPlacerView();
mPreviewPlacerView.showSlidingKeyInputPreview(tracker); mSlidingKeyInputPreview.setPreviewPosition(tracker);
} }
@Override @Override
public void dismissSlidingKeyInputPreview() { public void dismissSlidingKeyInputPreview() {
mPreviewPlacerView.dismissSlidingKeyInputPreview(); mSlidingKeyInputPreview.dismissSlidingKeyInputPreview();
} }
public void setGesturePreviewMode(final boolean drawsGesturePreviewTrail, public void setGesturePreviewMode(final boolean drawsGesturePreviewTrail,
final boolean drawsGestureFloatingPreviewText) { final boolean drawsGestureFloatingPreviewText) {
mPreviewPlacerView.setGesturePreviewMode( mGestureFloatingPreviewText.setPreviewEnabled(drawsGestureFloatingPreviewText);
drawsGesturePreviewTrail, drawsGestureFloatingPreviewText); mGestureTrailsPreview.setPreviewEnabled(drawsGesturePreviewTrail);
} }
public void showGestureFloatingPreviewText(final SuggestedWords suggestedWords) { public void showGestureFloatingPreviewText(final SuggestedWords suggestedWords) {
locatePreviewPlacerView(); locatePreviewPlacerView();
mPreviewPlacerView.setGestureFloatingPreviewText(suggestedWords); mGestureFloatingPreviewText.setSuggetedWords(suggestedWords);
} }
public void dismissGestureFloatingPreviewText() { public void dismissGestureFloatingPreviewText() {
@ -888,9 +904,11 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mDrawingHandler.dismissGestureFloatingPreviewText(mGestureFloatingPreviewTextLingerTimeout); mDrawingHandler.dismissGestureFloatingPreviewText(mGestureFloatingPreviewTextLingerTimeout);
} }
@Override
public void showGesturePreviewTrail(final PointerTracker tracker) { public void showGesturePreviewTrail(final PointerTracker tracker) {
locatePreviewPlacerView(); locatePreviewPlacerView();
mPreviewPlacerView.invalidatePointer(tracker); mGestureFloatingPreviewText.setPreviewPosition(tracker);
mGestureTrailsPreview.setPreviewPosition(tracker);
} }
// Note that this method is called from a non-UI thread. // Note that this method is called from a non-UI thread.

View File

@ -17,7 +17,6 @@
package com.android.inputmethod.keyboard.internal; package com.android.inputmethod.keyboard.internal;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
@ -25,78 +24,45 @@ import android.graphics.PorterDuffXfermode;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.RelativeLayout; 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.CoordinateUtils;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SuggestedWords; import java.util.ArrayList;
public final class PreviewPlacerView extends RelativeLayout { public final class PreviewPlacerView extends RelativeLayout {
private final int[] mKeyboardViewOrigin = CoordinateUtils.newInstance(); private final int[] mKeyboardViewOrigin = CoordinateUtils.newInstance();
// TODO: Move these AbstractDrawingPvreiew objects to MainKeyboardView. private final ArrayList<AbstractDrawingPreview> mPreviews = CollectionUtils.newArrayList();
private final GestureFloatingPreviewText mGestureFloatingPreviewText;
private final GestureTrailsPreview mGestureTrailsPreview;
private final SlidingKeyInputPreview mSlidingKeyInputPreview;
public PreviewPlacerView(final Context context, final AttributeSet attrs) { public PreviewPlacerView(final Context context, final AttributeSet attrs) {
this(context, attrs, R.attr.keyboardViewStyle); super(context, attrs);
}
public PreviewPlacerView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context);
setWillNotDraw(false); 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(); final Paint layerPaint = new Paint();
layerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); layerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
setLayerType(LAYER_TYPE_HARDWARE, layerPaint); setLayerType(LAYER_TYPE_HARDWARE, layerPaint);
} }
public void addPreview(final AbstractDrawingPreview preview) {
mPreviews.add(preview);
}
public void setKeyboardViewGeometry(final int[] originCoords, final int width, public void setKeyboardViewGeometry(final int[] originCoords, final int width,
final int height) { final int height) {
CoordinateUtils.copy(mKeyboardViewOrigin, originCoords); CoordinateUtils.copy(mKeyboardViewOrigin, originCoords);
mGestureFloatingPreviewText.setKeyboardGeometry(originCoords, width, height); final int count = mPreviews.size();
mGestureTrailsPreview.setKeyboardGeometry(originCoords, width, height); for (int i = 0; i < count; i++) {
mSlidingKeyInputPreview.setKeyboardGeometry(originCoords, width, height); 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 @Override
protected void onDetachedFromWindow() { protected void onDetachedFromWindow() {
super.onDetachedFromWindow(); super.onDetachedFromWindow();
mGestureFloatingPreviewText.onDetachFromWindow(); final int count = mPreviews.size();
mGestureTrailsPreview.onDetachFromWindow(); for (int i = 0; i < count; i++) {
mSlidingKeyInputPreview.onDetachFromWindow(); mPreviews.get(i).onDetachFromWindow();
}
} }
@Override @Override
@ -105,14 +71,10 @@ public final class PreviewPlacerView extends RelativeLayout {
final int originX = CoordinateUtils.x(mKeyboardViewOrigin); final int originX = CoordinateUtils.x(mKeyboardViewOrigin);
final int originY = CoordinateUtils.y(mKeyboardViewOrigin); final int originY = CoordinateUtils.y(mKeyboardViewOrigin);
canvas.translate(originX, originY); canvas.translate(originX, originY);
mGestureFloatingPreviewText.drawPreview(canvas); final int count = mPreviews.size();
mGestureTrailsPreview.drawPreview(canvas); for (int i = 0; i < count; i++) {
mSlidingKeyInputPreview.drawPreview(canvas); mPreviews.get(i).drawPreview(canvas);
}
canvas.translate(-originX, -originY); canvas.translate(-originX, -originY);
} }
// TODO: Move this method to MainKeyboardView.
public void setGestureFloatingPreviewText(final SuggestedWords suggestedWords) {
mGestureFloatingPreviewText.setSuggetedWords(suggestedWords);
}
} }