belongs to Maven artifact com.android.support:leanback-v17:28.0.0-alpha1
BackgroundManager
public
final
class
BackgroundManager
extends Object
java.lang.Object | |
↳ | android.support.v17.leanback.app.BackgroundManager |
Supports background image continuity between multiple Activities.
An Activity should instantiate a BackgroundManager and attach(Window)
to the Activity's window. When the Activity is started, the background is
initialized to the current background values stored in a continuity service.
The background continuity service is updated as the background is updated.
At some point, for example when it is stopped, the Activity may release its background state.
When an Activity is resumed, if the BackgroundManager has not been released, the continuity service is updated from the BackgroundManager state. If the BackgroundManager was released, the BackgroundManager inherits the current state from the continuity service.
When the last Activity is destroyed, the background state is reset.
Backgrounds consist of several layers, from back to front:
- the background Drawable of the theme
- a solid color (set via
setColor(int)
) - two Drawables, previous and current (set via
setBitmap(Bitmap)
orsetDrawable(Drawable)
), which may be in transition
BackgroundManager holds references to potentially large bitmap Drawables.
Call release()
to release these references when the Activity is not
visible.
Summary
Public methods | |
---|---|
void
|
attach(Window window)
Makes the background visible on the given Window. |
void
|
attachToView(View sceneRoot)
Adds the composite drawable to the given view. |
void
|
clearDrawable()
Clears the Drawable set by |
int
|
getColor()
Returns the current background color. |
Drawable
|
getDefaultDimLayer()
This method was deprecated in API level 25.1.0. No longer support dim layer. |
Drawable
|
getDimLayer()
This method was deprecated in API level 25.1.0. No longer support dim layer. |
Drawable
|
getDrawable()
Returns the current background |
static
BackgroundManager
|
getInstance(Activity activity)
Returns the BackgroundManager associated with the given Activity. |
boolean
|
isAttached()
Returns true if the background manager is currently attached; false otherwise. |
boolean
|
isAutoReleaseOnStop()
|
void
|
release()
Release references to Drawable/Bitmap. |
void
|
setAutoReleaseOnStop(boolean autoReleaseOnStop)
Enable or disable call release() in Activity onStop(). |
void
|
setBitmap(Bitmap bitmap)
Sets the given bitmap into the background. |
void
|
setColor(int color)
Sets the background to the given color. |
void
|
setDimLayer(Drawable drawable)
This method was deprecated in API level 25.1.0. No longer support dim layer. |
void
|
setDrawable(Drawable drawable)
Sets the given drawable into the background. |
void
|
setThemeDrawableResourceId(int resourceId)
Sets the resource id for the drawable to be shown when there is no background set. |
Inherited methods | |
---|---|
From
class
java.lang.Object
|
Public methods
attach
void attach (Window window)
Makes the background visible on the given Window. The background manager must be attached when the background is set.
Parameters | |
---|---|
window |
Window |
attachToView
void attachToView (View sceneRoot)
Adds the composite drawable to the given view.
Parameters | |
---|---|
sceneRoot |
View |
clearDrawable
void clearDrawable ()
Clears the Drawable set by setDrawable(Drawable)
or setBitmap(Bitmap)
.
BackgroundManager will show a solid color set by setColor(int)
or theme drawable
if color is not provided.
getDefaultDimLayer
Drawable getDefaultDimLayer ()
This method was deprecated
in API level 25.1.0.
No longer support dim layer.
Returns the default drawable used as a dim layer.
Returns | |
---|---|
Drawable |
getDimLayer
Drawable getDimLayer ()
This method was deprecated
in API level 25.1.0.
No longer support dim layer.
Returns the drawable used as a dim layer.
Returns | |
---|---|
Drawable |
getDrawable
Drawable getDrawable ()
Returns the current background Drawable
.
Returns | |
---|---|
Drawable |
getInstance
BackgroundManager getInstance (Activity activity)
Returns the BackgroundManager associated with the given Activity.
The BackgroundManager will be created on-demand for each individual Activity. Subsequent calls will return the same BackgroundManager created for this Activity.
Parameters | |
---|---|
activity |
Activity |
Returns | |
---|---|
BackgroundManager |
isAttached
boolean isAttached ()
Returns true if the background manager is currently attached; false otherwise.
Returns | |
---|---|
boolean |
isAutoReleaseOnStop
boolean isAutoReleaseOnStop ()
Returns | |
---|---|
boolean |
True if release() in Activity.onStop(), false otherwise. |
release
void release ()
Release references to Drawable/Bitmap. Typically called in Activity onStop() to reduce memory
overhead when not visible. It's app's responsibility to restore the drawable/bitmap in
Activity onStart(). The method is automatically called in onStop() when
isAutoReleaseOnStop()
is true.
See also:
setAutoReleaseOnStop
void setAutoReleaseOnStop (boolean autoReleaseOnStop)
Enable or disable call release() in Activity onStop(). Default is true.
Parameters | |
---|---|
autoReleaseOnStop |
boolean : True to call release() in Activity onStop(), false otherwise.
|
setBitmap
void setBitmap (Bitmap bitmap)
Sets the given bitmap into the background. When using setCoverImageBitmap to set the background, the provided bitmap will be scaled and cropped to correctly fit within the dimensions of the view. The timing for when this becomes visible in the app is undefined and may take place after a small delay.
Parameters | |
---|---|
bitmap |
Bitmap |
setColor
void setColor (int color)
Sets the background to the given color. The timing for when this becomes visible in the app is undefined and may take place after a small delay.
Parameters | |
---|---|
color |
int |
setDimLayer
void setDimLayer (Drawable drawable)
This method was deprecated
in API level 25.1.0.
No longer support dim layer.
Sets the drawable used as a dim layer.
Parameters | |
---|---|
drawable |
Drawable |
setDrawable
void setDrawable (Drawable drawable)
Sets the given drawable into the background. The provided Drawable will be used unmodified as the background, without any scaling or cropping applied to it. The timing for when this becomes visible in the app is undefined and may take place after a small delay.
Parameters | |
---|---|
drawable |
Drawable |
setThemeDrawableResourceId
void setThemeDrawableResourceId (int resourceId)
Sets the resource id for the drawable to be shown when there is no background set. Overrides the window background drawable from the theme. This should be called before attaching.
Parameters | |
---|---|
resourceId |
int |
Interfaces
- BrowseFragment.FragmentHost
- BrowseFragment.MainFragmentAdapterProvider
- BrowseFragment.MainFragmentRowsAdapterProvider
- BrowseSupportFragment.FragmentHost
- BrowseSupportFragment.MainFragmentAdapterProvider
- BrowseSupportFragment.MainFragmentRowsAdapterProvider
- HeadersFragment.OnHeaderClickedListener
- HeadersFragment.OnHeaderViewSelectedListener
- HeadersSupportFragment.OnHeaderClickedListener
- HeadersSupportFragment.OnHeaderViewSelectedListener
- SearchFragment.SearchResultProvider
- SearchSupportFragment.SearchResultProvider
Classes
- BackgroundManager
- BaseFragment
- BaseSupportFragment
- BrandedFragment
- BrandedSupportFragment
- BrowseFragment
- BrowseFragment.BrowseTransitionListener
- BrowseFragment.FragmentFactory
- BrowseFragment.ListRowFragmentFactory
- BrowseFragment.MainFragmentAdapter
- BrowseFragment.MainFragmentAdapterRegistry
- BrowseFragment.MainFragmentRowsAdapter
- BrowseSupportFragment
- BrowseSupportFragment.BrowseTransitionListener
- BrowseSupportFragment.FragmentFactory
- BrowseSupportFragment.ListRowFragmentFactory
- BrowseSupportFragment.MainFragmentAdapter
- BrowseSupportFragment.MainFragmentAdapterRegistry
- BrowseSupportFragment.MainFragmentRowsAdapter
- DetailsFragment
- DetailsFragmentBackgroundController
- DetailsSupportFragment
- DetailsSupportFragmentBackgroundController
- ErrorFragment
- ErrorSupportFragment
- GuidedStepFragment
- GuidedStepSupportFragment
- HeadersFragment
- HeadersSupportFragment
- OnboardingFragment
- OnboardingSupportFragment
- PlaybackFragment
- PlaybackFragmentGlueHost
- PlaybackSupportFragment
- PlaybackSupportFragmentGlueHost
- ProgressBarManager
- RowsFragment
- RowsFragment.MainFragmentAdapter
- RowsFragment.MainFragmentRowsAdapter
- RowsSupportFragment
- RowsSupportFragment.MainFragmentAdapter
- RowsSupportFragment.MainFragmentRowsAdapter
- SearchFragment
- SearchSupportFragment
- VerticalGridFragment
- VerticalGridSupportFragment
- VideoFragment
- VideoFragmentGlueHost
- VideoSupportFragment
- VideoSupportFragmentGlueHost