-
public class RotationMonitor
Rotation monitor can be use watch for device rotation changes. It uses 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 TYPE_ACCELEROMETER, TYPE_GYROSCOPE and TYPE_MAGNETIC_FIELD to detect the rotation changes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
RotationMonitor.Listener
Defines the contract of listener that can receive notifications about device rotation changes.
-
Field Summary
Fields Modifier and Type Field Description private RotationMonitor.Listener
listener
-
Constructor Summary
Constructors Constructor Description RotationMonitor(Context context)
Constructs a new rotation monitor for the given context.
-
Method Summary
Modifier and Type Method Description synchronized RotationMonitor.Listener
getListener()
Gets reference to the current listener that will be notified when an rotation change is detected. synchronized void
setListener(@Nullable() 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. int
getRotation()
Returns the rotation of the screen from its "natural" rotation.The returned value may be Surface.ROTATION_0 (no rotation), Surface.ROTATION_90,Surface.ROTATION_180, or Surface.ROTATION_270. -
-
Constructor Detail
-
RotationMonitor
RotationMonitor(Context context)
Constructs a new rotation monitor for the given context.- Parameters:
context
- the context of the view that owns this rotation monitor.
-
-
Method Detail
-
getListener
@Nullable() synchronized RotationMonitor.Listener getListener()
Gets reference to the current listener that will be notified when an rotation change is detected.
-
setListener
synchronized void setListener(@Nullable() RotationMonitor.Listener listener)
Sets reference to the current listener that must be notified when an rotation change is detected.
- Parameters:
listener
- reference the rotation listener.
-
startTracking
void startTracking()
Starts the rotation monitor to start tracking for device rotation changes.
-
stopTracking
void stopTracking()
Stops the rotation monitor.
-
getRotation
int getRotation()
Returns the rotation of the screen from its "natural" rotation.The returned value may be Surface.ROTATION_0 (no rotation), Surface.ROTATION_90,Surface.ROTATION_180, or Surface.ROTATION_270. For example, if a device has a naturally tallscreen, and the user has turned it on its side to go into a landscape rotation, the valuereturned here may be either Surface.ROTATION_90 or Surface.ROTATION_270 depending on thedirection it was turned. The angle is the rotation of the drawn graphics on the screen,which is the opposite direction of the physical rotation of the device. For example, if thedevice is rotated 90 degrees counter-clockwise, to compensate rendering will be rotatedby 90 degrees clockwise and thus the returned value here will be Surface.ROTATION_90.
-
-
-
-