• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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.google.android.setupdesign.view;
18 
19 import android.content.Context;
20 import android.os.Build.VERSION;
21 import android.os.Build.VERSION_CODES;
22 import android.util.AttributeSet;
23 import android.view.WindowInsets;
24 import android.widget.LinearLayout;
25 import com.google.android.setupcompat.partnerconfig.PartnerConfigHelper;
26 import com.google.android.setupcompat.util.Logger;
27 
28 /**
29  * A custom LinearLayout that modifies system window insets, specifically the bottom inset, based on
30  * partner configuration.
31  *
32  * <p>This layout for large screen is designed to handle edge-to-edge display scenarios,
33  * particularly when {@link PartnerConfigHelper#isGlifExpressiveEnabled(Context)} is true. It
34  * removes the bottom system window inset, effectively extending the layout to the bottom edge of
35  * the screen.
36  *
37  * <p>This layout should be used as a root layout or within a view hierarchy where edge-to-edge
38  * behavior is desired. It ensures that content extends to the bottom of the screen when the Glif
39  * Expressive feature is enabled.
40  */
41 public class InsetAdjustmentLayout extends LinearLayout {
42 
43   private static final Logger LOG = new Logger("InsetAdjustmentLayout");
44 
InsetAdjustmentLayout(Context context)45   public InsetAdjustmentLayout(Context context) {
46     super(context);
47   }
48 
InsetAdjustmentLayout(Context context, AttributeSet attrs)49   public InsetAdjustmentLayout(Context context, AttributeSet attrs) {
50     super(context, attrs);
51   }
52 
InsetAdjustmentLayout(Context context, AttributeSet attrs, int defStyleAttr)53   public InsetAdjustmentLayout(Context context, AttributeSet attrs, int defStyleAttr) {
54     super(context, attrs, defStyleAttr);
55   }
56 
57   @Override
onApplyWindowInsets(WindowInsets insets)58   public WindowInsets onApplyWindowInsets(WindowInsets insets) {
59     // TODO: b/398407478 - Add test case for edge to edge to layout from library.
60     if (PartnerConfigHelper.isGlifExpressiveEnabled(getContext())) {
61       if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP && insets.getSystemWindowInsetBottom() > 0) {
62         LOG.atDebug("NavigationBarHeight: " + insets.getSystemWindowInsetBottom());
63         insets =
64             insets.replaceSystemWindowInsets(
65                 insets.getSystemWindowInsetLeft(),
66                 insets.getSystemWindowInsetTop(),
67                 insets.getSystemWindowInsetRight(),
68                 /* bottom= */ 0);
69       }
70     }
71     return super.onApplyWindowInsets(insets);
72   }
73 }
74