1 /* 2 * Copyright 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 androidx.core.splashscreen 18 19 import android.content.res.Resources 20 import android.util.TypedValue 21 import android.view.View 22 import android.view.WindowInsetsController 23 import androidx.annotation.RequiresApi 24 25 /** 26 * Utility function for applying themes fixes to the system bar when the [SplashScreenViewProvider] 27 * is added and removed. 28 */ 29 @RequiresApi(31) 30 internal object ThemeUtils { 31 object Api31 { 32 33 /** 34 * Apply the theme's values for the system bar appearance to the decorView. 35 * 36 * This needs to be called when the [SplashScreenViewProvider] is added and after it's been 37 * removed. 38 */ 39 @JvmStatic 40 @JvmOverloads applyThemesSystemBarAppearancenull41 fun applyThemesSystemBarAppearance( 42 theme: Resources.Theme, 43 decor: View, 44 tv: TypedValue = TypedValue() 45 ) { 46 var appearance = 0 47 val mask = 48 WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS or 49 WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS 50 if (theme.resolveAttribute(android.R.attr.windowLightStatusBar, tv, true)) { 51 if (tv.data != 0) { 52 appearance = appearance or WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS 53 } 54 } 55 if (theme.resolveAttribute(android.R.attr.windowLightNavigationBar, tv, true)) { 56 if (tv.data != 0) { 57 appearance = 58 appearance or WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS 59 } 60 } 61 decor.windowInsetsController!!.setSystemBarsAppearance(appearance, mask) 62 } 63 } 64 } 65