use of android.graphics.ColorFilter in project fresco by facebook.
the class DrawableTestUtils method stubGetPaint.
/**
* Stubs getPaint for BitmapDrawables.
* @param drawable drawable to stub methods of
*/
public static void stubGetPaint(Drawable drawable) {
if (!(drawable instanceof BitmapDrawable)) {
return;
}
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
final Paint paint = new Paint();
when(bitmapDrawable.getPaint()).thenReturn(paint);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
paint.setColorFilter((ColorFilter) invocation.getArguments()[0]);
return null;
}
}).when(bitmapDrawable).setColorFilter(any(ColorFilter.class));
}
use of android.graphics.ColorFilter in project fresco by facebook.
the class ForwardingDrawableTest method testSettersAndGetters.
@Test
public void testSettersAndGetters() {
ColorFilter colorFilterMock = mock(ColorFilter.class);
Rect rectMock = mock(Rect.class);
int alpha = 77;
boolean dither = true;
boolean filterBitmap = false;
boolean visible = false;
boolean restart = false;
//when(mInnerDrawable.setVisible(visible, restart)).thenReturn(true);
when(mInnerDrawable.getOpacity()).thenReturn(11);
Assert.assertEquals(11, mDrawable.getOpacity());
mDrawable.getPadding(rectMock);
mDrawable.setAlpha(alpha);
mDrawable.setDither(dither);
mDrawable.setFilterBitmap(filterBitmap);
mDrawable.setColorFilter(colorFilterMock);
mDrawable.onBoundsChange(rectMock);
mDrawable.setVisible(visible, restart);
verify(mInnerDrawable).getPadding(rectMock);
verify(mInnerDrawable).setAlpha(alpha);
verify(mInnerDrawable).setDither(dither);
verify(mInnerDrawable).setFilterBitmap(filterBitmap);
verify(mInnerDrawable).setColorFilter(colorFilterMock);
verify(mInnerDrawable).setBounds(rectMock);
verify(mInnerDrawable).setVisible(visible, restart);
}
use of android.graphics.ColorFilter in project ElasticDownload by Tibolte.
the class VectorDrawable method draw.
@Override
public void draw(Canvas canvas) {
final Rect bounds = getBounds();
if (bounds.width() == 0 || bounds.height() == 0) {
// too small to draw
return;
}
final int saveCount = canvas.save();
final boolean needMirroring = needMirroring();
canvas.translate(bounds.left, bounds.top);
if (needMirroring) {
canvas.translate(bounds.width(), 0);
canvas.scale(-1.0f, 1.0f);
}
// Color filters always override tint filters.
final ColorFilter colorFilter = mColorFilter == null ? mTintFilter : mColorFilter;
if (!mAllowCaching) {
// AnimatedVectorDrawable
if (!mVectorState.hasTranslucentRoot()) {
mVectorState.mVPathRenderer.draw(canvas, bounds.width(), bounds.height(), colorFilter);
} else {
mVectorState.createCachedBitmapIfNeeded(bounds);
mVectorState.updateCachedBitmap(bounds);
mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter);
}
} else {
// Static Vector Drawable case.
mVectorState.createCachedBitmapIfNeeded(bounds);
if (!mVectorState.canReuseCache()) {
mVectorState.updateCachedBitmap(bounds);
mVectorState.updateCacheStates();
}
mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter);
}
canvas.restoreToCount(saveCount);
}
use of android.graphics.ColorFilter in project robolectric by robolectric.
the class ShadowCanvas method describeBitmap.
private void describeBitmap(Bitmap bitmap, Paint paint) {
separateLines();
appendDescription(shadowOf(bitmap).getDescription());
if (paint != null) {
ColorFilter colorFilter = paint.getColorFilter();
if (colorFilter != null) {
appendDescription(" with " + colorFilter);
}
}
}
use of android.graphics.ColorFilter in project remusic by aa112901.
the class StateListDrawableUtils method inflateDrawable.
@Override
protected Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
StateListDrawable sd = null;
ArrayList<int[]> states = new ArrayList<>();
ArrayList<Drawable> drawables = new ArrayList<>();
SparseArray<ColorFilter> mColorFilterMap = null;
final int innerDepth = parser.getDepth() + 1;
int type;
int depth;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
if (depth > innerDepth || !parser.getName().equals("item")) {
continue;
}
Drawable dr = getAttrDrawable(context, attrs, android.R.attr.drawable);
states.add(extractStateSet(attrs));
// attributes and extracting states.
if (dr == null) {
while ((type = parser.next()) == XmlPullParser.TEXT) {
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable");
}
dr = createFromXmlInner(context, parser, attrs);
} else {
ColorFilter colorFilter = getAttrColorFilter(context, attrs, R.attr.drawableTint, R.attr.drawableTintMode);
if (colorFilter != null) {
if (mColorFilterMap == null) {
mColorFilterMap = new SparseArray<>();
}
mColorFilterMap.put(drawables.size(), colorFilter);
}
}
drawables.add(dr);
}
if (states.size() >= 1) {
if (mColorFilterMap != null) {
sd = new FilterableStateListDrawable();
for (int i = 0; i < states.size(); i++) {
((FilterableStateListDrawable) sd).addState(states.get(i), drawables.get(i), mColorFilterMap.get(i));
}
} else {
sd = new StateListDrawable();
for (int i = 0; i < states.size(); i++) {
sd.addState(states.get(i), drawables.get(i));
}
}
}
return sd;
}
Aggregations