1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * Copyright (C) 2024 Mopria Alliance, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.bips.ui; 19 20 import android.app.Activity; 21 import android.view.View; 22 23 import androidx.core.graphics.Insets; 24 import androidx.core.view.ViewCompat; 25 import androidx.core.view.WindowInsetsCompat; 26 27 public final class ViewUtil { setWindowInsetsListener(View view, Activity activity)28 public static void setWindowInsetsListener(View view, Activity activity) { 29 ViewCompat.setOnApplyWindowInsetsListener(view, (v, windowInsets) -> { 30 if (activity.isFinishing()) { 31 return windowInsets; 32 } 33 Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); 34 v.setPadding(insets.left, insets.top, insets.right, insets.bottom); 35 return WindowInsetsCompat.CONSUMED; 36 }); 37 } 38 } 39