aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com/camilstaps/rushhour/util/SystemUiHiderBase.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/camilstaps/rushhour/util/SystemUiHiderBase.java')
-rw-r--r--app/src/main/java/com/camilstaps/rushhour/util/SystemUiHiderBase.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/app/src/main/java/com/camilstaps/rushhour/util/SystemUiHiderBase.java b/app/src/main/java/com/camilstaps/rushhour/util/SystemUiHiderBase.java
new file mode 100644
index 0000000..bc8615b
--- /dev/null
+++ b/app/src/main/java/com/camilstaps/rushhour/util/SystemUiHiderBase.java
@@ -0,0 +1,63 @@
+package com.camilstaps.rushhour.util;
+
+import android.app.Activity;
+import android.view.View;
+import android.view.WindowManager;
+
+/**
+ * A base implementation of {@link SystemUiHider}. Uses APIs available in all
+ * API levels to show and hide the status bar.
+ */
+public class SystemUiHiderBase extends SystemUiHider {
+ /**
+ * Whether or not the system UI is currently visible. This is a cached value
+ * from calls to {@link #hide()} and {@link #show()}.
+ */
+ private boolean mVisible = true;
+
+ /**
+ * Constructor not intended to be called by clients. Use
+ * {@link SystemUiHider#getInstance} to obtain an instance.
+ */
+ protected SystemUiHiderBase(Activity activity, View anchorView, int flags) {
+ super(activity, anchorView, flags);
+ }
+
+ @Override
+ public void setup() {
+ if ((mFlags & FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES) == 0) {
+ mActivity.getWindow().setFlags(
+ WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
+ | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
+ WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
+ | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
+ }
+ }
+
+ @Override
+ public boolean isVisible() {
+ return mVisible;
+ }
+
+ @Override
+ public void hide() {
+ if ((mFlags & FLAG_FULLSCREEN) != 0) {
+ mActivity.getWindow().setFlags(
+ WindowManager.LayoutParams.FLAG_FULLSCREEN,
+ WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ }
+ mOnVisibilityChangeListener.onVisibilityChange(false);
+ mVisible = false;
+ }
+
+ @Override
+ public void show() {
+ if ((mFlags & FLAG_FULLSCREEN) != 0) {
+ mActivity.getWindow().setFlags(
+ 0,
+ WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ }
+ mOnVisibilityChangeListener.onVisibilityChange(true);
+ mVisible = true;
+ }
+}