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); }
public static void loadRound(final Context context, String url, final ImageView iv) { Glide.with(context)// .load(url)// .asBitmap()// .placeholder(R.drawable.company_logo)// .centerCrop()// .into(new BitmapImageViewTarget(iv) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(context.getResources(), resource); circularBitmapDrawable.setCircular(true); iv.setImageDrawable(circularBitmapDrawable); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_do); ButterKnife.bind(this); // handDo(); // processRetry(); // processRetryWhen(); // processRepeat(); processRepeatWhen(); GradientDrawable drawable = new GradientDrawable(); drawable.setColor(Color.BLUE); drawable.setCornerRadius(5); tvD.setText("赢"); tvD.setBackground(drawable); BitmapDrawable drawable1 = new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.bg1)); Bitmap bm = drawTBit(drawable1); ivDo.setImageBitmap(drawCircle(bm)); RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.bg1)); roundedBitmapDrawable.setCornerRadius(20); ivDo1.setImageDrawable(roundedBitmapDrawable); }
/** * Handle a google signIn * @param result - the result of the signin attempt */ private void handleSignInResult(GoogleSignInResult result) { Log.d(TAG, "handleSignInResult:" + result.isSuccess()); final ImageView accountImageView = findViewById(R.id.account_picture); if (result.isSuccess()) { // Signed in successfully, show authenticated UI. GoogleSignInAccount acct = result.getSignInAccount(); if (acct != null) { Glide.with(this).load(acct.getPhotoUrl()).asBitmap().centerCrop().into(new BitmapImageViewTarget(accountImageView) { /** * Set a glide image * @param resource - the image to set */ @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), resource); circularBitmapDrawable.setCircular(true); accountImageView.setImageDrawable(circularBitmapDrawable); } }); } } }
@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); } }
public void loadRoundImage(final Context context, String imgPath, final ImageView imageView, int placeholderResId, int failedResId) { if (context == null) { return; } Context appContext = context.getApplicationContext(); Glide.with(appContext). load(imgPath) .asBitmap() .placeholder(placeholderResId) .error(failedResId) .centerCrop() .into(new BitmapImageViewTarget(imageView) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(context.getResources(), resource); circularBitmapDrawable.setCircular(true); imageView.setImageDrawable(circularBitmapDrawable); } }); }
/***** * MVP View methods implementation *****/ @Override public void showAvatar(String avatarUrl) { if (avatarUrl.contains("gif")) { Glide.with(this).load(avatarUrl).asGif().into(avatar); } else { Glide.with(this).load(avatarUrl).asBitmap().centerCrop().into(new BitmapImageViewTarget(avatar) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), resource); circularBitmapDrawable.setCircular(true); avatar.setImageDrawable(circularBitmapDrawable); } }); } }
/** * Crops image into a circle that fits within the ImageView. */ public static void displayRoundImageFromUrl(final Context context, final String url, final ImageView imageView) { Glide.with(context) .load(url) .asBitmap() .centerCrop() .dontAnimate() .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, 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(); }
@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); } }); }
/** * 设置地图中心的标记,也是定位的当前位置 * 暂注释掉,测试后解除 */ private void setCenterMaker(final LatLng latLng, final float radius, String url) { logo = getLayoutInflater().inflate(R.layout.view_sign_logo, null); imgHeadCenter = (ImageView) logo.findViewById(R.id.head_signmap); if (roundedBitmapDrawable != null) { imgHeadCenter.setImageDrawable(roundedBitmapDrawable); Log.e("load","imgHeadCenter2="+roundedBitmapDrawable); } if (latLng != null) { addCenterMark(latLng); addCircle(latLng, radius); } Utils.load(GdmapTestLocateActivity.this, url, imgHeadCenter, new OnImgLoadFinish() { @Override public void loadFinish(RoundedBitmapDrawable drawable) { GdmapTestLocateActivity.this.roundedBitmapDrawable = drawable; Log.e("load","imgHeadCenter1="+drawable); } }); }
public void showDialog(String title, String end, String start, String reputation, String encouragment, String referee, Drawable profileImage, Goal.GoalCompleteResult goalCompleteResult, String guid) { Bundle bundle = new Bundle(); bundle.putBoolean("isMyGoal", true); bundle.putString("title", title); bundle.putString("end", end); bundle.putString("start", start); bundle.putString("reputation", reputation); bundle.putString("referee", referee); bundle.putString("encouragement", encouragment); if (profileImage instanceof RoundedBitmapDrawable) bundle.putParcelable("profile", ((RoundedBitmapDrawable) profileImage).getBitmap()); else if (profileImage instanceof BitmapDrawable) bundle.putParcelable("profile", ((BitmapDrawable) profileImage).getBitmap()); bundle.putSerializable("goalCompleteResult", goalCompleteResult); bundle.putString("guid", guid); GoalsDetailedDialog detailedDialog = new GoalsDetailedDialog(); detailedDialog.setArguments(bundle); detailedDialog.setTargetFragment(this, Constants.RESULT_MY_GOAL_DIALOG); detailedDialog.show(getActivity().getSupportFragmentManager(), "GoalsDetailedDialog"); }
public void showDialog(String title, String end, String start, String reputation, String encouragment, String referee, Drawable profileImage, Goal.GoalCompleteResult goalCompleteResult, String guid) { Bundle bundle = new Bundle(); bundle.putBoolean("isMyGoal", false); bundle.putString("title", title); bundle.putString("end", end); bundle.putString("start", start); bundle.putString("reputation", reputation); bundle.putString("referee", referee); bundle.putString("encouragement", encouragment); if (profileImage instanceof RoundedBitmapDrawable) bundle.putParcelable("profile", ((RoundedBitmapDrawable) profileImage).getBitmap()); else if (profileImage instanceof BitmapDrawable) bundle.putParcelable("profile", ((BitmapDrawable) profileImage).getBitmap()); bundle.putSerializable("goalCompleteResult", goalCompleteResult); bundle.putString("guid", guid); GoalsDetailedDialog detailedDialog = new GoalsDetailedDialog(); detailedDialog.setArguments(bundle); detailedDialog.setTargetFragment(this, Constants.RESULT_MY_GOAL_DIALOG); detailedDialog.show(getActivity().getSupportFragmentManager(), "GoalsDetailedDialog"); }
@Override public void onBindViewHolder(final AnchorHotViewHolder holder, final int position) { ComMember member = mData.get(position); if (StringUtils.isNotEmpty(member.getImageUrl())){ Glide.with(mContext).load(member.getImageUrl()).asBitmap().centerCrop().into(new BitmapImageViewTarget(holder.pic) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), resource); circularBitmapDrawable.setCircular(true); holder.pic.setImageDrawable(circularBitmapDrawable); } }); } }
public void setCircleInfo(CircleInfo info) { mTvCircleName.setText(info.getCircleName()); mTvTitle.setText(info.getCircleName()); mTvCircleNum.setText(info.getNum() + "人"); mTvIntroduce.setText(info.getAnnouncement()); String path = info.getLogoUrl(); if (!path.contains("http://")) { path = BuildConfig.QiniuBase + path; } Glide.with(this.getActivity()).load(path).asBitmap().error(R.mipmap.icon_default_pic).centerCrop().into(new BitmapImageViewTarget(mImgTop) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getActivity().getResources(), resource); circularBitmapDrawable.setCircular(true); mImgTop.setImageDrawable(circularBitmapDrawable); } }); }
public void setData(CircleInfo info) { Glide.with(this.getActivity()).load(info.getLogoUrl()).asBitmap().centerCrop().into(new BitmapImageViewTarget(mImgPic) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getActivity().getResources(), resource); circularBitmapDrawable.setCircular(true); mImgPic.setImageDrawable(circularBitmapDrawable); } }); mTvName.setText(info.getCircleName()); mEdtAnnouncement.setText(info.getAnnouncement()); // mTvType.setText(); }
@Override public void onBindViewHolder(final AnchorHotViewHolder holder, final int position) { ProjectComments comments = mData.get(position); if (comments != null) { ComMember member = comments.getCommentUser(); if (null != member && StringUtils.isNotEmpty(member.getName())) { holder.tvName.setText(member.getName()); } if (StringUtils.isNotEmpty(member.getImageUrl())){ Glide.with(mContext).load(member.getImageUrl()).asBitmap().centerCrop().into(new BitmapImageViewTarget(holder.pic) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), resource); circularBitmapDrawable.setCircular(true); holder.pic.setImageDrawable(circularBitmapDrawable); } }); } } holder.tvContent.setText(comments.getComment()); holder.tvTime.setText(TimeUtil.getDateToString(comments.getCreateTime())); }
public void setUserInfo(ComMember member) { if (member.getImageUrl() != null) { Glide.with(this.getActivity()).load(member.getImageUrl()).asBitmap().centerCrop().into(new BitmapImageViewTarget(imgPic) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getActivity().getResources(), resource); circularBitmapDrawable.setCircular(true); imgPic.setImageDrawable(circularBitmapDrawable); } }); } if (member.getName() != null) tvName.setText(member.getName()); tv_center_shareholder.setVisibility(member.getShareholder() == 0 ? View.GONE : View.VISIBLE); tv_center_investor.setVisibility(member.getInvestor() == 0 ? View.GONE : View.VISIBLE); if (StringUtils.isNotEmpty(member.getCompany())) tv_center_company.setText(member.getCompany()); if (StringUtils.isNotEmpty(member.getPosition())) tv_center_position.setText(member.getPosition()); }
public void setData(ReciveRedPacket info,String name ,String tip) { tv_money.setText(info.getMoney()+""); String path = info.getImgUrl(); if (!path.contains("http://")){ path = BuildConfig.QiniuBase + path; } Glide.with(this.getActivity()).load(path).asBitmap().centerCrop().into(new BitmapImageViewTarget(img_icon) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getActivity().getResources(), resource); circularBitmapDrawable.setCircular(true); img_icon.setImageDrawable(circularBitmapDrawable); } }); tv_name.setText(name+"的红包"); // EMTextMessageBody txtBody = (EMTextMessageBody) message.getBody(); // Spannable span = EaseSmileUtils.getSmiledText(this.getActivity(), txtBody.getMessage()); // 设置内容 tv_tip.setText(tip); }
/** * 将url编程圆形的加载在 ImageView中 */ public static void requestCircleImg(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); } }); }
public void setRightMessage(Context context, String name, String message, String time, String avatar) { layoutright.setVisibility(View.VISIBLE); layoutLeft.setVisibility(View.GONE); txtNameRight.setVisibility(View.GONE); txtNameRight.setText(name); txtMessageRight.setText(message); txtTimeRight.setText(time); Glide.with(context) .load(avatar) .asBitmap().centerCrop() .placeholder(R.mipmap.ic_nfkita_round) .into(new BitmapImageViewTarget(imgAvatar) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable rounded = RoundedBitmapDrawableFactory.create(context.getResources(), resource); rounded.setCircular(true); imgAvatar.setImageDrawable(rounded); } }); }
private void loadData() { String avatar = CacheManager.grabString("avatar"); String name = CacheManager.grabString("name"); String email = CacheManager.grabString("email"); Glide.with(getContext()) .load(avatar) .asBitmap().centerCrop() .placeholder(R.mipmap.ic_nfkita_round) .into(new BitmapImageViewTarget(imgAvatar) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable rounded = RoundedBitmapDrawableFactory.create(getContext().getResources(), resource); rounded.setCircular(true); imgAvatar.setImageDrawable(rounded); } }); txtFullName.setText(name); txtEmail.setText(email); }
private void loadProfilePic() { Glide.with(mContext).load(mSharedPreferences.getString(PROFILE_PIC_URL, "")) .asBitmap() .fitCenter() .diskCacheStrategy(DiskCacheStrategy.ALL) .error(R.drawable.default_avatar) .into(new BitmapImageViewTarget(profileImg) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), resource); circularBitmapDrawable.setCircular(true); profileImg.setImageDrawable(circularBitmapDrawable); } }); }
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); }); }
@Override public void onBindViewHolder(final ViewHolder holder, int position) { if(!(sponsorItemArrayList.get(position).sponsor_name.isEmpty())){ holder.sponsorname.setText(sponsorItemArrayList.get(position).sponsor_name); } if(!(sponsorItemArrayList.get(position).image_id==null)){ // holder.sponsorimage.setImageResource(sponsorItemArrayList.get(position).image_id); Glide.with(context).load(sponsorItemArrayList.get(position).image_id).asBitmap().diskCacheStrategy(DiskCacheStrategy.ALL).into(new ImageViewTarget<Bitmap>(holder.sponsorimage) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable drawable= RoundedBitmapDrawableFactory.create(context.getResources(),resource); drawable.setCircular(false); holder.sponsorimage.setImageDrawable(drawable); } }); } }
private void setImage(final UserItemViewHolder holder, User user) { Glide.with(mContext) .load(USER_IMAGES_URL + user.getImage()) .asBitmap() .placeholder(R.drawable.person_placeholder) .diskCacheStrategy(DiskCacheStrategy.ALL) .centerCrop() .into(new BitmapImageViewTarget(holder.userImage) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), resource); circularBitmapDrawable.setCircular(true); holder.userImage.setImageDrawable(circularBitmapDrawable); } }); }
@Override public void bindCursor(Cursor cursor) { name.setText(cursor.getString(cursor.getColumnIndex(PlaceContract.PlaceEntry.COLUMN_NAME))); id.setText(cursor.getString(cursor.getColumnIndex(PlaceContract.PlaceEntry.COLUMN_PLACE_ID))); photo.setText(cursor.getString(cursor.getColumnIndex(PlaceContract.PlaceEntry.COLUMN_PHOTO))); vicinity.setText(cursor.getString(cursor.getColumnIndex(PlaceContract.PlaceEntry.COLUMN_VICINITY))); Glide.with(icon.getContext()) .load(Config.getPlacePhotoUrl("80", cursor.getString(cursor.getColumnIndex(PlaceContract.PlaceEntry.COLUMN_PHOTO)), Config.API_KEY)) .asBitmap().centerCrop().into(new BitmapImageViewTarget(icon) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), resource); circularBitmapDrawable.setCircular(true); icon.setImageDrawable(circularBitmapDrawable); } }); // Log.e("Photo" , Config.getPlacePhotoUrl("80", cursor.getString(cursor.getColumnIndex(PlaceContract.PlaceEntry.COLUMN_PHOTO)), Config.API_KEY)); }
/** 与Glide高耦合的设置图片 */ public ViewHolder setImageCircle(@IdRes final int viewId, @DrawableRes int resId){ final ImageView imageView = getView(viewId); Glide.with(mContext) .load(resId) .asBitmap() .into(new BitmapImageViewTarget(imageView) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), resource); circularBitmapDrawable.setCircular(true); imageView.setImageDrawable(circularBitmapDrawable); } }); return this; }
@Override public View getView(int position, View convertView, ViewGroup container) { if (convertView == null) { convertView = LayoutInflater.from(getActivity()).inflate(R.layout.list_item_ride, container, false); } final Ride ride = (Ride) getItem(position); ((TextView) convertView.findViewById(R.id.ride_date)).setText(ride.date); ((TextView) convertView.findViewById(R.id.ride_time)).setText(ride.time); final ImageView img = (ImageView) convertView.findViewById(R.id.thumbnail); Glide.with(getActivity()).load(imageResIds[position % 5]).asBitmap().fitCenter().into(new BitmapImageViewTarget(img) { // 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; }
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); }
@BindingAdapter(value = {"imageUrl", "circle"}, requireAll = false) public static void loadImage(ImageView view, String url, Boolean circle) { if (circle == null || !circle) { Glide.with(view.getContext()).load(url).into(view); } else { Glide.with(view.getContext()).load(url).asBitmap().centerCrop().into(new BitmapImageViewTarget(view) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(view.getResources(), resource); circularBitmapDrawable.setCircular(true); view.setImageDrawable(circularBitmapDrawable); } }); } }
@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 fillProfile(Profile value) { Glide.with(this) .load(value.getPicture()) .asBitmap() .centerCrop() .into(new BitmapImageViewTarget(imageView) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), resource); circularBitmapDrawable.setCircular(true); imageView.setImageDrawable(circularBitmapDrawable); } }); result.setText(value.getName()); }
@Override public void showProfile(User user) { Glide.with(getContext()).load(user.getAvatarUrl()) .asBitmap() .centerCrop() .into(new BitmapImageViewTarget(avatar) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getContext().getResources(), resource); circularBitmapDrawable.setCircular(true); avatar.setImageDrawable(circularBitmapDrawable); } }); name.setText(user.getName()); username.setText(user.getUsername()); shotCount.setText(String.valueOf(user.getShotsCount())); followerCount.setText(String.valueOf(user.getFollowersCount())); likesCount.setText(String.valueOf(user.getLikesReceivedCount())); bio.setText(Html.fromHtml("Co-founder & designer of <a href=\\\"https://dribbble.com/dribbble\\\">@Dribbble</a>. Principal of SimpleBits. Aspiring clawhammer banjoist.")); }
public void bind(Comment comment) { Glide.with(itemView.getContext()).load(comment.getUser().getAvatarUrl()) .asBitmap() .centerCrop() .into(new BitmapImageViewTarget(avatar) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(itemView.getContext().getResources(), resource); circularBitmapDrawable.setCircular(true); avatar.setImageDrawable(circularBitmapDrawable); } }); name.setText(comment.getUser().getName()); content.setText(comment.getBody()); LinkUtils.setTextWithLinks(content, comment.getBody()); time.setText(DateUtils.parse(comment.getCreatedAt())); }
@Override public void onResponse(Call call, Response response) throws IOException { if (!response.isSuccessful()) { return; } try(ResponseBody body = response.body()) { Bitmap loaded = BitmapFactory.decodeStream(body.byteStream()); if (loaded == null) { // decode failed return; } Bitmap scaled = Bitmap.createScaledBitmap(loaded, mCaller.getWidth(), mCaller.getHeight(), false); RoundedBitmapDrawable rbd = RoundedBitmapDrawableFactory.create(mCaller.getContext().getResources(), scaled); rbd.setCornerRadius(Math.max(scaled.getWidth(), scaled.getHeight()) / 2.0f); setRetrieved(rbd); ImageCache.getInstance(mCaller.getContext()).putCached(call.request().url().toString(), rbd); mCaller.post(this); } }
protected void initBitmapCache() { Log.i(LOG_TAG, "Initialize bitmap cache"); // Get max available VM memory, exceeding this amount will throw an // OutOfMemory exception. Stored in kilobytes as LruCache takes an // int in its constructor. final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); // Use 1/8th of the available memory for this memory cache. final int cacheSize = maxMemory / 8; mImageCache = new LruCache<String, RoundedBitmapDrawable>(cacheSize) { @Override protected int sizeOf(String key, RoundedBitmapDrawable drawable) { // The cache size will be measured in kilobytes rather than number of items. // return bitmap.getByteCount() / 1024; Bitmap bitmap = drawable.getBitmap(); return (bitmap.getRowBytes() * bitmap.getHeight()) / 1024; } }; }