Search in sources :

Example 1 with RoundedBitmapDrawable

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);
        }
    });
}
Also used : RoundedBitmapDrawable(androidx.core.graphics.drawable.RoundedBitmapDrawable) Bitmap(android.graphics.Bitmap) BitmapImageViewTarget(com.bumptech.glide.request.target.BitmapImageViewTarget) Drawable(android.graphics.drawable.Drawable) RoundedBitmapDrawable(androidx.core.graphics.drawable.RoundedBitmapDrawable)

Example 2 with RoundedBitmapDrawable

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;
}
Also used : RoundedBitmapDrawable(androidx.core.graphics.drawable.RoundedBitmapDrawable) Bitmap(android.graphics.Bitmap)

Example 3 with 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;
}
Also used : RoundedBitmapDrawable(androidx.core.graphics.drawable.RoundedBitmapDrawable)

Example 4 with RoundedBitmapDrawable

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());
    }
}
Also used : SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) RoundedBitmapDrawable(androidx.core.graphics.drawable.RoundedBitmapDrawable) Bitmap(android.graphics.Bitmap) Drawable(android.graphics.drawable.Drawable) TextDrawable(com.owncloud.android.ui.TextDrawable) RoundedBitmapDrawable(androidx.core.graphics.drawable.RoundedBitmapDrawable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation)

Example 5 with RoundedBitmapDrawable

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;
}
Also used : RoundedBitmapDrawable(androidx.core.graphics.drawable.RoundedBitmapDrawable)

Aggregations

RoundedBitmapDrawable (androidx.core.graphics.drawable.RoundedBitmapDrawable)6 Bitmap (android.graphics.Bitmap)4 Drawable (android.graphics.drawable.Drawable)2 Canvas (android.graphics.Canvas)1 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)1 BitmapImageViewTarget (com.bumptech.glide.request.target.BitmapImageViewTarget)1 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)1 TextDrawable (com.owncloud.android.ui.TextDrawable)1