Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy-budiyev committed Dec 16, 2017
1 parent fdbb62f commit 8c9fd30
Showing 1 changed file with 15 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
Expand All @@ -39,6 +38,7 @@
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.annotation.StyleRes;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
Expand Down Expand Up @@ -76,6 +76,7 @@ public class CircularProgressBar extends View {
private boolean mAnimateProgress;
private boolean mDrawBackgroundStroke;
private boolean mIndeterminateGrowMode;
private boolean mVisible;
private Paint mForegroundStrokePaint;
private Paint mBackgroundStrokePaint;
private RectF mDrawRect;
Expand All @@ -98,7 +99,7 @@ public CircularProgressBar(@NonNull Context context, @Nullable AttributeSet attr
initialize(context, attrs, defStyleAttr, 0);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public CircularProgressBar(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
Expand All @@ -116,12 +117,11 @@ public boolean isIndeterminate() {
* Indeterminate mode, disabled by default
*/
public void setIndeterminate(boolean indeterminate) {
stopIndeterminateAnimations();
mIndeterminate = indeterminate;
invalidate();
if (indeterminate) {
if (mVisible && indeterminate) {
startIndeterminateAnimations();
} else {
stopIndeterminateAnimations();
}
}

Expand All @@ -140,7 +140,7 @@ public void setProgress(float progress) {
mProgress = progress;
} else {
stopProgressAnimation();
if (mAnimateProgress && isLaidOutCompat()) {
if (mVisible && mAnimateProgress) {
setProgressAnimated(progress);
} else {
setProgressInternal(progress);
Expand Down Expand Up @@ -183,14 +183,11 @@ public void setAnimateProgress(boolean animate) {
* Minimum angle for indeterminate mode
*/
public void setIndeterminateMinimumAngle(@FloatRange(from = 0f, to = 360f) float angle) {
boolean animating = isIndeterminateAnimating();
if (animating) {
stopIndeterminateAnimations();
}
stopIndeterminateAnimations();
mIndeterminateMinimumAngle = angle;
mIndeterminateSweepAnimator.setFloatValues(360f - angle * 2f);
invalidate();
if (animating) {
if (mVisible && mIndeterminate) {
startIndeterminateAnimations();
}
}
Expand All @@ -199,13 +196,10 @@ public void setIndeterminateMinimumAngle(@FloatRange(from = 0f, to = 360f) float
* Rotation animation duration for indeterminate mode
*/
public void setIndeterminateRotationAnimationDuration(@IntRange(from = 0) long duration) {
boolean animating = isIndeterminateAnimating();
if (animating) {
stopIndeterminateAnimations();
}
stopIndeterminateAnimations();
mIndeterminateStartAnimator.setDuration(duration);
invalidate();
if (animating) {
if (mVisible && mIndeterminate) {
startIndeterminateAnimations();
}
}
Expand All @@ -214,13 +208,10 @@ public void setIndeterminateRotationAnimationDuration(@IntRange(from = 0) long d
* Sweep animation duration for indeterminate mode
*/
public void setIndeterminateSweepAnimationDuration(@IntRange(from = 0) long duration) {
boolean animating = isIndeterminateAnimating();
if (animating) {
stopIndeterminateAnimations();
}
stopIndeterminateAnimations();
mIndeterminateSweepAnimator.setDuration(duration);
invalidate();
if (animating) {
if (mVisible && mIndeterminate) {
startIndeterminateAnimations();
}
}
Expand Down Expand Up @@ -271,6 +262,7 @@ public void setDrawBackgroundStroke(boolean draw) {
@Override
public void onVisibilityAggregated(boolean visible) {
super.onVisibilityAggregated(visible);
mVisible = visible;
if (mIndeterminate) {
if (visible) {
startIndeterminateAnimations();
Expand Down Expand Up @@ -328,6 +320,7 @@ protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight)
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mVisible = true;
if (mIndeterminate) {
startIndeterminateAnimations();
}
Expand All @@ -336,6 +329,7 @@ protected void onAttachedToWindow() {
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mVisible = false;
stopIndeterminateAnimations();
stopProgressAnimation();
}
Expand Down Expand Up @@ -426,10 +420,6 @@ private void initialize(@NonNull Context context, @Nullable AttributeSet attribu
mIndeterminateSweepAnimator.addListener(new SweepAnimatorListener());
}

private boolean isLaidOutCompat() {
return getWidth() > 0 && getHeight() > 0;
}

private void invalidateDrawRect() {
int width = getWidth();
int height = getHeight();
Expand Down Expand Up @@ -493,10 +483,6 @@ private void startIndeterminateAnimations() {
}
}

private boolean isIndeterminateAnimating() {
return mIndeterminate && (mIndeterminateStartAnimator.isRunning() || mIndeterminateSweepAnimator.isRunning());
}

private final class ProgressUpdateListener implements ValueAnimator.AnimatorUpdateListener {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Expand Down

0 comments on commit 8c9fd30

Please sign in to comment.