summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
Diffstat (limited to 'library')
-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);
}
}