use of android.support.v4.graphics.drawable.RoundedBitmapDrawable in project android by nextcloud.
the class BitmapUtils method bitmapToCircularBitmapDrawable.
/**
* Returns a new circular bitmap drawable by creating it from a bitmap, setting initial target density based on
* the display metrics of the resources.
*
* @param resources the resources for initial target density
* @param bitmap the original bitmap
* @return the circular bitmap
*/
public static RoundedBitmapDrawable bitmapToCircularBitmapDrawable(Resources resources, Bitmap bitmap) {
RoundedBitmapDrawable roundedBitmap = RoundedBitmapDrawableFactory.create(resources, bitmap);
roundedBitmap.setCircular(true);
return roundedBitmap;
}
use of android.support.v4.graphics.drawable.RoundedBitmapDrawable in project android_packages_apps_Dialer by LineageOS.
the class DrawableConverter method getRoundedDrawable.
@Nullable
public static Drawable getRoundedDrawable(@NonNull Context context, @Nullable Drawable photo, int width, int height) {
Bitmap bitmap = drawableToBitmap(photo);
if (bitmap != null) {
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, width, height, false);
RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), scaledBitmap);
drawable.setAntiAlias(true);
drawable.setCornerRadius(drawable.getIntrinsicHeight() / 2);
return drawable;
}
return null;
}
use of android.support.v4.graphics.drawable.RoundedBitmapDrawable in project android_packages_apps_Dialer by LineageOS.
the class ContactPhotoLoader method createPhotoIconDrawable.
/**
* @return a {@link Drawable} of circular photo icon if the photo can be loaded, {@code null}
* otherwise.
*/
@Nullable
private Drawable createPhotoIconDrawable() {
if (mContactInfo.photoUri == null) {
return null;
}
try {
InputStream input = mContext.getContentResolver().openInputStream(mContactInfo.photoUri);
if (input == null) {
LogUtil.w("ContactPhotoLoader.createPhotoIconDrawable", "createPhotoIconDrawable: InputStream is null");
return null;
}
Bitmap bitmap = BitmapFactory.decodeStream(input);
input.close();
if (bitmap == null) {
LogUtil.w("ContactPhotoLoader.createPhotoIconDrawable", "createPhotoIconDrawable: Bitmap is null");
return null;
}
final RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), bitmap);
drawable.setAntiAlias(true);
drawable.setCircular(true);
return drawable;
} catch (IOException e) {
LogUtil.e("ContactPhotoLoader.createPhotoIconDrawable", e.toString());
return null;
}
}
use of android.support.v4.graphics.drawable.RoundedBitmapDrawable in project android_packages_apps_Dialer by MoKee.
the class ContactPhotoLoader method createPhotoIconDrawable.
/**
* @return a {@link Drawable} of circular photo icon if the photo can be loaded, {@code null}
* otherwise.
*/
@Nullable
private Drawable createPhotoIconDrawable() {
if (mContactInfo.photoUri == null) {
return null;
}
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(mContext.getContentResolver(), mContactInfo.photoUri);
final RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), bitmap);
drawable.setAntiAlias(true);
drawable.setCornerRadius(bitmap.getHeight() / 2);
return drawable;
} catch (IOException e) {
Log.e(TAG, e.toString());
return null;
}
}
use of android.support.v4.graphics.drawable.RoundedBitmapDrawable in project android_packages_apps_Dialer by MoKee.
the class CallCardFragment method setDrawableToImageViews.
/**
* Set all the ImageViews to the same photo. Currently there are 2 photo views: the large one
* (which fills about the bottom half of the screen) and the small one, which displays as a
* circle next to the primary contact info. This method does not handle whether the ImageView
* is shown or not.
*
* @param photo The photo to set for the image views.
*/
private void setDrawableToImageViews(Drawable photo) {
if (photo == null) {
photo = ContactInfoCache.getInstance(getView().getContext()).getDefaultContactPhotoDrawable();
}
if (mPrimaryPhotoDrawable == photo) {
return;
}
mPrimaryPhotoDrawable = photo;
mPhotoLarge.setImageDrawable(photo);
// Modify the drawable to be round for the smaller ImageView.
Bitmap bitmap = drawableToBitmap(photo);
if (bitmap != null) {
final RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
drawable.setAntiAlias(true);
drawable.setCornerRadius(bitmap.getHeight() / 2);
photo = drawable;
}
mPhotoSmall.setImageDrawable(photo);
}
Aggregations