aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/DrawableTint.java83
-rw-r--r--app/src/main/res/drawable-hdpi/ic_stat_star.pngbin826 -> 0 bytes
-rw-r--r--app/src/main/res/drawable-hdpi/ic_toggle_star.pngbin0 -> 904 bytes
-rw-r--r--app/src/main/res/drawable-mdpi/ic_toggle_star.pngbin0 -> 612 bytes
-rw-r--r--app/src/main/res/drawable-xhdpi/ic_toggle_star.pngbin0 -> 1260 bytes
-rw-r--r--app/src/main/res/drawable-xxhdpi/ic_toggle_star.pngbin0 -> 1930 bytes
-rw-r--r--app/src/main/res/drawable-xxxhdpi/ic_toggle_star.pngbin0 -> 2798 bytes
7 files changed, 83 insertions, 0 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/util/DrawableTint.java b/app/src/main/java/github/daneren2005/dsub/util/DrawableTint.java
new file mode 100644
index 00000000..d3c4ebb4
--- /dev/null
+++ b/app/src/main/java/github/daneren2005/dsub/util/DrawableTint.java
@@ -0,0 +1,83 @@
+/*
+ This file is part of Subsonic.
+ Subsonic 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.
+ Subsonic 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 Subsonic. If not, see <http://www.gnu.org/licenses/>.
+ Copyright 2015 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.util;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.graphics.PorterDuff;
+import android.graphics.drawable.Drawable;
+import android.support.annotation.AttrRes;
+import android.support.annotation.DrawableRes;
+import android.util.TypedValue;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import github.daneren2005.dsub.R;
+
+public class DrawableTint {
+ private static final Map<Integer, Integer> attrMap = new HashMap<>();
+ private static final WeakHashMap<Integer, Drawable> tintedDrawables = new WeakHashMap<>();
+
+ public static Drawable getTintedDrawable(Context context, @DrawableRes int drawableRes, @AttrRes int colorAttr) {
+ if(tintedDrawables.containsKey(drawableRes)) {
+ return tintedDrawables.get(drawableRes);
+ }
+
+ int color;
+ if(attrMap.containsKey(colorAttr)) {
+ color = attrMap.get(colorAttr);
+ } else {
+ TypedValue typedValue = new TypedValue();
+ Resources.Theme theme = context.getTheme();
+ theme.resolveAttribute(colorAttr, typedValue, true);
+ color = typedValue.data;
+ attrMap.put(colorAttr, color);
+ }
+
+ Drawable background = context.getResources().getDrawable(drawableRes);
+ background.setColorFilter(color, PorterDuff.Mode.SRC_IN);
+ tintedDrawables.put(drawableRes, background);
+ return background;
+ }
+ public static int getDrawableRes(Context context, @AttrRes int drawableAttr) {
+ if(attrMap.containsKey(drawableAttr)) {
+ return attrMap.get(drawableAttr);
+ } else {
+ int[] attrs = new int[]{drawableAttr};
+ TypedArray typedArray = context.obtainStyledAttributes(attrs);
+ @DrawableRes int drawableRes = typedArray.getResourceId(0, 0);
+ typedArray.recycle();
+ attrMap.put(drawableAttr, drawableRes);
+ return drawableRes;
+ }
+ }
+ public static Drawable getTintedAttrDrawable(Context context, @AttrRes int drawableAttr, @AttrRes int colorAttr) {
+ if(tintedDrawables.containsKey(drawableAttr)) {
+ return getTintedDrawable(context, attrMap.get(drawableAttr), colorAttr);
+ }
+
+ @DrawableRes int drawableRes = getDrawableRes(context, drawableAttr);
+ return getTintedDrawable(context, drawableRes, colorAttr);
+ }
+
+ public static void wipeTintCache() {
+ attrMap.clear();
+ tintedDrawables.clear();
+ }
+}
diff --git a/app/src/main/res/drawable-hdpi/ic_stat_star.png b/app/src/main/res/drawable-hdpi/ic_stat_star.png
deleted file mode 100644
index 67ad40f5..00000000
--- a/app/src/main/res/drawable-hdpi/ic_stat_star.png
+++ /dev/null
Binary files differ
diff --git a/app/src/main/res/drawable-hdpi/ic_toggle_star.png b/app/src/main/res/drawable-hdpi/ic_toggle_star.png
new file mode 100644
index 00000000..f9ef8772
--- /dev/null
+++ b/app/src/main/res/drawable-hdpi/ic_toggle_star.png
Binary files differ
diff --git a/app/src/main/res/drawable-mdpi/ic_toggle_star.png b/app/src/main/res/drawable-mdpi/ic_toggle_star.png
new file mode 100644
index 00000000..6d949fd0
--- /dev/null
+++ b/app/src/main/res/drawable-mdpi/ic_toggle_star.png
Binary files differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_toggle_star.png b/app/src/main/res/drawable-xhdpi/ic_toggle_star.png
new file mode 100644
index 00000000..5c54298c
--- /dev/null
+++ b/app/src/main/res/drawable-xhdpi/ic_toggle_star.png
Binary files differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_toggle_star.png b/app/src/main/res/drawable-xxhdpi/ic_toggle_star.png
new file mode 100644
index 00000000..4db2a37c
--- /dev/null
+++ b/app/src/main/res/drawable-xxhdpi/ic_toggle_star.png
Binary files differ
diff --git a/app/src/main/res/drawable-xxxhdpi/ic_toggle_star.png b/app/src/main/res/drawable-xxxhdpi/ic_toggle_star.png
new file mode 100644
index 00000000..6116210d
--- /dev/null
+++ b/app/src/main/res/drawable-xxxhdpi/ic_toggle_star.png
Binary files differ