Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SmoothProgressBar starts on resume activity #35

Closed
Thermometer91 opened this issue May 14, 2014 · 11 comments
Closed

SmoothProgressBar starts on resume activity #35

Thermometer91 opened this issue May 14, 2014 · 11 comments

Comments

@Thermometer91
Copy link

Heya,

My compliments for this awesome library! I love the way I can customize the progress bar on so many levels.

I am running into an issue with my progress bar starting, when my activity resumes (after dismissing another activity and coming back to the progress bar activity).

I tried to handle it with the setSmoothProgressDrawableCallbacks, and handling hiding & showing in the onStop() and onStart() methods, but this doesn't give the expected result.

I am initializing my progress bar in my activity's onCreate():

mProgressBar = (SmoothProgressBar) findViewById(R.id.route_detail_progressbar);
mProgressBar.setVisibility(View.VISIBLE);
mProgressBar.setSmoothProgressDrawableCallbacks(new ProgressBarListener());
mProgressBar.progressiveStart();

And having customized the progress bar in XML:

<fr.castorflex.android.smoothprogressbar.SmoothProgressBar
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/route_detail_progressbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:layout_marginTop="-3dp"
        android:visibility="gone"
        app:spb_sections_count="2"
        app:spb_color="@color/Primary"
        app:spb_speed="0.7"
        app:spb_stroke_width="7dp"
        app:spb_stroke_separator_length="16dp"
        app:spb_reversed="false"
        app:spb_mirror_mode="false"
        app:spb_progressiveStart_activated="true"
        app:spb_progressiveStart_speed="1.5"
        app:spb_progressiveStop_speed="3.4"
        />

Without adding the ProgressBarListener, everything works as expected, except that when the activity comes in view, it starts again.

My ProgressBarListener:

private class ProgressBarListener implements SmoothProgressDrawable.Callbacks
    {
        @Override
        public void onStop() {
            mProgressBar.setVisibility(View.GONE);
        }

        @Override
        public void onStart() {
            mProgressBar.setVisibility(View.VISIBLE);
        }
    }

With the listener, I don't see the progress bar at all.

Do you have any idea what I am doing wrong? I've put breakpoints in the listener, and it seems that onStop() is called first, then onStart() is called twice strangely enough.

Thanks in advance!

@castorflex
Copy link
Owner

Hi @thermometer.

Thank you for your detailed issue!

You make me realize I really have to write some doc :s ... sorry about that.

If the attribute spb_progressiveStart_activated is set to true, that means the progressbar will be started progressively every times it is shown. To be honest, I am really thinking about removing this attribute in the future releases.

Can you try to set the spb_progressiveStart_activated to false (or simply remove it), and call progressiveStart / progressiveStop.

I'll try to reproduce it,

Thanks!

@castorflex
Copy link
Owner

Actually I just tried to reproduce it, and couldn't. I created a branch (named issue35) to try to reproduce your problem. Here is the commit: 2d93cd0

Can you try to install the sample app or modify the sample app code in this branch so we can reproduce your issue?

Thank you.

@Thermometer91
Copy link
Author

Awesome! Thanks for the quick reply.

Yeah I think the javadoc/readme could use some work. I can help with the readme part if you want 👍

I noticed that when I only have 1 activity with the progress bar, the issue won't occur. I think it has something to do with me having another activity with a progressbar (both with an instance of the listener) on top of the activity. I will try to reproduce it in the sample and let you know here.

@sahildave
Copy link

Hi, does the stop animation of the progressbar is like SwipeRefreshLayout? i.e the ongoing animation gets completed first before making the progressbar invisible or gone?

I am just setting setVisiblity as gone after my asynctask is completed. How could I make it end with a more smoother animation?

@castorflex
Copy link
Owner

@sahildave The stop method just stops the animation. I think you are refering to the progressStop method.

    mProgressBar.setSmoothProgressDrawableCallbacks(new SmoothProgressDrawable.Callbacks() {
      @Override
      public void onStop() {
        mPocketBar.setVisibility(View.GONE);
      }

      @Override
      public void onStart() {
        mPocketBar.setVisibility(View.VISIBLE);
      }
    });

    mProgressBar.progressiveStop();

PS: please, create a StackOverflow post next time

Thermometer91 pushed a commit to Thermometer91/SmoothProgressBar that referenced this issue May 19, 2014
- Added listener to second activity
- Set initial visibility to gone
- progressiveStart the progressBar after init
castorflex added a commit that referenced this issue May 19, 2014
@Thermometer91
Copy link
Author

Heya,

I partly reproduced my issue in the sample you provided. If I add the listener, set initial visibility to gone in the XML and then start the progressBar, it stays hidden until I again activate it via the button on progressiveStart(). Weirdly enough, after activating it via the button, if I stop it, and try to activate it again, it can't get visible anymore. I tried to replicate my issue (with 2 activities loaded, both having a progressBar and listeners), but that doesn't seem to make a difference.

Now, the same implementation of the sample and my app, shows different results. In my app, only the second activity I start, won't show the progressBar. The first works fine with the same code. In the sample, both activities won't show the progressBar. I have the feeling it has something to do with my first activity having a fragment in it with the progressBar, instead of in the activity.

A theory I have why the progressBar won't show in the sample, is because I may start it earlier (in onCreate() ) than the XML is rendered (with visibility="gone"), but I have too little knowledge of the render order to know this theory to be true. This also won't explain why the progressBar won't get visible anymore, after the progressiveStop().

Now, for my original issue, I fixed my problem. I removed spb_progressiveStart_activated, initial visibility and all changes to visibility. The only reason I was setting visibility on start and stop, was because spb_progressiveStart_activated made the progressBar active on resume. Now everything behaves as it should. Maybe it is a good idea to remove the spb_progressiveStart_activated property altogether or document it better in the readme.

@castorflex
Copy link
Owner

Can you test 424e40c ?

@Thermometer91
Copy link
Author

Awesome, that fixes the onStart() method that only got called once. Any idea why it isn't visible initially in the sample (on this branch)? I expect that to be something out of the scope for your library, so you can close this issue if you want 👍 . Do you want me to try modifying the readme to make it clearer to understand and submit a pull req?

@castorflex
Copy link
Owner

The ActivityThread change the visibility of the decor after onResume() is called, setting it to INVISIBLE, then to VISIBLE. This visibility change will be dispatched through the whole hierarchy, including ProgressBar. When the ProgressBar's onVisibilityChanged(View, int) is called with a visibility = GONE/INVISIBLE, it stops the animation, which will call the SmoothProgressBar.CallBacks#onStop() method.

That is why onStop() will be called just after onStart(). Unfortunately, we set the visibility to GONE in the callback, so the ProgressBar won't be shown :(

I'll try to work around.

iNdieboyjeff pushed a commit to iNdieboyjeff/SmoothProgressBar that referenced this issue Jul 2, 2014


# By Antoine Merle (4) and Subrahmanya Somayaji M (1)
# Via Antoine Merle
* 'master' of https://github.com/castorflex/SmoothProgressBar:
  Added gif in readme
  Updated plugins, incremented versions code/numbers...
  Updated Sample
  Added a test before scheduling the next update. Closes castorflex#35
  Added screenshots
@kalvn
Copy link

kalvn commented Aug 13, 2014

I have the same kind of issue when displaying the SmoothProgressBar in a fragment which is inside a ViewPager.
For example in my application, I have 3 pages so 3 framgents with the same type. On loading, I display the smoothscrollingbar on the 2 first fragments because they have stuff to load but not the third one. Nevertheless, when I swipe to the third page, the smoothscrollingbar is displayed (even if I put it INVISIBLE in the XML).

It's like something is showing it in the onStart or onResume of the fragment, which is called each time you swipe to a page.

@drindt
Copy link

drindt commented Aug 1, 2015

Here seems that:

android:indeterminate="true"

is the problem. When this is set

app:spb_progressiveStart_activated="true"

is totally ignored. Setting this all programmatically seems fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants