Search in sources :

Example 16 with RoundedBitmapDrawable

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

Example 17 with RoundedBitmapDrawable

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;
}
Also used : RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) Bitmap(android.graphics.Bitmap) Nullable(android.support.annotation.Nullable)

Example 18 with RoundedBitmapDrawable

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;
    }
}
Also used : RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream) IOException(java.io.IOException) Nullable(android.support.annotation.Nullable)

Example 19 with RoundedBitmapDrawable

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;
    }
}
Also used : RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) Bitmap(android.graphics.Bitmap) IOException(java.io.IOException) Nullable(android.support.annotation.Nullable)

Example 20 with RoundedBitmapDrawable

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

Aggregations

RoundedBitmapDrawable (android.support.v4.graphics.drawable.RoundedBitmapDrawable)30 Bitmap (android.graphics.Bitmap)14 View (android.view.View)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 Resources (android.content.res.Resources)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 Drawable (android.graphics.drawable.Drawable)4 NonNull (android.support.annotation.NonNull)3 Nullable (android.support.annotation.Nullable)3 RecyclerView (android.support.v7.widget.RecyclerView)3 IOException (java.io.IOException)3 Uri (android.net.Uri)2 SpannableStringBuilder (android.text.SpannableStringBuilder)2 LayoutInflater (android.view.LayoutInflater)2 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)2 BitmapImageViewTarget (com.bumptech.glide.request.target.BitmapImageViewTarget)2 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1