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

AndroidWear 2.0 - New Level of Freedom for Your...

AndroidWear 2.0 - New Level of Freedom for Your Action - IT NonStop Dnipro 2016

Talk about Android Wear 2.0 at IT NonStop Dnipro 2016

Royce Mars

August 14, 2016
Tweet

More Decks by Royce Mars

Other Decks in Programming

Transcript

  1. Android Wear 2.0 New level of freedom for your action

    Докладчик: Constantine Mars Senior Developer @ DataArt, Co-Organizer @ GDG Dnipro +ConstantineMars
  2. Officially supported by: • LGE Watch Urbane 2nd Edition •

    Huawei Watch Android Wear 2.0 Preview is available for
  3. Complications - “any feature in a timepiece beyond the simple

    display of hours and minutes” (Wikipedia)
  4. • Short text • Long text • Range of values

    • Icon (small picture) • Image (big picture) Complication types:
  5. Each complication should have unique id private static final int

    LEFT_DIAL_COMPLICATION = 0; private static final int RIGHT_DIAL_COMPLICATION = 1; public static final int[] COMPLICATION_IDS = {LEFT_DIAL_COMPLICATION, RIGHT_DIAL_COMPLICATION}; // Left and right dial supported types. public static final int[][] COMPLICATION_SUPPORTED_TYPES = { {ComplicationData.TYPE_SHORT_TEXT}, {ComplicationData.TYPE_SHORT_TEXT} };
  6. ComplicationData type stores complication info (text, icon, type) onComplicationDataUpdate() is

    initiated by Data Provider private SparseArray<ComplicationData> mActiveComplicationDataSparseArray; … @Override public void onComplicationDataUpdate( int complicationId, ComplicationData complicationData) { Log.d(TAG, "onComplicationDataUpdate() id: " + complicationId); // Adds/updates active complication data in the array. mActiveComplicationDataSparseArray.put(complicationId, complicationData); invalidate(); }
  7. Rendering complications private void drawComplications(Canvas canvas, long currentTimeMillis) { //

    onDraw() for (int i = 0; i < COMPLICATION_IDS.length; i++) { ComplicationData complicationData = mActiveComplicationDataSparseArray.get(COMPLICATION_IDS[i]); if ((complicationData != null) && (complicationData.isActive(currentTimeMillis)) && (complicationData.getType() == ComplicationData.TYPE_SHORT_TEXT)) { ComplicationText mainText = complicationData.getShortText(); canvas.drawText( mainText, 0, mainText.length(), complicationsX, mComplicationsY, mComplicationPaint);
  8. Extend ComplicationProviderService and declare it in AndroidManifest.xml android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST android:icon android.support.wearable.complications.UPDATE_PERIOD_SECONDS

    android.support.wearable.complications.PROVIDER_CONFIG_ACTION <meta-data android:name="android.support.wearable.complications.SUPPORTED_TYPES" android:value="SHORT_TEXT"/>
  9. Exposing data from provider in onComplicationUpdate() @Override public void onComplicationUpdate(int

    complicationId, int dataType, ComplicationManager complicationManager) { int randomNumber = (int) Math.floor(Math.random() * 10); String randomNumberText = String.format(Locale.getDefault(), "%d!", randomNumber); switch (dataType) { case ComplicationData.TYPE_SHORT_TEXT: ComplicationData complicationData = new ComplicationData.Builder(ComplicationData.TYPE_SHORT_TEXT) .setShortText(ComplicationText.plainText(randomNumberText)) .build(); break; ...
  10. Exposing data from provider Trigger update with ComplicationManager.updateComplicationData() @Override public

    void onComplicationUpdate(int complicationId, int dataType, ComplicationManager complicationManager) { ... if (complicationData != null) { complicationManager.updateComplicationData(complicationId, complicationData); }
  11. Allow smart replies, based on Google Assistant NotificationCompat.Action action =

    new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, getString(R.string.label), replyPendingIntent) .addRemoteInput(remoteInput) // 1) allow generated replies .setAllowGeneratedReplies(true) .build();
  12. Use MessagingStyle for notification Notification noti = new NotificationCompat.Builder() .setContentTitle(messages.length

    + " new messages with " + sender.toString()) .setContentText(subject) .setSmallIcon(R.drawable.new_message) .setLargeIcon(aBitmap) // 2) set the style to MessagingStyle .setStyle(new NotificationCompat.MessagingStyle(resources.getString(R.string.reply_name)) .addMessage(messages[0].getText(), messages[0].getTime(), messages[0].getSender()) .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getSender()))