Add support for setTint in all Drawables, clean up lint warnings
Change-Id: Ia38b9d3e9d5c0072382050e815bdd9232b672e50
This commit is contained in:
@@ -31,6 +31,7 @@ import android.graphics.Paint;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuff.Mode;
|
||||
import android.graphics.drawable.ColorDrawable.ColorState;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Shader;
|
||||
@@ -618,9 +619,11 @@ public class BitmapDrawable extends Drawable {
|
||||
|
||||
@Override
|
||||
public void setTint(ColorStateList tint, PorterDuff.Mode tintMode) {
|
||||
mBitmapState.mTint = tint;
|
||||
mBitmapState.mTintMode = tintMode;
|
||||
computeTintFilter();
|
||||
final BitmapState state = mBitmapState;
|
||||
state.mTint = tint;
|
||||
state.mTintMode = tintMode;
|
||||
|
||||
mTintFilter = updateTintFilter(mTintFilter, tint, tintMode);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@@ -638,21 +641,6 @@ public class BitmapDrawable extends Drawable {
|
||||
return mBitmapState.mTintMode;
|
||||
}
|
||||
|
||||
private void computeTintFilter() {
|
||||
final BitmapState state = mBitmapState;
|
||||
if (state.mTint != null && state.mTintMode != null) {
|
||||
final int color = state.mTint.getColorForState(getState(), 0);
|
||||
if (mTintFilter != null) {
|
||||
mTintFilter.setColor(color);
|
||||
mTintFilter.setMode(state.mTintMode);
|
||||
} else {
|
||||
mTintFilter = new PorterDuffColorFilter(color, state.mTintMode);
|
||||
}
|
||||
} else {
|
||||
mTintFilter = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide Candidate for future API inclusion
|
||||
*/
|
||||
@@ -679,17 +667,11 @@ public class BitmapDrawable extends Drawable {
|
||||
|
||||
@Override
|
||||
protected boolean onStateChange(int[] stateSet) {
|
||||
final ColorStateList tint = mBitmapState.mTint;
|
||||
if (tint != null) {
|
||||
final int newColor = tint.getColorForState(stateSet, 0);
|
||||
final int oldColor = mTintFilter.getColor();
|
||||
if (oldColor != newColor) {
|
||||
mTintFilter.setColor(newColor);
|
||||
invalidateSelf();
|
||||
return true;
|
||||
}
|
||||
final BitmapState state = mBitmapState;
|
||||
if (state.mTint != null && state.mTintMode != null) {
|
||||
mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user