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 android.Manifest.permission#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 AmbientCallbackProvider#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 AmbientCallbackProvider#getAmbientCallback()
), then ambient mode will NOT be enabled.
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 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 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
|
Inherited functions |
From class Fragment
Boolean |
equals(@Nullable other: Any?)
Subclasses can not override equals().
|
FragmentActivity? |
getActivity()
Return the FragmentActivity this fragment is currently associated with. May return null if the fragment is associated with a Context instead.
|
Boolean |
getAllowEnterTransitionOverlap()
Returns whether the the exit transition and enter transition overlap or not. When true, the enter transition will start as soon as possible. When false, the enter transition will wait until the exit transition completes before starting.
|
Boolean |
getAllowReturnTransitionOverlap()
Returns whether the the return transition and reenter transition overlap or not. When true, the reenter transition will start as soon as possible. When false, the reenter transition will wait until the return transition completes before starting.
|
Bundle? |
getArguments()
Return the arguments supplied when the fragment was instantiated, if any.
|
FragmentManager |
getChildFragmentManager()
Return a private FragmentManager for placing and managing Fragments inside of this Fragment.
|
Context? |
getContext()
Return the Context this fragment is currently associated with.
|
ViewModelProvider.Factory |
getDefaultViewModelProviderFactory()
Returns the default ViewModelProvider.Factory that should be used when no custom Factory is provided to the ViewModelProvider constructors.
The Fragment's arguments when this is first called will be used as the defaults to any androidx.lifecycle.SavedStateHandle passed to a view model created using this factory.
|
Any? |
getEnterTransition()
Returns the Transition that will be used to move Views into the initial scene. The entering Views will be those that are regular Views or ViewGroups that have ViewGroup#isTransitionGroup return true. Typical Transitions will extend android.transition.Visibility as entering is governed by changing visibility from View#INVISIBLE to View#VISIBLE .
|
Any? |
getExitTransition()
Returns the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack. The exiting Views will be those that are regular Views or ViewGroups that have ViewGroup#isTransitionGroup return true. Typical Transitions will extend android.transition.Visibility as exiting is governed by changing visibility from View#VISIBLE to View#INVISIBLE . If transition is null, the views will remain unaffected.
|
FragmentManager? |
getFragmentManager()
Return the FragmentManager for interacting with fragments associated with this fragment's activity. Note that this will be non-null slightly before getActivity() , during the time from when the fragment is placed in a FragmentTransaction until it is committed and attached to its activity.
If this Fragment is a child of another Fragment, the FragmentManager returned here will be the parent's getChildFragmentManager() .
|
Any? |
getHost()
Return the host object of this fragment. May return null if the fragment isn't currently being hosted.
|
Int |
getId()
Return the identifier this fragment is known by. This is either the android:id value supplied in a layout or the container view ID supplied when adding the fragment.
|
LayoutInflater |
getLayoutInflater()
Returns the cached LayoutInflater used to inflate Views of this Fragment. If onGetLayoutInflater(Bundle) has not been called onGetLayoutInflater(Bundle) will be called with a null argument and that value will be cached.
The cached LayoutInflater will be replaced immediately prior to onCreateView(LayoutInflater, ViewGroup, Bundle) and cleared immediately after onDetach() .
|
Lifecycle |
getLifecycle()
Returns the Lifecycle of the provider.
Overriding this method is no longer supported and this method will be made final in a future version of Fragment.
|
LoaderManager |
getLoaderManager()
Return the LoaderManager for this fragment.
|
Fragment? |
getParentFragment()
Returns the parent Fragment containing this Fragment. If this Fragment is attached directly to an Activity, returns null.
|
FragmentManager |
getParentFragmentManager()
Return the FragmentManager for interacting with fragments associated with this fragment's activity. Note that this will be available slightly before getActivity() , during the time from when the fragment is placed in a FragmentTransaction until it is committed and attached to its activity.
If this Fragment is a child of another Fragment, the FragmentManager returned here will be the parent's getChildFragmentManager() .
|
Any? |
getReenterTransition()
Returns the Transition that will be used to move Views in to the scene when returning due to popping a back stack. The entering Views will be those that are regular Views or ViewGroups that have ViewGroup#isTransitionGroup return true. Typical Transitions will extend android.transition.Visibility as exiting is governed by changing visibility from View#VISIBLE to View#INVISIBLE . If nothing is set, the default will be to use the same transition as getExitTransition() .
|
Resources |
getResources()
Return requireActivity().getResources() .
|
Boolean |
getRetainInstance()
Returns true if this fragment instance's state will be retained across configuration changes, and false if it will not.
|
Any? |
getReturnTransition()
Returns the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack. The exiting Views will be those that are regular Views or ViewGroups that have ViewGroup#isTransitionGroup return true. Typical Transitions will extend android.transition.Visibility as entering is governed by changing visibility from View#VISIBLE to View#INVISIBLE . If nothing is set, the default will be to use the same transition as getEnterTransition() .
|
SavedStateRegistry |
getSavedStateRegistry()
|
Any? |
getSharedElementEnterTransition()
Returns the Transition that will be used for shared elements transferred into the content Scene. Typical Transitions will affect size and location, such as android.transition.ChangeBounds . A null value will cause transferred shared elements to blink to the final position.
|
Any? |
getSharedElementReturnTransition()
Return the Transition that will be used for shared elem | |