From 30712dcdf75eb6d4587c147da5fb81011699a88f Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Tue, 4 Aug 2009 20:03:31 -0700 Subject: [PATCH] Update to use new multi-pointer APIs. --- .../android/development/PointerLocation.java | 119 +++++++++++------- 1 file changed, 73 insertions(+), 46 deletions(-) diff --git a/apps/Development/src/com/android/development/PointerLocation.java b/apps/Development/src/com/android/development/PointerLocation.java index 4ef97a211..419e2e470 100644 --- a/apps/Development/src/com/android/development/PointerLocation.java +++ b/apps/Development/src/com/android/development/PointerLocation.java @@ -65,6 +65,7 @@ public class PointerLocation extends Activity { private final Paint mTextLevelPaint; private final Paint mPaint; private final Paint mTargetPaint; + private final Paint mPathPaint; private final FontMetricsInt mTextMetrics = new FontMetricsInt(); private int mHeaderBottom; private boolean mCurDown; @@ -92,6 +93,9 @@ public class PointerLocation extends Activity { mTargetPaint = new Paint(); mTargetPaint.setAntiAlias(false); mTargetPaint.setARGB(192, 0, 0, 255); + mPathPaint = new Paint(); + mPathPaint.setAntiAlias(false); + mPathPaint.setARGB(255, 64, 128, 255); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(1); } @@ -138,35 +142,45 @@ public class PointerLocation extends Activity { final int N = ps.mXs.size(); float lastX=0, lastY=0; - mPaint.setARGB(255, 0, 255, 255); + boolean haveLast = false; + boolean drawn = false; + mPaint.setARGB(255, 128, 255, 255); for (int i=0; i 0) { - canvas.drawLine(lastX, lastY, x, y, mTargetPaint); + if (Float.isNaN(x)) { + haveLast = false; + continue; + } + if (haveLast) { + canvas.drawLine(lastX, lastY, x, y, mPathPaint); canvas.drawPoint(lastX, lastY, mPaint); + drawn = true; } lastX = x; lastY = y; + haveLast = true; } - if (ps.mVelocity != null) { - mPaint.setARGB(255, 255, 0, 0); - float xVel = ps.mVelocity.getXVelocity() * (1000/60); - float yVel = ps.mVelocity.getYVelocity() * (1000/60); - canvas.drawLine(lastX, lastY, lastX+xVel, lastY+yVel, mPaint); - } else { - canvas.drawPoint(lastX, lastY, mPaint); + + if (drawn) { + if (ps.mVelocity != null) { + mPaint.setARGB(255, 255, 64, 128); + float xVel = ps.mVelocity.getXVelocity() * (1000/60); + float yVel = ps.mVelocity.getYVelocity() * (1000/60); + canvas.drawLine(lastX, lastY, lastX+xVel, lastY+yVel, mPaint); + } else { + canvas.drawPoint(lastX, lastY, mPaint); + } + } + + if (mCurDown && ps.mCurDown) { + canvas.drawLine(0, (int)ps.mCurY, getWidth(), (int)ps.mCurY, mTargetPaint); + canvas.drawLine((int)ps.mCurX, 0, (int)ps.mCurX, getHeight(), mTargetPaint); + int pressureLevel = (int)(ps.mCurPressure*255); + mPaint.setARGB(255, pressureLevel, 128, 255-pressureLevel); + canvas.drawPoint(ps.mCurX, ps.mCurY, mPaint); + canvas.drawCircle(ps.mCurX, ps.mCurY, ps.mCurWidth, mPaint); } - } - - if (mCurDown && NP > 0) { - final PointerState ps = mPointers.get(0); - canvas.drawLine(0, (int)ps.mCurY, getWidth(), (int)ps.mCurY, mTargetPaint); - canvas.drawLine((int)ps.mCurX, 0, (int)ps.mCurX, getHeight(), mTargetPaint); - int pressureLevel = (int)(ps.mCurPressure*255); - mPaint.setARGB(255, pressureLevel, 128, 255-pressureLevel); - canvas.drawPoint(ps.mCurX, ps.mCurY, mPaint); - canvas.drawCircle(ps.mCurX, ps.mCurY, ps.mCurWidth, mPaint); } } @@ -188,57 +202,70 @@ public class PointerLocation extends Activity { // mRect.setEmpty(); //} if (action == MotionEvent.ACTION_DOWN) { + if (NP == 0) { + PointerState ps = new PointerState(); + ps.mVelocity = VelocityTracker.obtain(); + mPointers.add(ps); + NP++; + } for (int p=0; p> MotionEvent.ACTION_POINTER_SHIFT); - ps.mXs.clear(); - ps.mYs.clear(); + final int id = (action&MotionEvent.ACTION_POINTER_ID_MASK) + >> MotionEvent.ACTION_POINTER_ID_SHIFT; + while (NP <= id) { + PointerState ps = new PointerState(); + ps.mVelocity = VelocityTracker.obtain(); + mPointers.add(ps); + NP++; + } + final PointerState ps = mPointers.get(id); ps.mVelocity = VelocityTracker.obtain(); + ps.mCurDown = true; } - if (NP > event.getPointerCount()) { - NP = event.getPointerCount(); - } + final int NI = event.getPointerCount(); mCurDown = action != MotionEvent.ACTION_UP && action != MotionEvent.ACTION_CANCEL; - for (int p=0; p> MotionEvent.ACTION_POINTER_ID_SHIFT; + final PointerState ps = mPointers.get(id); + ps.mXs.add(Float.NaN); + ps.mYs.add(Float.NaN); + ps.mCurDown = false; + } + //if (mCurDown) { // mRect.union(mCurX-mCurWidth-3, mCurY-mCurWidth-3, // mCurX+mCurWidth+3, mCurY+mCurWidth+3);