"it's time" - android wear codelab - gdg meetsu - l'aquila
DESCRIPTION
CodeLab from GDG MeetsU in L'Aquila, a Google Developer Group Roma Lazio-AbruzzoTRANSCRIPT
It’s TimeAndroid Wear e Smartwatch:le app diventano indossabili
Giuseppe CerrattiAlessandro Mancinie il Team del GDG Roma L-Ab
Giuseppe Cerratti
[email protected]/in/giuseppecerrattiplus.google.com/+GiuseppeCerratti
Alessandro Mancini
[email protected]/in/AleMan79plus.google.com/+AlessandroMancini13
developer.android.com/wear
“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
Design Principales
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
The Cardpattern
AppLaucher Icon
Image
Text
Title
developer.android.com/wear
The ContextStream
Il Context Stream èuna lista verticale di Card
Nello stream viene visualizzatauna sola Card per volta.
developer.android.com/wear
How can I use it?!
Plun!
developer.android.com/wear
Officialdevices
Motorolamoto360
LGG Watch
Let’sCode!
Scarica il codice del codelabal seguente link:
github.com/GDG-L-Ab/Wearun_ToDo
Code
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
Tasto destro sulla libreria-> build path-> add to build path
Importandroid.preview
Wearun/ libs/
Copiare la libreria:wearable-preview-support.jar
MainActivity.java
import android.preview.support.wearable.notifications.*;import android.preview.support.v4.app.NotificationManagerCompat;import android.support.v4.app.NotificationCompat;
Importandroid.preview
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
Test!
Let’sInteract
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();
}}
<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
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
Test!
Add anotherAction!
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
@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
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
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
That’sAll!