use of androidx.core.graphics.drawable.RoundedBitmapDrawable in project android by nextcloud.
the class AvatarGroupLayout method showFederatedShareAvatar.
private void showFederatedShareAvatar(Context context, String user, float avatarRadius, Resources resources, ImageView avatar) {
// maybe federated share
String[] split = user.split("@");
String userId = split[0];
String server = split[1];
String url = "https://" + server + "/index.php/avatar/" + userId + "/" + resources.getInteger(R.integer.file_avatar_px);
Drawable placeholder;
try {
placeholder = TextDrawable.createAvatarByUserId(userId, avatarRadius);
} catch (Exception e) {
Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
placeholder = ThemeDrawableUtils.tintDrawable(ResourcesCompat.getDrawable(resources, R.drawable.account_circle_white, null), R.color.black);
}
avatar.setTag(null);
Glide.with(context).load(url).asBitmap().placeholder(placeholder).error(placeholder).into(new BitmapImageViewTarget(avatar) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(resources, resource);
circularBitmapDrawable.setCircular(true);
avatar.setImageDrawable(circularBitmapDrawable);
}
});
}
use of androidx.core.graphics.drawable.RoundedBitmapDrawable in project BottomSheet by soarcn.
the class ListAcitivty method getRoundedBitmap.
private Drawable getRoundedBitmap(int imageId) {
Bitmap src = BitmapFactory.decodeResource(getResources(), imageId);
Bitmap dst;
if (src.getWidth() >= src.getHeight()) {
dst = Bitmap.createBitmap(src, src.getWidth() / 2 - src.getHeight() / 2, 0, src.getHeight(), src.getHeight());
} else {
dst = Bitmap.createBitmap(src, 0, src.getHeight() / 2 - src.getWidth() / 2, src.getWidth(), src.getWidth());
}
RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), dst);
roundedBitmapDrawable.setCornerRadius(dst.getWidth() / 2);
roundedBitmapDrawable.setAntiAlias(true);
return roundedBitmapDrawable;
}
use of androidx.core.graphics.drawable.RoundedBitmapDrawable in project android by owncloud.
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 androidx.core.graphics.drawable.RoundedBitmapDrawable in project android by nextcloud.
the class ContactListAdapter method setPhoto.
private void setPhoto(ImageView imageView, Photo firstPhoto) {
String url = firstPhoto.getUrl();
byte[] data = firstPhoto.getData();
if (data != null && data.length > 0) {
Bitmap thumbnail = BitmapFactory.decodeByteArray(data, 0, data.length);
RoundedBitmapDrawable drawable = BitmapUtils.bitmapToCircularBitmapDrawable(context.getResources(), thumbnail);
imageView.setImageDrawable(drawable);
} else if (url != null) {
SimpleTarget target = new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
imageView.setImageDrawable(resource);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
imageView.setImageDrawable(errorDrawable);
}
};
DisplayUtils.downloadIcon(accountManager, clientFactory, context, url, target, R.drawable.ic_user, imageView.getWidth(), imageView.getHeight());
}
}
use of androidx.core.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, float radius) {
if (bitmap == null) {
return null;
}
RoundedBitmapDrawable roundedBitmap = RoundedBitmapDrawableFactory.create(resources, bitmap);
roundedBitmap.setCircular(true);
if (radius != -1) {
roundedBitmap.setCornerRadius(radius);
}
return roundedBitmap;
}
Aggregations