Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ public class MyApplication extends Application {
Iconify
.with(new FontAwesomeModule())
.with(new EntypoModule())
.with(new TypiconsModule());
.with(new MaterialModule());
.with(new MeteoconsModule());
.with(new WeathericonsModule());
.with(new SimpleLineIconsModule());
.with(new TypiconsModule())
.with(new MaterialModule())
.with(new MaterialCommunityModule())
.with(new MeteoconsModule())
.with(new WeathericonsModule())
.with(new SimpleLineIconsModule())
.with(new IoniconsModule());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.joanzapata.iconify;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.*;
import android.graphics.drawable.Drawable;
import android.text.TextPaint;
Expand Down Expand Up @@ -33,6 +34,7 @@ public class IconDrawable extends Drawable {
private int size = -1;

private int alpha = 255;
private ColorStateList colorStateList;

/**
* Create an IconDrawable.
Expand Down Expand Up @@ -130,7 +132,11 @@ public IconDrawable color(int color) {
* @return The current IconDrawable for chaining.
*/
public IconDrawable colorRes(int colorRes) {
paint.setColor(context.getResources().getColor(colorRes));
colorStateList = context.getResources().getColorStateList(colorRes);
if (colorStateList == null) {
colorStateList = ColorStateList.valueOf(Color.BLACK);
}
paint.setColor(colorStateList.getColorForState(getState(), colorStateList.getDefaultColor()));
invalidateSelf();
return this;
}
Expand Down Expand Up @@ -175,11 +181,21 @@ public boolean isStateful() {
}

@Override
public boolean setState(int[] stateSet) {
int oldValue = paint.getAlpha();
int newValue = isEnabled(stateSet) ? alpha : alpha / 2;
paint.setAlpha(newValue);
return oldValue != newValue;
protected boolean onStateChange(int[] state) {
boolean changed;
if (colorStateList == null || !colorStateList.isStateful()) {
int oldValue = paint.getAlpha();
int newValue = isEnabled(state) ? alpha : alpha / 2;
paint.setAlpha(newValue);
changed = oldValue != newValue;
} else {
int oldColor = paint.getColor();
int newColor = colorStateList.getColorForState(state, oldColor);
paint.setColor(newColor);
changed = oldColor != newColor;
}

return changed;
}

@Override
Expand Down