下面列出了怎么用android.support.v4.graphics.drawable.RoundedBitmapDrawable的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 加载带有圆角的矩形图片 用glide处理
*
* @param path 路径
* @param round 圆角半径
* @param resId 加载失败时的图片
* @param target 控件
*/
public static void loadImgByPicassoWithRound(final Context activity, String path, final int round, int resId, final ImageView target) {
if (path != null && path.length() > 0) {
Glide.with(activity)
.load(path)
.asBitmap()
.placeholder(resId)
.error(resId)
//设置缓存
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new BitmapImageViewTarget(target) {
@Override
protected void setResource(Bitmap resource) {
super.setResource(resource);
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(activity.getResources(), resource);
//设置圆角弧度
circularBitmapDrawable.setCornerRadius(round);
target.setImageDrawable(circularBitmapDrawable);
}
});
}
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
if (holder instanceof BookCommentHolder) {
List<BookReviewBean> reviews = reviewsListResponse.getReviews();
Glide.with(BaseApplication.getAppContext())
.load(reviews.get(position).getAuthor().getAvatar())
.asBitmap()
.centerCrop()
.into(new BitmapImageViewTarget(((BookCommentHolder) holder).iv_avatar) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(BaseApplication.getAppContext().getResources(), resource);
circularBitmapDrawable.setCircular(true);
((BookCommentHolder) holder).iv_avatar.setImageDrawable(circularBitmapDrawable);
}
});
((BookCommentHolder) holder).tv_user_name.setText(reviews.get(position).getAuthor().getName());
if (reviews.get(position).getRating() != null) {
((BookCommentHolder) holder).ratingBar_hots.setRating(Float.valueOf(reviews.get(position).getRating().getValue()));
}
((BookCommentHolder) holder).tv_comment_content.setText(reviews.get(position).getSummary());
((BookCommentHolder) holder).tv_favorite_num.setText(reviews.get(position).getVotes() + "");
((BookCommentHolder) holder).tv_update_time.setText(reviews.get(position).getUpdated().split(" ")[0]);
}
}
private void initHalloweenTheme() {
if (!isHalloween) {
return;
}
Bitmap bmp = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.ground);
RoundedBitmapDrawable dr = RoundedBitmapDrawableFactory.create(getContext().getResources(), bmp);
dr.setCornerRadius(dialogRadius);
dr.setAntiAlias(true);
ground.setBackgroundDrawable(dr);
plane.setImageResource(R.drawable.witch);
tomb.setImageResource(R.drawable.tomb_hw);
moon.setVisibility(View.VISIBLE);
ground.setVisibility(View.VISIBLE);
pumpkin.setVisibility(View.VISIBLE);
wifiOn.getBackground().mutate().setColorFilter(ContextCompat.getColor(getContext(), R.color.colorNoInternetGradCenterH), PorterDuff.Mode.SRC_IN);
mobileOn.getBackground().mutate().setColorFilter(ContextCompat.getColor(getContext(), R.color.colorNoInternetGradCenterH), PorterDuff.Mode.SRC_IN);
airplaneOff.getBackground().mutate().setColorFilter(ContextCompat.getColor(getContext(), R.color.colorNoInternetGradCenterH), PorterDuff.Mode.SRC_IN);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri uri = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
if(flag==1) {passwordDatabase.updatePic(bitmap); }
else if(flag==0) {passwordDatabase.setPic(bitmap); flag=1; }
profile.setImageBitmap(bitmap);
//round image
RoundedBitmapDrawable roundedImageDrawable = createRoundedBitmapImageDrawableWithBorder(bitmap);
profile.setImageDrawable(roundedImageDrawable);
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public void onDraw(Canvas canvas) {
if (bitmap != null) {
int size = Math.min(canvas.getWidth(), canvas.getHeight());
if (size != this.size) {
this.size = size;
bitmap = ThumbnailUtils.extractThumbnail(bitmap, size, size);
RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
roundedBitmapDrawable.setCornerRadius(size / 2);
roundedBitmapDrawable.setAntiAlias(true);
bitmap = ImageUtils.drawableToBitmap(roundedBitmapDrawable);
}
canvas.drawBitmap(bitmap, 0, 0, paint);
}
}
@Override
public void onBindViewHolder(final XianViewHolder holder, int position) {
final XianduItem item = xiandus.get(position);
holder.rootView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
WebUtils.openInternal(context, item.getUrl());
}
});
holder.tv_name.setText(String.format("%s. %s", position + 1, item.getName()));
holder.tv_info.setText(item.getUpdateTime() + " • " + item.getFrom());
Glide.with(context).load(item.getIcon()).asBitmap().diskCacheStrategy(DiskCacheStrategy.ALL).fitCenter().into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(context.getResources(), resource);
circularBitmapDrawable.setCircular(true);
holder.iv.setImageDrawable(circularBitmapDrawable);
}
});
}
/**
* 加载带有圆角的矩形图片 用glide处理
*
* @param path 路径
* @param round 圆角半径
* @param resId 加载失败时的图片
* @param target 控件
*/
public static void loadImgByPicassoWithRound(final Context activity, String path, final int round, int resId, final ImageView target) {
if (path != null && path.length() > 0) {
Glide.with(activity)
.asBitmap()
.load(path)
.placeholder(resId)
.error(resId)
//设置缓存
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new BitmapImageViewTarget(target) {
@Override
protected void setResource(Bitmap resource) {
super.setResource(resource);
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(activity.getResources(), resource);
//设置圆角弧度
circularBitmapDrawable.setCornerRadius(round);
target.setImageDrawable(circularBitmapDrawable);
}
});
}
}
@Override
public void onLargeIconAvailable(Bitmap icon, int fallbackColor) {
if (icon == null) {
mIconGenerator.setBackgroundColor(fallbackColor);
icon = mIconGenerator.generateIconForUrl(mItem.getUrl());
mItemView.setIcon(new BitmapDrawable(getResources(), icon));
mItem.setTileType(fallbackColor == ICON_BACKGROUND_COLOR
? MostVisitedTileType.ICON_DEFAULT : MostVisitedTileType.ICON_COLOR);
} else {
RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(
getResources(), icon);
int cornerRadius = Math.round(ICON_CORNER_RADIUS_DP
* getResources().getDisplayMetrics().density * icon.getWidth()
/ mDesiredIconSize);
roundedIcon.setCornerRadius(cornerRadius);
roundedIcon.setAntiAlias(true);
roundedIcon.setFilterBitmap(true);
mItemView.setIcon(roundedIcon);
mItem.setTileType(MostVisitedTileType.ICON_REAL);
}
mSnapshotMostVisitedChanged = true;
if (mIsInitialLoad) loadTaskCompleted();
}
@Override
protected Drawable doInBackground(Void... voids) {
// This is run on a background thread.
try {
// TODO(peconn): Replace this with something from the C++ Chrome stack.
URL imageUrl = new URL(mUrl);
InputStream in = imageUrl.openStream();
Bitmap raw = BitmapFactory.decodeStream(in);
int dimension = Math.min(raw.getHeight(), raw.getWidth());
RoundedBitmapDrawable img = RoundedBitmapDrawableFactory.create(mResources,
ThumbnailUtils.extractThumbnail(raw, dimension, dimension));
img.setCircular(true);
return img;
} catch (IOException e) {
Log.e(TAG, "Error downloading image: " + e.toString());
}
return null;
}
@Override
public void onLargeIconAvailable(
Bitmap icon, int fallbackColor, boolean isFallbackColorDefault) {
if (icon == null) {
mIconGenerator.setBackgroundColor(fallbackColor);
icon = mIconGenerator.generateIconForUrl(mItem.getUrl());
mItemView.setIcon(new BitmapDrawable(getResources(), icon));
mItem.setTileType(isFallbackColorDefault ? MostVisitedTileType.ICON_DEFAULT
: MostVisitedTileType.ICON_COLOR);
} else {
RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(
getResources(), icon);
int cornerRadius = Math.round(ICON_CORNER_RADIUS_DP
* getResources().getDisplayMetrics().density * icon.getWidth()
/ mDesiredIconSize);
roundedIcon.setCornerRadius(cornerRadius);
roundedIcon.setAntiAlias(true);
roundedIcon.setFilterBitmap(true);
mItemView.setIcon(roundedIcon);
mItem.setTileType(MostVisitedTileType.ICON_REAL);
}
mSnapshotMostVisitedChanged = true;
if (mIsInitialLoad) loadTaskCompleted();
}
public void updateUi(Card card) {
TextView extraText = (TextView) findViewById(R.id.extra_text);
TextView primaryText = (TextView) findViewById(R.id.primary_text);
final ImageView imageView = (ImageView) findViewById(R.id.main_image);
extraText.setText(card.getExtraText());
primaryText.setText(card.getTitle());
// Create a rounded drawable.
int resourceId = card.getLocalImageResourceId(getContext());
Bitmap bitmap = BitmapFactory
.decodeResource(getContext().getResources(), resourceId);
RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getContext().getResources(), bitmap);
drawable.setAntiAlias(true);
drawable.setCornerRadius(
Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
imageView.setImageDrawable(drawable);
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
if (holder instanceof BookCommentHolder) {
List<HotReview.Reviews> reviews = mHotView.getReviews();
Glide.with(UIUtils.getContext())
.load(EBookUtils.getImageUrl(reviews.get(position).getAuthor().getAvatar()))
.asBitmap()
.centerCrop()
.into(new BitmapImageViewTarget(((BookCommentHolder) holder).iv_avatar) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(UIUtils.getContext().getResources(), resource);
circularBitmapDrawable.setCircular(true);
((BookCommentHolder) holder).iv_avatar.setImageDrawable(circularBitmapDrawable);
}
});
((BookCommentHolder) holder).tv_user_name.setText(reviews.get(position).getAuthor().getNickname());
((BookCommentHolder) holder).ratingBar_hots.setRating((float) reviews.get(position).getRating());
((BookCommentHolder) holder).tv_comment_content.setText(reviews.get(position).getContent());
((BookCommentHolder) holder).tv_favorite_num.setText(reviews.get(position).getLikeCount() + "");
((BookCommentHolder) holder).tv_update_time.setText(reviews.get(position).getUpdated().split("T")[0]);
}
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
if (holder instanceof BookCommentHolder) {
List<BookReviewResponse> reviews = reviewsListResponse.getReviews();
Glide.with(UIUtils.getContext())
.load(reviews.get(position).getAuthor().getAvatar())
.asBitmap()
.centerCrop()
.into(new BitmapImageViewTarget(((BookCommentHolder) holder).iv_avatar) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(UIUtils.getContext().getResources(), resource);
circularBitmapDrawable.setCircular(true);
((BookCommentHolder) holder).iv_avatar.setImageDrawable(circularBitmapDrawable);
}
});
((BookCommentHolder) holder).tv_user_name.setText(reviews.get(position).getAuthor().getName());
if (reviews.get(position).getRating() != null) {
((BookCommentHolder) holder).ratingBar_hots.setRating(Float.valueOf(reviews.get(position).getRating().getValue()));
}
((BookCommentHolder) holder).tv_comment_content.setText(reviews.get(position).getSummary());
((BookCommentHolder) holder).tv_favorite_num.setText(reviews.get(position).getVotes() + "");
((BookCommentHolder) holder).tv_update_time.setText(reviews.get(position).getUpdated().split(" ")[0]);
}
}
private void showAddToDesktop(SubscriptionType type, String id, String imgUrl, String name) {
Alerts.list(null, AppUtils.getContext().getString(R.string.add_to_desktop))
.flatMap(it -> {
return ImageUtils.loadImage(ImageUtils.parseUri(imgUrl), 128, 128)
.map(bitmap -> {
RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(AppUtils.getContext().getResources(), bitmap);
drawable.setCornerRadius(20);
return (Drawable)drawable;
})
.onErrorReturnItem(AppUtils.getContext().getResources().getDrawable(R.drawable.jianshu_icon))
.map(BitmapUtils::toBitmap);
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(bitmap -> {
ShortcutUtils.addShortcut(type, id, name, bitmap);
}, err -> {
LogUtils.e(err);
});
}
public void setupImageView() {
if (imageView != null) {
String path = PrefHelper.getString(PrefConstant.CUSTOM_ICON);
if (!InputHelper.isEmpty(path)) {
path = Uri.decode(PrefHelper.getString(PrefConstant.CUSTOM_ICON));
boolean fileExists = new File(path).exists();
if (fileExists) {
imageView.setImageDrawable(null);
Bitmap src = BitmapFactory.decodeFile(path);
if (src == null) {
imageView.setImageResource(R.drawable.ic_app_drawer_icon);
onMoving(false);
return;
}
RoundedBitmapDrawable dr = RoundedBitmapDrawableFactory.create(getResources(), src);
dr.setCornerRadius(Math.max(src.getWidth(), src.getHeight()) / 2.0f);
imageView.setImageDrawable(dr);
return;
}
}
imageView.setImageResource(R.drawable.ic_app_drawer_icon);
onMoving(false);
}
}
@Override
public View getView(int position, View convertView, ViewGroup container) {
if (convertView == null) {
convertView = LayoutInflater.from(getActivity()).inflate(R.layout.list_item_article, container, false);
}
final DummyContent.DummyItem item = (DummyContent.DummyItem) getItem(position);
((TextView) convertView.findViewById(R.id.article_title)).setText(item.title);
((TextView) convertView.findViewById(R.id.article_subtitle)).setText(item.author);
final ImageView img = (ImageView) convertView.findViewById(R.id.thumbnail);
Glide.with(getActivity()).load(item.photoId).asBitmap().fitCenter().into(new BitmapImageViewTarget(img) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getActivity().getResources(), resource);
circularBitmapDrawable.setCircular(true);
img.setImageDrawable(circularBitmapDrawable);
}
});
return convertView;
}
@Override
public void onLargeIconAvailable(Bitmap icon, int fallbackColor,
boolean isFallbackColorDefault) {
// TODO(twellington): move this somewhere that can be shared with bookmarks.
if (icon == null) {
mIconGenerator.setBackgroundColor(fallbackColor);
icon = mIconGenerator.generateIconForUrl(getItem().getUrl());
mIconImageView.setImageDrawable(new BitmapDrawable(getResources(), icon));
} else {
RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(
getResources(),
Bitmap.createScaledBitmap(icon, mDisplayedIconSize, mDisplayedIconSize, false));
roundedIcon.setCornerRadius(mCornerRadius);
mIconImageView.setImageDrawable(roundedIcon);
}
}
/**
* 得到唱盘图片
* 唱盘图片由空心圆盘及音乐专辑图片“合成”得到
*/
public Drawable getDiscDrawable(Bitmap bitmap) {
int discSize = (int) (mScreenWidth * DisplayUtil.SCALE_DISC_SIZE);
int musicPicSize = (int) (mScreenWidth * DisplayUtil.SCALE_MUSIC_PIC_SIZE);
Bitmap bitmapDisc = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R
.drawable.ic_disc), discSize, discSize, false);
Bitmap bitmapMusicPic = Bitmap.createScaledBitmap(bitmap, musicPicSize, musicPicSize, true);
BitmapDrawable discDrawable = new BitmapDrawable(bitmapDisc);
RoundedBitmapDrawable roundMusicDrawable = RoundedBitmapDrawableFactory.create
(getResources(), bitmapMusicPic);
//抗锯齿
discDrawable.setAntiAlias(true);
roundMusicDrawable.setAntiAlias(true);
Drawable[] drawables = new Drawable[2];
drawables[0] = roundMusicDrawable;
drawables[1] = discDrawable;
LayerDrawable layerDrawable = new LayerDrawable(drawables);
int musicPicMargin = (int) ((DisplayUtil.SCALE_DISC_SIZE - DisplayUtil
.SCALE_MUSIC_PIC_SIZE) * mScreenWidth / 2);
//调整专辑图片的四周边距,让其显示在正中
layerDrawable.setLayerInset(0, musicPicMargin, musicPicMargin, musicPicMargin,
musicPicMargin);
return layerDrawable;
}
static RoundedBitmapDrawable get(Activity activity, Uri thumbnail) {
RoundedBitmapDrawable dr = null;
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(activity.getContentResolver(), thumbnail);
dr = RoundedBitmapDrawableFactory.create(activity.getResources(), bitmap);
dr.setCircular(true);
} catch (Exception e) {
e.printStackTrace();
}
return dr;
}
private RoundedBitmapDrawable createRoundedBitmapImageDrawableWithBorder(Bitmap bitmap){
int bitmapWidthImage = bitmap.getWidth();
int bitmapHeightImage = bitmap.getHeight();
int borderWidthHalfImage = 4;
int bitmapRadiusImage = Math.min(bitmapWidthImage,bitmapHeightImage)/2;
int bitmapSquareWidthImage = Math.min(bitmapWidthImage,bitmapHeightImage);
int newBitmapSquareWidthImage = bitmapSquareWidthImage+borderWidthHalfImage;
Bitmap roundedImageBitmap = Bitmap.createBitmap(newBitmapSquareWidthImage,newBitmapSquareWidthImage,Bitmap.Config.ARGB_8888);
Canvas mcanvas = new Canvas(roundedImageBitmap);
mcanvas.drawColor(Color.RED);
int i = borderWidthHalfImage + bitmapSquareWidthImage - bitmapWidthImage;
int j = borderWidthHalfImage + bitmapSquareWidthImage - bitmapHeightImage;
mcanvas.drawBitmap(bitmap, i, j, null);
Paint borderImagePaint = new Paint();
borderImagePaint.setStyle(Paint.Style.STROKE);
borderImagePaint.setStrokeWidth(borderWidthHalfImage*2);
borderImagePaint.setColor(Color.GRAY);
mcanvas.drawCircle(mcanvas.getWidth()/2, mcanvas.getWidth()/2, newBitmapSquareWidthImage/2, borderImagePaint);
RoundedBitmapDrawable roundedImageBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(),roundedImageBitmap);
roundedImageBitmapDrawable.setCornerRadius(bitmapRadiusImage);
roundedImageBitmapDrawable.setAntiAlias(true);
return roundedImageBitmapDrawable;
}
private Bitmap getRoundBitmap(@DrawableRes int drawable, int size) {
Bitmap bitmap = ImageUtils.drawableToBitmap(ContextCompat.getDrawable(getContext(), drawable));
bitmap = Bitmap.createBitmap(bitmap, bitmap.getWidth() / 6, bitmap.getHeight() / 6, (int) (0.666 * bitmap.getWidth()), (int) (0.666 * bitmap.getHeight()));
bitmap = ThumbnailUtils.extractThumbnail(bitmap, size, size);
RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
roundedBitmapDrawable.setCornerRadius(size / 2);
roundedBitmapDrawable.setAntiAlias(true);
return ImageUtils.drawableToBitmap(roundedBitmapDrawable);
}
@Override
public void onBindViewHolder(LeaderBoardViewHolder holder, int position) {
LeaderBoardActivity.LeaderBoardUserModel user=users.get(position);
holder.username.setText(user.getName().toString());
holder.score.setText("Score: "+Integer.toString(user.getSets().getScore()));
Glide.with(context).load(user.getPhoto()).into(holder.photo);
final ImageView imageView=holder.photo;
Glide.with(context).load(user.getPhoto()).asBitmap().centerCrop().into(new BitmapImageViewTarget(imageView) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(context.getResources(), resource);
circularBitmapDrawable.setCircular(true);
imageView.setImageDrawable(circularBitmapDrawable);
}
});
Integer prsnlscore = user.getSets().getScore();
if(prsnlscore>=800) holder.useraward.setImageResource(R.drawable.trophy_gold);
else if(prsnlscore>=600) holder.useraward.setImageResource(R.drawable.trophy_silver);
else if(prsnlscore>=450) holder.useraward.setImageResource(R.drawable.trophy_bronze);
else if(prsnlscore>=300) holder.useraward.setImageResource(R.drawable.trophy_goldbadge);
else if(prsnlscore>=150) holder.useraward.setImageResource(R.drawable.trophy_silverbadge);
else if(prsnlscore>0) holder.useraward.setImageResource(R.drawable.trophy_bronzebadge);
else if(prsnlscore==0) holder.useraward.setImageResource(R.drawable.trophy_participation);
holder.sets.setText("Sets: "+Integer.toString(user.getSets().getSets()));
}
@Override
public void onBindViewHolder(LeaderBoardViewHolder holder, int position) {
LeaderBoardActivity.LeaderBoardUserModel user=users.get(position);
holder.username.setText(user.getName().toString());
holder.score.setText("Score: "+Integer.toString(user.getSets().getScore()));
Glide.with(context).load(user.getPhoto()).into(holder.photo);
final ImageView imageView=holder.photo;
Glide.with(context).load(user.getPhoto()).asBitmap().centerCrop().into(new BitmapImageViewTarget(imageView) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(context.getResources(), resource);
circularBitmapDrawable.setCircular(true);
imageView.setImageDrawable(circularBitmapDrawable);
}
});
Integer prsnlscore = user.getSets().getScore();
if(prsnlscore>=800) holder.useraward.setImageResource(R.drawable.trophy_gold);
else if(prsnlscore>=600) holder.useraward.setImageResource(R.drawable.trophy_silver);
else if(prsnlscore>=450) holder.useraward.setImageResource(R.drawable.trophy_bronze);
else if(prsnlscore>=300) holder.useraward.setImageResource(R.drawable.trophy_goldbadge);
else if(prsnlscore>=150) holder.useraward.setImageResource(R.drawable.trophy_silverbadge);
else if(prsnlscore>0) holder.useraward.setImageResource(R.drawable.trophy_bronzebadge);
else if(prsnlscore==0) holder.useraward.setImageResource(R.drawable.trophy_participation);
holder.sets.setText("Sets: "+Integer.toString(user.getSets().getSets()));
}
private void setAvatarPreLollipop(@DrawableRes int resId) {
Drawable drawable = ResourcesCompat.getDrawable(getResources(), resId,
getContext().getTheme());
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
@SuppressWarnings("ConstantConditions")
RoundedBitmapDrawable roundedDrawable = RoundedBitmapDrawableFactory.create(getResources(),
bitmapDrawable.getBitmap());
roundedDrawable.setCircular(true);
setImageDrawable(roundedDrawable);
}
private Bitmap getRoundBitmap(@DrawableRes int drawable, int size) {
Bitmap bitmap = ImageUtils.drawableToBitmap(ContextCompat.getDrawable(getContext(), drawable));
bitmap = Bitmap.createBitmap(bitmap, bitmap.getWidth() / 6, bitmap.getHeight() / 6, (int) (0.666 * bitmap.getWidth()), (int) (0.666 * bitmap.getHeight()));
bitmap = ThumbnailUtils.extractThumbnail(bitmap, size, size);
RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
roundedBitmapDrawable.setCornerRadius(size / 2);
roundedBitmapDrawable.setAntiAlias(true);
return ImageUtils.drawableToBitmap(roundedBitmapDrawable);
}
@Override
protected Drawable getDrawable(Bitmap bitmap) {
if (cropCircle) {
RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(imageView.getResources(), bitmap);
roundedBitmapDrawable.setCircular(true);
roundedBitmapDrawable.setAntiAlias(true);
return roundedBitmapDrawable;
} else {
return super.getDrawable(bitmap);
}
}
public static void displayCircularImage(final Context context, String url, final ImageView imageView) {
Glide.with(context).load(url).asBitmap().centerCrop().into(new BitmapImageViewTarget(imageView) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(context.getResources(), resource);
circularBitmapDrawable.setCircular(true);
imageView.setImageDrawable(circularBitmapDrawable);
}
});
}
@Override
public void onLargeIconAvailable(Bitmap icon, int fallbackColor) {
if (icon == null) {
mIconGenerator.setBackgroundColor(fallbackColor);
icon = mIconGenerator.generateIconForUrl(mUrl);
mIconImageView.setImageDrawable(new BitmapDrawable(getResources(), icon));
} else {
RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(
getResources(),
Bitmap.createScaledBitmap(icon, mDisplayedIconSize, mDisplayedIconSize, false));
roundedIcon.setCornerRadius(mCornerRadius);
mIconImageView.setImageDrawable(roundedIcon);
}
}
private Drawable getFaviconDrawable(Bitmap icon, int fallbackColor, String url) {
if (icon == null) {
mIconGenerator.setBackgroundColor(fallbackColor);
icon = mIconGenerator.generateIconForUrl(url);
return new BitmapDrawable(getResources(), icon);
} else {
RoundedBitmapDrawable roundedIcon =
RoundedBitmapDrawableFactory.create(getResources(),
Bitmap.createScaledBitmap(icon, mFaviconSize, mFaviconSize, false));
roundedIcon.setCornerRadius(mCornerRadius);
return roundedIcon;
}
}
@Override
public void onDraw(Canvas canvas) {
Bitmap image = ImageUtils.drawableToBitmap(getDrawable());
if (image != null) {
int size = Math.min(getWidth(), getHeight());
image = ThumbnailUtils.extractThumbnail(image, size, size);
RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), image);
roundedBitmapDrawable.setCornerRadius(size / 2);
roundedBitmapDrawable.setAntiAlias(true);
canvas.drawBitmap(ImageUtils.drawableToBitmap(roundedBitmapDrawable), 0, 0, paint);
}
}