DefaultTimeBar
@UnstableApi
public class DefaultTimeBar extends View implements TimeBar
A time bar that shows a current position, buffered position, duration and ad markers.
A DefaultTimeBar can be customized by setting attributes, as outlined below.
Attributes
The following attributes can be set on a DefaultTimeBar when used in a layout XML file:bar_height- Dimension for the height of the time bar.- Default:
DEFAULT_BAR_HEIGHT_DP
- Default:
touch_target_height- Dimension for the height of the area in which touch interactions with the time bar are handled. If no height is specified, this also determines the height of the view.- Default:
DEFAULT_TOUCH_TARGET_HEIGHT_DP
- Default:
ad_marker_width- Dimension for the width of any ad markers shown on the bar. Ad markers are superimposed on the time bar to show the times at which ads will play.- Default:
DEFAULT_AD_MARKER_WIDTH_DP
- Default:
scrubber_enabled_size- Dimension for the diameter of the circular scrubber handle when scrubbing is enabled but not in progress. Set to zero if no scrubber handle should be shown.- Default:
DEFAULT_SCRUBBER_ENABLED_SIZE_DP
- Default:
scrubber_disabled_size- Dimension for the diameter of the circular scrubber handle when scrubbing isn't enabled. Set to zero if no scrubber handle should be shown.- Default:
DEFAULT_SCRUBBER_DISABLED_SIZE_DP
- Default:
scrubber_dragged_size- Dimension for the diameter of the circular scrubber handle when scrubbing is in progress. Set to zero if no scrubber handle should be shown.- Default:
DEFAULT_SCRUBBER_DRAGGED_SIZE_DP
- Default:
scrubber_drawable- Optional reference to a drawable to draw for the scrubber handle. If set, this overrides the default behavior, which is to draw a circle for the scrubber handle.played_color- Color for the portion of the time bar representing media before the current playback position.- Corresponding method:
setPlayedColor - Default:
DEFAULT_PLAYED_COLOR
- Corresponding method:
scrubber_color- Color for the scrubber handle.- Corresponding method:
setScrubberColor - Default:
DEFAULT_SCRUBBER_COLOR
- Corresponding method:
buffered_color- Color for the portion of the time bar after the current played position up to the current buffered position.- Corresponding method:
setBufferedColor - Default:
DEFAULT_BUFFERED_COLOR
- Corresponding method:
unplayed_color- Color for the portion of the time bar after the current buffered position.- Corresponding method:
setUnplayedColor - Default:
DEFAULT_UNPLAYED_COLOR
- Corresponding method:
ad_marker_color- Color for unplayed ad markers.- Corresponding method:
setAdMarkerColor - Default:
DEFAULT_AD_MARKER_COLOR
- Corresponding method:
played_ad_marker_color- Color for played ad markers.- Corresponding method:
setPlayedAdMarkerColor - Default:
DEFAULT_PLAYED_AD_MARKER_COLOR
- Corresponding method:
Summary
Constants |
|
|---|---|
static final int |
Vertical gravity for progress bar to be located at the bottom in the view. |
static final int |
Vertical gravity for progress bar to be located at the center in the view. |
static final int |
DEFAULT_AD_MARKER_COLOR = -1291845888Default color for ad markers. |
static final int |
Default width for ad markers, in dp. |
static final int |
Default height for the time bar, in dp. |
static final int |
DEFAULT_BUFFERED_COLOR = -855638017Default color for the buffered portion of the time bar. |
static final int |
DEFAULT_PLAYED_AD_MARKER_COLOR = 872414976Default color for played ad markers. |
static final int |
DEFAULT_PLAYED_COLOR = -1Default color for the played portion of the time bar. |
static final int |
Default color for the scrubber handle. |
static final int |
Default diameter for the scrubber when disabled, in dp. |
static final int |
Default diameter for the scrubber when dragged, in dp. |
static final int |
Default diameter for the scrubber when enabled, in dp. |
static final int |
Default height for the touch target, in dp. |
static final int |
DEFAULT_UNPLAYED_COLOR = 872415231Default color for the unplayed portion of the time bar. |
Public constructors |
|---|
DefaultTimeBar(Context context) |
DefaultTimeBar(Context context, @Nullable AttributeSet attrs) |
DefaultTimeBar( |
DefaultTimeBar( |
DefaultTimeBar( |
Public methods |
|
|---|---|
void |
addListener(TimeBar.OnScrubListener listener)Adds a listener for scrubbing events. |
long |
Returns the preferred delay in milliseconds of media time after which the time bar position should be updated. |
void |
hideScrubber(boolean disableScrubberPadding)Hides the scrubber handle. |
void |
hideScrubber(long hideAnimationDurationMs)Hides the scrubber handle with animation. |
void |
|
void |
|
void |
|
void |
|
boolean |
|
void |
onRtlPropertiesChanged(int layoutDirection) |
boolean |
onTouchEvent(MotionEvent event) |
boolean |
performAccessibilityAction(int action, @Nullable Bundle args) |
void |
removeListener(TimeBar.OnScrubListener listener)Removes a listener for scrubbing events. |
void |
setAdGroupTimesMs(Sets the times of ad groups and whether each ad group has been played. |
void |
setAdMarkerColor(@ColorInt int adMarkerColor)Sets the color for unplayed ad markers. |
void |
setBufferedColor(@ColorInt int bufferedColor)Sets the color for the portion of the time bar after the current played position up to the current buffered position. |
void |
setBufferedPosition(long bufferedPosition)Sets the buffered position. |
void |
setDuration(long duration)Sets the duration. |
void |
setEnabled(boolean enabled) |
void |
setKeyCountIncrement(int count)Sets the position increment for key presses and accessibility actions, as a number of increments that divide the duration of the media. |
void |
setKeyTimeIncrement(long time)Sets the position increment for key presses and accessibility actions, in milliseconds. |
void |
setPlayedAdMarkerColor(@ColorInt int playedAdMarkerColor)Sets the color for played ad markers. |
void |
setPlayedColor(@ColorInt int playedColor)Sets the color for the portion of the time bar representing media before the playback position. |
void |
setPosition(long position)Sets the current position. |
void |
setScrubberColor(@ColorInt int scrubberColor)Sets the color for the scrubber handle. |
void |
setUnplayedColor(@ColorInt int unplayedColor)Sets the color for the portion of the time bar after the current played position. |
void |
Shows the scrubber handle. |
void |
showScrubber(long showAnimationDurationMs)Shows the scrubber handle with animation. |
Protected methods |
|
|---|---|
void |
|
void |
onFocusChanged( |
void |
onLayout(boolean changed, int left, int top, int right, int bottom) |
void |
onMeasure(int widthMeasureSpec, int heightMeasureSpec) |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited methods |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Constants
BAR_GRAVITY_BOTTOM
public static final int BAR_GRAVITY_BOTTOM = 1
Vertical gravity for progress bar to be located at the bottom in the view.
BAR_GRAVITY_CENTER
public static final int BAR_GRAVITY_CENTER = 0
Vertical gravity for progress bar to be located at the center in the view.
DEFAULT_AD_MARKER_COLOR
public static final int DEFAULT_AD_MARKER_COLOR = -1291845888
Default color for ad markers.
DEFAULT_AD_MARKER_WIDTH_DP
public static final int DEFAULT_AD_MARKER_WIDTH_DP = 4
Default width for ad markers, in dp.
DEFAULT_BAR_HEIGHT_DP
public static final int DEFAULT_BAR_HEIGHT_DP = 4
Default height for the time bar, in dp.
DEFAULT_BUFFERED_COLOR
public static final int DEFAULT_BUFFERED_COLOR = -855638017
Default color for the buffered portion of the time bar.
DEFAULT_PLAYED_AD_MARKER_COLOR
public static final int DEFAULT_PLAYED_AD_MARKER_COLOR = 872414976
Default color for played ad markers.
DEFAULT_PLAYED_COLOR
public static final int DEFAULT_PLAYED_COLOR = -1
Default color for the played portion of the time bar.
DEFAULT_SCRUBBER_COLOR
public static final int DEFAULT_SCRUBBER_COLOR = -1
Default color for the scrubber handle.
DEFAULT_SCRUBBER_DISABLED_SIZE_DP
public static final int DEFAULT_SCRUBBER_DISABLED_SIZE_DP = 0
Default diameter for the scrubber when disabled, in dp.
DEFAULT_SCRUBBER_DRAGGED_SIZE_DP
public static final int DEFAULT_SCRUBBER_DRAGGED_SIZE_DP = 16
Default diameter for the scrubber when dragged, in dp.
DEFAULT_SCRUBBER_ENABLED_SIZE_DP
public static final int DEFAULT_SCRUBBER_ENABLED_SIZE_DP = 12
Default diameter for the scrubber when enabled, in dp.
DEFAULT_TOUCH_TARGET_HEIGHT_DP
public static final int DEFAULT_TOUCH_TARGET_HEIGHT_DP = 26
Default height for the touch target, in dp.
DEFAULT_UNPLAYED_COLOR
public static final int DEFAULT_UNPLAYED_COLOR = 872415231
Default color for the unplayed portion of the time bar.
Public constructors
DefaultTimeBar
public DefaultTimeBar(
Context context,
@Nullable AttributeSet attrs,
int defStyleAttr
)
DefaultTimeBar
public DefaultTimeBar(
Context context,
@Nullable AttributeSet attrs,
int defStyleAttr,
@Nullable AttributeSet timebarAttrs
)
DefaultTimeBar
public DefaultTimeBar(
Context context,
@Nullable AttributeSet attrs,
int defStyleAttr,
@Nullable AttributeSet timebarAttrs,
int defStyleRes
)
Public methods
addListener
public void addListener(TimeBar.OnScrubListener listener)
Adds a listener for scrubbing events.
| Parameters | |
|---|---|
TimeBar.OnScrubListener listener |
The listener to add. |
getPreferredUpdateDelay
public long getPreferredUpdateDelay()
Returns the preferred delay in milliseconds of media time after which the time bar position should be updated.
| Returns | |
|---|---|
long |
Preferred delay, in milliseconds of media time. |
hideScrubber
public void hideScrubber(long hideAnimationDurationMs)
Hides the scrubber handle with animation.
| Parameters | |
|---|---|
long hideAnimationDurationMs |
The duration for scrubber hiding animation. |
onInitializeAccessibilityNodeInfo
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
performAccessibilityAction
public boolean performAccessibilityAction(int action, @Nullable Bundle args)
removeListener
public void removeListener(TimeBar.OnScrubListener listener)
Removes a listener for scrubbing events.
| Parameters | |
|---|---|
TimeBar.OnScrubListener listener |
The listener to remove. |
setAdGroupTimesMs
public void setAdGroupTimesMs(
@Nullable long[] adGroupTimesMs,
@Nullable boolean[] playedAdGroups,
int adGroupCount
)
Sets the times of ad groups and whether each ad group has been played.
| Parameters | |
|---|---|
@Nullable long[] adGroupTimesMs |
An array where the first |
@Nullable boolean[] playedAdGroups |
An array where the first |
int adGroupCount |
The number of ad groups. |
setAdMarkerColor
public void setAdMarkerColor(@ColorInt int adMarkerColor)
Sets the color for unplayed ad markers.
| Parameters | |
|---|---|
@ColorInt int adMarkerColor |
The color for unplayed ad markers. |
setBufferedColor
public void setBufferedColor(@ColorInt int bufferedColor)
Sets the color for the portion of the time bar after the current played position up to the current buffered position.
| Parameters | |
|---|---|
@ColorInt int bufferedColor |
The color for the portion of the time bar after the current played position up to the current buffered position. |
setBufferedPosition
public void setBufferedPosition(long bufferedPosition)
Sets the buffered position.
| Parameters | |
|---|---|
long bufferedPosition |
The current buffered position to show, in milliseconds. |
setDuration
public void setDuration(long duration)
Sets the duration.
| Parameters | |
|---|---|
long duration |
The duration to show, in milliseconds. |
setKeyCountIncrement
public void setKeyCountIncrement(int count)
Sets the position increment for key presses and accessibility actions, as a number of increments that divide the duration of the media. For example, passing 20 will cause key presses to increment/decrement the position by 1/20th of the duration (if known).
Clears any increment specified in a preceding call to setKeyTimeIncrement.
| Parameters | |
|---|---|
int count |
The number of increments that divide the duration of the media. |
setKeyTimeIncrement
public void setKeyTimeIncrement(long time)
Sets the position increment for key presses and accessibility actions, in milliseconds.
Clears any increment specified in a preceding call to setKeyCountIncrement.
| Parameters | |
|---|---|
long time |
The time increment, in milliseconds. |
setPlayedAdMarkerColor
public void setPlayedAdMarkerColor(@ColorInt int playedAdMarkerColor)
Sets the color for played ad markers.
| Parameters | |
|---|---|
@ColorInt int playedAdMarkerColor |
The color for played ad markers. |
setPlayedColor
public void setPlayedColor(@ColorInt int playedColor)
Sets the color for the portion of the time bar representing media before the playback position.
| Parameters | |
|---|---|
@ColorInt int playedColor |
The color for the portion of the time bar representing media before the playback position. |
setPosition
public void setPosition(long position)
Sets the current position.
| Parameters | |
|---|---|
long position |
The current position to show, in milliseconds. |
setScrubberColor
public void setScrubberColor(@ColorInt int scrubberColor)
Sets the color for the scrubber handle.
| Parameters | |
|---|---|
@ColorInt int scrubberColor |
The color for the scrubber handle. |
setUnplayedColor
public void setUnplayedColor(@ColorInt int unplayedColor)
Sets the color for the portion of the time bar after the current played position.
| Parameters | |
|---|---|
@ColorInt int unplayedColor |
The color for the portion of the time bar after the current played position. |
showScrubber
public void showScrubber(long showAnimationDurationMs)
Shows the scrubber handle with animation.
| Parameters | |
|---|---|
long showAnimationDurationMs |
The duration for scrubber showing animation. |
Protected methods
onFocusChanged
protected void onFocusChanged(
boolean gainFocus,
int direction,
@Nullable Rect previouslyFocusedRect
)