use of android.app.Notification in project android-gcm by chiuki.
the class GCMIntentService method prepareNotification.
private Notification prepareNotification(Context context, String msg) {
long when = System.currentTimeMillis();
Notification notification = new Notification(R.drawable.ic_stat_cloud, msg, when);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(context, MessageActivity.class);
// Set a unique data uri for each notification to make sure the activity
// gets updated
intent.setData(Uri.parse(msg));
intent.putExtra(Constants.FIELD_MESSAGE, msg);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
String title = context.getString(R.string.app_name);
notification.setLatestEventInfo(context, title, msg, pendingIntent);
return notification;
}
use of android.app.Notification in project android_frameworks_base by ParanoidAndroid.
the class StatusBarNotification method cloneLight.
/**
* @hide
*/
public StatusBarNotification cloneLight() {
final Notification no = new Notification();
// light copy
this.notification.cloneInto(no, false);
return new StatusBarNotification(this.pkg, this.basePkg, this.id, this.tag, this.uid, this.initialPid, this.score, no, this.user, this.postTime);
}
use of android.app.Notification in project android_frameworks_base by ParanoidAndroid.
the class BaseStatusBar method prepareHaloNotification.
public void prepareHaloNotification(NotificationData.Entry entry, StatusBarNotification notification, boolean update) {
Notification notif = notification.getNotification();
// Get the remote view
try {
if (!update) {
ViewGroup mainView = (ViewGroup) notif.contentView.apply(mContext, null, mOnClickHandler);
if (mainView instanceof FrameLayout) {
entry.haloContent = mainView.getChildAt(1);
mainView.removeViewAt(1);
} else {
entry.haloContent = mainView;
}
} else {
notif.contentView.reapply(mContext, entry.haloContent, mOnClickHandler);
}
} catch (Exception e) {
// Non uniform content?
android.util.Log.d("PARANOID", " Non uniform content?");
}
// Construct the round icon
final float haloSize = Settings.System.getFloat(mContext.getContentResolver(), Settings.System.HALO_SIZE, 1.0f);
int iconSize = (int) (mContext.getResources().getDimensionPixelSize(R.dimen.halo_bubble_size) * haloSize);
int smallIconSize = (int) (mContext.getResources().getDimensionPixelSize(R.dimen.status_bar_icon_size) * haloSize);
int largeIconWidth = notif.largeIcon != null ? (int) (notif.largeIcon.getWidth() * haloSize) : 0;
int largeIconHeight = notif.largeIcon != null ? (int) (notif.largeIcon.getHeight() * haloSize) : 0;
Bitmap roundIcon = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(roundIcon);
canvas.drawARGB(0, 0, 0, 0);
// halo-bubble, we'll use that one and cut it round
if (notif.largeIcon != null && largeIconWidth >= iconSize / 2) {
Paint smoothingPaint = new Paint();
smoothingPaint.setAntiAlias(true);
smoothingPaint.setFilterBitmap(true);
smoothingPaint.setDither(true);
canvas.drawCircle(iconSize / 2, iconSize / 2, iconSize / 2.3f, smoothingPaint);
smoothingPaint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
final int newWidth = iconSize;
final int newHeight = iconSize * largeIconWidth / largeIconHeight;
Bitmap scaledBitmap = Bitmap.createScaledBitmap(notif.largeIcon, newWidth, newHeight, true);
canvas.drawBitmap(scaledBitmap, null, new Rect(0, 0, iconSize, iconSize), smoothingPaint);
} else {
try {
Drawable icon = StatusBarIconView.getIcon(mContext, new StatusBarIcon(notification.getPackageName(), notification.getUser(), notif.icon, notif.iconLevel, notif.number, notif.tickerText));
if (icon == null)
icon = mContext.getPackageManager().getApplicationIcon(notification.getPackageName());
int margin = (iconSize - smallIconSize) / 2;
icon.setBounds(margin, margin, iconSize - margin, iconSize - margin);
icon.draw(canvas);
} catch (Exception e) {
// NameNotFoundException
}
}
entry.roundIcon = roundIcon;
}
use of android.app.Notification in project android_frameworks_base by ParanoidAndroid.
the class GlobalScreenshot method notifyScreenshotError.
static void notifyScreenshotError(Context context, NotificationManager nManager) {
Resources r = context.getResources();
// Clear all existing notification, compose the new notification and show it
Notification.Builder b = new Notification.Builder(context).setTicker(r.getString(R.string.screenshot_failed_title)).setContentTitle(r.getString(R.string.screenshot_failed_title)).setContentText(r.getString(R.string.screenshot_failed_text)).setSmallIcon(R.drawable.stat_notify_image_error).setWhen(System.currentTimeMillis()).setAutoCancel(true);
Notification n = new Notification.BigTextStyle(b).bigText(r.getString(R.string.screenshot_failed_text)).build();
nManager.notify(SCREENSHOT_NOTIFICATION_ID, n);
}
use of android.app.Notification in project android_frameworks_base by ParanoidAndroid.
the class TabletStatusBar method updateNotificationIcons.
@Override
protected void updateNotificationIcons() {
if (mIconLayout == null)
return;
// first, populate the main notification panel
loadNotificationPanel();
final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(mIconSize + 2 * mIconHPadding, mNaturalBarHeight);
// alternate behavior in DND mode
if (mNotificationDNDMode) {
if (mIconLayout.getChildCount() == 0) {
final Notification dndNotification = new Notification.Builder(mContext).setContentTitle(mContext.getText(R.string.notifications_off_title)).setContentText(mContext.getText(R.string.notifications_off_text)).setSmallIcon(R.drawable.ic_notification_dnd).setOngoing(true).getNotification();
final StatusBarIconView iconView = new StatusBarIconView(mContext, "_dnd", dndNotification);
iconView.setImageResource(R.drawable.ic_notification_dnd);
iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
iconView.setPadding(mIconHPadding, 0, mIconHPadding, 0);
mNotificationDNDDummyEntry = new NotificationData.Entry(null, new StatusBarNotification("", 0, "", 0, 0, Notification.PRIORITY_MAX, dndNotification, android.os.Process.myUserHandle()), iconView);
mIconLayout.addView(iconView, params);
}
return;
} else if (0 != (mDisabled & StatusBarManager.DISABLE_NOTIFICATION_ICONS)) {
// just leave the area totally empty
return;
}
int N = mNotificationData.size();
if (DEBUG) {
Slog.d(TAG, "refreshing icons: " + N + " notifications, mIconLayout=" + mIconLayout);
}
ArrayList<View> toShow = new ArrayList<View>();
// Extra Special Icons
// The IME switcher and compatibility mode icons take the place of notifications. You didn't
// need to see all those new emails, did you?
int maxNotificationIconsCount = mMaxNotificationIcons;
if (mInputMethodSwitchButton.getVisibility() != View.GONE)
maxNotificationIconsCount--;
if (mCompatModeButton.getVisibility() != View.GONE)
maxNotificationIconsCount--;
final boolean provisioned = isDeviceProvisioned();
// If the device hasn't been through Setup, we only show system notifications
for (int i = 0; toShow.size() < maxNotificationIconsCount; i++) {
if (i >= N)
break;
Entry ent = mNotificationData.get(N - i - 1);
if ((provisioned && ent.notification.getScore() >= HIDE_ICONS_BELOW_SCORE) || showNotificationEvenIfUnprovisioned(ent.notification) || mHaloTaskerActive) {
toShow.add(ent.icon);
}
}
ArrayList<View> toRemove = new ArrayList<View>();
for (int i = 0; i < mIconLayout.getChildCount(); i++) {
View child = mIconLayout.getChildAt(i);
if (!toShow.contains(child)) {
toRemove.add(child);
}
}
for (View remove : toRemove) {
mIconLayout.removeView(remove);
}
for (int i = 0; i < toShow.size(); i++) {
View v = toShow.get(i);
v.setPadding(mIconHPadding, 0, mIconHPadding, 0);
if (v.getParent() == null) {
mIconLayout.addView(v, i, params);
}
}
}
Aggregations