Example usage for android.support.v4.graphics.drawable RoundedBitmapDrawableFactory create

List of usage examples for android.support.v4.graphics.drawable RoundedBitmapDrawableFactory create

Introduction

In this page you can find the example usage for android.support.v4.graphics.drawable RoundedBitmapDrawableFactory create.

Prototype

public static RoundedBitmapDrawable create(Resources resources, InputStream inputStream) 

Source Link

Usage

From source file:org.opensilk.common.ui.widget.CircleImageView.java

protected RoundedBitmapDrawable createRoundDrawable(Bitmap bm) {
    RoundedBitmapDrawable d = RoundedBitmapDrawableFactory.create(getResources(), bm);
    d.setCornerRadius(radius);
    return d;
}

From source file:android.support.v17.leanback.supportleanbackshowcase.cards.CharacterCardView.java

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);//www  .  jav  a 2s. com
        drawable.setAntiAlias(true);
        drawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
        imageView.setImageDrawable(drawable);
    }
}

From source file:com.android.dialer.contactinfo.ContactPhotoLoader.java

/**
 * @return a {@link Drawable} of  circular photo icon if the photo can be loaded, {@code null}
 * otherwise.// ww  w . j a v  a  2 s.  c  o  m
 */
@Nullable
private Drawable createPhotoIconDrawable() {
    if (mContactInfo.photoUri == null) {
        return null;
    }
    try {
        Bitmap bitmap = MediaStore.Images.Media.getBitmap(mContext.getContentResolver(), mContactInfo.photoUri);
        final RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(mContext.getResources(),
                bitmap);
        drawable.setAntiAlias(true);
        drawable.setCornerRadius(bitmap.getHeight() / 2);
        return drawable;
    } catch (IOException e) {
        Log.e(TAG, e.toString());
        return null;
    }
}

From source file:es.esy.vivekrajendran.news.dialogs.DevDialog.java

private void initViews(View view) {
    final ImageView profilePic = (ImageView) view.findViewById(R.id.circular_profile_pic);
    Glide.with(context).load("https://avatars2.githubusercontent.com/u/14991281?v=3&s=460").asBitmap()
            .centerCrop().placeholder(R.drawable.ic_account_circle_black_24px)
            .into(new BitmapImageViewTarget(profilePic) {
                @Override/*from  w ww .  jav  a2s  . c o m*/
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory
                            .create(context.getResources(), resource);
                    circularBitmapDrawable.setCircular(true);
                    profilePic.setImageDrawable(circularBitmapDrawable);
                }
            });
}

From source file:com.android.mms.ui.ConversationListItem.java

public ConversationListItem(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (sDefaultContactImage == null) {
        Resources res = context.getResources();
        Bitmap defaultImage = BitmapFactory.decodeResource(res, R.drawable.ic_contact_picture);
        sDefaultContactImage = RoundedBitmapDrawableFactory.create(res, defaultImage);
        sDefaultContactImage.setAntiAlias(true);
        sDefaultContactImage/*from   w  w w.  j a  v a  2  s . c  o  m*/
                .setCornerRadius(Math.max(defaultImage.getWidth() / 2, defaultImage.getHeight() / 2));
    }
}

From source file:im.neon.view.VectorCircularImageView.java

/**
 * Update the bitmap./* www  .j  ava  2  s. co m*/
 * The bitmap is first squared before adding corners
 * @param bm the new bitmap
 */
public void setImageBitmap(Bitmap bm) {
    if (null != bm) {
        // convert the bitmap to a square bitmap
        int width = bm.getWidth();
        int height = bm.getHeight();

        if (width == height) {
            // nothing to do
        }
        // larger than high
        else if (width > height) {
            try {
                bm = Bitmap.createBitmap(bm, (width - height) / 2, 0, height, height);
            } catch (Exception e) {
                Log.e(LOG_TAG, "## setImageBitmap - createBitmap " + e.getMessage());
            }
        }
        // higher than large
        else {
            try {
                bm = Bitmap.createBitmap(bm, 0, (height - width) / 2, width, width);
            } catch (Exception e) {
                Log.e(LOG_TAG, "## setImageBitmap - createBitmap " + e.getMessage());
            }
        }

        try {
            // create a rounded bitmap
            RoundedBitmapDrawable img = RoundedBitmapDrawableFactory.create(getResources(), bm);
            img.setAntiAlias(true);
            img.setCornerRadius(height / 2.0f);

            // apply it to the image
            super.setImageDrawable(img);
        } catch (Exception e) {
            Log.e(LOG_TAG, "## setImageBitmap - RoundedBitmapDrawableFactory.create " + e.getMessage());
            super.setImageBitmap(null);
        }
    } else {
        super.setImageBitmap(null);
    }
}

From source file:org.chromium.chrome.browser.bookmarks.BookmarkItemRow.java

@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 {/*from  ww w  . j  a v a 2  s .c om*/
        RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(getResources(),
                Bitmap.createScaledBitmap(icon, mDisplayedIconSize, mDisplayedIconSize, false));
        roundedIcon.setCornerRadius(mCornerRadius);
        mIconImageView.setImageDrawable(roundedIcon);
    }
}

From source file:com.vagabond.dealhunting.ui.StoreAdapter.java

@Override
public void onBindViewHolder(final StoreAdpaterViewHolder holder, int position) {
    if (!mCursor.moveToPosition(position)) {
        return;/* w ww  .ja va  2 s  .c  o m*/
    }
    holder.storeTitle.setText(mCursor.getString(INDEX_COLUMN_TITLE));
    holder.storeTitleDetail.setText(String.format("%s %s", context.getString(R.string.promotion_text),
            mCursor.getString(INDEX_COLUMN_TITLE)));

    Picasso.with(context).load(mCursor.getString(INDEX_COLUMN_THUMBNAIL)).into(new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            RoundedBitmapDrawable iconStoreDrawable = RoundedBitmapDrawableFactory
                    .create(context.getResources(), bitmap);
            iconStoreDrawable.setCircular(true);
            holder.storeIV.setImageDrawable(iconStoreDrawable);
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {

        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    });
}

From source file:com.google.samples.apps.topeka.widget.AvatarView.java

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);// w  w w.ja va 2 s  . c  o m
    setImageDrawable(roundedDrawable);
}

From source file:bruce.kk.imglibcompare.glide.GlideActivity.java

@OnClick({ R.id.btn_load_local, R.id.btn_load_url, R.id.btn_load_cancel })
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.btn_load_local:
        Glide.with(GlideActivity.this).load(R.mipmap.ic_loading).into(ivImg);
        break;//from  w  w  w .  j  a v  a 2 s.c  o m
    case R.id.btn_load_url:
        Glide.with(GlideActivity.this).load(ImgConstant.GIF_URL).centerCrop().placeholder(R.mipmap.ic_loading2)
                .error(R.mipmap.ic_failed)
                //  tansform 
                .transform(new BitmapTransformation(GlideActivity.this) {
                    @Override
                    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth,
                            int outHeight) {
                        RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getResources(),
                                toTransform);
                        drawable.setCornerRadius(20);
                        //                             drawable.setCircular(true); // ?
                        // ? 
                        int width = drawable.getIntrinsicWidth();
                        int height = drawable.getIntrinsicHeight();
                        // ??
                        Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE
                                ? Bitmap.Config.ARGB_8888
                                : Bitmap.Config.RGB_565;
                        //  bitmap
                        Bitmap bitmap = Bitmap.createBitmap(width, height, config);
                        Canvas canvas = new Canvas(bitmap);
                        drawable.setBounds(0, 0, width, height);
                        drawable.draw(canvas);
                        return bitmap;
                    }

                    @Override
                    public String getId() {
                        return "1001";
                    }
                }).crossFade().listener(new RequestListener<String, GlideDrawable>() {
                    @Override
                    public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                            boolean isFirstResource) {
                        LogDetails.i("model: %s\ntarget: %s\nisFirstResource: %s\nException: %s", model, target,
                                isFirstResource, e);
                        target.onLoadFailed(new Exception("load failed, please check your code"),
                                getResources().getDrawable(R.mipmap.ic_failed));
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(GlideDrawable resource, String model,
                            Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                        LogDetails.i(
                                "model: %s\ntarget: %s\nisFirstResource: %s\nisFromMemoryCache: %s\nresource: %s",
                                model, target, isFirstResource, isFromMemoryCache, resource);
                        target.onLoadStarted(getResources().getDrawable(R.mipmap.ic_start));
                        return false;
                    }
                }).into(ivImg);
        break;
    case R.id.btn_load_cancel:
        Glide.clear(ivImg);
        break;
    }
}