RotationProvider
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.ListenerCallback interface to receive rotation updates. |
Public constructors |
|---|
RotationProvider(@NonNull Context context)Creates a new RotationProvider. |
Public methods |
|
|---|---|
boolean |
addListener(Sets a |
void |
removeListener(@NonNull RotationProvider.Listener listener)Removes the given |
Public constructors
RotationProvider
public RotationProvider(@NonNull Context context)
Creates a new RotationProvider.
Public methods
addListener
public boolean addListener(
@NonNull Executor executor,
@NonNull RotationProvider.Listener listener
)
Sets a Listener that listens for rotation changes.
| Parameters | |
|---|---|
@NonNull Executor executor |
The executor in which the |
removeListener
public void removeListener(@NonNull RotationProvider.Listener listener)
Removes the given Listener from this object.
The removed listener will no longer receive rotation updates.