List of usage examples for android.support.v4.graphics.drawable RoundedBitmapDrawable getBitmap
public final Bitmap getBitmap()
From source file:org.appspot.apprtc.util.ThumbnailsCacheManager.java
public static void LoadImage(final String url, LoadImageCallback callback, final Resources resources, final String displayname, final boolean rounded, boolean fromCache) { final LoadImageCallback mCallback = callback; final Handler uiHandler = new Handler(); final int FG_COLOR = 0xFFFAFAFA; final String name = displayname; if (fromCache) { Bitmap bitmap = ThumbnailsCacheManager.getBitmapFromDiskCache(url); if (bitmap != null) { if (rounded) { RoundedBitmapDrawable roundedBitmap = RoundedBitmapDrawableFactory.create(resources, bitmap); roundedBitmap.setCircular(true); mCallback.onImageLoaded(roundedBitmap.getBitmap()); } else { mCallback.onImageLoaded(bitmap); }/*from www . j a va 2s . c o m*/ return; } } AsyncHttpURLConnection httpConnection = new AsyncHttpURLConnection("GET", url, "", new AsyncHttpURLConnection.AsyncHttpEvents() { @Override public void onHttpError(String errorMessage) { Log.d("LoadImage", errorMessage); } @Override public void onHttpComplete(String response) { int size = 256; Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); final String trimmedName = name == null ? "" : name.trim(); drawTile(canvas, trimmedName, 0, 0, size, size); ThumbnailsCacheManager.addBitmapToCache(url, bitmap); onHttpComplete(bitmap); } @Override public void onHttpComplete(final Bitmap response) { if (mCallback != null) { uiHandler.post(new Runnable() { @Override public void run() { if (rounded) { RoundedBitmapDrawable roundedBitmap = RoundedBitmapDrawableFactory .create(resources, response); roundedBitmap.setCircular(true); mCallback.onImageLoaded(roundedBitmap.getBitmap()); } else { mCallback.onImageLoaded(response); } } }); } } private boolean drawTile(Canvas canvas, String letter, int tileColor, int left, int top, int right, int bottom) { letter = letter.toUpperCase(Locale.getDefault()); Paint tilePaint = new Paint(), textPaint = new Paint(); tilePaint.setColor(tileColor); textPaint.setFlags(Paint.ANTI_ALIAS_FLAG); textPaint.setColor(FG_COLOR); textPaint.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL)); textPaint.setTextSize((float) ((right - left) * 0.8)); Rect rect = new Rect(); canvas.drawRect(new Rect(left, top, right, bottom), tilePaint); textPaint.getTextBounds(letter, 0, 1, rect); float width = textPaint.measureText(letter); canvas.drawText(letter, (right + left) / 2 - width / 2, (top + bottom) / 2 + rect.height() / 2, textPaint); return true; } private boolean drawTile(Canvas canvas, String name, int left, int top, int right, int bottom) { if (name != null) { final String letter = getFirstLetter(name); final int color = ThumbnailsCacheManager.getColorForName(name); drawTile(canvas, letter, color, left, top, right, bottom); return true; } return false; } }); httpConnection.setBitmap(); httpConnection.send(); }
From source file:com.yoloo.android.util.glide.transfromation.RoundedCornersTransformation2.java
@Override public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { Bitmap source = resource.get();// ww w . j a v a 2 s . c o m RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), source); drawable.setCornerRadius(radius); return BitmapResource.obtain(drawable.getBitmap(), bitmapPool); }
From source file:arun.com.chromer.webheads.ui.views.BaseWebHead.java
@Nullable public Bitmap getFaviconBitmap() { try {// w w w . java 2s. co m final RoundedBitmapDrawable roundedBitmapDrawable = (RoundedBitmapDrawable) getFaviconDrawable(); return roundedBitmapDrawable != null ? roundedBitmapDrawable.getBitmap() : null; } catch (Exception e) { Timber.e("Error while getting favicon bitmap: %s", e.getMessage()); } return null; }