Register now for Android Dev Summit 2019!

AmbientModeSupport

class AmbientModeSupport : Fragment
kotlin.Any
   ↳ androidx.fragment.app.Fragment
   ↳ androidx.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 android.Manifest.permission#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 AmbientCallback. The FragmentActivity will also receive a 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 AmbientController can be found below:

<code>AmbientMode.AmbientController controller = AmbientMode.attachAmbientSupport(this);
      boolean isAmbient =  controller.isAmbient();
  </code>

Summary

Nested classes

abstract

Callback to receive ambient mode state changes.

abstract

Interface for any Activity that wishes to implement Ambient Mode.

A class for interacting with the ambient mode on a wearable device.

Constants

static String!

Property in bundle passed to AmbientCallback#onEnterAmbient(Bundle) to indicate whether burn-in protection is required.

static String!

Property in bundle passed to AmbientCallback#onEnterAmbient(Bundle) to indicate whether the device has low-bit ambient mode.

static String

Fragment tag used by default when adding AmbientModeSupport to add ambient support to a FragmentActivity.

Public constructors

Constructor

Public methods

static AmbientModeSupport.AmbientController!
attach(activity: T)

Attach ambient support to the given activity.

Unit
dump(prefix: String, fd: FileDescriptor?, writer: PrintWriter, args: Array<String!>?)

Unit
onAttach(context: Context)

Unit
onCreate(savedInstanceState: Bundle?)

Unit

Unit

Unit

Unit

Unit

Inherited functions

Constants

EXTRA_BURN_IN_PROTECTION

static val EXTRA_BURN_IN_PROTECTION: String!

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.

Value: WearableActivityController.EXTRA_BURN_IN_PROTECTION

EXTRA_LOWBIT_AMBIENT

static val EXTRA_LOWBIT_AMBIENT: String!

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.

Value: WearableActivityController.EXTRA_LOWBIT_AMBIENT

FRAGMENT_TAG

static val FRAGMENT_TAG: String

Fragment tag used by default when adding AmbientModeSupport to add ambient support to a FragmentActivity.

Value: "android.support.wearable.ambient.AmbientMode"

Public constructors

<init>

AmbientModeSupport()

Constructor

Public methods

attach

static fun <T : FragmentActivity!> attach(activity: T): AmbientModeSupport.AmbientController!

Attach ambient support to the given activity. Calling this method with an Activity implementing the 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 AmbientCallbackProvider interface and that will only enable the auto-resume functionality. This is equivalent to providing (@code null} from the AmbientCallbackProvider.

Parameters
activity T: the activity to attach ambient support to.
Return
AmbientModeSupport.AmbientController!: the associated AmbientController which can be used to query the state of ambient mode.

dump

fun dump(prefix: String, fd: FileDescriptor?, writer: PrintWriter, args: Array<String!>?): Unit

onAttach

@CallSuper fun onAttach(context: Context): Unit

onCreate

@CallSuper fun onCreate(savedInstanceState: Bundle?): Unit

onDestroy

@CallSuper fun onDestroy(): Unit

onDetach

@CallSuper fun onDetach(): Unit

onPause

@CallSuper fun onPause(): Unit

onResume

@CallSuper fun onResume(): Unit

onStop

@CallSuper fun onStop(): Unit