F. Kordon - Sorbonne Université - CC2018 Notifications Renault@lrde.epita.fr
� 86 Inform the User that something just happened (SMS, mail, etc) will happen (reminders, meetings, etc.) E. Renault - Sorbonne Université - CC2018 Only visible for a certain amount of time they do not stop the current activity they use dedicated (restricted) space for their display the user is free to interrupt its activity through an action Lollipop (and higher version ) provide new notifications that are more aesthetic and allow more actions
Relative Importance of Notifications � 87 MAX Critical: something requires an immediate attention E. Renault - Sorbonne Université - CC2018 HIGH Communication: SMS, mail, telephony, ... DEFAULT All others: games, .... LOW Non-important: Software upgrades MIN Contextual informations: weather, etc.
Relative Importance of Notifications � 87 MAX Critical: something requires an immediate attention E. Renault - Sorbonne Université - CC2018 HIGH Communication: SMS, mail, telephony, ... e r a s n o i t a c f i i o t N o t g n i d r o c c a d e DEFAULT e r All others: games, .... d o r s e i t r i o r i p i r e h t LOW Non-important: Software upgrades MIN Contextual informations: weather, etc.
Relative Importance of Notifications � 87 MAX Critical: something requires an immediate attention E. Renault - Sorbonne Université - CC2018 HIGH Communication: SMS, mail, telephony, ... o t n e s r i a n s o n t i o a i t c a i c p l f i p i o t a N r u o Y o n t a g h n t i d n t r o a c r t c o a p m d e i e DEFAULT e r All others: games, .... o r d m o r s e s n e i o t r i r o e h r i p t o i r e e h h t t l l a LOW Non-important: Software upgrades MIN Contextual informations: weather, etc.
Manage Notifications (1/2) � 88 Building a notification NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getBaseContext()) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("My notification") E. Renault - Sorbonne Université - CC2018 .setContentText("Hello World!") .setPriority(Notification.PRIORITY_MAX); Grab the notification manager // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Publish it: mNotifyMgr.notify(mNotificationId, mBuilder.build()); For later updates
Manage Notifications (2/2) � 89 Suppress a notification cancel(int): delete a notification using its identifier cancelAll(): delete all notifications from the current application E. Renault - Sorbonne Université - CC2018 Fix the visibility on the home screen setVisibility: fix the visibility using above criteria Display all the content of the VISIBILITY_PUBLIC notification Only display basic VISIBILITY_PRIVATE informations (application, etc.) Minimum display: not even the VISIBILITY_SECRET name of the originated application
Toasts � 90 Toast Contextual Message Immediate message popping like a toast E. Renault - Sorbonne Université - CC2018 Toast.makeText(getApplicationContext(), "MyText",Toast.LENGTH_SHORT).show(); The length of the display can be fixed ‣ Toast.LENGTH_SHORT: 2 secondes ‣ Toast.LENGTH_LONG: 3.5 secondes The position over the screen can be fixed using setGravity ‣ Gravity.TOP, Gravity.BOTTOM, Gravity.RIGHT, Gravity.LEFT toast.setGravity(Gravity.TOP|Gravity.LEFT, xoffset, yoffset);
Customized Toasts � 91 Toasts can be customized Define a layout (here TextView + ImageView) Use the layout inflater to build it E. Renault - Sorbonne Université - CC2018 LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout_root)); TextView text = (TextView) layout.findViewById(R.id.textDisplay); text.setText("This is a custom toast"); Toast toast = new Toast(getApplicationContext()); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); Use constructor only if there is a View in the customized Toast! Otherwise makeText if enough!
AlertDialog � 92 Generic user interaction A title Three button maximum ‣ with customizable actions Clickable list of elements E. Renault - Sorbonne Université - CC2018 Customized Layout new AlertDialog.Builder(MainActivity.this) .setTitle("Delete entry") .setMessage("Are you sure you want to delete this entry?") .setIcon(android.R.drawable.ic_dialog_alert) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // continue with delete } }).show();
Snackbar � 93 Non-intrusive notifications One button (i.e. action) maximum Customizable E. Renault - Sorbonne Université - CC2018 Build.graddle may be updated compile ‘com.android.support:design:23.1.1' Snackbar. make (findViewById(R.id. container ), "Item 9 pressed" , Snackbar. LENGTH_INDEFINITE ) .setAction( "close" , new View.OnClickListener() { @Override public void onClick(View v) { } }).show();
Summary � 94 Many components can be used to interact with the user without building a with with dedicated buttons it helps to have a homogeneous environment across applications E. Renault - Sorbonne Université - CC2018 Notifications warn that something happened Priority can be fixed Contextual notifications Toast: transient information Dialog: require a user action Other kind of notification exist For instance, ProgressView notify that something is actually in progress
F. Kordon - Sorbonne Université - CC2018
Recommend
More recommend