private void updateCharValues(float startPercentage, float endPercentage, bool force) { if (values == null) { return; } int n = chartData.xPercentage.Length; int nl = lines.Count; int startIndex = -1; int endIndex = -1; for (int j = 0; j < n; j++) { if (chartData.xPercentage[j] >= startPercentage && startIndex == -1) { startIndex = j; } if (chartData.xPercentage[j] <= endPercentage) { endIndex = j; } } if (endIndex < startIndex) { startIndex = endIndex; } if (!force && lastEndIndex == endIndex && lastStartIndex == startIndex) { return; } lastEndIndex = endIndex; lastStartIndex = startIndex; isEmpty = true; sum = 0; for (int i = 0; i < nl; i++) { values[i] = 0; } for (int j = startIndex; j <= endIndex; j++) { for (int i = 0; i < nl; i++) { values[i] += chartData.lines[i].y[j]; sum += chartData.lines[i].y[j]; if (isEmpty && lines[i].enabled && chartData.lines[i].y[j] > 0) { isEmpty = false; } } } if (!force) { for (int i = 0; i < nl; i++) { PieChartViewData line = lines[i]; if (line.animator != null) { line.animator.Cancel(); } float animateTo; if (sum == 0) { animateTo = 0; } else { animateTo = values[i] / sum; } ValueAnimator animator = CreateAnimator(line.drawingPart, animateTo, new AnimatorUpdateListener(animation => { line.drawingPart = (float)animation.GetAnimatedValue(); Invalidate(); })); line.animator = animator; animator.Start(); } } else { for (int i = 0; i < nl; i++) { if (sum == 0) { lines[i].drawingPart = 0; } else { lines[i].drawingPart = values[i] / sum; } } } }
public bool Uncapture(PointerPoint point, int pointerIndex) { if (pointerIndex == 0) { if (tryMoveTo) { tryMoveTo = false; float dx = moveToX - (int)point.Position.X; float dy = moveToY - (int)point.Position.Y; if (/*@event.getAction() == MotionEvent.ACTION_UP &&*/ DateTime.Now.ToTimestamp() * 1000 - startTapTime < 300 && Math.Sqrt(dx * dx + dy * dy) < 10) { float moveToX = (this.moveToX - BaseChartView.HORIZONTAL_PADDING) / pickerWidth; float w = pickerEnd - pickerStart; float moveToLeft = moveToX - w / 2f; float moveToRight = moveToX + w / 2f; if (moveToLeft < 0f) { moveToLeft = 0; moveToRight = w; } else if (moveToRight > 1f) { moveToLeft = 1f - w; moveToRight = 1f; } float moveFromLeft = pickerStart; float moveFromRight = pickerEnd; moveToAnimator = ValueAnimator.OfFloat(0f, 1f); float finalMoveToLeft = moveToLeft; float finalMoveToRight = moveToRight; view.OnPickerJumpTo(finalMoveToLeft, finalMoveToRight, true); moveToAnimator.AddUpdateListener(new AnimatorUpdateListener(animation => { float v = (float)animation.GetAnimatedValue(); pickerStart = moveFromLeft + (finalMoveToLeft - moveFromLeft) * v; pickerEnd = moveFromRight + (finalMoveToRight - moveFromRight) * v; view.OnPickerJumpTo(finalMoveToLeft, finalMoveToRight, false); })); moveToAnimator.setInterpolator(BaseChartView.INTERPOLATOR); moveToAnimator.Start(); } return(true); } if (capturedStates[0] != null) { capturedStates[0].uncapture(); } capturedStates[0] = null; if (capturedStates[1] != null) { capturedStates[0] = capturedStates[1]; capturedStates[1] = null; } } else { if (capturedStates[1] != null) { capturedStates[1].uncapture(); } capturedStates[1] = null; } return(false); }