StatusBarNotificationspublic class StatusBarNotifications extends android.app.Activity Demonstrates adding notifications to the status bar |
Fields Summary |
---|
private android.app.NotificationManager | mNotificationManager | private static int | MOOD_NOTIFICATIONS |
Methods Summary |
---|
protected void | onCreate(android.os.Bundle icicle)
super.onCreate(icicle);
setContentView(R.layout.status_bar_notifications);
Button button;
// Get the notification manager serivce.
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
button = (Button) findViewById(R.id.happy);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
setMood(R.drawable.stat_happy, R.string.status_bar_notifications_happy_message,
false);
}
});
button = (Button) findViewById(R.id.neutral);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
setMood(R.drawable.stat_neutral, R.string.status_bar_notifications_ok_message,
false);
}
});
button = (Button) findViewById(R.id.sad);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
setMood(R.drawable.stat_sad, R.string.status_bar_notifications_sad_message, false);
}
});
button = (Button) findViewById(R.id.happyMarquee);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
setMood(R.drawable.stat_happy, R.string.status_bar_notifications_happy_message,
true);
}
});
button = (Button) findViewById(R.id.neutralMarquee);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
setMood(R.drawable.stat_neutral, R.string.status_bar_notifications_ok_message, true);
}
});
button = (Button) findViewById(R.id.sadMarquee);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
setMood(R.drawable.stat_sad, R.string.status_bar_notifications_sad_message, true);
}
});
button = (Button) findViewById(R.id.happyViews);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
setMoodRemoteView(R.drawable.stat_happy, R.string.status_bar_notifications_happy_message);
}
});
button = (Button) findViewById(R.id.neutralViews);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
setMoodRemoteView(R.drawable.stat_neutral, R.string.status_bar_notifications_ok_message);
}
});
button = (Button) findViewById(R.id.sadViews);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
setMoodRemoteView(R.drawable.stat_sad, R.string.status_bar_notifications_sad_message);
}
});
button = (Button) findViewById(R.id.clear);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
mNotificationManager.cancel(MOOD_NOTIFICATIONS);
}
});
| private void | setMood(int moodId, int textId, boolean showTicker)
String str = getResources().getString(textId);
Notification notification = new Notification(moodId, str, null, showTicker ? str : null,
null);
mNotificationManager.notify(MOOD_NOTIFICATIONS, notification);
| private void | setMoodRemoteView(int moodId, int textId)
String str = getResources().getString(textId);
RemoteViews remoteViews = new RemoteViews(this.getPackageName(),
R.layout.status_bar_balloon);
remoteViews.setImageViewResource(R.id.icon, moodId);
remoteViews.setTextViewText(R.id.text, str);
Notification notification = new Notification(moodId, str, null, null, remoteViews);
mNotificationManager.notify(MOOD_NOTIFICATIONS, notification);
|
|