java.lang.Object | ||||
↳ | android.content.Context | |||
↳ | android.content.ContextWrapper | |||
↳ | android.app.Service | |||
↳ | android.service.dreams.DreamService |
Extend this class to implement a custom dream (available to the user as a "Daydream").
Dreams are interactive screensavers launched when a charging device is idle, or docked in a desk dock. Dreams provide another modality for apps to express themselves, tailored for an exhibition/lean-back experience.
The DreamService
lifecycle is as follows:
onAttachedToWindow()
Use this for initial setup, such as calling setContentView()
.
onDreamingStarted()
Your dream has started, so you should begin animations or other behaviors here.
onDreamingStopped()
Use this to stop the things you started in onDreamingStarted()
.
onDetachedFromWindow()
Use this to dismantle resources (for example, detach from handlers and listeners).
In addition, onCreate and onDestroy (from the Service interface) will also be called, but initialization and teardown should be done by overriding the hooks above.
To be available to the system, your DreamService
should be declared in the
manifest as follows:
<service android:name=".MyDream" android:exported="true" android:icon="@drawable/my_icon" android:label="@string/my_dream_label" > <intent-filter> <action android:name="android.service.dreams.DreamService" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <!-- Point to additional information for this dream (optional) --> <meta-data android:name="android.service.dream" android:resource="@xml/my_dream" /> </service>
If specified with the <meta-data>
element,
additional information for the dream is defined using the
<dream>
element in a separate XML file.
Currently, the only addtional
information you can provide is for a settings activity that allows the user to configure
the dream behavior. For example:
<dream xmlns:android="http://schemas.android.com/apk/res/android" android:settingsActivity="com.example.app/.MyDreamSettingsActivity" />
This makes a Settings button available alongside your dream's listing in the system settings, which when pressed opens the specified activity.
To specify your dream layout, call setContentView(View)
, typically during the
onAttachedToWindow()
callback. For example:
public class MyDream extends DreamService { @Override public void onAttachedToWindow() { super.onAttachedToWindow(); // Exit dream upon user touch setInteractive(false); // Hide system UI setFullscreen(true); // Set the dream layout setContentView(R.layout.dream); } }
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | DREAM_META_DATA | Name under which a Dream publishes information about itself. | |||||||||
String | SERVICE_INTERFACE | The Intent that must be declared as handled by the service. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.app.Service
| |||||||||||
From class
android.content.Context
| |||||||||||
From interface
android.content.ComponentCallbacks2
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a view to the Dream's window, leaving other content views in place.
| |||||||||||
Called to process generic motion events.
| |||||||||||
Called to process key events.
| |||||||||||
Called to process a key shortcut event.
| |||||||||||
Called to process population of
AccessibilityEvent s. | |||||||||||
Called to process touch screen events.
| |||||||||||
Called to process trackball events.
| |||||||||||
Finds a view that was identified by the id attribute from the XML that
was processed in
onCreate() . | |||||||||||
Stops the dream and detaches from the window.
| |||||||||||
Retrieves the current
Window for the dream. | |||||||||||
Retrieves the current
WindowManager for the dream. | |||||||||||
Returns whether or not this dream is in fullscreen mode.
| |||||||||||
Returns whether or not this dream is interactive.
| |||||||||||
Returns whether or not this dream keeps the screen bright while dreaming.
| |||||||||||
Called when an action mode has been finished.
| |||||||||||
Called when an action mode has been started.
| |||||||||||
Called when the window has been attached to the window manager.
| |||||||||||
Return the communication channel to the service.
| |||||||||||
This hook is called whenever the content view of the screen changes
(due to a call to
Window.setContentView or
Window.addContentView ). | |||||||||||
Called when this Dream is constructed.
| |||||||||||
Initialize the contents of the menu for panel 'featureId'.
| |||||||||||
Instantiate the view to display in the panel for 'featureId'.
| |||||||||||
Called by the system to notify a Service that it is no longer used and is being removed.
| |||||||||||
Called when the window has been attached to the window manager.
| |||||||||||
Called when the dream's window has been created and is visible and animation may now begin.
| |||||||||||
Called when this Dream is stopped, either by external request or by calling finish(),
before the window has been removed.
| |||||||||||
Called when a panel's menu item has been selected by the user.
| |||||||||||
Called when a panel's menu is opened by the user.
| |||||||||||
Called when a panel is being closed.
| |||||||||||
Prepare a panel to be displayed.
| |||||||||||
Called when the user signals the desire to start a search.
| |||||||||||
This is called whenever the current window attributes change.
| |||||||||||
This hook is called whenever the window focus changes.
| |||||||||||
Called when an action mode is being started for this window.
| |||||||||||
Sets a view to be the content view for this Dream.
| |||||||||||
Inflates a layout resource and set it to be the content view for this Dream.
| |||||||||||
Sets a view to be the content view for this Dream.
| |||||||||||
Controls
FLAG_FULLSCREEN
on the dream's window. | |||||||||||
Marks this dream as interactive to receive input events.
| |||||||||||
Marks this dream as keeping the screen bright while dreaming.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Print the Service's state into the given stream.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.app.Service
| |||||||||||
From class
android.content.ContextWrapper
| |||||||||||
From class
android.content.Context
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
android.content.ComponentCallbacks
| |||||||||||
From interface
android.content.ComponentCallbacks2
| |||||||||||
From interface
android.view.Window.Callback
|
Name under which a Dream publishes information about itself.
This meta-data must reference an XML resource containing
a <
tag.
dream
>
The Intent
that must be declared as handled by the service.
Adds a view to the Dream's window, leaving other content views in place.
Note: Requires a window, do not call before onAttachedToWindow()
view | The desired content to display. |
---|---|
params | Layout parameters for the view. |
Called to process generic motion events. At the very least your
implementation must call
superDispatchGenericMotionEvent(MotionEvent)
to do the
standard processing.
event | The generic motion event. |
---|
Called to process key events. At the very least your
implementation must call
superDispatchKeyEvent(KeyEvent)
to do the
standard key processing.
event | The key event. |
---|
Called to process a key shortcut event.
At the very least your implementation must call
superDispatchKeyShortcutEvent(KeyEvent)
to do the
standard key shortcut processing.
event | The key shortcut event. |
---|
Called to process population of AccessibilityEvent
s.
event | The event. |
---|
Called to process touch screen events. At the very least your
implementation must call
superDispatchTouchEvent(MotionEvent)
to do the
standard touch screen processing.
event | The touch screen event. |
---|
Called to process trackball events. At the very least your
implementation must call
superDispatchTrackballEvent(MotionEvent)
to do the
standard trackball processing.
event | The trackball event. |
---|
Finds a view that was identified by the id attribute from the XML that
was processed in onCreate()
.
Note: Requires a window, do not call before onAttachedToWindow()
Stops the dream and detaches from the window.
When the dream ends, the system will be allowed to go to sleep fully unless there is a reason for it to be awake such as recent user activity or wake locks being held.
Retrieves the current Window
for the dream.
Behaves similarly to getWindow()
.
Retrieves the current WindowManager
for the dream.
Behaves similarly to getWindowManager()
.
Returns whether or not this dream is in fullscreen mode. Defaults to false.
Returns whether or not this dream is interactive. Defaults to false.
Returns whether or not this dream keeps the screen bright while dreaming. Defaults to false, allowing the screen to dim if necessary.
Called when an action mode has been finished. The appropriate mode callback method will have already been invoked.
mode | The mode that was just finished. |
---|
Called when an action mode has been started. The appropriate mode callback method will have already been invoked.
mode | The new mode that has just been started. |
---|
Called when the window has been attached to the window manager.
See View.onAttachedToWindow()
for more information.
Return the communication channel to the service. May return null if
clients can not bind to the service. The returned
IBinder
is usually for a complex interface
that has been described using
aidl.
Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.
intent | The Intent that was used to bind to this service,
as given to Context.bindService . Note that any extras that were included with
the Intent at that point will not be seen here. |
---|
This hook is called whenever the content view of the screen changes
(due to a call to
Window.setContentView
or
Window.addContentView
).
Initialize the contents of the menu for panel 'featureId'. This is called if onCreatePanelView() returns null, giving you a standard menu in which you can place your items. It is only called once for the panel, the first time it is shown.
You can safely hold on to menu (and any items created from it), making modifications to it as desired, until the next time onCreatePanelMenu() is called for this feature.
featureId | The panel being created. |
---|---|
menu | The menu inside the panel. |
Instantiate the view to display in the panel for 'featureId'. You can return null, in which case the default content (typically a menu) will be created for you.
featureId | Which panel is being created. |
---|
Called by the system to notify a Service that it is no longer used and is being removed. The service should clean up any resources it holds (threads, registered receivers, etc) at this point. Upon return, there will be no more calls in to this Service object and it is effectively dead. Do not call this method directly.
Called when the window has been attached to the window manager.
See View.onDetachedFromWindow()
for more information.
Called when the dream's window has been created and is visible and animation may now begin.
Called when this Dream is stopped, either by external request or by calling finish(), before the window has been removed.
Called when a panel's menu item has been selected by the user.
featureId | The panel that the menu is in. |
---|---|
item | The menu item that was selected. |
Called when a panel's menu is opened by the user. This may also be called when the menu is changing from one type to another (for example, from the icon menu to the expanded menu).
featureId | The panel that the menu is in. |
---|---|
menu | The menu that is opened. |
Called when a panel is being closed. If another logical subsequent panel is being opened (and this panel is being closed to make room for the subsequent panel), this method will NOT be called.
featureId | The panel that is being displayed. |
---|---|
menu | If onCreatePanelView() returned null, this is the Menu being displayed in the panel. |
Prepare a panel to be displayed. This is called right before the panel window is shown, every time it is shown.
featureId | The panel that is being displayed. |
---|---|
view | The View that was returned by onCreatePanelView(). |
menu | If onCreatePanelView() returned null, this is the Menu being displayed in the panel. |
Called when the user signals the desire to start a search.
This is called whenever the current window attributes change.
This hook is called whenever the window focus changes. See
View.onWindowFocusChanged(boolean)
for more information.
hasFocus | Whether the window now has focus. |
---|
Called when an action mode is being started for this window. Gives the callback an opportunity to handle the action mode in its own unique and beautiful way. If this method returns null the system can choose a way to present the mode or choose not to start the mode at all.
callback | Callback to control the lifecycle of this action mode |
---|
Sets a view to be the content view for this Dream.
Behaves similarly to setContentView(android.view.View)
in an activity,
including using MATCH_PARENT
as the layout height and width of the view.
Note: This requires a window, so you should usually call it during
onAttachedToWindow()
and never earlier (you cannot call it
during onCreate()
).
Inflates a layout resource and set it to be the content view for this Dream.
Behaves similarly to setContentView(int)
.
Note: Requires a window, do not call before onAttachedToWindow()
layoutResID | Resource ID to be inflated. |
---|
Sets a view to be the content view for this Dream.
Behaves similarly to
setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
in an activity.
Note: This requires a window, so you should usually call it during
onAttachedToWindow()
and never earlier (you cannot call it
during onCreate()
).
view | The desired content to display. |
---|---|
params | Layout parameters for the view. |
Controls FLAG_FULLSCREEN
on the dream's window.
fullscreen | If true, the fullscreen flag will be set; else it will be cleared. |
---|
Marks this dream as interactive to receive input events.
Non-interactive dreams (default) will dismiss on the first input event.
Interactive dreams should call finish()
to dismiss themselves.
interactive | True if this dream will handle input events. |
---|
Marks this dream as keeping the screen bright while dreaming.
screenBright | True to keep the screen bright while dreaming. |
---|
Print the Service's state into the given stream. This gets invoked if
you run "adb shell dumpsys activity service <yourservicename>"
(note that for this command to work, the service must be running, and
you must specify a fully-qualified service name).
This is distinct from "dumpsys <servicename>", which only works for
named system services and which invokes the dump(FileDescriptor, String[])
method
on the IBinder
interface registered with ServiceManager.
fd | The raw file descriptor that the dump is being sent to. |
---|---|
pw | The PrintWriter to which you should dump your state. This will be closed for you after you return. |
args | additional arguments to the dump request. |