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

Commit 00be88f1 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

New pulsing notification layout

Test: wake up with power
Test: look at shelf on lock screen
Test: lock device w/ notifications from home screen
Test: receive notification on AOD
Test: atest KeyguardClockPositionAlgorithmTest
Test: atest NotificationRoundnessManagerTest
Test: atest ScrimControllerTest
Test: atest NotificationContentViewTest
Bug: 111405682
Change-Id: I9b4f2febd56a62256124567bffebc9f5f8255847
parent 3d36dd83
Loading
Loading
Loading
Loading
+26 −77
Original line number Diff line number Diff line
@@ -384,9 +384,7 @@ public class Notification implements Parcelable
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_messaging);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_media);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_media);
        STANDARD_LAYOUTS.add(R.layout.notification_template_ambient_header);
        STANDARD_LAYOUTS.add(R.layout.notification_template_header);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_ambient);
    }

    /**
@@ -4570,9 +4568,7 @@ public class Notification implements Parcelable
            if (p.title != null) {
                contentView.setViewVisibility(R.id.title, View.VISIBLE);
                contentView.setTextViewText(R.id.title, processTextSpans(p.title));
                if (!p.ambient) {
                setTextViewColorPrimary(contentView, R.id.title, p);
                }
                contentView.setViewLayoutWidth(R.id.title, showProgress
                        ? ViewGroup.LayoutParams.WRAP_CONTENT
                        : ViewGroup.LayoutParams.MATCH_PARENT);
@@ -4581,9 +4577,7 @@ public class Notification implements Parcelable
                int textId = showProgress ? com.android.internal.R.id.text_line_1
                        : com.android.internal.R.id.text;
                contentView.setTextViewText(textId, processTextSpans(p.text));
                if (!p.ambient) {
                setTextViewColorSecondary(contentView, textId, p);
                }
                contentView.setViewVisibility(textId, View.VISIBLE);
            }

@@ -4842,7 +4836,7 @@ public class Notification implements Parcelable
            if (mN.mLargeIcon == null && mN.largeIcon != null) {
                mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon);
            }
            boolean showLargeIcon = mN.mLargeIcon != null && !p.hideLargeIcon && !p.ambient;
            boolean showLargeIcon = mN.mLargeIcon != null && !p.hideLargeIcon;
            if (showLargeIcon) {
                contentView.setViewVisibility(R.id.right_icon, View.VISIBLE);
                contentView.setImageViewIcon(R.id.right_icon, mN.mLargeIcon);
@@ -4856,7 +4850,7 @@ public class Notification implements Parcelable
         * @return if the reply icon is visible
         */
        private boolean bindReplyIcon(RemoteViews contentView, StandardTemplateParams p) {
            boolean actionVisible = !p.hideReplyIcon && !p.ambient;
            boolean actionVisible = !p.hideReplyIcon;
            Action action = null;
            if (actionVisible) {
                action = findReplyAction();
@@ -4896,21 +4890,18 @@ public class Notification implements Parcelable
        private void bindNotificationHeader(RemoteViews contentView, StandardTemplateParams p) {
            bindSmallIcon(contentView, p);
            bindHeaderAppName(contentView, p);
            if (!p.ambient) {
                // Ambient view does not have these
            bindHeaderText(contentView, p);
            bindHeaderTextSecondary(contentView, p);
            bindHeaderChronometerAndTime(contentView, p);
            bindProfileBadge(contentView, p);
            bindAlertedIcon(contentView, p);
            }
            bindActivePermissions(contentView, p);
            bindExpandButton(contentView, p);
            mN.mUsesStandardHeader = true;
        }

        private void bindActivePermissions(RemoteViews contentView, StandardTemplateParams p) {
            int color = p.ambient ? resolveAmbientColor(p) : getNeutralColor(p);
            int color = getNeutralColor(p);
            contentView.setDrawableTint(R.id.camera, false, color, PorterDuff.Mode.SRC_ATOP);
            contentView.setDrawableTint(R.id.mic, false, color, PorterDuff.Mode.SRC_ATOP);
            contentView.setDrawableTint(R.id.overlay, false, color, PorterDuff.Mode.SRC_ATOP);
@@ -5021,13 +5012,12 @@ public class Notification implements Parcelable
            if (isColorized(p)) {
                setTextViewColorPrimary(contentView, R.id.app_name_text, p);
            } else {
                contentView.setTextColor(R.id.app_name_text,
                        p.ambient ? resolveAmbientColor(p) : getSecondaryTextColor(p));
                contentView.setTextColor(R.id.app_name_text, getSecondaryTextColor(p));
            }
        }

        private boolean isColorized(StandardTemplateParams p) {
            return p.allowColorization && !p.ambient && mN.isColorized();
            return p.allowColorization && mN.isColorized();
        }

        private void bindSmallIcon(RemoteViews contentView, StandardTemplateParams p) {
@@ -5097,7 +5087,7 @@ public class Notification implements Parcelable
            List<Notification.Action> nonContextualActions = filterOutContextualActions(mActions);

            int N = nonContextualActions.size();
            boolean emphazisedMode = mN.fullScreenIntent != null && !p.ambient;
            boolean emphazisedMode = mN.fullScreenIntent != null;
            big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode);
            if (N > 0) {
                big.setViewVisibility(R.id.actions_container, View.VISIBLE);
@@ -5122,7 +5112,7 @@ public class Notification implements Parcelable
            }

            CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY);
            if (!p.ambient && validRemoteInput && replyText != null
            if (validRemoteInput && replyText != null
                    && replyText.length > 0 && !TextUtils.isEmpty(replyText[0])
                    && p.maxRemoteInputHistory > 0) {
                boolean showSpinner = mN.extras.getBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER);
@@ -5239,11 +5229,10 @@ public class Notification implements Parcelable
         * Construct a RemoteViews for the final notification header only. This will not be
         * colorized.
         *
         * @param ambient if true, generate the header for the ambient display layout.
         * @hide
         */
        public RemoteViews makeNotificationHeader(boolean ambient) {
            return makeNotificationHeader(mParams.reset().ambient(ambient).fillTextsFrom(this));
        public RemoteViews makeNotificationHeader() {
            return makeNotificationHeader(mParams.reset().fillTextsFrom(this));
        }

        /**
@@ -5256,8 +5245,7 @@ public class Notification implements Parcelable
            // Headers on their own are never colorized
            p.disallowColorization();
            RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(),
                    p.ambient ? R.layout.notification_template_ambient_header
                            : R.layout.notification_template_header);
                    R.layout.notification_template_header);
            resetNotificationHeader(header);
            bindNotificationHeader(header, p);
            return header;
@@ -5269,11 +5257,7 @@ public class Notification implements Parcelable
         * @hide
         */
        public RemoteViews makeAmbientNotification() {
            RemoteViews ambient = applyStandardTemplateWithActions(
                    R.layout.notification_template_material_ambient,
                    mParams.reset().ambient(true).fillTextsFrom(this).hasProgress(false),
                    null /* result */);
            return ambient;
            return createHeadsUpContentView(false /* increasedHeight */);
        }

        private void hideLine1Text(RemoteViews result) {
@@ -5377,14 +5361,8 @@ public class Notification implements Parcelable
            }
            mN.extras = publicExtras;
            RemoteViews view;
            if (ambient) {
                publicExtras.putCharSequence(EXTRA_TITLE,
                        mContext.getString(com.android.internal.R.string.notification_hidden_text));
                view = makeAmbientNotification();
            } else{
                view = makeNotificationHeader(false /* ambient */);
            view = makeNotificationHeader();
            view.setBoolean(R.id.notification_header, "setExpandOnlyOnButton", true);
            }
            mN.extras = savedBundle;
            mN.mLargeIcon = largeIcon;
            mN.largeIcon = largeIconLegacy;
@@ -5404,7 +5382,6 @@ public class Notification implements Parcelable
        public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) {
            StandardTemplateParams p = mParams.reset()
                    .forceDefaultColor()
                    .ambient(false)
                    .fillTextsFrom(this);
            if (!useRegularSubtext || TextUtils.isEmpty(mParams.summaryText)) {
                p.summaryText(createSummaryText());
@@ -5495,8 +5472,7 @@ public class Notification implements Parcelable
                if (isColorized(p)) {
                    setTextViewColorPrimary(button, R.id.action0, p);
                } else if (getRawColor(p) != COLOR_DEFAULT && mTintActionButtons) {
                    button.setTextColor(R.id.action0,
                            p.ambient ? resolveAmbientColor(p) : resolveContrastColor(p));
                    button.setTextColor(R.id.action0, resolveContrastColor(p));
                }
            }
            button.setIntTag(R.id.action0, R.id.notification_action_index_tag,
@@ -5589,13 +5565,8 @@ public class Notification implements Parcelable
        }

        private CharSequence processLegacyText(CharSequence charSequence) {
            return processLegacyText(charSequence, false /* ambient */);
        }

        private CharSequence processLegacyText(CharSequence charSequence, boolean ambient) {
            boolean isAlreadyLightText = isLegacy() || textColorsNeedInversion();
            boolean wantLightText = ambient;
            if (isAlreadyLightText != wantLightText) {
            if (isAlreadyLightText) {
                return getColorUtil().invertCharSequenceColors(charSequence);
            } else {
                return charSequence;
@@ -5609,9 +5580,7 @@ public class Notification implements Parcelable
                StandardTemplateParams p) {
            boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon);
            int color;
            if (p.ambient) {
                color = resolveAmbientColor(p);
            } else if (isColorized(p)) {
            if (isColorized(p)) {
                color = getPrimaryTextColor(p);
            } else {
                color = resolveContrastColor(p);
@@ -5698,17 +5667,6 @@ public class Notification implements Parcelable
            return mNeutralColor;
        }

        int resolveAmbientColor(StandardTemplateParams p) {
            int rawColor = getRawColor(p);
            if (mCachedAmbientColorIsFor == rawColor && mCachedAmbientColorIsFor != COLOR_INVALID) {
                return mCachedAmbientColor;
            }
            final int contrasted = ContrastColorUtil.resolveAmbientColor(mContext, rawColor);

            mCachedAmbientColorIsFor = rawColor;
            return mCachedAmbientColor = contrasted;
        }

        /**
         * Apply the unstyled operations and return a new {@link Notification} object.
         * @hide
@@ -10144,7 +10102,6 @@ public class Notification implements Parcelable

    private static class StandardTemplateParams {
        boolean hasProgress = true;
        boolean ambient = false;
        CharSequence title;
        CharSequence text;
        CharSequence headerTextSecondary;
@@ -10157,7 +10114,6 @@ public class Notification implements Parcelable

        final StandardTemplateParams reset() {
            hasProgress = true;
            ambient = false;
            title = null;
            text = null;
            summaryText = null;
@@ -10213,22 +10169,15 @@ public class Notification implements Parcelable
            return this;
        }

        final StandardTemplateParams ambient(boolean ambient) {
            Preconditions.checkState(title == null && text == null, "must set ambient before text");
            this.ambient = ambient;
            return this;
        }

        final StandardTemplateParams fillTextsFrom(Builder b) {
            Bundle extras = b.mN.extras;
            this.title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE), ambient);
            this.title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE));

            // Big text notifications should contain their content when viewed in ambient mode.
            CharSequence text = extras.getCharSequence(EXTRA_BIG_TEXT);
            if (!ambient || TextUtils.isEmpty(text)) {
            if (TextUtils.isEmpty(text)) {
                text = extras.getCharSequence(EXTRA_TEXT);
            }
            this.text = b.processLegacyText(text, ambient);
            this.text = b.processLegacyText(text);
            this.summaryText = extras.getCharSequence(EXTRA_SUB_TEXT);
            return this;
        }
+0 −28
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2017 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<!-- hack to work around <include /> not being supported at the top level -->
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingStart="@dimen/notification_extra_margin_ambient"
    android:paddingEnd="@dimen/notification_extra_margin_ambient"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <include
        layout="@layout/notification_template_header"
        android:theme="@style/Theme.DeviceDefault.Notification.Ambient"/>
</FrameLayout>
+0 −94
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2017 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/status_bar_latest_event_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:tag="ambient"
    android:paddingStart="@dimen/notification_extra_margin_ambient"
    android:paddingEnd="@dimen/notification_extra_margin_ambient"
    >
    <include layout="@layout/notification_template_ambient_header"
             android:theme="@style/Theme.DeviceDefault.Notification.Ambient" />

    <LinearLayout
            android:id="@+id/notification_action_list_margin_target"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="top"
            android:layout_marginTop="@dimen/notification_content_margin_top"
            android:layout_marginBottom="@dimen/notification_action_list_height"
            android:paddingTop="4dp"
            android:paddingBottom="6dp"
            android:clipToPadding="false"
            android:orientation="vertical">

        <LinearLayout
            android:id="@+id/notification_main_column"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:layout_weight="1"
            android:paddingStart="@dimen/notification_content_margin_start"
            android:paddingEnd="@dimen/notification_content_margin_end"
            android:clipToPadding="false"
            android:minHeight="@dimen/notification_min_content_height"
            android:orientation="vertical"
            >
            <TextView android:id="@+id/title"
                android:textAppearance="@style/TextAppearance.DeviceDefault.Notification.Title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="top|center_horizontal"
                android:singleLine="true"
                android:ellipsize="marquee"
                android:fadingEdge="horizontal"
                android:textSize="@dimen/notification_ambient_title_text_size"
                android:textColor="#ffffffff"
            />
            <TextView android:id="@+id/text"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:textAppearance="@style/TextAppearance.DeviceDefault.Notification"
                android:singleLine="false"
                android:layout_weight="1"
                android:gravity="top|center_horizontal"
                android:visibility="gone"
                android:textSize="@dimen/notification_ambient_text_size"
                android:textColor="#eeffffff"
                android:layout_marginTop="4dp"
                android:ellipsize="end"
                android:maxLines="3"
            />
        </LinearLayout>
        <FrameLayout android:id="@+id/actions_container"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_gravity="bottom">
            <com.android.internal.widget.NotificationActionListLayout
                android:id="@+id/actions"
                android:layout_width="match_parent"
                android:layout_height="@dimen/notification_action_list_height"
                android:paddingEnd="4dp"
                android:orientation="horizontal"
                android:gravity="center"
                android:visibility="gone"
            />
        </FrameLayout>
    </LinearLayout>
</FrameLayout>
+0 −11
Original line number Diff line number Diff line
@@ -194,9 +194,6 @@
    <!-- The margin for text at the end of the image view for media notifications -->
    <dimen name="notification_media_image_margin_end">72dp</dimen>

    <!-- The additional margin on the sides of the ambient view. -->
    <dimen name="notification_extra_margin_ambient">16dp</dimen>

    <!-- The height of the notification action list -->
    <dimen name="notification_action_list_height">60dp</dimen>

@@ -233,9 +230,6 @@
    <!-- The bottom padding for the notification header -->
    <dimen name="notification_header_padding_bottom">16dp</dimen>

    <!-- The margin at the top of the notification header when dozing. -->
    <dimen name="notification_header_margin_top_ambient">3dp</dimen>

    <!-- The margin at the bottom of the notification header. -->
    <dimen name="notification_header_margin_bottom">0dp</dimen>

@@ -400,11 +394,6 @@
    <dimen name="notification_title_text_size">14sp</dimen>
    <!-- Size of smaller notification text (see TextAppearance.StatusBar.EventContent.Line2, Info, Time) -->
    <dimen name="notification_subtext_size">12sp</dimen>
    <!-- Size of notification text (see TextAppearance.StatusBar.EventContent) -->
    <dimen name="notification_ambient_text_size">16sp</dimen>
    <!-- Size of notification text titles (see TextAppearance.StatusBar.EventContent.Title) -->
    <dimen name="notification_ambient_title_text_size">24sp</dimen>

    <!-- Top padding for notifications in the standard layout. -->
    <dimen name="notification_top_pad">10dp</dimen>

+0 −3
Original line number Diff line number Diff line
@@ -271,9 +271,6 @@ easier.
    <style name="TextAppearance.DeviceDefault.Notification.Info" parent="TextAppearance.Material.Notification.Info">
        <item name="fontFamily">@string/config_bodyFontFamily</item>
    </style>
    <style name="TextAppearance.DeviceDefault.Notification.Info.Ambient" parent="TextAppearance.Material.Notification.Info.Ambient">
        <item name="fontFamily">@string/config_bodyFontFamily</item>
    </style>
    <style name="TextAppearance.DeviceDefault.Widget" parent="TextAppearance.Material.Widget">
        <item name="fontFamily">@string/config_bodyFontFamily</item>
    </style>
Loading