implement ch.blinkenlights.android.vanilla.VanillaImageButton

This commit is contained in:
Adrian Ulrich 2015-04-03 10:43:13 +02:00
parent 1fb36bef5d
commit f058f21b97
4 changed files with 84 additions and 6 deletions

View File

@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ImageButton
<ch.blinkenlights.android.vanilla.VanillaImageButton
android:id="@+id/shuffle"
android:layout_height="fill_parent"
android:layout_width="0px"
@ -30,7 +30,7 @@ THE SOFTWARE.
android:scaleType="fitCenter"
android:src="@drawable/shuffle_inactive"
android:contentDescription="@string/cycle_shuffle_mode" />
<ImageButton
<ch.blinkenlights.android.vanilla.VanillaImageButton
android:id="@+id/previous"
android:layout_height="fill_parent"
android:layout_width="0px"
@ -39,7 +39,7 @@ THE SOFTWARE.
android:scaleType="fitCenter"
android:src="@drawable/previous"
android:contentDescription="@string/previous_song" />
<ImageButton
<ch.blinkenlights.android.vanilla.VanillaImageButton
android:id="@+id/play_pause"
android:layout_height="fill_parent"
android:layout_width="0px"
@ -48,7 +48,7 @@ THE SOFTWARE.
android:scaleType="fitCenter"
android:src="@drawable/play"
android:contentDescription="@string/play_pause" />
<ImageButton
<ch.blinkenlights.android.vanilla.VanillaImageButton
android:id="@+id/next"
android:layout_height="fill_parent"
android:layout_width="0px"
@ -57,7 +57,7 @@ THE SOFTWARE.
android:scaleType="fitCenter"
android:src="@drawable/next"
android:contentDescription="@string/next_song" />
<ImageButton
<ch.blinkenlights.android.vanilla.VanillaImageButton
android:id="@+id/end_action"
android:layout_height="fill_parent"
android:layout_width="0px"
@ -66,4 +66,4 @@ THE SOFTWARE.
android:scaleType="fitCenter"
android:src="@drawable/repeat_inactive"
android:contentDescription="@string/cycle_repeat_mode" />
</merge>
</merge>

View File

@ -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);

View File

@ -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";
}

View File

@ -0,0 +1,74 @@
/*
* Copyright (C) 2015 Adrian Ulrich <adrian@blinkenlights.ch>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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);
}
}
}