Skip to content

Commit

Permalink
Added ThemeHelper method to set accent colors to different ui-elements
Browse files Browse the repository at this point in the history
  • Loading branch information
newhinton committed Feb 23, 2019
1 parent b311c73 commit 5c7e616
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -116,6 +116,8 @@ public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_audio);

ThemeHelper.setAccentColor(this.getActivity());
}
}

Expand All @@ -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);
Expand Down Expand Up @@ -177,6 +181,8 @@ public void onCreate(Bundle savedInstanceState)
// ignored. Whee!
}


ThemeHelper.setAccentColor(this.getActivity());
getActivity().finish();
}
}
Expand All @@ -187,6 +193,8 @@ public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_playback);

ThemeHelper.setAccentColor(this.getActivity());
}
}

Expand All @@ -196,6 +204,8 @@ public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_library);

ThemeHelper.setAccentColor(this.getActivity());
}
}

Expand All @@ -205,6 +215,8 @@ public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_notifications);

ThemeHelper.setAccentColor(this.getActivity());
}
}

Expand All @@ -214,6 +226,8 @@ public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_shake);

ThemeHelper.setAccentColor(this.getActivity());
}
}

Expand All @@ -223,6 +237,8 @@ public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_coverart);

ThemeHelper.setAccentColor(this.getActivity());
}
}

Expand All @@ -232,6 +248,8 @@ public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_misc);

ThemeHelper.setAccentColor(this.getActivity());
}
}

Expand All @@ -241,6 +259,8 @@ public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_playlist);

ThemeHelper.setAccentColor(this.getActivity());
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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<CheckBox> checkboxes = new ArrayList<CheckBox>();
ArrayList<View> 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.
Expand Down
56 changes: 29 additions & 27 deletions app/src/main/res/layout/bottombar_controls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,64 +21,66 @@
THE SOFTWARE.
-->

<ch.blinkenlights.android.vanilla.BottomBarControls
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?tabs_background"
android:orientation="vertical"
<ch.blinkenlights.android.vanilla.BottomBarControls xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bottombar_controls"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:background="?tabs_background"
android:orientation="vertical">

<LinearLayout
android:layout_height="@dimen/row_normal_height"
android:id="@+id/content_controls"
android:layout_width="fill_parent"
android:layout_height="@dimen/row_normal_height"
android:background="@drawable/unbound_ripple_light"
android:gravity="center_vertical"
android:id="@+id/content_controls">
android:gravity="center_vertical">

<ImageView
android:id="@+id/cover"
android:scaleType="centerCrop"
android:layout_width="@dimen/cover_size"
android:layout_height="@dimen/cover_size"
android:layout_marginLeft="@dimen/cover_padding"
android:layout_gravity="center_vertical"
android:contentDescription="@string/cover_art" />
android:layout_marginLeft="@dimen/cover_padding"
android:contentDescription="@string/cover_art"
android:scaleType="centerCrop" />

<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0px"
android:layout_weight="1"
android:layout_marginLeft="@dimen/text_padding"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/text_padding"
android:layout_weight="1"
android:orientation="vertical">

<TextView
android:id="@+id/title"
android:textSize="14sp"
android:singleLine="true"
android:gravity="center_vertical"
android:ellipsize="marquee"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="@android:color/background_light"
android:layout_height="wrap_content" />
android:textSize="14sp" />

<TextView
android:id="@+id/artist"
android:textSize="12sp"
android:singleLine="true"
android:gravity="center_vertical"
android:ellipsize="marquee"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="@android:color/secondary_text_dark"
android:layout_height="wrap_content" />
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>

<SearchView
android:visibility="gone"
android:layout_height="@dimen/row_normal_height"
android:id="@+id/search_view"
android:layout_width="fill_parent"
android:layout_height="@dimen/row_normal_height"
android:iconifiedByDefault="false"
android:imeOptions="actionSearch|flagNoFullscreen"
android:id="@+id/search_view" />
android:visibility="gone" />


</ch.blinkenlights.android.vanilla.BottomBarControls>

0 comments on commit 5c7e616

Please sign in to comment.