Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 08ff158a authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Notif redesign: Don't apply effects to app icons

In order to know if we're showing the app icon from places where we
can't inject NotificationIconStyleProvider, I added a property to
ExpandableNotificationRow. It's not ideal that now the
shouldShowAppIcon getter has side effects, but it's better than
attempting an overly complex solution to be able to access
NotificationRowIconView otherwise.

Bug: 371174789
Test: tested manually that e.g. icons in grouped messaging notifications
from Notify aren't greyed out
Flag: android.app.notifications_redesign_app_icons

Change-Id: I632daa937f237aa7bea22b9e7fd84939be1a5a34
parent c36a6daa
Loading
Loading
Loading
Loading
+39 −18
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar;

import android.app.Flags;
import android.app.Notification;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
@@ -60,20 +61,6 @@ public class NotificationGroupingUtil {
            return row.getEntry().getSbn().getNotification();
        }
    };
    private static final IconComparator ICON_VISIBILITY_COMPARATOR = new IconComparator() {
        public boolean compare(View parent, View child, Object parentData,
                Object childData) {
            return hasSameIcon(parentData, childData)
                    && hasSameColor(parentData, childData);
        }
    };
    private static final IconComparator GREY_COMPARATOR = new IconComparator() {
        public boolean compare(View parent, View child, Object parentData,
                Object childData) {
            return !hasSameIcon(parentData, childData)
                    || hasSameColor(parentData, childData);
        }
    };
    private static final ResultApplicator GREY_APPLICATOR = new ResultApplicator() {
        @Override
        public void apply(View parent, View view, boolean apply, boolean reset) {
@@ -90,34 +77,58 @@ public class NotificationGroupingUtil {

    public NotificationGroupingUtil(ExpandableNotificationRow row) {
        mRow = row;

        final IconComparator iconVisibilityComparator = new IconComparator(mRow) {
            public boolean compare(View parent, View child, Object parentData,
                    Object childData) {
                return hasSameIcon(parentData, childData)
                        && hasSameColor(parentData, childData);
            }
        };
        final IconComparator greyComparator = new IconComparator(mRow) {
            public boolean compare(View parent, View child, Object parentData,
                    Object childData) {
                if (Flags.notificationsRedesignAppIcons() && mRow.isShowingAppIcon()) {
                    return false;
                }
                return !hasSameIcon(parentData, childData)
                        || hasSameColor(parentData, childData);
            }
        };

        // To hide the icons if they are the same and the color is the same
        mProcessors.add(new Processor(mRow,
                com.android.internal.R.id.icon,
                ICON_EXTRACTOR,
                ICON_VISIBILITY_COMPARATOR,
                iconVisibilityComparator,
                VISIBILITY_APPLICATOR));
        // To grey them out the icons and expand button when the icons are not the same
        // To grey out the icons when they are not the same, or they have the same color
        mProcessors.add(new Processor(mRow,
                com.android.internal.R.id.status_bar_latest_event_content,
                ICON_EXTRACTOR,
                GREY_COMPARATOR,
                greyComparator,
                GREY_APPLICATOR));
        // To show the large icon on the left side instead if all the small icons are the same
        mProcessors.add(new Processor(mRow,
                com.android.internal.R.id.status_bar_latest_event_content,
                ICON_EXTRACTOR,
                ICON_VISIBILITY_COMPARATOR,
                iconVisibilityComparator,
                LEFT_ICON_APPLICATOR));
        // To only show the work profile icon in the group header
        mProcessors.add(new Processor(mRow,
                com.android.internal.R.id.profile_badge,
                null /* Extractor */,
                BADGE_COMPARATOR,
                VISIBILITY_APPLICATOR));
        // To hide the app name in group children
        mProcessors.add(new Processor(mRow,
                com.android.internal.R.id.app_name_text,
                null,
                APP_NAME_COMPARATOR,
                APP_NAME_APPLICATOR));
        // To hide the header text if it's the same
        mProcessors.add(Processor.forTextView(mRow, com.android.internal.R.id.header_text));

        mDividers.add(com.android.internal.R.id.header_text_divider);
        mDividers.add(com.android.internal.R.id.header_text_secondary_divider);
        mDividers.add(com.android.internal.R.id.time_divider);
@@ -261,6 +272,7 @@ public class NotificationGroupingUtil {
            mParentData = mExtractor == null ? null : mExtractor.extractData(mParentRow);
            mApply = !mComparator.isEmpty(mParentView);
        }

        public void compareToGroupParent(ExpandableNotificationRow row) {
            if (!mApply) {
                return;
@@ -356,12 +368,21 @@ public class NotificationGroupingUtil {
    }

    private abstract static class IconComparator implements ViewComparator {
        private final ExpandableNotificationRow mRow;

        IconComparator(ExpandableNotificationRow row) {
            mRow = row;
        }

        @Override
        public boolean compare(View parent, View child, Object parentData, Object childData) {
            return false;
        }

        protected boolean hasSameIcon(Object parentData, Object childData) {
            if (Flags.notificationsRedesignAppIcons() && mRow.isShowingAppIcon()) {
                return true;
            }
            Icon parentIcon = getIcon((Notification) parentData);
            Icon childIcon = getIcon((Notification) childData);
            return parentIcon.sameAs(childIcon);
+19 −0
Original line number Diff line number Diff line
@@ -262,6 +262,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
     */
    private boolean mIsHeadsUp;

    /**
     * Whether or not the notification is showing the app icon instead of the small icon.
     */
    private boolean mIsShowingAppIcon;

    private boolean mLastChronometerRunning = true;
    private ViewStub mChildrenContainerStub;
    private GroupMembershipManager mGroupMembershipManager;
@@ -816,6 +821,20 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        }
    }

    /**
     * Indicate that the notification is showing the app icon instead of the small icon.
     */
    public void setIsShowingAppIcon(boolean isShowingAppIcon) {
        mIsShowingAppIcon = isShowingAppIcon;
    }

    /**
     * Whether or not the notification is showing the app icon instead of the small icon.
     */
    public boolean isShowingAppIcon() {
        return mIsShowingAppIcon;
    }

    @Override
    public boolean showingPulsing() {
        return isHeadsUpState() && (isDozing() || (mOnKeyguard && isBypassEnabled()));
+20 −12
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.View
import com.android.internal.widget.NotificationRowIconView
import com.android.internal.widget.NotificationRowIconView.NotificationIconProvider
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.NotifRemoteViewsFactory
import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder
@@ -47,20 +48,27 @@ constructor(
        return when (name) {
            NotificationRowIconView::class.java.name ->
                NotificationRowIconView(context, attrs).also { view ->
                    view.setIconProvider(createIconProvider(row, context))
                }
            else -> null
        }
    }

    private fun createIconProvider(
        row: ExpandableNotificationRow,
        context: Context,
    ): NotificationIconProvider {
        val sbn = row.entry.sbn
                    view.setIconProvider(
                        object : NotificationRowIconView.NotificationIconProvider {
        return object : NotificationIconProvider {
            override fun shouldShowAppIcon(): Boolean {
                                return iconStyleProvider.shouldShowAppIcon(row.entry.sbn, context)
                val shouldShowAppIcon = iconStyleProvider.shouldShowAppIcon(row.entry.sbn, context)
                row.setIsShowingAppIcon(shouldShowAppIcon)
                return shouldShowAppIcon
            }

            override fun getAppIcon(): Drawable {
                return appIconProvider.getOrFetchAppIcon(sbn.packageName, context)
            }
        }
                    )
                }
            else -> null
        }
    }
}