Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Droidcon Turin 2015 - Android wear sdk introduction

86 views

Published on

Talk about Android weark sdk during Droidcon Turin 2015

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Droidcon Turin 2015 - Android wear sdk introduction

  1. 1. Introduction to the SDK Tiziano Basile Mike Trizio
  2. 2. #androidwear
  3. 3. #androidwear
  4. 4. #androidwear
  5. 5. #androidwear
  6. 6. #androidwear
  7. 7. #androidwear
  8. 8. you talk to the wearable #androidwear
  9. 9. actions #androidwear
  10. 10. actions #androidwear
  11. 11. the wearable talks to you actions #androidwear
  12. 12. actions context #androidwear
  13. 13. actions context #androidwear
  14. 14. Launched automatically #androidwear
  15. 15. Glanceable #androidwear
  16. 16. Suggest and demand #androidwear
  17. 17. Zero or low interaction #androidwear
  18. 18. #androidwear
  19. 19. Notifications Apps #androidwear
  20. 20. Notifications #androidwear
  21. 21. #androidwear
  22. 22. #androidwear NO WORK REQUIRED
  23. 23. #androidwear
  24. 24. #androidwear NO WORK REQUIRED
  25. 25. RepliesPagesStacks #androidwear
  26. 26. Apps #androidwear
  27. 27. Send data Custom UI Voice Actions #androidwear
  28. 28. #androidwear
  29. 29. Node Data Message #androidwear
  30. 30. Send data Custom UI Voice Actions #androidwear
  31. 31. #androidwear
  32. 32. #androidwear
  33. 33. dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.google.android.support:wearable:+' compile 'com.google.android.gms:play-services-wearable:+' } build.gradle #androidwear
  34. 34. Classes #androidwear ● BoxInsetLayout ● Card Fragment ● CircledImageView ● ConfirmationActivity ● DismissOverlayView ● GridViewPager ● GridPagerAdapter ● FragmentGridPagerAdapter ● WatchViewStub
  35. 35. Send data Custom UI Voice Actions #androidwear
  36. 36. #androidwear
  37. 37. Available commands #androidwear ● Call a car/taxi ● Take a note ● Set alarm ● Set timer ● Start/Stop a bike ride ● Start/Stop a run ● Start/Stop a workout ● Show heart rate ● Show step count
  38. 38. Apps
  39. 39. Notifications Stand alone Apps
  40. 40. Just edit you handheld app’s code and you’re ready to go! Notifications
  41. 41. Add build.gradle dependencies compile "com.android.support:support-v4:20.0.+" Import support library’s classes import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationManagerCompat; import android.support.v4.app.NotificationCompat.WearableExtender; build.gradle
  42. 42. Create and issue the notification Notification mNotification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Simple Notification") .setContentText("Just a title, a text and an icon") .build(); NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(this); mNotificationManager.notify(mNotificationId, mNotification); MobileActivity.java
  43. 43. Add a “open on device” action Intent intent = new Intent(this, NotificationIntentActivity.class); intent.putExtra("EventID", 1); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); Notification mNotification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Simple Notification") .setContentText("Just a title, a text and an icon") .setContentIntent(pendingIntent) .build(); MobileActivity.java
  44. 44. Add a custom action Intent intent = new Intent(Intent.ACTION_VIEW); Uri position = Uri.parse("geo:0,0?q=41.109388,16.878843"); intent.setData(position); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); Notification mNotification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Simple Notification") .setContentText("Just a title, a text and an icon") .addAction(R.drawable.ic_location, "Check your position", pendingIntent); .build(); MobileActivity.java
  45. 45. Add a custom action ONLY ON WEAR NotificationCompat.Action mAction = new NotificationCompat.Action.Builder( R.drawable.ic_location, “Check your position” mPendingIntent).build(); NotificationCompat.WearableExtender mExtender = new NotificationCompat.WearableExtender() .addAction(mAction); Notification mNotification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Simple Notification") .setContentText("Just a title, a text and an icon") .extend(mExtender) .build(); MobileActivity.java
  46. 46. WearableExtender NotificationCompat.WearableExtender mExtender = new NotificationCompat.WearableExtender() .addAction(mAction) .setBackground(myBitmap) //set a background image .setHintHideIcon(true); //hide the notification icon on the card Further info about the WearableExtender class at http://bit.ly/1sA2DsL MobileActivity.java
  47. 47. Voice Inputs ● Handled by the Cue Card ● Can provide a list of predefined commands ● Use RemoteInput class to request user interaction via voice commands
  48. 48. Prepare Voice Input public static final String EXTRA_VOICE_REPLY = “user voice”; public String[] mChoices = getResources().getStringArray(R.array.choices); RemoteInput mVoiceInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel(“Reply”) .setChoices(choices) //optional .build(); ...let’s add it to a notification MobileActivity.java
  49. 49. Prepare Voice Input NotificationCompat.Action mVoiceAction = new NotificationCompat.Action.Builder(R.drawable.icon, “Reply”, mPendingIntent) .addRemoteInput(mVoiceInput) .build(); NotificationCompat.WearableExtender mExtender = new NotificationCompat.WearableExtender() .addAction(mVoiceAction); Notification mNotification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon) .setContentTitle(R.string.notification_title) .setContentText(“Here’s the notification text”) .extend(mExtender) .build(); MobileActivity.java
  50. 50. Receive Voice Input @Override public void onCreate(Bundle onSavedInstanceState){ super.onCreate(onSavedInstanceState); Intent mReceivedIntent = getIntent(); Bundle mRemoteInput = RemoteInput.getResultsFromIntent(mReceivedIntent); String mreply = “”; if(mRemoteInput != null){ mReply = mRemoteInput.getCharSequence(EXTRA_VOICE_REPLY).toString(); } } MobileActivity.java
  51. 51. Paged Notifications NotificationCompat.Builder mFirstPageBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.icon) .setContentTitle(R.string.title) .setContentText(“This is the first page”); Notification mSecondPage = new NotificationCompat.Builder(this) .setContentTitle(R.string.titletwo) .setContentText(“This is the second page!”) .build(); Notification mNotification = new NotificationCompat.WearableExtender() .addPage(mSecondPage) .extend(mFirstPage) .build(); MobileActivity.java
  52. 52. Stacked Notifications public static final String APP_GROUP = “App Notifications”; Notification mNotification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Simple Notification") .setContentText("Just a title, a text and an icon") .setGroup(APP_GROUP) .build(); MobileActivity.java
  53. 53. Stacked Notifications, GroupSummary public static final String APP_GROUP = “App Notifications”; Notification mSummaryNotification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(largeIcon) .setStyle(new NotificationCompat.InboxStyle() .addLine("First Notification Hi, I'm a notification") .addLine("Second Notification Yay, here's the second one!") .setBigContentTitle("2 Notifications from your app") .setSummaryText("com.example.app")) .setGroup(GROUP_ID) .setGroupSummary(true) .build(); MobileActivity.java
  54. 54. Write your wear apps almost like phone apps Stand Alone Apps
  55. 55. ● Access to device’s sensors ● A wearable app is more useful in some situations ● Quick info without pulling out the phone Stand Alone Apps
  56. 56. ● Short Timeline ● Needs a companion app because of Playstore compatibility ● Less functionality than a phone app ● DON’T PORT YOUR UI ON A WEARABLE!!! Stand Alone Apps
  57. 57. android.webkit android.print android.app.backup android.appwidget android.hardware.usb no support on wear Don’t use these packages
  58. 58. How to create a wearable app?
  59. 59. Phase 1: Prepare your devices ● Pair your phone with wear/emulator ● Enable Bluetooth debug in wear app ● Enabe Bluetooth debug on the wear device ● Enable Developer Options on wear (as easy as on the phone) ● Connect the phone to the PC ● Open terminal and launch one of the following commands adb -s <phone id> forward tcp:5601 tcp:5601 adb forward tcp:4444 localabstract:/adb-hub; adb connect localhost:4444
  60. 60. Phase 2: create a project
  61. 61. ● Notifications: ● Data Layer: ● UI: If you don’t need to share notification between mobile and wear, use the standard notification class, otherwise use NotificationCompat Use only if you need to sync data or send messages between mobile and wear. Remove if not necessary You should use it if you want to create beautiful UI that really rocks! Docs available at http://bit.ly/1p8ekRu Choose your libraries
  62. 62. <activity android:name=”com.app.NotificationActivity” android:exported=”true” android:allowEmbedded=”true” android:taskAffinity=”” android:theme=”@android:style/Theme.DeviceDefault.Light”> </activity> Use Activity as Custom Notification .Manifest
  63. 63. Intent mNotificationIntent = new Intent(this, NotificationActivity.class); PendingIntent mNotificationPendingIntent = PendingIntent.getActivity( this, 0, mNotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); Notification mNotification = new Notification.Builder(this) .setSmallIcon(R.drawable.icon) //Mandatory .setContentTitle(R.string.title) .extend(new Notification.WearableExtender() .setDisplayIntent(mNotificationPendingIntent)) .build(); WearActivity.java Use Activity as Custom Notification
  64. 64. Built-in intents Custom intents Freestyle Add Voice Commands
  65. 65. Built-in intents Just add an intent filter in your Activity Add Voice Commands
  66. 66. Built-in Intents <activity android:name=”.NoteActivity”> <intent-filter> <action android:name=”android.intent.action.SEND”/> <category android:name=”com.google.android.voicesearch.SELF_NOTE” /> </intent-filter> </activity> A complete list of built-in intents can be found at http://bit.ly/1p8omlo Add Voice Commands .Manifest
  67. 67. Custom intents Add an attribute in the activity tag in manifest Add Voice Commands
  68. 68. <activity android:name=”.NoteActivity” android:label=”NoteApp”> <intent-filter> <action android:name=”android.intent.action.MAIN”/> <category android:name=”android.intent.category.LAUNCHER” /> </intent-filter> </activity> The user can launch the app saying “Launch NoteApp” Custom Intents Add Voice Commands .Manifest
  69. 69. Freestyle use startActivityForResult() Add Voice Commands
  70. 70. private static final int SPEECH_REQ_CODE = 1; ... ... Intent speechIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_FORM_FREE_FORM); startActivityForResult(speechIntent, SPEECH_REQ_CODE); Freestyle Add Voice Commands .WearActivity
  71. 71. @Override protected void onActivityResult(int requestCode, int resultCode, Intent data){ if(requestCode == SPEECH_REQ_CODE && resultCode == RESULT_OK){ List<String> results = data.getStringArrayListExtra( RecognizerIntent.EXTRA_RESULTS); String spokenText = results.get(0); } super.onActivityResult(requestCode, resultCode, data); } .WearActivity Freestyle Add Voice Commands
  72. 72. https://github.com/tizionario/AndroidWearSDKDemo Try it yourself!
  73. 73. What’s next? Kickstart your experience with Android Wear Mario Viviani Advanced Dev Tips for Android Wear Alfredo Morresi
  74. 74. Tomorrow Fit4Dev - Case Study Nicola Policoro & Marco Rinaldi 14:50 @ Sala Lisbona
  75. 75. Thank you! please leave a feedback Tiziano Basile (@tizionario) tiz.basile@gmail.com Mike Trizio (@mik3lantoni0) mikelantonio.trizio@gmail.com

×