30

"It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Embed Size (px)

DESCRIPTION

CodeLab from GDG MeetsU in L'Aquila, a Google Developer Group Roma Lazio-Abruzzo

Citation preview

Page 1: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila
Page 2: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

It’s TimeAndroid Wear e Smartwatch:le app diventano indossabili

Giuseppe CerrattiAlessandro Mancinie il Team del GDG Roma L-Ab

Page 3: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Giuseppe Cerratti

[email protected]/in/giuseppecerrattiplus.google.com/+GiuseppeCerratti

Alessandro Mancini

[email protected]/in/AleMan79plus.google.com/+AlessandroMancini13

Page 4: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

developer.android.com/wear

Page 5: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

“Android wearables provide just the right information at just the right time, allowing you to be connected to the virtual world and present in the real world.”

developer.android.com/wear

Right infoat right time

Page 6: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Design Principales

Page 7: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

The Card

Le Card sono alla basedella UI di Android Wear

Sono molto più che notifiche.

Le Card appaiono solo se invocate o se strettamente necessarie all’utente in un certo istante.

developer.android.com/wear

Page 8: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

The Cardpattern

AppLaucher Icon

Image

Text

Title

developer.android.com/wear

Page 9: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

The ContextStream

Il Context Stream èuna lista verticale di Card

Nello stream viene visualizzatauna sola Card per volta.

developer.android.com/wear

Page 10: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

How can I use it?!

Page 11: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Plun!

developer.android.com/wear

Page 12: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Officialdevices

Motorolamoto360

LGG Watch

Page 13: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Let’sCode!

Page 14: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Scarica il codice del codelabal seguente link:

github.com/GDG-L-Ab/Wearun_ToDo

Code

Page 15: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Caution: The current Android Wear Developer Preview is intended for development and testing purposes only, not for production apps. Google may change this Developer Preview significantly prior to the official release of the Android Wear SDK.

Get the Developer Preview

Page 16: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Tasto destro sulla libreria-> build path-> add to build path

Importandroid.preview

Wearun/ libs/

Copiare la libreria:wearable-preview-support.jar

Page 17: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

MainActivity.java

import android.preview.support.wearable.notifications.*;import android.preview.support.v4.app.NotificationManagerCompat;import android.support.v4.app.NotificationCompat;

Importandroid.preview

Page 18: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

int notificationId = 001;

NotificationCompat.Builder notifBuilder =new NotificationCompat.Builder(getApplicationContext())

.setSmallIcon(R.drawable.ic_launcher)

.setContentTitle("Lap Time")

.setContentText("Swipe to save the lap time");

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());

notificationManager.notify(notificationId,notifBuilder.build());

Build notification

Page 19: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Test!

Page 20: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Let’sInteract

Page 21: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Create intentreciever

public class NotificationReceiver extends BroadcastReceiver{

public static final String ACTION_START = "com.giux.wearun.ACTION_START";

@Overridepublic void onReceive(Context context, Intent intent) {

String action = intent.getAction();MainActivity.start();

}}

Page 22: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

<application><receiver android:name="com.giux.wearun.NotificationReceiver" android:exported="true" > <intent-filter> <action android:name="com.giux.wearun.ACTION_START"/> <action android:name="com.giux.wearun.ACTION_LAP"/> <action android:name="com.giux.wearun.ACTION_STOP"/> </intent-filter> </receiver>

</application>

Intent &manifest

Page 23: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Intent intent = new Intent(NotificationReceiver.ACTION_START).setClass(getBaseContext(), NotificationReceiver.class);

PendingIntent pending = PendingIntent.getBroadcast(getBaseContext(), notifId, intent,

0);…

.addAction(R.drawable.ic_start, "Start", pending );

….

addAction

Page 24: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Test!

Page 25: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

Add anotherAction!

Page 26: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

public class NotificationReceiver extends BroadcastReceiver{

public static final String ACTION_START = "com.giux.wearun.ACTION_START";

public static final String ACTION_LAP ="com.giux.wearun.ACTION_LAP";

public static final String ACTION_STOP = "com.giux.wearun.ACTION_STOP";

Edit the Broadcast Reciever

Page 27: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

@Overridepublic void onReceive(Context context, Intent intent) {

String action = intent.getAction();

switch (action) {case ACTION_START:

MainActivity.start();break;

…default:

break;}

Edit the Intent Reciever

Page 28: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

public PendingIntent createIntent(String extra, int notifId){Intent intent = null;

switch (extra) {case "start":

intent = new Intent(NotificationReceiver.ACTION_START).setClass(getBaseContext(),

NotificationReceiver.class);break;…

}PendingIntent pending =

PendingIntent.getBroadcast(getBaseContext(), notifId, intent, 0);

return pending;}

More Intent

Page 29: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

public void notif(){…

.setContentTitle("Lap Time").setContentText("Swipe to save the lap time").addAction(R.drawable.ic_start, "Start", createIntent("start", notificationId))//ToDo

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());

notificationManager.notify(notificationId, notifBuilder.build());

}

More Action

Page 30: "It's Time" - Android Wear codelab - GDG MeetsU - L'Aquila

That’sAll!