1 /* 2 * Copyright (C) 2023 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.torus.utils.extensions 18 19 import android.app.Activity 20 import android.view.View 21 import android.view.WindowInsets 22 import android.view.WindowInsetsController 23 24 /** 25 * Extends [Activity] to allow to set immersive fullscreen mode. 26 */ Activitynull27fun Activity.setImmersiveFullScreen() { 28 // Sets into Immersive mode. 29 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) { 30 window.setDecorFitsSystemWindows(false) 31 32 // Hides Navigation bar and Status bar. 33 val controller = window.insetsController 34 35 if (controller != null) { 36 controller.hide( 37 WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars() 38 ) 39 controller.systemBarsBehavior = 40 WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE 41 } 42 } else { 43 // Sets into Immersive mode on older APIs. 44 window.decorView.systemUiVisibility = ( 45 View.SYSTEM_UI_FLAG_IMMERSIVE 46 // Set the content to appear under the system bars so that the 47 // content doesn't resize when the system bars hide and show. 48 or View.SYSTEM_UI_FLAG_LAYOUT_STABLE 49 or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 50 or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 51 // Hide the nav bar and status bar 52 or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 53 or View.SYSTEM_UI_FLAG_FULLSCREEN 54 ) 55 } 56 } 57