Android Wear

  • Published on
    22-Nov-2014

  • View
    1.005

  • Download
    0

DESCRIPTION

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

Transcript

  • 1. Ok Google, o que ?+Nelson Glauber@nglaubernglauber.blogspot.com

2. Android Wear estende aplataforma Android para umanova gerao de dispositivos,com uma usabilidadedesenhada especificamentepara os wearables. 3. Serve para que?Vida realPega o telefoneDevagando no telefone125 vezes ao dia em mdia!!!Mais tempo para interagir com as pessoas sua volta 4. UI baseada em umstream de cards 5. Comandos de voz 6. Princpios de UI 7. LanadasautomaticamenteGlanceableSugesto edemanda 8. No interrompa o usurioGrandes reas de toqueMicro-interaes 9. O que precisamos? 10. O que precisamos?Android Studio0.8Google PlayServicesAndroid WearDevice 11. LGG Watch280x280, 512MB, 4GB, 400mAhQualcomm Snapdragon 400 - 1.2GhzAcelermetro, Gyro, CompassSamsungGear Live320x320, 512MB, 4GB, 300mAhQualcom Snapdragon 400 - 1.2GhzAcelermetro, Gyro, Compass e Heart 12. MotorolaMoto 360320x290, 512MB, 4GB, 320mAhTI OMAP 3 - 1.2GhzPedometer e HeartLGG Watch R320x320, 512MB, 4GB, 410mAhQualcomm Snapdragon - 1.2GhzAcelerometer, Gyro, Compass,Barometer e Heart 13. adb -d forward tcp:5601 tcp:5601 14. Android Wear Companion 15. NotificaesSincronizadasComandosde VozAplicaesWearEnvio e sincronizaode dadosAPIs 16. NotificaesSincronizadasComandosde VozAplicaesWearEnvio e sincronizaode dadosAPIs 17. NotificaesImagem deBackgroundcone daaplicaoTtuloTexto 18. Notificaes simples 19. Notificaes simplesPendingIntent pit = PendingIntent.getActivity(this, 0, new Intent(this, MainMobileActivity.class), 0);!Notification notification = new NotificationCompat.Builder(this).setDefaults(Notification.DEFAULT_ALL).setContentTitle("Notificao Simples").setContentText("Texto da notificao").setSmallIcon(R.drawable.ic_notificacao).setLargeIcon(largeIcon).setContentIntent(pit).setAutoCancel(true).build();NotificationManagerCompat.from(this).notify(1000, notification); 20. Notificaes com ao 21. Notificaes com aoIntent 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 notificao simples.addAction(new NotificationCompat.Action(R.drawable.ic_agenda, "Agenda", pitAcao)).build(); 22. Notificaes em pilha 23. Notificaes em pilhastatic int idNotificacao = 0;!Notification notification = new NotificationCompat.Builder(this)// demais chamadas da notificao simples.setContentTitle("Notificao Simples "+ ++idNotificacao).setGroup("meuGrupo").build(); 24. NotificationCompat.WearableExtender extensionWear =new NotificationCompat.WearableExtender().setBackground(largeIcon);!NotificationCompat.InboxStyle inboxStyle =new NotificationCompat.InboxStyle().setBigContentTitle("Notificao em Pilha").addLine("Vrias mensagens no 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); 25. Notificaes com pginas 26. NotificationCompat.Builder notificationPage1 =new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_notificacao).setContentTitle("Primeira Pgina").setContentText("Essa a primeira pgina").setLargeIcon(largeIcon).setAutoCancel(true).setContentIntent(pit).setDefaults(NotificationCompat.DEFAULT_ALL);!Notification notificationPage2 =new NotificationCompat.Builder(this).setStyle(new NotificationCompat.BigTextStyle().setBigContentTitle("Segunda pgina").bigText("Essa a segunda pgina")).build();!Notification notificationWithTwoPages =new NotificationCompat.WearableExtender().addPage(notificationPage2).extend(notificationPage1).build();!NotificationManagerCompat nm =NotificationManagerCompat.from(this);nm.notify(1000, notificationWithTwoPages); 27. NotificaesSincronizadasComandosde VozAplicaesWearEnvio e sincronizaode dadosAPIs 28. Respondendo com voz 29. 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 notificao simples.extend(wearableExtender).build(); 30. Respondendo com vozBundle remoteInput =remoteInput.getResultsFromIntent(getIntent());!String voz =remoteInput.getCharSequence(EXTRA_RESPOSTA_VOZ).toString(); 31. Comandos de vozCall a car/taxi Take a noteSet alarm Set timerStart/stop bike Start/stop a runStart/stop workout Show heart rateShow step count App Name :)https://developer.android.com/training/wearables/apps/voice.html 32. NotificaesSincronizadasComandosde VozAplicaesWearEnvio e sincronizaode dadosAPIs 33. Aplicaes WearMinhaAppMobileAPK WearAPK 34. MinhaApp 35. WatchViewStubBoxInsetLayoutWearableListViewCircledImageViewGridViewPagerGridPagerAdapterFragmentGridPagerAdapterCardFragmentConfirmationActivityDismissOverlayViewComponentesandroid.support.wearable.view. 36. res/layout/rect_activity_main_wear.xmlres/layout/round_activity_main_wear.xml 37. WearableListViewWearableListViewWearableListView.ItemWearableListView.ClickListenerRecyclerView.AdapterCircledImageView 38. GridViewPagerGridViewPagerGridPagerAdapterFragmentGridPagerAdapterCardFragmentCardFrame 39. ConfirmationActivityIntent it = new Intent(context, ConfirmationActivity.class);it.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE,ConfirmationActivity.OPEN_ON_PHONE_ANIMATION);startActivity(it); 40. DismissOverlayView 41. NotificaesSincronizadasComandosde VozAplicaesWearEnvio e sincronizaode dadosAPIs 42. Comunicao Mobile/WearMinhaAppMobileAPK WearAPK 43. Google Play Servicescompile 'com.google.android.gms:play-services:5.0.89'GoogleApiClient googleApiClient =new GoogleApiClient.Builder(context).addApi(Wearable.API).addConnectionCallbacks(cc).addOnConnectionFailedListener(cfl).build(); 44. Node APIMessage APIData API 45. Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).setResultCallback(new ResultCallback() {@Overridepublic void onResult(NodeApi.GetConnectedNodesResult result) {Node node = result.getNodes().get(0);}});Wearable.NodeApi.addListener(mGoogleApiClient, new NodeApi.NodeListener() {@Overridepublic void onPeerConnected(Node node) {}@Overridepublic void onPeerDisconnected(Node node) {}});Node API 46. Message APIWearable.MessageApi.sendMessage(mGoogleApiClient,node.getId(), "/navegacao", new byte[]{ 1, 2, 3 } );Wearable.MessageApi.addListener(mGoogleApiClient,new MessageApi.MessageListener() {@Overridepublic void onMessageReceived(MessageEvent messageEvent) {String remetente = messageEvent.getSourceNodeId();String caminho = messageEvent.getPath();byte[] dados = messageEvent.getData();}}); 47. Data APIPutDataMapRequest putDataMapRequest =PutDataMapRequest.create("/dados");DataMap dataMap = putDataMapRequest.getDataMap();dataMap.putInt("numero", 1);dataMap.putString("nome", "Glauber");!Wearable.DataApi.putDataItem(mGoogleApiClient,putDataMapRequest.asPutDataRequest()); 48. Wearable.DataApi.addListener(mGoogleApiClient,new DataApi.DataListener() {@Overridepublic 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 49. WearableListenerServiceextends ServiceimplementsNodeApi.NodeListener,MessageApi.MessageListener,DataApi.DataListenerNode APIMessage APIData API 50. Dvidas? 51. Nelson Glauber@nglauber+NelsonGlaubernglauber.blogspot.com