TiltGesture


public static class TiltGesture


Container for device tilt gesture detection logic and the Tilt state representation.

The primary way to use this is via the TiltGesture.detect method, which provides a Flow of Tilt states.

Summary

Nested types

public final class TiltGesture.State

Represents the tilt state of the device, transition progress.

Public fields

static @NonNull TiltGesture

Public methods

final @NonNull Flow<@NonNull TiltGesture.State>

Begins detecting the device's tilt state and returns a cold Flow of Tilt updates.

Public fields

INSTANCE

Added in 1.0.0-alpha10
public static @NonNull TiltGesture INSTANCE

Public methods

detect

Added in 1.0.0-alpha10
public final @NonNull Flow<@NonNull TiltGesture.Statedetect(@NonNull Session session)

Begins detecting the device's tilt state and returns a cold Flow of Tilt updates.

This function observes changes to the ArDevice.state obtained from the provided session. The device's tilt is calculated based on the devicePose.rotation from this state.

Precondition: The session must be configured with device tracking set to androidx.xr.runtime.Config.DeviceTrackingMode.LAST_KNOWN. If androidx.xr.runtime.Config.DeviceTrackingMode.DISABLED is used, this function will throw an IllegalStateException when attempting to acquire the ArDevice instance.

The returned flow is cold: a new stream of tilt updates is created for each collector. The flow emits new State objects containing Tilt (i.e., Tilt.UP or Tilt.DOWN) based on the orientation derived from the device pose.

It is recommended to collect this flow from a coroutine scope with the same coroutine context used to create the XR Session, as changes to ArDevice.state drive the emissions.

Parameters
@NonNull Session session

The active XR session. It must be configured with device tracking enabled androidx.xr.runtime.Config.DeviceTrackingMode.LAST_KNOWN

Returns
@NonNull Flow<@NonNull TiltGesture.State>

A Flow that emits the current State, starting with an initial state of State.tilt as Tilt.UP and State.progress as 0f.