@Override public void onDraw(Canvas c) { mRect.setView(this); if (colors.getBkgColor() != Color.TRANSPARENT) { paint.setColor(colors.getBkgColor()); mRect.drawRounded(c, paint); } paint.setColor(colors.getSndColor()); mRect.drawRimRounded(c, paint); mRect.drawStripesX(c, mn, paint); for (int i = 0; i < pressCount; i++) { PointF f = mActivePointers.get(i); if (f != null) { paint.setColor(palette[i]); mRect.drawCross(c, f.x, f.y, paint); int mSelected = ViewUtils.getCell(mn, f.x); paint.setColor(colors.getSndColor()); mRect.drawSelectedStripesX(c, mn, mSelected, paint); } } if (!mLabels.isEmpty()) { paint.setColor(textColor); mRect.drawStripesXText(c, mn, paint, mLabels); } }
private void normalizePoint(PointF f) { f.x = (f.x - getLeft()) / mRect.getWidth(); f.y = (f.y - getTop()) / mRect.getHeight(); }
@Override public boolean onTouchEvent(MotionEvent event) { int pointerIndex = event.getActionIndex(); int pointerId = event.getPointerId(pointerIndex); int maskedAction = event.getActionMasked(); switch (maskedAction) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: { performClick(); if (event.getPointerCount() < mMaxTouch) { pressCount = event.getPointerCount(); PointF f = new PointF(); f.x = event.getX(pointerIndex); f.y = event.getY(pointerIndex); if (mRect.contains(f)) { normalizePoint(f); mActivePointers.put(pointerId, f); mListener.on(pointerId, ViewUtils.getCell(mn, f.x), mRangeY.fromRelative(f.y)); } } } case MotionEvent.ACTION_MOVE: { // a pointer was moved for (int size = event.getPointerCount(), i = 0; i < size; i++) { pointerId = event.getPointerId(i); PointF point = mActivePointers.get(pointerId); if (point != null) { point.x = event.getX(i); point.y = event.getY(i); if (mRect.contains(point)) { normalizePoint(point); mListener.move( pointerId, ViewUtils.getCell(mn, point.x), mRangeY.fromRelative(point.y)); } else { mActivePointers.remove(pointerId); mListener.off(pointerId); } } } break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_CANCEL: { PointF f = new PointF(); f.x = event.getX(pointerIndex); f.y = event.getY(pointerIndex); if (mRect.contains(f)) { mActivePointers.remove(pointerId); mListener.off(pointerId); } break; } } invalidate(); return true; }