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

Commit dc81adf3 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Reduce notification minimized height

Bug: 163626038
Test: manual
Change-Id: Ic5e94389f2f41eebcecc8df393ff2f26c1d7e426
parent 87257cbb
Loading
Loading
Loading
Loading
+81 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.
 */

package com.android.internal.widget;

import android.annotation.Nullable;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.RemoteViews;

/**
 * This custom subclass of FrameLayout enforces that its calculated height be no larger than the
 * standard height of a notification.  This is not required in the normal case, as the
 * NotificationContentView gets this same value from the ExpandableNotificationRow, and enforces it
 * as a maximum.  It is required in the case of the HUN version of the headerless notification,
 * because that style puts the actions below the headerless portion.  If we don't cap this, then in
 * certain situations (larger fonts, decorated custom views) the contents of the headerless
 * notification push on the margins and increase the size of that view, which causes the actions to
 * be cropped on the bottom by the HUN notification max height.
 */
@RemoteViews.RemoteView
public class NotificationMaxHeightFrameLayout extends FrameLayout {
    private final int mNotificationMaxHeight;

    public NotificationMaxHeightFrameLayout(Context context) {
        this(context, null, 0, 0);
    }

    public NotificationMaxHeightFrameLayout(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0, 0);
    }

    public NotificationMaxHeightFrameLayout(Context context, @Nullable AttributeSet attrs,
            int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public NotificationMaxHeightFrameLayout(Context context, AttributeSet attrs, int defStyleAttr,
            int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        // `notification_min_height` refers to "minimized" not "minimum"; it is a max height
        mNotificationMaxHeight = getFontScaledHeight(mContext,
                com.android.internal.R.dimen.notification_min_height);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (MeasureSpec.getSize(heightMeasureSpec) > mNotificationMaxHeight) {
            final int mode = MeasureSpec.getMode(heightMeasureSpec);
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(mNotificationMaxHeight, mode);
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    /**
     * NOTE: This is copied from com.android.systemui.statusbar.notification.NotificationUtils
     *
     * @param dimenId the dimen to look up
     * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
     */
    private static int getFontScaledHeight(Context context, int dimenId) {
        final int dimensionPixelSize = context.getResources().getDimensionPixelSize(dimenId);
        final float factor = Math.max(1.0f, context.getResources().getDisplayMetrics().scaledDensity
                / context.getResources().getDisplayMetrics().density);
        return (int) (dimensionPixelSize * factor);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
  ~ limitations under the License
  -->

<FrameLayout
<com.android.internal.widget.NotificationMaxHeightFrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/status_bar_latest_event_content"
    android:layout_width="match_parent"
@@ -125,4 +125,4 @@

    </FrameLayout>

</FrameLayout>
</com.android.internal.widget.NotificationMaxHeightFrameLayout>
+29 −18
Original line number Diff line number Diff line
@@ -23,15 +23,25 @@
    android:tag="headsUp"
    >

    <LinearLayout
        android:id="@+id/notification_action_list_margin_target"
    <com.android.internal.widget.RemeasuringLinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/notification_action_list_height"
        android:clipChildren="false"
        android:orientation="vertical"
        >

        <include layout="@layout/notification_template_material_base" />
        <include
            layout="@layout/notification_template_material_base"
            android:id="@null"
            />

        <com.android.internal.widget.RemeasuringLinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="-12dp"
            android:clipChildren="false"
            android:orientation="vertical"
            >

            <ViewStub
                android:layout="@layout/notification_material_reply_text"
@@ -50,5 +60,6 @@
                />

            <include layout="@layout/notification_material_action_list" />
    </LinearLayout>
        </com.android.internal.widget.RemeasuringLinearLayout>
    </com.android.internal.widget.RemeasuringLinearLayout>
</FrameLayout>
+1 −1
Original line number Diff line number Diff line
@@ -308,7 +308,7 @@
    <dimen name="notification_headerless_min_height">56dp</dimen>

    <!-- Height of a small notification in the status bar -->
    <dimen name="notification_min_height">106dp</dimen>
    <dimen name="notification_min_height">76dp</dimen>

    <!-- The width of the big icons in notifications. -->
    <dimen name="notification_large_icon_width">64dp</dimen>
+8 −2
Original line number Diff line number Diff line
@@ -133,17 +133,23 @@
    <!-- Height of a small notification in the status bar which was used before android P -->
    <dimen name="notification_min_height_before_p">92dp</dimen>

    <!-- Height of a small notification in the status bar which was used before android S -->
    <dimen name="notification_min_height_before_s">106dp</dimen>

    <!-- Height of a large notification in the status bar -->
    <dimen name="notification_max_height">294dp</dimen>

    <!-- Height of a heads up notification in the status bar for legacy custom views -->
    <dimen name="notification_max_heads_up_height_legacy">128dp</dimen>

    <!-- Height of a heads up notification in the status bar for custom views before andoid P -->
    <!-- Height of a heads up notification in the status bar for custom views before android P -->
    <dimen name="notification_max_heads_up_height_before_p">148dp</dimen>

    <!-- Height of a heads up notification in the status bar for custom views before android S -->
    <dimen name="notification_max_heads_up_height_before_s">162dp</dimen>

    <!-- Height of a heads up notification in the status bar -->
    <dimen name="notification_max_heads_up_height">162dp</dimen>
    <dimen name="notification_max_heads_up_height">132dp</dimen>

    <!-- Height of a heads up notification in the status bar -->
    <dimen name="notification_max_heads_up_height_increased">188dp</dimen>
Loading