Skip to content

Example of using the Android rotation sensor and visualizing the device rotation with a custom view.

License

Notifications You must be signed in to change notification settings

kplatfoot/android-rotation-sensor-sample

Repository files navigation

android-rotation-sensor-sample

This is a sample application that uses the Android rotation sensor and displays the device rotation (pitch/roll) with a custom view (an attitude indicator, aka "artificial horizon").

It shows proper usage of the following Android features:

  • Monitoring the rotation vector sensor (but only while the activity is visible).
  • Converting the raw rotation matrix to pitch and roll, measured in degrees.
  • Adjusting the rotation values based on the device orientation (e.g. portrait vs. landscape).
  • Drawing a custom view, including using Porter-Duff transfer mode to create an anti-aliased circle cut-out.

Screenshot

The kotlin branch shows the same app written in Kotlin.

The arch-components branch shows how to use the new Android Architecture Components to start/stop the sensor listener automatically at the right time in the activity lifecycle.

About

Example of using the Android rotation sensor and visualizing the device rotation with a custom view.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages