Java Code Examples for android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory#create()
The following examples show how to use
android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory#create() .
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: TextCardView.java From leanback-showcase with Apache License 2.0 | 6 votes |
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 2
Source File: InterestsItemView.java From delion with Apache License 2.0 | 6 votes |
@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 3
Source File: NewTabPageView.java From delion with Apache License 2.0 | 6 votes |
@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 4
Source File: BookmarkItemRow.java From AndroidChromium with Apache License 2.0 | 5 votes |
@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); } }
Example 5
Source File: CharacterCardView.java From leanback-showcase with Apache License 2.0 | 5 votes |
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 6
Source File: AvatarView.java From CoolSignIn with Apache License 2.0 | 5 votes |
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 7
Source File: RoundedNetworkImageView.java From RestVolley with Apache License 2.0 | 5 votes |
/** * get circle drawable. * @param context Context * @param bitmap Bitmap * @return {@link RoundedBitmapDrawable} */ public static RoundedBitmapDrawable getCircleDrawable(Context context, Bitmap bitmap) { RoundedBitmapDrawable circleDrawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap); circleDrawable.setAntiAlias(true); circleDrawable.setCornerRadius(Math.min(bitmap.getWidth(), bitmap.getHeight()) / 2.0f); return circleDrawable; }
Example 8
Source File: TileGroup.java From 365browser with Apache License 2.0 | 5 votes |
@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 9
Source File: BookmarkItemRow.java From delion with Apache License 2.0 | 5 votes |
@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); } }
Example 10
Source File: BookmarkItemRow.java From 365browser with Apache License 2.0 | 5 votes |
@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); } }
Example 11
Source File: DrawableUtils.java From meiShi with Apache License 2.0 | 5 votes |
public static Drawable roundedBitmap(Bitmap bitmap) { RoundedBitmapDrawable circleDrawable = RoundedBitmapDrawableFactory.create(App.getInstance().getResources(), bitmap); circleDrawable.getPaint().setAntiAlias(true); circleDrawable.setCircular(true); circleDrawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f); return circleDrawable; }
Example 12
Source File: AppIconView.java From Cleaner with Apache License 2.0 | 5 votes |
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); }
Example 13
Source File: ConfirmImportantSitesDialogFragment.java From 365browser with Apache License 2.0 | 5 votes |
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 14
Source File: CardViewActivity.java From FrostyBackgroundTestApp with Apache License 2.0 | 5 votes |
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 15
Source File: AppIconView.java From MediaNotification with Apache License 2.0 | 5 votes |
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); }
Example 16
Source File: RoundedImageListener.java From attendee-checkin with Apache License 2.0 | 5 votes |
@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 17
Source File: RoundedContact.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
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; }
Example 18
Source File: Utils.java From ColorBox-library with GNU General Public License v3.0 | 4 votes |
static RoundedBitmapDrawable round(Resources resources, boolean isLand, int dim, int color) { Bitmap.Config conf = Bitmap.Config.ARGB_8888; int dimen = isLand ? Math.round((int) resources.getDimension(dim) * 0.85f) : (int) resources.getDimension(dim); Bitmap bitmap = Bitmap.createBitmap(dimen, dimen, conf); bitmap.eraseColor(color); // Create a new RoundedBitmapDrawable RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(resources, bitmap); roundedBitmapDrawable.setCircular(true); roundedBitmapDrawable.setAntiAlias(true); // Return the RoundedBitmapDrawable return roundedBitmapDrawable; }
Example 19
Source File: ContactHolder.java From actor-platform with GNU Affero General Public License v3.0 | 4 votes |
private RoundedBitmapDrawable getRoundedBitmapDrawable(Context context, Bitmap b) { RoundedBitmapDrawable d = RoundedBitmapDrawableFactory.create(context.getResources(), Bitmap.createScaledBitmap(b, Screen.dp(48), Screen.dp(48), false)); d.setCornerRadius(d.getIntrinsicHeight() / 2); d.setAntiAlias(true); return d; }
Example 20
Source File: ThemePreference.java From LaunchEnr with GNU General Public License v3.0 | 3 votes |
private static RoundedBitmapDrawable createRoundedBitmapDrawable(Bitmap bitmap, int color, Resources mResources) { bitmap.eraseColor(color); // Create a new RoundedBitmapDrawable RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(mResources, bitmap); roundedBitmapDrawable.setCircular(true); roundedBitmapDrawable.setAntiAlias(true); // Return the RoundedBitmapDrawable return roundedBitmapDrawable; }