I’m working on this code where I populate the city picture using Picasso and getting it from expansion file. Then, I followed the instructions here and here.
No one worked for me. The code bellow and few more details follows:
final ExpansionFileLoader expansionFileLoader = new ExpansionFileLoader(this, App.Constants.EXPANSION_FILE_VERSION_NUMBER);
Picasso picasso = new Picasso.Builder(this)
.downloader(new Downloader() {
@Override
public Response load(Uri uri, int networkPolicy) throws IOException {
Log.d("CityActivity", "loading the image file of the chosen city");
InputStream inputStream = expansionFileLoader.getInputStream(uri.toString());
return new Response(inputStream, false, -1);
}
@Override
public void shutdown() {
}
})
.build();
picasso.load(Uri.parse(App.ViewData.selectedCity.image_file_path)).into(PicassoTools.setBackgroundTarget(findViewById(R.id.navigation_drawer_layout)));
I have put breakpoints in the downloader and the main reason is because load is not being called for some reason. So probably Im doing some basic mistake when creating the downloader or Picasso builder.
Btw, I'm using Picasso 2.5.
That is my target settings(which is just a detail, and won't matter for the load method to be called):
public static Target setBackgroundTarget(View view) {
return setBackgroundTarget(view, null);
}
public static Target setBackgroundTarget(View view, Runnable callback) {
Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
view.setBackgroundDrawable(new BitmapDrawable(App.context.getResources(), bitmap));
} else {
view.setBackground(new BitmapDrawable(App.context.getResources(), bitmap));
}
if (callback != null) callback.run();
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
Log.e("PICASSO", "Bitmap Failed");
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
// use placeholder drawable if desired
Log.d("PICASSO", "Bitmap Preload");
}
};
view.setTag(target);
return target;
}
Let me know any other detail you wanna know. Thanks a lot for the help. Cheers