コード例 #1
0
 public void captured()
 {
     a = ValueAnimator.ofFloat(view, 0, 1f);
     a.setDuration(600);
     a.setInterpolator(BaseChartView.INTERPOLATOR);
     a.addUpdateListener(new AnimatorUpdateListener(animation =>
     {
         aValue = (float)animation.getAnimatedValue();
         view.invalidate();
     }));
     a.start();
 }
コード例 #2
0
        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;
                    }
                }
            }
        }
コード例 #3
0
        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 - 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(view, 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);
        }