am 4987108f: Add surrounding drawing view to AbstractDrawingPreview constructor
* commit '4987108f34c08825ccb1c859c971bf232438c4aa': Add surrounding drawing view to AbstractDrawingPreview constructormain
commit
1ab8cdbe32
|
@ -17,6 +17,7 @@
|
||||||
package com.android.inputmethod.keyboard.internal;
|
package com.android.inputmethod.keyboard.internal;
|
||||||
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import com.android.inputmethod.keyboard.PointerTracker;
|
import com.android.inputmethod.keyboard.PointerTracker;
|
||||||
|
|
||||||
|
@ -25,9 +26,18 @@ import com.android.inputmethod.keyboard.PointerTracker;
|
||||||
* GestureFloatingPrevewText, GestureTrail, and SlidingKeyInputPreview.
|
* GestureFloatingPrevewText, GestureTrail, and SlidingKeyInputPreview.
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractDrawingPreview {
|
public abstract class AbstractDrawingPreview {
|
||||||
|
private final View mDrawingView;
|
||||||
private boolean mPreviewEnabled;
|
private boolean mPreviewEnabled;
|
||||||
|
|
||||||
public void setPreviewEnabled(final boolean enabled) {
|
protected AbstractDrawingPreview(final View drawingView) {
|
||||||
|
mDrawingView = drawingView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final View getDrawingView() {
|
||||||
|
return mDrawingView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setPreviewEnabled(final boolean enabled) {
|
||||||
mPreviewEnabled = enabled;
|
mPreviewEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +45,14 @@ public abstract class AbstractDrawingPreview {
|
||||||
return mPreviewEnabled;
|
return mPreviewEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setKeyboardGeometry(final int[] originCoords, final int width, final int height) {
|
||||||
|
// Default implementation is empty.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDetachFromWindow() {
|
||||||
|
// Default implementation is empty.
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws the preview
|
* Draws the preview
|
||||||
* @param canvas The canvas where the preview is drawn.
|
* @param canvas The canvas where the preview is drawn.
|
||||||
|
@ -43,7 +61,7 @@ public abstract class AbstractDrawingPreview {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the position of the preview.
|
* Set the position of the preview.
|
||||||
* @param pt The new location of the preview is based on the points in PointerTracker pt.
|
* @param tracker The new location of the preview is based on the points in PointerTracker.
|
||||||
*/
|
*/
|
||||||
public abstract void setPreviewPosition(final PointerTracker pt);
|
public abstract void setPreviewPosition(final PointerTracker tracker);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package com.android.inputmethod.keyboard.internal;
|
package com.android.inputmethod.keyboard.internal;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
@ -24,6 +23,7 @@ import android.graphics.Paint.Align;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import com.android.inputmethod.keyboard.PointerTracker;
|
import com.android.inputmethod.keyboard.PointerTracker;
|
||||||
import com.android.inputmethod.latin.CoordinateUtils;
|
import com.android.inputmethod.latin.CoordinateUtils;
|
||||||
|
@ -98,16 +98,18 @@ public class GestureFloatingPreviewText extends AbstractDrawingPreview {
|
||||||
PREVIEW_TEXT_ARRAY_CAPACITY);
|
PREVIEW_TEXT_ARRAY_CAPACITY);
|
||||||
|
|
||||||
protected SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
|
protected SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
|
||||||
protected final Context mContext;
|
|
||||||
public final int[] mLastPointerCoords = CoordinateUtils.newInstance();
|
public final int[] mLastPointerCoords = CoordinateUtils.newInstance();
|
||||||
|
|
||||||
public GestureFloatingPreviewText(final TypedArray typedArray, final Context context) {
|
public GestureFloatingPreviewText(final View drawingView, final TypedArray typedArray) {
|
||||||
|
super(drawingView);
|
||||||
mParams = new GesturePreviewTextParams(typedArray);
|
mParams = new GesturePreviewTextParams(typedArray);
|
||||||
mHighlightedWordIndex = 0;
|
mHighlightedWordIndex = 0;
|
||||||
mContext = context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSuggetedWords(final SuggestedWords suggestedWords) {
|
public void setSuggetedWords(final SuggestedWords suggestedWords) {
|
||||||
|
if (!isPreviewEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
mSuggestedWords = suggestedWords;
|
mSuggestedWords = suggestedWords;
|
||||||
updatePreviewPosition();
|
updatePreviewPosition();
|
||||||
}
|
}
|
||||||
|
@ -120,8 +122,13 @@ public class GestureFloatingPreviewText extends AbstractDrawingPreview {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPreviewPosition(final PointerTracker pt) {
|
public void setPreviewPosition(final PointerTracker tracker) {
|
||||||
pt.getLastCoordinates(mLastPointerCoords);
|
final boolean needsToUpdateLastPointer =
|
||||||
|
tracker.isOldestTrackerInQueue() && isPreviewEnabled();
|
||||||
|
if (!needsToUpdateLastPointer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tracker.getLastCoordinates(mLastPointerCoords);
|
||||||
updatePreviewPosition();
|
updatePreviewPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +171,7 @@ public class GestureFloatingPreviewText extends AbstractDrawingPreview {
|
||||||
final float rectWidth = textWidth + hPad * 2.0f;
|
final float rectWidth = textWidth + hPad * 2.0f;
|
||||||
final float rectHeight = textHeight + vPad * 2.0f;
|
final float rectHeight = textHeight + vPad * 2.0f;
|
||||||
|
|
||||||
final int displayWidth = mContext.getResources().getDisplayMetrics().widthPixels;
|
final int displayWidth = getDrawingView().getResources().getDisplayMetrics().widthPixels;
|
||||||
final float rectX = Math.min(
|
final float rectX = Math.min(
|
||||||
Math.max(CoordinateUtils.x(mLastPointerCoords) - rectWidth / 2.0f, 0.0f),
|
Math.max(CoordinateUtils.x(mLastPointerCoords) - rectWidth / 2.0f, 0.0f),
|
||||||
displayWidth - rectWidth);
|
displayWidth - rectWidth);
|
||||||
|
@ -176,5 +183,7 @@ public class GestureFloatingPreviewText extends AbstractDrawingPreview {
|
||||||
final int textY = (int)(rectY + vPad) + textHeight;
|
final int textY = (int)(rectY + vPad) + textHeight;
|
||||||
mPreviewTextXArray.add(0, textX);
|
mPreviewTextXArray.add(0, textX);
|
||||||
mPreviewTextYArray.add(0, textY);
|
mPreviewTextYArray.add(0, textY);
|
||||||
|
// TODO: Should narrow the invalidate region.
|
||||||
|
getDrawingView().invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ import com.android.inputmethod.latin.SuggestedWords;
|
||||||
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: Consolidate gesture preview trail with {@link KeyboardView}
|
// TODO: Separate gesture preview trail drawing code into separate class.
|
||||||
private final SparseArray<GesturePreviewTrail> mGesturePreviewTrails =
|
private final SparseArray<GesturePreviewTrail> mGesturePreviewTrails =
|
||||||
CollectionUtils.newSparseArray();
|
CollectionUtils.newSparseArray();
|
||||||
private final Params mGesturePreviewTrailParams;
|
private final Params mGesturePreviewTrailParams;
|
||||||
|
@ -55,6 +55,7 @@ public final class PreviewPlacerView extends RelativeLayout {
|
||||||
private final Rect mOffscreenSrcRect = new Rect();
|
private final Rect mOffscreenSrcRect = new Rect();
|
||||||
private final Rect mDirtyRect = new Rect();
|
private final Rect mDirtyRect = new Rect();
|
||||||
private final Rect mGesturePreviewTrailBoundsRect = new Rect(); // per trail
|
private final Rect mGesturePreviewTrailBoundsRect = new Rect(); // per trail
|
||||||
|
// TODO: Move these AbstractDrawingPvreiew objects to MainKeyboardView.
|
||||||
private final GestureFloatingPreviewText mGestureFloatingPreviewText;
|
private final GestureFloatingPreviewText mGestureFloatingPreviewText;
|
||||||
private boolean mShowSlidingKeyInputPreview;
|
private boolean mShowSlidingKeyInputPreview;
|
||||||
private final int[] mRubberBandFrom = CoordinateUtils.newInstance();
|
private final int[] mRubberBandFrom = CoordinateUtils.newInstance();
|
||||||
|
@ -104,7 +105,7 @@ public final class PreviewPlacerView extends RelativeLayout {
|
||||||
attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
|
attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
|
||||||
// TODO: mGestureFloatingPreviewText could be an instance of GestureFloatingPreviewText or
|
// TODO: mGestureFloatingPreviewText could be an instance of GestureFloatingPreviewText or
|
||||||
// MultiGesturePreviewText, depending on the user's choice in the settings.
|
// MultiGesturePreviewText, depending on the user's choice in the settings.
|
||||||
mGestureFloatingPreviewText = new GestureFloatingPreviewText(mainKeyboardViewAttr, context);
|
mGestureFloatingPreviewText = new GestureFloatingPreviewText(this, mainKeyboardViewAttr);
|
||||||
mGesturePreviewTrailParams = new Params(mainKeyboardViewAttr);
|
mGesturePreviewTrailParams = new Params(mainKeyboardViewAttr);
|
||||||
mainKeyboardViewAttr.recycle();
|
mainKeyboardViewAttr.recycle();
|
||||||
|
|
||||||
|
@ -120,11 +121,14 @@ public final class PreviewPlacerView extends RelativeLayout {
|
||||||
setLayerType(LAYER_TYPE_HARDWARE, layerPaint);
|
setLayerType(LAYER_TYPE_HARDWARE, layerPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeyboardViewGeometry(final int[] originCoords, final int w, final int h) {
|
public void setKeyboardViewGeometry(final int[] originCoords, final int width,
|
||||||
|
final int height) {
|
||||||
CoordinateUtils.copy(mKeyboardViewOrigin, originCoords);
|
CoordinateUtils.copy(mKeyboardViewOrigin, originCoords);
|
||||||
mOffscreenOffsetY = (int)(h * GestureStroke.EXTRA_GESTURE_TRAIL_AREA_ABOVE_KEYBOARD_RATIO);
|
mGestureFloatingPreviewText.setKeyboardGeometry(originCoords, width, height);
|
||||||
mOffscreenWidth = w;
|
mOffscreenOffsetY = (int)(
|
||||||
mOffscreenHeight = mOffscreenOffsetY + h;
|
height * GestureStroke.EXTRA_GESTURE_TRAIL_AREA_ABOVE_KEYBOARD_RATIO);
|
||||||
|
mOffscreenWidth = width;
|
||||||
|
mOffscreenHeight = mOffscreenOffsetY + height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGesturePreviewMode(final boolean drawsGesturePreviewTrail,
|
public void setGesturePreviewMode(final boolean drawsGesturePreviewTrail,
|
||||||
|
@ -134,11 +138,7 @@ public final class PreviewPlacerView extends RelativeLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invalidatePointer(final PointerTracker tracker) {
|
public void invalidatePointer(final PointerTracker tracker) {
|
||||||
final boolean needsToUpdateLastPointer =
|
mGestureFloatingPreviewText.setPreviewPosition(tracker);
|
||||||
tracker.isOldestTrackerInQueue() && mGestureFloatingPreviewText.isPreviewEnabled();
|
|
||||||
if (needsToUpdateLastPointer) {
|
|
||||||
mGestureFloatingPreviewText.setPreviewPosition(tracker);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mDrawsGesturePreviewTrail) {
|
if (mDrawsGesturePreviewTrail) {
|
||||||
GesturePreviewTrail trail;
|
GesturePreviewTrail trail;
|
||||||
|
@ -150,10 +150,8 @@ public final class PreviewPlacerView extends RelativeLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trail.addStroke(tracker.getGestureStrokeWithPreviewPoints(), tracker.getDownTime());
|
trail.addStroke(tracker.getGestureStrokeWithPreviewPoints(), tracker.getDownTime());
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Should narrow the invalidate region.
|
// TODO: Should narrow the invalidate region.
|
||||||
if (mDrawsGesturePreviewTrail || needsToUpdateLastPointer) {
|
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,6 +173,7 @@ public final class PreviewPlacerView extends RelativeLayout {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDetachedFromWindow() {
|
protected void onDetachedFromWindow() {
|
||||||
|
mGestureFloatingPreviewText.onDetachFromWindow();
|
||||||
freeOffscreenBuffer();
|
freeOffscreenBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,9 +253,7 @@ public final class PreviewPlacerView extends RelativeLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGestureFloatingPreviewText(final SuggestedWords suggestedWords) {
|
public void setGestureFloatingPreviewText(final SuggestedWords suggestedWords) {
|
||||||
if (!mGestureFloatingPreviewText.isPreviewEnabled()) return;
|
|
||||||
mGestureFloatingPreviewText.setSuggetedWords(suggestedWords);
|
mGestureFloatingPreviewText.setSuggetedWords(suggestedWords);
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawSlidingKeyInputPreview(final Canvas canvas) {
|
private void drawSlidingKeyInputPreview(final Canvas canvas) {
|
||||||
|
|
Loading…
Reference in New Issue