From e5dbae103f57baa2baafbc552f0dfcb1006513a8 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 25 Nov 2013 21:06:36 -0800 Subject: Fix immersive mode implementation --- res/values/strings.xml | 2 +- .../dsub/activity/SettingsActivity.java | 14 ++------ .../dsub/activity/SubsonicActivity.java | 37 +++++++++++----------- src/github/daneren2005/dsub/util/Util.java | 5 +++ 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 72dade05..b19c7b7d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -251,7 +251,7 @@ Dark Black Holo - Fullscreen + Fullscreen Hide as many UI elements as Android will allow Display Track # Display Track # in front of songs if one exists diff --git a/src/github/daneren2005/dsub/activity/SettingsActivity.java b/src/github/daneren2005/dsub/activity/SettingsActivity.java index 4dac82bd..49a5f15b 100644 --- a/src/github/daneren2005/dsub/activity/SettingsActivity.java +++ b/src/github/daneren2005/dsub/activity/SettingsActivity.java @@ -380,7 +380,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer return screen; } - + private void applyTheme() { String activeTheme = Util.getTheme(this); if ("dark".equals(activeTheme)) { @@ -389,17 +389,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer setTheme(R.style.Theme_DSub_Black); } else if ("light".equals(activeTheme)) { setTheme(R.style.Theme_DSub_Light); - } else if ("dark_fullscreen".equals(activeTheme)) { - setTheme(R.style.Theme_DSub_Dark_Fullscreen); - } else if ("black_fullscreen".equals(activeTheme)) { - setTheme(R.style.Theme_DSub_Black_Fullscreen); - } else if ("light_fullscreen".equals(activeTheme)) { - setTheme(R.style.Theme_DSub_Light_Fullscreen); - } else if("holo".equals(activeTheme)) { - setTheme(R.style.Theme_DSub_Holo); - } else if("holo_fullscreen".equals(activeTheme)) { - setTheme(R.style.Theme_DSub_Holo_Fullscreen); - }else { + } else { setTheme(R.style.Theme_DSub_Holo); } } diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java index dc149def..78ed14f3 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -45,6 +45,8 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; @@ -73,6 +75,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte private static final String TAG = SubsonicActivity.class.getSimpleName(); private static ImageLoader IMAGE_LOADER; protected static String theme; + protected static boolean fullScreen; private String[] drawerItemsDescriptions; private String[] drawerItems; private boolean drawerIdle = true; @@ -98,6 +101,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte setUncaughtExceptionHandler(); applyTheme(); super.onCreate(bundle); + applyFullscreen(); startService(new Intent(this, DownloadServiceImpl.class)); setVolumeControlStream(AudioManager.STREAM_MUSIC); @@ -126,7 +130,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte Util.registerMediaButtonEventReceiver(this); // Make sure to update theme - if (theme != null && !theme.equals(Util.getTheme(this))) { + if (theme != null && !theme.equals(Util.getTheme(this)) || fullScreen != Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_FULL_SCREEN, false)) { restart(); } @@ -610,9 +614,10 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte private void applyTheme() { theme = Util.getTheme(this); - + if(theme != null && theme.indexOf("fullscreen") != -1) { theme = theme.substring(0, theme.indexOf("_fullscreen")); + Util.setTheme(this, theme); } if ("dark".equals(theme)) { @@ -624,25 +629,21 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte } else { setTheme(R.style.Theme_DSub_Holo); } - - if(Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_FULL_SCREEN, false)) { - getWindow().requestFeature(Window.FEATURE_NO_TITLE); - getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); - + } + private void applyFullscreen() { + fullScreen = Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_FULL_SCREEN, false); + if(fullScreen) { // Hide additional elements on higher Android versions - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | - View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | - View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | - View.SYSTEM_UI_FLAG_FULLSCREEN; - - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - flags = flags | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; - } - + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_FULLSCREEN | + View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; + getWindow().getDecorView().setSystemUiVisibility(flags); + } else if(Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + getWindow().requestFeature(Window.FEATURE_NO_TITLE); } + getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); } } diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java index ce6ba914..83e8deee 100644 --- a/src/github/daneren2005/dsub/util/Util.java +++ b/src/github/daneren2005/dsub/util/Util.java @@ -279,6 +279,11 @@ public final class Util { SharedPreferences prefs = getPreferences(context); return prefs.getString(Constants.PREFERENCES_KEY_THEME, null); } + public static void setTheme(Context context, String theme) { + SharedPreferences.Editor editor = getPreferences(context).edit(); + editor.putString(Constants.PREFERENCES_KEY_THEME, theme); + editor.commit(); + } public static boolean getDisplayTrack(Context context) { SharedPreferences prefs = getPreferences(context); -- cgit v1.2.3