Show progress while uploading image from server to image

I am a ListView and want to show the progress until the image is loaded from the server into an ImageView using the Picasso library, still showing the ic_launcher that can be retrieved when the image is loaded from the server into the ImageView, but what if I would like to show the progress

    Picasso.with(context)
    .load(imageURL)
    .transform(transformation)
    .placeholder(R.drawable.ic_launcher)
    .error(R.drawable.ic_launcher)
    .into(viewHolder.imageView);

      

+3


source to share


5 answers


in your xml file you need to put progress above the image, set the visibility of the progress visible indicator and in your code

Picasso.with(context)
       .load(file)
       .into(imageView, new Callback() {
           @Override
           public void onSuccess() {
               progressbar.setVisibility(View.GONE);
           }
       });

      



When loading image you need setVisibility (View.GONE) to go to next page

+5


source


At the last Google Developers Summit in Thailand, Google introduced us to the Android Image Downloader Library developed by bumptech Glide as a Google Recommended Library. It is used in many Google open source projects to date, including the official Google I / O 2014 app.

I managed to interest me. I spent a whole night playing with her and decided to share my experience on this blog. In the beginning, I must say that it looks 90% similar to Picasso. To be more precise, I think this is something of a Picasso clone.



Anyway, it's completely different. You will find out how.

http://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en

+6


source


Add the ProgressBar to your XML where you put the ImageView, or do it programmatically. Then you can do:

 ProgressBar progressBar ; //initialize it as you dud with the imageView
    progressBar.setVisibility(View.VISIBLE);
    Picasso.with(context)
            .load(imageURL)
            .transform(transformation)
            .placeholder(R.drawable.ic_launcher)
            .error(R.drawable.ic_launcher)
            .into(viewHolder.imageView, new Callback() {
                @Override
                public void onSuccess() {
                    progressBar.setVisibility(View.GONE);
                }
                @Override
                public void onError() {
                }
            });

      

+2


source


mProgressDialog = new ProgressDialog(getActivity());
        mProgressDialog.setMessage("Wait a moment, loading image...");
        mProgressDialog.setCanceledOnTouchOutside(false);
        mProgressDialog.setCancelable(false);
        mProgressDialog.show();

        Picasso.with(getActivity()).load(mImagePath).into(mImageView, new Callback() {
            @Override
            public void onSuccess() {
                mProgressDialog.dismiss();
            }

            @Override
            public void onError() {
                mProgressDialog.dismiss();
                Toast.makeText(getActivity(), "Download failed", Toast.LENGTH_LONG).show();
            }
        });

      

+1


source


I think you can use Target Class of Picasso

Target t = new Target() {
 @Override
 public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
         //hideProgress
}

@Override
public void onBitmapFailed(Drawable errorDrawable) {
           //hideProgress
}

 @Override
  public void onPrepareLoad(Drawable placeHolderDrawable) {

        //lshow Progress
 }
};

 Picasso.with(context)
.load(strImage)
.transform(transformation)
.placeholder(R.drawable.nothing_found)
.error(R.drawable.nothing_found)
.into(t);

      

0


source







All Articles