Debian Codegraph @

core/java/com/android/internal/widget/NotificationMaxHeightFrameLayout.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.android.internal.widget;
18
19 import android.annotation.Nullable;
20 import android.content.Context;
21 import android.util.AttributeSet;
22 import android.widget.FrameLayout;
23 import android.widget.RemoteViews;
24
25 /**
26 * This custom subclass of FrameLayout enforces that its calculated height be no larger than the
27 * standard height of a notification. This is not required in the normal case, as the
28 * NotificationContentView gets this same value from the ExpandableNotificationRow, and enforces it
29 * as a maximum. It is required in the case of the HUN version of the headerless notification,
30 * because that style puts the actions below the headerless portion. If we don't cap this, then in
31 * certain situations (larger fonts, decorated custom views) the contents of the headerless
32 * notification push on the margins and increase the size of that view, which causes the actions to
33 * be cropped on the bottom by the HUN notification max height.
34 */
35 @RemoteViews.RemoteView
36 public class NotificationMaxHeightFrameLayout extends FrameLayout {
37 private final int mNotificationMaxHeight;
38
39 public NotificationMaxHeightFrameLayout(Context context) {
40 this(context, null, 0, 0);
41 }
42
43 public NotificationMaxHeightFrameLayout(Context context, @Nullable AttributeSet attrs) {
44 this(context, attrs, 0, 0);
45 }
46
47 public NotificationMaxHeightFrameLayout(Context context, @Nullable AttributeSet attrs,
48 int defStyleAttr) {
49 this(context, attrs, defStyleAttr, 0);
50 }
51
52 public NotificationMaxHeightFrameLayout(Context context, AttributeSet attrs, int defStyleAttr,
53 int defStyleRes) {
54 super(context, attrs, defStyleAttr, defStyleRes);
55 // `notification_min_height` refers to "minimized" not "minimum"; it is a max height
56 mNotificationMaxHeight = getFontScaledHeight(mContext,
57 com.android.internal.R.dimen.notification_min_height);
58 }
59
60 @Override
61 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
62 if (MeasureSpec.getSize(heightMeasureSpec) > mNotificationMaxHeight) {
63 final int mode = MeasureSpec.getMode(heightMeasureSpec);
64 heightMeasureSpec = MeasureSpec.makeMeasureSpec(mNotificationMaxHeight, mode);
65 }
66 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
67 }
68
69 /**
70 * NOTE: This is copied from com.android.systemui.statusbar.notification.NotificationUtils
71 *
72 * @param dimenId the dimen to look up
73 * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
74 */
75 private static int getFontScaledHeight(Context context, int dimenId) {
76 final int dimensionPixelSize = context.getResources().getDimensionPixelSize(dimenId);
77 final float factor = Math.max(1.0f, context.getResources().getDisplayMetrics().scaledDensity
78 / context.getResources().getDisplayMetrics().density);
79 return (int) (dimensionPixelSize * factor);
80 }
81 }