Methods Summary |
---|
private void | applyIndeterminateTint()
if (mIndeterminateDrawable != null && mProgressTintInfo != null) {
final ProgressTintInfo tintInfo = mProgressTintInfo;
if (tintInfo.mHasIndeterminateTint || tintInfo.mHasIndeterminateTintMode) {
mIndeterminateDrawable = mIndeterminateDrawable.mutate();
if (tintInfo.mHasIndeterminateTint) {
mIndeterminateDrawable.setTintList(tintInfo.mIndeterminateTintList);
}
if (tintInfo.mHasIndeterminateTintMode) {
mIndeterminateDrawable.setTintMode(tintInfo.mIndeterminateTintMode);
}
// The drawable (or one of its children) may not have been
// stateful before applying the tint, so let's try again.
if (mIndeterminateDrawable.isStateful()) {
mIndeterminateDrawable.setState(getDrawableState());
}
}
}
|
private void | applyPrimaryProgressTint()Should only be called if we've already verified that mProgressDrawable
and mProgressTintInfo are non-null.
if (mProgressTintInfo.mHasProgressTint
|| mProgressTintInfo.mHasProgressTintMode) {
final Drawable target = getTintTarget(R.id.progress, true);
if (target != null) {
if (mProgressTintInfo.mHasProgressTint) {
target.setTintList(mProgressTintInfo.mProgressTintList);
}
if (mProgressTintInfo.mHasProgressTintMode) {
target.setTintMode(mProgressTintInfo.mProgressTintMode);
}
// The drawable (or one of its children) may not have been
// stateful before applying the tint, so let's try again.
if (target.isStateful()) {
target.setState(getDrawableState());
}
}
}
|
private void | applyProgressBackgroundTint()Should only be called if we've already verified that mProgressDrawable
and mProgressTintInfo are non-null.
if (mProgressTintInfo.mHasProgressBackgroundTint
|| mProgressTintInfo.mHasProgressBackgroundTintMode) {
final Drawable target = getTintTarget(R.id.background, false);
if (target != null) {
if (mProgressTintInfo.mHasProgressBackgroundTint) {
target.setTintList(mProgressTintInfo.mProgressBackgroundTintList);
}
if (mProgressTintInfo.mHasProgressBackgroundTintMode) {
target.setTintMode(mProgressTintInfo.mProgressBackgroundTintMode);
}
// The drawable (or one of its children) may not have been
// stateful before applying the tint, so let's try again.
if (target.isStateful()) {
target.setState(getDrawableState());
}
}
}
|
private void | applyProgressTints()Applies the progress tints in order of increasing specificity.
if (mProgressDrawable != null && mProgressTintInfo != null) {
applyPrimaryProgressTint();
applyProgressBackgroundTint();
applySecondaryProgressTint();
}
|
private void | applySecondaryProgressTint()Should only be called if we've already verified that mProgressDrawable
and mProgressTintInfo are non-null.
if (mProgressTintInfo.mHasSecondaryProgressTint
|| mProgressTintInfo.mHasSecondaryProgressTintMode) {
final Drawable target = getTintTarget(R.id.secondaryProgress, false);
if (target != null) {
if (mProgressTintInfo.mHasSecondaryProgressTint) {
target.setTintList(mProgressTintInfo.mSecondaryProgressTintList);
}
if (mProgressTintInfo.mHasSecondaryProgressTintMode) {
target.setTintMode(mProgressTintInfo.mSecondaryProgressTintMode);
}
// The drawable (or one of its children) may not have been
// stateful before applying the tint, so let's try again.
if (target.isStateful()) {
target.setState(getDrawableState());
}
}
}
|
private synchronized void | doRefreshProgress(int id, int progress, boolean fromUser, boolean callBackToApp)
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);
if (progressDrawable != null && canResolveLayoutDirection()) {
progressDrawable.setLayoutDirection(getLayoutDirection());
}
}
final int level = (int) (scale * MAX_LEVEL);
(progressDrawable != null ? progressDrawable : d).setLevel(level);
} else {
invalidate();
}
if (callBackToApp && id == R.id.progress) {
onProgressRefresh(scale, fromUser);
}
|
void | drawTrack(android.graphics.Canvas canvas)Draws the progress bar track.
final Drawable d = mCurrentDrawable;
if (d != null) {
// Translate canvas so a indeterminate circular progress bar with padding
// rotates properly in its animation
final int saveCount = canvas.save();
if(isLayoutRtl() && mMirrorForRtl) {
canvas.translate(getWidth() - mPaddingRight, mPaddingTop);
canvas.scale(-1.0f, 1.0f);
} else {
canvas.translate(mPaddingLeft, mPaddingTop);
}
final long time = getDrawingTime();
if (mHasAnimation) {
mAnimation.getTransformation(time, mTransformation);
final float scale = mTransformation.getAlpha();
try {
mInDrawing = true;
d.setLevel((int) (scale * MAX_LEVEL));
} finally {
mInDrawing = false;
}
postInvalidateOnAnimation();
}
d.draw(canvas);
canvas.restoreToCount(saveCount);
if (mShouldStartAnimationDrawable && d instanceof Animatable) {
((Animatable) d).start();
mShouldStartAnimationDrawable = false;
}
}
|
public void | drawableHotspotChanged(float x, float y)
super.drawableHotspotChanged(x, y);
if (mProgressDrawable != null) {
mProgressDrawable.setHotspot(x, y);
}
if (mIndeterminateDrawable != null) {
mIndeterminateDrawable.setHotspot(x, y);
}
|
protected void | drawableStateChanged()
super.drawableStateChanged();
updateDrawableState();
|
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.content.res.ColorStateList | getIndeterminateTintList()
return mProgressTintInfo != null ? mProgressTintInfo.mIndeterminateTintList : null;
|
public android.graphics.PorterDuff.Mode | getIndeterminateTintMode()Returns the blending mode used to apply the tint to the indeterminate
drawable, if specified.
return mProgressTintInfo != null ? mProgressTintInfo.mIndeterminateTintMode : null;
|
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.content.res.ColorStateList | getProgressBackgroundTintList()Returns the tint applied to the progress background, if specified.
return mProgressTintInfo != null ? mProgressTintInfo.mProgressBackgroundTintList : null;
|
public android.graphics.PorterDuff.Mode | getProgressBackgroundTintMode()
return mProgressTintInfo != null ? mProgressTintInfo.mProgressBackgroundTintMode : null;
|
public android.graphics.drawable.Drawable | getProgressDrawable()Get the drawable used to draw the progress bar in
progress mode.
return mProgressDrawable;
|
public android.content.res.ColorStateList | getProgressTintList()Returns the tint applied to the progress drawable, if specified.
return mProgressTintInfo != null ? mProgressTintInfo.mProgressTintList : null;
|
public android.graphics.PorterDuff.Mode | getProgressTintMode()Returns the blending mode used to apply the tint to the progress
drawable, if specified.
return mProgressTintInfo != null ? mProgressTintInfo.mProgressTintMode : null;
|
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 android.content.res.ColorStateList | getSecondaryProgressTintList()Returns the tint applied to the secondary progress drawable, if
specified.
return mProgressTintInfo != null ? mProgressTintInfo.mSecondaryProgressTintList : null;
|
public android.graphics.PorterDuff.Mode | getSecondaryProgressTintMode()Returns the blending mode used to apply the tint to the secondary
progress drawable, if specified.
return mProgressTintInfo != null ? mProgressTintInfo.mSecondaryProgressTintMode : null;
|
private android.graphics.drawable.Drawable | getTintTarget(int layerId, boolean shouldFallback)Returns the drawable to which a tint or tint mode should be applied.
Drawable layer = null;
final Drawable d = mProgressDrawable;
if (d != null) {
mProgressDrawable = d.mutate();
if (d instanceof LayerDrawable) {
layer = ((LayerDrawable) d).findDrawableByLayerId(layerId);
}
if (shouldFallback && layer == null) {
layer = d;
}
}
return layer;
|
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;
|
public void | jumpDrawablesToCurrentState()
super.jumpDrawablesToCurrentState();
if (mProgressDrawable != null) mProgressDrawable.jumpToCurrentState();
if (mIndeterminateDrawable != null) mIndeterminateDrawable.jumpToCurrentState();
|
protected void | onAttachedToWindow()
super.onAttachedToWindow();
if (mIndeterminate) {
startAnimation();
}
if (mRefreshData != null) {
synchronized (this) {
final int count = mRefreshData.size();
for (int i = 0; i < count; i++) {
final RefreshData rd = mRefreshData.get(i);
doRefreshProgress(rd.id, rd.progress, rd.fromUser, true);
rd.recycle();
}
mRefreshData.clear();
}
}
mAttached = true;
|
protected void | onDetachedFromWindow()
if (mIndeterminate) {
stopAnimation();
}
if (mRefreshProgressRunnable != null) {
removeCallbacks(mRefreshProgressRunnable);
}
if (mRefreshProgressRunnable != null && mRefreshIsPosted) {
removeCallbacks(mRefreshProgressRunnable);
}
if (mAccessibilityEventSender != null) {
removeCallbacks(mAccessibilityEventSender);
}
// This should come after stopAnimation(), otherwise an invalidate message remains in the
// queue, which can prevent the entire view hierarchy from being GC'ed during a rotation
super.onDetachedFromWindow();
mAttached = false;
|
protected synchronized void | onDraw(android.graphics.Canvas canvas)
super.onDraw(canvas);
drawTrack(canvas);
|
public void | onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)
super.onInitializeAccessibilityEvent(event);
event.setClassName(ProgressBar.class.getName());
event.setItemCount(mMax);
event.setCurrentItemIndex(mProgress);
|
public void | onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo info)
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(ProgressBar.class.getName());
|
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()));
}
updateDrawableState();
dw += mPaddingLeft + mPaddingRight;
dh += mPaddingTop + mPaddingBottom;
setMeasuredDimension(resolveSizeAndState(dw, widthMeasureSpec, 0),
resolveSizeAndState(dh, heightMeasureSpec, 0));
|
void | onProgressRefresh(float scale, boolean fromUser)
if (AccessibilityManager.getInstance(mContext).isEnabled()) {
scheduleAccessibilityEventSender();
}
|
public void | onResolveDrawables(int layoutDirection)
final Drawable d = mCurrentDrawable;
if (d != null) {
d.setLayoutDirection(layoutDirection);
}
if (mIndeterminateDrawable != null) {
mIndeterminateDrawable.setLayoutDirection(layoutDirection);
}
if (mProgressDrawable != null) {
mProgressDrawable.setLayoutDirection(layoutDirection);
}
|
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)
updateDrawableBounds(w, h);
|
protected void | onVisibilityChanged(android.view.View changedView, int visibility)
super.onVisibilityChanged(changedView, visibility);
if (mIndeterminate) {
// let's be nice with the UI thread
if (visibility == GONE || visibility == INVISIBLE) {
stopAnimation();
} else {
startAnimation();
}
}
|
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, true);
} else {
if (mRefreshProgressRunnable == null) {
mRefreshProgressRunnable = new RefreshProgressRunnable();
}
final RefreshData rd = RefreshData.obtain(id, progress, fromUser);
mRefreshData.add(rd);
if (mAttached && !mRefreshIsPosted) {
post(mRefreshProgressRunnable);
mRefreshIsPosted = true;
}
}
|
private void | scheduleAccessibilityEventSender()Schedule a command for sending an accessibility event.
Note: A command is used to ensure that accessibility events
are sent at most one in a given time frame to save
system resources while the progress changes quickly.
if (mAccessibilityEventSender == null) {
mAccessibilityEventSender = new AccessibilityEventSender();
} else {
removeCallbacks(mAccessibilityEventSender);
}
postDelayed(mAccessibilityEventSender, TIMEOUT_SEND_ACCESSIBILITY_EVENT);
|
private void | setDrawableTint(int id, android.content.res.ColorStateList tint, android.graphics.PorterDuff.Mode tintMode, boolean fallback)
Drawable layer = null;
// We expect a layer drawable, so try to find the target ID.
final Drawable d = mCurrentDrawable;
if (d instanceof LayerDrawable) {
layer = ((LayerDrawable) d).findDrawableByLayerId(id);
}
if (fallback && layer == null) {
layer = d;
}
layer.mutate();
layer.setTintList(tint);
layer.setTintMode(tintMode);
|
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 (mIndeterminateDrawable != d) {
if (mIndeterminateDrawable != null) {
mIndeterminateDrawable.setCallback(null);
unscheduleDrawable(mIndeterminateDrawable);
}
mIndeterminateDrawable = d;
if (d != null) {
d.setCallback(this);
d.setLayoutDirection(getLayoutDirection());
if (d.isStateful()) {
d.setState(getDrawableState());
}
applyIndeterminateTint();
}
if (mIndeterminate) {
mCurrentDrawable = d;
postInvalidate();
}
}
|
public void | setIndeterminateDrawableTiled(android.graphics.drawable.Drawable d)Define the tileable drawable used to draw the progress bar in
indeterminate mode.
If the drawable is a BitmapDrawable or contains BitmapDrawables, a
tiled copy will be generated for display as a progress bar.
if (d != null) {
d = tileifyIndeterminate(d);
}
setIndeterminateDrawable(d);
|
public void | setIndeterminateTintList(android.content.res.ColorStateList tint)Applies a tint to the indeterminate drawable. Does not modify the
current tint mode, which is {@link PorterDuff.Mode#SRC_IN} by default.
Subsequent calls to {@link #setIndeterminateDrawable(Drawable)} will
automatically mutate the drawable and apply the specified tint and
tint mode using
{@link Drawable#setTintList(ColorStateList)}.
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mIndeterminateTintList = tint;
mProgressTintInfo.mHasIndeterminateTint = true;
applyIndeterminateTint();
|
public void | setIndeterminateTintMode(android.graphics.PorterDuff.Mode tintMode)Specifies the blending mode used to apply the tint specified by
{@link #setIndeterminateTintList(ColorStateList)} to the indeterminate
drawable. The default mode is {@link PorterDuff.Mode#SRC_IN}.
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mIndeterminateTintMode = tintMode;
mProgressTintInfo.mHasIndeterminateTintMode = true;
applyIndeterminateTint();
|
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;
}
refreshProgress(R.id.progress, mProgress, false);
}
|
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 | setProgressBackgroundTintList(android.content.res.ColorStateList tint)Applies a tint to the progress background, if one exists. Does not
modify the current tint mode, which is
{@link PorterDuff.Mode#SRC_ATOP} by default.
The progress background must be specified as a layer with
id {@link android.R.id#background} in a {@link LayerDrawable}
used as the progress drawable.
Subsequent calls to {@link #setProgressDrawable(Drawable)} where the
drawable contains a progress background will automatically mutate the
drawable and apply the specified tint and tint mode using
{@link Drawable#setTintList(ColorStateList)}.
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mProgressBackgroundTintList = tint;
mProgressTintInfo.mHasProgressBackgroundTint = true;
if (mProgressDrawable != null) {
applyProgressBackgroundTint();
}
|
public void | setProgressBackgroundTintMode(android.graphics.PorterDuff.Mode tintMode)Specifies the blending mode used to apply the tint specified by
{@link #setProgressBackgroundTintList(ColorStateList)}} to the progress
background. The default mode is {@link PorterDuff.Mode#SRC_IN}.
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mProgressBackgroundTintMode = tintMode;
mProgressTintInfo.mHasProgressBackgroundTintMode = true;
if (mProgressDrawable != null) {
applyProgressBackgroundTint();
}
|
public void | setProgressDrawable(android.graphics.drawable.Drawable d)Define the drawable used to draw the progress bar in progress mode.
if (mProgressDrawable != d) {
if (mProgressDrawable != null) {
mProgressDrawable.setCallback(null);
unscheduleDrawable(mProgressDrawable);
}
mProgressDrawable = d;
if (d != null) {
d.setCallback(this);
d.setLayoutDirection(getLayoutDirection());
if (d.isStateful()) {
d.setState(getDrawableState());
}
// Make sure the ProgressBar is always tall enough
int drawableHeight = d.getMinimumHeight();
if (mMaxHeight < drawableHeight) {
mMaxHeight = drawableHeight;
requestLayout();
}
applyProgressTints();
}
if (!mIndeterminate) {
mCurrentDrawable = d;
postInvalidate();
}
updateDrawableBounds(getWidth(), getHeight());
updateDrawableState();
doRefreshProgress(R.id.progress, mProgress, false, false);
doRefreshProgress(R.id.secondaryProgress, mSecondaryProgress, false, false);
}
|
public void | setProgressDrawableTiled(android.graphics.drawable.Drawable d)Define the tileable drawable used to draw the progress bar in
progress mode.
If the drawable is a BitmapDrawable or contains BitmapDrawables, a
tiled copy will be generated for display as a progress bar.
if (d != null) {
d = tileify(d, false);
}
setProgressDrawable(d);
|
public void | setProgressTintList(android.content.res.ColorStateList tint)Applies a tint to the progress indicator, if one exists, or to the
entire progress drawable otherwise. Does not modify the current tint
mode, which is {@link PorterDuff.Mode#SRC_IN} by default.
The progress indicator should be specified as a layer with
id {@link android.R.id#progress} in a {@link LayerDrawable}
used as the progress drawable.
Subsequent calls to {@link #setProgressDrawable(Drawable)} will
automatically mutate the drawable and apply the specified tint and
tint mode using
{@link Drawable#setTintList(ColorStateList)}.
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mProgressTintList = tint;
mProgressTintInfo.mHasProgressTint = true;
if (mProgressDrawable != null) {
applyPrimaryProgressTint();
}
|
public void | setProgressTintMode(android.graphics.PorterDuff.Mode tintMode)Specifies the blending mode used to apply the tint specified by
{@link #setProgressTintList(ColorStateList)}} to the progress
indicator. The default mode is {@link PorterDuff.Mode#SRC_IN}.
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mProgressTintMode = tintMode;
mProgressTintInfo.mHasProgressTintMode = true;
if (mProgressDrawable != null) {
applyPrimaryProgressTint();
}
|
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 | setSecondaryProgressTintList(android.content.res.ColorStateList tint)Applies a tint to the secondary progress indicator, if one exists.
Does not modify the current tint mode, which is
{@link PorterDuff.Mode#SRC_ATOP} by default.
The secondary progress indicator must be specified as a layer with
id {@link android.R.id#secondaryProgress} in a {@link LayerDrawable}
used as the progress drawable.
Subsequent calls to {@link #setProgressDrawable(Drawable)} where the
drawable contains a secondary progress indicator will automatically
mutate the drawable and apply the specified tint and tint mode using
{@link Drawable#setTintList(ColorStateList)}.
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mSecondaryProgressTintList = tint;
mProgressTintInfo.mHasSecondaryProgressTint = true;
if (mProgressDrawable != null) {
applySecondaryProgressTint();
}
|
public void | setSecondaryProgressTintMode(android.graphics.PorterDuff.Mode tintMode)Specifies the blending mode used to apply the tint specified by
{@link #setSecondaryProgressTintList(ColorStateList)}} to the secondary
progress indicator. The default mode is
{@link PorterDuff.Mode#SRC_ATOP}.
if (mProgressTintInfo == null) {
mProgressTintInfo = new ProgressTintInfo();
}
mProgressTintInfo.mSecondaryProgressTintMode = tintMode;
mProgressTintInfo.mHasSecondaryProgressTintMode = true;
if (mProgressDrawable != null) {
applySecondaryProgressTint();
}
|
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 {
startAnimation();
}
}
}
|
void | startAnimation()Start the indeterminate progress animation.
if (getVisibility() != VISIBLE) {
return;
}
if (mIndeterminateDrawable instanceof Animatable) {
mShouldStartAnimationDrawable = true;
mHasAnimation = false;
} else {
mHasAnimation = true;
if (mInterpolator == null) {
mInterpolator = new LinearInterpolator();
}
if (mTransformation == null) {
mTransformation = new Transformation();
} else {
mTransformation.clear();
}
if (mAnimation == null) {
mAnimation = new AlphaAnimation(0.0f, 1.0f);
} else {
mAnimation.reset();
}
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.
mHasAnimation = false;
if (mIndeterminateDrawable instanceof Animatable) {
((Animatable) mIndeterminateDrawable).stop();
mShouldStartAnimationDrawable = false;
}
postInvalidate();
|
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 BitmapDrawable bitmap = (BitmapDrawable) drawable;
final Bitmap tileBitmap = bitmap.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);
// Ensure the tint and filter are propagated in the correct order.
shapeDrawable.setTintList(bitmap.getTint());
shapeDrawable.setTintMode(bitmap.getTintMode());
shapeDrawable.setColorFilter(bitmap.getColorFilter());
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;
|
private void | updateDrawableBounds(int w, int h)
// onDraw will translate the canvas so we draw starting at 0,0.
// Subtract out padding for the purposes of the calculations below.
w -= mPaddingRight + mPaddingLeft;
h -= mPaddingTop + mPaddingBottom;
int right = w;
int bottom = h;
int top = 0;
int left = 0;
if (mIndeterminateDrawable != null) {
// Aspect ratio logic does not apply to AnimationDrawables
if (mOnlyIndeterminate && !(mIndeterminateDrawable instanceof AnimationDrawable)) {
// Maintain aspect ratio. Certain kinds of animated drawables
// get very confused otherwise.
final int intrinsicWidth = mIndeterminateDrawable.getIntrinsicWidth();
final int intrinsicHeight = mIndeterminateDrawable.getIntrinsicHeight();
final float intrinsicAspect = (float) intrinsicWidth / intrinsicHeight;
final float boundAspect = (float) w / h;
if (intrinsicAspect != boundAspect) {
if (boundAspect > intrinsicAspect) {
// New width is larger. Make it smaller to match height.
final int width = (int) (h * intrinsicAspect);
left = (w - width) / 2;
right = left + width;
} else {
// New height is larger. Make it smaller to match width.
final int height = (int) (w * (1 / intrinsicAspect));
top = (h - height) / 2;
bottom = top + height;
}
}
}
if (isLayoutRtl() && mMirrorForRtl) {
int tempLeft = left;
left = w - right;
right = w - tempLeft;
}
mIndeterminateDrawable.setBounds(left, top, right, bottom);
}
if (mProgressDrawable != null) {
mProgressDrawable.setBounds(0, 0, right, bottom);
}
|
private void | updateDrawableState()
int[] state = getDrawableState();
if (mProgressDrawable != null && mProgressDrawable.isStateful()) {
mProgressDrawable.setState(state);
}
if (mIndeterminateDrawable != null && mIndeterminateDrawable.isStateful()) {
mIndeterminateDrawable.setState(state);
}
|
protected boolean | verifyDrawable(android.graphics.drawable.Drawable who)
return who == mProgressDrawable || who == mIndeterminateDrawable
|| super.verifyDrawable(who);
|