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

Commit 6f96b0b7 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Fix HUNs

* Add and prefer a heads up template which is
  the base template + actions
* When a HUN shows a template with a header,
  only allow hiding that header if there is
  no large icon to avoid a visual mess.

Bug: 163626038
Test: manual
Change-Id: Ia42e0a6b1b1ecd4dd438a817f9442a838a2bdb5c
parent 41cdfc0a
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -384,6 +384,7 @@ public class Notification implements Parcelable
    private static final ArraySet<Integer> STANDARD_LAYOUTS = new ArraySet<>();
    static {
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_base);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_heads_up_base);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_base);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_picture);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_text);
@@ -4876,7 +4877,8 @@ public class Notification implements Parcelable

        private RemoteViews applyStandardTemplate(int resId, StandardTemplateParams p,
                TemplateBindResult result) {
            p.headerless(resId == getBaseLayoutResource());
            p.headerless(resId == getBaseLayoutResource()
                    || resId == getHeadsUpBaseLayoutResource());
            RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId);

            resetStandardTemplate(contentView);
@@ -5144,10 +5146,7 @@ public class Notification implements Parcelable
            if (mN.mLargeIcon == null && mN.largeIcon != null) {
                mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon);
            }
            // Hide the large icon in Heads Up view, because the icon is partly within header,
            // which for HUNs will be hidden and cropped.
            boolean showLargeIcon = mN.mLargeIcon != null && !p.hideLargeIcon
                    && p.mViewType != StandardTemplateParams.VIEW_TYPE_HEADS_UP;
            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);
@@ -5610,7 +5609,7 @@ public class Notification implements Parcelable
                    .viewType(StandardTemplateParams.VIEW_TYPE_HEADS_UP)
                    .fillTextsFrom(this)
                    .setMaxRemoteInputHistory(1);
            return applyStandardTemplateWithActions(getBigBaseLayoutResource(),
            return applyStandardTemplateWithActions(getHeadsUpBaseLayoutResource(),
                    p,
                    null /* result */);
        }
@@ -6168,6 +6167,10 @@ public class Notification implements Parcelable
            return R.layout.notification_template_material_base;
        }

        private int getHeadsUpBaseLayoutResource() {
            return R.layout.notification_template_material_heads_up_base;
        }

        private int getBigBaseLayoutResource() {
            return R.layout.notification_template_material_big_base;
        }
@@ -7088,6 +7091,7 @@ public class Notification implements Parcelable
        @Override
        public RemoteViews makeHeadsUpContentView(boolean increasedHeight) {
            if (increasedHeight && mBuilder.mActions.size() > 0) {
                // TODO(b/163626038): pass VIEW_TYPE_HEADS_UP?
                return makeBigContentView();
            }
            return super.makeHeadsUpContentView(increasedHeight);
@@ -8657,7 +8661,7 @@ public class Notification implements Parcelable
            }
            TemplateBindResult result = new TemplateBindResult();
            RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions(
                    mBuilder.getBigBaseLayoutResource(),
                    mBuilder.getHeadsUpBaseLayoutResource(),
                    StandardTemplateParams.VIEW_TYPE_HEADS_UP, result);
            buildIntoRemoteViewContent(remoteViews, headsUpContentView, result, false);
            return remoteViews;
+54 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ Copyright (C) 2014 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:orientation="vertical"
    android:clipChildren="false"
    android:tag="headsUp"
    >

    <LinearLayout
        android:id="@+id/notification_action_list_margin_target"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/notification_action_list_height"
        android:orientation="vertical"
        >

        <include layout="@layout/notification_template_material_base" />

        <ViewStub
            android:layout="@layout/notification_material_reply_text"
            android:id="@+id/notification_material_reply_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />

        <include
            layout="@layout/notification_template_smart_reply_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/notification_content_margin_start"
            android:layout_marginEnd="@dimen/notification_content_margin_end"
            android:layout_marginTop="@dimen/notification_content_margin"
            />

        <include layout="@layout/notification_material_action_list" />
    </LinearLayout>
</FrameLayout>
+1 −0
Original line number Diff line number Diff line
@@ -2184,6 +2184,7 @@
  <java-symbol type="layout" name="notification_material_action_list" />
  <java-symbol type="layout" name="notification_material_action_tombstone" />
  <java-symbol type="layout" name="notification_template_material_base" />
  <java-symbol type="layout" name="notification_template_material_heads_up_base" />
  <java-symbol type="layout" name="notification_template_material_big_base" />
  <java-symbol type="layout" name="notification_template_material_big_picture" />
  <java-symbol type="layout" name="notification_template_material_inbox" />
+9 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.statusbar.notification.row.wrapper;

import static android.view.View.VISIBLE;

import static com.android.systemui.statusbar.notification.row.ExpandableNotificationRow.DEFAULT_HEADER_VISIBLE_AMOUNT;

import android.app.PendingIntent;
@@ -61,6 +63,7 @@ public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapp
    private ArraySet<PendingIntent> mCancelledPendingIntents = new ArraySet<>();
    private UiOffloadThread mUiOffloadThread;
    private View mRemoteInputHistory;
    private boolean mCanHideHeader;
    private float mHeaderTranslation;

    protected NotificationTemplateViewWrapper(Context ctx, View view,
@@ -236,6 +239,10 @@ public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapp
        // the transformation types and we need to have our values set by then.
        resolveTemplateViews(row.getEntry().getSbn());
        super.onContentUpdated(row);
        // With the modern templates, a large icon visually overlaps the header, so we can't
        // simply hide the header -- just show the
        mCanHideHeader = mNotificationHeader != null
                && (mPicture == null || mPicture.getVisibility() != VISIBLE);
        if (row.getHeaderVisibleAmount() != DEFAULT_HEADER_VISIBLE_AMOUNT) {
            setHeaderVisibleAmount(row.getHeaderVisibleAmount());
        }
@@ -294,14 +301,14 @@ public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapp

    @Override
    public int getHeaderTranslation(boolean forceNoHeader) {
        return forceNoHeader ? mFullHeaderTranslation : (int) mHeaderTranslation;
        return forceNoHeader && mCanHideHeader ? mFullHeaderTranslation : (int) mHeaderTranslation;
    }

    @Override
    public void setHeaderVisibleAmount(float headerVisibleAmount) {
        super.setHeaderVisibleAmount(headerVisibleAmount);
        float headerTranslation = 0f;
        if (mNotificationHeader != null) {
        if (mCanHideHeader && mNotificationHeader != null) {
            mNotificationHeader.setAlpha(headerVisibleAmount);
            headerTranslation = (1.0f - headerVisibleAmount) * mFullHeaderTranslation;
        }