lecture 9 notifications , dialogs and media

15
Lecture 9 LECTURE 9 NOTIFICATIONS , DIALOGS AND MEDIA

Upload: mina-fawzy

Post on 04-Jun-2018

232 views

Category:

Documents


0 download

TRANSCRIPT

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

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

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

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

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

Notifications

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.

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.

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);

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)

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

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

Dialogs

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

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

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();

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();

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();}

});

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

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

Progress Dialog

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

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

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

Media

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

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

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();

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);

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

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

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>