DetailsFragmentBackgroundController

public class DetailsFragmentBackgroundController
extends Object

java.lang.Object
   ↳ androidx.leanback.app.DetailsFragmentBackgroundController


This class is deprecated.
use DetailsSupportFragmentBackgroundController

Controller for DetailsFragment 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:
 DetailsFragmentBackgroundController mController = new DetailsFragmentBackgroundController(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 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);
 }
 

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 onCreateVideoFragment() and onCreateGlueHost().

Summary

Public constructors

DetailsFragmentBackgroundController(DetailsFragment fragment)

Creates a DetailsFragmentBackgroundController for a DetailsFragment.

Public methods

boolean canNavigateToVideoFragment()

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 FitWidthBitmapDrawable as cover drawable and ColorDrawable as bottom drawable.

final Fragment findOrCreateVideoFragment()

Adds or gets fragment for rendering video in DetailsFragment.

final Drawable getBottomDrawable()

Returns the drawable at bottom.

final Bitmap getCoverBitmap()

Returns Bitmap set by setCoverBitmap(Bitmap).

final Drawable getCoverDrawable()

Returns the cover drawable at top.

final int getParallaxDrawableMaxOffset()

Returns Default parallax offset in pixels for bitmap moving vertically.

final PlaybackGlue getPlaybackGlue()

Returns current PlaybackGlue or null if not set or cleared.

final int getSolidColor()

Returns color set by setSolidColor(int).

PlaybackGlueHost onCreateGlueHost()

Creates a PlaybackGlueHost to host PlaybackGlue.

Fragment onCreateVideoFragment()

Creates a Fragment to host PlaybackGlue.

final void setCoverBitmap(Bitmap bitmap)

Convenient method to set Bitmap in cover drawable.

final void setParallaxDrawableMaxOffset(int offset)

Sets default parallax offset in pixels for bitmap moving vertically.

final void setSolidColor(int color)

Convenient method to set color in bottom drawable.

void setupVideoPlayback(PlaybackGlue playbackGlue)

Enable video playback and set proper PlaybackGlueHost.

final void switchToRows()

Switch to rows fragment.

final void switchToVideo()

Switch to video fragment, note that this method is not affected by result of canNavigateToVideoFragment().

Inherited methods