Complications for Android Wear

D4be3ad792b57408b3ab6fe98caef08e?s=47 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.

D4be3ad792b57408b3ab6fe98caef08e?s=128

danybony

August 23, 2016
Tweet

Transcript

  1. Complications for Android Wear Daniele Bonaldo

  2. changebydoing.wordpress.com 3500 BC - Sundials

  3. Andrew Shiva [CC BY-SA 3.0], via Wikimedia Commons 1200 -

    Clocks
  4. Larry Yuma [CC-BY-SA-3.0], via Wikimedia Commons 1400 - Watches

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

    simple display of hours and minutes - Wikipedia, Complication Complication
  6. Android Wear and complications

  7. Watch face Data provider Android Wear Update request Complication data

    Complication data
  8. Different types https://developer.android.com/wear

  9. Short text Required field: Optional fields: • Short text •

    Icon • Short title
  10. Icon Required field: • Icon

  11. Ranged value Required fields: Optional fields: • Value • Min

    value • Max value • Icon • Short text • Short title
  12. Long text Required field: Optional fields: • Long text •

    Long title • Icon • Small image
  13. Small image Required field: • Small image

  14. Large image Required field: • Large image

  15. Watch face Data provider Android Wear

  16. Watch face Data provider Android Wear

  17. Subdials IWC Portugieser Perpetual Calendar

  18. Windows Rolex Daydate

  19. Additional hands Rolex GMT Master

  20. Placeholders https://www.google.com/design/spec-wear/patterns/complications.html

  21. None
  22. complication id = 1 complication id = 3 complication id

    = 2
  23. 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
  24. Complication chooser

  25. WatchFaceConfigActivity Intent intent = ProviderChooserIntent.createProviderChooserIntent(
 watchFaceComponentName,
 complicationId,
 ComplicationData.TYPE_RANGED_VALUE,
 ComplicationData.TYPE_SHORT_TEXT,
 ComplicationData.TYPE_ICON


    );
 
 startActivityForResult(intent, REQUEST_CODE);
  26. 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
 }
  27. 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
 }
  28. ComplicationWatchFaceService.Engine @Override
 public void onDraw(Canvas canvas, Rect bounds) { ...

    if (complicationData.isActive(currentTimeMillis)) {
 // draw the complication
 } ...
 }
  29. 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);
 }
 }
 }
  30. Watch face Data provider Android Wear

  31. Watch face Data provider Android Wear

  32. 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>
  33. 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(
  34. 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) { ... }
  35. 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) { ... }
  36. 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);
 } }

  37. Watch face Data provider Android Wear

  38. 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
  39. 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