use of android.graphics.drawable.BitmapDrawable in project qksms by moezbhatti.
the class ImageUtils method drawableToBitmap.
public static Bitmap drawableToBitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
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 nmid-headline by miao1007.
the class EditPage method genBackground.
private void genBackground() {
background = new ColorDrawable(DIM_COLOR);
if (backgroundView != null) {
try {
Bitmap bgBm = captureView(backgroundView, backgroundView.getWidth(), backgroundView.getHeight());
bgBm = blur(bgBm, 20, 8);
BitmapDrawable blurBm = new BitmapDrawable(activity.getResources(), bgBm);
background = new LayerDrawable(new Drawable[] { blurBm, background });
} catch (Throwable e) {
e.printStackTrace();
}
}
}
use of android.graphics.drawable.BitmapDrawable in project Signal-Android by WhisperSystems.
the class ColorPreference method setColorViewValue.
private static void setColorViewValue(View view, int color, boolean selected) {
if (view instanceof ImageView) {
ImageView imageView = (ImageView) view;
Resources res = imageView.getContext().getResources();
Drawable currentDrawable = imageView.getDrawable();
GradientDrawable colorChoiceDrawable;
if (currentDrawable instanceof GradientDrawable) {
// Reuse drawable
colorChoiceDrawable = (GradientDrawable) currentDrawable;
} else {
colorChoiceDrawable = new GradientDrawable();
colorChoiceDrawable.setShape(GradientDrawable.OVAL);
}
// Set stroke to dark version of color
// int darkenedColor = Color.rgb(
// Color.red(color) * 192 / 256,
// Color.green(color) * 192 / 256,
// Color.blue(color) * 192 / 256);
colorChoiceDrawable.setColor(color);
// colorChoiceDrawable.setStroke((int) TypedValue.applyDimension(
// TypedValue.COMPLEX_UNIT_DIP, 2, res.getDisplayMetrics()), darkenedColor);
Drawable drawable = colorChoiceDrawable;
if (selected) {
BitmapDrawable checkmark = (BitmapDrawable) res.getDrawable(R.drawable.check);
checkmark.setGravity(Gravity.CENTER);
drawable = new LayerDrawable(new Drawable[] { colorChoiceDrawable, checkmark });
}
imageView.setImageDrawable(drawable);
} else if (view instanceof TextView) {
((TextView) view).setTextColor(color);
}
}
use of android.graphics.drawable.BitmapDrawable in project LikeButton by jd-alexander.
the class MainActivity method usingCustomIcons.
public void usingCustomIcons() {
//shown when the button is in its default state or when unLiked.
smileButton.setUnlikeDrawable(new BitmapDrawable(getResources(), new IconicsDrawable(this, CommunityMaterial.Icon.cmd_emoticon).colorRes(android.R.color.darker_gray).sizeDp(25).toBitmap()));
//shown when the button is liked!
smileButton.setLikeDrawable(new BitmapDrawable(getResources(), new IconicsDrawable(this, CommunityMaterial.Icon.cmd_emoticon).colorRes(android.R.color.holo_purple).sizeDp(25).toBitmap()));
}
use of android.graphics.drawable.BitmapDrawable in project SmartAndroidSource by jaychou2012.
the class IcsProgressBar method tileify.
/**
* Converts a drawable to a tiled version of itself. It will recursively
* traverse layer and state list drawables.
*/
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 /*
* else if (drawable instanceof StateListDrawable) { StateListDrawable
* in = (StateListDrawable) drawable; StateListDrawable out = new
* StateListDrawable(); int numStates = in.getStateCount(); for (int i =
* 0; i < numStates; i++) { out.addState(in.getStateSet(i),
* tileify(in.getStateDrawable(i), clip)); } return out;
*
* }
*/
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;
}
Aggregations