Android Wear

52
Ok Google, o que é +Nelson Glauber ? @nglauber nglauber.blogspot.com

description

Slides da minha palestra sobre Android Wear apresentada no GDG DevFest Centro-Oeste em 27/Set/2014.

Transcript of Android Wear

Page 1: Android Wear

Ok Google, o que é

+Nelson Glauber

?

@nglauber nglauber.blogspot.com

Page 2: Android Wear

Android Wear estende a plataforma Android para uma nova geração de dispositivos, com uma usabilidade desenhada especificamente para os wearables.

Page 3: Android Wear

Serve para que?

125 vezes ao dia em média!!!

Vida realPega o telefone

Devagando no telefone

Mais tempo para interagir com as pessoas à sua volta

Page 4: Android Wear

UI baseada em um stream de cards

Page 5: Android Wear

Comandos de voz

Page 6: Android Wear

Princípios de UI

Page 7: Android Wear

Lançadas automaticamente

Glanceable

Sugestão e demanda

Page 8: Android Wear

Não interrompa o usuário

Grandes áreas de toque

Micro-interações

Page 9: Android Wear

O que precisamos?

Page 10: Android Wear

O que precisamos?

Android Studio 0.8

Google Play Services

Android Wear Device

Page 11: Android Wear

LG G Watch

280x280, 512MB, 4GB, 400mAh Qualcomm Snapdragon 400 - 1.2Ghz

Acelerômetro, Gyro, Compass

Samsung Gear Live

320x320, 512MB, 4GB, 300mAh Qualcom Snapdragon 400 - 1.2Ghz

Acelerômetro, Gyro, Compass e Heart

Page 12: Android Wear

Motorola Moto 360

320x290, 512MB, 4GB, 320mAh TI OMAP 3 - 1.2Ghz Pedometer e Heart

LG G Watch R

320x320, 512MB, 4GB, 410mAh Qualcomm Snapdragon - 1.2Ghz

Acelerometer, Gyro, Compass, Barometer e Heart

Page 13: Android Wear

adb -d forward tcp:5601 tcp:5601

Page 14: Android Wear

Android Wear Companion

Page 15: Android Wear

Notificações Sincronizadas

Comandos de Voz

Aplicações Wear

Envio e sincronização de dados

APIs

Page 16: Android Wear

Notificações Sincronizadas

Comandos de Voz

Aplicações Wear

Envio e sincronização de dados

APIs

Page 17: Android Wear

Notificações

Imagem de Background

Ícone da aplicação

Título

Texto

Page 18: Android Wear

Notificações simples

Page 19: Android Wear

Notificações simples

PendingIntent pit = PendingIntent.getActivity( this, 0, new Intent(this, MainMobileActivity.class), 0); !Notification notification = new NotificationCompat.Builder(this) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle("Notificação Simples") .setContentText("Texto da notificação") .setSmallIcon(R.drawable.ic_notificacao) .setLargeIcon(largeIcon) .setContentIntent(pit) .setAutoCancel(true) .build(); NotificationManagerCompat.from(this).notify(1000, notification);

Page 20: Android Wear

Notificações com ação

Page 21: Android Wear

Notificações com ação

Intent itAgenda = new Intent(Intent.ACTION_VIEW); itAgenda.setData( Uri.parse("content://com.android.calendar/time")); PendingIntent pitAcao = PendingIntent.getActivity(this, 0, itAgenda, 0); !Notification notification = new NotificationCompat.Builder(this) // demais chamadas da notificação simples .addAction( new NotificationCompat.Action( R.drawable.ic_agenda, "Agenda", pitAcao)) .build();

Page 22: Android Wear

Notificações em pilha

Page 23: Android Wear

Notificações em pilha

static int idNotificacao = 0; !Notification notification = new NotificationCompat.Builder(this) // demais chamadas da notificação simples .setContentTitle("Notificação Simples "+ ++idNotificacao) .setGroup("meuGrupo") .build();

Page 24: Android Wear

NotificationCompat.WearableExtender extensionWear = new NotificationCompat.WearableExtender() .setBackground(largeIcon); !NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle() .setBigContentTitle("Notificação em Pilha") .addLine("Várias mensagens não lidas") .setSummaryText("Resumo"); !Notification notificationSummary = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_notificacao) .setStyle(inboxStyle) .extend(extensionWear) .setGroup("meuGrupo") .setGroupSummary(true) .build(); !NotificationManagerCompat nm = NotificationManagerCompat.from(this); !nm.notify(idNotificacao, notification); nm.notify(1000, notificationSummary);

Page 25: Android Wear

Notificações com páginas

Page 26: Android Wear

NotificationCompat.Builder notificationPage1 = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_notificacao) .setContentTitle("Primeira Página") .setContentText("Essa é a primeira página") .setLargeIcon(largeIcon) .setAutoCancel(true) .setContentIntent(pit) .setDefaults(NotificationCompat.DEFAULT_ALL); !Notification notificationPage2 = new NotificationCompat.Builder(this) .setStyle(new NotificationCompat.BigTextStyle() .setBigContentTitle("Segunda página") .bigText("Essa é a segunda página")) .build(); !Notification notificationWithTwoPages = new NotificationCompat.WearableExtender() .addPage(notificationPage2) .extend(notificationPage1) .build(); !NotificationManagerCompat nm = NotificationManagerCompat.from(this); nm.notify(1000, notificationWithTwoPages);

Page 27: Android Wear

Notificações Sincronizadas

Comandos de Voz

Aplicações Wear

Envio e sincronização de dados

APIs

Page 28: Android Wear

Respondendo com voz

Page 29: Android Wear

Respondendo com vozRemoteInput remoteInput = new RemoteInput.Builder(DetalheActivity.EXTRA_RESPOSTA_VOZ) .setLabel("Diga a resposta") .build(); !NotificationCompat.Action action = new NotificationCompat.Action.Builder( R.drawable.ic_responder, "Responder", pit) .addRemoteInput(remoteInput) .build(); !NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender() .addAction(action); !Notification notification = new NotificationCompat.Builder(this) // demais chamadas da notificação simples .extend(wearableExtender) .build();

Page 30: Android Wear

Respondendo com voz

Bundle remoteInput = remoteInput.getResultsFromIntent(getIntent()); !String voz = remoteInput.getCharSequence(EXTRA_RESPOSTA_VOZ).toString();

Page 31: Android Wear

Comandos de voz

Call a car/taxi Take a note

Set alarm Set timer

Start/stop bike Start/stop a run

Start/stop workout Show heart rate

Show step count App Name :)

https://developer.android.com/training/wearables/apps/voice.html

Page 32: Android Wear

Notificações Sincronizadas

Comandos de Voz

Aplicações Wear

Envio e sincronização de dados

APIs

Page 33: Android Wear

Aplicações Wear

MinhaApp

MobileAPK WearAPK

Page 34: Android Wear

MinhaApp

Page 35: Android Wear

WatchViewStub BoxInsetLayout WearableListView CircledImageView GridViewPager GridPagerAdapter FragmentGridPagerAdapter CardFragment ConfirmationActivity DismissOverlayView

Componentesandroid.support.wearable.view.

Page 36: Android Wear

<android.support.wearable.view.WatchViewStub xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/watch_view_stub" android:layout_width="match_parent" android:layout_height="match_parent" app:rectLayout="@layout/rect_activity_main_wear" app:roundLayout="@layout/round_activity_main_wear" tools:context=".MainWearActivity" tools:deviceIds="wear"> </android.support.wearable.view.WatchViewStub>

res/layout/rect_activity_main_wear.xml

res/layout/round_activity_main_wear.xml

Page 37: Android Wear

WearableListView

WearableListView WearableListView.Item WearableListView.ClickListener RecyclerView.Adapter CircledImageView

Page 38: Android Wear

GridViewPager

GridViewPager GridPagerAdapter FragmentGridPagerAdapter CardFragment CardFrame

Page 39: Android Wear

ConfirmationActivity<activity android:name= "android.support.wearable.activity.ConfirmationActivity"/>

Intent it = new Intent(context, ConfirmationActivity.class); it.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.OPEN_ON_PHONE_ANIMATION); startActivity(it);

Page 40: Android Wear

<style name="AppTheme" parent="@android:style/Theme.DeviceDefault"> <item name="android:windowSwipeToDismiss">false</item> </style>

<android.support.wearable.view.DismissOverlayView android:id="@+id/dismiss" android:layout_width="match_parent" android:layout_height="match_parent"/>

DismissOverlayView

Page 41: Android Wear

Notificações Sincronizadas

Comandos de Voz

Aplicações Wear

Envio e sincronização de dados

APIs

Page 42: Android Wear

Comunicação Mobile/Wear

MinhaApp

MobileAPK WearAPK

Page 43: Android Wear

Google Play Services

GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context) .addApi(Wearable.API) .addConnectionCallbacks(cc) .addOnConnectionFailedListener(cfl) .build();

compile 'com.google.android.gms:play-services:5.0.89'

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

Page 44: Android Wear

Node API

Message API

Data API

Page 45: Android Wear

Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).setResultCallback( new ResultCallback<NodeApi.GetConnectedNodesResult>() { @Override public void onResult(NodeApi.GetConnectedNodesResult result) { Node node = result.getNodes().get(0); } });

Wearable.NodeApi.addListener(mGoogleApiClient, new NodeApi.NodeListener() { @Override public void onPeerConnected(Node node) { } @Override public void onPeerDisconnected(Node node) { } });

Node API

Page 46: Android Wear

Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), "/navegacao", new byte[]{ 1, 2, 3 } );

Message API

Wearable.MessageApi.addListener(mGoogleApiClient, new MessageApi.MessageListener() { @Override public void onMessageReceived(MessageEvent messageEvent) { String remetente = messageEvent.getSourceNodeId(); String caminho = messageEvent.getPath(); byte[] dados = messageEvent.getData(); } });

Page 47: Android Wear

PutDataMapRequest putDataMapRequest = PutDataMapRequest.create("/dados"); DataMap dataMap = putDataMapRequest.getDataMap(); dataMap.putInt("numero", 1); dataMap.putString("nome", "Glauber"); !Wearable.DataApi.putDataItem( mGoogleApiClient, putDataMapRequest.asPutDataRequest());

Data API

Page 48: Android Wear

Wearable.DataApi.addListener(mGoogleApiClient, new DataApi.DataListener() { @Override public void onDataChanged(DataEventBuffer dataEvents) { for (DataEvent dataEvent : dataEvents){ if (dataEvent.getType() == DataEvent.TYPE_CHANGED){ DataMapItem dataMapItem = DataMapItem.fromDataItem(dataEvent.getDataItem()); Uri uri = dataMapItem.getUri(); if (uri.getPath().equals("/dados")) { DataMap dataMap = dataMapItem.getDataMap(); int numero = dataMap.getInt("numero"); String nome = dataMap.getString("nome"); } } } }

});

Data API

Page 49: Android Wear

WearableListenerService extends Service implements NodeApi.NodeListener, MessageApi.MessageListener, DataApi.DataListener

Node API

Message API

Data API

<service android:name="ngvl.android.devfest.MeuService"> <intent-filter> <action android:name="com.google.android.gms.wearable.BIND_LISTENER" /> </intent-filter> </service>

Page 50: Android Wear
Page 51: Android Wear

Dúvidas?

Page 52: Android Wear

Nelson Glauber@nglauber

+NelsonGlauber nglauber.blogspot.com