|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectandroid.view.View
android.widget.ProgressBar
public class ProgressBar
Visual indicator of progress in some operation. Displays a bar to the user representing how far the operation has progressed; the application can change the amount of progress (modifying the length of the bar) as it moves forward. There is also a secondary progress displayable on a progress bar which is useful for displaying intermediate progress, such as the buffer level during a streaming playback progress bar.
A progress bar can also be made indeterminate. In indeterminate mode, the progress bar shows a cyclic animation. This mode is used by applications when the length of the task is unknown.
The following code example shows how a progress bar can be used from a worker thread to update the user interface to notify the user of progress:
public class MyActivity extends Activity {
private static final int PROGRESS = 0x1;
private ProgressBar mProgress;
private int mProgressStatus = 0;
private Handler mHandler = new Handler();
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.progressbar_activity);
mProgress = (ProgressBar) findViewById(R.id.progress_bar);
// Start lengthy operation in a background thread
new Thread(new Runnable() {
public void run() {
while (mProgressStatus < 100) {
mProgressStatus = doWork();
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
mProgress.setProgress(mProgressStatus);
}
});
}
}
}).start();
}
}
XML attributes
See ProgressBar Attributes,
View Attributes
Styles
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class android.view.View |
|---|
View.BaseSavedState, View.MeasureSpec, View.OnClickListener, View.OnCreateContextMenuListener, View.OnFocusChangeListener, View.OnKeyListener, View.OnLongClickListener, View.OnTouchListener |
| Field Summary | |
|---|---|
(package private) int |
mMaxHeight
|
(package private) int |
mMaxWidth
|
(package private) int |
mMinHeight
|
(package private) int |
mMinWidth
|
(package private) Bitmap |
mSampleTile
|
| Constructor Summary | |
|---|---|
ProgressBar(Context context)
Create a new progress bar with range 0...100 and initial progress of 0. |
|
ProgressBar(Context context,
AttributeSet attrs)
|
|
ProgressBar(Context context,
AttributeSet attrs,
int defStyle)
|
|
| Method Summary | |
|---|---|
(package private) Drawable |
getCurrentDrawable()
|
(package private) Shape |
getDrawableShape()
|
Drawable |
getIndeterminateDrawable()
Get the drawable used to draw the progress bar in indeterminate mode. |
Interpolator |
getInterpolator()
Gets the acceleration curve type for the indeterminate animation. |
int |
getMax()
Return the upper limit of this progress bar's range. |
int |
getProgress()
Get the progress bar's current level of progress. |
Drawable |
getProgressDrawable()
Get the drawable used to draw the progress bar in progress mode. |
int |
getSecondaryProgress()
Get the progress bar's current level of secondary progress. |
void |
incrementProgressBy(int diff)
Increase the progress bar's progress by the specified amount. |
void |
incrementSecondaryProgressBy(int diff)
Increase the progress bar's secondary progress by the specified amount. |
void |
invalidateDrawable(Drawable dr)
Invalidates the specified Drawable. |
boolean |
isIndeterminate()
Indicate whether this progress bar is in indeterminate mode. |
protected void |
onDraw(Canvas canvas)
Implement this to do your drawing. |
protected void |
onMeasure(int widthMeasureSpec,
int heightMeasureSpec)
Measure the view and its content to determine the measured width and the measured height. |
(package private) void |
onProgressRefresh(float scale,
boolean fromTouch)
|
protected void |
onSizeChanged(int w,
int h,
int oldw,
int oldh)
This is called during layout when the size of this view has changed. |
void |
postInvalidate()
Cause an invalidate to happen on a subsequent cycle through the event loop. |
void |
setIndeterminate(boolean indeterminate)
Change the indeterminate mode for this progress bar. |
void |
setIndeterminateDrawable(Drawable d)
Define the drawable used to draw the progress bar in indeterminate mode. |
void |
setInterpolator(Context context,
int resID)
Sets the acceleration curve for the indeterminate animation. |
void |
setInterpolator(Interpolator interpolator)
Sets the acceleration curve for the indeterminate animation. |
void |
setMax(int max)
Set the range of the progress bar to 0...max. |
void |
setProgress(int progress)
Set the current progress to the specified value. |
(package private) void |
setProgress(int progress,
boolean fromTouch)
|
void |
setProgressDrawable(Drawable d)
Define the drawable used to draw the progress bar in progress mode. |
void |
setSecondaryProgress(int secondaryProgress)
Set the current secondary progress to the specified value. |
void |
setVisibility(int v)
Set the enabled state of this view. |
(package private) void |
startAnimation()
Start the indeterminate progress animation. |
(package private) void |
stopAnimation()
Stop the indeterminate progress animation. |
protected boolean |
verifyDrawable(Drawable who)
If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
int mMinWidth
int mMaxWidth
int mMinHeight
int mMaxHeight
Bitmap mSampleTile
| Constructor Detail |
|---|
public ProgressBar(Context context)
context - the application environment
public ProgressBar(Context context,
AttributeSet attrs)
public ProgressBar(Context context,
AttributeSet attrs,
int defStyle)
| Method Detail |
|---|
Shape getDrawableShape()
public boolean isIndeterminate()
Indicate whether this progress bar is in indeterminate mode.
public 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.
indeterminate - true to enable the indeterminate modepublic Drawable getIndeterminateDrawable()
Get the drawable used to draw the progress bar in indeterminate mode.
Drawable instancesetIndeterminateDrawable(android.graphics.drawable.Drawable),
setIndeterminate(boolean)public void setIndeterminateDrawable(Drawable d)
Define the drawable used to draw the progress bar in indeterminate mode.
d - the new drawablegetIndeterminateDrawable(),
setIndeterminate(boolean)public Drawable getProgressDrawable()
Get the drawable used to draw the progress bar in progress mode.
Drawable instancesetProgressDrawable(android.graphics.drawable.Drawable),
setIndeterminate(boolean)public void setProgressDrawable(Drawable d)
Define the drawable used to draw the progress bar in progress mode.
d - the new drawablegetProgressDrawable(),
setIndeterminate(boolean)Drawable getCurrentDrawable()
protected boolean verifyDrawable(Drawable who)
ViewBe sure to call through to the super class when overriding this function.
verifyDrawable in class Viewwho - The Drawable to verify. Return true if it is one you are
displaying, else return the result of calling through to the
super class.
View.unscheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable),
View.drawableStateChanged()public void postInvalidate()
View
postInvalidate in class ViewView.invalidate()
void onProgressRefresh(float scale,
boolean fromTouch)
public void setProgress(int progress)
Set the current progress to the specified value. Does not do anything if the progress bar is in indeterminate mode.
progress - the new progress, between 0 and getMax()setIndeterminate(boolean),
isIndeterminate(),
getProgress(),
incrementProgressBy(int)
void setProgress(int progress,
boolean fromTouch)
public 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.
secondaryProgress - the new secondary progress, between 0 and getMax()setIndeterminate(boolean),
isIndeterminate(),
getSecondaryProgress(),
incrementSecondaryProgressBy(int)public int getProgress()
Get the progress bar's current level of progress. Return 0 when the progress bar is in indeterminate mode.
getMax()setIndeterminate(boolean),
isIndeterminate(),
setProgress(int),
setMax(int),
getMax()public int getSecondaryProgress()
Get the progress bar's current level of secondary progress. Return 0 when the progress bar is in indeterminate mode.
getMax()setIndeterminate(boolean),
isIndeterminate(),
setSecondaryProgress(int),
setMax(int),
getMax()public int getMax()
Return the upper limit of this progress bar's range.
setMax(int),
getProgress(),
getSecondaryProgress()public void setMax(int max)
Set the range of the progress bar to 0...max.
max - the upper range of this progress bargetMax(),
setProgress(int),
setSecondaryProgress(int)public final void incrementProgressBy(int diff)
Increase the progress bar's progress by the specified amount.
diff - the amount by which the progress must be increasedsetProgress(int)public final void incrementSecondaryProgressBy(int diff)
Increase the progress bar's secondary progress by the specified amount.
diff - the amount by which the secondary progress must be increasedsetSecondaryProgress(int)void startAnimation()
Start the indeterminate progress animation.
void stopAnimation()
Stop the indeterminate progress animation.
public void setInterpolator(Context context,
int resID)
context - The application environmentresID - The resource identifier of the interpolator to loadpublic void setInterpolator(Interpolator interpolator)
interpolator - The interpolator which defines the acceleration curvepublic Interpolator getInterpolator()
Interpolator associated to this animationpublic void setVisibility(int v)
View
setVisibility in class Viewv - One of View.VISIBLE, View.INVISIBLE, or View.GONE.public void invalidateDrawable(Drawable dr)
View
invalidateDrawable in interface Drawable.CallbackinvalidateDrawable in class Viewdr - the drawable to invalidate
protected void onSizeChanged(int w,
int h,
int oldw,
int oldh)
View
onSizeChanged in class Vieww - Current width of this view.h - Current height of this view.oldw - Old width of this view.oldh - Old height of this view.protected void onDraw(Canvas canvas)
View
onDraw in class Viewcanvas - the canvas on which the background will be drawn
protected void onMeasure(int widthMeasureSpec,
int heightMeasureSpec)
View
Measure the view and its content to determine the measured width and the
measured height. This method is invoked by View.measure(int, int) and
should be overriden by subclasses to provide accurate and efficient
measurement of their contents.
CONTRACT: When overriding this method, you
must call View.setMeasuredDimension(int, int) to store the
measured width and height of this view. Failure to do so will trigger an
IllegalStateException, thrown by
View.measure(int, int). Calling the superclass'
View.onMeasure(int, int) is a valid use.
The base class implementation of measure defaults to the background size,
unless a larger size is allowed by the MeasureSpec. Subclasses should
override View.onMeasure(int, int) to provide better measurements of
their content.
If this method is overridden, it is the subclass's responsibility to make
sure the measured height and width are at least the view's minimum height
and width (View.getSuggestedMinimumHeight() and
View.getSuggestedMinimumWidth()).
onMeasure in class ViewwidthMeasureSpec - horizontal space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec.heightMeasureSpec - vertical space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec.View.getMeasuredWidth(),
View.getMeasuredHeight(),
View.setMeasuredDimension(int, int),
View.getSuggestedMinimumHeight(),
View.getSuggestedMinimumWidth(),
View.MeasureSpec.getMode(int),
View.MeasureSpec.getSize(int)
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||