1 /* 2 * Copyright 2018 Google LLC All Rights Reserved. 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.skar.examples.helloskar.helpers; 18 19 import android.app.Activity; 20 import android.view.View; 21 import android.view.WindowManager; 22 23 /** 24 * Helper to set up the Android full screen mode. 25 */ 26 public final class FullScreenHelper { 27 /** 28 * Sets the Android fullscreen flags. Expected to be called from {@link 29 * Activity#onWindowFocusChanged(boolean hasFocus)}. 30 * 31 * @param activity the Activity on which the full screen mode will be set. 32 * @param hasFocus the hasFocus flag passed from the {@link Activity#onWindowFocusChanged(boolean 33 * hasFocus)} callback. 34 */ setFullScreenOnWindowFocusChanged(Activity activity, boolean hasFocus)35 public static void setFullScreenOnWindowFocusChanged(Activity activity, boolean hasFocus) { 36 if (hasFocus) { 37 // https://developer.android.com/training/system-ui/immersive.html#sticky 38 activity 39 .getWindow() 40 .getDecorView() 41 .setSystemUiVisibility( 42 View.SYSTEM_UI_FLAG_LAYOUT_STABLE 43 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 44 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 45 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 46 | View.SYSTEM_UI_FLAG_FULLSCREEN 47 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); 48 activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 49 } 50 } 51 } 52