SkillAgentSearch skills...

AndroidWearMotionSensors

Using the accelerometer and gyroscope on an Android Wear device

Install / Use

/learn @estherjk/AndroidWearMotionSensors
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Android Wear Motion Sensors

This project demonstrates the use of the accelerometer and gyroscope sensors on an Android Wear device. It displays the raw values for each sensor on its own page. It also performs simple shake and rotation detection using the accelerometer and gyroscope, respectively; when a shake or a rotation is detected, the background color changes to green.

See it in action here using the Moto 360.

Code Overview

The Java files of interest are in wear/src/main/java:

As the name suggests, MainActivity.java contains the code for the main activity. The 2D Picker pattern for Android Wear is used to page through the accelerometer and gyroscope fragments. This is accomplished by adding a GridViewPager element to the activity and setting an adapter that provides the pages by extending FragmentGridPagerAdapter (see SensorFragmentPagerAdapter.java). It also contains a DotsPageIndicator to identify which page is active.

SensorFragment.java provides the UI behavior for a sensor by displaying the raw data (available through the standard Android API) and performing simple shake / rotation detection. When instantiating a sensor fragment, the newInstance() function is used to specify the desired sensor (i.e. accelerometer or gyroscope). See SensorFragmentPagerAdapter.java to see how this is accomplished.

View on GitHub
GitHub Stars112
CategoryDevelopment
Updated7mo ago
Forks49

Languages

Java

Security Score

92/100

Audited on Aug 13, 2025

No findings