Search in sources :

Example 11 with RoundedBitmapDrawable

use of android.support.v4.graphics.drawable.RoundedBitmapDrawable in project actor-platform by actorapp.

the class ContactHolder method getRoundedBitmapDrawable.

private RoundedBitmapDrawable getRoundedBitmapDrawable(Context context, Bitmap b) {
    RoundedBitmapDrawable d = RoundedBitmapDrawableFactory.create(context.getResources(), Bitmap.createScaledBitmap(b, Screen.dp(48), Screen.dp(48), false));
    d.setCornerRadius(d.getIntrinsicHeight() / 2);
    d.setAntiAlias(true);
    return d;
}
Also used : RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable)

Example 12 with RoundedBitmapDrawable

use of android.support.v4.graphics.drawable.RoundedBitmapDrawable in project actor-platform by actorapp.

the class AndroidNotifications method getRoundedBitmapDrawable.

@NotNull
private RoundedBitmapDrawable getRoundedBitmapDrawable(FileSystemReference reference) {
    Bitmap b = BitmapFactory.decodeFile(reference.getDescriptor());
    RoundedBitmapDrawable d = RoundedBitmapDrawableFactory.create(context.getResources(), Bitmap.createScaledBitmap(b, Screen.dp(55), Screen.dp(55), false));
    d.setCornerRadius(d.getIntrinsicHeight() / 2);
    d.setAntiAlias(true);
    return d;
}
Also used : RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) Bitmap(android.graphics.Bitmap) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with RoundedBitmapDrawable

use of android.support.v4.graphics.drawable.RoundedBitmapDrawable in project qksms by moezbhatti.

the class ImageUtils method getRoundedDrawable.

public static RoundedBitmapDrawable getRoundedDrawable(Context context, Bitmap bitmap, int radiusDp) {
    float radius = (float) Units.dpToPx(context, radiusDp);
    RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);
    drawable.setCornerRadius(radius);
    drawable.setAntiAlias(true);
    return drawable;
}
Also used : RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable)

Example 14 with RoundedBitmapDrawable

use of android.support.v4.graphics.drawable.RoundedBitmapDrawable in project AndLang by wugemu.

the class GlideUtil method createRoundImageWithBorder.

private Drawable createRoundImageWithBorder(Context context, Bitmap bitmap, int borderWidthHalf, int borderColor) {
    // 原图宽度
    int bitmapWidth = bitmap.getWidth();
    // 原图高度
    int bitmapHeight = bitmap.getHeight();
    // 边框宽度 pixel
    // int borderWidthHalf = (int)context.getResources().getDimension(R.dimen.head_broder);
    // 转换为正方形后的宽高
    int bitmapSquareWidth = Math.min(bitmapWidth, bitmapHeight);
    // 最终图像的宽高
    int newBitmapSquareWidth = bitmapSquareWidth + borderWidthHalf;
    Bitmap roundedBitmap = Bitmap.createBitmap(newBitmapSquareWidth, newBitmapSquareWidth, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(roundedBitmap);
    int x = borderWidthHalf + bitmapSquareWidth - bitmapWidth;
    int y = borderWidthHalf + bitmapSquareWidth - bitmapHeight;
    // 裁剪后图像,注意X,Y要除以2 来进行一个中心裁剪
    canvas.drawBitmap(bitmap, x / 2, y / 2, null);
    Paint borderPaint = new Paint();
    borderPaint.setStyle(Paint.Style.STROKE);
    borderPaint.setStrokeWidth(borderWidthHalf);
    borderPaint.setColor(borderColor);
    borderPaint.setAntiAlias(true);
    // 添加边框
    canvas.drawCircle(canvas.getWidth() / 2, canvas.getWidth() / 2, newBitmapSquareWidth / 2, borderPaint);
    RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(context.getResources(), roundedBitmap);
    roundedBitmapDrawable.setGravity(Gravity.CENTER);
    roundedBitmapDrawable.setCircular(true);
    return roundedBitmapDrawable;
}
Also used : RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 15 with RoundedBitmapDrawable

use of android.support.v4.graphics.drawable.RoundedBitmapDrawable in project android by nextcloud.

the class ContactListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ContactListFragment.ContactItemViewHolder holder, final int position) {
    final int verifiedPosition = holder.getAdapterPosition();
    final VCard vcard = vCards.get(verifiedPosition);
    if (vcard != null) {
        if (checkedVCards.contains(position)) {
            holder.getName().setChecked(true);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                holder.getName().getCheckMarkDrawable().setColorFilter(ThemeUtils.primaryAccentColor(), PorterDuff.Mode.SRC_ATOP);
            }
        } else {
            holder.getName().setChecked(false);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                holder.getName().getCheckMarkDrawable().clearColorFilter();
            }
        }
        holder.getName().setText(getDisplayName(vcard));
        // photo
        if (vcard.getPhotos().size() > 0) {
            Photo firstPhoto = vcard.getPhotos().get(0);
            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);
                holder.getBadge().setImageDrawable(drawable);
            } else if (url != null) {
                ImageView badge = holder.getBadge();
                SimpleTarget target = new SimpleTarget<Drawable>() {

                    @Override
                    public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
                        holder.getBadge().setImageDrawable(resource);
                    }

                    @Override
                    public void onLoadFailed(Exception e, Drawable errorDrawable) {
                        super.onLoadFailed(e, errorDrawable);
                        holder.getBadge().setImageDrawable(errorDrawable);
                    }
                };
                DisplayUtils.downloadIcon(context, url, target, R.drawable.ic_user, badge.getWidth(), badge.getHeight());
            }
        } else {
            try {
                holder.getBadge().setImageDrawable(TextDrawable.createNamedAvatar(holder.getName().getText().toString(), context.getResources().getDimension(R.dimen.list_item_avatar_icon_radius)));
            } catch (Exception e) {
                holder.getBadge().setImageResource(R.drawable.ic_user);
            }
        }
        // Checkbox
        holder.setVCardListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                holder.getName().setChecked(!holder.getName().isChecked());
                if (holder.getName().isChecked()) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        holder.getName().getCheckMarkDrawable().setColorFilter(ThemeUtils.primaryAccentColor(), PorterDuff.Mode.SRC_ATOP);
                    }
                    if (!checkedVCards.contains(verifiedPosition)) {
                        checkedVCards.add(verifiedPosition);
                    }
                    if (checkedVCards.size() == 1) {
                        EventBus.getDefault().post(new VCardToggleEvent(true));
                    }
                } else {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        holder.getName().getCheckMarkDrawable().clearColorFilter();
                    }
                    if (checkedVCards.contains(verifiedPosition)) {
                        checkedVCards.remove(verifiedPosition);
                    }
                    if (checkedVCards.size() == 0) {
                        EventBus.getDefault().post(new VCardToggleEvent(false));
                    }
                }
            }
        });
    }
}
Also used : RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) Drawable(android.graphics.drawable.Drawable) TextDrawable(com.owncloud.android.ui.TextDrawable) RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) Photo(ezvcard.property.Photo) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) CheckedTextView(android.widget.CheckedTextView) IOException(java.io.IOException) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Bitmap(android.graphics.Bitmap) VCardToggleEvent(com.owncloud.android.ui.events.VCardToggleEvent) ImageView(android.widget.ImageView) VCard(ezvcard.VCard)

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