Skip to content

Commit 599873e

Browse files
committed
Release 1.0.4
1 parent 1772eff commit 599873e

8 files changed

Lines changed: 170 additions & 12 deletions

File tree

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Add below dependency in your **build.gradle** file.
1616

1717
```groovy
1818
dependencies {
19-
compile 'co.lujun:androidtagview:1.0.3'
19+
compile 'co.lujun:androidtagview:1.0.4'
2020
}
2121
```
2222

@@ -75,6 +75,9 @@ Now, you have successfully created some TagViews. The following will show some m
7575
| tag_clickable | boolean | Whether TagView can clickable(default unclickable)
7676
| tag_theme | enum | The TagView [theme](#themes)
7777
| tag_text_direction | enum | The TagView text [direction](#directions)
78+
| tag_ripple_color | color | The ripple effect color(default #EEEEEE)
79+
| tag_ripple_alpha | integer | The ripple effect color alpha(the value may between 0 - 255, default 128)
80+
| tag_ripple_duration | integer | The ripple effect duration(In milliseconds, default 1000ms)
7881

7982
**You can set these attributes in layout file, or use setters(each attribute has get and set method) to set them.**
8083

@@ -179,6 +182,10 @@ mTagContainerLayout.removeAllTags();
179182
```
180183

181184
## Change logs
185+
###1.0.4(2016-10-30)
186+
- Support ripple effect(Call requires API level 11), like [Android CustomButton](https://github.com/whilu/AndroidSample/tree/master/CustomButton)
187+
- fix bugs
188+
182189
###1.0.3(2016-4-3)
183190
- add ```getTags()``` method to get the list for all tags
184191
- fixed bugs in ListView/RecyclerView

androidtagview/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
defaultConfig {
88
minSdkVersion 9
99
targetSdkVersion 23
10-
versionCode 103
11-
versionName "1.0.3"
10+
versionCode 104
11+
versionName "1.0.4"
1212
}
1313
buildTypes {
1414
release {

androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ public class TagContainerLayout extends ViewGroup {
124124
/** Default tag min length*/
125125
private static final int TAG_MIN_LENGTH = 3;
126126

127+
/** The ripple effect duration(In milliseconds, default 1000ms)*/
128+
private int mRippleDuration = 1000;
129+
130+
/** The ripple effect color(default #EEEEEE)*/
131+
private int mRippleColor;
132+
133+
/** The ripple effect color alpha(the value may between 0 - 255, default 128)*/
134+
private int mRippleAlpha = 128;
135+
127136
public TagContainerLayout(Context context) {
128137
this(context, null);
129138
}
@@ -178,6 +187,9 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr){
178187
mTagTextColor = attributes.getColor(R.styleable.AndroidTagView_tag_text_color, mTagTextColor);
179188
mTagTextDirection = attributes.getInt(R.styleable.AndroidTagView_tag_text_direction, mTagTextDirection);
180189
isTagViewClickable = attributes.getBoolean(R.styleable.AndroidTagView_tag_clickable, false);
190+
mRippleColor = attributes.getColor(R.styleable.AndroidTagView_tag_ripple_color, Color.parseColor("#EEEEEE"));
191+
mRippleAlpha = attributes.getInteger(R.styleable.AndroidTagView_tag_ripple_alpha, mRippleAlpha);
192+
mRippleDuration = attributes.getInteger(R.styleable.AndroidTagView_tag_ripple_duration, mRippleDuration);
181193
attributes.recycle();
182194

183195
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
@@ -399,6 +411,9 @@ private void initTagView(TagView tagView){
399411
tagView.setIsViewClickable(isTagViewClickable);
400412
tagView.setBdDistance(mTagBdDistance);
401413
tagView.setOnTagClickListener(mOnTagClickListener);
414+
tagView.setRippleAlpha(mRippleAlpha);
415+
tagView.setRippleColor(mRippleColor);
416+
tagView.setRippleDuration(mRippleDuration);
402417
}
403418

404419
private void invalidateTags(){
@@ -1011,6 +1026,54 @@ public void setTagTextColor(int color) {
10111026
this.mTagTextColor = color;
10121027
}
10131028

1029+
/**
1030+
* Get the ripple effect color's alpha.
1031+
* @return
1032+
*/
1033+
public int getRippleAlpha() {
1034+
return mRippleAlpha;
1035+
}
1036+
1037+
/**
1038+
* Set TagView ripple effect alpha, the value may between 0 to 255, default is 128.
1039+
* @param mRippleAlpha
1040+
*/
1041+
public void setRippleAlpha(int mRippleAlpha) {
1042+
this.mRippleAlpha = mRippleAlpha;
1043+
}
1044+
1045+
/**
1046+
* Get the ripple effect color.
1047+
* @return
1048+
*/
1049+
public int getRippleColor() {
1050+
return mRippleColor;
1051+
}
1052+
1053+
/**
1054+
* Set TagView ripple effect color.
1055+
* @param mRippleColor
1056+
*/
1057+
public void setRippleColor(int mRippleColor) {
1058+
this.mRippleColor = mRippleColor;
1059+
}
1060+
1061+
/**
1062+
* Get the ripple effect duration.
1063+
* @return
1064+
*/
1065+
public int getRippleDuration() {
1066+
return mRippleDuration;
1067+
}
1068+
1069+
/**
1070+
* Set TagView ripple effect duration, default is 1000ms.
1071+
* @param mRippleDuration
1072+
*/
1073+
public void setRippleDuration(int mRippleDuration) {
1074+
this.mRippleDuration = mRippleDuration;
1075+
}
1076+
10141077
public float dp2px(Context context, float dp) {
10151078
final float scale = context.getResources().getDisplayMetrics().density;
10161079
return dp * scale + 0.5f;

androidtagview/src/main/java/co/lujun/androidtagview/TagView.java

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package co.lujun.androidtagview;
22

3+
import android.animation.ValueAnimator;
4+
import android.annotation.TargetApi;
35
import android.content.Context;
46
import android.graphics.Canvas;
57
import android.graphics.Paint;
8+
import android.graphics.Path;
69
import android.graphics.RectF;
10+
import android.graphics.Region;
711
import android.graphics.Typeface;
12+
import android.os.Build;
813
import android.support.v4.widget.ViewDragHelper;
914
import android.text.TextUtils;
1015
import android.view.MotionEvent;
@@ -64,7 +69,7 @@ public class TagView extends View {
6469
/** The distance between baseline and descent*/
6570
private float bdDistance;
6671

67-
private Paint mPaint;
72+
private Paint mPaint, mRipplePaint;
6873

6974
private RectF mRectF;
7075

@@ -75,9 +80,24 @@ public class TagView extends View {
7580
private int mLastX, mLastY;
7681

7782
private float fontH, fontW;
83+
84+
private float mTouchX, mTouchY;
85+
86+
/** The ripple effect duration(default 1000ms)*/
87+
private int mRippleDuration = 1000;
88+
89+
private float mRippleRadius;
90+
91+
private int mRippleColor;
92+
93+
private int mRippleAlpha;
94+
95+
private Path mPath;
7896

7997
private Typeface mTypeface;
8098

99+
private ValueAnimator mRippleValueAnimator;
100+
81101
private Runnable mLongClickHandle = new Runnable() {
82102
@Override
83103
public void run() {
@@ -98,7 +118,10 @@ public TagView(Context context, String text){
98118

99119
private void init(String text){
100120
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
121+
mRipplePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
122+
mRipplePaint.setStyle(Paint.Style.FILL);
101123
mRectF = new RectF();
124+
mPath = new Path();
102125
mOriginText = text == null ? "" : text;
103126
}
104127

@@ -162,6 +185,9 @@ protected void onDraw(Canvas canvas) {
162185
canvas.drawText(mAbstractText, getWidth() / 2 - fontW / 2,
163186
getHeight() / 2 + fontH / 2 - bdDistance, mPaint);
164187
}
188+
189+
// draw ripple for TagView
190+
drawRipple(canvas);
165191
}
166192

167193
@Override
@@ -192,6 +218,13 @@ public boolean dispatchTouchEvent(MotionEvent event) {
192218

193219
@Override
194220
public boolean onTouchEvent(MotionEvent event) {
221+
if (event.getAction() == MotionEvent.ACTION_DOWN) {
222+
mRippleRadius = 0.0f;
223+
mTouchX = event.getX();
224+
mTouchY = event.getY();
225+
splashRipple();
226+
}
227+
195228
if (isViewClickable && mOnTagClickListener != null){
196229
int x = (int) event.getX();
197230
int y = (int) event.getY();
@@ -227,6 +260,42 @@ public boolean onTouchEvent(MotionEvent event) {
227260
return super.onTouchEvent(event);
228261
}
229262

263+
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
264+
private void drawRipple(Canvas canvas){
265+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && canvas != null){
266+
canvas.save();
267+
mPath.reset();
268+
269+
canvas.clipPath(mPath);
270+
mPath.addRoundRect(mRectF, mBorderRadius, mBorderRadius, Path.Direction.CCW);
271+
272+
canvas.clipPath(mPath, Region.Op.REPLACE);
273+
canvas.drawCircle(mTouchX, mTouchY, mRippleRadius, mRipplePaint);
274+
canvas.restore();
275+
}
276+
}
277+
278+
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
279+
private void splashRipple(){
280+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && mTouchX > 0 && mTouchY > 0){
281+
mRipplePaint.setColor(mRippleColor);
282+
mRipplePaint.setAlpha(mRippleAlpha);
283+
final float maxDis = Math.max(Math.max(Math.max(mTouchX, mTouchY),
284+
Math.abs(getMeasuredWidth() - mTouchX)), Math.abs(getMeasuredHeight() - mTouchY));
285+
286+
mRippleValueAnimator = ValueAnimator.ofFloat(0.0f, maxDis).setDuration(mRippleDuration);
287+
mRippleValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
288+
@Override
289+
public void onAnimationUpdate(ValueAnimator animation) {
290+
float animValue = (float) animation.getAnimatedValue();
291+
mRippleRadius = animValue >= maxDis ? 0 : animValue;
292+
postInvalidate();
293+
}
294+
});
295+
mRippleValueAnimator.start();
296+
}
297+
}
298+
230299
public String getText(){
231300
return mOriginText;
232301
}
@@ -299,6 +368,18 @@ public void setTypeface(Typeface typeface) {
299368
onDealText();
300369
}
301370

371+
public void setRippleAlpha(int mRippleAlpha) {
372+
this.mRippleAlpha = mRippleAlpha;
373+
}
374+
375+
public void setRippleColor(int mRippleColor) {
376+
this.mRippleColor = mRippleColor;
377+
}
378+
379+
public void setRippleDuration(int mRippleDuration) {
380+
this.mRippleDuration = mRippleDuration;
381+
}
382+
302383
public void setBdDistance(float bdDistance) {
303384
this.bdDistance = bdDistance;
304385
}

androidtagview/src/main/res/values/attrs.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,9 @@
3838
<enum name="ltr" value="3" />
3939
<enum name="rtl" value="4" />
4040
</attr>
41+
42+
<attr name="tag_ripple_color" format="color" />
43+
<attr name="tag_ripple_alpha" format="integer" />
44+
<attr name="tag_ripple_duration" format="integer" />
4145
</declare-styleable>
4246
</resources>

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:1.5.0'
9-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
8+
classpath 'com.android.tools.build:gradle:2.2.1'
9+
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
1010
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
1111

1212
// NOTE: Do not place your application dependencies here; they belong
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Oct 21 11:34:03 PDT 2015
2-
distributionBase=GRADLE_USER_HOME
3-
distributionPath=wrapper/dists
4-
zipStoreBase=GRADLE_USER_HOME
5-
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
1+
#Sun Oct 30 18:08:28 CST 2016
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

sample/src/main/res/layout/content_main.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
app:container_gravity="center"
112112
app:horizontal_interval="10dp"
113113
app:tag_clickable="true"
114+
app:tag_ripple_alpha="47"
115+
app:tag_ripple_color="#000000"
116+
app:tag_ripple_duration="2000"
114117
app:tag_theme="pure_teal"
115118
app:vertical_interval="10dp" />
116119

0 commit comments

Comments
 (0)