@Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (isRotationEnabled) { // Set the pie rotation directly. final RectF circleOval = pieChart.getCircleOval(); final float centerX = circleOval.centerX(); final float centerY = circleOval.centerY(); float scrollTheta = vectorToScalarScroll(distanceX, distanceY, e2.getX() - centerX, e2.getY() - centerY); pieChart.setChartRotation(pieChart.getChartRotation() - (int) scrollTheta / FLING_VELOCITY_DOWNSCALE, false); return true; } return false; }
@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (isRotationEnabled) { // Set up the Scroller for a fling final RectF circleOval = pieChart.getCircleOval(); final float centerX = circleOval.centerX(); final float centerY = circleOval.centerY(); float scrollTheta = vectorToScalarScroll(velocityX, velocityY, e2.getX() - centerX, e2.getY() - centerY); scroller.abortAnimation(); scroller.fling(0, (int) pieChart.getChartRotation(), 0, (int) scrollTheta / FLING_VELOCITY_DOWNSCALE, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE); return true; } return false; }
public PieChartView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); pieChartRenderer = new PieChartRenderer(context, this, this); touchHandler = new PieChartTouchHandler(context, this); setChartRenderer(pieChartRenderer); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { this.rotationAnimator = new PieChartRotationAnimatorV8(this); } else { this.rotationAnimator = new PieChartRotationAnimatorV14(this); } setPieChartData(PieChartData.generateDummyData()); }
pieChartLast.setOnValueTouchListener(new PieChartLastTouchListener()); pieChartLast.setChartRotationEnabled(false);
pieChartLast.setPieChartData(pieChartData);
@Override public void onAnimationEnd(Animator animation) { chart.setChartRotation((int) targetRotation, false); animationListener.onAnimationFinished(); }
@Override public void onAnimationUpdate(ValueAnimator animation) { float scale = animation.getAnimatedFraction(); float rotation = startRotation + (targetRotation - startRotation) * scale; rotation = (rotation % 360 + 360) % 360; chart.setChartRotation((int) rotation, false); }
@Override public void cancelAnimation() { isAnimationStarted = false; handler.removeCallbacks(runnable); chart.setChartRotation((int) targetRotation, false); animationListener.onAnimationFinished(); }
@Override public boolean computeScroll() { if (!isRotationEnabled) { return false; } if (scroller.computeScrollOffset()) { pieChart.setChartRotation(scroller.getCurrY(), false); // pieChart.setChartRotation() will invalidate view so no need to return true; } return false; }