Android 12 Developer Preview is here! Try it out, and give us your feedback!


open class 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) {
      MediaPlayerGlue player = new MediaPlayerGlue(..);
  static class MyLoadBitmapTask extends ... {
      MyLoadBitmapTask(MyFragment fragment) {
          mFragmentRef = new WeakReference(fragment);
      protected void onPostExecute(Bitmap bitmap) {
          MyFragment fragment = mFragmentRef.get();
          if (fragment != null) {
  public void onStart() {
      new MyLoadBitmapTask(this).execute(url);
  public void onStop() {

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().


Public constructors

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

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.


Adds or gets fragment for rendering video in DetailsSupportFragment.


Returns the drawable at bottom.


Returns Bitmap set by setCoverBitmap(Bitmap).


Returns the cover drawable at top.


Returns Default parallax offset in pixels for bitmap moving vertically.


Returns current PlaybackGlue or null if not set or cleared.


Returns color set by setSolidColor(int).

open PlaybackGlueHost!

Creates a PlaybackGlueHost to host PlaybackGlue.

open Fragment!

Creates a Fragment to host PlaybackGlue.


Convenient method to set Bitmap in cover drawable.


Sets default parallax offset in pixels for bitmap moving vertically.

setSolidColor(@ColorInt color: Int)

Convenient method to set color in bottom drawable.

open Unit
setupVideoPlayback(@NonNull playbackGlue: PlaybackGlue)

Enable video playback and set proper PlaybackGlueHost.


Switch to rows fragment.


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

Public constructors


DetailsSupportFragmentBackgroundController(fragment: DetailsSupportFragment!)

Creates a DetailsSupportFragmentBackgroundController for a DetailsSupportFragment. Note that each DetailsSupportFragment can only associate with one DetailsSupportFragmentBackgroundController.

fragment DetailsSupportFragment!: The DetailsSupportFragment to control background and embedded video playing.
IllegalStateException If fragment was already associated with another controller.

Public methods


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.

Boolean True allow to navigate to video fragment.


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