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;
}
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;
}
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;
}
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;
}
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));
}
}
}
});
}
}
Aggregations