@@ -36,60 +36,75 @@ You can check how this library was implemented here (Old version): https://mediu
36
36
37
37
Add the button in your layout file and customize it the way you like it.
38
38
39
- <br.com.simplepass.loadingbutton.customViews.CircularProgressImageButton
40
- android:id="@+id/btn_id"
41
- android:layout_width="match_parent"
42
- android:layout_height="wrap_content"
43
- android:background="@drawable/circular_border_shape"
44
- app:spinning_bar_width="4dp" <!-- Optional -->
45
- app:spinning_bar_color="#FFF" <!-- Optional -->
46
- app:spinning_bar_padding="6dp" <!-- Optional -->
39
+ ``` xml
40
+ <br .com.simplepass.loadingbutton.customViews.CircularProgressImageButton
41
+ android:id=" @+id/btn_id"
42
+ android:layout_width=" match_parent"
43
+ android:layout_height=" wrap_content"
44
+ android:background=" @drawable/circular_border_shape" />
45
+ app:spinning_bar_width="4dp" <!-- Optional -->
46
+ app:spinning_bar_color="#FFF" <!-- Optional -->
47
+ app:spinning_bar_padding="6dp" <!-- Optional -->
48
+ ```
47
49
48
50
Then, instanciate the button
49
51
50
- CircularProgressButton btn = (CircularProgressButton) findViewById(R.id.btn_id)
52
+ ``` java
53
+ CircularProgressButton btn = (CircularProgressButton ) findViewById(R . id. btn_id)
54
+ btn. startAnimation();
51
55
52
- btn.startAnimation();
56
+ // [do some async task. When it finishes]
57
+ // You can choose the color and the image after the loading is finished
58
+ btn. doneLoadingAnimation(fillColor, bitmap);
53
59
54
- [do some async task. When it finishes]
55
- //You can choose the color and the image after the loading is finished
56
- btn.doneLoadingAnimation(fillColor, bitmap);
57
- [or just revert de animation]
58
- btn.revertAnimation();
60
+ // [or just revert de animation]
61
+ btn. revertAnimation();
62
+ ```
59
63
60
64
You can also add a callback to trigger an action after the startAnimation has finished resizing the button :
61
65
62
- btn.startAnimation {
63
- <start async task>
64
- }
66
+ ``` kotlin
67
+ btn.startAnimation {
68
+ < start async task>
69
+ }
70
+ ```
65
71
66
72
### Switch to determinant progress
67
73
You can switch between indeterminant and determinant progress:
68
74
69
- circularProgressButton.setProgress(10)
70
- ...
71
- circularProgressButton.setProgress(50)
72
- ...
73
- circularProgressButton.setProgress(100)
74
- ...
75
+ ``` java
76
+ circularProgressButton. setProgress(10 )
77
+ ...
78
+ circularProgressButton. setProgress(50 )
79
+ ...
80
+ circularProgressButton. setProgress(100 )
81
+ ```
75
82
76
83
### - Show 'done' animation
77
84
78
85
When the loading animation is running, call:
79
86
80
- //Choose the color and the image that will be show
81
- circularProgressButton.doneLoadingAnimation(fillColor, bitmap);
87
+ ``` java
88
+ // Choose the color and the image that will be show
89
+ circularProgressButton. doneLoadingAnimation(fillColor, bitmap);
90
+ ```
82
91
83
92
### - Revert the loading animation with different text or image
84
93
85
- progressButton.revertAnimation {
86
- progressButton.text = "Some new text"
87
- }
94
+ ``` kotlin
95
+ progressButton.revertAnimation {
96
+ progressButton.text = " Some new text"
97
+ }
98
+ ```
99
+
88
100
or
89
101
90
- progressImageButton.revertAnimation {
91
- progressImageButton.setImageResource(R.drawable.image)
92
- }
102
+ ``` kotlin
103
+ progressImageButton.revertAnimation {
104
+ progressImageButton.setImageResource(R .drawable.image)
105
+ }
106
+ ```
107
+
93
108
### - Button State
94
109
95
110
This button is a state machine and it changes its state during the animation process. The states are:
@@ -126,11 +141,11 @@ The button enters this state after `stopAnimation()` when the button is not morp
126
141
127
142
## Configure XML
128
143
129
- - app: spinning_bar_width : Changes the width of the spinning bar inside the button
130
- - app:spinning_bar_color: Changes the color of the spinning bar inside the button
131
- - app:spinning_bar_padding: Changes the padding of the spinning bar in relation of the button bounds.
132
- - app:initialCornerAngle: The initial corner angle of the animation. Insert 0 if you have a square button.
133
- - app:finalCornerAngle: The final corner angle of the animation.
144
+ - ` app:spinning_bar_width ` : Changes the width of the spinning bar inside the button
145
+ - ` app:spinning_bar_color ` : Changes the color of the spinning bar inside the button
146
+ - ` app:spinning_bar_padding ` : Changes the padding of the spinning bar in relation of the button bounds.
147
+ - ` app:initialCornerAngle ` : The initial corner angle of the animation. Insert 0 if you have a square button.
148
+ - ` app:finalCornerAngle ` : The final corner angle of the animation.
134
149
135
150
## Problems and troubleshooting
136
151
@@ -141,12 +156,12 @@ This library only supports androidx since prior the version 2.0.0. So don't try
141
156
### Avoid Memory Leaks
142
157
Prior to version 2.1.0, to avoid memory leaks is your code, you must dispose the buttons in the onDestroy method. Example:
143
158
144
- override fun onDestroy() {
145
- super. onDestroy()
146
-
147
- progressButton.dispose()
148
- }
149
-
159
+ ``` java
160
+ override fun onDestroy() {
161
+ super . onDestroy()
162
+ progressButton. dispose()
163
+ }
164
+ ```
150
165
151
166
In version 2.1.0, ` ProgressButton ` was updated to be a ` LifecycleObserver ` and will automatically
152
167
call ` dispose() ` when an ` onDestroy() ` event is observed by the lifecycle owner.
0 commit comments