public class RotationMonitor
extends java.lang.Object
Sensor.TYPE_ROTATION_VECTOR
sensor if available to detect device rotation changes. If the
sensor is not available then the rotation monitor will attempt use the sensors
Sensor.TYPE_ACCELEROMETER
, Sensor.TYPE_GYROSCOPE
and Sensor.TYPE_MAGNETIC_FIELD
to detect the rotation changes.Modifier and Type | Class and Description |
---|---|
static interface |
RotationMonitor.Listener
Defines the contract of listener that can receive notifications about device rotation changes.
|
Constructor and Description |
---|
RotationMonitor(android.content.Context context)
Constructs a new rotation monitor for the given context.
|
Modifier and Type | Method and Description |
---|---|
RotationMonitor.Listener |
getListener()
Gets reference to the current listener that will be notified when an rotation change is detected.
|
int |
getRotation()
Returns the rotation of the screen from its "natural" rotation.
|
void |
setListener(RotationMonitor.Listener listener)
Sets reference to the current listener that must be notified when an rotation change is detected.
|
void |
startTracking()
Starts the rotation monitor to start tracking for device rotation changes.
|
void |
stopTracking()
Stops the rotation monitor.
|
public RotationMonitor(android.content.Context context)
context
- the context of the view that owns this rotation monitor.@Nullable public RotationMonitor.Listener getListener()
public void setListener(@Nullable RotationMonitor.Listener listener)
listener
- reference the rotation listener.public void startTracking()
public void stopTracking()
public int getRotation()
android.view.Display#getRotation()}