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. Complications for Android Wear
    Daniele Bonaldo

    View full-size slide

  2. changebydoing.wordpress.com
    3500 BC - Sundials

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  5. Words to watch
    Any feature in a timepiece
    beyond the simple display
    of hours and minutes
    - Wikipedia, Complication
    Complication

    View full-size slide

  6. Android Wear and complications

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  10. Icon
    Required field:
    • Icon

    View full-size slide

  11. Ranged value
    Required fields:
    Optional fields:
    • Value
    • Min value
    • Max value
    • Icon
    • Short text
    • Short title

    View full-size slide

  12. Long text
    Required field:
    Optional fields:
    • Long text
    • Long title
    • Icon
    • Small image

    View full-size slide

  13. Small image
    Required field:
    • Small image

    View full-size slide

  14. Large image
    Required field:
    • Large image

    View full-size slide

  15. Watch
    face
    Data
    provider
    Android
    Wear

    View full-size slide

  16. Watch
    face
    Data
    provider
    Android
    Wear

    View full-size slide

  17. Subdials
    IWC Portugieser Perpetual Calendar

    View full-size slide

  18. Windows
    Rolex Daydate

    View full-size slide

  19. Additional hands
    Rolex GMT Master

    View full-size slide

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

    View full-size slide

  21. complication id = 1
    complication id = 3
    complication id = 2

    View full-size slide

  22. 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

    View full-size slide

  23. Complication chooser

    View full-size slide

  24. WatchFaceConfigActivity
    Intent intent = ProviderChooserIntent.createProviderChooserIntent(

    watchFaceComponentName,

    complicationId,

    ComplicationData.TYPE_RANGED_VALUE,

    ComplicationData.TYPE_SHORT_TEXT,

    ComplicationData.TYPE_ICON

    );


    startActivityForResult(intent, REQUEST_CODE);

    View full-size slide

  25. 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

    }

    View full-size slide

  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

    }

    View full-size slide

  27. ComplicationWatchFaceService.Engine
    @Override

    public void onDraw(Canvas canvas, Rect bounds) {
    ...
    if (complicationData.isActive(currentTimeMillis)) {

    // draw the complication

    }
    ...

    }

    View full-size slide

  28. 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);

    }

    }

    }

    View full-size slide

  29. Watch
    face
    Data
    provider
    Android
    Wear

    View full-size slide

  30. Watch
    face
    Data
    provider
    Android
    Wear

    View full-size slide

  31. AndroidManifest.xml
    android:label="@string/complications_provider_label"

    android:icon="@drawable/complications_provider_icon">



    android:name="android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST"/>



    android:value=“SHORT_TEXT, ICON"/>


    android:value=“360"/>


    View full-size slide

  32. 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(

    View full-size slide

  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(
    int complicationId) { ... }

    View full-size slide

  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) { ... }

    View full-size slide

  35. 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);

    }
    }


    View full-size slide

  36. Watch
    face
    Data
    provider
    Android
    Wear

    View full-size slide

  37. 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

    View full-size slide

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

    View full-size slide