Build 1.0_r1(from source)

android.widget
Class ProgressBar

java.lang.Object
  extended by android.view.View
      extended by android.widget.ProgressBar
All Implemented Interfaces:
Drawable.Callback, KeyEvent.Callback
Direct Known Subclasses:
AbsSeekBar

public class ProgressBar
extends View

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
           
 
Fields inherited from class android.view.View
DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FIRST_STATE_SET, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, INVISIBLE, KEEP_SCREEN_ON, LAST_STATE_SET, mBottom, mContext, mCurrentAnimation, MIDDLE_STATE_SET, mLayoutParams, mLeft, mLocation, mMeasuredHeight, mMeasuredWidth, mOnClickListener, mOnCreateContextMenuListener, mOnFocusChangeListener, mOnLongClickListener, mPaddingBottom, mPaddingLeft, mPaddingRight, mPaddingTop, mParent, mRight, mScrollX, mScrollY, mTag, mTop, NO_ID, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FIRST_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_LAST_STATE_SET, PRESSED_MIDDLE_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_SINGLE_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SINGLE_STATE_SET, SOUND_EFFECTS_ENABLED, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET
 
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 android.view.View
addFocusables, addTouchables, applyDrawableToTransparentRegion, bringToFront, buildDrawingCache, cancelLongPress, clearAnimation, clearFocus, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createContextMenu, debug, debug, debugIndent, destroyDrawingCache, dispatchDraw, dispatchKeyEvent, dispatchKeyShortcutEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetPressed, dispatchSetSelected, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, draw, drawableStateChanged, finalize, findFocus, findViewById, findViewTraversal, findViewWithTag, findViewWithTagTraversal, fitSystemWindows, focusSearch, forceLayout, gatherTransparentRegion, getAnimation, getApplicationWindowToken, getBackground, getBaseline, getBottom, getBottomFadingEdgeStrength, getContext, getContextMenuInfo, getDefaultSize, getDrawableState, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getId, getKeepScreenOn, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMeasuredHeight, getMeasuredWidth, getNextFocusDownId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getParent, getResources, getRight, getRightFadingEdgeStrength, getRootView, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getTag, getTop, getTopFadingEdgeStrength, getTouchables, getTouchDelegate, getVerticalFadingEdgeLength, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowToken, getWindowVisibility, hasFocus, hasFocusable, hasWindowFocus, inflate, initializeFadingEdge, initializeScrollbars, invalidate, invalidate, invalidate, isClickable, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isInTouchMode, isLayoutRequested, isLongClickable, isPressed, isRootNamespace, isSaveEnabled, isSelected, isShown, isSoundEffectsEnabled, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, layout, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onAnimationEnd, onAnimationStart, onAttachedToWindow, onCreateContextMenu, onCreateDrawableState, onDetachedFromWindow, onFinishInflate, onFocusChanged, onKeyDown, onKeyMultiple, onKeyShortcut, onKeyUp, onLayout, onRestoreInstanceState, onSaveInstanceState, onScrollChanged, onSetAlpha, onTouchEvent, onTrackballEvent, onWindowFocusChanged, onWindowVisibilityChanged, performClick, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, refreshDrawableState, removeCallbacks, requestFocus, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, resolveSize, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, setAnimation, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setClickable, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFocusable, setFocusableInTouchMode, setFrame, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setId, setIsRootNamespace, setKeepScreenOn, setLayoutParams, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnCreateContextMenuListener, setOnFocusChangeListener, setOnKeyListener, setOnLongClickListener, setOnTouchListener, setPadding, setPressed, setSaveEnabled, setScrollBarStyle, setSelected, setSoundEffectsEnabled, setTag, setTouchDelegate, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setWillNotCacheDrawing, setWillNotDraw, showContextMenu, startAnimation, unscheduleDrawable, unscheduleDrawable, willNotCacheDrawing, willNotDraw
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mMinWidth

int mMinWidth

mMaxWidth

int mMaxWidth

mMinHeight

int mMinHeight

mMaxHeight

int mMaxHeight

mSampleTile

Bitmap mSampleTile
Constructor Detail

ProgressBar

public ProgressBar(Context context)
Create a new progress bar with range 0...100 and initial progress of 0.

Parameters:
context - the application environment

ProgressBar

public ProgressBar(Context context,
                   AttributeSet attrs)

ProgressBar

public ProgressBar(Context context,
                   AttributeSet attrs,
                   int defStyle)
Method Detail

getDrawableShape

Shape getDrawableShape()

isIndeterminate

public boolean isIndeterminate()

Indicate whether this progress bar is in indeterminate mode.

Returns:
true if the progress bar is in indeterminate mode

setIndeterminate

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.

Parameters:
indeterminate - true to enable the indeterminate mode

getIndeterminateDrawable

public Drawable getIndeterminateDrawable()

Get the drawable used to draw the progress bar in indeterminate mode.

Returns:
a Drawable instance
See Also:
setIndeterminateDrawable(android.graphics.drawable.Drawable), setIndeterminate(boolean)

setIndeterminateDrawable

public void setIndeterminateDrawable(Drawable d)

Define the drawable used to draw the progress bar in indeterminate mode.

Parameters:
d - the new drawable
See Also:
getIndeterminateDrawable(), setIndeterminate(boolean)

getProgressDrawable

public Drawable getProgressDrawable()

Get the drawable used to draw the progress bar in progress mode.

Returns:
a Drawable instance
See Also:
setProgressDrawable(android.graphics.drawable.Drawable), setIndeterminate(boolean)

setProgressDrawable

public void setProgressDrawable(Drawable d)

Define the drawable used to draw the progress bar in progress mode.

Parameters:
d - the new drawable
See Also:
getProgressDrawable(), setIndeterminate(boolean)

getCurrentDrawable

Drawable getCurrentDrawable()
Returns:
The drawable currently used to draw the progress bar

verifyDrawable

protected boolean verifyDrawable(Drawable who)
Description copied from class: View
If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. This allows animations for those drawables to be scheduled.

Be sure to call through to the super class when overriding this function.

Overrides:
verifyDrawable in class View
Parameters:
who - The Drawable to verify. Return true if it is one you are displaying, else return the result of calling through to the super class.
Returns:
boolean If true than the Drawable is being displayed in the view; else false and it is not allowed to animate.
See Also:
View.unscheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable), View.drawableStateChanged()

postInvalidate

public void postInvalidate()
Description copied from class: View
Cause an invalidate to happen on a subsequent cycle through the event loop. Use this to invalidate the View from a non-UI thread.

Overrides:
postInvalidate in class View
See Also:
View.invalidate()

onProgressRefresh

void onProgressRefresh(float scale,
                       boolean fromTouch)

setProgress

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.

Parameters:
progress - the new progress, between 0 and getMax()
See Also:
setIndeterminate(boolean), isIndeterminate(), getProgress(), incrementProgressBy(int)

setProgress

void setProgress(int progress,
                 boolean fromTouch)

setSecondaryProgress

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.

Parameters:
secondaryProgress - the new secondary progress, between 0 and getMax()
See Also:
setIndeterminate(boolean), isIndeterminate(), getSecondaryProgress(), incrementSecondaryProgressBy(int)

getProgress

public int getProgress()

Get the progress bar's current level of progress. Return 0 when the progress bar is in indeterminate mode.

Returns:
the current progress, between 0 and getMax()
See Also:
setIndeterminate(boolean), isIndeterminate(), setProgress(int), setMax(int), getMax()

getSecondaryProgress

public int getSecondaryProgress()

Get the progress bar's current level of secondary progress. Return 0 when the progress bar is in indeterminate mode.

Returns:
the current secondary progress, between 0 and getMax()
See Also:
setIndeterminate(boolean), isIndeterminate(), setSecondaryProgress(int), setMax(int), getMax()

getMax

public int getMax()

Return the upper limit of this progress bar's range.

Returns:
a positive integer
See Also:
setMax(int), getProgress(), getSecondaryProgress()

setMax

public void setMax(int max)

Set the range of the progress bar to 0...max.

Parameters:
max - the upper range of this progress bar
See Also:
getMax(), setProgress(int), setSecondaryProgress(int)

incrementProgressBy

public final void incrementProgressBy(int diff)

Increase the progress bar's progress by the specified amount.

Parameters:
diff - the amount by which the progress must be increased
See Also:
setProgress(int)

incrementSecondaryProgressBy

public final void incrementSecondaryProgressBy(int diff)

Increase the progress bar's secondary progress by the specified amount.

Parameters:
diff - the amount by which the secondary progress must be increased
See Also:
setSecondaryProgress(int)

startAnimation

void startAnimation()

Start the indeterminate progress animation.


stopAnimation

void stopAnimation()

Stop the indeterminate progress animation.


setInterpolator

public void setInterpolator(Context context,
                            int resID)
Sets the acceleration curve for the indeterminate animation. The interpolator is loaded as a resource from the specified context.

Parameters:
context - The application environment
resID - The resource identifier of the interpolator to load

setInterpolator

public void setInterpolator(Interpolator interpolator)
Sets the acceleration curve for the indeterminate animation. Defaults to a linear interpolation.

Parameters:
interpolator - The interpolator which defines the acceleration curve

getInterpolator

public Interpolator getInterpolator()
Gets the acceleration curve type for the indeterminate animation.

Returns:
the Interpolator associated to this animation

setVisibility

public void setVisibility(int v)
Description copied from class: View
Set the enabled state of this view.

Overrides:
setVisibility in class View
Parameters:
v - One of View.VISIBLE, View.INVISIBLE, or View.GONE.

invalidateDrawable

public void invalidateDrawable(Drawable dr)
Description copied from class: View
Invalidates the specified Drawable.

Specified by:
invalidateDrawable in interface Drawable.Callback
Overrides:
invalidateDrawable in class View
Parameters:
dr - the drawable to invalidate

onSizeChanged

protected void onSizeChanged(int w,
                             int h,
                             int oldw,
                             int oldh)
Description copied from class: View
This is called during layout when the size of this view has changed. If you were just added to the view hierarchy, you're called with the old values of 0.

Overrides:
onSizeChanged in class View
Parameters:
w - Current width of this view.
h - Current height of this view.
oldw - Old width of this view.
oldh - Old height of this view.

onDraw

protected void onDraw(Canvas canvas)
Description copied from class: View
Implement this to do your drawing.

Overrides:
onDraw in class View
Parameters:
canvas - the canvas on which the background will be drawn

onMeasure

protected void onMeasure(int widthMeasureSpec,
                         int heightMeasureSpec)
Description copied from class: 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()).

Overrides:
onMeasure in class View
Parameters:
widthMeasureSpec - 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.
See Also:
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)

Please submit a feedback, bug or feature