List of usage examples for android.support.v4.graphics.drawable RoundedBitmapDrawable setCornerRadius
public void setCornerRadius(float f)
From source file:com.ticketmaster.servos.util.picasso.RoundedBitmapTransform.java
@Override public Bitmap transform(Bitmap source) { RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(res, source); drawable.setCornerRadius(getCornerRadius(source)); Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), source.getConfig()); Canvas canvas = new Canvas(output); drawable.setAntiAlias(true);//from w w w .j a va 2 s . c om drawable.setBounds(0, 0, source.getWidth(), source.getHeight()); drawable.draw(canvas); if (source != output) { source.recycle(); } return output; }
From source file:com.google.android.apps.gutenberg.util.RoundedImageListener.java
@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); }/* ww w .j av a 2 s .com*/ }
From source file:nu.yona.app.ui.profile.BaseProfileFragment.java
/** * Gets image.//from www.j a v a 2 s . c om * * @param bitmap the bitmap * @param withAlpha the with alpha * @param backgroundColor the background color * @param firstName the first name * @param lastName the last name * @return the image */ protected Drawable getImage(Bitmap bitmap, boolean withAlpha, int backgroundColor, String firstName, String lastName) { if (bitmap != null) {// TODO: 10/05/16 When server provides user profile image, we need to check and enable if part on base of that. RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap); drawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight())); drawable.setAlpha(ALPHA); return drawable; } return null; }
From source file:android.support.v17.leanback.supportleanbackshowcase.cards.TextCardView.java
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);/*w w w. j a v a2 s . c o m*/ drawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f); imageView.setImageDrawable(drawable); }
From source file:org.mozilla.gecko.fxa.activities.PicassoPreferenceIconTarget.java
@Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { // Updating icons from Java is not supported prior to API 11. if (!AppConstants.Versions.feature11Plus) { return;/*from w ww . ja va 2s . co m*/ } final Drawable drawable; if (cornerRadius > 0) { final RoundedBitmapDrawable roundedBitmapDrawable; roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(resources, bitmap); roundedBitmapDrawable.setCornerRadius(cornerRadius); roundedBitmapDrawable.setAntiAlias(true); drawable = roundedBitmapDrawable; } else { drawable = new BitmapDrawable(resources, bitmap); } preference.setIcon(drawable); }
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);//from w ww . j av a 2s .c o m drawable.setAntiAlias(true); drawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f); imageView.setImageDrawable(drawable); } }
From source file:im.vector.view.VectorCircularImageView.java
/** * Update the bitmap.//from ww w . j a va 2 s . c o 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 this.setImageDrawable(img); } catch (Exception e) { Log.e(LOG_TAG, "## setImageBitmap - RoundedBitmapDrawableFactory.create " + e.getMessage()); super.setImageBitmap(null); } } else { super.setImageBitmap(null); } }
From source file:im.neon.view.VectorCircularImageView.java
/** * Update the bitmap./*from ww w . ja v a 2 s. c o 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 {// www .j a v a 2 s.c o m RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(getResources(), Bitmap.createScaledBitmap(icon, mDisplayedIconSize, mDisplayedIconSize, false)); roundedIcon.setCornerRadius(mCornerRadius); mIconImageView.setImageDrawable(roundedIcon); } }
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.//www . ja va 2s . c om */ @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; } }