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;
}
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());
}
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);
}
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;
}
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;
}
Aggregations