android - How to use CircleImageView with Volley's NetworkImageView? -
i need circle images rectangular/square images taken network. in application images volley's networkimageview. found fantastic library https://github.com/hdodenhof/circleimageview don't understand how can use networkimageview.
can me?
check class
public class circulairenetworkimageview extends networkimageview { private int borderwidth; private int canvassize; private bitmap image; private paint paint; private paint paintborder; public circulairenetworkimageview(final context context) { this(context, null); } public circulairenetworkimageview(context context, attributeset attrs) { this(context, attrs, r.attr.actionbuttonstyle); } public circulairenetworkimageview(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); paint = new paint(); paint.setantialias(true); paintborder = new paint(); paintborder.setantialias(true); } public void setborderwidth(int borderwidth) { this.borderwidth = borderwidth; this.requestlayout(); this.invalidate(); } public void setbordercolor(int bordercolor) { if (paintborder != null) paintborder.setcolor(bordercolor); this.invalidate(); } public void addshadow() { setlayertype(layer_type_software, paintborder); paintborder.setshadowlayer(4.0f, 0.0f, 2.0f, color.black); } @suppresslint("drawallocation") @override public void ondraw(canvas canvas) { // load bitmap image = drawabletobitmap(getdrawable()); // init shader if (image != null) { canvassize = canvas.getwidth(); if(canvas.getheight()<canvassize) canvassize = canvas.getheight(); bitmapshader shader = new bitmapshader(bitmap.createscaledbitmap(image, canvassize, canvassize, false), shader.tilemode.clamp, shader.tilemode.clamp); paint.setshader(shader); // circlecenter x or y of view's center // radius radius in pixels of cirle drawn // paint contains shader texture shape int circlecenter = (canvassize - (borderwidth * 2)) / 2; canvas.drawcircle(circlecenter + borderwidth, circlecenter + borderwidth, ((canvassize - (borderwidth * 2)) / 2) + borderwidth - 4.0f, paintborder); canvas.drawcircle(circlecenter + borderwidth, circlecenter + borderwidth, ((canvassize - (borderwidth * 2)) / 2) - 4.0f, paint); } } @override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) { int width = measurewidth(widthmeasurespec); int height = measureheight(heightmeasurespec); setmeasureddimension(width, height); } private int measurewidth(int measurespec) { int result = 0; int specmode = measurespec.getmode(measurespec); int specsize = measurespec.getsize(measurespec); if (specmode == measurespec.exactly) { // parent has determined exact size child. result = specsize; } else if (specmode == measurespec.at_most) { // child can large wants specified size. result = specsize; } else { // parent has not imposed constraint on child. result = canvassize; } return result; } private int measureheight(int measurespecheight) { int result = 0; int specmode = measurespec.getmode(measurespecheight); int specsize = measurespec.getsize(measurespecheight); if (specmode == measurespec.exactly) { // told how big result = specsize; } else if (specmode == measurespec.at_most) { // child can large wants specified size. result = specsize; } else { // measure text (beware: ascent negative number) result = canvassize; } return (result + 2); } public bitmap drawabletobitmap(drawable drawable) { if (drawable == null) { return null; } else 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; } }
Comments
Post a Comment