diff options
author | Jeff Brown <jeffbrown@google.com> | 2010-07-30 19:20:11 -0700 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2010-07-30 20:08:29 -0700 |
commit | 9e2ad36be87f2703b3d737189944d82f93bd4f27 (patch) | |
tree | 409280a29fa2d12b395e5f6faa0e3e375d7af1b3 /core/java/com/android/internal/widget/PointerLocationView.java | |
parent | 543f250d9cb05ebca4fb4dacce37545c0bb9a8ca (diff) | |
download | frameworks_base-9e2ad36be87f2703b3d737189944d82f93bd4f27.zip frameworks_base-9e2ad36be87f2703b3d737189944d82f93bd4f27.tar.gz frameworks_base-9e2ad36be87f2703b3d737189944d82f93bd4f27.tar.bz2 |
Enhanced VelocityTracker for > 5 pointers and fixed bugs.
Improved PointerLocation tool to use VelocityTracker more efficiently
and correctly when multiple pointers are down.
Fixed a bug in TouchInputMapper where it was not correctly copying
the id to index map in the last touch data. This could cause strange
behavior on secondary pointer up events.
Also added finished callback pooling in InputQueue.
Change-Id: Ia85e52ac2fb7350960ea1d7edfbe81a1b3e8267b
Diffstat (limited to 'core/java/com/android/internal/widget/PointerLocationView.java')
-rw-r--r-- | core/java/com/android/internal/widget/PointerLocationView.java | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/core/java/com/android/internal/widget/PointerLocationView.java b/core/java/com/android/internal/widget/PointerLocationView.java index f487a16..d5a9979 100644 --- a/core/java/com/android/internal/widget/PointerLocationView.java +++ b/core/java/com/android/internal/widget/PointerLocationView.java @@ -38,7 +38,8 @@ public class PointerLocationView extends View { private float mCurPressure; private float mCurSize; private int mCurWidth; - private VelocityTracker mVelocity; + private float mXVelocity; + private float mYVelocity; } private final ViewConfiguration mVC; @@ -56,6 +57,8 @@ public class PointerLocationView extends View { private final ArrayList<PointerState> mPointers = new ArrayList<PointerState>(); + private final VelocityTracker mVelocity; + private boolean mPrintCoords = true; public PointerLocationView(Context c) { @@ -88,8 +91,9 @@ public class PointerLocationView extends View { mPaint.setStrokeWidth(1); PointerState ps = new PointerState(); - ps.mVelocity = VelocityTracker.obtain(); mPointers.add(ps); + + mVelocity = VelocityTracker.obtain(); } public void setPrintCoords(boolean state) { @@ -146,11 +150,11 @@ public class PointerLocationView extends View { } canvas.drawRect(itemW * 3, 0, (itemW * 4) - 1, bottom, mTextBackgroundPaint); - int velocity = ps.mVelocity == null ? 0 : (int) (ps.mVelocity.getXVelocity() * 1000); + int velocity = (int) (ps.mXVelocity * 1000); canvas.drawText("Xv: " + velocity, 1 + itemW * 3, base, mTextPaint); canvas.drawRect(itemW * 4, 0, (itemW * 5) - 1, bottom, mTextBackgroundPaint); - velocity = ps.mVelocity == null ? 0 : (int) (ps.mVelocity.getYVelocity() * 1000); + velocity = (int) (ps.mYVelocity * 1000); canvas.drawText("Yv: " + velocity, 1 + itemW * 4, base, mTextPaint); canvas.drawRect(itemW * 5, 0, (itemW * 6) - 1, bottom, mTextBackgroundPaint); @@ -205,14 +209,10 @@ public class PointerLocationView extends View { } 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); - } + mPaint.setARGB(255, 255, 64, 128); + float xVel = ps.mXVelocity * (1000/60); + float yVel = ps.mYVelocity * (1000/60); + canvas.drawLine(lastX, lastY, lastX+xVel, lastY+yVel, mPaint); } } } @@ -236,11 +236,12 @@ public class PointerLocationView extends View { // mRect.setEmpty(); //} if (action == MotionEvent.ACTION_DOWN) { + mVelocity.clear(); + for (int p=0; p<NP; p++) { final PointerState ps = mPointers.get(p); ps.mXs.clear(); ps.mYs.clear(); - ps.mVelocity = VelocityTracker.obtain(); ps.mCurDown = false; } mPointers.get(0).mCurDown = true; @@ -256,12 +257,10 @@ public class PointerLocationView extends View { final int id = event.getPointerId(index); 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 (mPrintCoords) { Log.i("Pointer", "Pointer " + (id+1) + ": DOWN"); @@ -276,12 +275,13 @@ public class PointerLocationView extends View { if (mMaxNumPointers < mCurNumPointers) { mMaxNumPointers = mCurNumPointers; } + + mVelocity.addMovement(event); + mVelocity.computeCurrentVelocity(1); for (int i=0; i<NI; i++) { final int id = event.getPointerId(i); final PointerState ps = mPointers.get(id); - ps.mVelocity.addMovement(event); - ps.mVelocity.computeCurrentVelocity(1); final int N = event.getHistorySize(); for (int j=0; j<N; j++) { if (mPrintCoords) { @@ -309,6 +309,8 @@ public class PointerLocationView extends View { ps.mCurPressure = event.getPressure(i); ps.mCurSize = event.getSize(i); ps.mCurWidth = (int)(ps.mCurSize*(getWidth()/3)); + ps.mXVelocity = mVelocity.getXVelocity(id); + ps.mYVelocity = mVelocity.getYVelocity(id); } if ((action&MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_UP) { |