Class ProgressBar

java.lang.Object
icyllis.modernui.view.View
icyllis.modernui.widget.ProgressBar
All Implemented Interfaces:
Drawable.Callback
Direct Known Subclasses:
AbsSeekBar

public class ProgressBar extends View
  • Field Details

    • VISUAL_PROGRESS

      protected static final FloatProperty<ProgressBar> VISUAL_PROGRESS
      Property wrapper around the visual state of the progress functionality handled by the setProgress(int, boolean) method. This does not correspond directly to the actual progress -- only the visual state.
  • Constructor Details

    • ProgressBar

      public ProgressBar(Context context)
      Create a new progress bar with range 0...10000 and initial progress of 0.
      Parameters:
      context - the application environment
  • Method Details

    • setMaximumWidth

      public void setMaximumWidth(int maxWidth)
      Sets the maximum width the progress bar can have.
      Parameters:
      maxWidth - the maximum width to be set, in pixels
    • getMaximumWidth

      public int getMaximumWidth()
      Returns:
      the maximum width the progress bar can have, in pixels
    • setMaximumHeight

      public void setMaximumHeight(int maxHeight)
      Sets the maximum height the progress bar can have.
      Parameters:
      maxHeight - the maximum height to be set, in pixels
    • getMaximumHeight

      public int getMaximumHeight()
      Returns:
      the maximum height the progress bar can have, in pixels
    • 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 overridden 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 super.onMeasure() 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 the base one to provide better measurements of their content.

      Overrides:
      onMeasure in class View
      Parameters:
      widthMeasureSpec - width measure specification imposed by the parent MeasureSpec
      heightMeasureSpec - height measure specification imposed by the parent MeasureSpec
    • 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

      public void setIndeterminateDrawable(Drawable d)
      Define the drawable used to draw the progress bar in indeterminate mode.

      For the Drawable to animate, it must implement

      invalid reference
      Animatable
      , or override Drawable.onLevelChange(int). A Drawable that implements Animatable will be animated via that interface and therefore provides the greatest amount of customization. A Drawable that only overrides onLevelChange(int) is animated directly by ProgressBar and only the animation
      invalid reference
      duration
      ,
      invalid reference
      repeating behavior
      , and
      invalid reference
      interpolator
      can be modified, and only before the indeterminate animation begins.
      Parameters:
      d - the new drawable
      See Also:
    • setIndeterminateTintList

      public void setIndeterminateTintList(@Nullable ColorStateList tint)
      Applies a tint to the indeterminate drawable. Does not modify the current tint mode, which is BlendMode.SRC_IN by default.

      Subsequent calls to setIndeterminateDrawable(Drawable) will automatically mutate the drawable and apply the specified tint and tint mode using Drawable.setTintList(ColorStateList).

      Parameters:
      tint - the tint to apply, may be null to clear tint
      See Also:
    • getIndeterminateTintList

      @Nullable public ColorStateList getIndeterminateTintList()
      Returns:
      the tint applied to the indeterminate drawable
      See Also:
    • setIndeterminateTintBlendMode

      public void setIndeterminateTintBlendMode(@Nullable BlendMode blendMode)
      Specifies the blending mode used to apply the tint specified by setIndeterminateTintList(ColorStateList) to the indeterminate drawable. The default mode is BlendMode.SRC_IN.
      Parameters:
      blendMode - the blending mode used to apply the tint, may be null to clear tint
      See Also:
    • getIndeterminateTintBlendMode

      @Nullable public BlendMode getIndeterminateTintBlendMode()
      Returns the blending mode used to apply the tint to the indeterminate drawable, if specified.
      Returns:
      the blending mode used to apply the tint to the indeterminate drawable
      See Also:
    • getProgressDrawable

      public Drawable getProgressDrawable()

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

      Returns:
      a Drawable instance
      See Also:
    • 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:
    • setProgressTintList

      public void setProgressTintList(@Nullable 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
      invalid reference
      PorterDuff.Mode#SRC_IN
      by default.

      The progress indicator should be specified as a layer with id

      invalid reference
      android.R.id#progress
      in a LayerDrawable used as the progress drawable.

      Subsequent calls to setProgressDrawable(Drawable) will automatically mutate the drawable and apply the specified tint and tint mode using Drawable.setTintList(ColorStateList).

      Parameters:
      tint - the tint to apply, may be null to clear tint
      See Also:
    • getProgressTintList

      @Nullable public ColorStateList getProgressTintList()
      Returns the tint applied to the progress drawable, if specified.
      Returns:
      the tint applied to the progress drawable
      See Also:
    • setProgressTintBlendMode

      public void setProgressTintBlendMode(@Nullable BlendMode blendMode)
      Specifies the blending mode used to apply the tint specified by setProgressTintList(ColorStateList)} to the progress indicator. The default mode is
      invalid reference
      PorterDuff.Mode#SRC_IN
      .
      Parameters:
      blendMode - the blending mode used to apply the tint, may be null to clear tint
      See Also:
    • getProgressTintBlendMode

      @Nullable public BlendMode getProgressTintBlendMode()
      Returns the blending mode used to apply the tint to the progress drawable, if specified.
      Returns:
      the blending mode used to apply the tint to the progress drawable
      See Also:
    • setProgressBackgroundTintList

      public void setProgressBackgroundTintList(@Nullable ColorStateList tint)
      Applies a tint to the progress background, if one exists. Does not modify the current tint mode, which is
      invalid reference
      PorterDuff.Mode#SRC_ATOP
      by default.

      The progress background must be specified as a layer with id

      invalid reference
      android.R.id#background
      in a LayerDrawable used as the progress drawable.

      Subsequent calls to setProgressDrawable(Drawable) where the drawable contains a progress background will automatically mutate the drawable and apply the specified tint and tint mode using Drawable.setTintList(ColorStateList).

      Parameters:
      tint - the tint to apply, may be null to clear tint
      See Also:
    • getProgressBackgroundTintList

      @Nullable public ColorStateList getProgressBackgroundTintList()
      Returns the tint applied to the progress background, if specified.
      Returns:
      the tint applied to the progress background
      See Also:
    • setProgressBackgroundTintBlendMode

      public void setProgressBackgroundTintBlendMode(@Nullable BlendMode blendMode)
      Specifies the blending mode used to apply the tint specified by setProgressBackgroundTintList(ColorStateList)} to the progress background. The default mode is BlendMode.SRC_IN.
      Parameters:
      blendMode - the blending mode used to apply the tint, may be null to clear tint
      See Also:
    • getProgressBackgroundTintBlendMode

      @Nullable public BlendMode getProgressBackgroundTintBlendMode()
      Returns:
      the blending mode used to apply the tint to the progress background
      See Also:
    • setSecondaryProgressTintList

      public void setSecondaryProgressTintList(@Nullable ColorStateList tint)
      Applies a tint to the secondary progress indicator, if one exists. Does not modify the current tint mode, which is
      invalid reference
      PorterDuff.Mode#SRC_ATOP
      by default.

      The secondary progress indicator must be specified as a layer with id

      invalid reference
      android.R.id#secondaryProgress
      in a LayerDrawable used as the progress drawable.

      Subsequent calls to setProgressDrawable(Drawable) where the drawable contains a secondary progress indicator will automatically mutate the drawable and apply the specified tint and tint mode using Drawable.setTintList(ColorStateList).

      Parameters:
      tint - the tint to apply, may be null to clear tint
      See Also:
    • getSecondaryProgressTintList

      @Nullable public ColorStateList getSecondaryProgressTintList()
      Returns the tint applied to the secondary progress drawable, if specified.
      Returns:
      the tint applied to the secondary progress drawable
      See Also:
    • setSecondaryProgressTintBlendMode

      public void setSecondaryProgressTintBlendMode(@Nullable BlendMode blendMode)
      Specifies the blending mode used to apply the tint specified by setSecondaryProgressTintList(ColorStateList)} to the secondary progress indicator. The default mode is
      invalid reference
      PorterDuff.Mode#SRC_ATOP
      .
      Parameters:
      blendMode - the blending mode used to apply the tint, may be null to clear tint
      See Also:
    • getSecondaryProgressTintBlendMode

      @Nullable public BlendMode getSecondaryProgressTintBlendMode()
      Returns the blending mode used to apply the tint to the secondary progress drawable, if specified.
      Returns:
      the blending mode used to apply the tint to the secondary progress drawable
      See Also:
    • setProgress

      public void setProgress(int progress)
      Sets the current progress to the specified value. Does not do anything if the progress bar is in indeterminate mode.

      This method will immediately update the visual position of the progress indicator. To animate the visual position to the target value, use setProgress(int, boolean)}.

      Parameters:
      progress - the new progress, between getMin() and getMax()
      See Also:
    • setProgress

      public void setProgress(int progress, boolean animate)
      Sets the current progress to the specified value, optionally animating the visual position between the current and target values.

      Animation does not affect the result of getProgress(), which will return the target value immediately after this method is called.

      Parameters:
      progress - the new progress value, between getMin() and getMax()
      animate - true to animate between the current and target values or false to not animate
    • 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 getMin() and getMax()
      See Also:
    • 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 getMin() and getMax()
      See Also:
    • 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 getMin() and getMax()
      See Also:
    • 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:
    • 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:
    • getMin

      public int getMin()

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

      Returns:
      a positive integer
      See Also:
    • getMax

      public int getMax()

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

      Returns:
      a positive integer
      See Also:
    • setMin

      public void setMin(int min)

      Set the lower range of the progress bar to min.

      Parameters:
      min - the lower range of this progress bar
      See Also:
    • setMax

      public void setMax(int max)

      Set the upper range of the progress bar max.

      Parameters:
      max - the upper range of this progress bar
      See Also:
    • getCurrentDrawable

      @Nullable public Drawable getCurrentDrawable()
      Returns the drawable currently used to draw the progress bar. This will be either getProgressDrawable() or getIndeterminateDrawable() depending on whether the progress bar is in determinate or indeterminate mode.
      Returns:
      the drawable currently used to draw the progress bar
    • verifyDrawable

      protected boolean verifyDrawable(@NonNull 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 then the Drawable is being displayed in the view; else false and it is not allowed to animate.
      See Also:
    • jumpDrawablesToCurrentState

      public void jumpDrawablesToCurrentState()
      Description copied from class: View
      Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.

      Also calls StateListAnimator.jumpToCurrentState() if there is a StateListAnimator attached to this view.

      Overrides:
      jumpDrawablesToCurrentState in class View
    • onResolveDrawables

      public void onResolveDrawables(int layoutDirection)
      Description copied from class: View
      Called when layout direction has been resolved.

      The default implementation does nothing.

      Overrides:
      onResolveDrawables in class View
      Parameters:
      layoutDirection - The resolved layout direction.
      See Also:
    • onDraw

      protected void onDraw(@NonNull Canvas canvas)
      Description copied from class: View
      Draw the content of this view, implement this to do your drawing.

      Note that (0, 0) will be the top left of the bounds, and (width, height) will be the bottom right of the bounds.

      Overrides:
      onDraw in class View
      Parameters:
      canvas - the canvas to draw content
    • onSizeChanged

      protected void onSizeChanged(int w, int h, int oldw, int oldh)
      Description copied from class: View
      Called when width or height changed
      Overrides:
      onSizeChanged in class View
      Parameters:
      w - new width
      h - new height
      oldw - previous width
      oldh - previous height
    • drawableStateChanged

      protected void drawableStateChanged()
      Description copied from class: View
      This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

      If the View has a StateListAnimator, it will also be called to run necessary state change animations.

      Be sure to call through to the superclass when overriding this function.

      Overrides:
      drawableStateChanged in class View
      See Also:
    • drawableHotspotChanged

      public void drawableHotspotChanged(float x, float y)
      Description copied from class: View
      This function is called whenever the view hotspot changes and needs to be propagated to drawables or child views managed by the view.

      Dispatching to child views is handled by View.dispatchDrawableHotspotChanged(float, float).

      Be sure to call through to the superclass when overriding this function.

      Overrides:
      drawableHotspotChanged in class View
      Parameters:
      x - hotspot x coordinate
      y - hotspot y coordinate