use of android.graphics.drawable.BitmapDrawable in project android_frameworks_base by ParanoidAndroid.
the class CustomBar method loadIcon.
protected void loadIcon(int index, String iconName, Density density) {
View child = getChildAt(index);
if (child instanceof ImageView) {
ImageView imageView = (ImageView) child;
String[] pathOut = new String[1];
Density[] densityInOut = new Density[] { density };
InputStream stream = getIcon(iconName, densityInOut, pathOut, true);
density = densityInOut[0];
if (stream != null) {
// look for a cached bitmap
Bitmap bitmap = Bridge.getCachedBitmap(pathOut[0], true);
if (bitmap == null) {
try {
bitmap = Bitmap_Delegate.createBitmap(stream, false, /*isMutable*/
density);
Bridge.setCachedBitmap(pathOut[0], bitmap, true);
} catch (IOException e) {
return;
}
}
if (bitmap != null) {
BitmapDrawable drawable = new BitmapDrawable(getContext().getResources(), bitmap);
imageView.setImageDrawable(drawable);
}
}
}
}
use of android.graphics.drawable.BitmapDrawable in project CircularImageView by Pkmmte.
the class CircularImageView method drawableToBitmap.
/**
* Convert a drawable object into a Bitmap
*
* @param drawable
* @return
*/
public Bitmap drawableToBitmap(Drawable drawable) {
if (drawable == null) {
// Don't do anything without a proper drawable
return null;
} else if (drawable instanceof BitmapDrawable) {
// Use the getBitmap() method instead if BitmapDrawable
return ((BitmapDrawable) drawable).getBitmap();
}
// Create Bitmap object out of the drawable
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
use of android.graphics.drawable.BitmapDrawable in project HoloEverywhere by Prototik.
the class ProgressBar method tileify.
private Drawable tileify(Drawable drawable, boolean clip) {
if (drawable instanceof LayerDrawable) {
LayerDrawable background = (LayerDrawable) drawable;
final int N = background.getNumberOfLayers();
Drawable[] outDrawables = new Drawable[N];
for (int i = 0; i < N; i++) {
int id = background.getId(i);
outDrawables[i] = tileify(background.getDrawable(i), id == android.R.id.progress || id == android.R.id.secondaryProgress);
}
LayerDrawable newBg = new LayerDrawable(outDrawables);
for (int i = 0; i < N; i++) {
newBg.setId(i, background.getId(i));
}
return newBg;
} else if (drawable instanceof StateListDrawable) {
StateListDrawable in = (StateListDrawable) drawable;
StateListDrawable out = new StateListDrawable();
int numStates = ReflectHelper.invoke(in, "getStateCount", int.class);
for (int i = 0; i < numStates; i++) {
out.addState(ReflectHelper.invoke(in, "getStateSet", int[].class, i), tileify(ReflectHelper.invoke(in, "getStateDrawable", Drawable.class, i), clip));
}
return out;
} else if (drawable instanceof BitmapDrawable) {
final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
if (mSampleTile == null) {
mSampleTile = tileBitmap;
}
final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
shapeDrawable.getPaint().setShader(bitmapShader);
return clip ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
}
return drawable;
}
use of android.graphics.drawable.BitmapDrawable in project Fairphone by Kwamecorp.
the class Utilities method createIconBitmap.
/**
* Returns a bitmap suitable for the all apps view.
*/
static Bitmap createIconBitmap(Drawable icon, Context context) {
synchronized (sCanvas) {
// we share the statics :-(
if (sIconWidth == -1) {
initStatics(context);
}
int width = sIconWidth;
int height = sIconHeight;
if (icon instanceof PaintDrawable) {
PaintDrawable painter = (PaintDrawable) icon;
painter.setIntrinsicWidth(width);
painter.setIntrinsicHeight(height);
} else if (icon instanceof BitmapDrawable) {
// Ensure the bitmap has a density.
BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
Bitmap bitmap = bitmapDrawable.getBitmap();
if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
}
}
int sourceWidth = icon.getIntrinsicWidth();
int sourceHeight = icon.getIntrinsicHeight();
if (sourceWidth > 0 && sourceHeight > 0) {
// There are intrinsic sizes.
if (width < sourceWidth || height < sourceHeight) {
// It's too big, scale it down.
final float ratio = (float) sourceWidth / sourceHeight;
if (sourceWidth > sourceHeight) {
height = (int) (width / ratio);
} else if (sourceHeight > sourceWidth) {
width = (int) (height * ratio);
}
} else if (sourceWidth < width && sourceHeight < height) {
// Don't scale up the icon
width = sourceWidth;
height = sourceHeight;
}
}
// no intrinsic size --> use default size
int textureWidth = sIconTextureWidth;
int textureHeight = sIconTextureHeight;
final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, Bitmap.Config.ARGB_8888);
final Canvas canvas = sCanvas;
canvas.setBitmap(bitmap);
final int left = (textureWidth - width) / 2;
final int top = (textureHeight - height) / 2;
// suppress dead code warning
@SuppressWarnings("all") final boolean debug = false;
if (debug) {
// draw a big box for the icon for debugging
canvas.drawColor(sColors[sColorIndex]);
if (++sColorIndex >= sColors.length)
sColorIndex = 0;
Paint debugPaint = new Paint();
debugPaint.setColor(0xffcccc00);
canvas.drawRect(left, top, left + width, top + height, debugPaint);
}
sOldBounds.set(icon.getBounds());
icon.setBounds(left, top, left + width, top + height);
icon.draw(canvas);
icon.setBounds(sOldBounds);
canvas.setBitmap(null);
return bitmap;
}
}
use of android.graphics.drawable.BitmapDrawable in project Fairphone by Kwamecorp.
the class Utilities method createIconBitmap.
/**
* Returns a bitmap suitable for the all apps view. Used to convert pre-ICS
* icon bitmaps that are stored in the database (which were 74x74 pixels at hdpi size)
* to the proper size (48dp)
*/
static Bitmap createIconBitmap(Bitmap icon, Context context) {
int textureWidth = sIconTextureWidth;
int textureHeight = sIconTextureHeight;
int sourceWidth = icon.getWidth();
int sourceHeight = icon.getHeight();
if (sourceWidth > textureWidth && sourceHeight > textureHeight) {
// Icon is bigger than it should be; clip it (solves the GB->ICS migration case)
return Bitmap.createBitmap(icon, (sourceWidth - textureWidth) / 2, (sourceHeight - textureHeight) / 2, textureWidth, textureHeight);
} else if (sourceWidth == textureWidth && sourceHeight == textureHeight) {
// Icon is the right size, no need to change it
return icon;
} else {
// Icon is too small, render to a larger bitmap
final Resources resources = context.getResources();
return createIconBitmap(new BitmapDrawable(resources, icon), context);
}
}
Aggregations