Cleaup gesture preview drawing code a bit
Change-Id: Ie75d497ba88805d945d6039ecad09ed0e8e5e4d3main
parent
4c6db0592e
commit
978c0fc878
|
@ -50,6 +50,9 @@ public class PreviewPlacerView extends RelativeLayout {
|
||||||
private final SparseArray<PointerTracker> mPointers = new SparseArray<PointerTracker>();
|
private final SparseArray<PointerTracker> mPointers = new SparseArray<PointerTracker>();
|
||||||
|
|
||||||
private String mGestureFloatingPreviewText;
|
private String mGestureFloatingPreviewText;
|
||||||
|
private int mLastPointerX;
|
||||||
|
private int mLastPointerY;
|
||||||
|
|
||||||
private boolean mDrawsGesturePreviewTrail;
|
private boolean mDrawsGesturePreviewTrail;
|
||||||
private boolean mDrawsGestureFloatingPreviewText;
|
private boolean mDrawsGestureFloatingPreviewText;
|
||||||
|
|
||||||
|
@ -154,32 +157,31 @@ public class PreviewPlacerView extends RelativeLayout {
|
||||||
public void invalidatePointer(PointerTracker tracker) {
|
public void invalidatePointer(PointerTracker tracker) {
|
||||||
synchronized (mPointers) {
|
synchronized (mPointers) {
|
||||||
mPointers.put(tracker.mPointerId, tracker);
|
mPointers.put(tracker.mPointerId, tracker);
|
||||||
|
}
|
||||||
|
mLastPointerX = tracker.getLastX();
|
||||||
|
mLastPointerY = tracker.getLastY();
|
||||||
// TODO: Should narrow the invalidate region.
|
// TODO: Should narrow the invalidate region.
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Canvas canvas) {
|
public void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
synchronized (mPointers) {
|
|
||||||
canvas.translate(mXOrigin, mYOrigin);
|
canvas.translate(mXOrigin, mYOrigin);
|
||||||
|
if (mDrawsGesturePreviewTrail) {
|
||||||
|
synchronized (mPointers) {
|
||||||
final int trackerCount = mPointers.size();
|
final int trackerCount = mPointers.size();
|
||||||
boolean hasDrawnFloatingPreviewText = false;
|
|
||||||
for (int index = 0; index < trackerCount; index++) {
|
for (int index = 0; index < trackerCount; index++) {
|
||||||
final PointerTracker tracker = mPointers.valueAt(index);
|
final PointerTracker tracker = mPointers.valueAt(index);
|
||||||
if (mDrawsGesturePreviewTrail) {
|
|
||||||
tracker.drawGestureTrail(canvas, mGesturePaint);
|
tracker.drawGestureTrail(canvas, mGesturePaint);
|
||||||
}
|
}
|
||||||
// TODO: Figure out more cleaner way to draw gesture preview text.
|
|
||||||
if (mDrawsGestureFloatingPreviewText && !hasDrawnFloatingPreviewText) {
|
|
||||||
drawGestureFloatingPreviewText(canvas, tracker, mGestureFloatingPreviewText);
|
|
||||||
hasDrawnFloatingPreviewText = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mDrawsGestureFloatingPreviewText) {
|
||||||
|
drawGestureFloatingPreviewText(canvas, mGestureFloatingPreviewText);
|
||||||
|
}
|
||||||
canvas.translate(-mXOrigin, -mYOrigin);
|
canvas.translate(-mXOrigin, -mYOrigin);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void setGestureFloatingPreviewText(String gestureFloatingPreviewText) {
|
public void setGestureFloatingPreviewText(String gestureFloatingPreviewText) {
|
||||||
mGestureFloatingPreviewText = gestureFloatingPreviewText;
|
mGestureFloatingPreviewText = gestureFloatingPreviewText;
|
||||||
|
@ -194,15 +196,16 @@ public class PreviewPlacerView extends RelativeLayout {
|
||||||
mDrawingHandler.cancelAllMessages();
|
mDrawingHandler.cancelAllMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawGestureFloatingPreviewText(Canvas canvas, PointerTracker tracker,
|
private void drawGestureFloatingPreviewText(Canvas canvas, String gestureFloatingPreviewText) {
|
||||||
String gestureFloatingPreviewText) {
|
|
||||||
if (TextUtils.isEmpty(gestureFloatingPreviewText)) {
|
if (TextUtils.isEmpty(gestureFloatingPreviewText)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Paint paint = mTextPaint;
|
final Paint paint = mTextPaint;
|
||||||
final int lastX = tracker.getLastX();
|
// TODO: Figure out how we should deal with the floating preview text with multiple moving
|
||||||
final int lastY = tracker.getLastY();
|
// fingers.
|
||||||
|
final int lastX = mLastPointerX;
|
||||||
|
final int lastY = mLastPointerY;
|
||||||
final int textSize = (int)paint.getTextSize();
|
final int textSize = (int)paint.getTextSize();
|
||||||
final int canvasWidth = canvas.getWidth();
|
final int canvasWidth = canvas.getWidth();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue