use of android.graphics.BitmapShader in project mobile-android by photo.
the class Wheel method onLayout.
/*
* (non-Javadoc)
*
* @see android.view.View#onLayout(boolean, int, int, int, int)
*/
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
mInLayout = true;
if (changed || mForceLayout) {
mWidth = right - left;
mHeight = bottom - top;
mTickSpace = (float) mWidth / mTicksCount;
mTicksSize = mWidth / mTicksCount / 4.0f;
mTicksSize = Math.min(Math.max(mTicksSize, 3.5f), 6.0f);
mIndicatorX = (float) mWidth / 2.0f;
mOriginalX = (int) mIndicatorX;
mMaxX = mWidth * mWheelSizeFactor;
mIndicator = makeBitmapIndicator((int) Math.ceil(mTicksSize), bottom - top);
mTickBitmap = makeTickerBitmap((int) Math.ceil(mTicksSize), bottom - top);
mShader3 = new BitmapShader(makeBitmap3(right - left, bottom - top), Shader.TileMode.CLAMP, Shader.TileMode.REPEAT);
mMinX = -mMaxX;
if (null != mLayoutListener) {
mLayoutListener.onLayout(this);
}
}
mInLayout = false;
mForceLayout = false;
}
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 material by rey5137.
the class ContactChipSpan method setImage.
public void setImage(Bitmap bm) {
if (mBitmap != bm) {
mBitmap = bm;
if (mBitmap != null) {
mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mMatrix.reset();
float scale = mHeight / (float) Math.min(mBitmap.getWidth(), mBitmap.getHeight());
mMatrix.setScale(scale, scale, 0, 0);
mMatrix.postTranslate((mHeight - mBitmap.getWidth() * scale) / 2, (mHeight - mBitmap.getHeight() * scale) / 2);
mBitmapShader.setLocalMatrix(mMatrix);
}
}
}
use of android.graphics.BitmapShader in project EffectiveAndroid by rallat.
the class CircleTransform method transform.
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
if (squaredBitmap != source) {
source.recycle();
}
Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
squaredBitmap.recycle();
return bitmap;
}
use of android.graphics.BitmapShader in project android-shape-imageview by siyamed.
the class ShaderHelper method createShader.
protected void createShader() {
Bitmap bitmap = calculateDrawableSizes();
if (bitmap != null && bitmap.getWidth() > 0 && bitmap.getHeight() > 0) {
shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
imagePaint.setShader(shader);
}
}
Aggregations