diff --git a/README.md b/README.md index 03c1833..bb278dd 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ In build.gradle config dependency. ``` groovy -compile 'org.quanqi:CircularProgress:1.0.0' +compile 'org.quanqi:CircularProgress:1.0.2' ``` In laout xml diff --git a/deploy.gradle b/deploy.gradle index 3f03089..d201190 100644 --- a/deploy.gradle +++ b/deploy.gradle @@ -1,5 +1,6 @@ /* * Copyright 2013 Chris Banes + * Copyright 2014 Jing Quanqi * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/gradle.properties b/library/gradle.properties index 29bf8a0..40c2e56 100644 --- a/library/gradle.properties +++ b/library/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.0.1 +VERSION_NAME=1.0.2 VERSION_CODE=2 GROUP=org.quanqi diff --git a/library/src/main/java/org/quanqi/circularprogress/CircularProgressDrawable.java b/library/src/main/java/org/quanqi/circularprogress/CircularProgressDrawable.java index 023279a..2ccc581 100644 --- a/library/src/main/java/org/quanqi/circularprogress/CircularProgressDrawable.java +++ b/library/src/main/java/org/quanqi/circularprogress/CircularProgressDrawable.java @@ -26,11 +26,12 @@ public class CircularProgressDrawable extends Drawable implements Animatable { private static final Interpolator SWEEP_INTERPOLATOR = new DecelerateInterpolator(); - private static final int ANGLE_ANIMATOR_DURATION = 2000; + private int angleAnimatorDuration = 2000; - private static final int SWEEP_ANIMATOR_DURATION = 600; + private int sweepAnimatorDuration = 600; + + private int minSweepAngle = 30; - private static final int MIN_SWEEP_ANGLE = 30; private final RectF fBounds = new RectF(); private ObjectAnimator mObjectAnimatorSweep; @@ -67,10 +68,10 @@ public void draw(Canvas canvas) { float startAngle = mCurrentGlobalAngle - mCurrentGlobalAngleOffset; float sweepAngle = mCurrentSweepAngle; if (mModeAppearing) { - sweepAngle += MIN_SWEEP_ANGLE; + sweepAngle += minSweepAngle; } else { startAngle = startAngle + sweepAngle; - sweepAngle = 360 - sweepAngle - MIN_SWEEP_ANGLE; + sweepAngle = 360 - sweepAngle - minSweepAngle; } canvas.drawArc(fBounds, startAngle, sweepAngle, false, mPaint); } @@ -93,7 +94,7 @@ public int getOpacity() { private void toggleAppearingMode() { mModeAppearing = !mModeAppearing; if (mModeAppearing) { - mCurrentGlobalAngleOffset = (mCurrentGlobalAngleOffset + MIN_SWEEP_ANGLE * 2) % 360; + mCurrentGlobalAngleOffset = (mCurrentGlobalAngleOffset + minSweepAngle * 2) % 360; } } @@ -136,14 +137,14 @@ public void set(CircularProgressDrawable object, Float value) { private void setupAnimations() { mObjectAnimatorAngle = ObjectAnimator.ofFloat(this, mAngleProperty, 360f); mObjectAnimatorAngle.setInterpolator(ANGLE_INTERPOLATOR); - mObjectAnimatorAngle.setDuration(ANGLE_ANIMATOR_DURATION); + mObjectAnimatorAngle.setDuration(angleAnimatorDuration); mObjectAnimatorAngle.setRepeatMode(ValueAnimator.RESTART); mObjectAnimatorAngle.setRepeatCount(ValueAnimator.INFINITE); mObjectAnimatorSweep = ObjectAnimator.ofFloat(this, - mSweepProperty, 360f - MIN_SWEEP_ANGLE * 2); + mSweepProperty, 360f - minSweepAngle * 2); mObjectAnimatorSweep.setInterpolator(SWEEP_INTERPOLATOR); - mObjectAnimatorSweep.setDuration(SWEEP_ANIMATOR_DURATION); + mObjectAnimatorSweep.setDuration(sweepAnimatorDuration); mObjectAnimatorSweep.setRepeatMode(ValueAnimator.RESTART); mObjectAnimatorSweep.setRepeatCount(ValueAnimator.INFINITE); mObjectAnimatorSweep.addListener(new Animator.AnimatorListener() { @@ -214,4 +215,37 @@ public float getCurrentSweepAngle() { return mCurrentSweepAngle; } + public static final class Builder { + + private CircularProgressDrawable drawable; + private int angleAnimatorDuration = 2000; + private int sweepAnimatorDuration = 600; + private int minSweepAngle = 30; + private int borderWidth = 4; + private int color = 0x00ff00; + + public CircularProgressDrawable build() { + CircularProgressDrawable drawable = new CircularProgressDrawable(color, borderWidth); + drawable.angleAnimatorDuration = angleAnimatorDuration; + drawable.sweepAnimatorDuration = sweepAnimatorDuration; + drawable.minSweepAngle = minSweepAngle; + return drawable; + } + + public void angleAnimatorDuration(int millis) { + this.angleAnimatorDuration = millis; + } + + public void sweepAnimatorDuration(int millis) { + this.sweepAnimatorDuration = millis; + } + + public void borderWidth(int px) { + this.borderWidth = px; + } + + public void color(int color) { + this.color = color; + } + } }