Fields Summary |
---|
private static final android.view.animation.Interpolator | LINEAR_INTERPOLATOR |
private static final android.view.animation.Interpolator | END_CURVE_INTERPOLATOR |
private static final android.view.animation.Interpolator | START_CURVE_INTERPOLATOR |
private static final android.view.animation.Interpolator | EASE_INTERPOLATOR |
static final int | LARGE |
static final int | DEFAULT |
private static final int | CIRCLE_DIAMETER |
private static final float | CENTER_RADIUS |
private static final float | STROKE_WIDTH |
private static final int | CIRCLE_DIAMETER_LARGE |
private static final float | CENTER_RADIUS_LARGE |
private static final float | STROKE_WIDTH_LARGE |
private final int[] | COLORS |
private static final int | ANIMATION_DURATIONThe duration of a single progress spin in milliseconds. |
private static final float | NUM_POINTSThe number of points in the progress "star". |
private final ArrayList | mAnimatorsThe list of animators operating on this drawable. |
private final Ring | mRingThe indicator ring, used to manage animation state. |
private float | mRotationCanvas rotation in degrees. |
private static final int | ARROW_WIDTHLayout info for the arrowhead in dp |
private static final int | ARROW_HEIGHT |
private static final float | ARROW_OFFSET_ANGLE |
private static final int | ARROW_WIDTH_LARGELayout info for the arrowhead for the large spinner in dp |
private static final int | ARROW_HEIGHT_LARGE |
private static final float | MAX_PROGRESS_ARC |
private android.content.res.Resources | mResources |
private android.view.View | mParent |
private android.view.animation.Animation | mAnimation |
private float | mRotationCount |
private double | mWidth |
private double | mHeight |
boolean | mFinishing |
private final Callback | mCallback |
Methods Summary |
---|
private void | applyFinishTranslation(float interpolatedTime, android.support.v4.widget.MaterialProgressDrawable$Ring ring)
// shrink back down and complete a full rotation before
// starting other circles
// Rotation goes between [0..1].
float targetRotation = (float) (Math.floor(ring.getStartingRotation() / MAX_PROGRESS_ARC)
+ 1f);
final float startTrim = ring.getStartingStartTrim()
+ (ring.getStartingEndTrim() - ring.getStartingStartTrim()) * interpolatedTime;
ring.setStartTrim(startTrim);
final float rotation = ring.getStartingRotation()
+ ((targetRotation - ring.getStartingRotation()) * interpolatedTime);
ring.setRotation(rotation);
|
public void | draw(android.graphics.Canvas c)
final Rect bounds = getBounds();
final int saveCount = c.save();
c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
mRing.draw(c, bounds);
c.restoreToCount(saveCount);
|
public int | getAlpha()
return mRing.getAlpha();
|
public int | getIntrinsicHeight()
return (int) mHeight;
|
public int | getIntrinsicWidth()
return (int) mWidth;
|
public int | getOpacity()
return PixelFormat.TRANSLUCENT;
|
private float | getRotation()
return mRotation;
|
public boolean | isRunning()
final ArrayList<Animation> animators = mAnimators;
final int N = animators.size();
for (int i = 0; i < N; i++) {
final Animation animator = animators.get(i);
if (animator.hasStarted() && !animator.hasEnded()) {
return true;
}
}
return false;
|
public void | setAlpha(int alpha)
mRing.setAlpha(alpha);
|
public void | setArrowScale(float scale)
mRing.setArrowScale(scale);
|
public void | setBackgroundColor(int color)Update the background color of the circle image view.
mRing.setBackgroundColor(color);
|
public void | setColorFilter(android.graphics.ColorFilter colorFilter)
mRing.setColorFilter(colorFilter);
|
public void | setColorSchemeColors(int colors)Set the colors used in the progress animation from color resources.
The first color will also be the color of the bar that grows in response
to a user swipe gesture.
mRing.setColors(colors);
mRing.setColorIndex(0);
|
public void | setProgressRotation(float rotation)Set the amount of rotation to apply to the progress spinner.
mRing.setRotation(rotation);
|
void | setRotation(float rotation)
mRotation = rotation;
invalidateSelf();
|
private void | setSizeParameters(double progressCircleWidth, double progressCircleHeight, double centerRadius, double strokeWidth, float arrowWidth, float arrowHeight)
final Ring ring = mRing;
final DisplayMetrics metrics = mResources.getDisplayMetrics();
final float screenDensity = metrics.density;
mWidth = progressCircleWidth * screenDensity;
mHeight = progressCircleHeight * screenDensity;
ring.setStrokeWidth((float) strokeWidth * screenDensity);
ring.setCenterRadius(centerRadius * screenDensity);
ring.setColorIndex(0);
ring.setArrowDimensions(arrowWidth * screenDensity, arrowHeight * screenDensity);
ring.setInsets((int) mWidth, (int) mHeight);
|
public void | setStartEndTrim(float startAngle, float endAngle)Set the start and end trim for the progress spinner arc.
mRing.setStartTrim(startAngle);
mRing.setEndTrim(endAngle);
|
private void | setupAnimators()
final Ring ring = mRing;
final Animation animation = new Animation() {
@Override
public void applyTransformation(float interpolatedTime, Transformation t) {
if (mFinishing) {
applyFinishTranslation(interpolatedTime, ring);
} else {
// The minProgressArc is calculated from 0 to create an
// angle that
// matches the stroke width.
final float minProgressArc = (float) Math.toRadians(
ring.getStrokeWidth() / (2 * Math.PI * ring.getCenterRadius()));
final float startingEndTrim = ring.getStartingEndTrim();
final float startingTrim = ring.getStartingStartTrim();
final float startingRotation = ring.getStartingRotation();
// Offset the minProgressArc to where the endTrim is
// located.
final float minArc = MAX_PROGRESS_ARC - minProgressArc;
final float endTrim = startingEndTrim + (minArc
* START_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime));
ring.setEndTrim(endTrim);
final float startTrim = startingTrim + (MAX_PROGRESS_ARC
* END_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime));
ring.setStartTrim(startTrim);
final float rotation = startingRotation + (0.25f * interpolatedTime);
ring.setRotation(rotation);
float groupRotation = ((720.0f / NUM_POINTS) * interpolatedTime)
+ (720.0f * (mRotationCount / NUM_POINTS));
setRotation(groupRotation);
}
}
};
animation.setRepeatCount(Animation.INFINITE);
animation.setRepeatMode(Animation.RESTART);
animation.setInterpolator(LINEAR_INTERPOLATOR);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
mRotationCount = 0;
}
@Override
public void onAnimationEnd(Animation animation) {
// do nothing
}
@Override
public void onAnimationRepeat(Animation animation) {
ring.storeOriginals();
ring.goToNextColor();
ring.setStartTrim(ring.getEndTrim());
if (mFinishing) {
// finished closing the last ring from the swipe gesture; go
// into progress mode
mFinishing = false;
animation.setDuration(ANIMATION_DURATION);
ring.setShowArrow(false);
} else {
mRotationCount = (mRotationCount + 1) % (NUM_POINTS);
}
}
});
mAnimation = animation;
|
public void | showArrow(boolean show)
mRing.setShowArrow(show);
|
public void | start()
mAnimation.reset();
mRing.storeOriginals();
// Already showing some part of the ring
if (mRing.getEndTrim() != mRing.getStartTrim()) {
mFinishing = true;
mAnimation.setDuration(ANIMATION_DURATION/2);
mParent.startAnimation(mAnimation);
} else {
mRing.setColorIndex(0);
mRing.resetOriginals();
mAnimation.setDuration(ANIMATION_DURATION);
mParent.startAnimation(mAnimation);
}
|
public void | stop()
mParent.clearAnimation();
setRotation(0);
mRing.setShowArrow(false);
mRing.setColorIndex(0);
mRing.resetOriginals();
|
public void | updateSizes(int size)Set the overall size for the progress spinner. This updates the radius
and stroke width of the ring.
if (size == LARGE) {
setSizeParameters(CIRCLE_DIAMETER_LARGE, CIRCLE_DIAMETER_LARGE, CENTER_RADIUS_LARGE,
STROKE_WIDTH_LARGE, ARROW_WIDTH_LARGE, ARROW_HEIGHT_LARGE);
} else {
setSizeParameters(CIRCLE_DIAMETER, CIRCLE_DIAMETER, CENTER_RADIUS, STROKE_WIDTH,
ARROW_WIDTH, ARROW_HEIGHT);
}
|