CircularProgressButton btn = (CircularProgressButton) findViewById(R.id.btn_id)
btn.startAnimation();
//[do some async task. When it finishes]//You can choose the color and the image after the loading is finished
btn.doneLoadingAnimation(fillColor, bitmap);
//[or just revert de animation]
btn.revertAnimation();
You can also add a callback to trigger an action after the startAnimation has finished resizing the button :
This button is a state machine and it changes its state during the animation process. The states are:
Before Draw
This state is the initial one, the button is in this state before the View is draw on the screen. This is the state when the button is accesed in the onCreate() of an Activity.
Idle
After the button is drawn in the screen, it gets in the Idle state. It is basically waiting for an animation. Call startAnimation() to start animations with this button.
WAITING_PROGRESS
If the startAnimation() is called before the Idle state, the button goes to this state. The button waits for the button to be drawn in the screen before start the morph animation.
MORPHING
The button stays in this state during the morphing animation.
PROGRESS
After the morph animation, the button start the progress animation. From this state the done and revert animations can happen.
MORPHING_REVERT
The button stays in this state during the morphing animation reversal.
WAITING_DONE
If the doneLoadingAnimation(fillColor: Int, bitmap: Bitmap) is called when the button is still morphing, it enter in this state. The button waits for the morph animation to complete and then start the done animation.
DONE
The button enters this state when the doneLoadingAnimation finishes.
WAITING_TO_STOP
The button enters this state when the stopAnimation() is called before the morph state is completed. The button waits for the morph animation to complete and the stops further animations.
STOPPED
The button enters this state after stopAnimation() when the button is not morphing.
Configure XML
app:spinning_bar_width : Changes the width of the spinning bar inside the button
app:spinning_bar_color: Changes the color of the spinning bar inside the button
app:spinning_bar_padding: Changes the padding of the spinning bar in relation of the button bounds.
app:initialCornerAngle: The initial corner angle of the animation. Insert 0 if you have a square button.
app:finalCornerAngle: The final corner angle of the animation.
Problems and troubleshooting
Animation
This library only works with selector as the background, but not with shape as the root tag. Please put your shape inside a selector, like this: