belongs to Maven artifact com.android.support:wear:28.0.0-alpha1
AmbientModeSupport
  public
  
  final
  
  class
  AmbientModeSupport
  
  
  
  
    extends Fragment
  
  
  
  
  
  
| java.lang.Object | ||
| ↳ | android.support.v4.app.Fragment | |
| ↳ | android.support.wear.ambient.AmbientModeSupport | |
Use this as a headless Fragment to add ambient support to an Activity on Wearable devices.
 The application that uses this should add the WAKE_LOCK
 permission to its manifest.
 
 The primary entry  point for this code is the attach(FragmentActivity) method.
 It should be called with an FragmentActivity as an argument and that
 FragmentActivity will then be able to receive ambient lifecycle events through
 an AmbientModeSupport.AmbientCallback. The FragmentActivity will also receive a
 AmbientModeSupport.AmbientController object from the attachment which can be used to query the current
 status of the ambient mode. An example of how to attach AmbientModeSupport to your
 FragmentActivity and use the AmbientModeSupport.AmbientController can be found below:
 
AmbientMode.AmbientController controller = AmbientMode.attachAmbientSupport(this);
     boolean isAmbient =  controller.isAmbient();
 Summary
| Nested classes | |
|---|---|
| 
        
        
        
        
        class | AmbientModeSupport.AmbientCallbackCallback to receive ambient mode state changes. | 
| 
        
        
        
        
        interface | AmbientModeSupport.AmbientCallbackProviderInterface for any  | 
| 
        
        
        
        
        class | AmbientModeSupport.AmbientControllerA class for interacting with the ambient mode on a wearable device. | 
| Constants | |
|---|---|
| String | EXTRA_BURN_IN_PROTECTIONProperty in bundle passed to  | 
| String | EXTRA_LOWBIT_AMBIENTProperty in bundle passed to  | 
| String | FRAGMENT_TAGFragment tag used by default when adding  | 
| Public constructors | |
|---|---|
| 
      AmbientModeSupport()
      Constructor | |
| Public methods | |
|---|---|
| 
        
        
        static
        
        <T extends FragmentActivity>
        AmbientModeSupport.AmbientController | 
      attach(T activity)
      Attach ambient support to the given activity. | 
| 
        
        
        
        
        
        void | 
      dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)
      Print the Fragments's state into the given stream. | 
| 
        
        
        
        
        
        void | 
      onAttach(Context context)
      Called when a fragment is first attached to its context. | 
| 
        
        
        
        
        
        void | 
      onCreate(Bundle savedInstanceState)
      Called to do initial creation of a fragment. | 
| 
        
        
        
        
        
        void | 
      onDestroy()
      Called when the fragment is no longer in use. | 
| 
        
        
        
        
        
        void | 
      onDetach()
      Called when the fragment is no longer attached to its activity. | 
| 
        
        
        
        
        
        void | 
      onPause()
      Called when the Fragment is no longer resumed. | 
| 
        
        
        
        
        
        void | 
      onResume()
      Called when the fragment is visible to the user and actively running. | 
| 
        
        
        
        
        
        void | 
      onStop()
      Called when the Fragment is no longer started. | 
| Inherited methods | |
|---|---|
|  From
class 
  
    android.support.v4.app.Fragment
  
 | |
|  From
class 
  
    java.lang.Object
  
 | |
|  From
interface 
  
    android.content.ComponentCallbacks
  
 | |
|  From
interface 
  
    android.view.View.OnCreateContextMenuListener
  
 | |
|  From
interface 
  
    android.arch.lifecycle.LifecycleOwner
  
 | |
|  From
interface 
  
    android.arch.lifecycle.ViewModelStoreOwner
  
 | |
Constants
EXTRA_BURN_IN_PROTECTION
String EXTRA_BURN_IN_PROTECTION
Property in bundle passed to AmbientCallback#onEnterAmbient(Bundle) to indicate
 whether burn-in protection is required. When this property is set to true, views must be
 shifted around periodically in ambient mode. To ensure that content isn't shifted off
 the screen, avoid placing content within 10 pixels of the edge of the screen. Activities
 should also avoid solid white areas to prevent pixel burn-in. Both of these requirements
 only apply in ambient mode, and only when this property is set to true.
Constant Value: "com.google.android.wearable.compat.extra.BURN_IN_PROTECTION"
EXTRA_LOWBIT_AMBIENT
String EXTRA_LOWBIT_AMBIENT
Property in bundle passed to AmbientCallback#onEnterAmbient(Bundle) to indicate
 whether the device has low-bit ambient mode. When this property is set to true, the screen
 supports fewer bits for each color in ambient mode. In this case, activities should disable
 anti-aliasing in ambient mode.
Constant Value: "com.google.android.wearable.compat.extra.LOWBIT_AMBIENT"
FRAGMENT_TAG
String FRAGMENT_TAG
Fragment tag used by default when adding AmbientModeSupport to add ambient support to
 a FragmentActivity.
Constant Value: "android.support.wearable.ambient.AmbientMode"
Public constructors
Public methods
attach
AmbientModeSupport.AmbientController attach (T activity)
Attach ambient support to the given activity. Calling this method with an Activity
 implementing the AmbientModeSupport.AmbientCallbackProvider interface will provide you with an
 opportunity to react to ambient events such as onEnterAmbient. Alternatively,
 you can call this method with an Activity which does not implement
 the AmbientModeSupport.AmbientCallbackProvider interface and that will only enable the auto-resume
 functionality. This is equivalent to providing (@code null} from
 the AmbientModeSupport.AmbientCallbackProvider.
| Parameters | |
|---|---|
| activity | T: the activity to attach ambient support to. | 
| Returns | |
|---|---|
| AmbientModeSupport.AmbientController | the associated AmbientModeSupport.AmbientControllerwhich can be used to query the state of
 ambient mode. | 
dump
void dump (String prefix, 
                FileDescriptor fd, 
                PrintWriter writer, 
                String[] args)Print the Fragments's state into the given stream.
| Parameters | |
|---|---|
| prefix | String: Text to print at the front of each line. | 
| fd | FileDescriptor: The raw file descriptor that the dump is being sent to. | 
| writer | PrintWriter: The PrintWriter to which you should dump your state.  This will be
 closed for you after you return. | 
| args | String: additional arguments to the dump request. | 
onAttach
void onAttach (Context context)
Called when a fragment is first attached to its context.
 onCreate(Bundle) will be called after this.
| Parameters | |
|---|---|
| context | Context | 
onCreate
void onCreate (Bundle savedInstanceState)
Called to do initial creation of a fragment.  This is called after
 onAttach(Activity) and before
 onCreateView(LayoutInflater, ViewGroup, Bundle).
 
Note that this can be called while the fragment's activity is
 still in the process of being created.  As such, you can not rely
 on things like the activity's content view hierarchy being initialized
 at this point.  If you want to do work once the activity itself is
 created, see onActivityCreated(Bundle).
 
Any restored child fragments will be created before the base
 Fragment.onCreate method returns.
| Parameters | |
|---|---|
| savedInstanceState | Bundle: If the fragment is being re-created from
 a previous saved state, this is the state. | 
onDestroy
void onDestroy ()
Called when the fragment is no longer in use.  This is called
 after onStop() and before onDetach().
onDetach
void onDetach ()
Called when the fragment is no longer attached to its activity.  This
 is called after onDestroy().
onPause
void onPause ()
Called when the Fragment is no longer resumed.  This is generally
 tied to Activity.onPause of the containing
 Activity's lifecycle.
onResume
void onResume ()
Called when the fragment is visible to the user and actively running.
 This is generally
 tied to Activity.onResume of the containing
 Activity's lifecycle.
onStop
void onStop ()
Called when the Fragment is no longer started.  This is generally
 tied to Activity.onStop of the containing
 Activity's lifecycle.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
