forked from jd-alexander/LikeButton
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.md
More file actions
322 lines (207 loc) · 8.09 KB
/
Copy pathREADME.md
File metadata and controls
322 lines (207 loc) · 8.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# Like Button
[  ](https://jitpack.io/#jd-alexander/likebutton)
[](https://travis-ci.org/jd-alexander/LikeButton)
[](https://www.apache.org/licenses/LICENSE-2.0.html)
[](https://android-arsenal.com/details/1/3038)
Like Button is a library that allows you to create a button with animation effects similar to [Twitter's heart](https://dribbble.com/shots/2416983-Twitter-Heart-Animation) when you like something.

---
# Table of Contents
1. [Gradle Dependency](https://github.com/jd-alexander/LikeButton#gradle-dependency)
1. [Repository](https://github.com/jd-alexander/LikeButton#repository)
2. [Dependency](https://github.com/jd-alexander/LikeButton#dependency)
2. [Basic Usage](https://github.com/jd-alexander/LikeButton#basic-usage)
1. [Like Button XML](https://github.com/jd-alexander/LikeButton#like-button-xml)
2. [Attributes](https://github.com/jd-alexander/LikeButton#attributes)
3. [Button State](https://github.com/jd-alexander/LikeButton#button-state)
4. [Like Event Listener](https://github.com/jd-alexander/LikeButton#like-event-listener)
5. [Icon Types](https://github.com/jd-alexander/LikeButton#icon-types)
6. [Icon Size](https://github.com/jd-alexander/LikeButton#icon-size)
7. [Custom Icons](https://github.com/jd-alexander/LikeButton#custom-icons)
8. [Circle Color Config](https://github.com/jd-alexander/LikeButton#circle-color-config)
9. [Dots Color Config](https://github.com/jd-alexander/LikeButton#dots-color-config)
10. [Animation Size](https://github.com/jd-alexander/LikeButton#animation-size)
11. [Inspiration](https://github.com/jd-alexander/LikeButton#inspiration)
12. [Contribution](https://github.com/jd-alexander/LikeButton#contribution)
13. [License](https://github.com/jd-alexander/LikeButton#license)
---
# Gradle Dependency
#### Repository
Add this in your root `build.gradle` file (**not** your module `build.gradle` file):
```gradle
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
```
#### Dependency
Add this to your module's `build.gradle` file:
```gradle
dependencies {
...
compile 'com.github.jd-alexander:LikeButton:0.2.3'
}
}
```
---
# Basic Usage
#### Like Button XML
To use this like button in your layout simply copy and paste the xml below. This provides the default heart button.
```xml
<com.like.LikeButton
app:icon_type="heart"
app:icon_size="25dp"
android:id="@+id/star_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
```
#### Attributes
There are several other attributes that can be used to configure the button's behaviour and appearance. They are shown below and will be explained in the sections that follow long with their java counterparts.
```xml
<com.like.LikeButton
app:icon_type="Star"
app:circle_start_color="@color/colorPrimary"
app:like_drawable="@drawable/thumb_on"
app:unlike_drawable="@drawable/thumb_off"
app:dots_primary_color="@color/colorAccent"
app:dots_secondary_color="@color/colorPrimary"
app:circle_end_color="@color/colorAccent"
app:icon_size="25dp"
app:liked="true"
app:anim_scale_factor="2"
app:is_enabled="false"
/>
```
---
# Button State
To set the inital liked state of the button you simply use the setLiked functionality via XML or Java. This will show the button in the liked state with the drawable that you selected.
#### XML
```
app:liked="true"
```
#### Java
```java
likeButton.setLiked(true);
```
You can also set if the button is to be enabled or disabled. Once disabled, the animation, listener or any other functionality of the button won't be triggered.
#### XML
```
app:is_enabled="false"
```
#### Java
```java
likeButton.setEnabled(false);
```
---
# Like Event Listener
To listen to events from your like button, simply implement the listener that's triggered once the button is tapped.
```java
likeButton.setOnLikeListener(new OnLikeListener() {
@Override
public void liked(LikeButton likeButton) {
}
@Override
public void unLiked(LikeButton likeButton) {
}
});
```
---
# Icon Types
The libary is bundled with three icons that you can use. A heart,thumb and a star.
#### XML
To set the respective icon via xml simply use the word in the icon type attribute.
```
app:icon_type="heart"
```
#### Java
If you would like to set the icon via Java then simply call the set icon method on the button.
```java
likeButton.setIcon(IconType.Star);
```
---
# Icon Size
#### XML
To set the icon size via xml simply use this attribute
```xml
app:icon_size="20dp"
```
#### Java
If you are doing it programmatically you can set it with either the method for pixels or dp.
```java
likeButton.setIconSizePx(40);
likeButton.setIconSizeDp(20);
```
Note, it's very important that the size of the button is set even if you are planning to use custom drawables as described below as the library uses this value to determine the width and height of the effects that occur when the button is tapped.
---
# Custom Icons
#### XML
In order to use custom icons instead of the ones bundled with the library you simply set the drawables that represent the liked and unliked state of the button.
```
app:like_drawable="@drawable/thumb_on"
app:unlike_drawable="@drawable/thumb_off"
```
#### Java
```java
likeButton.setLikeDrawable(heart_on);
likeButton.setUnlikeDrawable(heart_off);
likeButton.setUnlikeDrawableRes(R.drawable.heart_off);
likeButton.setLikeDrawableRes(R.drawable.heart_on);
```
---
# Circle Color Config
If you watch the animation closely you will notice that there's a circle that begins from the center of the icon and and then it animates away from the center before the exploding dots animate. These colours can be changed to suit the theme of your icon.
#### XML
```
app:circle_start_color="@color/colorPrimary"
app:circle_end_color="@color/colorAccent"
```
#### Java
```java
likeButton.setCircleEndColorRes(R.color.colorAccent);
likeButton.setCircleEndColorRes(R.color.colorPrimary);
```
---
# Dots Color Config
The dots that represent the outer animation can be coloured also.
#### XML
```
app:dots_primary_color="@color/colorAccent"
app:dots_secondary_color="@color/colorPrimary"
```
#### Java
```
likeButton.setExplodingDotColorsRes(R.color.colorPrimary,R.color.colorAccent);
```
---
# Animation Size
To change the size of the dots that also contributes to the size of the overall like button view you can use the animation scale factor attribute via XML or it's Java equivalent
#### XML
```
app:anim_scale_factor="2.5"
```
#### Java
```
likeButton.setAnimationScaleFactor(2);
```
---
# Inspiration
This library was made by possible based on code and design inspiration from these sources:
https://github.com/frogermcs/LikeAnimation
https://github.com/lightsmeki/android_twitter_heart_animation_button
https://dribbble.com/shots/2416983-Twitter-Heart-Animation
# Contribution
Please fork repository and contribute using pull requests.
Any contributions, large or small, major features, bug fixes, additional language translations, unit/integration tests are welcomed and appreciated but will be thoroughly reviewed and discussed.
# License
Copyright 2016 Joel Dean
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.