Merge "Fix tint filters in NinePatchDrawable and ShapeDrawable"

This commit is contained in:
Alan Viverette
2014-06-17 01:37:40 +00:00
committed by Android (Google) Code Review
2 changed files with 12 additions and 35 deletions

View File

@@ -671,7 +671,7 @@ public class NinePatchDrawable extends Drawable {
mPadding = new Rect(state.mPadding);
}
updateTintFilter(mTintFilter, state.mTint, state.mTintMode);
mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode);
setNinePatch(state.mNinePatch);
}
}

View File

@@ -24,6 +24,7 @@ import android.graphics.ColorFilter;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.PorterDuff;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
@@ -284,31 +285,13 @@ public class ShapeDrawable extends Drawable {
}
@Override
public void setTint(ColorStateList tint, Mode tintMode) {
if (mShapeState.mTint != tint || mShapeState.mTintMode != tintMode) {
mShapeState.mTint = tint;
mShapeState.mTintMode = tintMode;
updateTintFilter();
invalidateSelf();
}
}
public void setTint(ColorStateList tint, PorterDuff.Mode tintMode) {
final ShapeState state = mShapeState;
state.mTint = tint;
state.mTintMode = tintMode;
/**
* Ensures the tint filter is consistent with the current tint color and
* mode.
*/
private void updateTintFilter() {
final ColorStateList tint = mShapeState.mTint;
final Mode tintMode = mShapeState.mTintMode;
if (tint != null && tintMode != null) {
if (mTintFilter == null) {
mTintFilter = new PorterDuffColorFilter(0, tintMode);
} else {
mTintFilter.setMode(tintMode);
}
} else {
mTintFilter = null;
}
mTintFilter = updateTintFilter(mTintFilter, tint, tintMode);
invalidateSelf();
}
@Override
@@ -349,17 +332,11 @@ public class ShapeDrawable extends Drawable {
@Override
protected boolean onStateChange(int[] stateSet) {
final ColorStateList tint = mShapeState.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 ShapeState state = mShapeState;
if (state.mTint != null && state.mTintMode != null) {
mTintFilter = updateTintFilter(mTintFilter, state.mTint, state.mTintMode);
return true;
}
return false;
}