1 package ${packageName}.util;
3 import android.annotation.TargetApi;
4 import android.app.Activity;
5 import android.os.Build;
6 import android.view.View;
7 import android.view.WindowManager;
10 * An API 11+ implementation of {@link SystemUiHider}. Uses APIs available in
11 * Honeycomb and later (specifically {@link View#setSystemUiVisibility(int)}) to
12 * show and hide the system UI.
14 @TargetApi(Build.VERSION_CODES.HONEYCOMB)
15 public class SystemUiHiderHoneycomb extends SystemUiHiderBase {
17 * Flags for {@link View#setSystemUiVisibility(int)} to use when showing the
20 private int mShowFlags;
23 * Flags for {@link View#setSystemUiVisibility(int)} to use when hiding the
26 private int mHideFlags;
29 * Flags to test against the first parameter in
30 * {@link android.view.View.OnSystemUiVisibilityChangeListener#onSystemUiVisibilityChange(int)}
31 * to determine the system UI visibility state.
33 private int mTestFlags;
36 * Whether or not the system UI is currently visible. This is cached from
37 * {@link android.view.View.OnSystemUiVisibilityChangeListener}.
39 private boolean mVisible = true;
42 * Constructor not intended to be called by clients. Use
43 * {@link SystemUiHider#getInstance} to obtain an instance.
45 protected SystemUiHiderHoneycomb(Activity activity, View anchorView, int flags) {
46 super(activity, anchorView, flags);
48 mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE;
49 mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
50 mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
52 if ((mFlags & FLAG_FULLSCREEN) != 0) {
53 // If the client requested fullscreen, add flags relevant to hiding
54 // the status bar. Note that some of these constants are new as of
55 // API 16 (Jelly Bean). It is safe to use them, as they are inlined
56 // at compile-time and do nothing on pre-Jelly Bean devices.
57 mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
58 mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
59 | View.SYSTEM_UI_FLAG_FULLSCREEN;
62 if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) {
63 // If the client requested hiding navigation, add relevant flags.
64 mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
65 mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
66 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
67 mTestFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
74 mAnchorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
80 mAnchorView.setSystemUiVisibility(mHideFlags);
86 mAnchorView.setSystemUiVisibility(mShowFlags);
91 public boolean isVisible() {
95 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener
96 = new View.OnSystemUiVisibilityChangeListener() {
98 public void onSystemUiVisibilityChange(int vis) {
99 // Test against mTestFlags to see if the system UI is visible.
100 if ((vis & mTestFlags) != 0) {
101 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
102 // Pre-Jelly Bean, we must manually hide the action bar
103 // and use the old window flags API.
104 mActivity.getActionBar().hide();
105 mActivity.getWindow().setFlags(
106 WindowManager.LayoutParams.FLAG_FULLSCREEN,
107 WindowManager.LayoutParams.FLAG_FULLSCREEN);
110 // Trigger the registered listener and cache the visibility
112 mOnVisibilityChangeListener.onVisibilityChange(false);
116 mAnchorView.setSystemUiVisibility(mShowFlags);
117 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
118 // Pre-Jelly Bean, we must manually show the action bar
119 // and use the old window flags API.
120 mActivity.getActionBar().show();
121 mActivity.getWindow().setFlags(
123 WindowManager.LayoutParams.FLAG_FULLSCREEN);
126 // Trigger the registered listener and cache the visibility
128 mOnVisibilityChangeListener.onVisibilityChange(true);