Search in sources :

Example 36 with ColorFilter

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));
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ColorFilter(android.graphics.ColorFilter) InvocationOnMock(org.mockito.invocation.InvocationOnMock) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint)

Example 37 with ColorFilter

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);
}
Also used : Rect(android.graphics.Rect) ColorFilter(android.graphics.ColorFilter) Test(org.junit.Test)

Example 38 with ColorFilter

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);
}
Also used : Rect(android.graphics.Rect) ColorFilter(android.graphics.ColorFilter) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint)

Example 39 with ColorFilter

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);
        }
    }
}
Also used : ColorFilter(android.graphics.ColorFilter)

Example 40 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;
}
Also used : FilterableStateListDrawable(com.bilibili.magicasakura.drawables.FilterableStateListDrawable) ColorFilter(android.graphics.ColorFilter) ArrayList(java.util.ArrayList) StateListDrawable(android.graphics.drawable.StateListDrawable) Drawable(android.graphics.drawable.Drawable) FilterableStateListDrawable(com.bilibili.magicasakura.drawables.FilterableStateListDrawable) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) StateListDrawable(android.graphics.drawable.StateListDrawable) FilterableStateListDrawable(com.bilibili.magicasakura.drawables.FilterableStateListDrawable)

Aggregations

ColorFilter (android.graphics.ColorFilter)50 LightingColorFilter (android.graphics.LightingColorFilter)21 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)17 Drawable (android.graphics.drawable.Drawable)17 FilterableStateListDrawable (com.simplecity.amp_library.ui.views.FilterableStateListDrawable)16 Paint (android.graphics.Paint)14 LayerDrawable (android.graphics.drawable.LayerDrawable)14 Path (android.graphics.Path)5 RectF (android.graphics.RectF)5 Test (org.junit.Test)5 Bitmap (android.graphics.Bitmap)4 Canvas (android.graphics.Canvas)4 Rect (android.graphics.Rect)3 Shader (android.graphics.Shader)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 StateListDrawable (android.graphics.drawable.StateListDrawable)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 FilterableStateListDrawable (com.bilibili.magicasakura.drawables.FilterableStateListDrawable)2