From f058f21b97fb638162df1b93195f1ee7e1138bc1 Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Fri, 3 Apr 2015 10:43:13 +0200 Subject: [PATCH] implement ch.blinkenlights.android.vanilla.VanillaImageButton --- res/layout/controls.xml | 12 +-- .../android/vanilla/PlaybackService.java | 3 + .../android/vanilla/PrefKeys.java | 1 + .../android/vanilla/VanillaImageButton.java | 74 +++++++++++++++++++ 4 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 src/ch/blinkenlights/android/vanilla/VanillaImageButton.java diff --git a/res/layout/controls.xml b/res/layout/controls.xml index 43bdf6b4..3229f777 100644 --- a/res/layout/controls.xml +++ b/res/layout/controls.xml @@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> - - - - - - \ No newline at end of file + diff --git a/src/ch/blinkenlights/android/vanilla/PlaybackService.java b/src/ch/blinkenlights/android/vanilla/PlaybackService.java index e2d6c822..d7a4e763 100644 --- a/src/ch/blinkenlights/android/vanilla/PlaybackService.java +++ b/src/ch/blinkenlights/android/vanilla/PlaybackService.java @@ -417,6 +417,9 @@ public final class PlaybackService extends Service Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_VANILLA, true) ? Song.mCoverLoadMode | Song.COVER_MODE_VANILLA : Song.mCoverLoadMode & ~(Song.COVER_MODE_VANILLA); Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_SHADOW , true) ? Song.mCoverLoadMode | Song.COVER_MODE_SHADOW : Song.mCoverLoadMode & ~(Song.COVER_MODE_SHADOW); + // The 'light' (aka: material) theme is the default on Android 5.x + VanillaImageButton.mLightTheme = settings.getBoolean(PrefKeys.USE_LIGHT_THEME, Build.VERSION.SDK_INT >= 21); + mHeadsetOnly = settings.getBoolean(PrefKeys.HEADSET_ONLY, false); mStockBroadcast = settings.getBoolean(PrefKeys.STOCK_BROADCAST, false); mNotificationAction = createNotificationAction(settings); diff --git a/src/ch/blinkenlights/android/vanilla/PrefKeys.java b/src/ch/blinkenlights/android/vanilla/PrefKeys.java index ff428854..0074cb1b 100644 --- a/src/ch/blinkenlights/android/vanilla/PrefKeys.java +++ b/src/ch/blinkenlights/android/vanilla/PrefKeys.java @@ -63,4 +63,5 @@ public class PrefKeys { public static final String REPLAYGAIN_BUMP = "replaygain_bump"; public static final String REPLAYGAIN_UNTAGGED_DEBUMP = "replaygain_untagged_debump"; public static final String ENABLE_READAHEAD = "enable_readahead"; + public static final String USE_LIGHT_THEME = "light_theme"; } diff --git a/src/ch/blinkenlights/android/vanilla/VanillaImageButton.java b/src/ch/blinkenlights/android/vanilla/VanillaImageButton.java new file mode 100644 index 00000000..e6863ac3 --- /dev/null +++ b/src/ch/blinkenlights/android/vanilla/VanillaImageButton.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2015 Adrian Ulrich + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +package ch.blinkenlights.android.vanilla; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.ImageButton; +import android.graphics.Color; +import android.graphics.ColorFilter; + +public class VanillaImageButton extends ImageButton { + + public static boolean mLightTheme = false; + + public VanillaImageButton(Context context) { + super(context); + updateImageTint(-1); + } + + public VanillaImageButton(Context context, AttributeSet attrs) { + super(context, attrs); + updateImageTint(-1); + } + + public VanillaImageButton(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + updateImageTint(-1); + } + + @Override + public void setImageResource(int resId) { + super.setImageResource(resId); + this.updateImageTint(resId); + } + + + private void updateImageTint(int resHint) { + boolean setFilter = mLightTheme == true; + + // These drawables should never be filtered: + switch (resHint) { + case R.drawable.repeat_active: + case R.drawable.repeat_current_active: + case R.drawable.stop_current_active: + case R.drawable.shuffle_active: + case R.drawable.shuffle_album_active: + case R.drawable.random_active: + setFilter = false; + } + + if (setFilter == true) { + this.setColorFilter(Color.argb(255, 130, 130, 130)); + } else { + this.setColorFilter(null); + } + } + +}