IT. Expert System.

Android Reference

DreamService


android.service.dreams

Class DreamService

  • All Implemented Interfaces:
    ComponentCallbacks, ComponentCallbacks2, Window.Callback


    public class DreamService
    extends Service
    implements Window.Callback
    Extend this class to implement a custom Dream (displayed to the user as a "Sleep Mode").

    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 Dream lifecycle is as follows:

    1. onAttachedToWindow()

      Use this for initial setup, such as calling setContentView().

    2. onDreamingStarted()

      Your dream has started, so you should begin animations or other behaviors here.

    3. onDreamingStopped()

      Use this to stop the things you started in onDreamingStarted().

    4. onDetachedFromWindow()

      Use this to dismantle resources your dream set up. 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, Dreams 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 &lt;meta-data&gt; 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:

    res/xml/my_dream.xml

     <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(int), 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);
         }
     }
     
    • Field Detail

      • DREAM_META_DATA

        public static final String DREAM_META_DATA
        Name under which a Dream publishes information about itself. This meta-data must reference an XML resource containing a <dream> tag.
        See Also:
        Constant Field Values
    • Constructor Detail

      • DreamService

        public DreamService()
    • Method Detail

      • setDebug

        public void setDebug(boolean dbg)
      • onCreatePanelMenu

        public boolean onCreatePanelMenu(int featureId,
                                Menu menu)
        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.

        Specified by:
        onCreatePanelMenu in interface Window.Callback
        Parameters:
        featureId - The panel being created.
        menu - The menu inside the panel.
        Returns:
        boolean You must return true for the panel to be displayed; if you return false it will not be shown.
      • onPreparePanel

        public boolean onPreparePanel(int featureId,
                             View view,
                             Menu menu)
        Prepare a panel to be displayed. This is called right before the panel window is shown, every time it is shown.
        Specified by:
        onPreparePanel in interface Window.Callback
        Parameters:
        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.
        Returns:
        boolean You must return true for the panel to be displayed; if you return false it will not be shown.
        See Also:
        Window.Callback.onCreatePanelView(int)
      • onMenuOpened

        public boolean onMenuOpened(int featureId,
                           Menu menu)
        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).
        Specified by:
        onMenuOpened in interface Window.Callback
        Parameters:
        featureId - The panel that the menu is in.
        menu - The menu that is opened.
        Returns:
        Return true to allow the menu to open, or false to prevent the menu from opening.
      • onMenuItemSelected

        public boolean onMenuItemSelected(int featureId,
                                 MenuItem item)
        Called when a panel's menu item has been selected by the user.
        Specified by:
        onMenuItemSelected in interface Window.Callback
        Parameters:
        featureId - The panel that the menu is in.
        item - The menu item that was selected.
        Returns:
        boolean Return true to finish processing of selection, or false to perform the normal menu handling (calling its Runnable or sending a Message to its target Handler).
      • onPanelClosed

        public void onPanelClosed(int featureId,
                         Menu menu)
        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.
        Specified by:
        onPanelClosed in interface Window.Callback
        Parameters:
        featureId - The panel that is being displayed.
        menu - If onCreatePanelView() returned null, this is the Menu being displayed in the panel.
      • onWindowStartingActionMode

        public ActionMode onWindowStartingActionMode(ActionMode.Callback callback)
        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.
        Specified by:
        onWindowStartingActionMode in interface Window.Callback
        Parameters:
        callback - Callback to control the lifecycle of this action mode
        Returns:
        The ActionMode that was started, or null if the system should present it
      • onActionModeStarted

        public void onActionModeStarted(ActionMode mode)
        Called when an action mode has been started. The appropriate mode callback method will have already been invoked.
        Specified by:
        onActionModeStarted in interface Window.Callback
        Parameters:
        mode - The new mode that has just been started.
      • onActionModeFinished

        public void onActionModeFinished(ActionMode mode)
        Called when an action mode has been finished. The appropriate mode callback method will have already been invoked.
        Specified by:
        onActionModeFinished in interface Window.Callback
        Parameters:
        mode - The mode that was just finished.
      • getWindow

        public Window getWindow()
        Retrieves the current Window for the dream. Behaves similarly to Activity.getWindow().
        Returns:
        The current window, or null if the dream is not started.
      • addContentView

        public void addContentView(View view,
                          ViewGroup.LayoutParams params)
        Adds a view to the Dream's window, leaving other content views in place.

        Note: Requires a window, do not call before onAttachedToWindow()

        Parameters:
        view - The desired content to display.
        params - Layout parameters for the view.
      • findViewById

        public View findViewById(int id)
        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()

        Returns:
        The view if found or null otherwise.
      • setInteractive

        public void setInteractive(boolean interactive)
        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.

        Parameters:
        interactive - True if this dream will handle input events.
      • isInteractive

        public boolean isInteractive()
        Returns whether or not this dream is interactive. Defaults to false.
        See Also:
        setInteractive(boolean)
      • setLowProfile

        public void setLowProfile(boolean lowProfile)
        Sets View.SYSTEM_UI_FLAG_LOW_PROFILE on the content view.
        Parameters:
        lowProfile - True to set View.SYSTEM_UI_FLAG_LOW_PROFILE
      • isLowProfile

        public boolean isLowProfile()
        Returns whether or not this dream is in low profile mode. Defaults to true.
        See Also:
        setLowProfile(boolean)
      • setFullscreen

        public void setFullscreen(boolean fullscreen)
        Controls WindowManager.LayoutParams.FLAG_FULLSCREEN on the dream's window.
        Parameters:
        fullscreen - If true, the fullscreen flag will be set; else it will be cleared.
      • isFullscreen

        public boolean isFullscreen()
        Returns whether or not this dream is in fullscreen mode. Defaults to false.
        See Also:
        setFullscreen(boolean)
      • setScreenBright

        public void setScreenBright(boolean screenBright)
        Marks this dream as keeping the screen bright while dreaming.
        Parameters:
        screenBright - True to keep the screen bright while dreaming.
      • isScreenBright

        public boolean isScreenBright()
        Returns whether or not this dream keeps the screen bright while dreaming. Defaults to false, allowing the screen to dim if necessary.
        See Also:
        setScreenBright(boolean)
      • onCreate

        public void onCreate()
        Called when this Dream is constructed.
        Overrides:
        onCreate in class Service
      • onDreamingStarted

        public void onDreamingStarted()
        Called when the dream's window has been created and is visible and animation may now begin.
      • onDreamingStopped

        public void onDreamingStopped()
        Called when this Dream is stopped, either by external request or by calling finish(), before the window has been removed.
      • onBind

        public final IBinder onBind(Intent intent)
        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.

        Specified by:
        onBind in class Service
        Parameters:
        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.
        Returns:
        Return an IBinder through which clients can call on to the service.
      • finish

        public final void finish()
        Stops the dream, detaches from the window, and wakes up.
      • onDestroy

        public void onDestroy()
        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.
        Overrides:
        onDestroy in class Service
      • dump

        protected void dump(FileDescriptor fd,
                PrintWriter pw,
                String[] args)
        Description copied from class: Service
        Print the Service's state into the given stream. This gets invoked if you run "adb shell dumpsys activity service <yourservicename>". This is distinct from "dumpsys <servicename>", which only works for named system services and which invokes the IBinder.dump(java.io.FileDescriptor, java.lang.String[]) method on the IBinder interface registered with ServiceManager.
        Overrides:
        dump in class Service
        Parameters:
        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.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 474 / 248538573. Delta: 0.05243 с