summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurice Lam <yukl@google.com>2018-02-01 18:01:33 -0800
committerMaurice Lam <yukl@google.com>2018-02-01 21:16:39 -0800
commitc9c5c4431a920e8a22d96bf3721e2c5377c9b57b (patch)
tree94742d939c31ce11833ffc8d3b17d92a004c8878
parentf2c8c89ad6048dd304f36928f1cddacbe7dbd920 (diff)
downloadsetupwizard-c9c5c4431a920e8a22d96bf3721e2c5377c9b57b.tar.gz
Set the back button sysUiVisibility as well
Changes to window sysUiVisibility is not picked up after the window is laid out, so add a call to set the decor view's sysUiVisibility as well. Test: ./gradlew connectedAndroidTest Bug: 72840994 Change-Id: I6f0744599f46adf1840738f226b4394e5b7ed1df
-rw-r--r--library/main/src/com/android/setupwizardlib/util/SystemBarHelper.java18
-rw-r--r--library/self.gradle1
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/SystemBarHelperTest.java20
3 files changed, 32 insertions, 7 deletions
diff --git a/library/main/src/com/android/setupwizardlib/util/SystemBarHelper.java b/library/main/src/com/android/setupwizardlib/util/SystemBarHelper.java
index 1c5f3d3..b31e82e 100644
--- a/library/main/src/com/android/setupwizardlib/util/SystemBarHelper.java
+++ b/library/main/src/com/android/setupwizardlib/util/SystemBarHelper.java
@@ -24,6 +24,7 @@ import android.content.res.TypedArray;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Handler;
+import android.support.annotation.RequiresPermission;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@@ -183,12 +184,25 @@ public class SystemBarHelper {
}
}
+ /**
+ * Sets whether the back button on the software navigation bar is visible. This only works if
+ * you have the STATUS_BAR permission. Otherwise framework will filter out this flag and this
+ * method call will not have any effect.
+ *
+ * <p>IMPORTANT: Do not assume that users have no way to go back when the back button is hidden.
+ * Many devices have physical back buttons, and accessibility services like TalkBack may have
+ * gestures mapped to back. Please use onBackPressed, onKeyDown, or other similar ways to
+ * make sure back button events are still handled (or ignored) properly.
+ */
+ @RequiresPermission("android.permission.STATUS_BAR")
public static void setBackButtonVisible(final Window window, final boolean visible) {
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
if (visible) {
removeVisibilityFlag(window, STATUS_BAR_DISABLE_BACK);
+ removeImmersiveFlagsFromDecorView(window, STATUS_BAR_DISABLE_BACK);
} else {
addVisibilityFlag(window, STATUS_BAR_DISABLE_BACK);
+ addImmersiveFlagsToDecorView(window, STATUS_BAR_DISABLE_BACK);
}
}
}
@@ -217,7 +231,7 @@ public class SystemBarHelper {
* {@link View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} only takes effect when it is added to a view
* instead of the window.
*/
- @TargetApi(VERSION_CODES.LOLLIPOP)
+ @TargetApi(VERSION_CODES.HONEYCOMB)
private static void addImmersiveFlagsToDecorView(final Window window, final int vis) {
getDecorView(window, new OnDecorViewInstalledListener() {
@Override
@@ -227,7 +241,7 @@ public class SystemBarHelper {
});
}
- @TargetApi(VERSION_CODES.LOLLIPOP)
+ @TargetApi(VERSION_CODES.HONEYCOMB)
private static void removeImmersiveFlagsFromDecorView(final Window window, final int vis) {
getDecorView(window, new OnDecorViewInstalledListener() {
@Override
diff --git a/library/self.gradle b/library/self.gradle
index 86dea0e..a4bff4e 100644
--- a/library/self.gradle
+++ b/library/self.gradle
@@ -29,6 +29,7 @@ android.sourceSets {
androidTestImplementation 'com.android.support.test:runner:1.0.0'
androidTestImplementation 'com.google.dexmaker:dexmaker:1.2'
androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2'
+ androidTestImplementation 'com.google.truth:truth:0.31'
androidTestImplementation 'junit:junit:4.+'
androidTestImplementation 'org.mockito:mockito-core:1.9.5'
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/SystemBarHelperTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/SystemBarHelperTest.java
index d3142f1..98c28f6 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/SystemBarHelperTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/SystemBarHelperTest.java
@@ -16,6 +16,8 @@
package com.android.setupwizardlib.test;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.junit.Assert.assertEquals;
import android.annotation.SuppressLint;
@@ -194,11 +196,15 @@ public class SystemBarHelperTest {
@UiThreadTest
@Test
public void testSetBackButtonVisibleTrue() {
- final Window window = createWindowWithSystemUiVisibility(0x456);
+ final Window window = createWindowWithSystemUiVisibility(STATUS_BAR_DISABLE_BACK | 0x456);
SystemBarHelper.setBackButtonVisible(window, true);
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
- assertEquals("View visibility should be 0x456", 0x456,
- window.getAttributes().systemUiVisibility);
+ assertThat(window.getAttributes().systemUiVisibility)
+ .named("window sysUiVisibility")
+ .isEqualTo(0x456);
+ assertThat(window.getDecorView().getSystemUiVisibility())
+ .named("decor view sysUiVisibility")
+ .isEqualTo(0x456);
}
}
@@ -208,8 +214,12 @@ public class SystemBarHelperTest {
final Window window = createWindowWithSystemUiVisibility(0x456);
SystemBarHelper.setBackButtonVisible(window, false);
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
- assertEquals("STATUS_BAR_DISABLE_BACK should be added to systemUiVisibility",
- 0x456 | STATUS_BAR_DISABLE_BACK, window.getAttributes().systemUiVisibility);
+ assertThat(window.getAttributes().systemUiVisibility)
+ .named("window sysUiVisibility")
+ .isEqualTo(0x456 | STATUS_BAR_DISABLE_BACK);
+ assertThat(window.getDecorView().getSystemUiVisibility())
+ .named("decor view sysUiVisibility")
+ .isEqualTo(0x456 | STATUS_BAR_DISABLE_BACK);
}
}