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

Android Wear

Android Wear

GDG Talks @ Ci&T – 2015-03-04

Douglas Kayama

March 04, 2015
Tweet

More Decks by Douglas Kayama

Other Decks in Technology

Transcript

  1. Ação só p/ relógio // Create an intent for the

    reply action Intent actionIntent = new Intent(this, ActionActivity.class); PendingIntent actionPendingIntent = PendingIntent.getActivity(this, 0, actionIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Create the action NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_action, getString(R.string.label), actionPendingIntent) .build(); // Build the notification and add the action via WearableExtender Notification notification = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.ic_message) .setContentTitle(getString(R.string.title)) .setContentText(getString(R.string.content)) .extend(new WearableExtender().addAction(action)) .build();
  2. Ação só p/ relógio // Create an intent for the

    reply action Intent actionIntent = new Intent(this, ActionActivity.class); PendingIntent actionPendingIntent = PendingIntent.getActivity(this, 0, actionIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Create the action NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_action, getString(R.string.label), actionPendingIntent) .build(); // Build the notification and add the action via WearableExtender Notification notification = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.ic_message) .setContentTitle(getString(R.string.title)) .setContentText(getString(R.string.content)) .extend(new WearableExtender().addAction(action)) .build();
  3. Voz // Key for the string that's delivered in the

    action's intent private static final String EXTRA_VOICE_REPLY = "extra_voice_reply"; String replyLabel = getResources().getString(R.string.reply_label); RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel(replyLabel) .build();
  4. Voz com opções public static final String EXTRA_VOICE_REPLY = "extra_voice_reply";

    ... String replyLabel = getResources().getString(R.string.reply_label); String[] replyChoices = getResources().getStringArray(R.array.reply_choices); RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel(replyLabel) .setChoices(replyChoices) .build();
  5. Voz // Create an intent for the reply action Intent

    replyIntent = new Intent(this, ReplyActivity.class); PendingIntent replyPendingIntent = PendingIntent.getActivity(this, 0, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Create the reply action and add the remote input NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, getString(R.string.label), replyPendingIntent) .addRemoteInput(remoteInput) .build(); // Build the notification and add the action via WearableExtender Notification notification = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.ic_message) .setContentTitle(getString(R.string.title)) .setContentText(getString(R.string.content)) .extend(new WearableExtender().addAction(action)) .build();
  6. Voz // Create an intent for the reply action Intent

    replyIntent = new Intent(this, ReplyActivity.class); PendingIntent replyPendingIntent = PendingIntent.getActivity(this, 0, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Create the reply action and add the remote input NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, getString(R.string.label), replyPendingIntent) .addRemoteInput(remoteInput) .build(); // Build the notification and add the action via WearableExtender Notification notification = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.ic_message) .setContentTitle(getString(R.string.title)) .setContentText(getString(R.string.content)) .extend(new WearableExtender().addAction(action)) .build();
  7. Voz private CharSequence getMessageText(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);

    if (remoteInput != null) { return remoteInput.getCharSequence(EXTRA_VOICE_REPLY); } return null; }
  8. Paginação BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle(); secondPageStyle.setBigContentTitle("Page 2") .bigText("A lot

    of text..."); // Create second page notification Notification secondPageNotification = new NotificationCompat.Builder(this) .setStyle(secondPageStyle) .build();
  9. Paginação // Extend the notification builder with the second page

    Notification notification = notificationBuilder .extend(new NotificationCompat.WearableExtender() .addPage(secondPageNotification)) .build();
  10. Paginação // Extend the notification builder with the second page

    Notification notification = notificationBuilder .extend(new NotificationCompat.WearableExtender() .addPage(secondPageNotification)) .build();
  11. Pilha Notification notif = new NotificationCompat.Builder(mContext) .setContentTitle("New mail from "

    + sender1) .setContentText(subject1) .setSmallIcon(R.drawable.new_mail) .setGroup(GROUP_KEY_EMAILS) .build(); … Notification notif2 = new NotificationCompat.Builder(mContext) .setContentTitle("New mail from " + sender2) .setContentText(subject2) .setSmallIcon(R.drawable.new_mail) .setGroup(GROUP_KEY_EMAILS) .build();
  12. Pilha Notification notif = new NotificationCompat.Builder(mContext) .setContentTitle("New mail from "

    + sender1) .setContentText(subject1) .setSmallIcon(R.drawable.new_mail) .setGroup(GROUP_KEY_EMAILS) .build(); … Notification notif2 = new NotificationCompat.Builder(mContext) .setContentTitle("New mail from " + sender2) .setContentText(subject2) .setSmallIcon(R.drawable.new_mail) .setGroup(GROUP_KEY_EMAILS) .build();
  13. Custom notification public void onCreate(Bundle bundle){ ... setContentView(R.layout.notification_activity); } <activity

    android:name="com.example.NotificationActivity" android:exported="true" android:allowEmbedded="true" android:theme="@android:style/Theme.DeviceDefault.Light" /> Intent notificationIntent = new Intent(this, NotificationActivity.class); PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  14. Layouts @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_wear); WatchViewStub

    stub = (WatchViewStub) findViewById(R.id.watch_view_stub); stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() { @Override public void onLayoutInflated(WatchViewStub stub) { // Now you can access your views TextView tv = (TextView) stub.findViewById(R.id.text); ... } }); }
  15. Layouts WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub); stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() { @Override

    public void onLayoutInflated(WatchViewStub stub) { // Now you can access your views TextView tv = (TextView) stub.findViewById(R.id.text); ... } });
  16. Confirmation • DelayedConfirmationView
 // Two seconds to cancel the action

    mDelayedView.setTotalTimeMs(2000); // Start the timer mDelayedView.start(); • DelayedConfirmationListener public void onTimerFinished(View view); // Usuário não cancelou, continue public void onTimerSelected(View view); // Usuário cancelou, abortar 

  17. Fechando <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent"> <!-- resto do layout -->

    <android.support.wearable.view.DismissOverlayView android:id="@+id/dismiss_overlay" android:layout_height="match_parent" android:layout_width="match_parent"/> <FrameLayout>
  18. Fechando mDismissOverlay = (DismissOverlayView) findViewById(R.id.dismiss_overlay); mDismissOverlay.setIntroText(R.string.long_press_intro); mDismissOverlay.showIntroIfNecessary(); // Configure a

    gesture detector mDetector = new GestureDetector(this, new SimpleOnGestureListener() { public void onLongPress(MotionEvent ev) { mDismissOverlay.show(); } });
  19. O que mais? • Transferência de dados entre wearable e

    device: • Wearable Data Layer • Watch Face: • CanvasWatchFaceService, CanvasWatchFaceService.Engine…