android - Logical concurrency issue with Picasso in custom View -


i creating custom view displays image bitmap loaded picasso framework. initialize need both bitmap , view measure. struggling threading cannot predict thread finish earlier.

the view starts picasso custom target in constructor. saves view's width , size in onsizechanged.

public class figureview extends view {  public figureview(context context) {     super(context);     target = new loadpicturetarget();     picasso.with(getcontext()).load(r.drawable.amalka).into(target); }  protected void onsizechanged(int w, int h, int oldw, int oldh) {     super.onsizechanged(w, h, oldw, oldh);     tilesrect.set(0, 0, w, h); } 

and target sets bitmap , computes resized picture dimensions fit view's available space:

class loadpicturetarget implements target {     public void onbitmaploaded(bitmap bitmap, picasso.loadedfrom from) {         basebitmap = bitmap;         origpicturerect = new rect(0, 0, basebitmap.getwidth(), basebitmap.getheight());         scaledpicturerect = misc.centerhorizontally(tilesrect.width(), tilesrect.height(), basebitmap.getwidth(), basebitmap.getheight());            invalidate();     }      public void onbitmapfailed(drawable errordrawable) { }      public void onprepareload(drawable placeholderdrawable) {  } } 

the problem onbitmaploaded called earlier onsizechanged. not always, cannot move new dimension calculation there either. moved onpaint() not solution need perform intensive bitmap manipulation once have tghe bitmap , available space dimensions.

what proper way implementation custom view picasso when need view size?


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -