From 5c7e61634a7f4cada56df68c5cd3e975f9e1e7e0 Mon Sep 17 00:00:00 2001 From: fnuesse Date: Sat, 23 Feb 2019 17:31:35 +0100 Subject: [PATCH] Added ThemeHelper method to set accent colors to different ui-elements --- .../android/vanilla/FolderPickerActivity.java | 2 +- .../android/vanilla/FullPlaybackActivity.java | 6 +- .../android/vanilla/LibraryActivity.java | 2 +- .../android/vanilla/PlaylistActivity.java | 2 +- .../android/vanilla/PreferencesActivity.java | 26 ++++++- .../vanilla/SlidingPlaybackActivity.java | 1 + .../android/vanilla/TabOrderActivity.java | 2 +- .../android/vanilla/ThemeHelper.java | 71 +++++++++++++++++++ .../main/res/layout/bottombar_controls.xml | 56 ++++++++------- 9 files changed, 135 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/FolderPickerActivity.java b/app/src/main/java/ch/blinkenlights/android/vanilla/FolderPickerActivity.java index 385e03245..c588c1a7c 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/FolderPickerActivity.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/FolderPickerActivity.java @@ -66,7 +66,7 @@ public abstract class FolderPickerActivity extends Activity @Override public void onCreate(Bundle savedInstanceState) { - ThemeHelper.setTheme(this, R.style.BackActionBar); + ThemeHelper.setTheme(this, R.style.BackActionBar, this); super.onCreate(savedInstanceState); setContentView(R.layout.folderpicker_content); diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java b/app/src/main/java/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java index aaf5063d6..7bc954096 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java @@ -29,6 +29,8 @@ import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.os.Message; import android.util.Log; @@ -106,7 +108,9 @@ public class FullPlaybackActivity extends SlidingPlaybackActivity @Override public void onCreate(Bundle icicle) { - ThemeHelper.setTheme(this, R.style.Playback); + ThemeHelper.setTheme(this, R.style.Playback, this); + + super.onCreate(icicle); setTitle(R.string.playback_view); diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/LibraryActivity.java b/app/src/main/java/ch/blinkenlights/android/vanilla/LibraryActivity.java index b4ed286d2..bc6ca8ed6 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/LibraryActivity.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/LibraryActivity.java @@ -158,7 +158,7 @@ public class LibraryActivity @Override public void onCreate(Bundle state) { - ThemeHelper.setTheme(this, R.style.Library); + ThemeHelper.setTheme(this, R.style.Library, this); super.onCreate(state); if (state == null) { diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/PlaylistActivity.java b/app/src/main/java/ch/blinkenlights/android/vanilla/PlaylistActivity.java index 7aed1101a..330104126 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/PlaylistActivity.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/PlaylistActivity.java @@ -102,7 +102,7 @@ public class PlaylistActivity extends Activity @Override public void onCreate(Bundle state) { - ThemeHelper.setTheme(this, R.style.BackActionBar); + ThemeHelper.setTheme(this, R.style.BackActionBar, this); super.onCreate(state); HandlerThread thread = new HandlerThread(getClass().getName()); diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/PreferencesActivity.java b/app/src/main/java/ch/blinkenlights/android/vanilla/PreferencesActivity.java index e1db733bd..b3efc21d4 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/PreferencesActivity.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/PreferencesActivity.java @@ -66,7 +66,7 @@ public class PreferencesActivity extends PreferenceActivity @Override protected void onCreate(Bundle savedInstanceState) { - ThemeHelper.setTheme(this, R.style.BackActionBar); + ThemeHelper.setTheme(this, R.style.BackActionBar, this); super.onCreate(savedInstanceState); SharedPrefHelper.getSettings(this).registerOnSharedPreferenceChangeListener(this); } @@ -116,6 +116,8 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference_audio); + + ThemeHelper.setAccentColor(this.getActivity()); } } @@ -130,6 +132,8 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + ThemeHelper.setAccentColor(this.getActivity()); + addPreferencesFromResource(R.xml.preference_replaygain); cbTrackReplayGain = (CheckBoxPreference)findPreference(PrefKeys.ENABLE_TRACK_REPLAYGAIN); cbAlbumReplayGain = (CheckBoxPreference)findPreference(PrefKeys.ENABLE_ALBUM_REPLAYGAIN); @@ -177,6 +181,8 @@ public void onCreate(Bundle savedInstanceState) // ignored. Whee! } + + ThemeHelper.setAccentColor(this.getActivity()); getActivity().finish(); } } @@ -187,6 +193,8 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference_playback); + + ThemeHelper.setAccentColor(this.getActivity()); } } @@ -196,6 +204,8 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference_library); + + ThemeHelper.setAccentColor(this.getActivity()); } } @@ -205,6 +215,8 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference_notifications); + + ThemeHelper.setAccentColor(this.getActivity()); } } @@ -214,6 +226,8 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference_shake); + + ThemeHelper.setAccentColor(this.getActivity()); } } @@ -223,6 +237,8 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference_coverart); + + ThemeHelper.setAccentColor(this.getActivity()); } } @@ -232,6 +248,8 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference_misc); + + ThemeHelper.setAccentColor(this.getActivity()); } } @@ -241,6 +259,8 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference_playlist); + + ThemeHelper.setAccentColor(this.getActivity()); } } @@ -250,6 +270,8 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + ThemeHelper.setAccentColor(this.getActivity()); + Activity activity = getActivity(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/vanilla-music/vanilla-music.github.io/wiki")); if (intent != null) { @@ -281,6 +303,8 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + ThemeHelper.setAccentColor(this.getActivity()); + Activity activity = getActivity(); Intent intent = activity.getPackageManager().getLaunchIntentForPackage(VPLUG_PACKAGE_NAME); diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/SlidingPlaybackActivity.java b/app/src/main/java/ch/blinkenlights/android/vanilla/SlidingPlaybackActivity.java index 395e94698..ca80387a1 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/SlidingPlaybackActivity.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/SlidingPlaybackActivity.java @@ -85,6 +85,7 @@ protected void bindControlButtons() { mSeekBar = (SeekBar)findViewById(R.id.seek_bar); mSeekBar.setMax(1000); mSeekBar.setOnSeekBarChangeListener(this); + ThemeHelper.setAccentColor(this); setDuration(0); } diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/TabOrderActivity.java b/app/src/main/java/ch/blinkenlights/android/vanilla/TabOrderActivity.java index b117466cd..86e86097c 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/TabOrderActivity.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/TabOrderActivity.java @@ -48,7 +48,7 @@ public class TabOrderActivity extends Activity @Override protected void onCreate(Bundle savedInstanceState) { - ThemeHelper.setTheme(this, R.style.BackActionBar); + ThemeHelper.setTheme(this, R.style.BackActionBar, this); super.onCreate(savedInstanceState); setTitle(R.string.tabs); diff --git a/app/src/main/java/ch/blinkenlights/android/vanilla/ThemeHelper.java b/app/src/main/java/ch/blinkenlights/android/vanilla/ThemeHelper.java index 87e9a3518..a6f6d64b7 100644 --- a/app/src/main/java/ch/blinkenlights/android/vanilla/ThemeHelper.java +++ b/app/src/main/java/ch/blinkenlights/android/vanilla/ThemeHelper.java @@ -17,10 +17,23 @@ package ch.blinkenlights.android.vanilla; +import android.app.ActionBar; +import android.app.Activity; import android.content.Context; +import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.content.SharedPreferences; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.drawable.ColorDrawable; import android.os.Build; +import android.view.View; +import android.widget.CheckBox; +import android.widget.SeekBar; + +import java.util.ArrayList; + +import androidx.fragment.app.Fragment; public class ThemeHelper { @@ -33,6 +46,64 @@ final public static void setTheme(Context context, int theme) { context.setTheme(getThemeResource(context, theme)); } + /** + * Sets the accentcolor to the value stored in the preferences. + */ + final public static void setAccentColor(Activity a) { + + String c = "#b13fb5"; + + int myColor = Color.parseColor(c); + + ActionBar actionBar = a.getActionBar(); + if(actionBar!=null){ + ColorDrawable colorDrawable = new ColorDrawable(myColor); + actionBar.setBackgroundDrawable(colorDrawable); + } + + SeekBar mSeekBar = (SeekBar)a.findViewById(R.id.seek_bar); + if(mSeekBar != null){ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + mSeekBar.getThumb().setColorFilter(myColor, PorterDuff.Mode.SRC_ATOP); + mSeekBar.getProgressDrawable().setColorFilter(myColor, PorterDuff.Mode.SRC_ATOP); + } + } + + BottomBarControls mBottomBarControls = (BottomBarControls) a.findViewById(R.id.bottombar_controls); + if(mBottomBarControls != null){ + mBottomBarControls.setBackgroundColor(myColor); + } + + + ArrayList checkboxes = new ArrayList(); + ArrayList availableViews = a.getWindow().getDecorView().getFocusables(View.FOCUS_FORWARD); + for (int i = 0; i < availableViews.size(); i++) { + View actualView = availableViews.get(i); + if(actualView instanceof CheckBox) { + checkboxes.add((CheckBox) actualView); + } + + } + for(CheckBox mCheckbox: checkboxes){ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + mCheckbox.setButtonTintList(ColorStateList.valueOf(myColor)); + } + } + + } + + /** + * Calls context.setTheme() with given theme. + * Will automatically swap the theme with an alternative + * version if the user requested us to use it + * + * Also sets the accentcolor to the value stored in the preferences. + */ + final public static void setTheme(Context context, int theme, Activity a) { + setTheme(context, theme); + setAccentColor(a); + } + /** * Returns the theme resource id to use based on the user preferences * and platform API. diff --git a/app/src/main/res/layout/bottombar_controls.xml b/app/src/main/res/layout/bottombar_controls.xml index ebf31cb71..3ba652d0e 100644 --- a/app/src/main/res/layout/bottombar_controls.xml +++ b/app/src/main/res/layout/bottombar_controls.xml @@ -21,64 +21,66 @@ THE SOFTWARE. --> - + android:background="?tabs_background" + android:orientation="vertical"> + android:gravity="center_vertical"> + android:layout_marginLeft="@dimen/cover_padding" + android:contentDescription="@string/cover_art" + android:scaleType="centerCrop" /> + + + android:textSize="14sp" /> + + android:textSize="12sp" /> + android:visibility="gone" />