AmbientMode

public final class AmbientMode


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 attachAmbientSupport method. It should be called with an Activity as an argument and that Activity will then be able to receive ambient lifecycle events through an AmbientCallback. The Activity 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 AmbientMode to your Activity and use the AmbientController can be found below:

{@code * AmbientMode.AmbientController controller = AmbientMode.attachAmbientSupport(this); * boolean isAmbient = controller.isAmbient(); * }

Summary

Nested types

AmbientMode.AmbientCallback

Callback to receive ambient mode state changes.

AmbientMode.AmbientCallbackProvider

Interface for any Activity that wishes to implement Ambient Mode.

AmbientMode.AmbientController

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

Constants

static final @NonNull String

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

static final @NonNull String

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

static final @NonNull String

Fragment tag used by default when adding AmbientMode to add ambient support to an Activity.

Public constructors

Constructor

Public methods

static @NonNull AmbientMode.AmbientController
<T extends Activity> attachAmbientSupport(@NonNull T activity)

Attach ambient support to the given activity.

@Override @NonNull void
dump(
    @NonNull String prefix,
    @NonNull FileDescriptor fd,
    @NonNull PrintWriter writer,
    @NonNull Array<@NonNull String> args
)

This method is deprecated.

@Override @CallSuper @NonNull void

This method is deprecated.

@Override @CallSuper @NonNull void
onCreate(@NonNull Bundle savedInstanceState)

This method is deprecated.

@Override @CallSuper @NonNull void

This method is deprecated.

@Override @CallSuper @NonNull void

This method is deprecated.

@Override @CallSuper @NonNull void

This method is deprecated.

@Override @CallSuper @NonNull void

This method is deprecated.

@Override @CallSuper @NonNull void

This method is deprecated.

Inherited methods

From class Fragment
final @NonNull boolean

This method is deprecated.

final @NonNull Activity

This method is deprecated.

@NonNull boolean

This method is deprecated.

@NonNull boolean

This method is deprecated.

final @NonNull Bundle

This method is deprecated.

final @NonNull FragmentManager

This method is deprecated.

@NonNull Context

This method is deprecated.

@NonNull Transition

This method is deprecated.

@NonNull Transition

This method is deprecated.

final @NonNull FragmentManager

This method is deprecated.

final @NonNull Object

This method is deprecated.

final @NonNull int

This method is deprecated.

final @NonNull LayoutInflater

This method is deprecated.

@NonNull LoaderManager

This method is deprecated.

final @NonNull Fragment

This method is deprecated.

@NonNull Transition

This method is deprecated.

final @NonNull Resources

This method is deprecated.

final @NonNull boolean

This method is deprecated.

@NonNull Transition

This method is deprecated.

@NonNull Transition

This method is deprecated.

@NonNull Transition

This method is deprecated.

final @NonNull String
getString(@NonNull int resId)

This method is deprecated.

final @NonNull String

This method is deprecated.

final @NonNull Fragment

This method is deprecated.

final @NonNull int

This method is deprecated.

final @NonNull CharSequence
getText(@NonNull int resId)

This method is deprecated.

@NonNull boolean

This method is deprecated.

@NonNull View

This method is deprecated.

final @NonNull int

This method is deprecated.

static @NonNull Fragment

This method is deprecated.

final @NonNull boolean

This method is deprecated.

final @NonNull boolean

This method is deprecated.

final @NonNull boolean

This method is deprecated.

final @NonNull boolean

This method is deprecated.

final @NonNull boolean

This method is deprecated.

final @NonNull boolean

This method is deprecated.

final @NonNull boolean

This method is deprecated.

final @NonNull boolean

This method is deprecated.

@NonNull void
onActivityCreated(@NonNull Bundle savedInstanceState)

This method is deprecated.

@NonNull void
onActivityResult(
    @NonNull int requestCode,
    @NonNull int resultCode,
    @NonNull Intent data
)

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull boolean

This method is deprecated.

@NonNull Animator
onCreateAnimator(
    @NonNull int transit,
    @NonNull boolean enter,
    @NonNull int nextAnim
)

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull View
onCreateView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup container,
    @NonNull Bundle savedInstanceState
)

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull LayoutInflater
onGetLayoutInflater(@NonNull Bundle savedInstanceState)

This method is deprecated.

@NonNull void
onHiddenChanged(@NonNull boolean hidden)

This method is deprecated.

@NonNull void
onInflate(@NonNull AttributeSet attrs, @NonNull Bundle savedInstanceState)

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void
onMultiWindowModeChanged(
    @NonNull boolean isInMultiWindowMode,
    @NonNull Configuration newConfig
)

This method is deprecated.

@NonNull boolean

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void
onPictureInPictureModeChanged(
    @NonNull boolean isInPictureInPictureMode,
    @NonNull Configuration newConfig
)

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void
onRequestPermissionsResult(
    @NonNull int requestCode,
    @NonNull Array<@NonNull String> permissions,
    @NonNull Array<@NonNull int> grantResults
)

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void
onTrimMemory(@NonNull int level)

This method is deprecated.

@NonNull void
onViewCreated(@NonNull View view, @NonNull Bundle savedInstanceState)

This method is deprecated.

@NonNull void
onViewStateRestored(@NonNull Bundle savedInstanceState)

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void

This method is deprecated.

final @NonNull void
requestPermissions(
    @NonNull Array<@NonNull String> permissions,
    @NonNull int requestCode
)

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void
setHasOptionsMenu(@NonNull boolean hasMenu)

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void
setMenuVisibility(@NonNull boolean menuVisible)

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void
setRetainInstance(@NonNull boolean retain)

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void
setTargetFragment(@NonNull Fragment fragment, @NonNull int requestCode)

This method is deprecated.

@NonNull void
setUserVisibleHint(@NonNull boolean isVisibleToUser)

This method is deprecated.

@NonNull boolean

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull void
startActivityForResult(@NonNull Intent intent, @NonNull int requestCode)

This method is deprecated.

@NonNull void
startIntentSenderForResult(
    @NonNull IntentSender intent,
    @NonNull int requestCode,
    @NonNull Intent fillInIntent,
    @NonNull int flagsMask,
    @NonNull int flagsValues,
    @NonNull int extraFlags,
    @NonNull Bundle options
)

This method is deprecated.

@NonNull void

This method is deprecated.

@NonNull String

This method is deprecated.

@NonNull void

This method is deprecated.

Constants

EXTRA_BURN_IN_PROTECTION

@NonNull
public static final @NonNull String EXTRA_BURN_IN_PROTECTION

Property in bundle passed to {@code 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.

EXTRA_LOWBIT_AMBIENT

@NonNull
public static final @NonNull String EXTRA_LOWBIT_AMBIENT

Property in bundle passed to {@code 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.

FRAGMENT_TAG

@NonNull
public static final @NonNull String FRAGMENT_TAG

Fragment tag used by default when adding AmbientMode to add ambient support to an Activity.

Public constructors

AmbientMode

public AmbientMode()

Constructor

Public methods

attachAmbientSupport

@NonNull
public static AmbientMode.AmbientController <T extends Activity> attachAmbientSupport(@NonNull T activity)

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 {@code 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
@NonNull T activity

the activity to attach ambient support to.

Returns
AmbientMode.AmbientController

the associated AmbientController which can be used to query the state of ambient mode.

dump

@Override
@NonNull
public @Override void dump(
    @NonNull String prefix,
    @NonNull FileDescriptor fd,
    @NonNull PrintWriter writer,
    @NonNull Array<@NonNull String> args
)

onAttach

@Override
@CallSuper
@NonNull
public @Override @CallSuper void onAttach(@NonNull Context context)

onCreate

@Override
@CallSuper
@NonNull
public @Override @CallSuper void onCreate(@NonNull Bundle savedInstanceState)

onDestroy

@Override
@CallSuper
@NonNull
public @Override @CallSuper void onDestroy()

onDetach

@Override
@CallSuper
@NonNull
public @Override @CallSuper void onDetach()

onPause

@Override
@CallSuper
@NonNull
public @Override @CallSuper void onPause()

onResume

@Override
@CallSuper
@NonNull
public @Override @CallSuper void onResume()

onStop

@Override
@CallSuper
@NonNull
public @Override @CallSuper void onStop()