android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory Java Examples

The following examples show how to use android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BookReviewsAdapter.java    From youqu_master with Apache License 2.0 6 votes vote down vote up
@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]);
    }
}
 
Example #2
Source File: NewTabPageView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #3
Source File: TextCardView.java    From leanback-showcase with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: GitHubUserActivity.java    From gank.io-unofficial-android-client with Apache License 2.0 6 votes vote down vote up
private void setUserInfo() {

    Glide.with(this)
        .load(mUserInfo.avatarUrl)
        .asBitmap()
        .placeholder(R.drawable.ic_slide_menu_avatar_no_login)
        .into(new BitmapImageViewTarget(mUserInfoAvatar) {

          @Override
          protected void setResource(Bitmap resource) {

            mUserInfoAvatar.setImageDrawable(RoundedBitmapDrawableFactory
                .create(GitHubUserActivity.this.getResources(), resource));
          }
        });
    mUsername.setText(mUserInfo.name);
  }
 
Example #5
Source File: EBookReviewsAdapter.java    From MaterialHome with Apache License 2.0 6 votes vote down vote up
@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]);
    }
}
 
Example #6
Source File: InterestsItemView.java    From delion with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #7
Source File: NewTabPageView.java    From delion with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #8
Source File: BookReviewsAdapter.java    From MaterialHome with Apache License 2.0 6 votes vote down vote up
@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]);
    }
}
 
Example #9
Source File: SubscriptionAdapter.java    From JianshuApp with GNU General Public License v3.0 6 votes vote down vote up
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);
            });
}
 
Example #10
Source File: FloatingView.java    From FastAccess with GNU General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #11
Source File: ArticleListFragment.java    From android-design-template with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #12
Source File: ImageUtil.java    From YCVideoPlayer with Apache License 2.0 6 votes vote down vote up
/**
 * 加载带有圆角的矩形图片  用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);
                    }
                });
    }
}
 
Example #13
Source File: ImageUtil.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
/**
 * 加载带有圆角的矩形图片  用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);
                    }
                });
    }
}
 
Example #14
Source File: NoInternetDialog.java    From NoInternetDialog with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #15
Source File: CircleImageView.java    From MediaNotification with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #16
Source File: XianduAdapter.java    From FakeWeather with Apache License 2.0 6 votes vote down vote up
@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);
        }
    });
}
 
Example #17
Source File: HistoryItemView.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #18
Source File: TileGroup.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onLargeIconAvailable(
        @Nullable Bitmap icon, int fallbackColor, boolean isFallbackColorDefault) {
    if (mTrackLoadTask) mObserver.onLoadTaskCompleted();

    Tile tile = getTile(mUrl);
    if (tile == null) return; // The tile might have been removed.

    if (icon == null) {
        mIconGenerator.setBackgroundColor(fallbackColor);
        icon = mIconGenerator.generateIconForUrl(mUrl);
        tile.setIcon(new BitmapDrawable(mContext.getResources(), icon));
        tile.setType(isFallbackColorDefault ? TileVisualType.ICON_DEFAULT
                                            : TileVisualType.ICON_COLOR);
    } else {
        RoundedBitmapDrawable roundedIcon =
                RoundedBitmapDrawableFactory.create(mContext.getResources(), icon);
        int cornerRadius = Math.round(ICON_CORNER_RADIUS_DP
                * mContext.getResources().getDisplayMetrics().density * icon.getWidth()
                / mDesiredIconSize);
        roundedIcon.setCornerRadius(cornerRadius);
        roundedIcon.setAntiAlias(true);
        roundedIcon.setFilterBitmap(true);

        tile.setIcon(roundedIcon);
        tile.setType(TileVisualType.ICON_REAL);
    }

    mObserver.onTileIconChanged(tile);
}
 
Example #19
Source File: CardViewActivity.java    From FrostyBackgroundTestApp with Apache License 2.0 5 votes vote down vote up
private void setBackgroundOnView(View view, Bitmap bitmap) {
  Drawable d;
  if (bitmap != null) {
    d = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
    ((RoundedBitmapDrawable) d).setCornerRadius(getResources().getDimensionPixelOffset(R.dimen.rounded_corner));

  } else {
    d = ContextCompat.getDrawable(CardViewActivity.this, R.drawable.white_background);
  }
  view.setBackground(d);
}
 
Example #20
Source File: AvatarView.java    From CoolSignIn with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #21
Source File: CharacterCardView.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
public void updateUi(Card card) {
    TextView primaryText = (TextView) findViewById(R.id.primary_text);
    final ImageView imageView = (ImageView) findViewById(R.id.main_image);

    primaryText.setText(card.getTitle());
    if (card.getLocalImageResourceName() != null) {
        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);
    }
}
 
Example #22
Source File: MainActivity.java    From gank.io-unofficial-android-client with Apache License 2.0 5 votes vote down vote up
public void setUserInfo() {

    GitHubUserInfo mUserInfo = (GitHubUserInfo) ACache.get(MainActivity.this)
        .getAsObject(ConstantUtil.CACHE_USER_KEY);

    if (mUserInfo != null) {
      isLogin = true;
      Glide.with(MainActivity.this)
          .load(mUserInfo.avatarUrl)
          .asBitmap()
          .placeholder(R.drawable.ic_slide_menu_avatar_no_login)
          .into(new BitmapImageViewTarget(mUserAvatar) {

            @Override
            protected void setResource(Bitmap resource) {

              mUserAvatar.setImageDrawable(RoundedBitmapDrawableFactory.create
                  (MainActivity.this.getResources(), resource));
            }
          });

      mUserName.setText(mUserInfo.name);
      mUserBio.setText(mUserInfo.bio);
    } else {
      isLogin = false;
    }
  }
 
Example #23
Source File: CircleImageView.java    From AppCompat-Extension-Library with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for creating a circle bitmap drawable using the {@link android.support.v4.graphics.drawable.RoundedBitmapDrawable}
 *
 * @param bitmap The bitmap which should be converted to a circle bitmap drawable
 * @return the {@link android.support.v4.graphics.drawable.RoundedBitmapDrawable} containing the bitmap
 */
public static RoundedBitmapDrawable getCircleBitmapDrawable(Context context, Bitmap bitmap) {
    RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);
    drawable.setCornerRadius(Math.max(bitmap.getWidth() / 2, bitmap.getHeight() / 2));
    drawable.setAntiAlias(true);
    return drawable;
}
 
Example #24
Source File: AndroidNotifications.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #25
Source File: MainActivity.java    From AlbumSelector with Apache License 2.0 5 votes vote down vote up
/**
 * 得到选择的图片路径集合
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == ImageSelector.REQUEST_SELECT_IMAGE) {
        if (resultCode == RESULT_OK) {
            ArrayList<String> imagesPath = data.getStringArrayListExtra(ImageSelector.SELECTED_RESULT);
            if (isAvatorModel && imagesPath != null) {
                mRlAvator.setVisibility(View.VISIBLE);
                Glide.with(this)
                        .load(imagesPath.get(0))
                        .asBitmap()
                        .into(new BitmapImageViewTarget(mIvAvator) {
                            @Override
                            protected void setResource(Bitmap resource) {
                                RoundedBitmapDrawable circularBitmapDrawable =
                                        RoundedBitmapDrawableFactory.create(getResources(), resource);
                                circularBitmapDrawable.setCircular(true);
                                mIvAvator.setImageDrawable(circularBitmapDrawable);
                            }
                        });

            } else if (imagesPath != null) {
                mRlAvator.setVisibility(View.GONE);
                mAdapter.refreshData(imagesPath);
            }

        }
    }
}
 
Example #26
Source File: ContactAdapter.java    From RememBirthday with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Crop ImageView in parameter for create a circle
 */
private void cropRoundedImageView(ImageView imageView) {
    Bitmap imageBitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
    RoundedBitmapDrawable imageDrawable = RoundedBitmapDrawableFactory.create(context.getResources(), imageBitmap);
    imageDrawable.setCircular(true);
    imageDrawable.setCornerRadius(Math.max(imageBitmap.getWidth(), imageBitmap.getHeight()) / 2.0f);
    imageView.setImageDrawable(imageDrawable);
}
 
Example #27
Source File: ChiefEditorAdapter.java    From RxZhihuDaily with MIT License 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.chief_editor_item, parent, false);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    final ViewHolder Hohholder = holder;
    if (Hohholder != null) {
        Glide
                .with(context)
                .load(editors.get(position).getAvatar())
                .asBitmap()
                .centerCrop()
                .into(new BitmapImageViewTarget(Hohholder.imgChiefEditorItem) {
                    @Override
                    protected void setResource(Bitmap resource) {
                        RoundedBitmapDrawable circularBitmapDrawable =
                                RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                        circularBitmapDrawable.setCircular(true);
                        Hohholder.imgChiefEditorItem.setImageDrawable(circularBitmapDrawable);
                    }
                });
    }
    return convertView;
}
 
Example #28
Source File: RoundedImageListener.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
    if (response.getBitmap() != null) {
        Bitmap src = response.getBitmap();
        RoundedBitmapDrawable avatar = RoundedBitmapDrawableFactory.create(
                mImageView.getResources(), src);
        avatar.setCornerRadius(Math.max(src.getWidth(), src.getHeight()) / 2.0f);
        mImageView.setImageDrawable(avatar);
    } else if (mDefaultImageResId != 0) {
        mImageView.setImageResource(mDefaultImageResId);
    }
}
 
Example #29
Source File: ConfirmImportantSitesDialogFragment.java    From 365browser with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example #30
Source File: BookmarkItemRow.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onLargeIconAvailable(
        Bitmap icon, int fallbackColor, boolean isFallbackColorDefault) {
    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);
    }
}