Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.text.TextPaint;
import android.util.TypedValue;

import java.lang.Override;

import static android.util.TypedValue.COMPLEX_UNIT_DIP;

/**
Expand Down Expand Up @@ -33,6 +35,8 @@ public class IconDrawable extends Drawable {

private int alpha = 255;

private IconDrawable.ConstantState constantState;

/**
* Create an IconDrawable.
* @param context Your activity or application context.
Expand Down Expand Up @@ -66,6 +70,7 @@ private void init(Context context, Icon icon) {
paint.setUnderlineText(false);
paint.setColor(Color.BLACK);
paint.setAntiAlias(true);
constantState = new IconDrawable.ConstantState(this);
}

/**
Expand Down Expand Up @@ -196,6 +201,15 @@ public int getOpacity() {
return this.alpha;
}

/*
* Fixes problem with setIcon() method, issue found (and wrongfully closed) here:
* https://github.com/JoanZapata/android-iconify/issues/93
*/
@Override
public Drawable.ConstantState getConstantState(){
return constantState;
}

/**
* Sets paint style.
* @param style to be applied
Expand All @@ -218,4 +232,23 @@ private int convertDpToPx(Context context, float dp) {
COMPLEX_UNIT_DIP, dp,
context.getResources().getDisplayMetrics());
}

public static class ConstantState extends Drawable.ConstantState{
private Drawable drawable;

public ConstantState(Drawable drawable){
super();
this.drawable = drawable;
}

public Drawable newDrawable(){
return drawable;
}

public int getChangingConfigurations(){
return 0;
}

}

}