belongs to Maven artifact com.android.support:leanback-v17:28.0.0-alpha1
DetailsSupportFragmentBackgroundController
public
class
DetailsSupportFragmentBackgroundController
extends Object
java.lang.Object | |
↳ | android.support.v17.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 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 play()
when fragment starts and
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 ... { WeakReferencemFragmentRef; 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); }
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 | |
---|---|
DetailsSupportFragmentBackgroundController(DetailsSupportFragment fragment)
Creates a DetailsSupportFragmentBackgroundController for a DetailsSupportFragment. |
Public methods | |
---|---|
boolean
|
canNavigateToVideoSupportFragment()
Precondition allows user navigate to video fragment using DPAD. |
void
|
enableParallax(Drawable coverDrawable, Drawable bottomDrawable, ParallaxTarget.PropertyValuesHolderTarget coverDrawableParallaxTarget)
Enables parallax background using a custom cover drawable at top and a custom bottom drawable. |
void
|
enableParallax()
Enables default parallax background using a |
final
Fragment
|
findOrCreateVideoSupportFragment()
Adds or gets fragment for rendering video in DetailsSupportFragment. |
final
Drawable
|
getBottomDrawable()
Returns the drawable at bottom. |
final
Bitmap
|
getCoverBitmap()
Returns Bitmap set by |
final
Drawable
|
getCoverDrawable()
Returns the cover drawable at top. |