From a3e6a41d34715b45d50c5a47d9f431140857d30d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 9 Sep 2015 08:38:24 -0700 Subject: Make colored action bar/status bar optional --- .../dsub/activity/SubsonicActivity.java | 5 +- .../daneren2005/dsub/adapter/SectionAdapter.java | 2 +- .../github/daneren2005/dsub/util/Constants.java | 1 + .../java/github/daneren2005/dsub/util/Util.java | 29 +++++++++--- .../main/res/layout/abstract_fragment_activity.xml | 8 ++-- app/src/main/res/layout/drawer_header.xml | 4 +- app/src/main/res/layout/settings_activity.xml | 6 +-- app/src/main/res/values-v21/themes.xml | 17 +++++++ app/src/main/res/values/attrs.xml | 4 ++ app/src/main/res/values/strings.xml | 2 + app/src/main/res/values/themes.xml | 54 ++++++++++++++++++++++ app/src/main/res/xml/settings.xml | 6 +++ 12 files changed, 120 insertions(+), 18 deletions(-) (limited to 'app') diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java index bc114272..ab68a59a 100644 --- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -85,6 +85,7 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte private static ImageLoader IMAGE_LOADER; protected static String theme; protected static boolean fullScreen; + protected static boolean actionbarColored; private static final int MENU_GROUP_SERVER = 10; private static final int MENU_ITEM_SERVER_BASE = 100; @@ -204,7 +205,8 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte Util.registerMediaButtonEventReceiver(this); // Make sure to update theme - if (theme != null && !theme.equals(Util.getTheme(this)) || fullScreen != Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_FULL_SCREEN, false)) { + SharedPreferences prefs = Util.getPreferences(this); + if (theme != null && !theme.equals(Util.getTheme(this)) || fullScreen != prefs.getBoolean(Constants.PREFERENCES_KEY_FULL_SCREEN, false) || actionbarColored != prefs.getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true)) { restart(); overridePendingTransition(R.anim.fade_in, R.anim.fade_out); DrawableTint.wipeTintCache(); @@ -873,6 +875,7 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte } Util.applyTheme(this, theme); + actionbarColored = Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true); } private void applyFullscreen() { fullScreen = Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_FULL_SCREEN, false); diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java index 53cc5e99..d8107158 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java @@ -413,7 +413,7 @@ public abstract class SectionAdapter extends RecyclerView.Adapter= Build.VERSION_CODES.LOLLIPOP) { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true)) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); diff --git a/app/src/main/java/github/daneren2005/dsub/util/Constants.java b/app/src/main/java/github/daneren2005/dsub/util/Constants.java index 3c685fe9..e9e668f7 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java @@ -159,6 +159,7 @@ public final class Constants { public static final String PREFERENCES_KEY_RENAME_DUPLICATES = "renameDuplicates"; public static final String PREFERENCES_KEY_FIRST_LEVEL_ARTIST = "firstLevelArtist"; public static final String PREFERENCES_KEY_START_ON_HEADPHONES = "startOnHeadphones"; + public static final String PREFERENCES_KEY_COLOR_ACTION_BAR = "colorActionBar"; public static final String OFFLINE_SCROBBLE_COUNT = "scrobbleCount"; public static final String OFFLINE_SCROBBLE_ID = "scrobbleID"; diff --git a/app/src/main/java/github/daneren2005/dsub/util/Util.java b/app/src/main/java/github/daneren2005/dsub/util/Util.java index ec73afa7..24895226 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Util.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java @@ -19,6 +19,7 @@ package github.daneren2005.dsub.util; import android.annotation.TargetApi; import android.app.Activity; +import android.graphics.Color; import android.support.annotation.StringRes; import android.support.v7.app.AlertDialog; import android.content.ComponentName; @@ -46,6 +47,8 @@ import android.text.util.Linkify; import android.util.Log; import android.util.SparseArray; import android.view.Gravity; +import android.view.Window; +import android.view.WindowManager; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; @@ -271,14 +274,26 @@ public final class Util { } public static int getThemeRes(Context context, String theme) { if(context instanceof SubsonicFragmentActivity || context instanceof SettingsActivity) { - if ("dark".equals(theme)) { - return R.style.Theme_DSub_Dark_No_Actionbar; - } else if ("black".equals(theme)) { - return R.style.Theme_DSub_Black_No_Actionbar; - } else if ("holo".equals(theme)) { - return R.style.Theme_DSub_Holo_No_Actionbar; + if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true)) { + if ("dark".equals(theme)) { + return R.style.Theme_DSub_Dark_No_Actionbar; + } else if ("black".equals(theme)) { + return R.style.Theme_DSub_Black_No_Actionbar; + } else if ("holo".equals(theme)) { + return R.style.Theme_DSub_Holo_No_Actionbar; + } else { + return R.style.Theme_DSub_Light_No_Actionbar; + } } else { - return R.style.Theme_DSub_Light_No_Actionbar; + if ("dark".equals(theme)) { + return R.style.Theme_DSub_Dark_No_Color; + } else if ("black".equals(theme)) { + return R.style.Theme_DSub_Black_No_Color; + } else if ("holo".equals(theme)) { + return R.style.Theme_DSub_Holo_No_Color; + } else { + return R.style.Theme_DSub_Light_No_Color; + } } } else { if ("dark".equals(theme)) { diff --git a/app/src/main/res/layout/abstract_fragment_activity.xml b/app/src/main/res/layout/abstract_fragment_activity.xml index 04e6ec81..d41b0115 100644 --- a/app/src/main/res/layout/abstract_fragment_activity.xml +++ b/app/src/main/res/layout/abstract_fragment_activity.xml @@ -18,9 +18,9 @@ android:id="@+id/main_toolbar" android:layout_height="?attr/actionBarSize" android:layout_width="match_parent" - android:background="?attr/colorPrimary" + android:background="?attr/actionbarBackgroundColor" android:elevation="4dp" - android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" + android:theme="?attr/actionbarThemeStyle" app:popupTheme="?attr/actionbarPopupStyle"/> @@ -36,7 +36,7 @@ android:id="@+id/slide_up_swipe_target" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/colorPrimary"> + android:background="?attr/actionbarBackgroundColor"> + style="?attr/drawerTitleStyle"/> + style="?attr/drawerSubtitleStyle"/> + app:theme="?attr/actionbarThemeStyle" + app:popupTheme="?attr/actionbarPopupStyle"/> true + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 8f1e27a8..e14370e2 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -47,9 +47,13 @@ + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fc61a0f0..453cfdb1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -457,6 +457,8 @@ Rename duplicate tracks to the original filename so you can tell them apart. Start on headphones Start when headphones are plugged in. This requires the use of a service which starts on boot up to check for the headphone plug event even when DSub is not running. + Color Action Bar + Color the action bar and status bar or leave them alone Shuffle By Start Year: diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 6eac0202..dd156170 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -51,10 +51,14 @@ @color/lightPrimary @color/lightPrimaryDark @color/lightAccent + @color/lightPrimary @style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse @style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle.Inverse @style/ThemeOverlay.AppCompat.Light + @style/ThemeOverlay.AppCompat.Dark.ActionBar @style/DarkSpinnerItem + @style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse + @style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle.Inverse true ?attr/colorPrimary @@ -109,9 +113,13 @@ @color/lightPrimary @color/lightPrimaryDark @color/lightAccent + @color/lightPrimary @style/TextAppearance.AppCompat.Widget.ActionBar.Title @style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle @style/ThemeOverlay.AppCompat.Dark + @style/ThemeOverlay.AppCompat.Dark.ActionBar + @style/TextAppearance.AppCompat.Widget.ActionBar.Title + @style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle true ?attr/colorPrimary @@ -127,6 +135,7 @@ @color/holoPrimary @color/holoPrimaryDark @color/holoAccent + @color/holoPrimary + + + + + + + + + + + diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 078ccbeb..b30d59fd 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -38,6 +38,12 @@ android:key="fullScreen" android:defaultValue="false"/> + +