1 package ${packageName}.util; 2 3 import android.app.Activity; 4 import android.view.View; 5 import android.view.WindowManager; 6 7 /** 8 * A base implementation of {@link SystemUiHider}. Uses APIs available in all 9 * API levels to show and hide the status bar. 10 */ 11 public class SystemUiHiderBase extends SystemUiHider { 12 /** 13 * Whether or not the system UI is currently visible. This is a cached value 14 * from calls to {@link #hide()} and {@link #show()}. 15 */ 16 private boolean mVisible = true; 17 18 /** 19 * Constructor not intended to be called by clients. Use 20 * {@link SystemUiHider#getInstance} to obtain an instance. 21 */ 22 protected SystemUiHiderBase(Activity activity, View anchorView, int flags) { 23 super(activity, anchorView, flags); 24 } 25 26 @Override 27 public void setup() { 28 if ((mFlags & FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES) == 0) { 29 mActivity.getWindow().setFlags( 30 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 31 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, 32 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 33 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); 34 } 35 } 36 37 @Override 38 public boolean isVisible() { 39 return mVisible; 40 } 41 42 @Override 43 public void hide() { 44 if ((mFlags & FLAG_FULLSCREEN) != 0) { 45 mActivity.getWindow().setFlags( 46 WindowManager.LayoutParams.FLAG_FULLSCREEN, 47 WindowManager.LayoutParams.FLAG_FULLSCREEN); 48 } 49 mOnVisibilityChangeListener.onVisibilityChange(false); 50 mVisible = false; 51 } 52 53 @Override 54 public void show() { 55 if ((mFlags & FLAG_FULLSCREEN) != 0) { 56 mActivity.getWindow().setFlags( 57 0, 58 WindowManager.LayoutParams.FLAG_FULLSCREEN); 59 } 60 mOnVisibilityChangeListener.onVisibilityChange(true); 61 mVisible = true; 62 } 63 } 64