Skip to content

Instantly share code, notes, and snippets.

@josh-burton
Created July 12, 2014 06:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josh-burton/88021de7ec712e1a3371 to your computer and use it in GitHub Desktop.
Save josh-burton/88021de7ec712e1a3371 to your computer and use it in GitHub Desktop.
Android Wear Watchface Background listener
private final BroadcastReceiver mBackgroundReceiver = new BroadcastReceiver() {
public void onReceive(Context paramAnonymousContext, Intent paramAnonymousIntent) {
if (paramAnonymousIntent.hasExtra("card_location")) {
mListener.onCardLocation(
Rect.unflattenFromString(paramAnonymousIntent.getStringExtra("card_location")));
}
if (paramAnonymousIntent.hasExtra("card_progress_enabled")) {
mListener.onCardProgressEnabled(paramAnonymousIntent.getBooleanExtra("card_progress_enabled", false));
}
if (paramAnonymousIntent.hasExtra("card_progress")) {
mListener.onCardProgressUpdate(paramAnonymousIntent.getFloatExtra("card_progress", 0.0F));
}
if (paramAnonymousIntent.hasExtra("ambient_mode")) {
mListener.onAmbientModeChanged(paramAnonymousIntent.getBooleanExtra("ambient_mode", false));
}
}
IntentFilter backgroundIntentFilter = new IntentFilter("com.google.android.clockwork.home.action.BACKGROUND_ACTION");
listener.registerReceiver(WatchFace.this.mBackgroundReceiver, backgroundIntentFilter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment