Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

About Create a widget in 5 minutes Widgets 3.0 (stack, list, grid) Widgets Notifications About Instant notification Rich notifications 4.1 Notgets? Some code

Slide 3

Slide 3 text

What is a widget?

Slide 4

Slide 4 text

What is a widget?

Slide 5

Slide 5 text

What is a widget? A fancy icon?

Slide 6

Slide 6 text

What is a widget? An app that works on your desktop? A fancy icon?

Slide 7

Slide 7 text

What is a widget? An app that works on your desktop? A fancy icon? A feature of an app?

Slide 8

Slide 8 text

What is a widget? An app that works on your desktop? A fancy icon? A feature of an app? A shortcut?

Slide 9

Slide 9 text

What is a widget? A quick, easy, pleasant and efficient access

Slide 10

Slide 10 text

What is a widget? A quick, easy, pleasant and efficient access It’s on your desktop, information is one click away

Slide 11

Slide 11 text

What is a widget? A quick, easy, pleasant and efficient access It’s on your desktop, information is one swipe away

Slide 12

Slide 12 text

What is a widget? A quick, easy, pleasant and efficient access It’s on your desktop.

Slide 13

Slide 13 text

What is a widget? A quick, easy, pleasant and efficient access Just swipe to the screen.

Slide 14

Slide 14 text

What is a widget? A quick, easy, pleasant and efficient access Visually attractive.

Slide 15

Slide 15 text

What is a widget? A quick, easy, pleasant and efficient access Visually attractive. you might use visually horrible apps but you would never put one one your desktop Press to rule the world

Slide 16

Slide 16 text

What is a widget? A quick, easy, pleasant and efficient access No permanent activity behind.

Slide 17

Slide 17 text

What is a widget? A quick, easy, pleasant and efficient access No permanent activity behind No views refreshing constantly*

Slide 18

Slide 18 text

What is a widget? A quick, easy, pleasant and efficient access No permanent activity behind No views refreshing constantly* It actually lives on your desktop

Slide 19

Slide 19 text

What is a widget? A quick, easy, pleasant and efficient access No permanent activity behind No views refreshing constantly* It actually lives on your desktop Remote views

Slide 20

Slide 20 text

What is a RemoteView?

Slide 21

Slide 21 text

What is a RemoteView? A view hierarchy that can be display in another process

Slide 22

Slide 22 text

What is a RemoteView? A view hierarchy that can be display in another process UI managed by a BroadcastReceiver

Slide 23

Slide 23 text

Limitations

Slide 24

Slide 24 text

Limitations Vertical swipe and tap events

Slide 25

Slide 25 text

Limitations Vertical swipe and tap events Not all layouts / views allowed

Slide 26

Slide 26 text

Limitations Vertical swipe and tap events Not all layouts / views allowed No animations*

Slide 27

Slide 27 text

Limitations Vertical swipe and tap events Not all layouts / views allowed No animations* No own lifecycle

Slide 28

Slide 28 text

Limitations Vertical swipe and tap events Not all layouts / views allowed Works with PendingIntents No animations* No own lifecycle

Slide 29

Slide 29 text

When to use

Slide 30

Slide 30 text

When to use Information at a glance (weather, calendar, unread messages)

Slide 31

Slide 31 text

When to use Information at a glance (weather, calendar, unread messages) Settings involving other apps or services (switch GPS, WiFi, BT)

Slide 32

Slide 32 text

When to use Information at a glance (weather, calendar, unread messages) Settings involving other apps or services (switch GPS, WiFi, BT) Provide control for background apps (music player)

Slide 33

Slide 33 text

When to use Information at a glance (weather, calendar, unread messages) Settings involving other apps or services (switch GPS, WiFi, BT) Provide control for background apps (music player) Custom shortcut

Slide 34

Slide 34 text

When to use Information at a glance (weather, calendar, unread messages) Settings involving other apps or services (switch GPS, WiFi, BT) Provide control for background apps (music player) Custom shortcut really need a widget?

Slide 35

Slide 35 text

Create a widget in 5 minutes 1.Create a new project (no activity required)

Slide 36

Slide 36 text

Create a widget in 5 minutes 1.Create a new project (no activity required)

Slide 37

Slide 37 text

Create a widget in 5 minutes 2.Create an XML appwidget-provider

Slide 38

Slide 38 text

Create a widget in 5 minutes 2.Create an XML appwidget-provider

Slide 39

Slide 39 text

Create a widget in 5 minutes 3.Create a new class extending AppWidgetProvider

Slide 40

Slide 40 text

Create a widget in 5 minutes 3.Create a new class extending AppWidgetProvider public class BasicWidgetProvider extends AppWidgetProvider{ @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds{ super.onUpdate(context, appWidgetManager, appWidgetIds ); //do something } }

Slide 41

Slide 41 text

Create a widget in 5 minutes 3.Create a new class extending AppWidgetProvider public class BasicWidgetProvider extends AppWidgetProvider{ @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds{ super.onUpdate(context, appWidgetManager, appWidgetIds ); //do something } } onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds ) void onEnabled( Context context ) void onDeleted( Context context, int[] appWidgetIds ) void onDisabled( Context context ) void onReceive( Context context, Intent intent )

Slide 42

Slide 42 text

Create a widget in 5 minutes 4.Create a layout for your widget

Slide 43

Slide 43 text

Create a widget in 5 minutes 4.Create a layout for your widget

Slide 44

Slide 44 text

Create a widget in 5 minutes 5.Declare the appwidget in your Manifest

Slide 45

Slide 45 text

Create a widget in 5 minutes 5.Declare the appwidget in your Manifest

Slide 46

Slide 46 text

And that’s it, less than 5 minutes for a basic widget

Slide 47

Slide 47 text

Widgets 3.0 stack grid s s list

Slide 48

Slide 48 text

Widgets 3.0 s s

Slide 49

Slide 49 text

Widgets 3.0 s s Create a StackView / ListView / GridView in widget’s XML Create a separate layout for the content Create a WidgetService Implement RemoteViewsService.RemoteViewsFactory will work like an adapter

Slide 50

Slide 50 text

What is a notification?

Slide 51

Slide 51 text

What is a notification? a message you can display to the user outside of your application's UI.

Slide 52

Slide 52 text

What is a notification? Notification bar Notification drawer

Slide 53

Slide 53 text

Instant notification NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon) .setContentTitle("My notification") .setContentText("Hello World!"); Intent resultIntent = new Intent(this, ResultActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(ResultActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT ); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(mId, mBuilder.build());

Slide 54

Slide 54 text

Instant notification NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon) .setContentTitle("My notification") .setContentText("Hello World!"); Intent resultIntent = new Intent(this, ResultActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(ResultActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT ); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(mId, mBuilder.build());

Slide 55

Slide 55 text

Expandable notifications (Jelly Bean 4.1 +)

Slide 56

Slide 56 text

What’s new?

Slide 57

Slide 57 text

What’s new? NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon) .setContentTitle("Event tracker") .setContentText("Events received") NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); String[] events = new String[6]; // Sets a title for the Inbox style big view inboxStyle.SetBigContentTitle("Event tracker details:"); . . . // Moves events into the big view for (int i=0; i < events.length; i++) { inboxStyle.addLine(events[i]); } // Moves the big view style object into the notification object. mBuilder.setStyle(inBoxStyle); . . .

Slide 58

Slide 58 text

What’s new? Notification noti = new Notification.Builder(this) .setContentTitle("11:30am, China room") .setContentText("Specs Meeting").setSmallIcon(R.drawable.icon) .setContentIntent(pIntent) .addAction(R.drawable.icon, "Snooze", pIntent).build(); . . .

Slide 59

Slide 59 text

What’s new? Notification noti = new Notification.Builder(this) .setContentTitle("11:30am, China room") .setContentText("Specs Meeting").setSmallIcon(R.drawable.icon) .setContentIntent(pIntent) .addAction(R.drawable.icon, "Snooze", pIntent) .addAction(R.drawable.icon, "More", pIntent) .addAction(R.drawable.icon, "And more", pIntent).build(); . . .

Slide 60

Slide 60 text

How to display a progress in notification bar?

Slide 61

Slide 61 text

How to display a progress in notification bar? mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(this); mBuilder.setContentTitle("Picture Download") .setContentText("Download in progress") .setSmallIcon(R.drawable.ic_notification); new Thread( new Runnable() { @Override public void run() { // do heavy stuff mBuilder.setProgress(100, incr, false); ... mNotifyManager.notify(0, mBuilder.build()); // update the notification mBuilder.setContentText("Download complete") // Removes the progress bar .setProgress(0,0,false); mNotifyManager.notify(ID, mBuilder.build()); } } ).start();

Slide 62

Slide 62 text

How to display an indeterminate progress? mBuilder.setProgress(0, 0, false); mNotifyManager.notify(0, mBuilder.build());

Slide 63

Slide 63 text

One more thing... :)

Slide 64

Slide 64 text

DON’T

Slide 65

Slide 65 text

DO

Slide 66

Slide 66 text

Notgets ?

Slide 67

Slide 67 text

Notgets ? A widget living in your notification bar

Slide 68

Slide 68 text

Notgets ? A widget living in your notification bar A widget living in your notification bar Notification + Widget -> Notget

Slide 69

Slide 69 text

Notgets ? A widget living in your notification bar A widget living in your notification bar Notification + Widget -> Notget

Slide 70

Slide 70 text

Notgets ?

Slide 71

Slide 71 text

Notgets ? Permanent display

Slide 72

Slide 72 text

Notgets ? Permanent display Practically uses no resources

Slide 73

Slide 73 text

Notgets ? Permanent display Practically uses no resources Easy access

Slide 74

Slide 74 text

MariusBudin GDG Widgets & Notifications goo.gl/OScRK

Slide 75

Slide 75 text

Thank you ! + Marius Budin @MariusBudin