use of android.graphics.BitmapShader in project weex-example by KalicyZhou.
the class ImageDrawable method createImageDrawable.
public static Drawable createImageDrawable(@Nullable Drawable original, @NonNull ImageView.ScaleType scaleType, @Nullable float[] borderRadius, int vWidth, int vHeight, boolean gif) {
Bitmap bm;
if (!gif && vWidth > 0 && vHeight > 0) {
if (original instanceof BitmapDrawable && (bm = ((BitmapDrawable) original).getBitmap()) != null) {
ImageDrawable imageDrawable;
imageDrawable = new ImageDrawable();
imageDrawable.bitmapWidth = bm.getWidth();
imageDrawable.bitmapHeight = bm.getHeight();
BitmapShader bitmapShader = new BitmapShader(bm, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
updateShaderAndSize(scaleType, vWidth, vHeight, imageDrawable, bitmapShader);
imageDrawable.getPaint().setShader(bitmapShader);
return imageDrawable;
} else if (original instanceof ImageDrawable) {
ImageDrawable imageDrawable = (ImageDrawable) original;
if (imageDrawable.getPaint() != null && imageDrawable.getPaint().getShader() instanceof BitmapShader) {
BitmapShader bitmapShader = (BitmapShader) imageDrawable.getPaint().getShader();
updateShaderAndSize(scaleType, vWidth, vHeight, imageDrawable, bitmapShader);
return imageDrawable;
}
}
}
return original;
}
use of android.graphics.BitmapShader in project android_frameworks_base by AOSPA.
the class TaskViewThumbnail method setThumbnail.
/** Sets the thumbnail to a given bitmap. */
void setThumbnail(Bitmap bm, ActivityManager.TaskThumbnailInfo thumbnailInfo) {
if (bm != null) {
bm.prepareToDraw();
mBitmapShader = new BitmapShader(bm, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mDrawPaint.setShader(mBitmapShader);
mThumbnailRect.set(0, 0, bm.getWidth(), bm.getHeight());
mThumbnailInfo = thumbnailInfo;
updateThumbnailScale();
} else {
mBitmapShader = null;
mDrawPaint.setShader(null);
mThumbnailRect.setEmpty();
mThumbnailInfo = null;
}
}
use of android.graphics.BitmapShader in project android_frameworks_base by DirtyUnicorns.
the class TaskViewThumbnail method setThumbnail.
/** Sets the thumbnail to a given bitmap. */
void setThumbnail(Bitmap bm, ActivityManager.TaskThumbnailInfo thumbnailInfo) {
if (bm != null) {
bm.prepareToDraw();
float INITIAL_SCALE = 0.75f;
int h = bm.getHeight();
int w = bm.getWidth();
Bitmap cropped = null;
int mode = currentHandsMode();
try {
if (mode == 1) {
cropped = Bitmap.createBitmap(bm, 0, (int) (h * (1 - INITIAL_SCALE)), (int) (w * INITIAL_SCALE), (int) (h * INITIAL_SCALE));
} else if (mode == 2) {
cropped = Bitmap.createBitmap(bm, (int) (w * (1 - INITIAL_SCALE)), (int) (h * (1 - INITIAL_SCALE)), (int) (w * INITIAL_SCALE), (int) (h * INITIAL_SCALE));
}
} catch (Exception e) {
cropped = bm;
}
mBitmapShader = new BitmapShader(mode != 0 ? cropped : bm, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mDrawPaint.setShader(mBitmapShader);
mThumbnailRect.set(0, 0, mode != 0 ? cropped.getWidth() : w, mode != 0 ? cropped.getHeight() : h);
mThumbnailInfo = thumbnailInfo;
updateThumbnailScale();
} else {
mBitmapShader = null;
mDrawPaint.setShader(null);
mThumbnailRect.setEmpty();
mThumbnailInfo = null;
}
}
use of android.graphics.BitmapShader in project httpclient by pixmob.
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;
}
use of android.graphics.BitmapShader in project 9GAG by stormzhang.
the class TitanicTextView method createShader.
/**
* Create the shader
* draw the wave with current color for a background
* repeat the bitmap horizontally, and clamp colors vertically
*/
private void createShader() {
if (wave == null) {
wave = getResources().getDrawable(R.drawable.wave);
}
int waveW = wave.getIntrinsicWidth();
int waveH = wave.getIntrinsicHeight();
Bitmap b = Bitmap.createBitmap(waveW, waveH, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
c.drawColor(getCurrentTextColor());
wave.setBounds(0, 0, waveW, waveH);
wave.draw(c);
shader = new BitmapShader(b, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
getPaint().setShader(shader);
offsetY = (getHeight() - waveH) / 2;
}
Aggregations