DetailsSupportFragmentBackgroundController
open class DetailsSupportFragmentBackgroundController
kotlin.Any | |
↳ | androidx.leanback.app.DetailsSupportFragmentBackgroundController |
Controller for DetailsSupportFragment parallax background and embedded video play.
The parallax background drawable is made of two parts: cover drawable (by default FitWidthBitmapDrawable
) above the details overview row and bottom drawable (by default ColorDrawable
) below the details overview row. While vertically scrolling rows, the size of cover drawable and bottom drawable will be updated and the cover drawable will by default perform a parallax shift using FitWidthBitmapDrawable#PROPERTY_VERTICAL_OFFSET
.
*************************** * Cover Drawable * * (FitWidthBitmapDrawable)* * * *************************** * DetailsOverviewRow * * * *************************** * Bottom Drawable * * (ColorDrawable) * * Related * * Content * ***************************Both parallax background drawable and embedded video play are optional. App must call
enableParallax()
and/or setupVideoPlayback(PlaybackGlue)
explicitly. The PlaybackGlue is automatically PlaybackGlue#play()
when fragment starts and PlaybackGlue#pause()
when fragment stops. When video is ready to play, cover drawable will be faded out. Example:
DetailsSupportFragmentBackgroundController mController = new DetailsSupportFragmentBackgroundController(this); public void onCreate(Bundle savedInstance) { super.onCreate(savedInstance); MediaPlayerGlue player = new MediaPlayerGlue(..); player.setUrl(...); mController.enableParallax(); mController.setupVideoPlayback(player); } static class MyLoadBitmapTask extends ... { WeakReference<myfragment> mFragmentRef; MyLoadBitmapTask(MyFragment fragment) { mFragmentRef = new WeakReference(fragment); } protected void onPostExecute(Bitmap bitmap) { MyFragment fragment = mFragmentRef.get(); if (fragment != null) { fragment.mController.setCoverBitmap(bitmap); } } } public void onStart() { new MyLoadBitmapTask(this).execute(url); } public void onStop() { mController.setCoverBitmap(null); } </myfragment>
To customize cover drawable and/or bottom drawable, app should call enableParallax(Drawable, Drawable, ParallaxTarget.PropertyValuesHolderTarget)
. If app supplies a custom cover Drawable, it should not call setCoverBitmap(Bitmap)
. If app supplies a custom bottom Drawable, it should not call setSolidColor(int)
.
To customize playback fragment, app should override onCreateVideoSupportFragment()
and onCreateGlueHost()
.
Summary
Public constructors | |
---|---|
<init>(fragment: DetailsSupportFragment!) Creates a DetailsSupportFragmentBackgroundController for a DetailsSupportFragment. |
Public methods | |
---|---|
open Boolean |
Precondition allows user navigate to video fragment using DPAD. |
open Unit |
Enables default parallax background using a |
open Unit |
enableParallax(@NonNull coverDrawable: Drawable, @NonNull bottomDrawable: Drawable, @Nullable coverDrawableParallaxTarget: ParallaxTarget.PropertyValuesHolderTarget?) Enables parallax background using a custom cover drawable at top and a custom bottom drawable. |
Fragment! |
Adds or gets fragment for rendering video in DetailsSupportFragment. |
Drawable! |
Returns the drawable at bottom. |
Bitmap! |
Returns Bitmap set by |
Drawable! |
Returns the cover drawable at top. |
Int |
Returns Default parallax offset in pixels for bitmap moving vertically. |
PlaybackGlue! |
Returns current PlaybackGlue or null if not set or cleared. |
Int |
Returns color set by |
open PlaybackGlueHost! |
Creates a PlaybackGlueHost to host PlaybackGlue. |
open Fragment! |
Creates a Fragment to host |
Unit |
setCoverBitmap(bitmap: Bitmap!) Convenient method to set Bitmap in cover drawable. |
Unit |
setParallaxDrawableMaxOffset(offset: Int) Sets default parallax offset in pixels for bitmap moving vertically. |
Unit |
setSolidColor(@ColorInt color: Int) Convenient method to set color in bottom drawable. |
open Unit |
setupVideoPlayback(@NonNull playbackGlue: PlaybackGlue) Enable video playback and set proper |
Unit |
Switch to rows fragment. |
Unit |
Switch to video fragment, note that this method is not affected by result of |
Public constructors
<init>
DetailsSupportFragmentBackgroundController(fragment: DetailsSupportFragment!)
Creates a DetailsSupportFragmentBackgroundController for a DetailsSupportFragment. Note that each DetailsSupportFragment can only associate with one DetailsSupportFragmentBackgroundController.
Parameters | |
---|---|
fragment |
DetailsSupportFragment!: The DetailsSupportFragment to control background and embedded video playing. |
Exceptions | |
---|---|
IllegalStateException |
If fragment was already associated with another controller. |
Public methods
canNavigateToVideoSupportFragment
open fun canNavigateToVideoSupportFragment(): Boolean
Precondition allows user navigate to video fragment using DPAD. Default implementation returns true if PlaybackGlue is not null. Subclass may override, e.g. only allow navigation when PlaybackGlue#isPrepared()
is true. Note this method does not block app calls switchToVideo
.
Return | |
---|---|
Boolean |
True allow to navigate to video fragment. |
enableParallax
open fun enableParallax(): Unit
Enables default parallax background using a FitWidthBitmapDrawable
as cover drawable and ColorDrawable
as bottom drawable. A vertical parallax movement will be applied to the FitWidthBitmapDrawable. App may use setSolidColor(int)
and setCoverBitmap(Bitmap)
to change the content of bottom drawable and cover drawable. This method must be called before setupVideoPlayback(PlaybackGlue)
.
Exceptions | |
---|---|
IllegalStateException |
If setupVideoPlayback(PlaybackGlue) was called. |
enableParallax
open fun enableParallax(
@NonNull coverDrawable: Drawable,
@NonNull bottomDrawable: Drawable,
@Nullable coverDrawableParallaxTarget: ParallaxTarget.PropertyValuesHolderTarget?
): Unit
Enables parallax background using a custom cover drawable at top and a custom bottom drawable. This method must be called before setupVideoPlayback(PlaybackGlue)
.
Parameters | |
---|---|
coverDrawable |
Drawable: Custom cover drawable shown at top. setCoverBitmap(Bitmap) will not work if coverDrawable is not FitWidthBitmapDrawable ; in that case it's app's responsibility to set content into coverDrawable. |
bottomDrawable |
Drawable: Drawable shown at bottom. setSolidColor(int) will not work if bottomDrawable is not ColorDrawable ; in that case it's app's responsibility to set content of bottomDrawable. |
coverDrawableParallaxTarget |
ParallaxTarget.PropertyValuesHolderTarget?: Target to perform parallax effect within coverDrawable. Use null for no parallax movement effect. Example to move bitmap within FitWidthBitmapDrawable: new ParallaxTarget.PropertyValuesHolderTarget( coverDrawable, PropertyValuesHolder.ofInt( FitWidthBitmapDrawable.PROPERTY_VERTICAL_OFFSET, 0, -120)) |
Exceptions | |
---|---|
IllegalStateException |
If setupVideoPlayback(PlaybackGlue) was called. |
findOrCreateVideoSupportFragment
fun findOrCreateVideoSupportFragment(): Fragment!
Adds or gets fragment for rendering video in DetailsSupportFragment. A subclass that overrides onCreateGlueHost()
should call this method to get a fragment for creating a PlaybackGlueHost
.
Return | |
---|---|
Fragment! |
Fragment the added or restored fragment responsible for rendering video. |
See Also
getBottomDrawable
fun getBottomDrawable(): Drawable!
Returns the drawable at bottom. Returns null if enableParallax()
is not called. By default it's a ColorDrawable
.
Return | |
---|---|
Drawable! |
The bottom drawable. |
getCoverBitmap
fun getCoverBitmap(): Bitmap!
Returns Bitmap set by setCoverBitmap(Bitmap)
.
Return | |
---|---|
Bitmap! |
Bitmap for cover drawable. |
getCoverDrawable
fun getCoverDrawable(): Drawable!
Returns the cover drawable at top. Returns null if enableParallax()
is not called. By default it's a FitWidthBitmapDrawable
.
Return | |
---|---|
Drawable! |
The cover drawable at top. |
getParallaxDrawableMaxOffset
fun getParallaxDrawableMaxOffset(): Int
Returns Default parallax offset in pixels for bitmap moving vertically. When 0, a default value would be used.
Return | |
---|---|
Int |
Default parallax offset in pixels for bitmap moving vertically. |
See Also
getPlaybackGlue
fun getPlaybackGlue(): PlaybackGlue!
Returns current PlaybackGlue or null if not set or cleared.
Return | |
---|---|
PlaybackGlue! |
Current PlaybackGlue or null |
getSolidColor
@ColorInt fun getSolidColor(): Int
Returns color set by setSolidColor(int)
.
Return | |
---|---|
Int |
Solid color used for bottom drawable. |
onCreateGlueHost
open fun onCreateGlueHost(): PlaybackGlueHost!
Creates a PlaybackGlueHost to host PlaybackGlue. App may override this if it overrides onCreateVideoSupportFragment()
. This method must be called after calling Fragment super.onCreate(). When override this method, app may call findOrCreateVideoSupportFragment()
to get or create a fragment.
Return | |
---|---|
PlaybackGlueHost! |
A new PlaybackGlueHost to host PlaybackGlue. |
onCreateVideoSupportFragment
open fun onCreateVideoSupportFragment(): Fragment!
Creates a Fragment to host PlaybackGlue
. Returns a new VideoSupportFragment
by default. App may override and return a different fragment and it also must override onCreateGlueHost()
.
Return | |
---|---|
|