Search in sources :

Example 6 with Notification

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;
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 7 with 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);
}
Also used : Notification(android.app.Notification)

Example 8 with Notification

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;
}
Also used : Rect(android.graphics.Rect) ViewGroup(android.view.ViewGroup) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Paint(android.graphics.Paint) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) Paint(android.graphics.Paint) Bitmap(android.graphics.Bitmap) PorterDuffXfermode(android.graphics.PorterDuffXfermode) FrameLayout(android.widget.FrameLayout) StatusBarIcon(com.android.internal.statusbar.StatusBarIcon)

Example 9 with Notification

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);
}
Also used : Resources(android.content.res.Resources) Notification(android.app.Notification)

Example 10 with Notification

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);
        }
    }
}
Also used : MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) LayoutParams(android.view.ViewGroup.LayoutParams) Entry(com.android.systemui.statusbar.NotificationData.Entry) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) QuickSettingsContainerView(com.android.systemui.statusbar.phone.QuickSettingsContainerView) View(android.view.View) TextView(android.widget.TextView) SignalClusterView(com.android.systemui.statusbar.SignalClusterView) StatusBarIconView(com.android.systemui.statusbar.StatusBarIconView) KeyButtonView(com.android.systemui.statusbar.policy.KeyButtonView) ScrollView(android.widget.ScrollView) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) Point(android.graphics.Point) Entry(com.android.systemui.statusbar.NotificationData.Entry) StatusBarNotification(android.service.notification.StatusBarNotification) LinearLayout(android.widget.LinearLayout) StatusBarIconView(com.android.systemui.statusbar.StatusBarIconView) NotificationData(com.android.systemui.statusbar.NotificationData)

Aggregations

Notification (android.app.Notification)552 PendingIntent (android.app.PendingIntent)265 Intent (android.content.Intent)240 NotificationManager (android.app.NotificationManager)122 StatusBarNotification (android.service.notification.StatusBarNotification)96 NotificationCompat (android.support.v4.app.NotificationCompat)58 Resources (android.content.res.Resources)55 Context (android.content.Context)47 Bitmap (android.graphics.Bitmap)47 Test (org.junit.Test)45 ITransientNotification (android.app.ITransientNotification)32 RemoteViews (android.widget.RemoteViews)30 RemoteException (android.os.RemoteException)24 UserHandle (android.os.UserHandle)17 Date (java.util.Date)16 Uri (android.net.Uri)15 Bundle (android.os.Bundle)13 File (java.io.File)13 ApplicationInfo (android.content.pm.ApplicationInfo)12 SuppressLint (android.annotation.SuppressLint)11