RotationProvider


class RotationProvider


Provider for receiving rotation updates from the SensorManager when the rotation of the device has changed.

This class monitors motion sensor and notifies the listener about physical orientation changes in the format of Surface rotation. It's useful when the Activity is in a fixed portrait or landscape orientation, while the app still wants to set the UseCase target rotation based on the device's physical rotation.

// Create a provider.
RotationProvider mRotationProvider = new RotationProvider(getContext());

// Add listener to receive updates.
mRotationProvider.addListener(rotation -> {
    mImageCapture.setTargetRotation(rotation);
});

// Remove when no longer needed.
mRotationProvider.clearListener();

Summary

Nested types

Callback interface to receive rotation updates.

Public constructors

Creates a new RotationProvider.

Public functions

Boolean

Sets a Listener that listens for rotation changes.

Unit

Removes the given Listener from this object.

Public constructors

RotationProvider

Added in 1.1.0
RotationProvider(context: Context)

Creates a new RotationProvider.

Public functions

addListener

Added in 1.1.0
fun addListener(executor: Executor, listener: RotationProvider.Listener): Boolean

Sets a Listener that listens for rotation changes.

removeListener

Added in 1.1.0
fun removeListener(listener: RotationProvider.Listener): Unit

Removes the given Listener from this object.

The removed listener will no longer receive rotation updates.