From 7f0feb346c9eff697176d3a21bbf5869107f715e Mon Sep 17 00:00:00 2001 From: Ruben Date: Fri, 19 Aug 2016 17:28:51 +0100 Subject: [PATCH] Make fullscreen less flickery --- .../emotionhero/GamingActivity.java | 111 +----------------- 1 file changed, 4 insertions(+), 107 deletions(-) diff --git a/app/src/main/java/com/rubenvandeven/emotionhero/GamingActivity.java b/app/src/main/java/com/rubenvandeven/emotionhero/GamingActivity.java index 6cbf75c..3f4b630 100644 --- a/app/src/main/java/com/rubenvandeven/emotionhero/GamingActivity.java +++ b/app/src/main/java/com/rubenvandeven/emotionhero/GamingActivity.java @@ -18,6 +18,7 @@ import android.view.MotionEvent; import android.view.SurfaceView; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.TextView; @@ -41,60 +42,7 @@ public class GamingActivity extends AppCompatActivity implements Detector.ImageL final int PERMISSIONS_REQUEST_CAMERA = 1; - /** - * Whether or not the system UI should be auto-hidden after - * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds. - */ - private static final boolean AUTO_HIDE = true; - - /** - * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after - * user interaction before hiding the system UI. - */ - private static final int AUTO_HIDE_DELAY_MILLIS = 3000; - - /** - * Some older devices needs a small delay between UI widget updates - * and a change of the status and navigation bar. - */ - private static final int UI_ANIMATION_DELAY = 300; - private final Handler mHideHandler = new Handler(); private TextView mContentView; - private final Runnable mHidePart2Runnable = new Runnable() { - @SuppressLint("InlinedApi") - @Override - public void run() { - // Delayed removal of status and navigation bar - - // Note that some of these constants are new as of API 16 (Jelly Bean) - // and API 19 (KitKat). It is safe to use them, as they are inlined - // at compile-time and do nothing on earlier devices. - mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE - | View.SYSTEM_UI_FLAG_FULLSCREEN - | View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); - } - }; - - private final Runnable mShowPart2Runnable = new Runnable() { - @Override - public void run() { - // Delayed display of UI elements - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.show(); - } - } - }; - private boolean mVisible; - private final Runnable mHideRunnable = new Runnable() { - @Override - public void run() { - hide(); - } - }; private CameraDetector detector; @@ -119,10 +67,11 @@ public class GamingActivity extends AppCompatActivity implements Detector.ImageL @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); + getSupportActionBar().hide(); setContentView(R.layout.activity_gaming); - mVisible = true; mContentView = (TextView) findViewById(R.id.fullscreen_content); RelativeLayout videoLayout = (RelativeLayout) findViewById(R.id.video_layout); @@ -140,7 +89,7 @@ public class GamingActivity extends AppCompatActivity implements Detector.ImageL mContentView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - toggle(); +// toggle(); } }); @@ -190,24 +139,6 @@ public class GamingActivity extends AppCompatActivity implements Detector.ImageL } - @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - - // Trigger the initial hide() shortly after the activity has been - // created, to briefly hint to the user that UI controls - // are available. - delayedHide(100); - } - - private void toggle() { - if (mVisible) { - hide(); - } else { - show(); - } - } - @Override protected void onResume() { super.onResume(); @@ -270,40 +201,6 @@ public class GamingActivity extends AppCompatActivity implements Detector.ImageL } } - private void hide() { - // Hide UI first - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.hide(); - } - mVisible = false; - - // Schedule a runnable to remove the status and navigation bar after a delay - mHideHandler.removeCallbacks(mShowPart2Runnable); - mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY); - } - - @SuppressLint("InlinedApi") - private void show() { - // Show the system bar - mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); - mVisible = true; - - // Schedule a runnable to display UI elements after a delay - mHideHandler.removeCallbacks(mHidePart2Runnable); - mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY); - } - - /** - * Schedules a call to hide() in [delay] milliseconds, canceling any - * previously scheduled calls. - */ - private void delayedHide(int delayMillis) { - mHideHandler.removeCallbacks(mHideRunnable); - mHideHandler.postDelayed(mHideRunnable, delayMillis); - } - @Override /** * Detector callback gives the faces found so we can match their scores to the given scenario.