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

Commit 6bf88a01 authored by Anthony Chen's avatar Anthony Chen
Browse files

Allow notification expansion to be toggleable.

Android Auto does not want notificaitons that have actions to be
expandable. Rather, they should always be in their expanded state. The
only exception to this are grouped notifications, which should be
collasped by default. They also can still be expanded.

Modify the code to allow this to be changed. In addition, modify some of
the animation so that the dividers so not flash when the notification
group is expanding.

There is also a change to bring the header of the notification to the
front so that the child notifications do not overlap it. This is because
in Auto, the app name and icon are not displayed in the header, but the
expand button is still there.

Test: booted on phone and Android Auto headunit.
Bug: 33210494
Change-Id: I0a121a0eaee6159ccea9961721abe92603484a17
parent 13dd7568
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -20,4 +20,4 @@
    android:id="@+id/notification_more_divider"
    android:layout_width="match_parent"
    android:layout_height="@dimen/notification_divider_height"
    android:background="#FF616161" />
    android:background="@color/notification_divider_color" />
+3 −0
Original line number Diff line number Diff line
@@ -78,6 +78,9 @@
    <!-- The color of the material notification background when low priority -->
    <color name="notification_material_background_low_priority_color">#fff5f5f5</color>

    <!-- The color of the dividing line between grouped notifications. -->
    <color name="notification_divider_color">#FF616161</color>

    <!-- The background color of the notification shade -->
    <color name="notification_shade_background_color">#ffeeeeee</color>

+26 −0
Original line number Diff line number Diff line
@@ -369,4 +369,30 @@
         has rounded corners, then the contents will be clipped to those corners. -->
    <bool name="config_clipNotificationsToOutline">false</bool>

    <!-- Whether or not notifications that can be expanded will always be in their expanded state.
         This value only affects notifications that are not a group of notifications from the same
         applications. If this value is false, then only the first notification will be expanded;
         the other notifications need to be manually expanded by the user. -->
    <bool name="config_alwaysExpandNonGroupedNotifications">false</bool>

    <!-- Whether or not an expandable notification can be manually expanded or collapsed by the
         user. Grouped notifications are still expandable even if this value is false. -->
    <bool name="config_enableNonGroupedNotificationExpand">true</bool>

    <!-- Whether or not there should be dividing lines between child notifications when the
         group has been expanded. -->
    <bool name="config_showDividersWhenGroupNotificationExpanded">false</bool>

    <!-- Whether or not the dividing lines should be shown when the container is expanding and
         collapsing. If this value is true, then the lines will only show when the container has
         been completely expanded. -->
    <bool name="config_hideDividersDuringExpand">false</bool>

    <!-- Whether or not child notifications that are part of a group will have shadows. -->
    <bool name="config_enableShadowOnChildNotifications">true</bool>

    <!-- Whether or not a view containing child notifications will have a custom background when
         it has been expanded to reveal its children. -->
    <bool name="config_showGroupNotificationBgWhenExpanded">false</bool>

</resources>
+13 −0
Original line number Diff line number Diff line
@@ -332,6 +332,19 @@
    <!-- The corner radius of the shadow behind the notification. -->
    <dimen name="notification_shadow_radius">0dp</dimen>

    <!-- The alpha of the dividing line between child notifications of a notification group. -->
    <item name="notification_divider_alpha" format="float" type="dimen">0.5</item>

    <!-- The height of the divider between the individual notifications in a notification
         group. -->
    <dimen name="notification_children_container_divider_height">@dimen/notification_divider_height</dimen>

    <!-- The height of the header for a container containing child notifications. -->
    <dimen name="notification_children_container_header_height">53dp</dimen>

    <!-- The top margin for the notification children container in its non-expanded form. -->
    <dimen name="notification_children_container_margin_top">@*android:dimen/notification_content_margin_top</dimen>

    <!-- The height of a notification header -->
    <dimen name="notification_header_height">53dp</dimen>

+24 −6
Original line number Diff line number Diff line
@@ -165,6 +165,18 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    private OnExpandClickListener mOnExpandClickListener;
    private boolean mGroupExpansionChanging;

    /**
     * Whether or not a notification that is not part of a group of notifications can be manually
     * expanded by the user.
     */
    private boolean mEnableNonGroupedNotificationExpand;

    /**
     * Whether or not to update the background of the header of the notification when its expanded.
     * If {@code true}, the header background will disappear when expanded.
     */
    private boolean mShowGroupBackgroundWhenExpanded;

    private OnClickListener mExpandClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
@@ -177,7 +189,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
                MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_GROUP_EXPANDER,
                        nowExpanded);
                onExpansionChanged(true /* userAction */, wasExpanded);
            } else {
            } else if (mEnableNonGroupedNotificationExpand) {
                if (v.isAccessibilityFocused()) {
                    mPrivateLayout.setFocusOnVisibilityChange();
                }
@@ -1141,7 +1153,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    }

    public interface ExpansionLogger {
        public void logNotificationExpansion(String key, boolean userAction, boolean expanded);
        void logNotificationExpansion(String key, boolean userAction, boolean expanded);
    }

    public ExpandableNotificationRow(Context context, AttributeSet attrs) {
@@ -1164,11 +1176,16 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        mMaxHeadsUpHeight = getFontScaledHeight(R.dimen.notification_max_heads_up_height);
        mMaxHeadsUpHeightIncreased = getFontScaledHeight(
                R.dimen.notification_max_heads_up_height_increased);

        Resources res = getResources();
        mIncreasedPaddingBetweenElements = res.getDimensionPixelSize(
                R.dimen.notification_divider_height_increased);
        mIconTransformContentShiftNoIcon = res.getDimensionPixelSize(
                R.dimen.notification_icon_transform_content_shift);
        mEnableNonGroupedNotificationExpand =
                res.getBoolean(R.bool.config_enableNonGroupedNotificationExpand);
        mShowGroupBackgroundWhenExpanded =
                res.getBoolean(R.bool.config_showGroupNotificationBgWhenExpanded);
    }

    /**
@@ -1384,7 +1401,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        if (mIsSummaryWithChildren && !mShowingPublic) {
            return !mChildrenExpanded;
        }
        return mExpandable;
        return mEnableNonGroupedNotificationExpand && mExpandable;
    }

    public void setExpandable(boolean expandable) {
@@ -1974,7 +1991,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    public void updateBackgroundForGroupState() {
        if (mIsSummaryWithChildren) {
            // Only when the group has finished expanding do we hide its background.
            mShowNoBackground = isGroupExpanded() && !isGroupExpansionChanging() && !isUserLocked();
            mShowNoBackground = !mShowGroupBackgroundWhenExpanded && isGroupExpanded()
                    && !isGroupExpansionChanging() && !isUserLocked();
            mChildrenContainer.updateHeaderForExpansion(mShowNoBackground);
            List<ExpandableNotificationRow> children = mChildrenContainer.getNotificationChildren();
            for (int i = 0; i < children.size(); i++) {
@@ -1983,7 +2001,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        } else if (isChildInGroup()) {
            final int childColor = getShowingLayout().getBackgroundColorForExpansionState();
            // Only show a background if the group is expanded OR if it is expanding / collapsing
            // and has a custom background color
            // and has a custom background color.
            final boolean showBackground = isGroupExpanded()
                    || ((mNotificationParent.isGroupExpansionChanging()
                    || mNotificationParent.isUserLocked()) && childColor != 0);
Loading