FileDocCategorySizeDatePackage
NotificationCompatJellybean.javaAPI DocAndroid 5.1 API17398Thu Mar 12 22:22:56 GMT 2015android.support.v4.app

NotificationCompatJellybean

public class NotificationCompatJellybean extends Object

Fields Summary
public static final String
TAG
static final String
EXTRA_LOCAL_ONLY
static final String
EXTRA_ACTION_EXTRAS
static final String
EXTRA_REMOTE_INPUTS
static final String
EXTRA_GROUP_KEY
static final String
EXTRA_GROUP_SUMMARY
static final String
EXTRA_SORT_KEY
static final String
EXTRA_USE_SIDE_CHANNEL
private static final String
KEY_ICON
private static final String
KEY_TITLE
private static final String
KEY_ACTION_INTENT
private static final String
KEY_EXTRAS
private static final String
KEY_REMOTE_INPUTS
private static final Object
sExtrasLock
private static Field
sExtrasField
private static boolean
sExtrasFieldAccessFailed
private static final Object
sActionsLock
private static Class
sActionClass
private static Field
sActionsField
private static Field
sActionIconField
private static Field
sActionTitleField
private static Field
sActionIntentField
private static boolean
sActionsAccessFailed
Constructors Summary
Methods Summary
public static voidaddBigPictureStyle(NotificationBuilderWithBuilderAccessor b, java.lang.CharSequence bigContentTitle, boolean useSummary, java.lang.CharSequence summaryText, android.graphics.Bitmap bigPicture, android.graphics.Bitmap bigLargeIcon, boolean bigLargeIconSet)

        Notification.BigPictureStyle style = new Notification.BigPictureStyle(b.getBuilder())
            .setBigContentTitle(bigContentTitle)
            .bigPicture(bigPicture);
        if (bigLargeIconSet) {
            style.bigLargeIcon(bigLargeIcon);
        }
        if (useSummary) {
            style.setSummaryText(summaryText);
        }
    
public static voidaddBigTextStyle(NotificationBuilderWithBuilderAccessor b, java.lang.CharSequence bigContentTitle, boolean useSummary, java.lang.CharSequence summaryText, java.lang.CharSequence bigText)

        Notification.BigTextStyle style = new Notification.BigTextStyle(b.getBuilder())
            .setBigContentTitle(bigContentTitle)
            .bigText(bigText);
        if (useSummary) {
            style.setSummaryText(summaryText);
        }
    
public static voidaddInboxStyle(NotificationBuilderWithBuilderAccessor b, java.lang.CharSequence bigContentTitle, boolean useSummary, java.lang.CharSequence summaryText, java.util.ArrayList texts)

        Notification.InboxStyle style = new Notification.InboxStyle(b.getBuilder())
            .setBigContentTitle(bigContentTitle);
        if (useSummary) {
            style.setSummaryText(summaryText);
        }
        for (CharSequence text: texts) {
            style.addLine(text);
        }
    
public static android.util.SparseArraybuildActionExtrasMap(java.util.List actionExtrasList)
Return an SparseArray for action extras or null if none was needed.

        SparseArray<Bundle> actionExtrasMap = null;
        for (int i = 0, count = actionExtrasList.size(); i < count; i++) {
            Bundle actionExtras = actionExtrasList.get(i);
            if (actionExtras != null) {
                if (actionExtrasMap == null) {
                    actionExtrasMap = new SparseArray<Bundle>();
                }
                actionExtrasMap.put(i, actionExtras);
            }
        }
        return actionExtrasMap;
    
private static booleanensureActionReflectionReadyLocked()

        if (sActionsAccessFailed) {
            return false;
        }
        try {
            if (sActionsField == null) {
                sActionClass = Class.forName("android.app.Notification$Action");
                sActionIconField = sActionClass.getDeclaredField("icon");
                sActionTitleField = sActionClass.getDeclaredField("title");
                sActionIntentField = sActionClass.getDeclaredField("actionIntent");
                sActionsField = Notification.class.getDeclaredField("actions");
                sActionsField.setAccessible(true);
            }
        } catch (ClassNotFoundException e) {
            Log.e(TAG, "Unable to access notification actions", e);
            sActionsAccessFailed = true;
        } catch (NoSuchFieldException e) {
            Log.e(TAG, "Unable to access notification actions", e);
            sActionsAccessFailed = true;
        }
        return !sActionsAccessFailed;
    
public static NotificationCompatBase.ActiongetAction(android.app.Notification notif, int actionIndex, NotificationCompatBase.Action.Factory factory, RemoteInputCompatBase.RemoteInput.Factory remoteInputFactory)

        synchronized (sActionsLock) {
            try {
                Object actionObject = getActionObjectsLocked(notif)[actionIndex];
                Bundle actionExtras = null;
                Bundle extras = getExtras(notif);
                if (extras != null) {
                    SparseArray<Bundle> actionExtrasMap = extras.getSparseParcelableArray(
                            EXTRA_ACTION_EXTRAS);
                    if (actionExtrasMap != null) {
                        actionExtras = actionExtrasMap.get(actionIndex);
                    }
                }
                return readAction(factory, remoteInputFactory,
                        sActionIconField.getInt(actionObject),
                        (CharSequence) sActionTitleField.get(actionObject),
                        (PendingIntent) sActionIntentField.get(actionObject),
                        actionExtras);
            } catch (IllegalAccessException e) {
                Log.e(TAG, "Unable to access notification actions", e);
                sActionsAccessFailed = true;
            }
        }
        return null;
    
public static intgetActionCount(android.app.Notification notif)

        synchronized (sActionsLock) {
            Object[] actionObjects = getActionObjectsLocked(notif);
            return actionObjects != null ? actionObjects.length : 0;
        }
    
private static NotificationCompatBase.ActiongetActionFromBundle(android.os.Bundle bundle, NotificationCompatBase.Action.Factory actionFactory, RemoteInputCompatBase.RemoteInput.Factory remoteInputFactory)

        return actionFactory.build(
                bundle.getInt(KEY_ICON),
                bundle.getCharSequence(KEY_TITLE),
                bundle.<PendingIntent>getParcelable(KEY_ACTION_INTENT),
                bundle.getBundle(KEY_EXTRAS),
                RemoteInputCompatJellybean.fromBundleArray(
                        BundleUtil.getBundleArrayFromBundle(bundle, KEY_REMOTE_INPUTS),
                        remoteInputFactory));
    
private static java.lang.Object[]getActionObjectsLocked(android.app.Notification notif)

        synchronized (sActionsLock) {
            if (!ensureActionReflectionReadyLocked()) {
                return null;
            }
            try {
                return (Object[]) sActionsField.get(notif);
            } catch (IllegalAccessException e) {
                Log.e(TAG, "Unable to access notification actions", e);
                sActionsAccessFailed = true;
                return null;
            }
        }
    
public static NotificationCompatBase.Action[]getActionsFromParcelableArrayList(java.util.ArrayList parcelables, NotificationCompatBase.Action.Factory actionFactory, RemoteInputCompatBase.RemoteInput.Factory remoteInputFactory)

        if (parcelables == null) {
            return null;
        }
        NotificationCompatBase.Action[] actions = actionFactory.newArray(parcelables.size());
        for (int i = 0; i < actions.length; i++) {
            actions[i] = getActionFromBundle((Bundle) parcelables.get(i),
                    actionFactory, remoteInputFactory);
        }
        return actions;
    
private static android.os.BundlegetBundleForAction(NotificationCompatBase.Action action)

        Bundle bundle = new Bundle();
        bundle.putInt(KEY_ICON, action.getIcon());
        bundle.putCharSequence(KEY_TITLE, action.getTitle());
        bundle.putParcelable(KEY_ACTION_INTENT, action.getActionIntent());
        bundle.putBundle(KEY_EXTRAS, action.getExtras());
        bundle.putParcelableArray(KEY_REMOTE_INPUTS, RemoteInputCompatJellybean.toBundleArray(
                action.getRemoteInputs()));
        return bundle;
    
public static android.os.BundlegetExtras(android.app.Notification notif)
Get the extras Bundle from a notification using reflection. Extras were present in Jellybean notifications, but the field was private until KitKat.

        synchronized (sExtrasLock) {
            if (sExtrasFieldAccessFailed) {
                return null;
            }
            try {
                if (sExtrasField == null) {
                    Field extrasField = Notification.class.getDeclaredField("extras");
                    if (!Bundle.class.isAssignableFrom(extrasField.getType())) {
                        Log.e(TAG, "Notification.extras field is not of type Bundle");
                        sExtrasFieldAccessFailed = true;
                        return null;
                    }
                    extrasField.setAccessible(true);
                    sExtrasField = extrasField;
                }
                Bundle extras = (Bundle) sExtrasField.get(notif);
                if (extras == null) {
                    extras = new Bundle();
                    sExtrasField.set(notif, extras);
                }
                return extras;
            } catch (IllegalAccessException e) {
                Log.e(TAG, "Unable to access notification extras", e);
            } catch (NoSuchFieldException e) {
                Log.e(TAG, "Unable to access notification extras", e);
            }
            sExtrasFieldAccessFailed = true;
            return null;
        }
    
public static java.lang.StringgetGroup(android.app.Notification n)

        return getExtras(n).getString(EXTRA_GROUP_KEY);
    
public static booleangetLocalOnly(android.app.Notification notif)

        return getExtras(notif).getBoolean(EXTRA_LOCAL_ONLY);
    
public static java.util.ArrayListgetParcelableArrayListForActions(NotificationCompatBase.Action[] actions)

        if (actions == null) {
            return null;
        }
        ArrayList<Parcelable> parcelables = new ArrayList<Parcelable>(actions.length);
        for (NotificationCompatBase.Action action : actions) {
            parcelables.add(getBundleForAction(action));
        }
        return parcelables;
    
public static java.lang.StringgetSortKey(android.app.Notification n)

        return getExtras(n).getString(EXTRA_SORT_KEY);
    
public static booleanisGroupSummary(android.app.Notification n)

        return getExtras(n).getBoolean(EXTRA_GROUP_SUMMARY);
    
public static NotificationCompatBase.ActionreadAction(NotificationCompatBase.Action.Factory factory, RemoteInputCompatBase.RemoteInput.Factory remoteInputFactory, int icon, java.lang.CharSequence title, android.app.PendingIntent actionIntent, android.os.Bundle extras)

        RemoteInputCompatBase.RemoteInput[] remoteInputs = null;
        if (extras != null) {
            remoteInputs = RemoteInputCompatJellybean.fromBundleArray(
                    BundleUtil.getBundleArrayFromBundle(extras, EXTRA_REMOTE_INPUTS),
                    remoteInputFactory);
        }
        return factory.build(icon, title, actionIntent, extras, remoteInputs);
    
public static android.os.BundlewriteActionAndGetExtras(Notification.Builder builder, NotificationCompatBase.Action action)

        builder.addAction(action.getIcon(), action.getTitle(), action.getActionIntent());
        Bundle actionExtras = new Bundle(action.getExtras());
        if (action.getRemoteInputs() != null) {
            actionExtras.putParcelableArray(EXTRA_REMOTE_INPUTS,
                    RemoteInputCompatJellybean.toBundleArray(action.getRemoteInputs()));
        }
        return actionExtras;