RotationProvider

@RequiresApi(value = 21)
public final 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

public interface RotationProvider.Listener

Callback interface to receive rotation updates.

Public constructors

Creates a new RotationProvider.

Public methods

boolean
addListener(
    @NonNull Executor executor,
    @NonNull RotationProvider.Listener listener
)

Sets a Listener that listens for rotation changes.

void

Removes the given Listener from this object.

Public constructors

RotationProvider

Added in 1.1.0
public RotationProvider(@NonNull Context context)

Creates a new RotationProvider.

Public methods

addListener

Added in 1.1.0
public boolean addListener(
    @NonNull Executor executor,
    @NonNull RotationProvider.Listener listener
)

Sets a Listener that listens for rotation changes.

removeListener

Added in 1.1.0
public void removeListener(@NonNull RotationProvider.Listener listener)

Removes the given Listener from this object.

The removed listener will no longer receive rotation updates.