packagecom.example.test;importandroid.app.Activity;importandroid.os.Build;importandroid.os.Bundle;importandroid.os.Handler;importandroid.view.View;importandroid.view.Window;importandroid.view.WindowManager;publicclassMainActivityextendsActivity{privatestaticfinalintHIDE_DELAY_MILLIS=1000;privateHandlermHandler;privateViewmView;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mView=getWindow().getDecorView();setup(getWindow());}@OverrideprotectedvoidonStart(){super.onStart();}publicvoidsetup(Windowwindow){hideSystemUi();// Pre-Jellybean just hide the status barif(Build.VERSION.SDK_INT<Build.VERSION_CODES.JELLY_BEAN){window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);}mHandler=newHandler();mView.setOnSystemUiVisibilityChangeListener(newView.OnSystemUiVisibilityChangeListener(){@OverridepublicvoidonSystemUiVisibilityChange(intvisibility){if((visibility&View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)==0){delay();}}});}privatevoidhideSystemUi(){if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN){// On Jellybean we can use new System UI flags to allow showing// titlebar/systembar// only upon touching the screen, while still having the content// laid out in// the entire screen.mView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);}else{mView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);}}privateRunnablemHideRunnable=newRunnable(){publicvoidrun(){hideSystemUi();}};publicvoiddelay(){mHandler.removeCallbacks(mHideRunnable);mHandler.postDelayed(mHideRunnable,HIDE_DELAY_MILLIS);}}