From 9b528c143ab7ca248b22c8ebddc3ab34833c4028 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Wed, 14 Oct 2009 16:30:09 -0700 Subject: [PATCH] Tweaks to Pointer Location. Have it show the amount of total movement after a release, and whether this is above the touch slop. Change-Id: Ie7eb359a84e20786779015c3146ea5d96f380188 --- .../android/development/PointerLocation.java | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/apps/Development/src/com/android/development/PointerLocation.java b/apps/Development/src/com/android/development/PointerLocation.java index 9935b7e63..38b4af2dc 100644 --- a/apps/Development/src/com/android/development/PointerLocation.java +++ b/apps/Development/src/com/android/development/PointerLocation.java @@ -24,6 +24,7 @@ import android.graphics.Paint.FontMetricsInt; import android.os.Bundle; import android.util.Log; import android.view.MotionEvent; +import android.view.ViewConfiguration; import android.view.WindowManager; import android.view.VelocityTracker; import android.view.View; @@ -59,6 +60,7 @@ public class PointerLocation extends Activity { } public class MyView extends View { + private final ViewConfiguration mVC; private final Paint mTextPaint; private final Paint mTextBackgroundPaint; private final Paint mTextLevelPaint; @@ -75,6 +77,7 @@ public class PointerLocation extends Activity { public MyView(Context c) { super(c); + mVC = ViewConfiguration.get(c); mTextPaint = new Paint(); mTextPaint.setAntiAlias(true); mTextPaint.setTextSize(10 @@ -132,11 +135,24 @@ public class PointerLocation extends Activity { canvas.drawText("P: " + mCurNumPointers + " / " + mMaxNumPointers, 1, base, mTextPaint); - canvas.drawRect(itemW, 0, (itemW * 2) - 1, bottom, mTextBackgroundPaint); - canvas.drawText("X: " + ps.mCurX, 1 + itemW, base, mTextPaint); - - canvas.drawRect(itemW * 2, 0, (itemW * 3) - 1, bottom, mTextBackgroundPaint); - canvas.drawText("Y: " + ps.mCurY, 1 + itemW * 2, base, mTextPaint); + final int N = ps.mXs.size(); + if ((mCurDown && ps.mCurDown) || N == 0) { + canvas.drawRect(itemW, 0, (itemW * 2) - 1, bottom, mTextBackgroundPaint); + canvas.drawText("X: " + ps.mCurX, 1 + itemW, base, mTextPaint); + canvas.drawRect(itemW * 2, 0, (itemW * 3) - 1, bottom, mTextBackgroundPaint); + canvas.drawText("Y: " + ps.mCurY, 1 + itemW * 2, base, mTextPaint); + } else { + float dx = ps.mXs.get(N-1) - ps.mXs.get(0); + float dy = ps.mYs.get(N-1) - ps.mYs.get(0); + canvas.drawRect(itemW, 0, (itemW * 2) - 1, bottom, + Math.abs(dx) < mVC.getScaledTouchSlop() + ? mTextBackgroundPaint : mTextLevelPaint); + canvas.drawText("dX: " + String.format("%.1f", dx), 1 + itemW, base, mTextPaint); + canvas.drawRect(itemW * 2, 0, (itemW * 3) - 1, bottom, + Math.abs(dy) < mVC.getScaledTouchSlop() + ? mTextBackgroundPaint : mTextLevelPaint); + canvas.drawText("dY: " + String.format("%.1f", dy), 1 + itemW * 2, base, mTextPaint); + } canvas.drawRect(itemW * 3, 0, (itemW * 4) - 1, bottom, mTextBackgroundPaint); int velocity = ps.mVelocity == null ? 0 : (int) (ps.mVelocity.getXVelocity() * 1000); @@ -237,6 +253,7 @@ public class PointerLocation extends Activity { } mPointers.get(0).mCurDown = true; mMaxNumPointers = 0; + Log.i("Pointer", "Pointer 1: DOWN"); } if ((action&MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN) { @@ -251,6 +268,7 @@ public class PointerLocation extends Activity { final PointerState ps = mPointers.get(id); ps.mVelocity = VelocityTracker.obtain(); ps.mCurDown = true; + Log.i("Pointer", "Pointer " + (id+1) + ": DOWN"); } final int NI = event.getPointerCount(); @@ -268,9 +286,18 @@ public class PointerLocation extends Activity { ps.mVelocity.computeCurrentVelocity(1); final int N = event.getHistorySize(); for (int j=0; j