Loading core/java/com/android/internal/widget/PointerLocationView.java +21 −8 Original line number Original line Diff line number Diff line Loading @@ -84,6 +84,7 @@ public class PointerLocationView extends View { private boolean mCurDown; private boolean mCurDown; private int mCurNumPointers; private int mCurNumPointers; private int mMaxNumPointers; private int mMaxNumPointers; private int mActivePointerId; private final ArrayList<PointerState> mPointers = new ArrayList<PointerState>(); private final ArrayList<PointerState> mPointers = new ArrayList<PointerState>(); private final VelocityTracker mVelocity; private final VelocityTracker mVelocity; Loading Loading @@ -123,6 +124,7 @@ public class PointerLocationView extends View { PointerState ps = new PointerState(); PointerState ps = new PointerState(); mPointers.add(ps); mPointers.add(ps); mActivePointerId = 0; mVelocity = VelocityTracker.obtain(); mVelocity = VelocityTracker.obtain(); Loading Loading @@ -183,8 +185,9 @@ public class PointerLocationView extends View { final int NP = mPointers.size(); final int NP = mPointers.size(); // Labels // Labels if (NP > 0) { if (mActivePointerId >= 0) { final PointerState ps = mPointers.get(0); final PointerState ps = mPointers.get(mActivePointerId); canvas.drawRect(0, 0, itemW-1, bottom,mTextBackgroundPaint); canvas.drawRect(0, 0, itemW-1, bottom,mTextBackgroundPaint); canvas.drawText(mText.clear() canvas.drawText(mText.clear() .append("P: ").append(mCurNumPointers) .append("P: ").append(mCurNumPointers) Loading Loading @@ -355,6 +358,11 @@ public class PointerLocationView extends View { NP++; NP++; } } if (mActivePointerId < 0 || ! mPointers.get(mActivePointerId).mCurDown) { mActivePointerId = id; } final PointerState ps = mPointers.get(id); final PointerState ps = mPointers.get(id); ps.mCurDown = true; ps.mCurDown = true; if (mPrintCoords) { if (mPrintCoords) { Loading Loading @@ -396,6 +404,7 @@ public class PointerLocationView extends View { } } if (action == MotionEvent.ACTION_UP if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_UP) { || (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_UP) { final int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) final int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; // will be 0 for UP >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; // will be 0 for UP Loading @@ -408,9 +417,13 @@ public class PointerLocationView extends View { .append(id + 1).append(": UP").toString()); .append(id + 1).append(": UP").toString()); } } if (action == MotionEvent.ACTION_UP) { if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { mCurDown = false; mCurDown = false; } else { } else { if (mActivePointerId == id) { mActivePointerId = event.getPointerId(index == 0 ? 1 : 0); } ps.addTrace(Float.NaN, Float.NaN); ps.addTrace(Float.NaN, Float.NaN); } } } } Loading Loading @@ -438,9 +451,9 @@ public class PointerLocationView extends View { // HACK // HACK // A quick and dirty string builder implementation optimized for GC. // A quick and dirty string builder implementation optimized for GC. // Using the basic StringBuilder implementation causes the application grind to a halt when // Using String.format causes the application grind to a halt when // more than a couple of pointers are down due to the number of temporary objects allocated // more than a couple of pointers are down due to the number of // while formatting strings for drawing or logging. // temporary objects allocated while formatting strings for drawing or logging. private static final class FasterStringBuilder { private static final class FasterStringBuilder { private char[] mChars; private char[] mChars; private int mLength; private int mLength; Loading Loading
core/java/com/android/internal/widget/PointerLocationView.java +21 −8 Original line number Original line Diff line number Diff line Loading @@ -84,6 +84,7 @@ public class PointerLocationView extends View { private boolean mCurDown; private boolean mCurDown; private int mCurNumPointers; private int mCurNumPointers; private int mMaxNumPointers; private int mMaxNumPointers; private int mActivePointerId; private final ArrayList<PointerState> mPointers = new ArrayList<PointerState>(); private final ArrayList<PointerState> mPointers = new ArrayList<PointerState>(); private final VelocityTracker mVelocity; private final VelocityTracker mVelocity; Loading Loading @@ -123,6 +124,7 @@ public class PointerLocationView extends View { PointerState ps = new PointerState(); PointerState ps = new PointerState(); mPointers.add(ps); mPointers.add(ps); mActivePointerId = 0; mVelocity = VelocityTracker.obtain(); mVelocity = VelocityTracker.obtain(); Loading Loading @@ -183,8 +185,9 @@ public class PointerLocationView extends View { final int NP = mPointers.size(); final int NP = mPointers.size(); // Labels // Labels if (NP > 0) { if (mActivePointerId >= 0) { final PointerState ps = mPointers.get(0); final PointerState ps = mPointers.get(mActivePointerId); canvas.drawRect(0, 0, itemW-1, bottom,mTextBackgroundPaint); canvas.drawRect(0, 0, itemW-1, bottom,mTextBackgroundPaint); canvas.drawText(mText.clear() canvas.drawText(mText.clear() .append("P: ").append(mCurNumPointers) .append("P: ").append(mCurNumPointers) Loading Loading @@ -355,6 +358,11 @@ public class PointerLocationView extends View { NP++; NP++; } } if (mActivePointerId < 0 || ! mPointers.get(mActivePointerId).mCurDown) { mActivePointerId = id; } final PointerState ps = mPointers.get(id); final PointerState ps = mPointers.get(id); ps.mCurDown = true; ps.mCurDown = true; if (mPrintCoords) { if (mPrintCoords) { Loading Loading @@ -396,6 +404,7 @@ public class PointerLocationView extends View { } } if (action == MotionEvent.ACTION_UP if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_UP) { || (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_UP) { final int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) final int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; // will be 0 for UP >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; // will be 0 for UP Loading @@ -408,9 +417,13 @@ public class PointerLocationView extends View { .append(id + 1).append(": UP").toString()); .append(id + 1).append(": UP").toString()); } } if (action == MotionEvent.ACTION_UP) { if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { mCurDown = false; mCurDown = false; } else { } else { if (mActivePointerId == id) { mActivePointerId = event.getPointerId(index == 0 ? 1 : 0); } ps.addTrace(Float.NaN, Float.NaN); ps.addTrace(Float.NaN, Float.NaN); } } } } Loading Loading @@ -438,9 +451,9 @@ public class PointerLocationView extends View { // HACK // HACK // A quick and dirty string builder implementation optimized for GC. // A quick and dirty string builder implementation optimized for GC. // Using the basic StringBuilder implementation causes the application grind to a halt when // Using String.format causes the application grind to a halt when // more than a couple of pointers are down due to the number of temporary objects allocated // more than a couple of pointers are down due to the number of // while formatting strings for drawing or logging. // temporary objects allocated while formatting strings for drawing or logging. private static final class FasterStringBuilder { private static final class FasterStringBuilder { private char[] mChars; private char[] mChars; private int mLength; private int mLength; Loading