Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuriy Budiyev committed Nov 30, 2017
1 parent da011de commit cfbe535
Showing 1 changed file with 27 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class CircularProgressBar extends View {
private static final float DEFAULT_INDETERMINATE_MINIMUM_ANGLE = 60f;
private static final int DEFAULT_FOREGROUND_STROKE_COLOR = Color.BLUE;
private static final int DEFAULT_BACKGROUND_STROKE_COLOR = Color.BLACK;
private static final int DEFAULT_PROGRESS_ANIMATION_DURATION = 500;
private static final int DEFAULT_PROGRESS_ANIMATION_DURATION = 100;
private static final int DEFAULT_INDETERMINATE_ROTATION_ANIMATION_DURATION = 2000;
private static final int DEFAULT_INDETERMINATE_ARC_ANIMATION_DURATION = 1000;
private static final boolean DEFAULT_ANIMATE_PROGRESS = true;
Expand Down Expand Up @@ -114,6 +114,7 @@ public float getProgress() {
/**
* Set current progress value for non-indeterminate mode
*/
@MainThread
public void setProgress(float progress) {
if (mIndeterminate) {
mProgress = progress;
Expand All @@ -131,6 +132,7 @@ public void setProgress(float progress) {
* Configure progress bar
*/
@NonNull
@MainThread
public Configurator configure() {
return new Configurator();
}
Expand Down Expand Up @@ -258,43 +260,31 @@ private void setProgressInternal(float progress) {
}

private void setProgressAnimated(float progress) {
ValueAnimator progressAnimator = mProgressAnimator;
if (progressAnimator == null) {
setProgressInternal(progress);
} else {
progressAnimator.setFloatValues(mProgress, progress);
progressAnimator.start();
}
mProgressAnimator.setFloatValues(mProgress, progress);
mProgressAnimator.start();
}

private void stopProgressAnimation() {
ValueAnimator progressAnimator = mProgressAnimator;
if (progressAnimator != null && progressAnimator.isRunning()) {
progressAnimator.cancel();
if (mProgressAnimator.isRunning()) {
mProgressAnimator.cancel();
}
}

private void stopIndeterminateAnimations() {
ValueAnimator growAnimator = mIndeterminateStartAnimator;
if (growAnimator != null && growAnimator.isRunning()) {
growAnimator.cancel();
if (mIndeterminateStartAnimator.isRunning()) {
mIndeterminateStartAnimator.cancel();
}
ValueAnimator sweepAnimator = mIndeterminateSweepAnimator;
if (sweepAnimator != null && sweepAnimator.isRunning()) {
sweepAnimator.cancel();
if (mIndeterminateSweepAnimator.isRunning()) {
mIndeterminateSweepAnimator.cancel();
}
}

private void startIndeterminateAnimations() {
if (isLaidOutCompat()) {
ValueAnimator growAnimator = mIndeterminateStartAnimator;
if (growAnimator != null && !growAnimator.isRunning()) {
growAnimator.start();
}
ValueAnimator sweepAnimator = mIndeterminateSweepAnimator;
if (sweepAnimator != null && !sweepAnimator.isRunning()) {
sweepAnimator.start();
}
if (!mIndeterminateStartAnimator.isRunning()) {
mIndeterminateStartAnimator.start();
}
if (!mIndeterminateSweepAnimator.isRunning()) {
mIndeterminateSweepAnimator.start();
}
}

Expand Down Expand Up @@ -332,18 +322,10 @@ protected void onDraw(Canvas canvas) {

@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();
}
int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
int height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
setMeasuredDimension(width, height);
invalidateDrawRect(width, height);
}

@Override
Expand All @@ -352,21 +334,21 @@ protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight)
}

@Override
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
super.onVisibilityChanged(changedView, visibility);
if (visibility == VISIBLE) {
if (mIndeterminate) {
public void onVisibilityAggregated(boolean visible) {
super.onVisibilityAggregated(visible);
if (mIndeterminate) {
if (visible) {
startIndeterminateAnimations();
} else {
stopIndeterminateAnimations();
}
} else {
stopIndeterminateAnimations();
}
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (mIndeterminate && isLaidOutCompat()) {
if (mIndeterminate) {
startIndeterminateAnimations();
}
}
Expand Down

0 comments on commit cfbe535

Please sign in to comment.