Top Banner
User notification Android Club 2015
22

User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Jan 04, 2016

Download

Documents

Doreen Howard
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

User notification

Android Club 2015

Page 2: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Agenda

• Toast• Custom Toast• Notification• Dialog

Page 3: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Toast: example

• Toast.makeText(getApplicationContext(), “Hello Android”, Toast.LENGTH_LONG).show();

Page 4: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Toast: practice

• Create new button• Text: Say hello• Set OnClickListener• Toast: “Hello [YOUR_NAME]!”

Page 5: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Custom Toast: example

Toast toast = new Toast(getApplicationContext());toast.setDuration(Toast.LENGTH_LONG);View view = getLayoutInflater().inflate(R.layout.toast_hello, null);toast.setView(view);toast.show();

Page 6: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Custom Toast: practice

• Create new Button• Text: Say hello• Set OnClickListener• OnClick: show one small image and

text• For example: Just do it!

Page 7: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Notification 5 steps

• Create PendingIntent• Create Notification• setLatestEventInfo()• NotificationManager• Notify

Page 8: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Notification: example

Intent intent = new Intent(this, MainActivity.class);PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0);

Notification notification = new Notification(R.drawable.friend, "Text1", System.currentTimeMillis());// Set the info for the views that show in the notification panel.notification.setLatestEventInfo(getApplicationContext(), "Text2", "Text3", pending);

// Send the notification.NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);manager.notify(0, notification);

Page 9: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Notification: practice

• Create PendingIntent which goes to FriendActivity

• Ticker text: “Friend: hello”• Title: Your friend name• Content: Message content

Page 10: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Dialog

• AlertDialog• ProgressDialog• DatePickerDialog• TimePickerDialog

Page 11: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

AlertDialog step-by-step

• Create AlertDialog builder• setTitle• setMessage• setPositiveButton• setNegativeButton• Create AlertDialog from builder• show

Page 12: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

AlertDialog: example

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( MainActivity.this);

// set titlealertDialogBuilder.setTitle("Delete");

// set dialog messagealertDialogBuilder .setMessage("Do you want to delete this file?") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity MainActivity.this.finish(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } });

// create alert dialogAlertDialog alertDialog = alertDialogBuilder.create();

// show italertDialog.show();

Page 13: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

AlertDialog: practice

• Show AlertDialog• Title: Exit app• Message: Do you want to exit app• Positive: Exit• Negative: No, I love this app

Page 14: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Progress Dialog: example

ProgressDialog dialog = ProgressDialog.show(this, "Downloading", "Downloading very big file", true);dialog.setCancelable(true);dialog.show();

Page 15: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

ProgressDialog: practice

• Show ProgressDialog• Title: Distance• Message: Calculating Distance from

Tashkent to Tokyo• Cancelable: true

Page 16: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Homework 1: Toast

• Show Toast: “This is toast”

Page 17: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Homework 2: Custom Toast

• Create layout for toast• Put text: This is toast• Put image: Toaster image• Show custom Toast using that layout

Page 18: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Homework 3: Notification

• Show notification• Icon: GooglePlay• Ticker text: Updating app• Message: Updating telegram app• Content: Updating telegram app to

the new version: 2.2.2

Page 19: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Homework 4: AlertDialog

• Title: Terms of service• Message: Are you agree with terms of

service?• Positive: I agree (open new activity)• Negative: I do not agree (close app)• setCancelable: false

Page 20: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Homework 5: ProgressDialog

• Show ProgressDialog• Title: AndroidClub• Message: Learning Android =)

Page 21: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Questions?

• Any questions?

Page 22: User notification Android Club 2015. Agenda Toast Custom Toast Notification Dialog.

Thank you

• Thank you for your attention!