public final class BackgroundManager extends Object
An Activity should instantiate a BackgroundManager and attach(android.view.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:
setColor(int)
)setBitmap(android.graphics.Bitmap)
or
setDrawable(android.graphics.drawable.Drawable)
), which may be in transitionBackgroundManager holds references to potentially large bitmap Drawables.
Call release()
to release these references when the Activity is not
visible.
Modifier and Type | Method and Description |
---|---|
void |
attach(Window window)
Makes the background visible on the given Window.
|
int |
getColor()
Returns the current background color.
|
Drawable |
getDefaultDimLayer()
Returns the default drawable used as a dim layer.
|
Drawable |
getDimLayer()
Returns the drawable used as a dim layer.
|
Drawable |
getDrawable()
Returns the current background
Drawable . |
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.
|
void |
release()
Release references to Drawables.
|
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)
Sets the drawable used as a 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.
|
public static BackgroundManager getInstance(Activity activity)
The BackgroundManager will be created on-demand for each individual Activity. Subsequent calls will return the same BackgroundManager created for this Activity.
public void attach(Window window)
public void setThemeDrawableResourceId(int resourceId)
public boolean isAttached()
public void release()
When an Activity is started, 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.
public void setDimLayer(Drawable drawable)
public Drawable getDimLayer()
public Drawable getDefaultDimLayer()
public void setColor(int color)
public void setDrawable(Drawable drawable)
public void setBitmap(Bitmap bitmap)
public final int getColor()