AmbientModeSupport

Added in 1.1.0
Deprecated in 1.3.0

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

This class is deprecated. Deprecated in Java

This interface is deprecated. Deprecated in Java

This class is deprecated. Deprecated in Java

Constants

const String!
EXTRA_BURN_IN_PROTECTION = "com.google.android.wearable.compat.extra.BURN_IN_PROTECTION"

This property is deprecated. Deprecated in Java

const String!
EXTRA_LOWBIT_AMBIENT = "com.google.android.wearable.compat.extra.LOWBIT_AMBIENT"

This property is deprecated. Deprecated in Java

const String!
FRAGMENT_TAG = "android.support.wearable.ambient.AmbientMode"

This property is deprecated. Deprecated in Java

Public constructors

This function is deprecated. Deprecated in Java

Public functions

java-static AmbientModeSupport.AmbientController!
<T : FragmentActivity?> attach(activity: T!)

This function is deprecated. Deprecated in Java

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

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit
@CallSuper
onCreate(savedInstanceState: Bundle!)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Inherited functions

From androidx.activity.result.ActivityResultCaller
abstract ActivityResultLauncher<I!>!
<I, O> registerForActivityResult(
    contract: ActivityResultContract<I!, O!>!,
    callback: ActivityResultCallback<O!>!
)

This function is deprecated. Deprecated in Java

From android.content.ComponentCallbacks
abstract Unit

This function is deprecated. Deprecated in Java

abstract Unit

This function is deprecated.

From androidx.activity.contextaware.ContextAware
abstract Unit

This function is deprecated. Deprecated in Java

abstract Context!

This function is deprecated. Deprecated in Java

abstract Unit

This function is deprecated. Deprecated in Java

From androidx.fragment.app.Fragment
Unit

This function is deprecated. Deprecated in Java

Boolean
equals(o: Any?)

This function is deprecated. Deprecated in Java

FragmentActivity?

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Bundle?

This function is deprecated. Deprecated in Java

FragmentManager

This function is deprecated. Deprecated in Java

Context?

This function is deprecated. Deprecated in Java

CreationExtras

This function is deprecated. Deprecated in Java

ViewModelProvider.Factory

This function is deprecated. Deprecated in Java

Any?

This function is deprecated. Deprecated in Java

Any?

This function is deprecated. Deprecated in Java

FragmentManager?

This function is deprecated.

This has been removed in favor of getParentFragmentManager() which throws an IllegalStateException if the FragmentManager is null.

Any?

This function is deprecated. Deprecated in Java

Int

This function is deprecated. Deprecated in Java

LayoutInflater

This function is deprecated. Deprecated in Java

Lifecycle

This function is deprecated. Deprecated in Java

LoaderManager

This function is deprecated.

Use LoaderManager.getInstance(this).

Fragment?

This function is deprecated. Deprecated in Java

FragmentManager

This function is deprecated. Deprecated in Java

Any?

This function is deprecated. Deprecated in Java

Resources

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated.

Instead of retaining the Fragment itself, use a non-retained Fragment and keep retained state in a ViewModel attached to that Fragment.

Any?

This function is deprecated. Deprecated in Java

SavedStateRegistry

This function is deprecated. Deprecated in Java

Any?

This function is deprecated. Deprecated in Java

Any?

This function is deprecated. Deprecated in Java

String

This function is deprecated. Deprecated in Java

String
getString(resId: @StringRes Int, formatArgs: Array<Any!>?)

This function is deprecated. Deprecated in Java

String?

This function is deprecated. Deprecated in Java

Fragment?

This function is deprecated.

Instead of using a target fragment to pass results, use setFragmentResult to deliver results to FragmentResultListener instances registered by other fragments via setFragmentResultListener.

Int

This function is deprecated.

When using the target fragment replacement of setFragmentResultListener and setFragmentResult, consider using setArguments to pass a requestKey if you need to support dynamic request keys.

CharSequence

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated.

Use setMaxLifecycle instead.

View?

This function is deprecated. Deprecated in Java

LifecycleOwner

This function is deprecated. Deprecated in Java

LiveData<LifecycleOwner!>

This function is deprecated. Deprecated in Java

ViewModelStore

This function is deprecated. Deprecated in Java

Int

This function is deprecated. Deprecated in Java

java-static Fragment
instantiate(context: Context, fname: String)

This function is deprecated.

Use getFragmentFactory and instantiate

java-static Fragment
instantiate(context: Context, fname: String, args: Bundle?)

This function is deprecated.

Use getFragmentFactory and instantiate, manually calling setArguments on the returned Fragment.

Boolean

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Unit

This function is deprecated.

use onViewCreated for code touching the view created by onCreateView and onCreate for other initialization.

Unit
onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)

This function is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

Unit

This function is deprecated.

See onAttach.

Unit

This function is deprecated.

The responsibility for listening for fragments being attached has been moved to FragmentManager.

Unit

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated. Deprecated in Java

Animation?
@MainThread
onCreateAnimation(transit: Int, enter: Boolean, nextAnim: Int)

This function is deprecated. Deprecated in Java

Animator?
@MainThread
onCreateAnimator(transit: Int, enter: Boolean, nextAnim: Int)

This function is deprecated. Deprecated in Java

Unit
@MainThread
onCreateContextMenu(
    menu: ContextMenu,
    v: View,
    menuInfo: ContextMenu.ContextMenuInfo?
)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

View?
@MainThread
onCreateView(
    inflater: LayoutInflater,
    container: ViewGroup?,
    savedInstanceState: Bundle?
)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

Unit

This function is deprecated. Deprecated in Java

LayoutInflater
onGetLayoutInflater(savedInstanceState: Bundle?)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit
@UiThread
@CallSuper
onInflate(
    activity: Activity,
    attrs: AttributeSet,
    savedInstanceState: Bundle?
)

This function is deprecated.

See onInflate.

Unit
@UiThread
@CallSuper
onInflate(
    context: Context,
    attrs: AttributeSet,
    savedInstanceState: Bundle?
)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated.

Unit
onMultiWindowModeChanged(isInMultiWindowMode: Boolean)

This function is deprecated. Deprecated in Java

Boolean

This function is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

Unit

This function is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

Unit
onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

Unit
@MainThread
onPrimaryNavigationFragmentChanged(
    isPrimaryNavigationFragment: Boolean
)

This function is deprecated. Deprecated in Java

Unit
onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<String!>,
    grantResults: IntArray<Int>
)

This function is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit
@MainThread
onViewCreated(view: View, savedInstanceState: Bundle?)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Context?

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit
postponeEnterTransition(duration: Long, timeUnit: TimeUnit)

This function is deprecated. Deprecated in Java

ActivityResultLauncher<I!>
@MainThread
<I, O> registerForActivityResult(
    contract: ActivityResultContract<I!, O!>,
    callback: ActivityResultCallback<O!>
)

This function is deprecated. Deprecated in Java

ActivityResultLauncher<I!>
@MainThread
<I, O> registerForActivityResult(
    contract: ActivityResultContract<I!, O!>,
    registry: ActivityResultRegistry,
    callback: ActivityResultCallback<O!>
)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit
requestPermissions(permissions: Array<String!>, requestCode: Int)

This function is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

FragmentActivity

This function is deprecated. Deprecated in Java

Bundle

This function is deprecated. Deprecated in Java

Context

This function is deprecated. Deprecated in Java

FragmentManager

This function is deprecated.

This has been renamed to getParentFragmentManager() to make it clear that you are accessing the FragmentManager that contains this Fragment and not the FragmentManager associated with child Fragments.

Any

This function is deprecated. Deprecated in Java

Fragment

This function is deprecated. Deprecated in Java

View

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit
setEnterTransition(transition: Any?)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit
setExitTransition(transition: Any?)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated.

This method is no longer needed when using a MenuProvider to provide a Menu to your activity, which replaces onCreateOptionsMenu as the recommended way to provide a consistent, optionally Lifecycle-aware, and modular way to handle menu creation and item selection.

Unit

This function is deprecated. Deprecated in Java

Unit
setMenuVisibility(menuVisible: Boolean)

This function is deprecated. Deprecated in Java

Unit
setReenterTransition(transition: Any?)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated.

Instead of retaining the Fragment itself, use a non-retained Fragment and keep retained state in a ViewModel attached to that Fragment.

Unit
setReturnTransition(transition: Any?)

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit
setTargetFragment(fragment: Fragment?, requestCode: Int)

This function is deprecated.

Instead of using a target fragment to pass results, the fragment requesting a result should use setFragmentResultListener to register a FragmentResultListener with a requestKey using its parent fragment manager.

Unit
setUserVisibleHint(isVisibleToUser: Boolean)

This function is deprecated.

If you are manually calling this method, use setMaxLifecycle instead.

Boolean

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

Unit
startActivity(intent: Intent, options: Bundle?)

This function is deprecated. Deprecated in Java

Unit
startActivityForResult(intent: Intent, requestCode: Int)

This function is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

Unit
startActivityForResult(intent: Intent, requestCode: Int, options: Bundle?)

This function is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

Unit
startIntentSenderForResult(
    intent: IntentSender,
    requestCode: Int,
    fillInIntent: Intent?,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int,
    options: Bundle?
)

This function is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

Unit

This function is deprecated. Deprecated in Java

String

This function is deprecated. Deprecated in Java

Unit

This function is deprecated. Deprecated in Java

From androidx.lifecycle.HasDefaultViewModelProviderFactory
CreationExtras!

This function is deprecated. Deprecated in Java

ViewModelProvider.Factory!

This function is deprecated. Deprecated in Java

From androidx.lifecycle.LifecycleOwner
abstract Lifecycle!

This function is deprecated. Deprecated in Java

From androidx.savedstate.SavedStateRegistryOwner
abstract SavedStateRegistry!

This function is deprecated. Deprecated in Java

From android.view.View.OnCreateContextMenuListener
abstract Unit
onCreateContextMenu(
    p: ContextMenu!,
    p1: View!,
    p2: ContextMenu.ContextMenuInfo!
)

This function is deprecated. Deprecated in Java

From androidx.lifecycle.ViewModelStoreOwner
abstract ViewModelStore!

This function is deprecated. Deprecated in Java

Constants

EXTRA_BURN_IN_PROTECTION

Added in 1.1.0
Deprecated in 1.3.0
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.

EXTRA_LOWBIT_AMBIENT

Added in 1.1.0
Deprecated in 1.3.0
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.

FRAGMENT_TAG

Added in 1.1.0
Deprecated in 1.3.0
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

AmbientModeSupport

Added in 1.1.0
Deprecated in 1.3.0
AmbientModeSupport()

Constructor

Public functions

attach

Added in 1.1.0
Deprecated in 1.3.0
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 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

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
fun onAttach(context: Context!): Unit

Called when a fragment is first attached to its context. onCreate will be called after this.

onCreate

@CallSuper
fun onCreate(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
fun onDestroy(): Unit

Called when the fragment is no longer in use. This is called after onStop and before onDetach.

onDetach

@CallSuper
fun onDetach(): Unit

Called when the fragment is no longer attached to its activity. This is called after onDestroy.

onPause

@CallSuper
fun onPause(): Unit

Called when the Fragment is no longer resumed. This is generally tied to Activity.onPause of the containing Activity's lifecycle.

onResume

@CallSuper
fun onResume(): 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
fun onStop(): Unit

Called when the Fragment is no longer started. This is generally tied to Activity.onStop of the containing Activity's lifecycle.