Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Self-Destructing Message Android App Retrieving and Viewing Messages Viewing Video Messages

Adding ProgressBarIndeterminate to the ViewImageActivity of Ribbit.

I was wondering if it was possible to add a ProgressBarIndeterminate to the ViewImageActivity of Ribbit. I tried adding one and setting visibility to true before the setting up the Uri and calling setProgressBarIndeterminateVisibility to false after the call to Picasso, but that way does not work. The image is still being loaded in the background, but the code runs through so the calls to Visibility true and false happen almost simultaneously . And if this already gets covered in preceding videos, I am sorry. I currently am on the Viewing Video Messages of the project.

2 Answers

Andrew West
Andrew West
3,245 Points

If I understand what you're saying, it sounds like the visibility is being set to true at the right time and being set to false too early. Could you provide the chunk of code around where you set the visibility to false?

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_view_image); setupActionBar();

    ImageView imageView = (ImageView)findViewById(R.id.imageView);
    setProgressBarIndeterminateVisibility(true);
    Uri imageUri = getIntent().getData();

    Picasso.with(this).load(imageUri.toString()).into(imageView);

    setProgressBarIndeterminateVisibility(false);
   Timer timer = new Timer();
    timer.schedule(new TimerTask()
    {
        @Override
        public void run()
        {
            finish();
        }
    }, 10*1000);

}

Here is the complete onCreate method. And this is for the ViewImageActivity of the Ribbit project. And then for devices that will process the Uri request slower, the timer may expire before the image is even loaded and it will be deleted before the user even sees the image, so I need to find a walk around that too.

Andrew West
Andrew West
3,245 Points

I'm not quite at the point in the Ribbit app where we use Picasso. But my guess is that

Picasso.with(this).load(imageUri.toString()).into(imageView);

loads the image in the background. If that's the case it makes sense that your progress indicator would quickly switch back to being invisible.

If I'm right about that then the two possible solutions are adding a callback function for Picasso (I'm not sure if that's doable). Or according to here you could add a placeholder image while the actual image is loading up. Via something like

Picasso.with(context).load(tnu).error(R.drawable.no_img).placeholder(R.drawable.img_def).into(holder.immoPic);

That does work and will have to make due. What I am going to do is take and make an animated drawable like in the magic ball app and just have it look like a loading bar... Thank you Andrew.