Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Complications for Android Wear

danybony
August 23, 2016

Complications for Android Wear

An overview at the new Complications API for Android Wear 2.0 and how complications can be used to add new functions and make every watchface more useful for the user.

danybony

August 23, 2016
Tweet

More Decks by danybony

Other Decks in Programming

Transcript

  1. Words to watch Any feature in a timepiece beyond the

    simple display of hours and minutes - Wikipedia, Complication Complication
  2. Ranged value Required fields: Optional fields: • Value • Min

    value • Max value • Icon • Short text • Short title
  3. complication id = 1 Ranged value Short text Icon complication

    id = 3 Ranged value Long text Short text Icon complication id = 2 Ranged value Short text Icon
  4. ComplicationWatchFaceService.Engine @Override
 public void onCreate(SurfaceHolder holder) { ...
 setActiveComplications(LEFT_DIAL_COMPLICATION, RIGHT_DIAL_COMPLICATION);

    }
 
 @Override
 public void onComplicationDataUpdate(
 int complicationId, ComplicationData complicationData) {
 // store the data to display it
 }
  5. ComplicationWatchFaceService.Engine @Override
 public void onCreate(SurfaceHolder holder) { ...
 setActiveComplications(LEFT_DIAL_COMPLICATION, RIGHT_DIAL_COMPLICATION);

    }
 
 @Override
 public void onComplicationDataUpdate(
 int complicationId, ComplicationData complicationData) {
 // store the data to display it
 }
  6. ComplicationWatchFaceService.Engine @Override
 public void onDraw(Canvas canvas, Rect bounds) { ...

    if (complicationData.isActive(currentTimeMillis)) {
 // draw the complication
 } ...
 }
  7. ComplicationWatchFaceService.Engine @Override
 public void onTapCommand(int tapType, int x, int y,

    long eventTime) {
 
 ...
 // get the complication data related to the tapped placeholder
 ... 
 if (complicationData.getTapAction() != null) {
 try {
 complicationData.getTapAction().send();
 } catch (PendingIntent.CanceledException e) {
 Log.d(TAG, "On complication tap action error " + e);
 }
 }
 }
  8. AndroidManifest.xml <service android:name=".CustomComplicationProviderService"
 android:label="@string/complications_provider_label"
 android:icon="@drawable/complications_provider_icon">
 
 <intent-filter>
 <action android:name="android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST"/>
 </intent-filter>


    
 <meta-data android:name="android.support.wearable.complications.SUPPORTED_TYPES"
 android:value=“SHORT_TEXT, ICON"/>
 
 <meta-data android:name="android.support.wearable.complications.UPDATE_PERIOD_SECONDS"
 android:value=“360"/> 
 </service>
  9. CustomComplicationProviderService @Override public void onComplicationActivated( int complicationId, int dataType, ComplicationManager

    manager) { ... }
 @Override
 public void onComplicationUpdate( int complicationId, int dataType, ComplicationManager manager) { ... }
 @Override
 public void onComplicationDeactivated(
  10. CustomComplicationProviderService @Override public void onComplicationActivated( int complicationId, int dataType, ComplicationManager

    manager) { ... }
 @Override
 public void onComplicationUpdate( int complicationId, int dataType, ComplicationManager manager) { ... }
 @Override
 public void onComplicationDeactivated( int complicationId) { ... }
  11. CustomComplicationProviderService @Override public void onComplicationActivated( int complicationId, int dataType, ComplicationManager

    manager) { ... }
 @Override
 public void onComplicationUpdate( int complicationId, int dataType, ComplicationManager manager) { ... }
 @Override
 public void onComplicationDeactivated( int complicationId) { ... }
  12. CustomComplicationProviderService @Override public void onComplicationActivated( int complicationId, int dataType, ComplicationManager

    manager) { if (dataType == ComplicationData.TYPE_SHORT_TEXT) {
 ComplicationData data = new ComplicationData.Builder(dataType)
 .setShortText(ComplicationText.plainText(“Hello!”))
 .setIcon(Icon.createWithResource( getPackageName(), R.drawable.action_item_background))
 .build(); 
 manager.updateComplicationData(complicationId, data);
 } }

  13. More info Codelab - Watch face complication https://codelabs.developers.google.com/codelabs/complications Codelab -

    Complication provider https://codelabs.developers.google.com/codelabs/data-providers Wear complications preview https://developer.android.com/wear/preview/features/complications.html
  14. Daniele Bonaldo Thank You! Any questions? All product and company

    names are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them