Courtesy: GitHub
Warning: file_get_contents(../git/googlesamples/android-play-games-in-motion/ failed to open stream: No such file or directory in /var/www/ on line 10

compileSdkVersion 21

applicationId ""

minSdkVersion 16

targetSdkVersion 21

versionCode 1

versionName "1.0"

compile group: 'junit', name: 'junit', version: '3.8'

compile ''

compile ''



  • android.permission.VIBRATE
  • android.permission.BLUETOOTH
  • android.permission.BLUETOOTH_ADMIN
  • android.permission.ACCESS_FINE_LOCATION


MainActivity class on the UI thread. It has a game handler for the game loop to execute on.

Responsible for transitioning from the start menu UI to the mission selection menu UI @param view The view that is invoking this method.

Updates UI as Google Fit's connection status changes.

The back button should be active as long as there are fragment transactions in the back stack. We always want the first fragment to be around so the back stack count needs to be 1. @return Whether the back button should be active.

Displays end run summary, with fictional and fitness results.


This is a Runnable for executing on the UI thread, and will add itself back to the UI thread handler at the end of the run() function. * While it will block the UI thread while running, it shouldn't block for that long. We could always make a game thread if needed.

This is the main game loop. Whenever it is done, it adds itself back to the handler.

Unlock a Play Games achievement. * @param achievementId the ID of the achievement from the Google Play Developer Console, @return true if Achievement unlocked, false otherwise.

Loads and begins a mission.

Starts a mission.

Ends a mission by halting updates.

Callback listener for MediaPlayer. @param player MediaPlayer instance.

A Binder for the connection between MainService and MainActivity that allows MainActivity to get the running instance of MainService.

Create a notification action that upon selection triggers the provided action. @param intent Intent to carry out when the notification action is selected. @param actionIconResourceId Resource Id of icon for this action. @param actionDescription Name of this action. @return A notification action that can be selected.

Builds and posts a notification from a set of options. @param options The options to build the notification.

Gets fitness statistics for the last played game. @return An array list of fitness statistics to display.

Queue a sound into the audio queue. @param uri The Uri of the sound. @param listener The listener to the sound. This is usually MainService but can be overridden.

Removes the first instance of a sound from the audio queue. @param uri Uri of the item to be removed.

Obtain audio focus for the application. This also checks if we are currently playing any other audio clips, so it checks for "audio focus" within the app. @return True if audio focus is obtained. False otherwise.

End audio playback, and abandon audio focus.

Checks if the state transition is valid. @param state State to transition to. @return True if the transition is valid, false if not.

Sets the next state if possible. @param state State to transition to.

Play the first item in the audio queue.

@return True if asynchronous preparations are all done, so that a mission can be started.

Broadcast to MainActivity to enable back navigation.

Display a Toast that requests user to reselect their mission.

Broadcast to MainActivity that mission has started.

Broadcast to MainActivity that mission has ended.