github.com/c-darwin/mobile@v0.0.0-20160313183840-ff625c46f7c9/app/work-cross/SystemUiHiderHoneycomb.java (about) 1 package org.golang.app; 2 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; 8 9 /** 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. 13 */ 14 @TargetApi(Build.VERSION_CODES.HONEYCOMB) 15 public class SystemUiHiderHoneycomb extends SystemUiHiderBase { 16 /** 17 * Flags for {@link View#setSystemUiVisibility(int)} to use when showing the 18 * system UI. 19 */ 20 private int mShowFlags; 21 22 /** 23 * Flags for {@link View#setSystemUiVisibility(int)} to use when hiding the 24 * system UI. 25 */ 26 private int mHideFlags; 27 28 /** 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. 32 */ 33 private int mTestFlags; 34 35 /** 36 * Whether or not the system UI is currently visible. This is cached from 37 * {@link android.view.View.OnSystemUiVisibilityChangeListener}. 38 */ 39 private boolean mVisible = true; 40 41 /** 42 * Constructor not intended to be called by clients. Use 43 * {@link SystemUiHider#getInstance} to obtain an instance. 44 */ 45 protected SystemUiHiderHoneycomb(Activity activity, View anchorView, int flags) { 46 super(activity, anchorView, flags); 47 48 mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE; 49 mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE; 50 mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE; 51 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; 60 } 61 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; 68 } 69 } 70 71 /** 72 * {@inheritDoc} 73 */ 74 @Override 75 public void setup() { 76 mAnchorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener); 77 } 78 79 /** 80 * {@inheritDoc} 81 */ 82 @Override 83 public void hide() { 84 mAnchorView.setSystemUiVisibility(mHideFlags); 85 } 86 87 /** 88 * {@inheritDoc} 89 */ 90 @Override 91 public void show() { 92 mAnchorView.setSystemUiVisibility(mShowFlags); 93 } 94 95 /** 96 * {@inheritDoc} 97 */ 98 @Override 99 public boolean isVisible() { 100 return mVisible; 101 } 102 103 private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener 104 = new View.OnSystemUiVisibilityChangeListener() { 105 @Override 106 public void onSystemUiVisibilityChange(int vis) { 107 // Test against mTestFlags to see if the system UI is visible. 108 if ((vis & mTestFlags) != 0) { 109 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { 110 // Pre-Jelly Bean, we must manually hide the action bar 111 // and use the old window flags API. 112 mActivity.getActionBar().hide(); 113 mActivity.getWindow().setFlags( 114 WindowManager.LayoutParams.FLAG_FULLSCREEN, 115 WindowManager.LayoutParams.FLAG_FULLSCREEN); 116 } 117 118 // Trigger the registered listener and cache the visibility 119 // state. 120 mOnVisibilityChangeListener.onVisibilityChange(false); 121 mVisible = false; 122 123 } else { 124 mAnchorView.setSystemUiVisibility(mShowFlags); 125 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { 126 // Pre-Jelly Bean, we must manually show the action bar 127 // and use the old window flags API. 128 mActivity.getActionBar().show(); 129 mActivity.getWindow().setFlags( 130 0, 131 WindowManager.LayoutParams.FLAG_FULLSCREEN); 132 } 133 134 // Trigger the registered listener and cache the visibility 135 // state. 136 mOnVisibilityChangeListener.onVisibilityChange(true); 137 mVisible = true; 138 } 139 } 140 }; 141 }