Search in sources :

Example 51 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project fresco by facebook.

the class WrappingUtils method applyLeafRounding.

/**
   * Rounds the given drawable with a {@link RoundedBitmapDrawable} or {@link RoundedColorDrawable}.
   *
   * <p> If the given drawable is not a {@link BitmapDrawable} or a {@link ColorDrawable}, it is
   * returned without being rounded.
   *
   * @return the rounded drawable, or the original drawable if rounding didn't take place
   */
private static Drawable applyLeafRounding(Drawable drawable, RoundingParams roundingParams, Resources resources) {
    if (drawable instanceof BitmapDrawable) {
        final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        RoundedBitmapDrawable roundedBitmapDrawable = new RoundedBitmapDrawable(resources, bitmapDrawable.getBitmap(), bitmapDrawable.getPaint());
        applyRoundingParams(roundedBitmapDrawable, roundingParams);
        return roundedBitmapDrawable;
    }
    if (drawable instanceof ColorDrawable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        RoundedColorDrawable roundedColorDrawable = RoundedColorDrawable.fromColorDrawable((ColorDrawable) drawable);
        applyRoundingParams(roundedColorDrawable, roundingParams);
        return roundedColorDrawable;
    }
    return drawable;
}
Also used : RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable)

Example 52 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project fresco by facebook.

the class RoundedBitmapDrawableTest method testPreservePaintOnDrawableCopy.

@Test
public void testPreservePaintOnDrawableCopy() {
    ColorFilter colorFilter = mock(ColorFilter.class);
    Paint originalPaint = mock(Paint.class);
    BitmapDrawable originalVersion = mock(BitmapDrawable.class);
    originalPaint.setColorFilter(colorFilter);
    when(originalVersion.getPaint()).thenReturn(originalPaint);
    RoundedBitmapDrawable roundedVersion = RoundedBitmapDrawable.fromBitmapDrawable(mResources, originalVersion);
    assertEquals(originalVersion.getPaint().getColorFilter(), roundedVersion.getPaint().getColorFilter());
}
Also used : ColorFilter(android.graphics.ColorFilter) Paint(android.graphics.Paint) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Test(org.junit.Test)

Example 53 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project fresco by facebook.

the class DrawableTestUtils method stubGetBitmap.

/**
   * Stubs getBitmap for BitmapDrawables.
   * @param drawable drawable to stub methods of
   */
public static void stubGetBitmap(Drawable drawable) {
    if (!(drawable instanceof BitmapDrawable)) {
        return;
    }
    BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
    final Bitmap bitmap = mock(Bitmap.class);
    when(bitmapDrawable.getBitmap()).thenReturn(bitmap);
}
Also used : Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 54 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project XobotOS by xamarin.

the class PointerIcon method loadResource.

private void loadResource(Resources resources, int resourceId) {
    XmlResourceParser parser = resources.getXml(resourceId);
    final int bitmapRes;
    final float hotSpotX;
    final float hotSpotY;
    try {
        XmlUtils.beginDocument(parser, "pointer-icon");
        TypedArray a = resources.obtainAttributes(parser, com.android.internal.R.styleable.PointerIcon);
        bitmapRes = a.getResourceId(com.android.internal.R.styleable.PointerIcon_bitmap, 0);
        hotSpotX = a.getFloat(com.android.internal.R.styleable.PointerIcon_hotSpotX, 0);
        hotSpotY = a.getFloat(com.android.internal.R.styleable.PointerIcon_hotSpotY, 0);
        a.recycle();
    } catch (Exception ex) {
        throw new IllegalArgumentException("Exception parsing pointer icon resource.", ex);
    } finally {
        parser.close();
    }
    if (bitmapRes == 0) {
        throw new IllegalArgumentException("<pointer-icon> is missing bitmap attribute.");
    }
    Drawable drawable = resources.getDrawable(bitmapRes);
    if (!(drawable instanceof BitmapDrawable)) {
        throw new IllegalArgumentException("<pointer-icon> bitmap attribute must " + "refer to a bitmap drawable.");
    }
    // Set the properties now that we have successfully loaded the icon.
    mBitmap = ((BitmapDrawable) drawable).getBitmap();
    mHotSpotX = hotSpotX;
    mHotSpotY = hotSpotY;
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) TypedArray(android.content.res.TypedArray) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 55 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project WordPress-Android by wordpress-mobile.

the class WPImageGetter method getDrawable.

@Override
public Drawable getDrawable(String source) {
    if (mImageLoader == null || mLoadingDrawable == null || mFailedDrawable == null) {
        throw new RuntimeException("Developer, you need to call setImageLoader, setLoadingDrawable and setFailedDrawable");
    }
    if (TextUtils.isEmpty(source)) {
        return null;
    }
    // images in reader comments may skip "http:" (no idea why) so make sure to add protocol here
    if (source.startsWith("//")) {
        source = "http:" + source;
    }
    // and then resized)
    if (mMaxSize > 0) {
        source = PhotonUtils.getPhotonImageUrl(source, mMaxSize, 0);
    }
    final RemoteDrawable remote = new RemoteDrawable(mLoadingDrawable, mFailedDrawable);
    mImageLoader.get(source, new ImageLoader.ImageListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            remote.displayFailed();
            TextView view = getView();
            if (view != null) {
                view.invalidate();
            }
        }

        @Override
        public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
            if (response.getBitmap() == null) {
                AppLog.w(T.UTILS, "WPImageGetter null bitmap");
            }
            TextView view = getView();
            if (view == null) {
                AppLog.w(T.UTILS, "WPImageGetter view is invalid");
                return;
            }
            int maxWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
            if (mMaxSize > 0 && (maxWidth > mMaxSize || maxWidth == 0)) {
                maxWidth = mMaxSize;
            }
            Drawable drawable = new BitmapDrawable(view.getContext().getResources(), response.getBitmap());
            remote.setRemoteDrawable(drawable, maxWidth);
            // accommodate the image isn't necessary
            if (!isImmediate) {
                view.setText(view.getText());
            }
        }
    });
    return remote;
}
Also used : VolleyError(com.android.volley.VolleyError) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) TextView(android.widget.TextView) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageLoader(com.android.volley.toolbox.ImageLoader)

Aggregations

BitmapDrawable (android.graphics.drawable.BitmapDrawable)640 Bitmap (android.graphics.Bitmap)426 Drawable (android.graphics.drawable.Drawable)187 Canvas (android.graphics.Canvas)182 Paint (android.graphics.Paint)110 Rect (android.graphics.Rect)77 View (android.view.View)77 ImageView (android.widget.ImageView)63 ColorDrawable (android.graphics.drawable.ColorDrawable)59 TextView (android.widget.TextView)51 IOException (java.io.IOException)40 Resources (android.content.res.Resources)35 LayerDrawable (android.graphics.drawable.LayerDrawable)33 AnimationDrawable (android.graphics.drawable.AnimationDrawable)30 File (java.io.File)27 Test (org.junit.Test)24 Matrix (android.graphics.Matrix)23 Intent (android.content.Intent)22 StateListDrawable (android.graphics.drawable.StateListDrawable)22 InputStream (java.io.InputStream)22