Android Picasso transformation not applied on each view show -
i'm using picasso :
picasso.with(mcontext) .load(url) .placeholder(fallback) .error(fallback) .transform(new circletransform(userstatus)) .into(this);
and transformation apply stroke , roundness image:
public class circletransform implements transformation { private int userstatus = userprofile.status_type_none; public circletransform(int userstatus) { this.userstatus = userstatus; } @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); if (userprofile.status_type_none != userstatus) { paint paintstroke = new paint(); paintstroke.setantialias(true); if (userprofile.status_type_bronze == userstatus) paintstroke.setcolor(colors.bronzecolor); else if (userprofile.status_type_silver == userstatus) paintstroke.setcolor(colors.silvercolor); else if (userprofile.status_type_gold == userstatus) paintstroke.setcolor(colors.goldcolor); else if (userprofile.status_type_platinum == userstatus) paintstroke.setcolor(colors.platinumcolor); else if (userprofile.status_type_diamond == userstatus) paintstroke.setcolor(colors.diamondcolor); paintstroke.setstyle(paint.style.stroke); float stroke = size * circle_size_in_percent; paintstroke.setstrokewidth(stroke); canvas.drawcircle(r, r, r - (stroke / 2), paintstroke); } squaredbitmap.recycle(); return bitmap; } @override public string key() { return "circle"; } }
the problem public bitmap transform(bitmap source)
not getting called each time image loaded.
the userstatus
variable changes behavior of transformation , must included in cache key. otherwise picasso thinks circle transformation can replaced another.
@override public string key() { return "circle" + userstatus; }
Comments
Post a Comment