I use Picasso to upload various images. Usually I just show them in ImageView , but in this situation I want to have a strong link for them so that I can use them in different places without accessing the cache or reloading them. Here is how I am trying to do this (note that there is more to this class - I just narrowed it down to the parts that are relevant to this question):
public class MapLayer { private Context mContext; private String mType; private Drawable mIcon = null; public MapLayer (Context context, String type) { mContext = context; mType = type; downloadIcon(); } public Drawable getIcon() {return mIcon;} private void downloadIcon() { String url = mContext.getString(R.string.maps_icon_url).replace("${type}", mType)); Target target = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { Log.d(TAG, "on bitmap loaded"); mIcon = new BitmapDrawable(mContext.getResources(), bitmap); } @Override public void onBitmapFailed(Drawable errorDrawable) { Log.d(TAG, "on bitmap failed"); } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { Log.d(TAG, "on prepare load"); mIcon = placeHolderDrawable; } }; ImageDownloader.getSharedInstance().load(url).into(target); } }
In each case, I get the output:
on prepare load
but nothing more. My icon is always zero. I know this from other classes where I call getIcon() .
What am I missing here? Thanks for any help.
source share