diff --git a/apps/Development/src/com/android/development/PointerLocation.java b/apps/Development/src/com/android/development/PointerLocation.java index 668e9ba16..4ef97a211 100644 --- a/apps/Development/src/com/android/development/PointerLocation.java +++ b/apps/Development/src/com/android/development/PointerLocation.java @@ -47,16 +47,9 @@ public class PointerLocation extends Activity { getWindow().setAttributes(lp); } - public class MyView extends View { - private final Paint mTextPaint; - private final Paint mTextBackgroundPaint; - private final Paint mTextLevelPaint; - private final Paint mPaint; - private final Paint mTargetPaint; - private final FontMetricsInt mTextMetrics = new FontMetricsInt(); + public static class PointerState { private final ArrayList mXs = new ArrayList(); private final ArrayList mYs = new ArrayList(); - private int mHeaderBottom; private boolean mCurDown; private int mCurX; private int mCurY; @@ -64,12 +57,26 @@ public class PointerLocation extends Activity { private float mCurSize; private int mCurWidth; private VelocityTracker mVelocity; + } + + public class MyView extends View { + private final Paint mTextPaint; + private final Paint mTextBackgroundPaint; + private final Paint mTextLevelPaint; + private final Paint mPaint; + private final Paint mTargetPaint; + private final FontMetricsInt mTextMetrics = new FontMetricsInt(); + private int mHeaderBottom; + private boolean mCurDown; + private final ArrayList mPointers + = new ArrayList(); public MyView(Context c) { super(c); mTextPaint = new Paint(); mTextPaint.setAntiAlias(true); - mTextPaint.setTextSize(10); + mTextPaint.setTextSize(10 + * getResources().getDisplayMetrics().density); mTextPaint.setARGB(255, 0, 0, 0); mTextBackgroundPaint = new Paint(); mTextBackgroundPaint.setAntiAlias(false); @@ -106,55 +113,72 @@ public class PointerLocation extends Activity { int w = getWidth()/5; int base = -mTextMetrics.ascent+1; int bottom = mHeaderBottom; - canvas.drawRect(0, 0, w-1, bottom, mTextBackgroundPaint); - canvas.drawText("X: " + mCurX, 1, base, mTextPaint); - canvas.drawRect(w, 0, (w * 2) - 1, bottom, mTextBackgroundPaint); - canvas.drawText("Y: " + mCurY, 1 + w, base, mTextPaint); - canvas.drawRect(w * 2, 0, (w * 3) - 1, bottom, mTextBackgroundPaint); - canvas.drawRect(w * 2, 0, (w * 2) + (mCurPressure * w) - 1, bottom, mTextLevelPaint); - canvas.drawText("Pres: " + mCurPressure, 1 + w * 2, base, mTextPaint); - canvas.drawRect(w * 3, 0, (w * 4) - 1, bottom, mTextBackgroundPaint); - canvas.drawRect(w * 3, 0, (w * 3) + (mCurSize * w) - 1, bottom, mTextLevelPaint); - canvas.drawText("Size: " + mCurSize, 1 + w * 3, base, mTextPaint); - canvas.drawRect(w * 4, 0, getWidth(), bottom, mTextBackgroundPaint); - int velocity = mVelocity == null ? 0 : (int) (mVelocity.getYVelocity() * 1000); - canvas.drawText("yVel: " + velocity, 1 + w * 4, base, mTextPaint); - final int N = mXs.size(); - float lastX=0, lastY=0; - mPaint.setARGB(255, 0, 255, 255); - for (int i=0; i 0) { - canvas.drawLine(lastX, lastY, x, y, mTargetPaint); + final int NP = mPointers.size(); + + if (NP > 0) { + final PointerState ps = mPointers.get(0); + canvas.drawRect(0, 0, w-1, bottom, mTextBackgroundPaint); + canvas.drawText("X: " + ps.mCurX, 1, base, mTextPaint); + canvas.drawRect(w, 0, (w * 2) - 1, bottom, mTextBackgroundPaint); + canvas.drawText("Y: " + ps.mCurY, 1 + w, base, mTextPaint); + canvas.drawRect(w * 2, 0, (w * 3) - 1, bottom, mTextBackgroundPaint); + canvas.drawRect(w * 2, 0, (w * 2) + (ps.mCurPressure * w) - 1, bottom, mTextLevelPaint); + canvas.drawText("Pres: " + ps.mCurPressure, 1 + w * 2, base, mTextPaint); + canvas.drawRect(w * 3, 0, (w * 4) - 1, bottom, mTextBackgroundPaint); + canvas.drawRect(w * 3, 0, (w * 3) + (ps.mCurSize * w) - 1, bottom, mTextLevelPaint); + canvas.drawText("Size: " + ps.mCurSize, 1 + w * 3, base, mTextPaint); + canvas.drawRect(w * 4, 0, getWidth(), bottom, mTextBackgroundPaint); + int velocity = ps.mVelocity == null ? 0 : (int) (ps.mVelocity.getYVelocity() * 1000); + canvas.drawText("yVel: " + velocity, 1 + w * 4, base, mTextPaint); + } + + for (int p=0; p 0) { + canvas.drawLine(lastX, lastY, x, y, mTargetPaint); + canvas.drawPoint(lastX, lastY, mPaint); + } + lastX = x; + lastY = y; + } + 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); } - lastX = x; - lastY = y; - } - if (mVelocity != null) { - mPaint.setARGB(255, 255, 0, 0); - float xVel = mVelocity.getXVelocity() * (1000/60); - float yVel = mVelocity.getYVelocity() * (1000/60); - canvas.drawLine(lastX, lastY, lastX+xVel, lastY+yVel, mPaint); - } else { - canvas.drawPoint(lastX, lastY, mPaint); } - if (mCurDown) { - canvas.drawLine(0, (int)mCurY, getWidth(), (int)mCurY, mTargetPaint); - canvas.drawLine((int)mCurX, 0, (int)mCurX, getHeight(), mTargetPaint); - int pressureLevel = (int)(mCurPressure*255); + 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(mCurX, mCurY, mPaint); - canvas.drawCircle(mCurX, mCurY, mCurWidth, mPaint); + canvas.drawPoint(ps.mCurX, ps.mCurY, mPaint); + canvas.drawCircle(ps.mCurX, ps.mCurY, ps.mCurWidth, mPaint); } } @Override public boolean onTouchEvent(MotionEvent event) { int action = event.getAction(); + + //Log.i("Pointer", "Motion: action=0x" + Integer.toHexString(action) + // + " pointers=" + event.getPointerCount()); + + int NP = mPointers.size(); + //mRect.set(0, 0, getWidth(), mHeaderBottom+1); //invalidate(mRect); //if (mCurDown) { @@ -164,26 +188,57 @@ public class PointerLocation extends Activity { // mRect.setEmpty(); //} if (action == MotionEvent.ACTION_DOWN) { - mXs.clear(); - mYs.clear(); - mVelocity = VelocityTracker.obtain(); + for (int p=0; p> MotionEvent.ACTION_POINTER_SHIFT); + ps.mXs.clear(); + ps.mYs.clear(); + ps.mVelocity = VelocityTracker.obtain(); + } + + if (NP > event.getPointerCount()) { + NP = event.getPointerCount(); + } + + mCurDown = action != MotionEvent.ACTION_UP + && action != MotionEvent.ACTION_CANCEL; + + for (int p=0; p