AmbientModeSupport
class AmbientModeSupport : Fragment
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 following describes the general use of this class:
Create a subclass of one of the FragmentActivity classes and implement the AmbientCallbackProvider interface. Override the getAmbientCallback method to provide the callbacks required for reacting to the ambient events from the Android system. If a valid AmbientCallback is not provided (either no implementation of the AmbientCallbackProvider interface, or returning null from getAmbientCallback), then ambient mode will NOT be enabled.
The primary entry point for this code is the attach 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 implement the AmbientCallbackProvider interface, attach AmbientModeSupport to your FragmentActivity and use the AmbientController can be found below:
public class MyActivity extends FragmentActivity implements AmbientModeSupport.AmbientCallbackProvider { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState) ... AmbientModeSupport.AmbientController controller = AmbientModeSupport.attach(this); boolean isAmbient = controller.isAmbient(); } @Override AmbientModeSupport.AmbientCallback getAmbientCallback() { return new AmbientModeSupport.AmbientCallback() { public void onEnterAmbient(Bundle ambientDetails) {...} public void onExitAmbient(Bundle ambientDetails) {...} } } }
Summary
Nested types |
|---|
abstract class AmbientModeSupport.AmbientCallbackCallback to receive ambient mode state changes. |
|
Interface for any |
inner class AmbientModeSupport.AmbientControllerA class for interacting with the ambient mode on a wearable device. |
Constants |
|
|---|---|
const String! |
EXTRA_BURN_IN_PROTECTION = "com.google.android.wearable.compat.extra.BURN_IN_PROTECTION"Property in bundle passed to |
const String! |
EXTRA_LOWBIT_AMBIENT = "com.google.android.wearable.compat.extra.LOWBIT_AMBIENT"Property in bundle passed to |
const String! |
FRAGMENT_TAG = "android.support.wearable.ambient.AmbientMode"Fragment tag used by default when adding |
Public constructors |
|---|
|
Constructor |
Public functions |
|
|---|---|
java-static AmbientModeSupport.AmbientController! |
<T : FragmentActivity?> Attach ambient support to the given activity. |
Unit |
Print the Fragments's state into the given stream. |
Unit |
Called when a fragment is first attached to its context. |
Unit |
Called to do initial creation of a fragment. |
Unit |
Called when the fragment is no longer in use. |
Unit |
Called when the fragment is no longer attached to its activity. |
Unit |
Called when the Fragment is no longer resumed. |
Unit |
Called when the fragment is visible to the user and actively running. |
Unit |
Called when the Fragment is no longer started. |
Inherited functions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
const val EXTRA_BURN_IN_PROTECTION = "com.google.android.wearable.compat.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.
const val EXTRA_LOWBIT_AMBIENT = "com.google.android.wearable.compat.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.
const val FRAGMENT_TAG = "android.support.wearable.ambient.AmbientMode": String!
Fragment tag used by default when adding AmbientModeSupport to add ambient support to a FragmentActivity.
Public constructors
Public functions
java-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. |
| Returns | |
|---|---|
AmbientModeSupport.AmbientController! |
the associated |
dump
fundump(
prefix: String!,
fd: FileDescriptor!,
writer: PrintWriter!,
args: Array<String!>!
): Unit
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: Array<String!>! |
additional arguments to the dump request. |
onAttach
@CallSuper
funonAttach(context: Context!): Unit
Called when a fragment is first attached to its context. onCreate will be called after this.
onCreate
@CallSuper
funonCreate(savedInstanceState: Bundle!): Unit
Called to do initial creation of a fragment. This is called after onAttach and before onCreateView.
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, add a androidx.lifecycle.LifecycleObserver on the activity's Lifecycle, removing it when it receives the CREATED callback.
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
@CallSuper
funonDestroy(): Unit
Called when the fragment is no longer in use. This is called after onStop and before onDetach.
onDetach
@CallSuper
funonDetach(): Unit
Called when the fragment is no longer attached to its activity. This is called after onDestroy.
onPause
@CallSuper
funonPause(): Unit
Called when the Fragment is no longer resumed. This is generally tied to Activity.onPause of the containing Activity's lifecycle.
onResume
@CallSuper
funonResume(): Unit
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
@CallSuper
funonStop(): Unit
Called when the Fragment is no longer started. This is generally tied to Activity.onStop of the containing Activity's lifecycle.