2

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

  • What does `PicassoTools.setBackgroundTarget` do? Does it create a `Target`? If so, is a reference to the `Target` kept anywhere? – LukaCiko Mar 02 '15 at 10:46
  • Yes, we have the reference. In PicassoTools we do a new target and do: view.setTag(target); and return the target, just for avoiding the GC to remove it. So, what would be the issue on the overridden load that is not being executed, even though I call "picasso.load(..."? tks! – user2527821 Mar 02 '15 at 21:01
  • I've got one solution. Will publish as soon as I get time. Cheers – user2527821 Mar 05 '15 at 05:22
  • The solution is to deploy the approach done: here:http://blog.jpardogo.com/requesthandler-api-for-picasso-library/ – user2527821 Mar 11 '15 at 16:20
  • jpardo changed his blog, so, the new link is: https://medium.com/@jpardogo/requesthandler-api-for-picasso-library-c3ee7c4bec25#.stqaq3dst – user2527821 Nov 30 '15 at 21:45

0 Answers0