Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leandroBorgesFerreira/LoadingButtonAndroid
A button to substitute the ProgressDialog
https://github.com/leandroBorgesFerreira/LoadingButtonAndroid
Last synced: about 2 months ago
JSON representation
A button to substitute the ProgressDialog
- Host: GitHub
- URL: https://github.com/leandroBorgesFerreira/LoadingButtonAndroid
- Owner: leandroBorgesFerreira
- License: mit
- Created: 2016-08-11T12:08:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-03-26T13:26:29.000Z (9 months ago)
- Last Synced: 2024-10-16T11:43:29.310Z (about 2 months ago)
- Language: Kotlin
- Size: 18.7 MB
- Stars: 1,953
- Watchers: 31
- Forks: 214
- Open Issues: 60
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-kotlin - LoadingButtonAndroid - A button to substitute the ProgressDialog (Libraries)
- awesome-list - leandroBorgesFerreira/LoadingButtonAndroid - A button to substitute the ProgressDialog (Kotlin)
- awesome-loading-indicators - LoadingButtonAndroid - A button to substitute the ProgressDialog. (Kotlin)
- Android-Awesome-Resources - LoadingButtonAndroid
README
![Java CI with Gradle](https://github.com/leandroBorgesFerreira/dag-command/workflows/Java%20CI%20with%20Gradle/badge.svg)![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.leandroborgesferreira/loading-button-android/badge.png?&gav=true)
# Progress Button Android
![enter image description here](https://i.stack.imgur.com/8SHR1.gif)
Android Button that morphs into a loading progress bar.
- Fully customizable in the XML
- Really simple to use.
- Makes your app looks cooler =DYou can check how this library was implemented here (Old version): https://medium.com/p/9efee6e39711/
## Contents
- [Installation](#installation)
- [How to use / Sample](#how-to-use)
- [Animate and revert animation](#animate-and-revert-animation)
- [Show done animation](#show-done-animation)
- [Revert the loading animation with different text or image](#revert-the-loading-animation-with-different-text-or-image)
- [Configure XML](#configure-xml)
- [Avoid Memory Leaks](#avoid-memory-leaks)
- [Be Creative](#be-creative)
- [Bugs and feedback](#bugs-and-feedback)
- [Credits](#credits)## Installation
```
implementation("com.github.leandroborgesferreira:loading-button-android:2.3.0")
```## How to use
### Animate and revert animation
Add the button in your layout file and customize it the way you like it.
```xml
app:spinning_bar_color="#FFF"
app:spinning_bar_padding="6dp" />
```Then, instanciate the button
```java
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 :
```kotlin
btn.startAnimation {
}
```### Switch to determinant progress
You can switch between indeterminant and determinant progress:```java
circularProgressButton.setProgress(10)
...
circularProgressButton.setProgress(50)
...
circularProgressButton.setProgress(100)
```### - Show 'done' animation
When the loading animation is running, call:
```java
//Choose the color and the image that will be show
circularProgressButton.doneLoadingAnimation(fillColor, bitmap);
```### - Revert the loading animation with different text or image
```kotlin
progressButton.revertAnimation {
progressButton.text = "Some new text"
}
```or
```kotlin
progressImageButton.revertAnimation {
progressImageButton.setImageResource(R.drawable.image)
}
```### - Button State
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:```
```
*I still need to debug this problem.*
### Manifest merge
This library only supports androidx since prior the version 2.0.0. So don't try to use it with the old Support Library. Use androidx instead.
### Avoid Memory Leaks
Prior to version 2.1.0, to avoid memory leaks is your code, you must dispose the buttons in the onDestroy method. Example:```java
override fun onDestroy() {
super.onDestroy()
progressButton.dispose()
}
```In version 2.1.0, `ProgressButton` was updated to be a `LifecycleObserver` and will automatically
call `dispose()` when an `onDestroy()` event is observed by the lifecycle owner.## Contributing
###Setup Git Pre-commit hook script (Optional)The purpose of setting up this optional pre-commit hook is so that the `lintKotlin` Gradle task runs each time you as a developer create a commit. Although the Travis build will run `lintKotlin` in the cloud, running this locally will allow you to catch Kotlin Lint violations early in the development cycle without having to wait for Travis's build report.
To enable the script, execute the following commands starting from the project's root directory:
cd .git/hooks
ln -s ../../scripts/pre-commit.sh pre-commit## Bugs and Feedback
For bugs, feature requests, and discussion please use [GitHub Issues](https://github.com/leandroBorgesFerreira/LoadingButtonAndroid/issues).
## Credits
This library was inspired in this repo: https://github.com/dmytrodanylyk/android-morphing-button
### And that's it! Enjoy!
****