Top Banner
Lecture 9 LECTURE 9 NOTIFICATIONS , DIALOGS AND MEDIA
15

Lecture 9 Notifications , Dialogs and Media

Jun 04, 2018

Download

Documents

Mina Fawzy
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: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 1/24

Lecture 9LECTURE 9 NOTIF ICATIONS , DIALOGS AND MEDIA

Page 2: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 2/24

Page 3: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 3/24

Notifications

Page 4: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 4/24

Status Notification•adds an icon with a message to the system's status bar and a notification message in thenotifications window.

•When the user selects the notification, Android fires an Intent that is defined by theNotification

•You can also configure the notification to alert the user with a sound, a vibration, and flashinglights on the device.

Page 5: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 5/24

Hint : Service and Notification•A background service should never launch an activity on its own in order to receive uinteraction. The service should instead create a status notification that will launch the activitywhen selected by the user.

Page 6: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 6/24

Code SampleNotificationManager mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

Notification notification = new Notification(icon, tickerText, when);

Intent notificationIntent = new Intent(this, MyAlarmService.class);

PendingIntent contentIntent = PendingIntent.getService( this, 0, notificationIntent, 0);

notification.setLatestEventInfo( this, contentTitle, contentText, contentIntent);

mNotificationManager.notify(HELLO_ID, notification);

Page 7: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 7/24

Setting Sound for the notificationnotification.sound =

Uri.parse (“file/// sdcard /myfile.mp3”);

or

notification.sound = Uri.parse("android.resource://" + getPackageName() +"/"+ R.raw.mafile)

Page 9: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 9/24

Dialogs

Page 10: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 10/24

Dialogs•A dialog is usually a small window that appears in front of the current Activity.

•The underlying Activity loses focus and the dialog accepts all user interaction.

• AlertDialog

• ProgressDialog

• DatePickerDialog

• TimePickerDialog

Page 11: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 11/24

Showing Dialogs•Override onCreateDialog(int id) method to initialize and create dialogs

•Use showDialog(int id) to show specific dialog

Page 12: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 12/24

Alert DialogAlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setMessage("Are you sure you want to exit?");

builder.setPositiveButton("Yes", new DialogInterface.OnClickListener()

{

public void onClick(DialogInterface dialog, int id)

{}

});

AlertDialog alert = builder.create(); alert.show();

Page 13: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 13/24

Alert Dialog : ListAlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setTitle("Pick a color");

builder.setItems(items, new DialogInterface.OnClickListener()

{public void onClick(DialogInterface dialog, int item){

Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();

}});

AlertDialog alert = builder.create();

alert.show();

Page 14: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 14/24

Showing Optionsbuilder.setSingleChoiceItems(items, -1,

new DialogInterface.OnClickListener()

{

public void onClick(DialogInterface dialog, int item)

{

Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();}

});

Page 15: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 15/24

Progress Dialog

Page 16: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 16/24

See More About Dialogs• http://developer.android.com/guide/topics/ui/dialogs.html

Page 17: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 17/24

Media

Page 18: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 18/24

Page 19: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 19/24

Playing a VideoVideoView ve = (VideoView)findViewById(R.layout.vidview);

ve.setMediaController( new MediaController(getApplicationContext()));

ve.setVideoURI(Uri.parse("android.resource://" + getPackageName() +"/"+ R.raw.vid));

ve.start();

ve.requestFocus();

Page 20: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 20/24

Using The Camera

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

Page 21: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 21/24

Animation•Frame By frame Animation

•Tweens Animation

–Scale

–Rotate

Page 22: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 22/24

Frame By Frame

Page 23: Lecture 9 Notifications , Dialogs and Media

8/13/2019 Lecture 9 Notifications , Dialogs and Media

http://slidepdf.com/reader/full/lecture-9-notifications-dialogs-and-media 23/24

Tween Animation<set android:interpolator="@android:anim/accelerate_interpolator">

<scale

android:fromXScale=" 1.4“

android:toXScale="0.0"

android:fromYScale="0.6"

android:toYScale="0.0"

android:pivotX="50%"

android:pivotY="50%"

android:duration=" 400“

android:startOffset="700"/>

</set>