kofigyan / StateProgressBar

Android library to realize the various states and transitions in a ProgressBar.
1.54k stars 233 forks source link

No animation when setCurrentSateNumber #23

Open wujushan opened 7 years ago

wujushan commented 7 years ago

When I call the method "setCurrentStateNumber" into a button listener to update current state ,there will be no animation.

kofigyan commented 7 years ago

Hello @wujushan , please can you provide me with a code snippet of how you do this call.

wujushan commented 6 years ago

Hi @kofigyan ,if it is necessary to call the method “enableAnimationToCurrentState(true)” before calling the method "setCurrentStateNumber"?This is my code below.

`public class Main2Activity extends AppCompatActivity { private String[] descriptionData = {"one", "two", "three"}; private StateProgressBar mStateProgressBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); mStateProgressBar = (StateProgressBar)findViewById(R.id.state_progress); mStateProgressBar.setStateDescriptionData(descriptionData); mStateProgressBar.setCurrentStateNumber(StateProgressBar.StateNumber.TWO); //animation }

/**
 * no animation if call into button listener
 * @param view
 */
public void onClick(View view){
   int id  = view.getId();
    switch (id){
        case R.id.one_btn:
            mStateProgressBar.setCurrentStateNumber(StateProgressBar.StateNumber.ONE);
            break;
        case R.id.two_btn:
            mStateProgressBar.enableAnimationToCurrentState(true);
            mStateProgressBar.setCurrentStateNumber(StateProgressBar.StateNumber.TWO);
            break;
        case R.id.three_btn:
            mStateProgressBar.setCurrentStateNumber(StateProgressBar.StateNumber.THREE);
            mStateProgressBar.enableAnimationToCurrentState(true);
            break;
    }
}

}`

Inzimam-Tariq commented 6 years ago

@wujushan have you found the solution? let me know when you find.

kofigyan commented 6 years ago

Please check out this link -https://youtu.be/-03NBianPfw . Let me know if is helpful.

sudansh commented 6 years ago

This wasn't helpful, As you can see the line animation didn't happen on button click. It just changed from state1 to state2.

unlimited101 commented 5 years ago

I have the same problem. And I think I know why it appears. You call enableAnimationToCurrentState(false) in Animtor.run() as soon as the animation stops. This disables the animation for further changes via setCurrentStateNumber(). It doesn't even help to call enableAnimationToCurrentState(true) before a call to setCurrentStateNumber() because Animator.run() happens asynchronously.

I think you need two variables. One mAnimateToCurrentProgressState which is only settable via public method. And something like a mIsCurrentlyAnimating which has only private access and which you can set to false inside Animtor.run().

Mumbaso21 commented 4 years ago

Have u find a solution to this problem ? I'm trying to use it but this problem is still there...