Methods Summary |
---|
private synchronized void | doRefreshProgress(int id, int progress, boolean fromUser)
float scale = mMax > 0 ? (float) progress / (float) mMax : 0;
final Drawable d = mCurrentDrawable;
if (d != null) {
Drawable progressDrawable = null;
if (d instanceof LayerDrawable) {
progressDrawable = ((LayerDrawable) d).findDrawableByLayerId(id);
}
final int level = (int) (scale * MAX_LEVEL);
(progressDrawable != null ? progressDrawable : d).setLevel(level);
} else {
invalidate();
}
if (id == R.id.progress) {
onProgressRefresh(scale, fromUser);
}
|
protected void | drawableStateChanged()
super.drawableStateChanged();
int[] state = getDrawableState();
if (mProgressDrawable != null && mProgressDrawable.isStateful()) {
mProgressDrawable.setState(state);
}
if (mIndeterminateDrawable != null && mIndeterminateDrawable.isStateful()) {
mIndeterminateDrawable.setState(state);
}
|
android.graphics.drawable.Drawable | getCurrentDrawable()
return mCurrentDrawable;
|
android.graphics.drawable.shapes.Shape | getDrawableShape()
final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
return new RoundRectShape(roundedCorners, null, null);
|
public android.graphics.drawable.Drawable | getIndeterminateDrawable()Get the drawable used to draw the progress bar in
indeterminate mode.
return mIndeterminateDrawable;
|
public android.view.animation.Interpolator | getInterpolator()Gets the acceleration curve type for the indeterminate animation.
return mInterpolator;
|
public synchronized int | getMax()Return the upper limit of this progress bar's range.
return mMax;
|
public synchronized int | getProgress()Get the progress bar's current level of progress. Return 0 when the
progress bar is in indeterminate mode.
return mIndeterminate ? 0 : mProgress;
|
public android.graphics.drawable.Drawable | getProgressDrawable()Get the drawable used to draw the progress bar in
progress mode.
return mProgressDrawable;
|
public synchronized int | getSecondaryProgress()Get the progress bar's current level of secondary progress. Return 0 when the
progress bar is in indeterminate mode.
return mIndeterminate ? 0 : mSecondaryProgress;
|
public final synchronized void | incrementProgressBy(int diff)Increase the progress bar's progress by the specified amount.
setProgress(mProgress + diff);
|
public final synchronized void | incrementSecondaryProgressBy(int diff)Increase the progress bar's secondary progress by the specified amount.
setSecondaryProgress(mSecondaryProgress + diff);
|
private void | initProgressBar()
Initialize the progress bar's default values:
- progress = 0
- max = 100
- animation duration = 4000 ms
- indeterminate = false
- behavior = repeat
mMax = 100;
mProgress = 0;
mSecondaryProgress = 0;
mIndeterminate = false;
mOnlyIndeterminate = false;
mDuration = 4000;
mBehavior = AlphaAnimation.RESTART;
mMinWidth = 24;
mMaxWidth = 48;
mMinHeight = 24;
mMaxHeight = 48;
|
public void | invalidateDrawable(android.graphics.drawable.Drawable dr)
if (!mInDrawing) {
if (verifyDrawable(dr)) {
final Rect dirty = dr.getBounds();
final int scrollX = mScrollX + mPaddingLeft;
final int scrollY = mScrollY + mPaddingTop;
invalidate(dirty.left + scrollX, dirty.top + scrollY,
dirty.right + scrollX, dirty.bottom + scrollY);
} else {
super.invalidateDrawable(dr);
}
}
|
public synchronized boolean | isIndeterminate()Indicate whether this progress bar is in indeterminate mode.
return mIndeterminate;
|
protected synchronized void | onDraw(android.graphics.Canvas canvas)
super.onDraw(canvas);
Drawable d = mCurrentDrawable;
if (d != null) {
// Translate canvas so a indeterminate circular progress bar with padding
// rotates properly in its animation
canvas.save();
canvas.translate(mPaddingLeft, mPaddingTop);
long time = getDrawingTime();
if (mAnimation != null) {
mAnimation.getTransformation(time, mTransformation);
float scale = mTransformation.getAlpha();
try {
mInDrawing = true;
d.setLevel((int) (scale * MAX_LEVEL));
} finally {
mInDrawing = false;
}
if (SystemClock.uptimeMillis() - mLastDrawTime >= ANIMATION_RESOLUTION) {
mLastDrawTime = SystemClock.uptimeMillis();
postInvalidateDelayed(ANIMATION_RESOLUTION);
}
}
d.draw(canvas);
canvas.restore();
if (mShouldStartAnimationDrawable && d instanceof AnimationDrawable) {
((AnimationDrawable) d).start();
mShouldStartAnimationDrawable = false;
}
}
|
protected synchronized void | onMeasure(int widthMeasureSpec, int heightMeasureSpec)
Drawable d = mCurrentDrawable;
int dw = 0;
int dh = 0;
if (d != null) {
dw = Math.max(mMinWidth, Math.min(mMaxWidth, d.getIntrinsicWidth()));
dh = Math.max(mMinHeight, Math.min(mMaxHeight, d.getIntrinsicHeight()));
}
dw += mPaddingLeft + mPaddingRight;
dh += mPaddingTop + mPaddingBottom;
setMeasuredDimension(resolveSize(dw, widthMeasureSpec),
resolveSize(dh, heightMeasureSpec));
|
void | onProgressRefresh(float scale, boolean fromUser)
|
public void | onRestoreInstanceState(android.os.Parcelable state)
SavedState ss = (SavedState) state;
super.onRestoreInstanceState(ss.getSuperState());
setProgress(ss.progress);
setSecondaryProgress(ss.secondaryProgress);
|
public android.os.Parcelable | onSaveInstanceState()
// Force our ancestor class to save its state
Parcelable superState = super.onSaveInstanceState();
SavedState ss = new SavedState(superState);
ss.progress = mProgress;
ss.secondaryProgress = mSecondaryProgress;
return ss;
|
protected void | onSizeChanged(int w, int h, int oldw, int oldh)
// onDraw will translate the canvas so we draw starting at 0,0
int right = w - mPaddingRight - mPaddingLeft;
int bottom = h - mPaddingBottom - mPaddingTop;
if (mIndeterminateDrawable != null) {
mIndeterminateDrawable.setBounds(0, 0, right, bottom);
}
if (mProgressDrawable != null) {
mProgressDrawable.setBounds(0, 0, right, bottom);
}
|
public void | postInvalidate()
if (!mNoInvalidate) {
super.postInvalidate();
}
|
private synchronized void | refreshProgress(int id, int progress, boolean fromUser)
if (mUiThreadId == Thread.currentThread().getId()) {
doRefreshProgress(id, progress, fromUser);
} else {
RefreshProgressRunnable r;
if (mRefreshProgressRunnable != null) {
// Use cached RefreshProgressRunnable if available
r = mRefreshProgressRunnable;
// Uncache it
mRefreshProgressRunnable = null;
r.setup(id, progress, fromUser);
} else {
// Make a new one
r = new RefreshProgressRunnable(id, progress, fromUser);
}
post(r);
}
|
public synchronized void | setIndeterminate(boolean indeterminate)Change the indeterminate mode for this progress bar. In indeterminate
mode, the progress is ignored and the progress bar shows an infinite
animation instead.
If this progress bar's style only supports indeterminate mode (such as the circular
progress bars), then this will be ignored.
if ((!mOnlyIndeterminate || !mIndeterminate) && indeterminate != mIndeterminate) {
mIndeterminate = indeterminate;
if (indeterminate) {
// swap between indeterminate and regular backgrounds
mCurrentDrawable = mIndeterminateDrawable;
startAnimation();
} else {
mCurrentDrawable = mProgressDrawable;
stopAnimation();
}
}
|
public void | setIndeterminateDrawable(android.graphics.drawable.Drawable d)Define the drawable used to draw the progress bar in
indeterminate mode.
if (d != null) {
d.setCallback(this);
}
mIndeterminateDrawable = d;
if (mIndeterminate) {
mCurrentDrawable = d;
postInvalidate();
}
|
public void | setInterpolator(android.content.Context context, int resID)Sets the acceleration curve for the indeterminate animation.
The interpolator is loaded as a resource from the specified context.
setInterpolator(AnimationUtils.loadInterpolator(context, resID));
|
public void | setInterpolator(android.view.animation.Interpolator interpolator)Sets the acceleration curve for the indeterminate animation.
Defaults to a linear interpolation.
mInterpolator = interpolator;
|
public synchronized void | setMax(int max)Set the range of the progress bar to 0...max.
if (max < 0) {
max = 0;
}
if (max != mMax) {
mMax = max;
postInvalidate();
if (mProgress > max) {
mProgress = max;
}
}
|
public synchronized void | setProgress(int progress)Set the current progress to the specified value. Does not do anything
if the progress bar is in indeterminate mode.
setProgress(progress, false);
|
synchronized void | setProgress(int progress, boolean fromUser)
if (mIndeterminate) {
return;
}
if (progress < 0) {
progress = 0;
}
if (progress > mMax) {
progress = mMax;
}
if (progress != mProgress) {
mProgress = progress;
refreshProgress(R.id.progress, mProgress, fromUser);
}
|
public void | setProgressDrawable(android.graphics.drawable.Drawable d)Define the drawable used to draw the progress bar in
progress mode.
if (d != null) {
d.setCallback(this);
}
mProgressDrawable = d;
if (!mIndeterminate) {
mCurrentDrawable = d;
postInvalidate();
}
|
public synchronized void | setSecondaryProgress(int secondaryProgress)
Set the current secondary progress to the specified value. Does not do
anything if the progress bar is in indeterminate mode.
if (mIndeterminate) {
return;
}
if (secondaryProgress < 0) {
secondaryProgress = 0;
}
if (secondaryProgress > mMax) {
secondaryProgress = mMax;
}
if (secondaryProgress != mSecondaryProgress) {
mSecondaryProgress = secondaryProgress;
refreshProgress(R.id.secondaryProgress, mSecondaryProgress, false);
}
|
public void | setVisibility(int v)
if (getVisibility() != v) {
super.setVisibility(v);
if (mIndeterminate) {
// let's be nice with the UI thread
if (v == GONE || v == INVISIBLE) {
stopAnimation();
} else if (v == VISIBLE) {
startAnimation();
}
}
}
|
void | startAnimation()Start the indeterminate progress animation.
int visibility = getVisibility();
if (visibility != VISIBLE) {
return;
}
if (mIndeterminateDrawable instanceof AnimationDrawable) {
mShouldStartAnimationDrawable = true;
mAnimation = null;
} else {
if (mInterpolator == null) {
mInterpolator = new LinearInterpolator();
}
mTransformation = new Transformation();
mAnimation = new AlphaAnimation(0.0f, 1.0f);
mAnimation.setRepeatMode(mBehavior);
mAnimation.setRepeatCount(Animation.INFINITE);
mAnimation.setDuration(mDuration);
mAnimation.setInterpolator(mInterpolator);
mAnimation.setStartTime(Animation.START_ON_FIRST_FRAME);
postInvalidate();
}
|
void | stopAnimation()Stop the indeterminate progress animation.
mAnimation = null;
mTransformation = null;
if (mIndeterminateDrawable instanceof AnimationDrawable) {
((AnimationDrawable) mIndeterminateDrawable).stop();
mShouldStartAnimationDrawable = false;
}
|
private android.graphics.drawable.Drawable | tileify(android.graphics.drawable.Drawable drawable, boolean clip)Converts a drawable to a tiled version of itself. It will recursively
traverse layer and state list drawables.
if (drawable instanceof LayerDrawable) {
LayerDrawable background = (LayerDrawable) drawable;
final int N = background.getNumberOfLayers();
Drawable[] outDrawables = new Drawable[N];
for (int i = 0; i < N; i++) {
int id = background.getId(i);
outDrawables[i] = tileify(background.getDrawable(i),
(id == R.id.progress || id == R.id.secondaryProgress));
}
LayerDrawable newBg = new LayerDrawable(outDrawables);
for (int i = 0; i < N; i++) {
newBg.setId(i, background.getId(i));
}
return newBg;
} else if (drawable instanceof StateListDrawable) {
StateListDrawable in = (StateListDrawable) drawable;
StateListDrawable out = new StateListDrawable();
int numStates = in.getStateCount();
for (int i = 0; i < numStates; i++) {
out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
}
return out;
} else if (drawable instanceof BitmapDrawable) {
final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
if (mSampleTile == null) {
mSampleTile = tileBitmap;
}
final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
final BitmapShader bitmapShader = new BitmapShader(tileBitmap,
Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
shapeDrawable.getPaint().setShader(bitmapShader);
return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT,
ClipDrawable.HORIZONTAL) : shapeDrawable;
}
return drawable;
|
private android.graphics.drawable.Drawable | tileifyIndeterminate(android.graphics.drawable.Drawable drawable)Convert a AnimationDrawable for use as a barberpole animation.
Each frame of the animation is wrapped in a ClipDrawable and
given a tiling BitmapShader.
if (drawable instanceof AnimationDrawable) {
AnimationDrawable background = (AnimationDrawable) drawable;
final int N = background.getNumberOfFrames();
AnimationDrawable newBg = new AnimationDrawable();
newBg.setOneShot(background.isOneShot());
for (int i = 0; i < N; i++) {
Drawable frame = tileify(background.getFrame(i), true);
frame.setLevel(10000);
newBg.addFrame(frame, background.getDuration(i));
}
newBg.setLevel(10000);
drawable = newBg;
}
return drawable;
|
protected boolean | verifyDrawable(android.graphics.drawable.Drawable who)
return who == mProgressDrawable || who == mIndeterminateDrawable
|| super.verifyDrawable(who);
|