Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 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.view.View;
23 import android.widget.FrameLayout;
24 import android.widget.RemoteViews;
25
26 /**
27 * This view will measure itself as having 0 size if all of its children are {@link #GONE}.
28 * Otherwise it acts like a normal {@link FrameLayout}.
29 */
30 @RemoteViews.RemoteView
31 public class NotificationVanishingFrameLayout extends FrameLayout {
32 public NotificationVanishingFrameLayout(Context context) {
33 this(context, null, 0, 0);
34 }
35
36 public NotificationVanishingFrameLayout(Context context, @Nullable AttributeSet attrs) {
37 this(context, attrs, 0, 0);
38 }
39
40 public NotificationVanishingFrameLayout(Context context, @Nullable AttributeSet attrs,
41 int defStyleAttr) {
42 this(context, attrs, defStyleAttr, 0);
43 }
44
45 public NotificationVanishingFrameLayout(Context context, AttributeSet attrs, int defStyleAttr,
46 int defStyleRes) {
47 super(context, attrs, defStyleAttr, defStyleRes);
48 }
49
50 @Override
51 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
52 if (allChildrenGone()) {
53 int zeroSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY);
54 super.onMeasure(zeroSpec, zeroSpec);
55 } else {
56 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
57 }
58 }
59
60 private boolean allChildrenGone() {
61 final int childCount = getChildCount();
62 for (int i = 0; i < childCount; i++) {
63 final View child = getChildAt(i);
64 if (child != null && child.getVisibility() != GONE) {
65 return false;
66 }
67 }
68 return true;
69 }
70 }