diff options
author | Marcello Albano <maralb@google.com> | 2020-04-20 22:34:44 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-04-20 22:34:44 +0000 |
commit | b434cab48878dd0d5ea0f1cca92c2a8cb41c9e69 (patch) | |
tree | 34a70a31a79f6c7c45b02402117c32b75841aa91 | |
parent | 2d66b13c9f104b78983a3ff1546f3a060cf46bb2 (diff) | |
parent | 5b0f87b345b3355c070aff873221fcf5f97ed495 (diff) | |
download | setupwizard-b434cab48878dd0d5ea0f1cca92c2a8cb41c9e69.tar.gz |
Added helper function to enable immersive mode on a window. am: b730c412dd am: 9b16e7cf7f am: 5b0f87b345
Change-Id: I505338d891e59e92084e1ea7712cdb1b08fde96e
2 files changed, 75 insertions, 3 deletions
diff --git a/library/main/src/com/android/car/setupwizardlib/util/CarSetupWizardUiUtils.java b/library/main/src/com/android/car/setupwizardlib/util/CarSetupWizardUiUtils.java index 3af842a..6b0d977 100644 --- a/library/main/src/com/android/car/setupwizardlib/util/CarSetupWizardUiUtils.java +++ b/library/main/src/com/android/car/setupwizardlib/util/CarSetupWizardUiUtils.java @@ -18,6 +18,7 @@ package com.android.car.setupwizardlib.util; import android.app.Activity; import android.view.View; +import android.view.Window; import androidx.core.util.Preconditions; @@ -35,14 +36,22 @@ public final class CarSetupWizardUiUtils { **/ @Deprecated public static void maybeHideSystemUI(Activity activity) { - Preconditions.checkNotNull(activity); + enableImmersiveMode(activity.getWindow()); + } + + /** + * Enables immersive mode hiding system UI. + * + * @param window to apply immersive mode. + */ + public static void enableImmersiveMode(Window window) { + Preconditions.checkNotNull(window); // See https://developer.android.com/training/system-ui/immersive#EnableFullscreen // Enables regular immersive mode. // For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE. // Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY - View decorView = activity.getWindow().getDecorView(); - decorView.setSystemUiVisibility( + window.getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY // Set the content to appear under the system bars so that the // content doesn't resize when the system bars hide and show. diff --git a/library/main/tests/robotests/src/com/android/car/setupwizardlib/util/CarSetupWizardUiUtilsTest.java b/library/main/tests/robotests/src/com/android/car/setupwizardlib/util/CarSetupWizardUiUtilsTest.java new file mode 100644 index 0000000..2fcf0b6 --- /dev/null +++ b/library/main/tests/robotests/src/com/android/car/setupwizardlib/util/CarSetupWizardUiUtilsTest.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.car.setupwizardlib.util; + +import static com.google.common.truth.Truth.assertThat; + +import android.app.Activity; +import android.view.View; + +import com.android.car.setupwizardlib.BaseDesignActivity; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; + +@RunWith(RobolectricTestRunner.class) +public class CarSetupWizardUiUtilsTest { + + private static final int IMMERSIVE_MODE_FLAGS = + View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_FULLSCREEN; + + private Activity mActivity; + + @Before + public void setup() { + mActivity = Robolectric.buildActivity(BaseDesignActivity.class).create().get(); + } + + @Test + public void maybeHideSystemUI() { + CarSetupWizardUiUtils.maybeHideSystemUI(mActivity); + assertThat(mActivity.getWindow().getDecorView().getSystemUiVisibility()) + .isEqualTo(IMMERSIVE_MODE_FLAGS); + } + + @Test + public void enableImmersiveMode() { + CarSetupWizardUiUtils.enableImmersiveMode(mActivity.getWindow()); + assertThat(mActivity.getWindow().getDecorView().getSystemUiVisibility()) + .isEqualTo(IMMERSIVE_MODE_FLAGS); + } +} |