From 66deb1a2c21b3d264f857f74652bcceb62dcf935 Mon Sep 17 00:00:00 2001 From: Yuriy Budiyev Date: Thu, 23 Nov 2017 15:32:26 +0300 Subject: [PATCH] Dev --- .../CircularProgressBar.java | 154 +++++++++--------- 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/src/main/java/com/budiyev/android/circularprogressbar/CircularProgressBar.java b/src/main/java/com/budiyev/android/circularprogressbar/CircularProgressBar.java index 89ddab1..a85b536 100644 --- a/src/main/java/com/budiyev/android/circularprogressbar/CircularProgressBar.java +++ b/src/main/java/com/budiyev/android/circularprogressbar/CircularProgressBar.java @@ -136,83 +136,6 @@ public Configurator configure() { return new Configurator(); } - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - int measuredWidth = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec); - int measuredHeight = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec); - setMeasuredDimension(measuredWidth, measuredHeight); - invalidateDrawRect(measuredWidth, measuredHeight); - } - - @Override - protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - invalidateDrawRect(); - if (mIndeterminate) { - startIndeterminateAnimations(); - } - } - - @Override - protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) { - invalidateDrawRect(width, height); - } - - @Override - protected void onVisibilityChanged(@NonNull View changedView, int visibility) { - super.onVisibilityChanged(changedView, visibility); - if (visibility == VISIBLE) { - if (mIndeterminate) { - startIndeterminateAnimations(); - } - } else { - stopIndeterminateAnimations(); - } - } - - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - if (mIndeterminate && isLaidOutCompat()) { - startIndeterminateAnimations(); - } - } - - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - stopIndeterminateAnimations(); - stopProgressAnimation(); - } - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - if (mDrawBackgroundStroke) { - canvas.drawOval(mDrawRect, mBackgroundStrokePaint); - } - float start; - float sweep; - if (mIndeterminate) { - float startAngle = mIndeterminateStartAngle; - float sweepAngle = mIndeterminateSweepAngle; - float offsetAngle = mIndeterminateOffsetAngle; - float minimumAngle = mIndeterminateMinimumAngle; - if (mIndeterminateGrowMode) { - start = startAngle - offsetAngle; - sweep = sweepAngle + minimumAngle; - } else { - start = startAngle + sweepAngle - offsetAngle; - sweep = 360f - sweepAngle - minimumAngle; - } - } else { - float maximum = mMaximum; - float progress = mProgress; - start = mStartAngle; - sweep = 360f * Math.abs(progress) > Math.abs(maximum) ? maximum : progress / maximum; - } - canvas.drawArc(mDrawRect, start, sweep, false, mForegroundStrokePaint); - } - private void initialize(@NonNull Context context, @Nullable AttributeSet attributeSet, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { mDrawRect = new RectF(); @@ -386,6 +309,83 @@ private void startIndeterminateAnimations() { } } + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + if (mDrawBackgroundStroke) { + canvas.drawOval(mDrawRect, mBackgroundStrokePaint); + } + float start; + float sweep; + if (mIndeterminate) { + float startAngle = mIndeterminateStartAngle; + float sweepAngle = mIndeterminateSweepAngle; + float offsetAngle = mIndeterminateOffsetAngle; + float minimumAngle = mIndeterminateMinimumAngle; + if (mIndeterminateGrowMode) { + start = startAngle - offsetAngle; + sweep = sweepAngle + minimumAngle; + } else { + start = startAngle + sweepAngle - offsetAngle; + sweep = 360f - sweepAngle - minimumAngle; + } + } else { + float maximum = mMaximum; + float progress = mProgress; + start = mStartAngle; + sweep = 360f * (Math.abs(progress) >= Math.abs(maximum) ? 1f : progress / maximum); + } + canvas.drawArc(mDrawRect, start, sweep, false, mForegroundStrokePaint); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int measuredWidth = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec); + int measuredHeight = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec); + setMeasuredDimension(measuredWidth, measuredHeight); + invalidateDrawRect(measuredWidth, measuredHeight); + } + + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + invalidateDrawRect(); + if (mIndeterminate) { + startIndeterminateAnimations(); + } + } + + @Override + protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) { + invalidateDrawRect(width, height); + } + + @Override + protected void onVisibilityChanged(@NonNull View changedView, int visibility) { + super.onVisibilityChanged(changedView, visibility); + if (visibility == VISIBLE) { + if (mIndeterminate) { + startIndeterminateAnimations(); + } + } else { + stopIndeterminateAnimations(); + } + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + if (mIndeterminate && isLaidOutCompat()) { + startIndeterminateAnimations(); + } + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + stopIndeterminateAnimations(); + stopProgressAnimation(); + } + public final class Configurator { private long progressAnimationDuration; private long indeterminateGrowAnimationDuration;