PlaybackSupportFragment
public
class
PlaybackSupportFragment
extends Fragment
java.lang.Object | ||
↳ | androidx.fragment.app.Fragment | |
↳ | androidx.leanback.app.PlaybackSupportFragment |
A fragment for displaying playback controls and related content.
A PlaybackSupportFragment renders the elements of its ObjectAdapter
as a set
of rows in a vertical list. The Adapter's PresenterSelector
must maintain subclasses
of RowPresenter
.
A playback row is a row rendered by PlaybackRowPresenter
.
App can call setPlaybackRow(Row)
to set playback row for the first element of adapter.
App can call setPlaybackRowPresenter(PlaybackRowPresenter)
to set presenter for it.
setPlaybackRow(Row)
and setPlaybackRowPresenter(PlaybackRowPresenter)
are
optional, app can pass playback row and PlaybackRowPresenter in the adapter using
setAdapter(ObjectAdapter)
.
Hiding and showing controls: the controls are initially visible and automatically show/hide when play/pause or user interacts with fragment.
-
App may manually call
showControlsOverlay(boolean)
orhideControlsOverlay(boolean)
to show or hide the controls. - The controls are visible by default upon onViewCreated(). To make it initially invisible, call hideControlsOverlay(false) in overridden onViewCreated(). Upon play or pause, PlaybackControlGlue or PlaybackTransportControlGlue will fade-in the controls and automatically fade out after a delay customized by
-
Upon user interaction event, fragment will fade-in the controls and automatically fade
out after a delay customized by
R.attr.playbackControlsAutoHideTickleTimeout
. To disable the fade in and fade out behavior, callsetShowOrHideControlsOverlayOnUserInteraction(boolean)
with false.
R.attr.playbackControlsAutoHideTimeout
. To disable the fade in and fade out
behavior: call #setControlsOverlayAutoHideEnabled(boolean)
with false.
Summary
Constants | |
---|---|
int |
BG_DARK
A dark translucent background. |
int |
BG_LIGHT
A light translucent background. |
int |
BG_NONE
No background. |
Public constructors | |
---|---|
PlaybackSupportFragment()
|
Public methods | |
---|---|
void
|
fadeOut()
This method is deprecated.
Call |
ObjectAdapter
|
getAdapter()
|
int
|
getBackgroundType()
Returns the background type. |
ProgressBarManager
|
getProgressBarManager()
Returns the ProgressBarManager that will show or hide progress bar in
|
void
|
hideControlsOverlay(boolean runAnimation)
Hide controls overlay. |
boolean
|
isControlsOverlayAutoHideEnabled()
Returns true if controls will be auto hidden after a delay when fragment is resumed. |
boolean
|
isControlsOverlayVisible()
Returns true if controls overlay is visible, false otherwise. |
boolean
|
isFadingEnabled()
This method is deprecated.
Uses |
boolean
|
isShowOrHideControlsOverlayOnUserInteraction()
Returns true if showing and auto-hiding controls when user interacts; false otherwise. |
void
|
notifyPlaybackRowChanged()
Updates the ui when the row data changes. |
void
|
onCreate(Bundle savedInstanceState)
Called to do initial creation of a fragment. |
View
|
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
Called to have the fragment instantiate its user interface view. |
void
|
onDestroy()
Called when the fragment is no longer in use. |
void
|
onDestroyView()
Called when the view previously created by |
void
|
onPause()
Called when the Fragment is no longer resumed. |
void
|
onResume()
Called when the fragment is visible to the user and actively running. |
void
|
onStart()
Called when the Fragment is visible to the user. |
void
|
onStop()
Called when the Fragment is no longer started. |
void
|
onViewCreated(View view, Bundle savedInstanceState)
Called immediately after |
void
|
setAdapter(ObjectAdapter adapter)
Sets the list of rows for the fragment. |
void
|
setBackgroundType(int type)
Sets the background type. |
void
|
setControlsOverlayAutoHideEnabled(boolean enabled)
Enables or disables auto hiding controls overlay after a short delay fragment is resumed. |
void
|
setFadingEnabled(boolean enabled)
This method is deprecated.
Uses |
void
|
setHostCallback(PlaybackGlueHost.HostCallback hostCallback)
Sets the |
void
|
setOnItemViewClickedListener(BaseOnItemViewClickedListener listener)
This listener is called every time there is a click in |
void
|
setOnItemViewSelectedListener(BaseOnItemViewSelectedListener listener)
This listener is called every time there is a selection in |
final
void
|
setOnKeyInterceptListener(View.OnKeyListener handler)
Sets the input event handler. |
void
|
setOnPlaybackItemViewClickedListener(BaseOnItemViewClickedListener listener)
Sets the |
void
|
setPlaybackRow(Row row)
Sets the playback row for the playback controls. |
void
|
setPlaybackRowPresenter(PlaybackRowPresenter presenter)
Sets the presenter for rendering the playback row set by |
void
|
setPlaybackSeekUiClient(PlaybackSeekUi.Client client)
Interface to be implemented by UI widget to support PlaybackSeekUi. |
void
|
setSelectedPosition(int position)
Sets the selected row position with smooth animation. |
void
|
setSelectedPosition(int position, boolean smooth)
Sets the selected row position. |
void
|
setShowOrHideControlsOverlayOnUserInteraction(boolean showOrHideControlsOverlayOnUserInteraction)
Enables or disables showing and auto-hiding controls when user interacts. |
void
|
showControlsOverlay(boolean runAnimation)
Show controls overlay. |
void
|
tickle()
Tickles the playback controls. |
Protected methods | |
---|---|
void
|
onBufferingStateChanged(boolean start)
Called when media has start or stop buffering. |
void
|
onError(int errorCode, CharSequence errorMessage)
Called when media has error. |
void
|
onVideoSizeChanged(int videoWidth, int videoHeight)
Called when size of the video changes. |
Inherited methods | |
---|---|
Constants
BG_DARK
public static final int BG_DARK
A dark translucent background.
Constant Value: 1 (0x00000001)
BG_LIGHT
public static final int BG_LIGHT
A light translucent background.
Constant Value: 2 (0x00000002)
BG_NONE
public static final int BG_NONE
No background.
Constant Value: 0 (0x00000000)
Public constructors
PlaybackSupportFragment
public PlaybackSupportFragment ()
Public methods
fadeOut
public void fadeOut ()
This method is deprecated.
Call hideControlsOverlay(boolean)
Fades out the playback overlay immediately.
getBackgroundType
public int getBackgroundType ()
Returns the background type.
Returns | |
---|---|
int |
getProgressBarManager
public ProgressBarManager getProgressBarManager ()
Returns the ProgressBarManager that will show or hide progress bar in
onBufferingStateChanged(boolean)
.
Returns | |
---|---|
ProgressBarManager |
The ProgressBarManager that will show or hide progress bar in
onBufferingStateChanged(boolean) .
|
hideControlsOverlay
public void hideControlsOverlay (boolean runAnimation)
Hide controls overlay.
Parameters | |
---|---|
runAnimation |
boolean : True to run animation, false otherwise.
|
isControlsOverlayAutoHideEnabled
public boolean isControlsOverlayAutoHideEnabled ()
Returns true if controls will be auto hidden after a delay when fragment is resumed.
Returns | |
---|---|
boolean |
isControlsOverlayVisible
public boolean isControlsOverlayVisible ()
Returns true if controls overlay is visible, false otherwise.
Returns | |
---|---|
boolean |
True if controls overlay is visible, false otherwise. |
isFadingEnabled
public boolean isFadingEnabled ()
This method is deprecated.
Uses isControlsOverlayAutoHideEnabled()
Returns | |
---|---|
boolean |
isShowOrHideControlsOverlayOnUserInteraction
public boolean isShowOrHideControlsOverlayOnUserInteraction ()
Returns true if showing and auto-hiding controls when user interacts; false otherwise.
Returns | |
---|---|
boolean |
notifyPlaybackRowChanged
public void notifyPlaybackRowChanged ()
Updates the ui when the row data changes.
onCreate
public void onCreate (Bundle savedInstanceState)
Called to do initial creation of a fragment. This is called after
onAttach(Activity)
and before
onCreateView(LayoutInflater, ViewGroup, Bundle)
.
Note that this can be called while the fragment's activity is
still in the process of being created. As such, you can not rely
on things like the activity's content view hierarchy being initialized
at this point. If you want to do work once the activity itself is
created, see onActivityCreated(Bundle)
.
Any restored child fragments will be created before the base
Fragment.onCreate
method returns.
Parameters | |
---|---|
savedInstanceState |
Bundle : If the fragment is being re-created from
a previous saved state, this is the state.
|
onCreateView
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
Called to have the fragment instantiate its user interface view.
This is optional, and non-graphical fragments can return null. This will be called between
onCreate(Bundle)
and onActivityCreated(Bundle)
.
A default View can be returned by calling Fragment(int)
in your
constructor. Otherwise, this method returns null.
It is recommended to only inflate the layout in this method and move
logic that operates on the returned View to onViewCreated(View, Bundle)
.
If you return a View from here, you will later be called in
onDestroyView()
when the view is being released.
Parameters | |
---|---|
inflater |
LayoutInflater : The LayoutInflater object that can be used to inflate
any views in the fragment, |
container |
ViewGroup : If non-null, this is the parent view that the fragment's
UI should be attached to. The fragment should not add the view itself,
but this can be used to generate the LayoutParams of the view. |
savedInstanceState |
Bundle : If non-null, this fragment is being re-constructed
from a previous saved state as given here. |
Returns | |
---|---|
View |
Return the View for the fragment's UI, or null. |
onDestroy
public void onDestroy ()
Called when the fragment is no longer in use. This is called
after onStop()
and before onDetach()
.
onDestroyView
public void onDestroyView ()
Called when the view previously created by onCreateView(LayoutInflater, ViewGroup, Bundle)
has
been detached from the fragment. The next time the fragment needs
to be displayed, a new view will be created. This is called
after onStop()
and before onDestroy()
. It is called
regardless of whether onCreateView(LayoutInflater, ViewGroup, Bundle)
returned a
non-null view. Internally it is called after the view's state has
been saved but before it has been removed from its parent.
onPause
public void onPause ()
Called when the Fragment is no longer resumed. This is generally
tied to Activity.onPause
of the containing
Activity's lifecycle.
onResume
public void onResume ()
Called when the fragment is visible to the user and actively running.
This is generally
tied to Activity.onResume
of the containing
Activity's lifecycle.
onStart
public void onStart ()
Called when the Fragment is visible to the user. This is generally
tied to Activity.onStart
of the containing
Activity's lifecycle.
onStop
public void onStop ()
Called when the Fragment is no longer started. This is generally
tied to Activity.onStop
of the containing
Activity's lifecycle.
onViewCreated
public void onViewCreated (View view, Bundle savedInstanceState)
Called immediately after onCreateView(LayoutInflater, ViewGroup, Bundle)
has returned, but before any saved state has been restored in to the view.
This gives subclasses a chance to initialize themselves once
they know their view hierarchy has been completely created. The fragment's
view hierarchy is not however attached to its parent at this point.
Parameters | |
---|---|
view |
View : The View returned by onCreateView(LayoutInflater, ViewGroup, Bundle) . |
savedInstanceState |
Bundle : If non-null, this fragment is being re-constructed
from a previous saved state as given here.
|
setAdapter
public void setAdapter (ObjectAdapter adapter)
Sets the list of rows for the fragment. A default ClassPresenterSelector
will be
created if ObjectAdapter.getPresenterSelector()
is null. if user provides
setPlaybackRow(Row)
and setPlaybackRowPresenter(PlaybackRowPresenter)
,
the row and presenter will be set onto the adapter.
Parameters | |
---|---|
adapter |
ObjectAdapter : The adapter that contains related rows and optional playback row.
|
setBackgroundType
public void setBackgroundType (int type)
Sets the background type.
Parameters | |
---|---|
type |
int : One of BG_LIGHT, BG_DARK, or BG_NONE.
|
setControlsOverlayAutoHideEnabled
public void setControlsOverlayAutoHideEnabled (boolean enabled)
Enables or disables auto hiding controls overlay after a short delay fragment is resumed.
If enabled and fragment is resumed, the view will fade out after a time period.
User interaction will kill the timer, next time fragment is resumed,
the timer will be started again if isControlsOverlayAutoHideEnabled()
is true.
In most cases app should not directly call setControlsOverlayAutoHideEnabled() as it's
called by PlaybackBaseControlGlue
on play or pause.
Parameters | |
---|---|
enabled |
boolean |
setFadingEnabled
public void setFadingEnabled (boolean enabled)
This method is deprecated.
Uses setControlsOverlayAutoHideEnabled(boolean)
Parameters | |
---|---|
enabled |
boolean |
setHostCallback
public void setHostCallback (PlaybackGlueHost.HostCallback hostCallback)
Sets the PlaybackGlueHost.HostCallback
. Implementor of this interface will
take appropriate actions to take action when the hosting fragment starts/stops processing.
Parameters | |
---|---|
hostCallback |
PlaybackGlueHost.HostCallback |
setOnItemViewClickedListener
public void setOnItemViewClickedListener (BaseOnItemViewClickedListener listener)
This listener is called every time there is a click in RowsSupportFragment
. This can
be used by users to take additional actions such as animations.
Parameters | |
---|---|
listener |
BaseOnItemViewClickedListener |
setOnItemViewSelectedListener
public void setOnItemViewSelectedListener (BaseOnItemViewSelectedListener listener)
This listener is called every time there is a selection in RowsSupportFragment
. This can
be used by users to take additional actions such as animations.
Parameters | |
---|---|
listener |
BaseOnItemViewSelectedListener |
setOnKeyInterceptListener
public final void setOnKeyInterceptListener (View.OnKeyListener handler)
Sets the input event handler.
Parameters | |
---|---|
handler |
View.OnKeyListener |
setOnPlaybackItemViewClickedListener
public void setOnPlaybackItemViewClickedListener (BaseOnItemViewClickedListener listener)
Sets the BaseOnItemViewClickedListener
that would be invoked for clicks
only on PlaybackRowPresenter.ViewHolder
.
Parameters | |
---|---|
listener |
BaseOnItemViewClickedListener |
setPlaybackRow
public void setPlaybackRow (Row row)
Sets the playback row for the playback controls. The row will be set as first element
of adapter if the adapter is ArrayObjectAdapter
or SparseArrayObjectAdapter
.
Parameters | |
---|---|
row |
Row : The row that represents the playback.
|
setPlaybackRowPresenter
public void setPlaybackRowPresenter (PlaybackRowPresenter presenter)
Sets the presenter for rendering the playback row set by setPlaybackRow(Row)
. If
adapter does not set a PresenterSelector
, setAdapter(ObjectAdapter)
will
create a ClassPresenterSelector
by default and map from the row object class to this
PlaybackRowPresenter
.
Parameters | |
---|---|
presenter |
PlaybackRowPresenter : Presenter used to render setPlaybackRow(Row) .
|
setPlaybackSeekUiClient
public void setPlaybackSeekUiClient (PlaybackSeekUi.Client client)
Interface to be implemented by UI widget to support PlaybackSeekUi.
Parameters | |
---|---|
client |
PlaybackSeekUi.Client |
setSelectedPosition
public void setSelectedPosition (int position)
Sets the selected row position with smooth animation.
Parameters | |
---|---|
position |
int |
setSelectedPosition
public void setSelectedPosition (int position, boolean smooth)
Sets the selected row position.
Parameters | |
---|---|
position |
int |
smooth |
boolean |
setShowOrHideControlsOverlayOnUserInteraction
public void setShowOrHideControlsOverlayOnUserInteraction (boolean showOrHideControlsOverlayOnUserInteraction)
Enables or disables showing and auto-hiding controls when user interacts. Enabled by default.
Auto-hide timer length is defined by R.attr.playbackControlsAutoHideTickleTimeout
.
Parameters | |
---|---|
showOrHideControlsOverlayOnUserInteraction |
boolean |
showControlsOverlay
public void showControlsOverlay (boolean runAnimation)
Show controls overlay.
Parameters | |
---|---|
runAnimation |
boolean : True to run animation, false otherwise.
|
tickle
public void tickle ()
Tickles the playback controls. Fades in the view if it was faded out. tickle()
will
kill and re-create a timer if R.attr.playbackControlsAutoHideTickleTimeout
is
positive.
In most cases app does not need call tickle() as it's automatically called on user interactions.
Protected methods
onBufferingStateChanged
protected void onBufferingStateChanged (boolean start)
Called when media has start or stop buffering. App may override. The default initial state is not buffering.
Parameters | |
---|---|
start |
boolean : True for buffering start, false otherwise.
|
onError
protected void onError (int errorCode, CharSequence errorMessage)
Called when media has error. App may override.
Parameters | |
---|---|
errorCode |
int : Optional error code for specific implementation. |
errorMessage |
CharSequence : Optional error message for specific implementation.
|
onVideoSizeChanged
protected void onVideoSizeChanged (int videoWidth, int videoHeight)
Called when size of the video changes. App may override.
Parameters | |
---|---|
videoWidth |
int : Intrinsic width of video |
videoHeight |
int : Intrinsic height of video
|