Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Plain Text by Sakthi ( 11 years ago )
public class CollageView extends ImageView {
private Paint mBorderPaint;
private static final int PADDING = 1;
private static final float STROKE_WIDTH = 1.0f;
float radius = 0.0f;
Bitmap bmp;
Matrix mMatrix = null;
boolean flag;
int pos;
Context mContext;
public CollageView(Context context) {
super(context, null);
mC
initBorderPaint();
}
public CollageView(Context context, AttributeSet attrs) {
super(context, attrs, 0);
mC
initBorderPaint();
}
public CollageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mC
initBorderPaint();
}
public void setImageBitmapSrc(Bitmap bmp, boolean flag) {
this.bmp = bmp;
this.flag = flag;
int pixRange = 0;
if(ConstantKeys.DEVICE_SCREEN_SIZE.equals("large")){
pixRange = 320;
} else {
pixRange = 240;
}
if(this.getMeasuredWidth() > pixRange){
this.setScaleX(0.5f);
this.setScaleY(0.5f);
} else {}
invalidate();
}
public void setRoundedCorner(int radius) {
this.radius = radius;
// invalidate();
postInvalidate();
}
public void setColorValue(int colorVal) {
mBorderPaint.setColor(colorVal);
invalidate();
}
public void setStorkeWidth(int strokeWidth) {
mBorderPaint.setStrokeWidth(strokeWidth);
invalidate();
}
public void setPaintColor(int pos){
mBorderPaint.setColor(DrawableResources.COLOR_TABLE[pos]);
this.pos = pos;
invalidate();
}
private void initBorderPaint() {
mBorderPaint = new Paint();
mBorderPaint.setAntiAlias(true);
mBorderPaint.setFilterBitmap(true);
mBorderPaint.setDither(true);
mBorderPaint.setColor(Color.WHITE);
mBorderPaint.setStyle(Paint.Style.STROKE);
mBorderPaint.setStrokeWidth(STROKE_WIDTH);
mBorderPaint.setStrokeJoin(Paint.Join.ROUND);
mBorderPaint.setStrokeCap(Paint.Cap.ROUND);
mMatrix = new Matrix();
Random mRandomPos = new Random();
int tx = mRandomPos.nextInt(240/2);
int ty = mRandomPos.nextInt(320/2);
mMatrix.setTranslate(tx, ty);
mMatrix.setScale(1f, 1f);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
setLayerType(LAYER_TYPE_SOFTWARE, null);
} else {}
flag = false;
}
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
getRoundRectPath(canvas);
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
getRoundRectPath(canvas);
}
private void getRoundRectPath(Canvas canvas) {
if(!flag){
Path clipPath = new Path();
clipPath.addRoundRect(new RectF(PADDING, PADDING, this.getMeasuredWidth() - PADDING, this.getMeasuredHeight() - PADDING), radius, radius, Path.Direction.CCW);
canvas.clipPath(clipPath);
canvas.drawBitmap(bmp, mMatrix, null);
canvas.drawRoundRect(new RectF(PADDING, PADDING, this.getMeasuredWidth() - PADDING, this.getMeasuredHeight() - PADDING), radius, radius, mBorderPaint);
} else {
canvas.drawBitmap(bmp, mMatrix, null);
canvas.drawRoundRect(new RectF(PADDING, PADDING, this.getMeasuredWidth() - PADDING, this.getMeasuredHeight() - PADDING), radius, radius, mBorderPaint);
}
}
}
Revise this Paste