Академический Документы
Профессиональный Документы
Культура Документы
Notifications
Notifications
Status Notification
adds an icon with a message to the system's status bar and a notification message in the notifications window. When the user selects the notification, Android fires an Intent that is defined by the Notification You can also configure the notification to alert the user with a sound, a vibration, and flashing lights on the device.
Code Sample
NotificationManager 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);
or
notification.sound = Uri.parse("android.resource://" + getPackageName() +"/"+ R.raw.mafile);
Dialogs
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
Showing Dialogs
Override onCreateDialog(int id) method to initialize and create dialogs Use showDialog(int id) to show specific dialog
Alert Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure you want to exit?");
}
}); AlertDialog alert = builder.create(); alert.show();
Showing Options
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item) { Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show(); } });
Progress Dialog
Media
Playing a Video
VideoView ve = (VideoView)findViewById(R.layout.vidview); ve.setMediaController(new MediaController(getApplicationContext()));
Animation
Frame By frame Animation Tweens Animation
Scale
Rotate
Frame By Frame
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>