From e044bc67973a21d6eeeb6653ed297a08d6cdb51e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Nicol=C3=A1s=20Pina?= Date: Thu, 24 Nov 2016 17:27:53 +0100 Subject: [PATCH 01/53] Show a sample tag while in edit mode. --- androidtagview/build.gradle | 8 ++++---- .../co/lujun/androidtagview/TagContainerLayout.java | 4 ++++ build.gradle | 2 +- sample/build.gradle | 10 +++++----- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index a80ff86..cb36870 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 23 - buildToolsVersion "22.0.1" + compileSdkVersion 25 + buildToolsVersion "25.0.0" defaultConfig { minSdkVersion 9 - targetSdkVersion 23 + targetSdkVersion 25 versionCode 105 versionName "1.0.5" } @@ -21,6 +21,6 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:23.1.1' + compile 'com.android.support:appcompat-v7:25.0.1' } apply from: 'https://raw.githubusercontent.com/whilu/AndroidPublishLibrary/master/project/library/bintray_publish.gradle' \ No newline at end of file diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index 3ce6199..b40c011 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -223,6 +223,10 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr){ setTagMaxLength(mTagMaxLength); setTagHorizontalPadding(mTagHorizontalPadding); setTagVerticalPadding(mTagVerticalPadding); + + if (isInEditMode()) { + addTag("sample tag"); + } } @Override diff --git a/build.gradle b/build.gradle index 66aa056..45efda8 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.1' + classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' diff --git a/sample/build.gradle b/sample/build.gradle index 85106e2..9435b08 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 - buildToolsVersion "22.0.1" + compileSdkVersion 25 + buildToolsVersion "25.0.0" defaultConfig { applicationId "co.lujun.sample" minSdkVersion 9 - targetSdkVersion 23 + targetSdkVersion 25 versionCode 1 versionName "1.0" } @@ -23,6 +23,6 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':androidtagview') testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:23.1.1' - compile 'com.android.support:design:23.1.1' + compile 'com.android.support:appcompat-v7:25.0.1' + compile 'com.android.support:design:25.0.1' } From f8ce5884684ed4d72623b60617b8da1daba65cb0 Mon Sep 17 00:00:00 2001 From: whilu Date: Wed, 7 Dec 2016 22:15:50 +0800 Subject: [PATCH 02/53] Fix: issue #35 --- .../androidtagview/TagContainerLayout.java | 13 +++-------- .../java/co/lujun/androidtagview/TagView.java | 23 +++++++++++++------ .../java/co/lujun/androidtagview/Utils.java | 21 +++++++++++++++++ 3 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 androidtagview/src/main/java/co/lujun/androidtagview/Utils.java diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index b40c011..170d894 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -18,6 +18,9 @@ import java.util.Arrays; import java.util.List; +import static co.lujun.androidtagview.Utils.dp2px; +import static co.lujun.androidtagview.Utils.sp2px; + /** * Author: lujun(http://blog.lujun.co) * Date: 2015-12-30 17:14 @@ -1185,14 +1188,4 @@ public float getCrossLineWidth() { public void setCrossLineWidth(float mCrossLineWidth) { this.mCrossLineWidth = mCrossLineWidth; } - - public float dp2px(Context context, float dp) { - final float scale = context.getResources().getDisplayMetrics().density; - return dp * scale + 0.5f; - } - - public float sp2px(Context context, float sp) { - final float scale = context.getResources().getDisplayMetrics().scaledDensity; - return sp * scale; - } } diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index d501f9e..e41353d 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -15,6 +15,9 @@ import android.view.MotionEvent; import android.view.View; +import static co.lujun.androidtagview.Utils.dp2px; +import static co.lujun.androidtagview.Utils.sp2px; + /** * Author: lujun(http://blog.lujun.co) * Date: 2015-12-31 11:47 @@ -54,10 +57,10 @@ public class TagView extends View { /** OnTagClickListener for click action*/ private OnTagClickListener mOnTagClickListener; - /** Move slop(default 20px)*/ - private int mMoveSlop = 20; + /** Move slop(default 5dp)*/ + private int mMoveSlop = 5; - /** Scroll slop threshold*/ + /** Scroll slop threshold 4dp*/ private int mSlopThreshold = 4; /** How long trigger long click callback(default 500ms)*/ @@ -123,16 +126,18 @@ public void run() { public TagView(Context context, String text){ super(context); - init(text); + init(context, text); } - private void init(String text){ + private void init(Context context, String text){ mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mRipplePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mRipplePaint.setStyle(Paint.Style.FILL); mRectF = new RectF(); mPath = new Path(); mOriginText = text == null ? "" : text; + mMoveSlop = (int) dp2px(context, mMoveSlop); + mSlopThreshold = (int) dp2px(context, mSlopThreshold); } private void onDealText(){ @@ -217,7 +222,9 @@ public boolean dispatchTouchEvent(MotionEvent event) { int action = event.getAction(); switch (action){ case MotionEvent.ACTION_DOWN: - getParent().requestDisallowInterceptTouchEvent(true); + if (getParent() != null) { + getParent().requestDisallowInterceptTouchEvent(true); + } mLastY = y; mLastX = x; break; @@ -225,7 +232,9 @@ public boolean dispatchTouchEvent(MotionEvent event) { case MotionEvent.ACTION_MOVE: if (Math.abs(mLastY - y) > mSlopThreshold || Math.abs(mLastX - x) > mSlopThreshold){ - getParent().requestDisallowInterceptTouchEvent(false); + if (getParent() != null) { + getParent().requestDisallowInterceptTouchEvent(false); + } isMoved = true; return false; } diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java b/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java new file mode 100644 index 0000000..c059416 --- /dev/null +++ b/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java @@ -0,0 +1,21 @@ +package co.lujun.androidtagview; + +import android.content.Context; + +/** + * Author: lujun(http://blog.lujun.co) + * Date: 2016-12-7 21:53 + */ + +public class Utils { + + public static float dp2px(Context context, float dp) { + final float scale = context.getResources().getDisplayMetrics().density; + return dp * scale + 0.5f; + } + + public static float sp2px(Context context, float sp) { + final float scale = context.getResources().getDisplayMetrics().scaledDensity; + return sp * scale; + } +} From f3e573b1d7a91a44fb0fd53d2076ba81433a6b50 Mon Sep 17 00:00:00 2001 From: whilu Date: Wed, 21 Dec 2016 22:29:28 +0800 Subject: [PATCH 03/53] Enhancement: #37 --- README.md | 6 +++--- .../androidtagview/TagContainerLayout.java | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index cf4e1ee..1c58aa2 100644 --- a/README.md +++ b/README.md @@ -64,10 +64,10 @@ Now, you have successfully created some TagViews. The following will show some m | container_max_lines | integer | The max lines for TagContainerLayout(default 0, auto increase) | tag_border_width | dimension | TagView Border width(default 0.5dp) | tag_corner_radius | dimension | TagView Border radius(default 15.0dp) -| tag_horizontal_padding | dimension | Horizontal padding for TagView, include left and right padding(left and right padding are equal, default 20px) -| tag_vertical_padding | dimension | Vertical padding for TagView, include top and bottom padding(top and bottom padding are equal, default 17px) +| tag_horizontal_padding | dimension | Horizontal padding for TagView, include left and right padding(left and right padding are equal, default 10dp) +| tag_vertical_padding | dimension | Vertical padding for TagView, include top and bottom padding(top and bottom padding are equal, default 8dp) | tag_text_size | dimension | TagView Text size(default 14sp) -| tag_bd_distance | dimension | The distance between baseline and descent(default 5.5px) +| tag_bd_distance | dimension | The distance between baseline and descent(default 2.75dp) | tag_text_color | color | TagView text color(default #FF666666) | tag_border_color | color | TagView border color(default #88F44336) | tag_background_color | color | TagView background color(default #33F44336) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index 170d894..9cc9589 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -72,11 +72,11 @@ public class TagContainerLayout extends ViewGroup { /** Text direction(support:TEXT_DIRECTION_RTL & TEXT_DIRECTION_LTR, default TEXT_DIRECTION_LTR)*/ private int mTagTextDirection = View.TEXT_DIRECTION_LTR; - /** Horizontal padding for TagView, include left & right padding(left & right padding are equal, default 20px)*/ - private int mTagHorizontalPadding = 20; + /** Horizontal padding for TagView, include left & right padding(left & right padding are equal, default 10dp)*/ + private int mTagHorizontalPadding = 10; - /** Vertical padding for TagView, include top & bottom padding(top & bottom padding are equal, default 17px)*/ - private int mTagVerticalPadding = 17; + /** Vertical padding for TagView, include top & bottom padding(top & bottom padding are equal, default 8dp)*/ + private int mTagVerticalPadding = 8; /** TagView border color(default #88F44336)*/ private int mTagBorderColor = Color.parseColor("#88F44336"); @@ -102,8 +102,8 @@ public class TagContainerLayout extends ViewGroup { /** TagView drag state(default STATE_IDLE)*/ private int mTagViewState = ViewDragHelper.STATE_IDLE; - /** The distance between baseline and descent(default 5.5px)*/ - private float mTagBdDistance = 5.5f; + /** The distance between baseline and descent(default 2.75dp)*/ + private float mTagBdDistance = 2.75f; /** OnTagClickListener for TagView*/ private TagView.OnTagClickListener mOnTagClickListener; @@ -176,7 +176,7 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr){ mBorderRadius = attributes.getDimension(R.styleable.AndroidTagView_container_border_radius, dp2px(context, mBorderRadius)); mTagBdDistance = attributes.getDimension(R.styleable.AndroidTagView_tag_bd_distance, - mTagBdDistance); + dp2px(context, mTagBdDistance)); mBorderColor = attributes.getColor(R.styleable.AndroidTagView_container_border_color, mBorderColor); mBackgroundColor = attributes.getColor(R.styleable.AndroidTagView_container_background_color, @@ -193,9 +193,10 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr){ mTagBorderRadius = attributes.getDimension( R.styleable.AndroidTagView_tag_corner_radius, dp2px(context, mTagBorderRadius)); mTagHorizontalPadding = (int) attributes.getDimension( - R.styleable.AndroidTagView_tag_horizontal_padding, mTagHorizontalPadding); + R.styleable.AndroidTagView_tag_horizontal_padding, + dp2px(context, mTagHorizontalPadding)); mTagVerticalPadding = (int) attributes.getDimension( - R.styleable.AndroidTagView_tag_vertical_padding, mTagVerticalPadding); + R.styleable.AndroidTagView_tag_vertical_padding, dp2px(context, mTagVerticalPadding)); mTagTextSize = attributes.getDimension(R.styleable.AndroidTagView_tag_text_size, sp2px(context, mTagTextSize)); mTagBorderColor = attributes.getColor(R.styleable.AndroidTagView_tag_border_color, From 84cca768c7667974bc9bd3075dcb05c518bd2d36 Mon Sep 17 00:00:00 2001 From: whilu Date: Tue, 14 Feb 2017 22:18:43 +0800 Subject: [PATCH 04/53] Release v1.0.6 --- README.md | 5 ++++- androidtagview/build.gradle | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1c58aa2..35edc53 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add below dependency in your **build.gradle** file. ```groovy dependencies { - compile 'co.lujun:androidtagview:1.0.5' + compile 'co.lujun:androidtagview:1.0.6' } ``` @@ -192,6 +192,9 @@ mTagContainerLayout.removeAllTags(); ``` ## Change logs +###1.0.6(2017-2-14) +- fix bugs + ###1.0.5(2016-11-9) - Add cross view for TagView diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index cb36870..a8a54e7 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 9 targetSdkVersion 25 - versionCode 105 - versionName "1.0.5" + versionCode 106 + versionName "1.0.6" } buildTypes { release { From 33482afad146fe65ca1c8d4a10b415105411e210 Mon Sep 17 00:00:00 2001 From: Mohamed Zakaria Date: Sun, 5 Mar 2017 15:32:55 +0200 Subject: [PATCH 05/53] [Fix] fixing arabic splitted characters --- .../java/co/lujun/androidtagview/TagView.java | 178 +++++++++++------- 1 file changed, 105 insertions(+), 73 deletions(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index e41353d..8421afc 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -16,7 +16,6 @@ import android.view.View; import static co.lujun.androidtagview.Utils.dp2px; -import static co.lujun.androidtagview.Utils.sp2px; /** * Author: lujun(http://blog.lujun.co) @@ -24,52 +23,84 @@ */ public class TagView extends View { - /** Border width*/ + /** + * Border width + */ private float mBorderWidth; - /** Border radius*/ + /** + * Border radius + */ private float mBorderRadius; - /** Text size*/ + /** + * Text size + */ private float mTextSize; - /** Horizontal padding for this view, include left & right padding(left & right padding are equal*/ + /** + * Horizontal padding for this view, include left & right padding(left & right padding are equal + */ private int mHorizontalPadding; - /** Vertical padding for this view, include top & bottom padding(top & bottom padding are equal)*/ + /** + * Vertical padding for this view, include top & bottom padding(top & bottom padding are equal) + */ private int mVerticalPadding; - /** TagView border color*/ + /** + * TagView border color + */ private int mBorderColor; - /** TagView background color*/ + /** + * TagView background color + */ private int mBackgroundColor; - /** TagView text color*/ + /** + * TagView text color + */ private int mTextColor; - /** Whether this view clickable*/ + /** + * Whether this view clickable + */ private boolean isViewClickable; - /** The max length for this tag view*/ + /** + * The max length for this tag view + */ private int mTagMaxLength; - /** OnTagClickListener for click action*/ + /** + * OnTagClickListener for click action + */ private OnTagClickListener mOnTagClickListener; - /** Move slop(default 5dp)*/ + /** + * Move slop(default 5dp) + */ private int mMoveSlop = 5; - /** Scroll slop threshold 4dp*/ + /** + * Scroll slop threshold 4dp + */ private int mSlopThreshold = 4; - /** How long trigger long click callback(default 500ms)*/ + /** + * How long trigger long click callback(default 500ms) + */ private int mLongPressTime = 500; - /** Text direction(support:TEXT_DIRECTION_RTL & TEXT_DIRECTION_LTR, default TEXT_DIRECTION_LTR)*/ + /** + * Text direction(support:TEXT_DIRECTION_RTL & TEXT_DIRECTION_LTR, default TEXT_DIRECTION_LTR) + */ private int mTextDirection = View.TEXT_DIRECTION_LTR; - /** The distance between baseline and descent*/ + /** + * The distance between baseline and descent + */ private float bdDistance; private Paint mPaint, mRipplePaint; @@ -83,10 +114,12 @@ public class TagView extends View { private int mLastX, mLastY; private float fontH, fontW; - + private float mTouchX, mTouchY; - /** The ripple effect duration(default 1000ms)*/ + /** + * The ripple effect duration(default 1000ms) + */ private int mRippleDuration = 1000; private float mRippleRadius; @@ -114,9 +147,9 @@ public class TagView extends View { private Runnable mLongClickHandle = new Runnable() { @Override public void run() { - if (!isMoved && !isUp){ - int state = ((TagContainerLayout)getParent()).getTagViewState(); - if (state == ViewDragHelper.STATE_IDLE){ + if (!isMoved && !isUp) { + int state = ((TagContainerLayout) getParent()).getTagViewState(); + if (state == ViewDragHelper.STATE_IDLE) { isExecLongClick = true; mOnTagClickListener.onTagLongClick((int) getTag(), getText()); } @@ -124,12 +157,12 @@ public void run() { } }; - public TagView(Context context, String text){ + public TagView(Context context, String text) { super(context); init(context, text); } - private void init(Context context, String text){ + private void init(Context context, String text) { mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mRipplePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mRipplePaint.setStyle(Paint.Style.FILL); @@ -140,24 +173,24 @@ private void init(Context context, String text){ mSlopThreshold = (int) dp2px(context, mSlopThreshold); } - private void onDealText(){ - if(!TextUtils.isEmpty(mOriginText)) { + private void onDealText() { + if (!TextUtils.isEmpty(mOriginText)) { mAbstractText = mOriginText.length() <= mTagMaxLength ? mOriginText : mOriginText.substring(0, mTagMaxLength - 3) + "..."; - }else { + } else { mAbstractText = ""; } mPaint.setTypeface(mTypeface); mPaint.setTextSize(mTextSize); final Paint.FontMetrics fontMetrics = mPaint.getFontMetrics(); fontH = fontMetrics.descent - fontMetrics.ascent; - if (mTextDirection == View.TEXT_DIRECTION_RTL){ + if (mTextDirection == View.TEXT_DIRECTION_RTL) { fontW = 0; for (char c : mAbstractText.toCharArray()) { String sc = String.valueOf(c); fontW += mPaint.measureText(sc); } - }else { + } else { fontW = mPaint.measureText(mAbstractText); } } @@ -197,14 +230,11 @@ protected void onDraw(Canvas canvas) { mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(mTextColor); - if (mTextDirection == View.TEXT_DIRECTION_RTL){ - float tmpX = (isEnableCross() ? getWidth() + getHeight() : getWidth()) / 2 + fontW / 2; - for (char c : mAbstractText.toCharArray()) { - String sc = String.valueOf(c); - tmpX -= mPaint.measureText(sc); - canvas.drawText(sc, tmpX, getHeight() / 2 + fontH / 2 - bdDistance, mPaint); - } - }else { + if (mTextDirection == View.TEXT_DIRECTION_RTL) { + canvas.drawText(mAbstractText, + (isEnableCross() ? getWidth() + fontW : getWidth()) / 2 - fontW / 2, + getHeight() / 2 + fontH / 2 - bdDistance, mPaint); + } else { canvas.drawText(mAbstractText, (isEnableCross() ? getWidth() - getHeight() : getWidth()) / 2 - fontW / 2, getHeight() / 2 + fontH / 2 - bdDistance, mPaint); @@ -216,11 +246,11 @@ protected void onDraw(Canvas canvas) { @Override public boolean dispatchTouchEvent(MotionEvent event) { - if (isViewClickable){ + if (isViewClickable) { int y = (int) event.getY(); int x = (int) event.getX(); int action = event.getAction(); - switch (action){ + switch (action) { case MotionEvent.ACTION_DOWN: if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); @@ -231,7 +261,7 @@ public boolean dispatchTouchEvent(MotionEvent event) { case MotionEvent.ACTION_MOVE: if (Math.abs(mLastY - y) > mSlopThreshold - || Math.abs(mLastX - x) > mSlopThreshold){ + || Math.abs(mLastX - x) > mSlopThreshold) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(false); } @@ -253,15 +283,15 @@ public boolean onTouchEvent(MotionEvent event) { mTouchY = event.getY(); splashRipple(); } - if (isEnableCross() && isClickCrossArea(event) && mOnTagClickListener != null){ + if (isEnableCross() && isClickCrossArea(event) && mOnTagClickListener != null) { if (action == MotionEvent.ACTION_DOWN) { mOnTagClickListener.onTagCrossClick((int) getTag()); } return true; - }else if (isViewClickable && mOnTagClickListener != null){ + } else if (isViewClickable && mOnTagClickListener != null) { int x = (int) event.getX(); int y = (int) event.getY(); - switch (action){ + switch (action) { case MotionEvent.ACTION_DOWN: mLastY = y; mLastX = x; @@ -272,10 +302,10 @@ public boolean onTouchEvent(MotionEvent event) { break; case MotionEvent.ACTION_MOVE: - if (isMoved){ + if (isMoved) { break; } - if (Math.abs(mLastX - x) > mMoveSlop || Math.abs(mLastY - y) > mMoveSlop){ + if (Math.abs(mLastX - x) > mMoveSlop || Math.abs(mLastY - y) > mMoveSlop) { isMoved = true; } break; @@ -292,34 +322,34 @@ public boolean onTouchEvent(MotionEvent event) { return super.onTouchEvent(event); } - private boolean isClickCrossArea(MotionEvent event){ - if (mTextDirection == View.TEXT_DIRECTION_RTL){ + private boolean isClickCrossArea(MotionEvent event) { + if (mTextDirection == View.TEXT_DIRECTION_RTL) { return event.getX() <= mCrossAreaWidth; } return event.getX() >= getWidth() - mCrossAreaWidth; } - private void drawCross(Canvas canvas){ - if (isEnableCross()){ + private void drawCross(Canvas canvas) { + if (isEnableCross()) { mCrossAreaPadding = mCrossAreaPadding > getHeight() / 2 ? getHeight() / 2 : mCrossAreaPadding; int ltX, ltY, rbX, rbY, lbX, lbY, rtX, rtY; - ltX = mTextDirection == View.TEXT_DIRECTION_RTL ? (int)(mCrossAreaPadding) : - (int)(getWidth() - getHeight() + mCrossAreaPadding); - ltY = mTextDirection == View.TEXT_DIRECTION_RTL ? (int)(mCrossAreaPadding) : - (int)(mCrossAreaPadding); - lbX = mTextDirection == View.TEXT_DIRECTION_RTL ? (int)(mCrossAreaPadding) : - (int)(getWidth() - getHeight() + mCrossAreaPadding); + ltX = mTextDirection == View.TEXT_DIRECTION_RTL ? (int) (mCrossAreaPadding) : + (int) (getWidth() - getHeight() + mCrossAreaPadding); + ltY = mTextDirection == View.TEXT_DIRECTION_RTL ? (int) (mCrossAreaPadding) : + (int) (mCrossAreaPadding); + lbX = mTextDirection == View.TEXT_DIRECTION_RTL ? (int) (mCrossAreaPadding) : + (int) (getWidth() - getHeight() + mCrossAreaPadding); lbY = mTextDirection == View.TEXT_DIRECTION_RTL ? - (int)(getHeight() - mCrossAreaPadding) : (int)(getHeight() - mCrossAreaPadding); + (int) (getHeight() - mCrossAreaPadding) : (int) (getHeight() - mCrossAreaPadding); rtX = mTextDirection == View.TEXT_DIRECTION_RTL ? - (int)(getHeight() - mCrossAreaPadding) : (int)(getWidth() - mCrossAreaPadding); - rtY = mTextDirection == View.TEXT_DIRECTION_RTL ? (int)(mCrossAreaPadding) : - (int)(mCrossAreaPadding); + (int) (getHeight() - mCrossAreaPadding) : (int) (getWidth() - mCrossAreaPadding); + rtY = mTextDirection == View.TEXT_DIRECTION_RTL ? (int) (mCrossAreaPadding) : + (int) (mCrossAreaPadding); rbX = mTextDirection == View.TEXT_DIRECTION_RTL ? - (int)(getHeight() - mCrossAreaPadding) : (int)(getWidth() - mCrossAreaPadding); + (int) (getHeight() - mCrossAreaPadding) : (int) (getWidth() - mCrossAreaPadding); rbY = mTextDirection == View.TEXT_DIRECTION_RTL ? - (int)(getHeight() - mCrossAreaPadding) : (int)(getHeight() - mCrossAreaPadding); + (int) (getHeight() - mCrossAreaPadding) : (int) (getHeight() - mCrossAreaPadding); mPaint.setStyle(Paint.Style.STROKE); mPaint.setColor(mCrossColor); @@ -330,8 +360,8 @@ private void drawCross(Canvas canvas){ } @TargetApi(Build.VERSION_CODES.HONEYCOMB) - private void drawRipple(Canvas canvas){ - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && canvas != null){ + private void drawRipple(Canvas canvas) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && canvas != null) { canvas.save(); mPath.reset(); @@ -345,8 +375,8 @@ private void drawRipple(Canvas canvas){ } @TargetApi(Build.VERSION_CODES.HONEYCOMB) - private void splashRipple(){ - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && mTouchX > 0 && mTouchY > 0){ + private void splashRipple() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && mTouchX > 0 && mTouchY > 0) { mRipplePaint.setColor(mRippleColor); mRipplePaint.setAlpha(mRippleAlpha); final float maxDis = Math.max(Math.max(Math.max(mTouchX, mTouchY), @@ -365,32 +395,32 @@ public void onAnimationUpdate(ValueAnimator animation) { } } - public String getText(){ + public String getText() { return mOriginText; } - public boolean getIsViewClickable(){ + public boolean getIsViewClickable() { return isViewClickable; } - public void setTagMaxLength(int maxLength){ + public void setTagMaxLength(int maxLength) { this.mTagMaxLength = maxLength; onDealText(); } - public void setOnTagClickListener(OnTagClickListener listener){ + public void setOnTagClickListener(OnTagClickListener listener) { this.mOnTagClickListener = listener; } - public void setTagBackgroundColor(int color){ + public void setTagBackgroundColor(int color) { this.mBackgroundColor = color; } - public void setTagBorderColor(int color){ + public void setTagBorderColor(int color) { this.mBorderColor = color; } - public void setTagTextColor(int color){ + public void setTagTextColor(int color) { this.mTextColor = color; } @@ -419,9 +449,11 @@ public void setIsViewClickable(boolean clickable) { this.isViewClickable = clickable; } - public interface OnTagClickListener{ + public interface OnTagClickListener { void onTagClick(int position, String text); + void onTagLongClick(int position, String text); + void onTagCrossClick(int position); } From b4079b372046f3b9c3508551759def1fe9894a79 Mon Sep 17 00:00:00 2001 From: Mohamed Zakaria Date: Sun, 5 Mar 2017 15:34:35 +0200 Subject: [PATCH 06/53] [Fix] fixing file style to prevent making many changes --- .../java/co/lujun/androidtagview/TagView.java | 162 +++++++----------- 1 file changed, 63 insertions(+), 99 deletions(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index 8421afc..1ef26cf 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -23,84 +23,52 @@ */ public class TagView extends View { - /** - * Border width - */ + /** Border width*/ private float mBorderWidth; - /** - * Border radius - */ + /** Border radius*/ private float mBorderRadius; - /** - * Text size - */ + /** Text size*/ private float mTextSize; - /** - * Horizontal padding for this view, include left & right padding(left & right padding are equal - */ + /** Horizontal padding for this view, include left & right padding(left & right padding are equal*/ private int mHorizontalPadding; - /** - * Vertical padding for this view, include top & bottom padding(top & bottom padding are equal) - */ + /** Vertical padding for this view, include top & bottom padding(top & bottom padding are equal)*/ private int mVerticalPadding; - /** - * TagView border color - */ + /** TagView border color*/ private int mBorderColor; - /** - * TagView background color - */ + /** TagView background color*/ private int mBackgroundColor; - /** - * TagView text color - */ + /** TagView text color*/ private int mTextColor; - /** - * Whether this view clickable - */ + /** Whether this view clickable*/ private boolean isViewClickable; - /** - * The max length for this tag view - */ + /** The max length for this tag view*/ private int mTagMaxLength; - /** - * OnTagClickListener for click action - */ + /** OnTagClickListener for click action*/ private OnTagClickListener mOnTagClickListener; - /** - * Move slop(default 5dp) - */ + /** Move slop(default 5dp)*/ private int mMoveSlop = 5; - /** - * Scroll slop threshold 4dp - */ + /** Scroll slop threshold 4dp*/ private int mSlopThreshold = 4; - /** - * How long trigger long click callback(default 500ms) - */ + /** How long trigger long click callback(default 500ms)*/ private int mLongPressTime = 500; - /** - * Text direction(support:TEXT_DIRECTION_RTL & TEXT_DIRECTION_LTR, default TEXT_DIRECTION_LTR) - */ + /** Text direction(support:TEXT_DIRECTION_RTL & TEXT_DIRECTION_LTR, default TEXT_DIRECTION_LTR)*/ private int mTextDirection = View.TEXT_DIRECTION_LTR; - /** - * The distance between baseline and descent - */ + /** The distance between baseline and descent*/ private float bdDistance; private Paint mPaint, mRipplePaint; @@ -117,9 +85,7 @@ public class TagView extends View { private float mTouchX, mTouchY; - /** - * The ripple effect duration(default 1000ms) - */ + /** The ripple effect duration(default 1000ms)*/ private int mRippleDuration = 1000; private float mRippleRadius; @@ -147,9 +113,9 @@ public class TagView extends View { private Runnable mLongClickHandle = new Runnable() { @Override public void run() { - if (!isMoved && !isUp) { - int state = ((TagContainerLayout) getParent()).getTagViewState(); - if (state == ViewDragHelper.STATE_IDLE) { + if (!isMoved && !isUp){ + int state = ((TagContainerLayout)getParent()).getTagViewState(); + if (state == ViewDragHelper.STATE_IDLE){ isExecLongClick = true; mOnTagClickListener.onTagLongClick((int) getTag(), getText()); } @@ -157,12 +123,12 @@ public void run() { } }; - public TagView(Context context, String text) { + public TagView(Context context, String text){ super(context); init(context, text); } - private void init(Context context, String text) { + private void init(Context context, String text){ mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mRipplePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mRipplePaint.setStyle(Paint.Style.FILL); @@ -173,24 +139,24 @@ private void init(Context context, String text) { mSlopThreshold = (int) dp2px(context, mSlopThreshold); } - private void onDealText() { - if (!TextUtils.isEmpty(mOriginText)) { + private void onDealText(){ + if(!TextUtils.isEmpty(mOriginText)) { mAbstractText = mOriginText.length() <= mTagMaxLength ? mOriginText : mOriginText.substring(0, mTagMaxLength - 3) + "..."; - } else { + }else { mAbstractText = ""; } mPaint.setTypeface(mTypeface); mPaint.setTextSize(mTextSize); final Paint.FontMetrics fontMetrics = mPaint.getFontMetrics(); fontH = fontMetrics.descent - fontMetrics.ascent; - if (mTextDirection == View.TEXT_DIRECTION_RTL) { + if (mTextDirection == View.TEXT_DIRECTION_RTL){ fontW = 0; for (char c : mAbstractText.toCharArray()) { String sc = String.valueOf(c); fontW += mPaint.measureText(sc); } - } else { + }else { fontW = mPaint.measureText(mAbstractText); } } @@ -246,11 +212,11 @@ protected void onDraw(Canvas canvas) { @Override public boolean dispatchTouchEvent(MotionEvent event) { - if (isViewClickable) { + if (isViewClickable){ int y = (int) event.getY(); int x = (int) event.getX(); int action = event.getAction(); - switch (action) { + switch (action){ case MotionEvent.ACTION_DOWN: if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); @@ -261,7 +227,7 @@ public boolean dispatchTouchEvent(MotionEvent event) { case MotionEvent.ACTION_MOVE: if (Math.abs(mLastY - y) > mSlopThreshold - || Math.abs(mLastX - x) > mSlopThreshold) { + || Math.abs(mLastX - x) > mSlopThreshold){ if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(false); } @@ -283,15 +249,15 @@ public boolean onTouchEvent(MotionEvent event) { mTouchY = event.getY(); splashRipple(); } - if (isEnableCross() && isClickCrossArea(event) && mOnTagClickListener != null) { + if (isEnableCross() && isClickCrossArea(event) && mOnTagClickListener != null){ if (action == MotionEvent.ACTION_DOWN) { mOnTagClickListener.onTagCrossClick((int) getTag()); } return true; - } else if (isViewClickable && mOnTagClickListener != null) { + }else if (isViewClickable && mOnTagClickListener != null){ int x = (int) event.getX(); int y = (int) event.getY(); - switch (action) { + switch (action){ case MotionEvent.ACTION_DOWN: mLastY = y; mLastX = x; @@ -302,10 +268,10 @@ public boolean onTouchEvent(MotionEvent event) { break; case MotionEvent.ACTION_MOVE: - if (isMoved) { + if (isMoved){ break; } - if (Math.abs(mLastX - x) > mMoveSlop || Math.abs(mLastY - y) > mMoveSlop) { + if (Math.abs(mLastX - x) > mMoveSlop || Math.abs(mLastY - y) > mMoveSlop){ isMoved = true; } break; @@ -322,34 +288,34 @@ public boolean onTouchEvent(MotionEvent event) { return super.onTouchEvent(event); } - private boolean isClickCrossArea(MotionEvent event) { - if (mTextDirection == View.TEXT_DIRECTION_RTL) { + private boolean isClickCrossArea(MotionEvent event){ + if (mTextDirection == View.TEXT_DIRECTION_RTL){ return event.getX() <= mCrossAreaWidth; } return event.getX() >= getWidth() - mCrossAreaWidth; } - private void drawCross(Canvas canvas) { - if (isEnableCross()) { + private void drawCross(Canvas canvas){ + if (isEnableCross()){ mCrossAreaPadding = mCrossAreaPadding > getHeight() / 2 ? getHeight() / 2 : mCrossAreaPadding; int ltX, ltY, rbX, rbY, lbX, lbY, rtX, rtY; - ltX = mTextDirection == View.TEXT_DIRECTION_RTL ? (int) (mCrossAreaPadding) : - (int) (getWidth() - getHeight() + mCrossAreaPadding); - ltY = mTextDirection == View.TEXT_DIRECTION_RTL ? (int) (mCrossAreaPadding) : - (int) (mCrossAreaPadding); - lbX = mTextDirection == View.TEXT_DIRECTION_RTL ? (int) (mCrossAreaPadding) : - (int) (getWidth() - getHeight() + mCrossAreaPadding); + ltX = mTextDirection == View.TEXT_DIRECTION_RTL ? (int)(mCrossAreaPadding) : + (int)(getWidth() - getHeight() + mCrossAreaPadding); + ltY = mTextDirection == View.TEXT_DIRECTION_RTL ? (int)(mCrossAreaPadding) : + (int)(mCrossAreaPadding); + lbX = mTextDirection == View.TEXT_DIRECTION_RTL ? (int)(mCrossAreaPadding) : + (int)(getWidth() - getHeight() + mCrossAreaPadding); lbY = mTextDirection == View.TEXT_DIRECTION_RTL ? - (int) (getHeight() - mCrossAreaPadding) : (int) (getHeight() - mCrossAreaPadding); + (int)(getHeight() - mCrossAreaPadding) : (int)(getHeight() - mCrossAreaPadding); rtX = mTextDirection == View.TEXT_DIRECTION_RTL ? - (int) (getHeight() - mCrossAreaPadding) : (int) (getWidth() - mCrossAreaPadding); - rtY = mTextDirection == View.TEXT_DIRECTION_RTL ? (int) (mCrossAreaPadding) : - (int) (mCrossAreaPadding); + (int)(getHeight() - mCrossAreaPadding) : (int)(getWidth() - mCrossAreaPadding); + rtY = mTextDirection == View.TEXT_DIRECTION_RTL ? (int)(mCrossAreaPadding) : + (int)(mCrossAreaPadding); rbX = mTextDirection == View.TEXT_DIRECTION_RTL ? - (int) (getHeight() - mCrossAreaPadding) : (int) (getWidth() - mCrossAreaPadding); + (int)(getHeight() - mCrossAreaPadding) : (int)(getWidth() - mCrossAreaPadding); rbY = mTextDirection == View.TEXT_DIRECTION_RTL ? - (int) (getHeight() - mCrossAreaPadding) : (int) (getHeight() - mCrossAreaPadding); + (int)(getHeight() - mCrossAreaPadding) : (int)(getHeight() - mCrossAreaPadding); mPaint.setStyle(Paint.Style.STROKE); mPaint.setColor(mCrossColor); @@ -360,8 +326,8 @@ private void drawCross(Canvas canvas) { } @TargetApi(Build.VERSION_CODES.HONEYCOMB) - private void drawRipple(Canvas canvas) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && canvas != null) { + private void drawRipple(Canvas canvas){ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && canvas != null){ canvas.save(); mPath.reset(); @@ -375,8 +341,8 @@ private void drawRipple(Canvas canvas) { } @TargetApi(Build.VERSION_CODES.HONEYCOMB) - private void splashRipple() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && mTouchX > 0 && mTouchY > 0) { + private void splashRipple(){ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && mTouchX > 0 && mTouchY > 0){ mRipplePaint.setColor(mRippleColor); mRipplePaint.setAlpha(mRippleAlpha); final float maxDis = Math.max(Math.max(Math.max(mTouchX, mTouchY), @@ -395,32 +361,32 @@ public void onAnimationUpdate(ValueAnimator animation) { } } - public String getText() { + public String getText(){ return mOriginText; } - public boolean getIsViewClickable() { + public boolean getIsViewClickable(){ return isViewClickable; } - public void setTagMaxLength(int maxLength) { + public void setTagMaxLength(int maxLength){ this.mTagMaxLength = maxLength; onDealText(); } - public void setOnTagClickListener(OnTagClickListener listener) { + public void setOnTagClickListener(OnTagClickListener listener){ this.mOnTagClickListener = listener; } - public void setTagBackgroundColor(int color) { + public void setTagBackgroundColor(int color){ this.mBackgroundColor = color; } - public void setTagBorderColor(int color) { + public void setTagBorderColor(int color){ this.mBorderColor = color; } - public void setTagTextColor(int color) { + public void setTagTextColor(int color){ this.mTextColor = color; } @@ -449,11 +415,9 @@ public void setIsViewClickable(boolean clickable) { this.isViewClickable = clickable; } - public interface OnTagClickListener { + public interface OnTagClickListener{ void onTagClick(int position, String text); - void onTagLongClick(int position, String text); - void onTagCrossClick(int position); } From 4dd343dfed963f19adf26aaca197e1f933018e18 Mon Sep 17 00:00:00 2001 From: whilu Date: Sun, 5 Mar 2017 23:54:23 +0800 Subject: [PATCH 07/53] Add: Whether to support 'letters show with RTL(eg: Android -> diordnA)' style(default false) --- README.md | 1 + .../androidtagview/TagContainerLayout.java | 22 +++++++++++++++ .../java/co/lujun/androidtagview/TagView.java | 27 ++++++++++++++++--- androidtagview/src/main/res/values/attrs.xml | 1 + 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 35edc53..0c4b02a 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ Now, you have successfully created some TagViews. The following will show some m | tag_cross_color | color | The cross icon color(default Color.BLACK) | tag_cross_line_width | dimension | The cross line width(default 1dp) | tag_cross_area_padding | dimension | The padding of the cross area(default 10dp) +| tag_support_letters_rlt | boolean | Whether to support 'letters show with RTL(eg: Android -> diordnA)' style(default false) **You can set these attributes in layout file, or use setters(each attribute has get and set method) to set them.** diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index 9cc9589..c598f09 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -108,6 +108,9 @@ public class TagContainerLayout extends ViewGroup { /** OnTagClickListener for TagView*/ private TagView.OnTagClickListener mOnTagClickListener; + /** Whether to support 'letters show with RTL(eg: Android -> diordnA)' style(default false)*/ + private boolean mTagSupportLettersRTL = false; + private Paint mPaint; private RectF mRectF; @@ -217,6 +220,8 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr){ mCrossColor = attributes.getColor(R.styleable.AndroidTagView_tag_cross_color, mCrossColor); mCrossLineWidth = attributes.getDimension(R.styleable.AndroidTagView_tag_cross_line_width, dp2px(context, mCrossLineWidth)); + mTagSupportLettersRTL = attributes.getBoolean(R.styleable.AndroidTagView_tag_support_letters_rlt, + mTagSupportLettersRTL); attributes.recycle(); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); @@ -450,6 +455,7 @@ private void initTagView(TagView tagView){ tagView.setCrossAreaPadding(mCrossAreaPadding); tagView.setCrossColor(mCrossColor); tagView.setCrossLineWidth(mCrossLineWidth); + tagView.setTagSupportLettersRTL(mTagSupportLettersRTL); } private void invalidateTags(){ @@ -1189,4 +1195,20 @@ public float getCrossLineWidth() { public void setCrossLineWidth(float mCrossLineWidth) { this.mCrossLineWidth = mCrossLineWidth; } + + /** + * Get the 'letters show with RTL(like: Android -> diordnA)' style if it's enabled + * @return + */ + public boolean isTagSupportLettersRTL() { + return mTagSupportLettersRTL; + } + + /** + * Set whether the 'support letters show with RTL(like: Android -> diordnA)' style is enabled + * @param mTagSupportLettersRTL + */ + public void setTagSupportLettersRTL(boolean mTagSupportLettersRTL) { + this.mTagSupportLettersRTL = mTagSupportLettersRTL; + } } diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index 1ef26cf..6578d27 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -71,6 +71,9 @@ public class TagView extends View { /** The distance between baseline and descent*/ private float bdDistance; + /** Whether to support 'letters show with RTL(eg: Android -> diordnA)' style(default false)*/ + private boolean mTagSupportLettersRTL = false; + private Paint mPaint, mRipplePaint; private RectF mRectF; @@ -197,9 +200,19 @@ protected void onDraw(Canvas canvas) { mPaint.setColor(mTextColor); if (mTextDirection == View.TEXT_DIRECTION_RTL) { - canvas.drawText(mAbstractText, - (isEnableCross() ? getWidth() + fontW : getWidth()) / 2 - fontW / 2, - getHeight() / 2 + fontH / 2 - bdDistance, mPaint); + if (mTagSupportLettersRTL){ + float tmpX = (isEnableCross() ? getWidth() + getHeight() : getWidth()) / 2 + + fontW / 2; + for (char c : mAbstractText.toCharArray()) { + String sc = String.valueOf(c); + tmpX -= mPaint.measureText(sc); + canvas.drawText(sc, tmpX, getHeight() / 2 + fontH / 2 - bdDistance, mPaint); + } + }else { + canvas.drawText(mAbstractText, + (isEnableCross() ? getWidth() + fontW : getWidth()) / 2 - fontW / 2, + getHeight() / 2 + fontH / 2 - bdDistance, mPaint); + } } else { canvas.drawText(mAbstractText, (isEnableCross() ? getWidth() - getHeight() : getWidth()) / 2 - fontW / 2, @@ -489,4 +502,12 @@ public int getCrossColor() { public void setCrossColor(int mCrossColor) { this.mCrossColor = mCrossColor; } + + public boolean isTagSupportLettersRTL() { + return mTagSupportLettersRTL; + } + + public void setTagSupportLettersRTL(boolean mTagSupportLettersRTL) { + this.mTagSupportLettersRTL = mTagSupportLettersRTL; + } } diff --git a/androidtagview/src/main/res/values/attrs.xml b/androidtagview/src/main/res/values/attrs.xml index ef35176..dafc15e 100644 --- a/androidtagview/src/main/res/values/attrs.xml +++ b/androidtagview/src/main/res/values/attrs.xml @@ -48,5 +48,6 @@ + \ No newline at end of file From 92ba2615b3345b1a4ebdaa3272211ebaf74e6a5a Mon Sep 17 00:00:00 2001 From: whilu Date: Mon, 6 Mar 2017 00:03:08 +0800 Subject: [PATCH 08/53] Release v1.1.0 --- README.md | 26 +++++++++++++++----------- androidtagview/build.gradle | 4 ++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 0c4b02a..a961841 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add below dependency in your **build.gradle** file. ```groovy dependencies { - compile 'co.lujun:androidtagview:1.0.6' + compile 'co.lujun:androidtagview:1.1.0' } ``` @@ -193,29 +193,33 @@ mTagContainerLayout.removeAllTags(); ``` ## Change logs +###1.1.0(2017-3-5) +- Fixed issue [#1](https://github.com/whilu/AndroidTagView/issues/45) +- Support 'letters show with RTL(eg: Android -> diordnA)' style + ###1.0.6(2017-2-14) -- fix bugs +- Fix bugs ###1.0.5(2016-11-9) - Add cross view for TagView ###1.0.4(2016-10-30) - Support ripple effect(Call requires API level 11), like [Android CustomButton](https://github.com/whilu/AndroidSample/tree/master/CustomButton) -- fix bugs +- Fix bugs ###1.0.3(2016-4-3) -- add ```getTags()``` method to get the list for all tags -- fixed bugs in ListView/RecyclerView +- Add ```getTags()``` method to get the list for all tags +- Fixed bugs in ListView/RecyclerView ###1.0.2(2016-1-18) -- support [gravity](#gravity) for ```TagContainerLayout``` -- support set typeface +- Support [gravity](#gravity) for ```TagContainerLayout``` +- Support set typeface ###1.0.1(2016-1-14) -- support text [direction](#directions) -- add ```removeAllTags()``` method for remove all TagViews -- fixed issue [#1](https://github.com/whilu/AndroidTagView/issues/1) -- fixed other bugs +- Support text [direction](#directions) +- Add ```removeAllTags()``` method for remove all TagViews +- Fixed issue [#1](https://github.com/whilu/AndroidTagView/issues/1) +- Fixed other bugs ###1.0.0(2016-1-6) - First release diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index a8a54e7..96ac19e 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 9 targetSdkVersion 25 - versionCode 106 - versionName "1.0.6" + versionCode 110 + versionName "1.1.0" } buildTypes { release { From 91349ee7e7bd4ab63034e7a004239981c24e331b Mon Sep 17 00:00:00 2001 From: whilu Date: Mon, 6 Mar 2017 00:32:25 +0800 Subject: [PATCH 09/53] Fix: generate JavaDoc error --- .../java/co/lujun/androidtagview/TagContainerLayout.java | 6 +++--- .../src/main/java/co/lujun/androidtagview/TagView.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index c598f09..25678be 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -108,7 +108,7 @@ public class TagContainerLayout extends ViewGroup { /** OnTagClickListener for TagView*/ private TagView.OnTagClickListener mOnTagClickListener; - /** Whether to support 'letters show with RTL(eg: Android -> diordnA)' style(default false)*/ + /** Whether to support 'letters show with RTL(eg: Android to diordnA)' style(default false)*/ private boolean mTagSupportLettersRTL = false; private Paint mPaint; @@ -1197,7 +1197,7 @@ public void setCrossLineWidth(float mCrossLineWidth) { } /** - * Get the 'letters show with RTL(like: Android -> diordnA)' style if it's enabled + * Get the 'letters show with RTL(like: Android to diordnA)' style if it's enabled * @return */ public boolean isTagSupportLettersRTL() { @@ -1205,7 +1205,7 @@ public boolean isTagSupportLettersRTL() { } /** - * Set whether the 'support letters show with RTL(like: Android -> diordnA)' style is enabled + * Set whether the 'support letters show with RTL(like: Android to diordnA)' style is enabled * @param mTagSupportLettersRTL */ public void setTagSupportLettersRTL(boolean mTagSupportLettersRTL) { diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index 6578d27..7f76c76 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -71,7 +71,7 @@ public class TagView extends View { /** The distance between baseline and descent*/ private float bdDistance; - /** Whether to support 'letters show with RTL(eg: Android -> diordnA)' style(default false)*/ + /** Whether to support 'letters show with RTL(eg: Android to diordnA)' style(default false)*/ private boolean mTagSupportLettersRTL = false; private Paint mPaint, mRipplePaint; From 1bcbba983e7facc1d52ef9ea58b25cdac5c7033e Mon Sep 17 00:00:00 2001 From: lujun Date: Mon, 6 Mar 2017 00:35:02 +0800 Subject: [PATCH 10/53] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a961841..d4d70a0 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,7 @@ mTagContainerLayout.removeAllTags(); ## Change logs ###1.1.0(2017-3-5) -- Fixed issue [#1](https://github.com/whilu/AndroidTagView/issues/45) +- Fixed issue [#45](https://github.com/whilu/AndroidTagView/issues/45) - Support 'letters show with RTL(eg: Android -> diordnA)' style ###1.0.6(2017-2-14) @@ -244,4 +244,4 @@ If you have any questions, contact me: [lujun.byte#gmail.com](mailto:lujun.byte@ 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. \ No newline at end of file + limitations under the License. From 1410847fe8dbfbace422d28a829e195257044c8f Mon Sep 17 00:00:00 2001 From: whilu Date: Fri, 17 Mar 2017 20:19:48 +0800 Subject: [PATCH 11/53] Fix: Do not draw ripple when TagView is unclickable --- .../src/main/java/co/lujun/androidtagview/TagView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index 7f76c76..aaa62ca 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -340,7 +340,7 @@ private void drawCross(Canvas canvas){ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private void drawRipple(Canvas canvas){ - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && canvas != null){ + if (isViewClickable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && canvas != null){ canvas.save(); mPath.reset(); From d0aa391a486e2d83f3f5a40c439eca1e5aaaab91 Mon Sep 17 00:00:00 2001 From: whilu Date: Mon, 27 Mar 2017 22:31:05 +0800 Subject: [PATCH 12/53] enhancement #49 --- .../src/main/java/co/lujun/androidtagview/TagView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index aaa62ca..9166bb6 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -263,7 +263,7 @@ public boolean onTouchEvent(MotionEvent event) { splashRipple(); } if (isEnableCross() && isClickCrossArea(event) && mOnTagClickListener != null){ - if (action == MotionEvent.ACTION_DOWN) { + if (action == MotionEvent.ACTION_UP) { mOnTagClickListener.onTagCrossClick((int) getTag()); } return true; From 4c72ba29fbc65fe5e27835dfea3f2a378d27ed4f Mon Sep 17 00:00:00 2001 From: whilu Date: Sun, 9 Apr 2017 23:02:06 +0800 Subject: [PATCH 13/53] enhancement #50 --- .../src/main/java/co/lujun/androidtagview/TagView.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index 9166bb6..533dbac 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -341,6 +341,12 @@ private void drawCross(Canvas canvas){ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private void drawRipple(Canvas canvas){ if (isViewClickable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && canvas != null){ + + // Disable hardware acceleration for 'Canvas.clipPath()' when running on API from 11 to 17 + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2){ + setLayerType(LAYER_TYPE_SOFTWARE, null); + } + canvas.save(); mPath.reset(); From dabc01b7384b6a8e46344bc0675d88cb4566ad0f Mon Sep 17 00:00:00 2001 From: Anant Shah Date: Sat, 15 Apr 2017 19:07:53 +0530 Subject: [PATCH 14/53] Custom Colored Tags --- .../androidtagview/TagContainerLayout.java | 410 +++++++++++++----- .../java/co/lujun/sample/MainActivity.java | 31 +- sample/src/main/res/layout/content_main.xml | 15 + 3 files changed, 333 insertions(+), 123 deletions(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index 25678be..11af67b 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -27,88 +27,149 @@ */ public class TagContainerLayout extends ViewGroup { - /** Vertical interval, default 5(dp)*/ + /** + * Vertical interval, default 5(dp) + */ private int mVerticalInterval; - /** Horizontal interval, default 5(dp)*/ + /** + * Support multiple colors in tags + */ + private ArrayList mColorArrayList; + + /** + * Horizontal interval, default 5(dp) + */ private int mHorizontalInterval; - /** TagContainerLayout border width(default 0.5dp)*/ + /** + * TagContainerLayout border width(default 0.5dp) + */ private float mBorderWidth = 0.5f; - /** TagContainerLayout border radius(default 10.0dp)*/ + /** + * TagContainerLayout border radius(default 10.0dp) + */ private float mBorderRadius = 10.0f; - /** The sensitive of the ViewDragHelper(default 1.0f, normal)*/ + /** + * The sensitive of the ViewDragHelper(default 1.0f, normal) + */ private float mSensitivity = 1.0f; - /** TagView average height*/ + /** + * TagView average height + */ private int mChildHeight; - /** TagContainerLayout border color(default #22FF0000)*/ + /** + * TagContainerLayout border color(default #22FF0000) + */ private int mBorderColor = Color.parseColor("#22FF0000"); - /** TagContainerLayout background color(default #11FF0000)*/ + /** + * TagContainerLayout background color(default #11FF0000) + */ private int mBackgroundColor = Color.parseColor("#11FF0000"); - /** The container layout gravity(default left)*/ + /** + * The container layout gravity(default left) + */ private int mGravity = Gravity.LEFT; - /** The max line count of TagContainerLayout */ + /** + * The max line count of TagContainerLayout + */ private int mMaxLines = 0; - /** The max length for TagView(default max length 23)*/ + /** + * The max length for TagView(default max length 23) + */ private int mTagMaxLength = 23; - /** TagView Border width(default 0.5dp)*/ + /** + * TagView Border width(default 0.5dp) + */ private float mTagBorderWidth = 0.5f; - /** TagView Border radius(default 15.0dp)*/ + /** + * TagView Border radius(default 15.0dp) + */ private float mTagBorderRadius = 15.0f; - /** TagView Text size(default 14sp)*/ + /** + * TagView Text size(default 14sp) + */ private float mTagTextSize = 14; - /** Text direction(support:TEXT_DIRECTION_RTL & TEXT_DIRECTION_LTR, default TEXT_DIRECTION_LTR)*/ + /** + * Text direction(support:TEXT_DIRECTION_RTL & TEXT_DIRECTION_LTR, default TEXT_DIRECTION_LTR) + */ private int mTagTextDirection = View.TEXT_DIRECTION_LTR; - /** Horizontal padding for TagView, include left & right padding(left & right padding are equal, default 10dp)*/ + /** + * Horizontal padding for TagView, include left & right padding(left & right padding are equal, default 10dp) + */ private int mTagHorizontalPadding = 10; - /** Vertical padding for TagView, include top & bottom padding(top & bottom padding are equal, default 8dp)*/ + /** + * Vertical padding for TagView, include top & bottom padding(top & bottom padding are equal, default 8dp) + */ private int mTagVerticalPadding = 8; - /** TagView border color(default #88F44336)*/ + /** + * TagView border color(default #88F44336) + */ private int mTagBorderColor = Color.parseColor("#88F44336"); - /** TagView background color(default #33F44336)*/ + /** + * TagView background color(default #33F44336) + */ private int mTagBackgroundColor = Color.parseColor("#33F44336"); - /** TagView text color(default #FF666666)*/ + /** + * TagView text color(default #FF666666) + */ private int mTagTextColor = Color.parseColor("#FF666666"); - /** TagView typeface*/ + /** + * TagView typeface + */ private Typeface mTagTypeface = Typeface.DEFAULT; - /** Whether TagView can clickable(default unclickable)*/ + /** + * Whether TagView can clickable(default unclickable) + */ private boolean isTagViewClickable; - /** Tags*/ + /** + * Tags + */ private List mTags; - /** Can drag TagView(default false)*/ + /** + * Can drag TagView(default false) + */ private boolean mDragEnable; - /** TagView drag state(default STATE_IDLE)*/ + /** + * TagView drag state(default STATE_IDLE) + */ private int mTagViewState = ViewDragHelper.STATE_IDLE; - /** The distance between baseline and descent(default 2.75dp)*/ + /** + * The distance between baseline and descent(default 2.75dp) + */ private float mTagBdDistance = 2.75f; - /** OnTagClickListener for TagView*/ + /** + * OnTagClickListener for TagView + */ private TagView.OnTagClickListener mOnTagClickListener; - /** Whether to support 'letters show with RTL(eg: Android to diordnA)' style(default false)*/ + /** + * Whether to support 'letters show with RTL(eg: Android to diordnA)' style(default false) + */ private boolean mTagSupportLettersRTL = false; private Paint mPaint; @@ -121,37 +182,59 @@ public class TagContainerLayout extends ViewGroup { private int[] mViewPos; - /** View theme(default PURE_CYAN)*/ + /** + * View theme(default PURE_CYAN) + */ private int mTheme = ColorFactory.PURE_CYAN; - /** Default interval(dp)*/ + /** + * Default interval(dp) + */ private static final float DEFAULT_INTERVAL = 5; - /** Default tag min length*/ + /** + * Default tag min length + */ private static final int TAG_MIN_LENGTH = 3; - /** The ripple effect duration(In milliseconds, default 1000ms)*/ + /** + * The ripple effect duration(In milliseconds, default 1000ms) + */ private int mRippleDuration = 1000; - /** The ripple effect color(default #EEEEEE)*/ + /** + * The ripple effect color(default #EEEEEE) + */ private int mRippleColor; - /** The ripple effect color alpha(the value may between 0 - 255, default 128)*/ + /** + * The ripple effect color alpha(the value may between 0 - 255, default 128) + */ private int mRippleAlpha = 128; - /** Enable draw cross icon(default false) */ + /** + * Enable draw cross icon(default false) + */ private boolean mEnableCross = false; - /** The cross area width(your cross click area, default equal to the TagView's height) */ + /** + * The cross area width(your cross click area, default equal to the TagView's height) + */ private float mCrossAreaWidth = 0.0f; - /** The padding of the cross area(default 10dp)*/ + /** + * The padding of the cross area(default 10dp) + */ private float mCrossAreaPadding = 10.0f; - /** The cross icon color(default Color.BLACK)*/ + /** + * The cross icon color(default Color.BLACK) + */ private int mCrossColor = Color.BLACK; - /** The cross line width(default 1dp)*/ + /** + * The cross line width(default 1dp) + */ private float mCrossLineWidth = 1.0f; public TagContainerLayout(Context context) { @@ -162,17 +245,17 @@ public TagContainerLayout(Context context, AttributeSet attrs) { this(context, attrs, 0); } - public TagContainerLayout(Context context, AttributeSet attrs, int defStyleAttr){ + public TagContainerLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context, attrs, defStyleAttr); } - private void init(Context context, AttributeSet attrs, int defStyleAttr){ + private void init(Context context, AttributeSet attrs, int defStyleAttr) { TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.AndroidTagView, defStyleAttr, 0); - mVerticalInterval = (int)attributes.getDimension(R.styleable.AndroidTagView_vertical_interval, + mVerticalInterval = (int) attributes.getDimension(R.styleable.AndroidTagView_vertical_interval, dp2px(context, DEFAULT_INTERVAL)); - mHorizontalInterval = (int)attributes.getDimension(R.styleable.AndroidTagView_horizontal_interval, + mHorizontalInterval = (int) attributes.getDimension(R.styleable.AndroidTagView_horizontal_interval, dp2px(context, DEFAULT_INTERVAL)); mBorderWidth = attributes.getDimension(R.styleable.AndroidTagView_container_border_width, dp2px(context, mBorderWidth)); @@ -250,13 +333,13 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec); int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec); - if (childCount == 0){ + if (childCount == 0) { setMeasuredDimension(0, 0); - }else if (heightSpecMode == MeasureSpec.AT_MOST + } else if (heightSpecMode == MeasureSpec.AT_MOST || heightSpecMode == MeasureSpec.UNSPECIFIED) { setMeasuredDimension(widthSpecSize, (mVerticalInterval + mChildHeight) * lines - mVerticalInterval + getPaddingTop() + getPaddingBottom()); - }else { + } else { setMeasuredDimension(widthSpecSize, heightSpecSize); } } @@ -270,7 +353,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { int childCount; - if ((childCount = getChildCount()) <= 0){ + if ((childCount = getChildCount()) <= 0) { return; } int availableW = getMeasuredWidth() - getPaddingLeft() - getPaddingRight(); @@ -284,16 +367,16 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { final View childView = getChildAt(i); if (childView.getVisibility() != GONE) { int width = childView.getMeasuredWidth(); - if (mGravity == Gravity.RIGHT){ - if (curRight - width < getPaddingLeft()){ + if (mGravity == Gravity.RIGHT) { + if (curRight - width < getPaddingLeft()) { curRight = getMeasuredWidth() - getPaddingRight(); curTop += mChildHeight + mVerticalInterval; } mViewPos[i * 2] = curRight - width; mViewPos[i * 2 + 1] = curTop; curRight -= width + mHorizontalInterval; - }else if (mGravity == Gravity.CENTER){ - if (curLeft + width - getPaddingLeft() > availableW){ + } else if (mGravity == Gravity.CENTER) { + if (curLeft + width - getPaddingLeft() > availableW) { int leftW = getMeasuredWidth() - mViewPos[(i - 1) * 2] - getChildAt(i - 1).getMeasuredWidth() - getPaddingRight(); for (int j = sPos; j < i; j++) { @@ -307,15 +390,15 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { mViewPos[i * 2 + 1] = curTop; curLeft += width + mHorizontalInterval; - if (i == childCount - 1){ + if (i == childCount - 1) { int leftW = getMeasuredWidth() - mViewPos[i * 2] - childView.getMeasuredWidth() - getPaddingRight(); for (int j = sPos; j < childCount; j++) { mViewPos[j * 2] = mViewPos[j * 2] + leftW / 2; } } - }else { - if (curLeft + width - getPaddingLeft() > availableW){ + } else { + if (curLeft + width - getPaddingLeft() > availableW) { curLeft = getPaddingLeft(); curTop += mChildHeight + mVerticalInterval; } @@ -363,12 +446,12 @@ public boolean onTouchEvent(MotionEvent event) { @Override public void computeScroll() { super.computeScroll(); - if (mViewDragHelper.continueSettling(true)){ + if (mViewDragHelper.continueSettling(true)) { requestLayout(); } } - private int getChildLines(int childCount){ + private int getChildLines(int childCount) { int availableW = getMeasuredWidth() - getPaddingLeft() - getPaddingRight(); int lines = 1; for (int i = 0, curLineW = 0; i < childCount; i++) { @@ -377,7 +460,7 @@ private int getChildLines(int childCount){ int height = childView.getMeasuredHeight(); mChildHeight = i == 0 ? height : Math.min(mChildHeight, height); curLineW += dis; - if (curLineW - mHorizontalInterval > availableW){ + if (curLineW - mHorizontalInterval > availableW) { lines++; curLineW = dis; } @@ -386,26 +469,26 @@ private int getChildLines(int childCount){ return mMaxLines <= 0 ? lines : mMaxLines; } - private int[] onUpdateColorFactory(){ + private int[] onUpdateColorFactory() { int[] colors; - if (mTheme == ColorFactory.RANDOM){ + if (mTheme == ColorFactory.RANDOM) { colors = ColorFactory.onRandomBuild(); - }else if (mTheme == ColorFactory.PURE_TEAL){ + } else if (mTheme == ColorFactory.PURE_TEAL) { colors = ColorFactory.onPureBuild(ColorFactory.PURE_COLOR.TEAL); - }else if (mTheme == ColorFactory.PURE_CYAN){ + } else if (mTheme == ColorFactory.PURE_CYAN) { colors = ColorFactory.onPureBuild(ColorFactory.PURE_COLOR.CYAN); - }else { + } else { colors = new int[]{mTagBackgroundColor, mTagBorderColor, mTagTextColor}; } return colors; } - private void onSetTag(){ - if (mTags == null){ + private void onSetTag() { + if (mTags == null) { throw new RuntimeException("NullPointer exception!"); } removeAllTags(); - if (mTags.size() == 0){ + if (mTags.size() == 0) { return; } for (int i = 0; i < mTags.size(); i++) { @@ -415,24 +498,36 @@ private void onSetTag(){ } private void onAddTag(String text, int position) { - if (position < 0 || position > mChildViews.size()){ + if (position < 0 || position > mChildViews.size()) { throw new RuntimeException("Illegal position!"); } TagView tagView = new TagView(getContext(), text); - initTagView(tagView); + initTagView(tagView, position); mChildViews.add(position, tagView); - if (position < mChildViews.size()){ + if (position < mChildViews.size()) { for (int i = position; i < mChildViews.size(); i++) { mChildViews.get(i).setTag(i); } - }else { + } else { tagView.setTag(position); } addView(tagView, position); } - private void initTagView(TagView tagView){ + private void initTagView(TagView tagView, int position) { int[] colors = onUpdateColorFactory(); + + if (mColorArrayList != null && mColorArrayList.size() > 0) { + if (mColorArrayList.size() == mTags.size()) + colors = mColorArrayList.get(position); + else + throw new RuntimeException("Color list is not equal to Tags List!"); + + } else { + colors = onUpdateColorFactory(); + } + + tagView.setTagBackgroundColor(colors[0]); tagView.setTagBorderColor(colors[1]); tagView.setTagTextColor(colors[2]); @@ -458,15 +553,15 @@ private void initTagView(TagView tagView){ tagView.setTagSupportLettersRTL(mTagSupportLettersRTL); } - private void invalidateTags(){ + private void invalidateTags() { for (View view : mChildViews) { final TagView tagView = (TagView) view; tagView.setOnTagClickListener(mOnTagClickListener); } } - private void onRemoveTag(int position){ - if (position < 0 || position >= mChildViews.size()){ + private void onRemoveTag(int position) { + if (position < 0 || position >= mChildViews.size()) { throw new RuntimeException("Illegal position!"); } mChildViews.remove(position); @@ -477,27 +572,27 @@ private void onRemoveTag(int position){ // TODO, make removed view null? } - private int[] onGetNewPosition(View view){ + private int[] onGetNewPosition(View view) { int left = view.getLeft(); int top = view.getTop(); - int bestMatchLeft = mViewPos[(int)view.getTag() * 2]; - int bestMatchTop = mViewPos[(int)view.getTag() * 2 + 1]; + int bestMatchLeft = mViewPos[(int) view.getTag() * 2]; + int bestMatchTop = mViewPos[(int) view.getTag() * 2 + 1]; int tmpTopDis = Math.abs(top - bestMatchTop); for (int i = 0; i < mViewPos.length / 2; i++) { - if (Math.abs(top - mViewPos[i * 2 +1]) < tmpTopDis){ - bestMatchTop = mViewPos[i * 2 +1]; - tmpTopDis = Math.abs(top - mViewPos[i * 2 +1]); + if (Math.abs(top - mViewPos[i * 2 + 1]) < tmpTopDis) { + bestMatchTop = mViewPos[i * 2 + 1]; + tmpTopDis = Math.abs(top - mViewPos[i * 2 + 1]); } } int rowChildCount = 0; int tmpLeftDis = 0; for (int i = 0; i < mViewPos.length / 2; i++) { - if (mViewPos[i * 2 + 1] == bestMatchTop){ - if (rowChildCount == 0){ + if (mViewPos[i * 2 + 1] == bestMatchTop) { + if (rowChildCount == 0) { bestMatchLeft = mViewPos[i * 2]; tmpLeftDis = Math.abs(left - bestMatchLeft); - }else { - if (Math.abs(left - mViewPos[i * 2]) < tmpLeftDis){ + } else { + if (Math.abs(left - mViewPos[i * 2]) < tmpLeftDis) { bestMatchLeft = mViewPos[i * 2]; tmpLeftDis = Math.abs(left - bestMatchLeft); } @@ -508,17 +603,17 @@ private int[] onGetNewPosition(View view){ return new int[]{bestMatchLeft, bestMatchTop}; } - private int onGetCoordinateReferPos(int left, int top){ - int pos = 0; + private int onGetCoordinateReferPos(int left, int top) { + int pos = 0; for (int i = 0; i < mViewPos.length / 2; i++) { - if (left == mViewPos[i * 2] && top == mViewPos[i * 2 + 1]){ + if (left == mViewPos[i * 2] && top == mViewPos[i * 2 + 1]) { pos = i; } } return pos; } - private void onChangeView(View view, int newPos, int originPos){ + private void onChangeView(View view, int newPos, int originPos) { mChildViews.remove(originPos); mChildViews.add(newPos, view); for (View child : mChildViews) { @@ -529,11 +624,11 @@ private void onChangeView(View view, int newPos, int originPos){ addView(view, newPos); } - private int ceilTagBorderWidth(){ - return (int)Math.ceil(mTagBorderWidth); + private int ceilTagBorderWidth() { + return (int) Math.ceil(mTagBorderWidth); } - private class DragHelperCallBack extends ViewDragHelper.Callback{ + private class DragHelperCallBack extends ViewDragHelper.Callback { @Override public void onViewDragStateChanged(int state) { @@ -585,14 +680,16 @@ public void onViewReleased(View releasedChild, float xvel, float yvel) { /** * Get current drag view state. + * * @return */ - public int getTagViewState(){ + public int getTagViewState() { return mTagViewState; } /** * Get TagView text baseline and descent distance. + * * @return */ public float getTagBdDistance() { @@ -601,6 +698,7 @@ public float getTagBdDistance() { /** * Set TagView text baseline and descent distance. + * * @param tagBdDistance */ public void setTagBdDistance(float tagBdDistance) { @@ -609,46 +707,59 @@ public void setTagBdDistance(float tagBdDistance) { /** * Set tags + * * @param tags */ - public void setTags(List tags){ + public void setTags(List tags) { mTags = tags; onSetTag(); } + + //For tags with custom color + public void setTags(List tags, ArrayList mColorArrayList) { + mTags = tags; + this.mColorArrayList = mColorArrayList; + onSetTag(); + } + /** * Set tags + * * @param tags */ - public void setTags(String... tags){ + public void setTags(String... tags) { mTags = Arrays.asList(tags); onSetTag(); } /** * Inserts the specified TagView into this ContainerLayout at the end. + * * @param text */ - public void addTag(String text){ + public void addTag(String text) { addTag(text, mChildViews.size()); } /** * Inserts the specified TagView into this ContainerLayout at the specified location. * The TagView is inserted before the current element at the specified location. + * * @param text * @param position */ - public void addTag(String text, int position){ + public void addTag(String text, int position) { onAddTag(text, position); postInvalidate(); } /** * Remove a TagView in specified position. + * * @param position */ - public void removeTag(int position){ + public void removeTag(int position) { onRemoveTag(position); postInvalidate(); } @@ -656,7 +767,7 @@ public void removeTag(int position){ /** * Remove all TagViews. */ - public void removeAllTags(){ + public void removeAllTags() { mChildViews.clear(); removeAllViews(); postInvalidate(); @@ -664,30 +775,33 @@ public void removeAllTags(){ /** * Set OnTagClickListener for TagView. + * * @param listener */ - public void setOnTagClickListener(TagView.OnTagClickListener listener){ + public void setOnTagClickListener(TagView.OnTagClickListener listener) { mOnTagClickListener = listener; invalidateTags(); } /** * Get TagView text. + * * @param position * @return */ - public String getTagText(int position){ - return ((TagView)mChildViews.get(position)).getText(); + public String getTagText(int position) { + return ((TagView) mChildViews.get(position)).getText(); } /** * Get a string list for all tags in TagContainerLayout. + * * @return */ - public List getTags(){ + public List getTags() { List tmpList = new ArrayList(); - for (View view : mChildViews){ - if (view instanceof TagView){ + for (View view : mChildViews) { + if (view instanceof TagView) { tmpList.add(((TagView) view).getText()); } } @@ -696,56 +810,63 @@ public List getTags(){ /** * Set whether the child view can be dragged. + * * @param enable */ - public void setDragEnable(boolean enable){ + public void setDragEnable(boolean enable) { this.mDragEnable = enable; } /** * Get current view is drag enable attribute. + * * @return */ - public boolean getDragEnable(){ + public boolean getDragEnable() { return mDragEnable; } /** * Set vertical interval + * * @param interval */ - public void setVerticalInterval(float interval){ + public void setVerticalInterval(float interval) { mVerticalInterval = (int) dp2px(getContext(), interval); postInvalidate(); } /** * Get vertical interval in this view. + * * @return */ - public int getVerticalInterval(){ + public int getVerticalInterval() { return mVerticalInterval; } /** * Set horizontal interval. + * * @param interval */ - public void setHorizontalInterval(float interval){ - mHorizontalInterval = (int)dp2px(getContext(), interval); + public void setHorizontalInterval(float interval) { + mHorizontalInterval = (int) dp2px(getContext(), interval); postInvalidate(); } /** * Get horizontal interval in this view. + * * @return */ - public int getHorizontalInterval(){ + public int getHorizontalInterval() { return mHorizontalInterval; } /** * Get TagContainerLayout border width. + * * @return */ public float getBorderWidth() { @@ -754,6 +875,7 @@ public float getBorderWidth() { /** * Set TagContainerLayout border width. + * * @param width */ public void setBorderWidth(float width) { @@ -762,6 +884,7 @@ public void setBorderWidth(float width) { /** * Get TagContainerLayout border radius. + * * @return */ public float getBorderRadius() { @@ -770,6 +893,7 @@ public float getBorderRadius() { /** * Set TagContainerLayout border radius. + * * @param radius */ public void setBorderRadius(float radius) { @@ -778,6 +902,7 @@ public void setBorderRadius(float radius) { /** * Get TagContainerLayout border color. + * * @return */ public int getBorderColor() { @@ -786,6 +911,7 @@ public int getBorderColor() { /** * Set TagContainerLayout border color. + * * @param color */ public void setBorderColor(int color) { @@ -794,6 +920,7 @@ public void setBorderColor(int color) { /** * Get TagContainerLayout background color. + * * @return */ public int getBackgroundColor() { @@ -802,6 +929,7 @@ public int getBackgroundColor() { /** * Set TagContainerLayout background color. + * * @param color */ public void setBackgroundColor(int color) { @@ -810,6 +938,7 @@ public void setBackgroundColor(int color) { /** * Get container layout gravity. + * * @return */ public int getGravity() { @@ -818,6 +947,7 @@ public int getGravity() { /** * Set container layout gravity. + * * @param gravity */ public void setGravity(int gravity) { @@ -826,6 +956,7 @@ public void setGravity(int gravity) { /** * Get TagContainerLayout ViewDragHelper sensitivity. + * * @return */ public float getSensitivity() { @@ -834,6 +965,7 @@ public float getSensitivity() { /** * Set TagContainerLayout ViewDragHelper sensitivity. + * * @param sensitivity */ public void setSensitivity(float sensitivity) { @@ -842,6 +974,7 @@ public void setSensitivity(float sensitivity) { /** * Set max line count for TagContainerLayout + * * @param maxLines max line count */ public void setMaxLines(int maxLines) { @@ -851,46 +984,52 @@ public void setMaxLines(int maxLines) { /** * Get TagContainerLayout's max lines + * * @return maxLines */ - public int getMaxLines(){ + public int getMaxLines() { return mMaxLines; } /** * Set the TagView text max length(must greater or equal to 3). + * * @param maxLength */ - public void setTagMaxLength(int maxLength){ + public void setTagMaxLength(int maxLength) { mTagMaxLength = maxLength < TAG_MIN_LENGTH ? TAG_MIN_LENGTH : maxLength; } /** * Get TagView max length. + * * @return */ - public int getTagMaxLength(){ + public int getTagMaxLength() { return mTagMaxLength; } /** * Set TagView theme. + * * @param theme */ - public void setTheme(int theme){ + public void setTheme(int theme) { mTheme = theme; } /** * Get TagView theme. + * * @return */ - public int getTheme(){ + public int getTheme() { return mTheme; } /** * Get TagView is clickable. + * * @return */ public boolean getIsTagViewClickable() { @@ -899,6 +1038,7 @@ public boolean getIsTagViewClickable() { /** * Set TagView is clickable + * * @param clickable */ public void setIsTagViewClickable(boolean clickable) { @@ -907,6 +1047,7 @@ public void setIsTagViewClickable(boolean clickable) { /** * Get TagView border width. + * * @return */ public float getTagBorderWidth() { @@ -915,6 +1056,7 @@ public float getTagBorderWidth() { /** * Set TagView border width. + * * @param width */ public void setTagBorderWidth(float width) { @@ -923,6 +1065,7 @@ public void setTagBorderWidth(float width) { /** * Get TagView border radius. + * * @return */ public float getTagBorderRadius() { @@ -931,6 +1074,7 @@ public float getTagBorderRadius() { /** * Set TagView border radius. + * * @param radius */ public void setTagBorderRadius(float radius) { @@ -939,6 +1083,7 @@ public void setTagBorderRadius(float radius) { /** * Get TagView text size. + * * @return */ public float getTagTextSize() { @@ -947,6 +1092,7 @@ public float getTagTextSize() { /** * Set TagView text size. + * * @param size */ public void setTagTextSize(float size) { @@ -955,6 +1101,7 @@ public void setTagTextSize(float size) { /** * Get TagView horizontal padding. + * * @return */ public int getTagHorizontalPadding() { @@ -963,6 +1110,7 @@ public int getTagHorizontalPadding() { /** * Set TagView horizontal padding. + * * @param padding */ public void setTagHorizontalPadding(int padding) { @@ -972,6 +1120,7 @@ public void setTagHorizontalPadding(int padding) { /** * Get TagView vertical padding. + * * @return */ public int getTagVerticalPadding() { @@ -980,6 +1129,7 @@ public int getTagVerticalPadding() { /** * Set TagView vertical padding. + * * @param padding */ public void setTagVerticalPadding(int padding) { @@ -989,6 +1139,7 @@ public void setTagVerticalPadding(int padding) { /** * Get TagView border color. + * * @return */ public int getTagBorderColor() { @@ -997,6 +1148,7 @@ public int getTagBorderColor() { /** * Set TagView border color. + * * @param color */ public void setTagBorderColor(int color) { @@ -1005,6 +1157,7 @@ public void setTagBorderColor(int color) { /** * Get TagView background color. + * * @return */ public int getTagBackgroundColor() { @@ -1013,6 +1166,7 @@ public int getTagBackgroundColor() { /** * Set TagView background color. + * * @param color */ public void setTagBackgroundColor(int color) { @@ -1021,6 +1175,7 @@ public void setTagBackgroundColor(int color) { /** * Get TagView text color. + * * @return */ public int getTagTextColor() { @@ -1030,6 +1185,7 @@ public int getTagTextColor() { /** * Set tag text direction, support:View.TEXT_DIRECTION_RTL and View.TEXT_DIRECTION_LTR, * default View.TEXT_DIRECTION_LTR + * * @param textDirection */ public void setTagTextDirection(int textDirection) { @@ -1038,6 +1194,7 @@ public void setTagTextDirection(int textDirection) { /** * Get TagView typeface. + * * @return */ public Typeface getTagTypeface() { @@ -1046,6 +1203,7 @@ public Typeface getTagTypeface() { /** * Set TagView typeface. + * * @param typeface */ public void setTagTypeface(Typeface typeface) { @@ -1054,6 +1212,7 @@ public void setTagTypeface(Typeface typeface) { /** * Get tag text direction + * * @return */ public int getTagTextDirection() { @@ -1062,6 +1221,7 @@ public int getTagTextDirection() { /** * Set TagView text color. + * * @param color */ public void setTagTextColor(int color) { @@ -1070,6 +1230,7 @@ public void setTagTextColor(int color) { /** * Get the ripple effect color's alpha. + * * @return */ public int getRippleAlpha() { @@ -1078,6 +1239,7 @@ public int getRippleAlpha() { /** * Set TagView ripple effect alpha, the value may between 0 to 255, default is 128. + * * @param mRippleAlpha */ public void setRippleAlpha(int mRippleAlpha) { @@ -1086,6 +1248,7 @@ public void setRippleAlpha(int mRippleAlpha) { /** * Get the ripple effect color. + * * @return */ public int getRippleColor() { @@ -1094,6 +1257,7 @@ public int getRippleColor() { /** * Set TagView ripple effect color. + * * @param mRippleColor */ public void setRippleColor(int mRippleColor) { @@ -1102,6 +1266,7 @@ public void setRippleColor(int mRippleColor) { /** * Get the ripple effect duration. + * * @return */ public int getRippleDuration() { @@ -1110,6 +1275,7 @@ public int getRippleDuration() { /** * Set TagView ripple effect duration, default is 1000ms. + * * @param mRippleDuration */ public void setRippleDuration(int mRippleDuration) { @@ -1118,6 +1284,7 @@ public void setRippleDuration(int mRippleDuration) { /** * Set TagView cross color. + * * @return */ public int getCrossColor() { @@ -1126,6 +1293,7 @@ public int getCrossColor() { /** * Set TagView cross color, default Color.BLACK. + * * @param mCrossColor */ public void setCrossColor(int mCrossColor) { @@ -1134,6 +1302,7 @@ public void setCrossColor(int mCrossColor) { /** * Get agView cross area's padding. + * * @return */ public float getCrossAreaPadding() { @@ -1142,6 +1311,7 @@ public float getCrossAreaPadding() { /** * Set TagView cross area padding, default 10dp. + * * @param mCrossAreaPadding */ public void setCrossAreaPadding(float mCrossAreaPadding) { @@ -1150,6 +1320,7 @@ public void setCrossAreaPadding(float mCrossAreaPadding) { /** * Get is the TagView's cross enable, default false. + * * @return */ public boolean isEnableCross() { @@ -1158,6 +1329,7 @@ public boolean isEnableCross() { /** * Enable or disable the TagView's cross. + * * @param mEnableCross */ public void setEnableCross(boolean mEnableCross) { @@ -1166,6 +1338,7 @@ public void setEnableCross(boolean mEnableCross) { /** * Get TagView cross area width. + * * @return */ public float getCrossAreaWidth() { @@ -1174,6 +1347,7 @@ public float getCrossAreaWidth() { /** * Set TagView area width. + * * @param mCrossAreaWidth */ public void setCrossAreaWidth(float mCrossAreaWidth) { @@ -1182,6 +1356,7 @@ public void setCrossAreaWidth(float mCrossAreaWidth) { /** * Get TagView cross line width. + * * @return */ public float getCrossLineWidth() { @@ -1190,6 +1365,7 @@ public float getCrossLineWidth() { /** * Set TagView cross line width, default 1dp. + * * @param mCrossLineWidth */ public void setCrossLineWidth(float mCrossLineWidth) { @@ -1198,6 +1374,7 @@ public void setCrossLineWidth(float mCrossLineWidth) { /** * Get the 'letters show with RTL(like: Android to diordnA)' style if it's enabled + * * @return */ public boolean isTagSupportLettersRTL() { @@ -1205,7 +1382,8 @@ public boolean isTagSupportLettersRTL() { } /** - * Set whether the 'support letters show with RTL(like: Android to diordnA)' style is enabled + * Set whether the 'support letters show with RTL(like: Android to diordnA)' style is enabled + * * @param mTagSupportLettersRTL */ public void setTagSupportLettersRTL(boolean mTagSupportLettersRTL) { diff --git a/sample/src/main/java/co/lujun/sample/MainActivity.java b/sample/src/main/java/co/lujun/sample/MainActivity.java index 843cd0e..28e004d 100644 --- a/sample/src/main/java/co/lujun/sample/MainActivity.java +++ b/sample/src/main/java/co/lujun/sample/MainActivity.java @@ -3,6 +3,7 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; +import android.graphics.Color; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.RecyclerView; @@ -22,7 +23,8 @@ public class MainActivity extends AppCompatActivity { - private TagContainerLayout mTagContainerLayout1, mTagContainerLayout2, mTagContainerLayout3, mTagContainerLayout4; + private TagContainerLayout mTagContainerLayout1, mTagContainerLayout2, + mTagContainerLayout3, mTagContainerLayout4, mTagcontainerLayout5; @Override protected void onCreate(Bundle savedInstanceState) { @@ -60,10 +62,16 @@ protected void onCreate(Bundle savedInstanceState) { String[] list3 = new String[]{"Persian", "波斯语", "فارسی", "Hello", "你好", "سلام"}; String[] list4 = new String[]{"Adele", "Whitney Houston"}; + List list5 = new ArrayList(); + list5.add("Custom Red Color"); + list5.add("Custom Blue Color"); + + mTagContainerLayout1 = (TagContainerLayout) findViewById(R.id.tagcontainerLayout1); mTagContainerLayout2 = (TagContainerLayout) findViewById(R.id.tagcontainerLayout2); mTagContainerLayout3 = (TagContainerLayout) findViewById(R.id.tagcontainerLayout3); mTagContainerLayout4 = (TagContainerLayout) findViewById(R.id.tagcontainerLayout4); + mTagcontainerLayout5 = (TagContainerLayout) findViewById(R.id.tagcontainerLayout5); // Set custom click listener mTagContainerLayout1.setOnTagClickListener(new TagView.OnTagClickListener() { @@ -126,6 +134,15 @@ public void onTagCrossClick(int position) { mTagContainerLayout3.setTags(list3); mTagContainerLayout4.setTags(list4); + ArrayList colors = new ArrayList(); + //int[]color = {backgroundColor, tagBorderColor, tagTextColor} + int[] col1 = {Color.parseColor("#ff0000"), Color.parseColor("#000000"), Color.parseColor("#ffffff")}; + int[] col2 = {Color.parseColor("#0000ff"), Color.parseColor("#000000"), Color.parseColor("#ffffff")}; + + colors.add(col1); + colors.add(col2); + + mTagcontainerLayout5.setTags(list5,colors); final EditText text = (EditText) findViewById(R.id.text_tag); Button btnAddTag = (Button) findViewById(R.id.btn_add_tag); btnAddTag.setOnClickListener(new View.OnClickListener() { @@ -154,13 +171,13 @@ public void onClick(View v) { } public class TagRecyclerViewAdapter - extends RecyclerView.Adapter{ + extends RecyclerView.Adapter { private Context mContext; private String[] mData; private View.OnClickListener mOnClickListener; - public TagRecyclerViewAdapter(Context context, String[] data){ + public TagRecyclerViewAdapter(Context context, String[] data) { this.mContext = context; this.mData = data; } @@ -182,17 +199,17 @@ public void onBindViewHolder(TagViewHolder holder, int position) { holder.button.setOnClickListener(mOnClickListener); } - public void setOnClickListener(View.OnClickListener listener){ + public void setOnClickListener(View.OnClickListener listener) { this.mOnClickListener = listener; } - class TagViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ + class TagViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { TagContainerLayout tagContainerLayout; View.OnClickListener clickListener; Button button; - public TagViewHolder(View v, View.OnClickListener listener){ + public TagViewHolder(View v, View.OnClickListener listener) { super(v); this.clickListener = listener; tagContainerLayout = (TagContainerLayout) v.findViewById(R.id.tagcontainerLayout); @@ -202,7 +219,7 @@ public TagViewHolder(View v, View.OnClickListener listener){ @Override public void onClick(View v) { - if (clickListener != null){ + if (clickListener != null) { clickListener.onClick(v); } } diff --git a/sample/src/main/res/layout/content_main.xml b/sample/src/main/res/layout/content_main.xml index 14184f7..a10ee50 100644 --- a/sample/src/main/res/layout/content_main.xml +++ b/sample/src/main/res/layout/content_main.xml @@ -119,6 +119,21 @@ app:tag_theme="pure_teal" app:vertical_interval="10dp" /> + + + + From 95f4b21a7d02fdbd140b3faeac35ed637a378fdd Mon Sep 17 00:00:00 2001 From: whilu Date: Sun, 16 Apr 2017 16:18:32 +0800 Subject: [PATCH 15/53] Release v1.1.1 --- .travis.yml | 4 +-- README.md | 31 ++++++++++++++----- androidtagview/build.gradle | 4 +-- .../androidtagview/TagContainerLayout.java | 27 +++++++++------- sample/src/main/res/layout/content_main.xml | 11 +++---- 5 files changed, 46 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index 64dae33..20bba8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,10 +7,10 @@ android: # - tools # The BuildTools version used by your project - - build-tools-22.0.1 + - build-tools-25.0.0 # The SDK version used to compile your project - - android-23 + - android-25 # Additional components - extra-google-google_play_services diff --git a/README.md b/README.md index d4d70a0..ed87011 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add below dependency in your **build.gradle** file. ```groovy dependencies { - compile 'co.lujun:androidtagview:1.1.0' + compile 'co.lujun:androidtagview:1.1.1' } ``` @@ -191,31 +191,46 @@ mTagContainerLayout.removeTag(int position); ```java mTagContainerLayout.removeAllTags(); ``` +* Set color for each TagView. +```java +List colors = new ArrayList(); +//int[] color = {TagBackgroundColor, TabBorderColor, TagTextColor} +int[] color1 = {Color.RED, Color.BLACK, Color.WHITE}; +int[] color2 = {Color.BLUE, Color.BLACK, Color.WHITE}; +colors.add(color1); +colors.add(color2); +mTagcontainerLayout.setTags(tags, colors); +``` ## Change logs -###1.1.0(2017-3-5) + +### 1.1.1(2017-4-16) +- Customize the color of the TagView, see [#51](https://github.com/whilu/AndroidTagView/pull/51) +- Fixed issue [#50](https://github.com/whilu/AndroidTagView/issues/50), [#49](https://github.com/whilu/AndroidTagView/issues/49) + +### 1.1.0(2017-3-5) - Fixed issue [#45](https://github.com/whilu/AndroidTagView/issues/45) - Support 'letters show with RTL(eg: Android -> diordnA)' style -###1.0.6(2017-2-14) +### 1.0.6(2017-2-14) - Fix bugs -###1.0.5(2016-11-9) +### 1.0.5(2016-11-9) - Add cross view for TagView -###1.0.4(2016-10-30) +### 1.0.4(2016-10-30) - Support ripple effect(Call requires API level 11), like [Android CustomButton](https://github.com/whilu/AndroidSample/tree/master/CustomButton) - Fix bugs -###1.0.3(2016-4-3) +### 1.0.3(2016-4-3) - Add ```getTags()``` method to get the list for all tags - Fixed bugs in ListView/RecyclerView -###1.0.2(2016-1-18) +### 1.0.2(2016-1-18) - Support [gravity](#gravity) for ```TagContainerLayout``` - Support set typeface -###1.0.1(2016-1-14) +### 1.0.1(2016-1-14) - Support text [direction](#directions) - Add ```removeAllTags()``` method for remove all TagViews - Fixed issue [#1](https://github.com/whilu/AndroidTagView/issues/1) diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index 96ac19e..93472dd 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 9 targetSdkVersion 25 - versionCode 110 - versionName "1.1.0" + versionCode 111 + versionName "1.1.1" } buildTypes { release { diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index 11af67b..75dca9d 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -33,7 +33,7 @@ public class TagContainerLayout extends ViewGroup { private int mVerticalInterval; /** - * Support multiple colors in tags + * The list to store the tags color info */ private ArrayList mColorArrayList; @@ -515,19 +515,18 @@ private void onAddTag(String text, int position) { } private void initTagView(TagView tagView, int position) { - int[] colors = onUpdateColorFactory(); - + int[] colors; if (mColorArrayList != null && mColorArrayList.size() > 0) { - if (mColorArrayList.size() == mTags.size()) + if (mColorArrayList.size() == mTags.size() && + mColorArrayList.get(position).length >= 3) { colors = mColorArrayList.get(position); - else - throw new RuntimeException("Color list is not equal to Tags List!"); - + } else { + throw new RuntimeException("Illegal color list!"); + } } else { colors = onUpdateColorFactory(); } - tagView.setTagBackgroundColor(colors[0]); tagView.setTagBorderColor(colors[1]); tagView.setTagTextColor(colors[2]); @@ -715,11 +714,15 @@ public void setTags(List tags) { onSetTag(); } - - //For tags with custom color - public void setTags(List tags, ArrayList mColorArrayList) { + /** + * Set tags with own color + * + * @param tags + * @param colorArrayList + */ + public void setTags(List tags, ArrayList colorArrayList) { mTags = tags; - this.mColorArrayList = mColorArrayList; + mColorArrayList = colorArrayList; onSetTag(); } diff --git a/sample/src/main/res/layout/content_main.xml b/sample/src/main/res/layout/content_main.xml index a10ee50..70c532b 100644 --- a/sample/src/main/res/layout/content_main.xml +++ b/sample/src/main/res/layout/content_main.xml @@ -38,9 +38,9 @@ app:container_enable_drag="true" app:horizontal_interval="10dp" app:tag_clickable="true" + app:tag_enable_cross="true" app:tag_theme="pure_teal" - app:vertical_interval="10dp" - app:tag_enable_cross="true"/> + app:vertical_interval="10dp" /> + app:vertical_interval="10dp" /> - - - Date: Sun, 16 Apr 2017 16:29:13 +0800 Subject: [PATCH 16/53] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ed87011..5c47663 100644 --- a/README.md +++ b/README.md @@ -236,7 +236,7 @@ mTagcontainerLayout.setTags(tags, colors); - Fixed issue [#1](https://github.com/whilu/AndroidTagView/issues/1) - Fixed other bugs -###1.0.0(2016-1-6) +### 1.0.0(2016-1-6) - First release ## Sample App From 496330a28962821d995885334dcaf505ba33a9ce Mon Sep 17 00:00:00 2001 From: whilu Date: Tue, 16 May 2017 00:00:08 +0800 Subject: [PATCH 17/53] 'LAYER_TYPE_SOFTWARE' still view drawn with hardware acceleration(API level 11-17), close draw ripple under this situation. --- README.md | 2 +- androidtagview/build.gradle | 4 +-- .../java/co/lujun/androidtagview/TagView.java | 28 +++++++++++-------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5c47663..33985f9 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add below dependency in your **build.gradle** file. ```groovy dependencies { - compile 'co.lujun:androidtagview:1.1.1' + compile 'co.lujun:androidtagview:1.1.2' } ``` diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index 93472dd..f7210dc 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 9 targetSdkVersion 25 - versionCode 111 - versionName "1.1.1" + versionCode 112 + versionName "1.1.2" } buildTypes { release { diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index 533dbac..dfb39dd 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -113,6 +113,8 @@ public class TagView extends View { private float mCrossLineWidth; + private boolean unSupportedClipPath = false; + private Runnable mLongClickHandle = new Runnable() { @Override public void run() { @@ -340,22 +342,26 @@ private void drawCross(Canvas canvas){ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private void drawRipple(Canvas canvas){ - if (isViewClickable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && canvas != null){ + if (isViewClickable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && + canvas != null && !unSupportedClipPath){ // Disable hardware acceleration for 'Canvas.clipPath()' when running on API from 11 to 17 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2){ setLayerType(LAYER_TYPE_SOFTWARE, null); } - - canvas.save(); - mPath.reset(); - - canvas.clipPath(mPath); - mPath.addRoundRect(mRectF, mBorderRadius, mBorderRadius, Path.Direction.CCW); - - canvas.clipPath(mPath, Region.Op.REPLACE); - canvas.drawCircle(mTouchX, mTouchY, mRippleRadius, mRipplePaint); - canvas.restore(); + try { + canvas.save(); + mPath.reset(); + + canvas.clipPath(mPath); + mPath.addRoundRect(mRectF, mBorderRadius, mBorderRadius, Path.Direction.CCW); + + canvas.clipPath(mPath, Region.Op.REPLACE); + canvas.drawCircle(mTouchX, mTouchY, mRippleRadius, mRipplePaint); + canvas.restore(); + }catch (UnsupportedOperationException e){ + unSupportedClipPath = true; + } } } From 9b1b7f9cbc0f72d1519335ecf000c09e95204931 Mon Sep 17 00:00:00 2001 From: whilu Date: Tue, 16 May 2017 00:06:26 +0800 Subject: [PATCH 18/53] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 33985f9..d7f0228 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,9 @@ mTagcontainerLayout.setTags(tags, colors); ## Change logs +### 1.1.2(2017-5-16) +- Fix bugs + ### 1.1.1(2017-4-16) - Customize the color of the TagView, see [#51](https://github.com/whilu/AndroidTagView/pull/51) - Fixed issue [#50](https://github.com/whilu/AndroidTagView/issues/50), [#49](https://github.com/whilu/AndroidTagView/issues/49) From 64c73da9e0d97234e19df793cbf890cbe34d19db Mon Sep 17 00:00:00 2001 From: whilu Date: Tue, 16 May 2017 21:43:25 +0800 Subject: [PATCH 19/53] Release v1.1.3 --- README.md | 11 +++++++++-- androidtagview/build.gradle | 4 ++-- .../androidtagview/TagContainerLayout.java | 19 ++++++++++++++++--- .../java/co/lujun/sample/MainActivity.java | 4 ++-- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d7f0228..0c1e336 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add below dependency in your **build.gradle** file. ```groovy dependencies { - compile 'co.lujun:androidtagview:1.1.2' + compile 'co.lujun:androidtagview:1.1.3' } ``` @@ -183,7 +183,7 @@ mTagContainerLayout.addTag(String text); ```java mTagContainerLayout.addTag(String text, int position); ``` -* Remove TagView on particular position, require the position of the TagView +* Remove TagView on particular position, require the position of the TagView. ```java mTagContainerLayout.removeTag(int position); ``` @@ -191,6 +191,10 @@ mTagContainerLayout.removeTag(int position); ```java mTagContainerLayout.removeAllTags(); ``` +* Get a TagView in specified position. +```java +mTagContainerLayout.getTagView(int position); +``` * Set color for each TagView. ```java List colors = new ArrayList(); @@ -204,6 +208,9 @@ mTagcontainerLayout.setTags(tags, colors); ## Change logs +### 1.1.3(2017-5-17) +- Add ```getTagView(int position)``` method to get TagView in specified position. + ### 1.1.2(2017-5-16) - Fix bugs diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index f7210dc..dbbf3b1 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 9 targetSdkVersion 25 - versionCode 112 - versionName "1.1.2" + versionCode 113 + versionName "1.1.3" } buildTypes { release { diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index 75dca9d..31c2870 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -35,7 +35,7 @@ public class TagContainerLayout extends ViewGroup { /** * The list to store the tags color info */ - private ArrayList mColorArrayList; + private List mColorArrayList; /** * Horizontal interval, default 5(dp) @@ -720,7 +720,7 @@ public void setTags(List tags) { * @param tags * @param colorArrayList */ - public void setTags(List tags, ArrayList colorArrayList) { + public void setTags(List tags, List colorArrayList) { mTags = tags; mColorArrayList = colorArrayList; onSetTag(); @@ -1385,11 +1385,24 @@ public boolean isTagSupportLettersRTL() { } /** - * Set whether the 'support letters show with RTL(like: Android to diordnA)' style is enabled + * Set whether the 'support letters show with RTL(like: Android to diordnA)' style is enabled. * * @param mTagSupportLettersRTL */ public void setTagSupportLettersRTL(boolean mTagSupportLettersRTL) { this.mTagSupportLettersRTL = mTagSupportLettersRTL; } + + /** + * Get TagView in specified position. + * + * @param position the position of the TagView + * @return + */ + public TagView getTagView(int position){ + if (position < 0 || position >= mChildViews.size()) { + throw new RuntimeException("Illegal position!"); + } + return (TagView) mChildViews.get(position); + } } diff --git a/sample/src/main/java/co/lujun/sample/MainActivity.java b/sample/src/main/java/co/lujun/sample/MainActivity.java index 28e004d..9028e45 100644 --- a/sample/src/main/java/co/lujun/sample/MainActivity.java +++ b/sample/src/main/java/co/lujun/sample/MainActivity.java @@ -134,7 +134,7 @@ public void onTagCrossClick(int position) { mTagContainerLayout3.setTags(list3); mTagContainerLayout4.setTags(list4); - ArrayList colors = new ArrayList(); + List colors = new ArrayList(); //int[]color = {backgroundColor, tagBorderColor, tagTextColor} int[] col1 = {Color.parseColor("#ff0000"), Color.parseColor("#000000"), Color.parseColor("#ffffff")}; int[] col2 = {Color.parseColor("#0000ff"), Color.parseColor("#000000"), Color.parseColor("#ffffff")}; @@ -142,7 +142,7 @@ public void onTagCrossClick(int position) { colors.add(col1); colors.add(col2); - mTagcontainerLayout5.setTags(list5,colors); + mTagcontainerLayout5.setTags(list5, colors); final EditText text = (EditText) findViewById(R.id.text_tag); Button btnAddTag = (Button) findViewById(R.id.btn_add_tag); btnAddTag.setOnClickListener(new View.OnClickListener() { From 8fbc1460520b011ff89667db7259b15a40bb6f9b Mon Sep 17 00:00:00 2001 From: whilu Date: Wed, 17 May 2017 23:13:03 +0800 Subject: [PATCH 20/53] add protection when delete tag in sample --- sample/src/main/java/co/lujun/sample/MainActivity.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sample/src/main/java/co/lujun/sample/MainActivity.java b/sample/src/main/java/co/lujun/sample/MainActivity.java index 9028e45..3253051 100644 --- a/sample/src/main/java/co/lujun/sample/MainActivity.java +++ b/sample/src/main/java/co/lujun/sample/MainActivity.java @@ -89,7 +89,9 @@ public void onTagLongClick(final int position, String text) { .setPositiveButton("Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - mTagContainerLayout1.removeTag(position); + if (position < mTagContainerLayout1.getChildCount()) { + mTagContainerLayout1.removeTag(position); + } } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { From 073800fe592fb480f910ca8776e81138824c81de Mon Sep 17 00:00:00 2001 From: whilu Date: Thu, 1 Jun 2017 23:05:16 +0800 Subject: [PATCH 21/53] add attribute for TagView background --- .../androidtagview/TagContainerLayout.java | 25 +++++++++++++++++++ androidtagview/src/main/res/values/attrs.xml | 1 + 2 files changed, 26 insertions(+) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index 31c2870..a8516d2 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -7,6 +7,7 @@ import android.graphics.Paint; import android.graphics.RectF; import android.graphics.Typeface; +import android.support.annotation.DrawableRes; import android.support.v4.widget.ViewDragHelper; import android.util.AttributeSet; import android.view.Gravity; @@ -237,6 +238,11 @@ public class TagContainerLayout extends ViewGroup { */ private float mCrossLineWidth = 1.0f; + /** + * TagView background resource + */ + private int mTagBackgroundResource; + public TagContainerLayout(Context context) { this(context, null); } @@ -305,6 +311,8 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr) { dp2px(context, mCrossLineWidth)); mTagSupportLettersRTL = attributes.getBoolean(R.styleable.AndroidTagView_tag_support_letters_rlt, mTagSupportLettersRTL); + mTagBackgroundResource = attributes.getResourceId(R.styleable.AndroidTagView_tag_background, + mTagBackgroundResource); attributes.recycle(); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); @@ -550,6 +558,7 @@ private void initTagView(TagView tagView, int position) { tagView.setCrossColor(mCrossColor); tagView.setCrossLineWidth(mCrossLineWidth); tagView.setTagSupportLettersRTL(mTagSupportLettersRTL); + tagView.setBackgroundResource(mTagBackgroundResource); } private void invalidateTags() { @@ -1405,4 +1414,20 @@ public TagView getTagView(int position){ } return (TagView) mChildViews.get(position); } + + /** + * Get TagView background resource + * @return + */ + public int getTagBackgroundResource() { + return mTagBackgroundResource; + } + + /** + * Set TagView background resource + * @param tagBackgroundResource + */ + public void setTagBackgroundResource(@DrawableRes int tagBackgroundResource) { + this.mTagBackgroundResource = tagBackgroundResource; + } } diff --git a/androidtagview/src/main/res/values/attrs.xml b/androidtagview/src/main/res/values/attrs.xml index dafc15e..6821af5 100644 --- a/androidtagview/src/main/res/values/attrs.xml +++ b/androidtagview/src/main/res/values/attrs.xml @@ -49,5 +49,6 @@ + \ No newline at end of file From ca1addf0a15c2caeaeaf9b6ce0066f8ef531b3ae Mon Sep 17 00:00:00 2001 From: whilu Date: Thu, 1 Jun 2017 23:19:02 +0800 Subject: [PATCH 22/53] release v1.1.4 --- README.md | 6 +++++- androidtagview/build.gradle | 4 ++-- .../co/lujun/androidtagview/ColorFactory.java | 16 ++++++++++++++++ .../lujun/androidtagview/TagContainerLayout.java | 16 ++++++++++++++++ .../java/co/lujun/androidtagview/TagView.java | 16 ++++++++++++++++ .../main/java/co/lujun/androidtagview/Utils.java | 16 ++++++++++++++++ 6 files changed, 71 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0c1e336..10cd713 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add below dependency in your **build.gradle** file. ```groovy dependencies { - compile 'co.lujun:androidtagview:1.1.3' + compile 'co.lujun:androidtagview:1.1.4' } ``` @@ -84,6 +84,7 @@ Now, you have successfully created some TagViews. The following will show some m | tag_cross_line_width | dimension | The cross line width(default 1dp) | tag_cross_area_padding | dimension | The padding of the cross area(default 10dp) | tag_support_letters_rlt | boolean | Whether to support 'letters show with RTL(eg: Android -> diordnA)' style(default false) +| tag_background | reference | TagView background resource(default none background) **You can set these attributes in layout file, or use setters(each attribute has get and set method) to set them.** @@ -208,6 +209,9 @@ mTagcontainerLayout.setTags(tags, colors); ## Change logs +### 1.1.4(2017-6-1) +- Add attribute for TagView background. + ### 1.1.3(2017-5-17) - Add ```getTagView(int position)``` method to get TagView in specified position. diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index dbbf3b1..b819a0e 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 9 targetSdkVersion 25 - versionCode 113 - versionName "1.1.3" + versionCode 114 + versionName "1.1.4" } buildTypes { release { diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/ColorFactory.java b/androidtagview/src/main/java/co/lujun/androidtagview/ColorFactory.java index e51a7ce..943813d 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/ColorFactory.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/ColorFactory.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 lujun + * + * 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. + */ + package co.lujun.androidtagview; import android.graphics.Color; diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index a8516d2..54ee53e 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 lujun + * + * 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. + */ + package co.lujun.androidtagview; import android.content.Context; diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index dfb39dd..9afd66d 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 lujun + * + * 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. + */ + package co.lujun.androidtagview; import android.animation.ValueAnimator; diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java b/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java index c059416..6691bcf 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 lujun + * + * 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. + */ + package co.lujun.androidtagview; import android.content.Context; From c3bc8cb3efb8bc9375cfd4b620c3ae7d6efcbea3 Mon Sep 17 00:00:00 2001 From: whilu Date: Mon, 3 Jul 2017 21:44:14 +0800 Subject: [PATCH 23/53] Update: README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 10cd713..1c2a557 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ Now, you have successfully created some TagViews. The following will show some m |theme|code|value|description |:---:|:---:|:---:|:---:| -| none | ColorFactory.NONE | -1 | If you customize TagView with your way, set this theme +| none | ColorFactory.NONE | -1 | **If you customize TagView with your way, set this theme** | random | ColorFactory.RANDOM | 0 | Create each TagView using random color | pure_cyan | ColorFactory.PURE_CYAN | 1 | All TagView created by pure cyan color | pure_teal | ColorFactory.PURE_TEAL | 2 | All TagView created by pure teal color From 472af7e47b28b6fff3cb92df3f27ea0c87f61068 Mon Sep 17 00:00:00 2001 From: whilu Date: Tue, 12 Sep 2017 22:42:29 +0800 Subject: [PATCH 24/53] Update Android support library to version 25.3.1 --- androidtagview/build.gradle | 2 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 ++-- sample/build.gradle | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index b819a0e..62e5883 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -21,6 +21,6 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:25.0.1' + compile 'com.android.support:appcompat-v7:25.3.1' } apply from: 'https://raw.githubusercontent.com/whilu/AndroidPublishLibrary/master/project/library/bintray_publish.gradle' \ No newline at end of file diff --git a/build.gradle b/build.gradle index 45efda8..dfdaff1 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' + classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c4e826c..284809d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Oct 30 18:08:28 CST 2016 +#Sun Sep 10 14:05:37 CST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/sample/build.gradle b/sample/build.gradle index 9435b08..2ba82e1 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -23,6 +23,6 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':androidtagview') testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:25.0.1' - compile 'com.android.support:design:25.0.1' + compile 'com.android.support:appcompat-v7:25.3.1' + compile 'com.android.support:design:25.3.1' } From d62e9b437e1900d302f657c0475fffe74cb0a7e6 Mon Sep 17 00:00:00 2001 From: Kamui Date: Tue, 12 Jun 2018 08:54:01 +0700 Subject: [PATCH 25/53] Make TagView selectable --- .../androidtagview/TagContainerLayout.java | 50 +++++++++++++++++++ .../java/co/lujun/androidtagview/TagView.java | 23 +++++++++ androidtagview/src/main/res/values/attrs.xml | 1 + 3 files changed, 74 insertions(+) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index 54ee53e..0c3d3aa 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -159,6 +159,11 @@ public class TagContainerLayout extends ViewGroup { */ private boolean isTagViewClickable; + /** + * Whether TagView can selectable(default unselectable) + */ + private boolean isTagViewSelectable; + /** * Tags */ @@ -314,6 +319,7 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr) { mTagTextColor = attributes.getColor(R.styleable.AndroidTagView_tag_text_color, mTagTextColor); mTagTextDirection = attributes.getInt(R.styleable.AndroidTagView_tag_text_direction, mTagTextDirection); isTagViewClickable = attributes.getBoolean(R.styleable.AndroidTagView_tag_clickable, false); + isTagViewSelectable = attributes.getBoolean(R.styleable.AndroidTagView_tag_selectable, false); mRippleColor = attributes.getColor(R.styleable.AndroidTagView_tag_ripple_color, Color.parseColor("#EEEEEE")); mRippleAlpha = attributes.getInteger(R.styleable.AndroidTagView_tag_ripple_alpha, mRippleAlpha); mRippleDuration = attributes.getInteger(R.styleable.AndroidTagView_tag_ripple_duration, mRippleDuration); @@ -563,6 +569,7 @@ private void initTagView(TagView tagView, int position) { tagView.setHorizontalPadding(mTagHorizontalPadding); tagView.setVerticalPadding(mTagVerticalPadding); tagView.setIsViewClickable(isTagViewClickable); + tagView.setIsViewSelectable(isTagViewSelectable); tagView.setBdDistance(mTagBdDistance); tagView.setOnTagClickListener(mOnTagClickListener); tagView.setRippleAlpha(mRippleAlpha); @@ -811,6 +818,31 @@ public void setOnTagClickListener(TagView.OnTagClickListener listener) { invalidateTags(); } + /** + * Toggle TagView's selected state. + * + * @param isSelected, position + */ + public void setTagViewSelectedState(boolean isSelected, int position) { + if (isTagViewSelectable) + ((TagView)mChildViews.get(position)).setIsViewSelected(isSelected); + } + + /** + * Return selected TagView + * + * @return list of selected positions + */ + public List getSelectedTagViewPositions() { + List selectedPositions = new ArrayList<>(); + for (int i = 0; i < mChildViews.size(); i++){ + if (((TagView)mChildViews.get(i)).getIsViewSelected()){ + selectedPositions.add(i); + } + } + return selectedPositions; + } + /** * Get TagView text. * @@ -1073,6 +1105,24 @@ public void setIsTagViewClickable(boolean clickable) { this.isTagViewClickable = clickable; } + /** + * Get TagView is selectable. + * + * @return + */ + public boolean getIsTagViewSelectable() { + return isTagViewSelectable; + } + + /** + * Set TagView is selectable + * + * @param selectable + */ + public void setIsTagViewSelectable(boolean selectable) { + this.isTagViewSelectable= selectable; + } + /** * Get TagView border width. * diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index 9afd66d..7dcf3de 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -66,6 +66,12 @@ public class TagView extends View { /** Whether this view clickable*/ private boolean isViewClickable; + /** Whether this view selectable*/ + private boolean isViewSelectable; + + /** Whether this view selected*/ + private boolean isViewSelected; + /** The max length for this tag view*/ private int mTagMaxLength; @@ -410,6 +416,10 @@ public boolean getIsViewClickable(){ return isViewClickable; } + public boolean getIsViewSelected(){ + return isViewSelected; + } + public void setTagMaxLength(int maxLength){ this.mTagMaxLength = maxLength; onDealText(); @@ -419,6 +429,10 @@ public void setOnTagClickListener(OnTagClickListener listener){ this.mOnTagClickListener = listener; } + public int getTagBackgroundColor(){ + return mBackgroundColor; + } + public void setTagBackgroundColor(int color){ this.mBackgroundColor = color; } @@ -456,6 +470,15 @@ public void setIsViewClickable(boolean clickable) { this.isViewClickable = clickable; } + public void setIsViewSelectable(boolean viewSelectable) { + isViewSelectable = viewSelectable; + } + + public void setIsViewSelected(boolean isSelected) { + if (isViewSelectable) + this.isViewSelected = isSelected; + } + public interface OnTagClickListener{ void onTagClick(int position, String text); void onTagLongClick(int position, String text); diff --git a/androidtagview/src/main/res/values/attrs.xml b/androidtagview/src/main/res/values/attrs.xml index 6821af5..098f9a9 100644 --- a/androidtagview/src/main/res/values/attrs.xml +++ b/androidtagview/src/main/res/values/attrs.xml @@ -28,6 +28,7 @@ + From 790bc519d009a492004ea783b62cf0d211325414 Mon Sep 17 00:00:00 2001 From: Kamui Date: Tue, 12 Jun 2018 09:07:23 +0700 Subject: [PATCH 26/53] Make test case for selectable tag in layout 3 --- .../java/co/lujun/sample/MainActivity.java | 107 ++++++++++++++---- sample/src/main/res/layout/content_main.xml | 5 +- 2 files changed, 91 insertions(+), 21 deletions(-) diff --git a/sample/src/main/java/co/lujun/sample/MainActivity.java b/sample/src/main/java/co/lujun/sample/MainActivity.java index 3253051..9401e0d 100644 --- a/sample/src/main/java/co/lujun/sample/MainActivity.java +++ b/sample/src/main/java/co/lujun/sample/MainActivity.java @@ -4,6 +4,8 @@ import android.content.Context; import android.content.DialogInterface; import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.RecyclerView; @@ -83,25 +85,37 @@ public void onTagClick(int position, String text) { @Override public void onTagLongClick(final int position, String text) { - AlertDialog dialog = new AlertDialog.Builder(MainActivity.this) - .setTitle("long click") - .setMessage("You will delete this tag!") - .setPositiveButton("Delete", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (position < mTagContainerLayout1.getChildCount()) { - mTagContainerLayout1.removeTag(position); - } - } - }) - .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }) - .create(); - dialog.show(); +// AlertDialog dialog = new AlertDialog.Builder(MainActivity.this) +// .setTitle("long click") +// .setMessage("You will delete this tag!") +// .setPositiveButton("Delete", new DialogInterface.OnClickListener() { +// @Override +// public void onClick(DialogInterface dialog, int which) { +// if (position < mTagContainerLayout1.getChildCount()) { +// mTagContainerLayout1.removeTag(position); +// } +// } +// }) +// .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { +// @Override +// public void onClick(DialogInterface dialog, int which) { +// dialog.dismiss(); +// } +// }) +// .create(); +// dialog.show(); + mTagContainerLayout1.setTagViewSelectedState(true, position); + + TagView tagView = (TagView)mTagContainerLayout1.getChildAt(position); + int color = tagView.getTagBackgroundColor(); + color = manipulateColor(color,0.3f); + //tagView.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN); + tagView.setTagBackgroundColor(color); + tagView.invalidate(); + + List selectedPositions = mTagContainerLayout1.getSelectedTagViewPositions(); + Toast.makeText(MainActivity.this, "selected-positions:" + selectedPositions.toString(), + Toast.LENGTH_SHORT).show(); } @Override @@ -112,6 +126,50 @@ public void onTagCrossClick(int position) { } }); + mTagContainerLayout3.setOnTagClickListener(new TagView.OnTagClickListener() { + @Override + public void onTagClick(int position, String text) { + } + + @Override + public void onTagLongClick(final int position, String text) { +// AlertDialog dialog = new AlertDialog.Builder(MainActivity.this) +// .setTitle("long click") +// .setMessage("You will delete this tag!") +// .setPositiveButton("Delete", new DialogInterface.OnClickListener() { +// @Override +// public void onClick(DialogInterface dialog, int which) { +// if (position < mTagContainerLayout1.getChildCount()) { +// mTagContainerLayout1.removeTag(position); +// } +// } +// }) +// .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { +// @Override +// public void onClick(DialogInterface dialog, int which) { +// dialog.dismiss(); +// } +// }) +// .create(); +// dialog.show(); + mTagContainerLayout3.setTagViewSelectedState(true, position); + + TagView tagView = (TagView)mTagContainerLayout3.getChildAt(position); + int color = tagView.getTagBackgroundColor(); + color = manipulateColor(color,0.3f); + tagView.setTagBackgroundColor(color); + tagView.invalidate(); + + List selectedPositions = mTagContainerLayout3.getSelectedTagViewPositions(); + Toast.makeText(MainActivity.this, "selected-positions:" + selectedPositions.toString(), + Toast.LENGTH_SHORT).show(); + } + + @Override + public void onTagCrossClick(int position) { + } + }); + // Custom settings // mTagContainerLayout1.setTagMaxLength(4); @@ -172,6 +230,17 @@ public void onClick(View v) { // recyclerView.setAdapter(adapter); } + public int manipulateColor(int color, float factor) { + int a = Color.alpha(color); + int r = Math.round(Color.red(color) * factor); + int g = Math.round(Color.green(color) * factor); + int b = Math.round(Color.blue(color) * factor); + return Color.argb(a, + Math.min(r,255), + Math.min(g,255), + Math.min(b,255)); + } + public class TagRecyclerViewAdapter extends RecyclerView.Adapter { diff --git a/sample/src/main/res/layout/content_main.xml b/sample/src/main/res/layout/content_main.xml index 70c532b..24d98fd 100644 --- a/sample/src/main/res/layout/content_main.xml +++ b/sample/src/main/res/layout/content_main.xml @@ -88,14 +88,15 @@ app:container_border_radius="0dp" app:container_gravity="right" app:horizontal_interval="10dp" - app:tag_background_color="#00000000" + app:tag_background_color="#FFFFFFFF" app:tag_border_color="#330000ff" app:tag_border_width="1dp" - app:tag_clickable="false" + app:tag_clickable="true" app:tag_corner_radius="1dp" app:tag_enable_cross="true" app:tag_horizontal_padding="15dp" app:tag_max_length="18" + app:tag_selectable="true" app:tag_text_color="#ff666666" app:tag_text_direction="rtl" app:tag_text_size="14sp" From c1fa0fd7c00a507905defd454b79ad6619797ebd Mon Sep 17 00:00:00 2001 From: Kamui Date: Tue, 12 Jun 2018 09:10:11 +0700 Subject: [PATCH 27/53] remove unnecessary code --- .../java/co/lujun/sample/MainActivity.java | 69 +++++-------------- 1 file changed, 19 insertions(+), 50 deletions(-) diff --git a/sample/src/main/java/co/lujun/sample/MainActivity.java b/sample/src/main/java/co/lujun/sample/MainActivity.java index 9401e0d..8a68920 100644 --- a/sample/src/main/java/co/lujun/sample/MainActivity.java +++ b/sample/src/main/java/co/lujun/sample/MainActivity.java @@ -85,37 +85,25 @@ public void onTagClick(int position, String text) { @Override public void onTagLongClick(final int position, String text) { -// AlertDialog dialog = new AlertDialog.Builder(MainActivity.this) -// .setTitle("long click") -// .setMessage("You will delete this tag!") -// .setPositiveButton("Delete", new DialogInterface.OnClickListener() { -// @Override -// public void onClick(DialogInterface dialog, int which) { -// if (position < mTagContainerLayout1.getChildCount()) { -// mTagContainerLayout1.removeTag(position); -// } -// } -// }) -// .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { -// @Override -// public void onClick(DialogInterface dialog, int which) { -// dialog.dismiss(); -// } -// }) -// .create(); -// dialog.show(); - mTagContainerLayout1.setTagViewSelectedState(true, position); - - TagView tagView = (TagView)mTagContainerLayout1.getChildAt(position); - int color = tagView.getTagBackgroundColor(); - color = manipulateColor(color,0.3f); - //tagView.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN); - tagView.setTagBackgroundColor(color); - tagView.invalidate(); - - List selectedPositions = mTagContainerLayout1.getSelectedTagViewPositions(); - Toast.makeText(MainActivity.this, "selected-positions:" + selectedPositions.toString(), - Toast.LENGTH_SHORT).show(); + AlertDialog dialog = new AlertDialog.Builder(MainActivity.this) + .setTitle("long click") + .setMessage("You will delete this tag!") + .setPositiveButton("Delete", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (position < mTagContainerLayout1.getChildCount()) { + mTagContainerLayout1.removeTag(position); + } + } + }) + .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }) + .create(); + dialog.show(); } @Override @@ -133,25 +121,6 @@ public void onTagClick(int position, String text) { @Override public void onTagLongClick(final int position, String text) { -// AlertDialog dialog = new AlertDialog.Builder(MainActivity.this) -// .setTitle("long click") -// .setMessage("You will delete this tag!") -// .setPositiveButton("Delete", new DialogInterface.OnClickListener() { -// @Override -// public void onClick(DialogInterface dialog, int which) { -// if (position < mTagContainerLayout1.getChildCount()) { -// mTagContainerLayout1.removeTag(position); -// } -// } -// }) -// .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { -// @Override -// public void onClick(DialogInterface dialog, int which) { -// dialog.dismiss(); -// } -// }) -// .create(); -// dialog.show(); mTagContainerLayout3.setTagViewSelectedState(true, position); TagView tagView = (TagView)mTagContainerLayout3.getChildAt(position); From 7d4e933b49df474ce20f8e10af09dd6545b05de6 Mon Sep 17 00:00:00 2001 From: Kamui Date: Tue, 12 Jun 2018 10:10:09 +0700 Subject: [PATCH 28/53] move some select logic from sample module to the library --- .../androidtagview/TagContainerLayout.java | 20 ++++++++++--- .../java/co/lujun/androidtagview/TagView.java | 29 ++++++++++++++++--- .../java/co/lujun/androidtagview/Utils.java | 19 ++++++++++++ .../java/co/lujun/sample/MainActivity.java | 18 +----------- 4 files changed, 61 insertions(+), 25 deletions(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index 0c3d3aa..9e1d6f0 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -558,6 +558,8 @@ private void initTagView(TagView tagView, int position) { } tagView.setTagBackgroundColor(colors[0]); + //TODO make selectedBackgroundColorSelectable configurable + tagView.setTagSelectedBackgroundColor(Utils.manipulateColorBrigthness(colors[0], 0.5f)); tagView.setTagBorderColor(colors[1]); tagView.setTagTextColor(colors[2]); tagView.setTagMaxLength(mTagMaxLength); @@ -819,13 +821,23 @@ public void setOnTagClickListener(TagView.OnTagClickListener listener) { } /** - * Toggle TagView's selected state. + * Select a tag * - * @param isSelected, position + * @param position + */ + public void selectTagView(int position) { + if (isTagViewSelectable) + ((TagView)mChildViews.get(position)).selectView(); + } + + /** + * Unselect a tag + * + * @param position */ - public void setTagViewSelectedState(boolean isSelected, int position) { + public void unselectTagView(int position) { if (isTagViewSelectable) - ((TagView)mChildViews.get(position)).setIsViewSelected(isSelected); + ((TagView)mChildViews.get(position)).unselectView(); } /** diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index 7dcf3de..5f46349 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -60,6 +60,9 @@ public class TagView extends View { /** TagView background color*/ private int mBackgroundColor; + /** TagView background color*/ + private int mSelectedBackgroundColor; + /** TagView text color*/ private int mTextColor; @@ -207,7 +210,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { protected void onDraw(Canvas canvas) { // draw background mPaint.setStyle(Paint.Style.FILL); - mPaint.setColor(mBackgroundColor); + mPaint.setColor(getIsViewSelected() ? mSelectedBackgroundColor : mBackgroundColor); canvas.drawRoundRect(mRectF, mBorderRadius, mBorderRadius, mPaint); // draw border @@ -433,10 +436,18 @@ public int getTagBackgroundColor(){ return mBackgroundColor; } + public int getTagSelectedBackgroundColor(){ + return mSelectedBackgroundColor; + } + public void setTagBackgroundColor(int color){ this.mBackgroundColor = color; } + public void setTagSelectedBackgroundColor(int color){ + this.mSelectedBackgroundColor = color; + } + public void setTagBorderColor(int color){ this.mBorderColor = color; } @@ -474,9 +485,19 @@ public void setIsViewSelectable(boolean viewSelectable) { isViewSelectable = viewSelectable; } - public void setIsViewSelected(boolean isSelected) { - if (isViewSelectable) - this.isViewSelected = isSelected; + //TODO change background color + public void selectView() { + if (isViewSelectable && !getIsViewSelected()) { + this.isViewSelected = true; + postInvalidate(); + } + } + + public void unselectView() { + if (isViewSelectable && getIsViewSelected()) { + this.isViewSelected = false; + postInvalidate(); + } } public interface OnTagClickListener{ diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java b/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java index 6691bcf..c63ba6a 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java @@ -17,6 +17,7 @@ package co.lujun.androidtagview; import android.content.Context; +import android.graphics.Color; /** * Author: lujun(http://blog.lujun.co) @@ -34,4 +35,22 @@ public static float sp2px(Context context, float sp) { final float scale = context.getResources().getDisplayMetrics().scaledDensity; return sp * scale; } + + /** + *Manipulate Birghtness of color + * + * @params color in int, brightness factor + * + * @return int + */ + public static int manipulateColorBrigthness(int color, float factor) { + int a = Color.alpha(color); + int r = Math.round(Color.red(color) * factor); + int g = Math.round(Color.green(color) * factor); + int b = Math.round(Color.blue(color) * factor); + return Color.argb(a, + Math.min(r,255), + Math.min(g,255), + Math.min(b,255)); + } } diff --git a/sample/src/main/java/co/lujun/sample/MainActivity.java b/sample/src/main/java/co/lujun/sample/MainActivity.java index 8a68920..ddfa9b0 100644 --- a/sample/src/main/java/co/lujun/sample/MainActivity.java +++ b/sample/src/main/java/co/lujun/sample/MainActivity.java @@ -121,13 +121,7 @@ public void onTagClick(int position, String text) { @Override public void onTagLongClick(final int position, String text) { - mTagContainerLayout3.setTagViewSelectedState(true, position); - - TagView tagView = (TagView)mTagContainerLayout3.getChildAt(position); - int color = tagView.getTagBackgroundColor(); - color = manipulateColor(color,0.3f); - tagView.setTagBackgroundColor(color); - tagView.invalidate(); + mTagContainerLayout3.selectTagView(position); List selectedPositions = mTagContainerLayout3.getSelectedTagViewPositions(); Toast.makeText(MainActivity.this, "selected-positions:" + selectedPositions.toString(), @@ -199,16 +193,6 @@ public void onClick(View v) { // recyclerView.setAdapter(adapter); } - public int manipulateColor(int color, float factor) { - int a = Color.alpha(color); - int r = Math.round(Color.red(color) * factor); - int g = Math.round(Color.green(color) * factor); - int b = Math.round(Color.blue(color) * factor); - return Color.argb(a, - Math.min(r,255), - Math.min(g,255), - Math.min(b,255)); - } public class TagRecyclerViewAdapter extends RecyclerView.Adapter { From f578f6ac02214ed4bb5b3d8adefd0cc2b2c1f0fe Mon Sep 17 00:00:00 2001 From: Kamui Date: Tue, 12 Jun 2018 10:15:10 +0700 Subject: [PATCH 29/53] add toggle select tag method --- .../lujun/androidtagview/TagContainerLayout.java | 16 ++++++++++++++++ .../main/java/co/lujun/sample/MainActivity.java | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index 9e1d6f0..dab44e1 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -820,6 +820,22 @@ public void setOnTagClickListener(TagView.OnTagClickListener listener) { invalidateTags(); } + /** + * Toggle select a tag + * + * @param position + */ + public void toggleSelectTagView(int position) { + if (isTagViewSelectable){ + TagView tagView = ((TagView)mChildViews.get(position)); + if (tagView.getIsViewSelected()){ + unselectTagView(position); + } else { + selectTagView(position); + } + } + } + /** * Select a tag * diff --git a/sample/src/main/java/co/lujun/sample/MainActivity.java b/sample/src/main/java/co/lujun/sample/MainActivity.java index ddfa9b0..a92f62f 100644 --- a/sample/src/main/java/co/lujun/sample/MainActivity.java +++ b/sample/src/main/java/co/lujun/sample/MainActivity.java @@ -121,7 +121,7 @@ public void onTagClick(int position, String text) { @Override public void onTagLongClick(final int position, String text) { - mTagContainerLayout3.selectTagView(position); + mTagContainerLayout3.toggleSelectTagView(position); List selectedPositions = mTagContainerLayout3.getSelectedTagViewPositions(); Toast.makeText(MainActivity.this, "selected-positions:" + selectedPositions.toString(), From 7c81776964a1a3ecc54c74fa1a335cc96430a941 Mon Sep 17 00:00:00 2001 From: Kamui Date: Tue, 12 Jun 2018 10:47:04 +0700 Subject: [PATCH 30/53] fix spelling --- .../co/lujun/androidtagview/TagContainerLayout.java | 10 +++++----- .../src/main/java/co/lujun/androidtagview/TagView.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index dab44e1..5df1811 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -829,9 +829,9 @@ public void toggleSelectTagView(int position) { if (isTagViewSelectable){ TagView tagView = ((TagView)mChildViews.get(position)); if (tagView.getIsViewSelected()){ - unselectTagView(position); + tagView.deselectView(); } else { - selectTagView(position); + tagView.selectView(); } } } @@ -847,13 +847,13 @@ public void selectTagView(int position) { } /** - * Unselect a tag + * Deselect a tag * * @param position */ - public void unselectTagView(int position) { + public void deselectTagView(int position) { if (isTagViewSelectable) - ((TagView)mChildViews.get(position)).unselectView(); + ((TagView)mChildViews.get(position)).deselectView(); } /** diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index 5f46349..426de42 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -493,7 +493,7 @@ public void selectView() { } } - public void unselectView() { + public void deselectView() { if (isViewSelectable && getIsViewSelected()) { this.isViewSelected = false; postInvalidate(); From c3bc26e380f222d29022caa1277a296c917974bf Mon Sep 17 00:00:00 2001 From: Kamui Date: Tue, 12 Jun 2018 10:55:20 +0700 Subject: [PATCH 31/53] deselect all tags when click on an unselected tag --- .../src/main/java/co/lujun/sample/MainActivity.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sample/src/main/java/co/lujun/sample/MainActivity.java b/sample/src/main/java/co/lujun/sample/MainActivity.java index a92f62f..c7a9fc9 100644 --- a/sample/src/main/java/co/lujun/sample/MainActivity.java +++ b/sample/src/main/java/co/lujun/sample/MainActivity.java @@ -117,6 +117,18 @@ public void onTagCrossClick(int position) { mTagContainerLayout3.setOnTagClickListener(new TagView.OnTagClickListener() { @Override public void onTagClick(int position, String text) { + List selectedPositions = mTagContainerLayout3.getSelectedTagViewPositions(); + //deselect all tags when click on an unselected tag. Otherwise show toast. + if (selectedPositions.isEmpty() || selectedPositions.contains(position)){ + Toast.makeText(MainActivity.this, "click-position:" + position + ", text:" + text, + Toast.LENGTH_SHORT).show(); + } else { + //deselect all tags + for (int i : selectedPositions){ + mTagContainerLayout3.deselectTagView(i); + } + } + } @Override From a0c3782c3bc9f22268c42ee10bd6597853b32e42 Mon Sep 17 00:00:00 2001 From: Kamui Date: Tue, 12 Jun 2018 12:57:57 +0700 Subject: [PATCH 32/53] fix spelling --- androidtagview/src/main/java/co/lujun/androidtagview/Utils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java b/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java index c63ba6a..7997564 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java @@ -39,7 +39,7 @@ public static float sp2px(Context context, float sp) { /** *Manipulate Birghtness of color * - * @params color in int, brightness factor + * @param color in int, brightness factor * * @return int */ From d77e47f9dbddc8d37ab47335073b1bd4f5a5f588 Mon Sep 17 00:00:00 2001 From: Kamui Date: Tue, 12 Jun 2018 15:58:59 +0700 Subject: [PATCH 33/53] change shade of selected background to be less dark --- .../main/java/co/lujun/androidtagview/TagContainerLayout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index 5df1811..6b4945e 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -559,7 +559,7 @@ private void initTagView(TagView tagView, int position) { tagView.setTagBackgroundColor(colors[0]); //TODO make selectedBackgroundColorSelectable configurable - tagView.setTagSelectedBackgroundColor(Utils.manipulateColorBrigthness(colors[0], 0.5f)); + tagView.setTagSelectedBackgroundColor(Utils.manipulateColorBrigthness(colors[0], 0.7f)); tagView.setTagBorderColor(colors[1]); tagView.setTagTextColor(colors[2]); tagView.setTagMaxLength(mTagMaxLength); From ae8503bd4ca474cff4fa714d85416d4c5e5621f2 Mon Sep 17 00:00:00 2001 From: Kamui Date: Tue, 12 Jun 2018 16:07:15 +0700 Subject: [PATCH 34/53] add getSelectedTagViewText() --- androidtagview/build.gradle | 4 +++- .../androidtagview/TagContainerLayout.java | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index b819a0e..7b1d047 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -23,4 +23,6 @@ dependencies { testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:25.0.1' } -apply from: 'https://raw.githubusercontent.com/whilu/AndroidPublishLibrary/master/project/library/bintray_publish.gradle' \ No newline at end of file +//TODO fix bug apply from: 'https://raw.githubusercontent.com/whilu/AndroidPublishLibrary/master/project/library/bintray_publish.gradle' +//https://github.com/google/ExoPlayer/commit/13592dfb53ec99ce1fdb2744e34717dbdec9dea8 +//https://github.com/davideas/FlexibleAdapter/issues/579 \ No newline at end of file diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index 6b4945e..c762662 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -857,7 +857,7 @@ public void deselectTagView(int position) { } /** - * Return selected TagView + * Return selected TagView positions * * @return list of selected positions */ @@ -871,6 +871,22 @@ public List getSelectedTagViewPositions() { return selectedPositions; } + /** + * Return selected TagView text + * + * @return list of selected tag text + */ + public List getSelectedTagViewText() { + List selectedTagText = new ArrayList<>(); + for (int i = 0; i < mChildViews.size(); i++){ + TagView tagView = (TagView)mChildViews.get(i); + if ((tagView.getIsViewSelected())){ + selectedTagText.add(tagView.getText()); + } + } + return selectedTagText; + } + /** * Get TagView text. * From dc1a07f90e61b4b63f5db718c6dbf82f8972b103 Mon Sep 17 00:00:00 2001 From: Kamui Date: Thu, 14 Jun 2018 09:16:44 +0700 Subject: [PATCH 35/53] update to newer gradle and sdk version --- androidtagview/build.gradle | 14 +++++++------- build.gradle | 4 +++- gradle/wrapper/gradle-wrapper.properties | 4 ++-- sample/build.gradle | 18 +++++++++--------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index 7b1d047..6fffe2f 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 25 - buildToolsVersion "25.0.0" + compileSdkVersion 27 + buildToolsVersion '27.0.3' defaultConfig { - minSdkVersion 9 - targetSdkVersion 25 + minSdkVersion 14 + targetSdkVersion 27 versionCode 114 versionName "1.1.4" } @@ -19,9 +19,9 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:25.0.1' + implementation fileTree(dir: 'libs', include: ['*.jar']) + testImplementation 'junit:junit:4.12' + implementation 'com.android.support:appcompat-v7:27.1.1' } //TODO fix bug apply from: 'https://raw.githubusercontent.com/whilu/AndroidPublishLibrary/master/project/library/bintray_publish.gradle' //https://github.com/google/ExoPlayer/commit/13592dfb53ec99ce1fdb2744e34717dbdec9dea8 diff --git a/build.gradle b/build.gradle index 45efda8..cd5647f 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' + classpath 'com.android.tools.build:gradle:3.1.3' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' @@ -17,6 +18,7 @@ buildscript { allprojects { repositories { jcenter() + google() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c4e826c..52aba3d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Oct 30 18:08:28 CST 2016 +#Thu Jun 14 09:04:10 ICT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/sample/build.gradle b/sample/build.gradle index 9435b08..1ac8d94 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.0" + compileSdkVersion 27 + buildToolsVersion "27.0.3" defaultConfig { applicationId "co.lujun.sample" - minSdkVersion 9 - targetSdkVersion 25 + minSdkVersion 14 + targetSdkVersion 27 versionCode 1 versionName "1.0" } @@ -20,9 +20,9 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile project(':androidtagview') - testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:25.0.1' - compile 'com.android.support:design:25.0.1' + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation project(':androidtagview') + testImplementation 'junit:junit:4.12' + implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.android.support:design:27.1.1' } From caf6b35a81675b6b4c7a0dd90e2413cc191c230d Mon Sep 17 00:00:00 2001 From: Kamui Date: Sun, 17 Jun 2018 10:43:10 +0700 Subject: [PATCH 36/53] add function to return size of the layout --- .../java/co/lujun/androidtagview/TagContainerLayout.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index c762662..c6da37d 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -887,6 +887,15 @@ public List getSelectedTagViewText() { return selectedTagText; } + /** + * Return number of child tags + * + * @return size + */ + public int size() { + return mChildViews.size(); + } + /** * Get TagView text. * From bfe178fe7cbe25555d918539e40277f2e8cfcd9b Mon Sep 17 00:00:00 2001 From: Kamui Date: Sun, 17 Jun 2018 14:42:36 +0700 Subject: [PATCH 37/53] add onSelectedTagDrag() method to drag selected tag --- .../src/main/java/co/lujun/androidtagview/TagView.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index 426de42..dd5d3b0 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -266,8 +266,8 @@ public boolean dispatchTouchEvent(MotionEvent event) { break; case MotionEvent.ACTION_MOVE: - if (Math.abs(mLastY - y) > mSlopThreshold - || Math.abs(mLastX - x) > mSlopThreshold){ + if (!isViewSelected && (Math.abs(mLastY - y) > mSlopThreshold + || Math.abs(mLastX - x) > mSlopThreshold)){ if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(false); } @@ -313,6 +313,9 @@ public boolean onTouchEvent(MotionEvent event) { } if (Math.abs(mLastX - x) > mMoveSlop || Math.abs(mLastY - y) > mMoveSlop){ isMoved = true; + if (isViewSelected){ + mOnTagClickListener.onSelectedTagDrag((int) getTag(), getText()); + } } break; @@ -503,6 +506,7 @@ public void deselectView() { public interface OnTagClickListener{ void onTagClick(int position, String text); void onTagLongClick(int position, String text); + void onSelectedTagDrag(int position, String text); void onTagCrossClick(int position); } From 85832b62cec0c8dd1b830b7a9f4605813039da01 Mon Sep 17 00:00:00 2001 From: Kamui Date: Sun, 17 Jun 2018 14:51:48 +0700 Subject: [PATCH 38/53] add onSelectedTagDrag() to sample app --- .../java/co/lujun/sample/MainActivity.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/sample/src/main/java/co/lujun/sample/MainActivity.java b/sample/src/main/java/co/lujun/sample/MainActivity.java index c7a9fc9..5efb065 100644 --- a/sample/src/main/java/co/lujun/sample/MainActivity.java +++ b/sample/src/main/java/co/lujun/sample/MainActivity.java @@ -1,11 +1,10 @@ package co.lujun.sample; import android.app.AlertDialog; +import android.content.ClipData; import android.content.Context; import android.content.DialogInterface; import android.graphics.Color; -import android.graphics.PorterDuff; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.RecyclerView; @@ -106,6 +105,10 @@ public void onClick(DialogInterface dialog, int which) { dialog.show(); } + @Override + public void onSelectedTagDrag(int position, String text) { + } + @Override public void onTagCrossClick(int position) { // mTagContainerLayout1.removeTag(position); @@ -119,12 +122,12 @@ public void onTagCrossClick(int position) { public void onTagClick(int position, String text) { List selectedPositions = mTagContainerLayout3.getSelectedTagViewPositions(); //deselect all tags when click on an unselected tag. Otherwise show toast. - if (selectedPositions.isEmpty() || selectedPositions.contains(position)){ + if (selectedPositions.isEmpty() || selectedPositions.contains(position)) { Toast.makeText(MainActivity.this, "click-position:" + position + ", text:" + text, Toast.LENGTH_SHORT).show(); } else { //deselect all tags - for (int i : selectedPositions){ + for (int i : selectedPositions) { mTagContainerLayout3.deselectTagView(i); } } @@ -140,6 +143,14 @@ public void onTagLongClick(final int position, String text) { Toast.LENGTH_SHORT).show(); } + @Override + public void onSelectedTagDrag(int position, String text) { + ClipData clip = ClipData.newPlainText("Text", text); + View view = mTagContainerLayout3.getTagView(position); + View.DragShadowBuilder shadow = new View.DragShadowBuilder(view); + view.startDrag(clip, shadow, Boolean.TRUE, 0); + } + @Override public void onTagCrossClick(int position) { } From 0eb6a8892450cf437b54b55773e5a5ec4fcb1765 Mon Sep 17 00:00:00 2001 From: Do Tuan Anh Date: Tue, 10 Jul 2018 17:22:15 +0700 Subject: [PATCH 39/53] add method to remove TagView in multiple consecutive positions --- .../androidtagview/TagContainerLayout.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index c6da37d..0e3270b 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -33,6 +33,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import static co.lujun.androidtagview.Utils.dp2px; @@ -605,6 +606,21 @@ private void onRemoveTag(int position) { // TODO, make removed view null? } + private void onRemoveConsecutiveTags(List positions) { + int smallestPosition = Collections.min(positions); + for (int position : positions) { + if (position < 0 || position >= mChildViews.size()) { + throw new RuntimeException("Illegal position!"); + } + mChildViews.remove(smallestPosition); + removeViewAt(smallestPosition); + } + for (int i = smallestPosition; i < mChildViews.size(); i++) { + mChildViews.get(i).setTag(i); + } + // TODO, make removed view null? + } + private int[] onGetNewPosition(View view) { int left = view.getLeft(); int top = view.getTop(); @@ -801,6 +817,16 @@ public void removeTag(int position) { postInvalidate(); } + /** + * Remove TagView in multiple consecutive positions. + * + * + */ + public void removeConsecutiveTags(List positions) { + onRemoveConsecutiveTags(positions); + postInvalidate(); + } + /** * Remove all TagViews. */ From 037e752005f594bfe4bec24ae14e516e47c9e58d Mon Sep 17 00:00:00 2001 From: Matt Cleinman Date: Wed, 15 Aug 2018 16:16:19 -0700 Subject: [PATCH 40/53] images working --- .../androidtagview/TagContainerLayout.java | 30 +++++++++++++++- .../java/co/lujun/androidtagview/TagView.java | 34 ++++++++++++++++++ sample/build.gradle | 6 ++++ sample/src/main/AndroidManifest.xml | 2 +- .../java/co/lujun/sample/MainActivity.java | 20 +++++++++++ .../src/main/res/drawable/yellow_avatar.png | Bin 0 -> 4577 bytes 6 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 sample/src/main/res/drawable/yellow_avatar.png diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index 54ee53e..605b3a4 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -164,6 +164,11 @@ public class TagContainerLayout extends ViewGroup { */ private List mTags; + /** + * Default image for new tags + */ + private int mDefaultImageDrawableID = -1; + /** * Can drag TagView(default false) */ @@ -525,7 +530,12 @@ private void onAddTag(String text, int position) { if (position < 0 || position > mChildViews.size()) { throw new RuntimeException("Illegal position!"); } - TagView tagView = new TagView(getContext(), text); + TagView tagView; + if (mDefaultImageDrawableID != -1) { + tagView = new TagView(getContext(), text, mDefaultImageDrawableID); + } else { + tagView = new TagView(getContext(), text); + } initTagView(tagView, position); mChildViews.add(position, tagView); if (position < mChildViews.size()) { @@ -1000,6 +1010,24 @@ public void setSensitivity(float sensitivity) { this.mSensitivity = sensitivity; } + /** + * Get default tag image + * + * @return + */ + public int getDefaultImageDrawableID() { + return mDefaultImageDrawableID; + } + + /** + * Set default image for tags. + * + * @param imageID + */ + public void setDefaultImageDrawableID(int imageID) { + this.mDefaultImageDrawableID = imageID; + } + /** * Set max line count for TagContainerLayout * diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index 9afd66d..a75f402 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -19,11 +19,15 @@ import android.animation.ValueAnimator; import android.annotation.TargetApi; import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapShader; +import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; import android.graphics.Region; +import android.graphics.Shader; import android.graphics.Typeface; import android.os.Build; import android.support.v4.widget.ViewDragHelper; @@ -119,6 +123,8 @@ public class TagView extends View { private ValueAnimator mRippleValueAnimator; + private Bitmap mBitmapImage; + private boolean mEnableCross; private float mCrossAreaWidth; @@ -149,6 +155,12 @@ public TagView(Context context, String text){ init(context, text); } + public TagView(Context context, String text, int defaultImageID){ + super(context); + init(context, text); + mBitmapImage = BitmapFactory.decodeResource(getResources(), defaultImageID); + } + private void init(Context context, String text){ mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mRipplePaint = new Paint(Paint.ANTI_ALIAS_FLAG); @@ -239,6 +251,9 @@ protected void onDraw(Canvas canvas) { // draw cross drawCross(canvas); + + // draw image + drawImage(canvas); } @Override @@ -326,6 +341,18 @@ private boolean isClickCrossArea(MotionEvent event){ return event.getX() >= getWidth() - mCrossAreaWidth; } + private void drawImage(Canvas canvas){ + if (isEnableImage()) { + Bitmap scaledImageBitmap = Bitmap.createScaledBitmap(mBitmapImage, Math.round(getHeight() - mBorderWidth), Math.round(getHeight() - mBorderWidth), false); + + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setShader(new BitmapShader(scaledImageBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); + RectF rect = new RectF(mBorderWidth, mBorderWidth, getHeight() - mBorderWidth, getHeight() - mBorderWidth); + canvas.drawRoundRect(rect, rect.height()/2, rect.height()/2, paint); + } + } + private void drawCross(Canvas canvas){ if (isEnableCross()){ mCrossAreaPadding = mCrossAreaPadding > getHeight() / 2 ? getHeight() / 2 : @@ -456,6 +483,11 @@ public void setIsViewClickable(boolean clickable) { this.isViewClickable = clickable; } + public void setImage(Bitmap newImage) { + this.mBitmapImage = newImage; + this.invalidate(); + } + public interface OnTagClickListener{ void onTagClick(int position, String text); void onTagLongClick(int position, String text); @@ -491,6 +523,8 @@ public void setBdDistance(float bdDistance) { this.bdDistance = bdDistance; } + public boolean isEnableImage() { return mBitmapImage != null; } + public boolean isEnableCross() { return mEnableCross; } diff --git a/sample/build.gradle b/sample/build.gradle index 9435b08..560f4c3 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -19,10 +19,16 @@ android { } } +repositories { + mavenCentral() + maven { url 'https://maven.google.com' } +} + dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':androidtagview') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:25.0.1' compile 'com.android.support:design:25.0.1' + compile 'com.github.bumptech.glide:glide:4.1.1' } diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index b96d3e8..e56e5f9 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -19,5 +19,5 @@ - + diff --git a/sample/src/main/java/co/lujun/sample/MainActivity.java b/sample/src/main/java/co/lujun/sample/MainActivity.java index 3253051..796b22e 100644 --- a/sample/src/main/java/co/lujun/sample/MainActivity.java +++ b/sample/src/main/java/co/lujun/sample/MainActivity.java @@ -3,6 +3,7 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; +import android.graphics.Bitmap; import android.graphics.Color; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; @@ -21,6 +22,10 @@ import co.lujun.androidtagview.TagContainerLayout; import co.lujun.androidtagview.TagView; +import com.bumptech.glide.Glide; +import com.bumptech.glide.request.transition.Transition; +import com.bumptech.glide.request.target.SimpleTarget; + public class MainActivity extends AppCompatActivity { private TagContainerLayout mTagContainerLayout1, mTagContainerLayout2, @@ -73,6 +78,8 @@ protected void onCreate(Bundle savedInstanceState) { mTagContainerLayout4 = (TagContainerLayout) findViewById(R.id.tagcontainerLayout4); mTagcontainerLayout5 = (TagContainerLayout) findViewById(R.id.tagcontainerLayout5); + mTagContainerLayout1.setDefaultImageDrawableID(R.drawable.yellow_avatar); + // Set custom click listener mTagContainerLayout1.setOnTagClickListener(new TagView.OnTagClickListener() { @Override @@ -132,6 +139,19 @@ public void onTagCrossClick(int position) { // After you set your own attributes for TagView, then set tag(s) or add tag(s) mTagContainerLayout1.setTags(list1); + for (int i=0; i() { + @Override + public void onResourceReady(Bitmap resource, Transition transition) { + mTagContainerLayout1.getTagView(index).setImage(resource); + } + }); + } + mTagContainerLayout2.setTags(list2); mTagContainerLayout3.setTags(list3); mTagContainerLayout4.setTags(list4); diff --git a/sample/src/main/res/drawable/yellow_avatar.png b/sample/src/main/res/drawable/yellow_avatar.png new file mode 100644 index 0000000000000000000000000000000000000000..605a8e794e969f5b22a0ff64bcd0146297b5b6d5 GIT binary patch literal 4577 zcmbtYc{o(<|E5N^EQLYJ`dTtWQ7CKC$d=t0`e*SSAcbB>VU1{a(NS-s}2a*YA&WpYxpMIiJsYp3i;X&xtiRz0SpPii3%XiObO7 znk5qxbJF3)b_6)XLw%hN?1Y10h#)J!TS0eS1JF!Y-TY8!aYJ8MceEwi)h*P&6RpX_ zbmF1mwX4?m#u-!{pXZ~KA68}BC^9lKwXs(WJd@;ukKdG4o-|$PSikk?>{FBTDY3~W z=pGFv)lXlPGUZ7h0)inn7=2yXBTyl?DtGkeOHIeyuXl}!GxUDClpD*!A~-W}Eut@U zw?(*auV#bg3i!Clkt;+d5GOB`iE@M&`sWyc!(#wIod4s+|M|v$dqqd8RP=*~!V8m$ zI;*f?`t1euOy0rHig}|=R{S~jg0$Z^nNC2rbJue%A|hp*tXC!zM@NgdPa9TAx@v@% z6Qtbhn}hXwW4Nf16UrRBPLGO5>&<=7<5T(U`N69$xJ52CtPkeh#8yZn3~)XY|G-}|_T7cmih{B>e&{92=Z*M93|btK??iZe zs<^A`Img~7`F{PXS5ko~*Rp=Ui+0Rpma=it+J_U~f8H6$6^d)RePNksP#G4EuJfm; z(KXDTcyFYOj#o5GDv010WCiLQk!Fz5jHpZE<{PbZM$3N0>tc%DpG_xh9D!cIj@tH)@V&>QcM3PgnBC)zfMDPSSmlmQ4eJtr|5cyuGiUt_^RtHjl?9tvv@(%-+wnYiu?KtxBlh=6=pvtbG>MxF7FtKyZ^OK`@N8 z=`EM?)66zbK%Fl)29MDz3LQ<73JqDXRENK^EP5WL%BTsm;J?LO_0vT^DLf6re>7Dk zZ*nCOI898_{CP_yOM>BhACU7cFIroKSt;_T)%UVZ@4@N$1tqwzd497H_(PAbxFUPMauVaO?$w zT!Pd0{j#Z<{H42hTt@h%5DCXqQIy<5{kqMFXC^DH{NYwG;@Sr)gfAX>8H&th;iO;9 z;9$Y0?lv9y6puu=rS6=1BSH!2Yz^WBH(FC`mzcll#x8_(TM`}plor_F**1oRqC#I*vi2^%n}n`iM;bMjMAL)%AA8oGOlB zVuP!`>w0^Pa!6=Eg6ajr50OA`BM|Tdq-!T?k)^w&bw~=~Nso}UN(2&1=q~-gNXl)O zlYvKp%VQtUl+|z9Ur}06+Gx89q;Of;o!3Mi7)akuWnll`JWFk|f;IBYQFVTMAIpi2JdF-njWLa{dW_CEorsc=Zjj6c7N!G)#|vphuRo+$P4s3~{NJpnD$&0uBW zjA1b$Aq7515BtQOC@uZQJxcxBK}vPh85BPpCr6O?6+u@ubl}-H!@ul^0Ui-S1LCQ0 z5JcpVg@R^HOp3lNV{l(u8@0naFU@*~2Y12@hyhCjB-oOMnQcz0`HVP1)$X&i#2;h_ ztJ+oBvZdSr12~fNa_1pwsZF9Dwe1)H%uJw5?Le746iqW+8UbrC5&`kWAklh(ZY#;z ziyg00mC2sEM23Ml+Dxd-r3(l|P;qA^nrAVsD*^BxJO+aQ0e4K*n#)Ar#%W zLmU*^*WR`FuGuXgN^r=5n>=l0JMS0UaUa4l7#P`9QJbD``^;>^e*_HOF0x2F@TJM> zD6gfVm~IMbbt@u%-{Ok^VaaFQ@6S&$x8z)gyN`ZcZdb@la;ofGTz`(0qV7b~@&NHN zz{TUvfRBDUowgIaCU`eNM?PBam=S?NGJnJ>jJC4&hQqJS#OTcbodyufj!j*>=S$hem)X%zmhE@ zgK#q$@>*ONoc$F~bAwn`YKJWVv%yS(4O}5@^IwSSAGzio8W4U~jOSH|(S@aOvVv|2 z2&;+zqkgNe2BM>_c4hfir0lp0 zIh`k=6dHLBV83=iR@Fa$`ALfLO6c*mnV+#Kx+a&VC-M`|!?MQb#_nxc zb+Lh2`RfUbKQ)qx0h^Hx`ebb#*W|+Ae6HhT;l5`sFZJ!T-e)_we%wt7q~@pCFk-=V#FWFXO@s6%R}hI-*TA*o@rW>K-MFeLcvx+ODvA zwbeg*p`3h-f|>#pvvD+grm`Zi5bz&iTlv5slphShL#s4`ay1!L?ny8q0tJW4Lz7pK)jG>NQ0au;)zh$mDD->vx{--o9GUjW8ltZ8|TLL0AS%e*EG#gMKd}BC$bS z5;0J|oJXhGG=Q+{fNw#`3Y5dJL#(vnqMr6X2yOUGnFuch^&`D_G*kJMSkeoKvu`~J z+YG1HIz&||kL;7C%tU6*@S62DTV?)1lhiOu?)RPI&SmMC_oAXgqt^wOYeCq_>>a=m z{j!P}5A=l#W`J3+{kWj6z2fE*y+&PVIS@8NY!5Inp5ZGEY<10t<|Xg279C0qY@D-y z^rXypIJ$L58x!w2F!E740>uGpTE3`kfw4HPm$J1W&O#mfH4sFqSbd9LX@Gm(k<>BL zJY(x-OytNPvAZE!sLU^n)BG?uQwM?^6vsK?!WXxADRI;kA9lDl&jY|VeX*GfsNO&_ z>hyAvbFwxoHgj3w4glL02*wu|8p|H+PMY(#09}fmaad=1ghclb{Tl3?-xP(*y($`R z9v{A*hmF=HR=ggu%Zv;dkjjC9-J2`Ya=PNsxMfx5z1nWAAHLhP@j(g2p%Ad(>=I8Xw)usXXraM4He7RE74_YJTEd|n} zDrrYip)HcJ1*oI9V^ligap_A8Z2D>l;^73MSYYSb#MA2GislMZ6TF)ntCs2I{Fan! z>p(!5MmKTeT_B8}`B1gd1p++u*W_;nokt!q!^V7sx$;r61td%nYy(x$5jlrwv}m%*WZ@As94jbgoy9jwcmTwf8pY3|MD`ip0x{M$|fes9A|#l-iVFzX;RrO4ZB z;31lPBf7@h;u~^#r0dKLW$93tqK;m958^ZXP`#uc!%20h&)aD1f_ z_WN$*EA#__wI}AKNP+trH?sJDR_XtZDS&&VAd3b50rL>%BOJpT%|n2H=edHIh=17 z-_`J)xk56rV%p139ezU(s5Kys_4`Fm zq*DezRa8=n{Mq!X#j2m`HkISWeH%2~Vm6#f(8$c)R@w&)f2ogwwnc|S%yGxH=p3^^ zzS2a$rtk4n0U}w$%2M>X1Apu6{i)twsQ% z=Pt5(70a^j5j0@_(T~)FBGr1%8GJsv@hi?H)a)SPZ$SPh7fH>FX$X^Fi|cv;^s59A zezU!KYJW9qQY$|Ob-6V+;CRqqjJ(A@>Lt-O{OhkD?B~WV9SbvV=UzIWV$YcNt^A!4 zk5kK8Ci+woNfpgaa8413MyaN6rKz7&SumW7<@?a-wD9vGP9-1+44|82g?_J9Tk3RJ zeplhR`pGw@(5^$d9Bg?;Y!1+E5$2^V(%DyMvqu4w%LRKKWORWi(S?LRS!$v_+@M+; z(Hu{Z1iaSh^>bT4f+<~9MZ-g%3Z6$r`pE?_rdRQa2@2aCT9mHXOCoLTN`0}>lJ2y1 zLH8>uzz*K&9hv=Q>DH~Vb?DoqY=9-7r8I&CH}Om?s*b_@hHxg>3`heTqR?QJ#~K0YlJCC_7tDocS@1%+^BhU^H3`)n0onJ|y%(nJ;D_o83EDej5oJ6E zD`vi8TJ#B7L_UmB<&~M;KCYvF{=N3Pug!b!gp5EjC!)bd6@;cz_oaL|w-q8O5IQcJ zhP6#UOOXs;Ezu_PX_ODR<5yw(3Go&MBgt>ST+cJ7(>Rk)Lf52J9g_*kE8oYKN0)Si zja=FUwbh)6awGc?dHCV_J$YsCotDGY+1{4yqQSmNyw(dOJJ|1glhL_sMx&~{MtwbT zwmf1lQU58R{F3_1Yhx?sT3dK3AEuSQ(($Z(v+5>U%;VGg+>(0^BNY(x?A>|y|M7pt izpW=aG7bchOt Date: Wed, 15 Aug 2018 17:08:38 -0700 Subject: [PATCH 41/53] Sizing complete for LTR languages --- .../src/main/java/co/lujun/androidtagview/TagView.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index a75f402..2ddde1a 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -198,7 +198,6 @@ private void onDealText(){ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int height = mVerticalPadding * 2 + (int) fontH; - int width = mHorizontalPadding * 2 + (int) fontW + (isEnableCross() ? height : 0); mCrossAreaWidth = Math.min(Math.max(mCrossAreaWidth, height), width); setMeasuredDimension(width, height); } @@ -245,7 +244,7 @@ protected void onDraw(Canvas canvas) { } } else { canvas.drawText(mAbstractText, - (isEnableCross() ? getWidth() - getHeight() : getWidth()) / 2 - fontW / 2, + (isEnableCross() ? getWidth() - getHeight() : getWidth()) / 2 - fontW / 2 + (isEnableImage() ? getHeight() / 2 : 0), getHeight() / 2 + fontH / 2 - bdDistance, mPaint); } From 86cec3d11cf64f1e701bfd8f0c88264674b53950 Mon Sep 17 00:00:00 2001 From: Matt Cleinman Date: Wed, 15 Aug 2018 17:13:48 -0700 Subject: [PATCH 42/53] complete for LTR, check to prevent images on RTL --- .../src/main/java/co/lujun/androidtagview/TagView.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index 2ddde1a..be878d0 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -198,6 +198,7 @@ private void onDealText(){ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int height = mVerticalPadding * 2 + (int) fontH; + int width = mHorizontalPadding * 2 + (int) fontW + (isEnableCross() ? height : 0) + (isEnableImage() ? height : 0); mCrossAreaWidth = Math.min(Math.max(mCrossAreaWidth, height), width); setMeasuredDimension(width, height); } @@ -522,7 +523,7 @@ public void setBdDistance(float bdDistance) { this.bdDistance = bdDistance; } - public boolean isEnableImage() { return mBitmapImage != null; } + public boolean isEnableImage() { return mBitmapImage != null && mTextDirection != View.TEXT_DIRECTION_RTL; } public boolean isEnableCross() { return mEnableCross; From 1b49e1305aa80f606a7bdf450a29b0166dda43d8 Mon Sep 17 00:00:00 2001 From: Matt Cleinman Date: Thu, 16 Aug 2018 14:25:46 -0700 Subject: [PATCH 43/53] PR feedback --- .../java/co/lujun/sample/MainActivity.java | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/sample/src/main/java/co/lujun/sample/MainActivity.java b/sample/src/main/java/co/lujun/sample/MainActivity.java index 796b22e..f6007f1 100644 --- a/sample/src/main/java/co/lujun/sample/MainActivity.java +++ b/sample/src/main/java/co/lujun/sample/MainActivity.java @@ -23,6 +23,7 @@ import co.lujun.androidtagview.TagView; import com.bumptech.glide.Glide; +import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.transition.Transition; import com.bumptech.glide.request.target.SimpleTarget; @@ -139,19 +140,7 @@ public void onTagCrossClick(int position) { // After you set your own attributes for TagView, then set tag(s) or add tag(s) mTagContainerLayout1.setTags(list1); - for (int i=0; i() { - @Override - public void onResourceReady(Bitmap resource, Transition transition) { - mTagContainerLayout1.getTagView(index).setImage(resource); - } - }); - } - + loadImages(list1); mTagContainerLayout2.setTags(list2); mTagContainerLayout3.setTags(list3); mTagContainerLayout4.setTags(list4); @@ -192,6 +181,31 @@ public void onClick(View v) { // recyclerView.setAdapter(adapter); } + private void loadImages(List list) { + String[] avatars = new String[]{"https://forums.oneplus.com/data/avatars/m/231/231279.jpg", + "https://d1marr3m5x4iac.cloudfront.net/images/block/movies/17214/17214_aa.jpg", + "https://lh3.googleusercontent.com/-KSI1bJ1aVS4/AAAAAAAAAAI/AAAAAAAAB9c/Vrgt6WyS5OU/il/photo.jpg"}; + + for (int i=0; i() { + @Override + public void onResourceReady(Bitmap resource, Transition transition) { + mTagContainerLayout1.getTagView(index).setImage(resource); + } + }); + try { + Thread.sleep(50); + } catch (InterruptedException e) { + System.err.println(e.getMessage()); + } + } + } + public class TagRecyclerViewAdapter extends RecyclerView.Adapter { From fbbda6cedf909426871b8ea8c80b36b577a971dd Mon Sep 17 00:00:00 2001 From: Do Tuan Anh Date: Mon, 3 Sep 2018 16:49:00 +0700 Subject: [PATCH 44/53] [F] selected tag color does not show up when Tag background is black --- androidtagview/build.gradle | 2 +- .../androidtagview/TagContainerLayout.java | 5 ++-- .../java/co/lujun/androidtagview/Utils.java | 29 ++++++++++++------- sample/build.gradle | 2 +- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index 6fffe2f..740549a 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -5,7 +5,7 @@ android { buildToolsVersion '27.0.3' defaultConfig { - minSdkVersion 14 + minSdkVersion 21 targetSdkVersion 27 versionCode 114 versionName "1.1.4" diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index 0e3270b..b8df9ee 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -549,7 +549,7 @@ private void initTagView(TagView tagView, int position) { int[] colors; if (mColorArrayList != null && mColorArrayList.size() > 0) { if (mColorArrayList.size() == mTags.size() && - mColorArrayList.get(position).length >= 3) { + mColorArrayList.get(position).length >= 4) { colors = mColorArrayList.get(position); } else { throw new RuntimeException("Illegal color list!"); @@ -559,10 +559,9 @@ private void initTagView(TagView tagView, int position) { } tagView.setTagBackgroundColor(colors[0]); - //TODO make selectedBackgroundColorSelectable configurable - tagView.setTagSelectedBackgroundColor(Utils.manipulateColorBrigthness(colors[0], 0.7f)); tagView.setTagBorderColor(colors[1]); tagView.setTagTextColor(colors[2]); + tagView.setTagSelectedBackgroundColor(colors[3]); tagView.setTagMaxLength(mTagMaxLength); tagView.setTextDirection(mTagTextDirection); tagView.setTypeface(mTagTypeface); diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java b/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java index 7997564..012b6ab 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java @@ -37,20 +37,29 @@ public static float sp2px(Context context, float sp) { } /** - *Manipulate Birghtness of color - * - * @param color in int, brightness factor + * If the color is Dark -> make it lighter and vice versa * + * @param color in int, + * @param factor 0.0 < factor < 1.0 * @return int */ - public static int manipulateColorBrigthness(int color, float factor) { + public static int manipulateColorBrightness(int color, float factor) { int a = Color.alpha(color); - int r = Math.round(Color.red(color) * factor); - int g = Math.round(Color.green(color) * factor); - int b = Math.round(Color.blue(color) * factor); + int r = Color.red(color); + int g = Color.green(color); + int b = Color.blue(color); +// if (r + b + g < 128 * 3) factor = 1 / factor;// check if the color is bright or dark +// r = Math.round(r * factor); +// b = Math.round(b * factor); +// g = Math.round(g * factor); + if (r > 127) r = 255 - Math.round((255 - r) * factor); + if (g > 127) g = 255 - Math.round((255 - g) * factor); + if (b > 127) b = 255 - Math.round((255 - b) * factor); + return Color.argb(a, - Math.min(r,255), - Math.min(g,255), - Math.min(b,255)); + Math.min(r, 255), + Math.min(g, 255), + Math.min(b, 255) + ); } } diff --git a/sample/build.gradle b/sample/build.gradle index 1ac8d94..4347fad 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -6,7 +6,7 @@ android { defaultConfig { applicationId "co.lujun.sample" - minSdkVersion 14 + minSdkVersion 21 targetSdkVersion 27 versionCode 1 versionName "1.0" From c88cacee9edfd595621adbfa06409d3728034eb2 Mon Sep 17 00:00:00 2001 From: Do Tuan Anh Date: Mon, 12 Nov 2018 15:32:51 +0700 Subject: [PATCH 45/53] update Build version + migrate to androidX + fix default color not include selected background color --- androidtagview/build.gradle | 7 +++---- .../java/co/lujun/androidtagview/ColorFactory.java | 6 ++++-- .../co/lujun/androidtagview/TagContainerLayout.java | 12 +++++++++--- .../main/java/co/lujun/androidtagview/TagView.java | 3 ++- build.gradle | 2 +- gradle.properties | 2 ++ gradle/wrapper/gradle-wrapper.properties | 2 +- sample/build.gradle | 9 ++++----- .../src/main/java/co/lujun/sample/MainActivity.java | 10 +++++----- sample/src/main/res/layout/activity_main.xml | 10 +++++----- sample/src/main/res/layout/content_main.xml | 5 ++--- 11 files changed, 38 insertions(+), 30 deletions(-) diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index 740549a..2ed3e1c 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -1,12 +1,11 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 27 - buildToolsVersion '27.0.3' + compileSdkVersion 28 defaultConfig { minSdkVersion 21 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 114 versionName "1.1.4" } @@ -21,7 +20,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) testImplementation 'junit:junit:4.12' - implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'androidx.appcompat:appcompat:1.0.1' } //TODO fix bug apply from: 'https://raw.githubusercontent.com/whilu/AndroidPublishLibrary/master/project/library/bintray_publish.gradle' //https://github.com/google/ExoPlayer/commit/13592dfb53ec99ce1fdb2744e34717dbdec9dea8 diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/ColorFactory.java b/androidtagview/src/main/java/co/lujun/androidtagview/ColorFactory.java index 943813d..f7871b7 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/ColorFactory.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/ColorFactory.java @@ -65,7 +65,8 @@ public static int[] onRandomBuild(){ int bgColor = Color.parseColor("#" + BG_COLOR_ALPHA + COLORS[random]); int bdColor = Color.parseColor("#" + BD_COLOR_ALPHA + COLORS[random]); int tColor = SHARP666666; - return new int[]{bgColor, bdColor, tColor}; + int tColor2 = SHARP727272; + return new int[]{bgColor, bdColor, tColor, tColor2}; } public static int[] onPureBuild(PURE_COLOR type){ @@ -73,7 +74,8 @@ public static int[] onPureBuild(PURE_COLOR type){ int bgColor = Color.parseColor("#" + BG_COLOR_ALPHA + color); int bdColor = Color.parseColor("#" + BD_COLOR_ALPHA + color); int tColor = SHARP727272; - return new int[]{bgColor, bdColor, tColor}; + int tColor2 = SHARP666666; + return new int[]{bgColor, bdColor, tColor, tColor2}; } } diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java index b8df9ee..86a4cb8 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagContainerLayout.java @@ -23,8 +23,6 @@ import android.graphics.Paint; import android.graphics.RectF; import android.graphics.Typeface; -import android.support.annotation.DrawableRes; -import android.support.v4.widget.ViewDragHelper; import android.util.AttributeSet; import android.view.Gravity; import android.view.MotionEvent; @@ -36,6 +34,9 @@ import java.util.Collections; import java.util.List; +import androidx.annotation.DrawableRes; +import androidx.customview.widget.ViewDragHelper; + import static co.lujun.androidtagview.Utils.dp2px; import static co.lujun.androidtagview.Utils.sp2px; @@ -145,6 +146,11 @@ public class TagContainerLayout extends ViewGroup { */ private int mTagBackgroundColor = Color.parseColor("#33F44336"); + /** + * Selected TagView background color(default #33FF7669) + */ + private int mSelectedTagBackgroundColor = Color.parseColor("#33FF7669"); + /** * TagView text color(default #FF666666) */ @@ -509,7 +515,7 @@ private int[] onUpdateColorFactory() { } else if (mTheme == ColorFactory.PURE_CYAN) { colors = ColorFactory.onPureBuild(ColorFactory.PURE_COLOR.CYAN); } else { - colors = new int[]{mTagBackgroundColor, mTagBorderColor, mTagTextColor}; + colors = new int[]{mTagBackgroundColor, mTagBorderColor, mTagTextColor, mSelectedTagBackgroundColor}; } return colors; } diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index dd5d3b0..48fe5ab 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -26,11 +26,12 @@ import android.graphics.Region; import android.graphics.Typeface; import android.os.Build; -import android.support.v4.widget.ViewDragHelper; import android.text.TextUtils; import android.view.MotionEvent; import android.view.View; +import androidx.customview.widget.ViewDragHelper; + import static co.lujun.androidtagview.Utils.dp2px; /** diff --git a/build.gradle b/build.gradle index cd5647f..80194e1 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' diff --git a/gradle.properties b/gradle.properties index 629cc7b..a565221 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,3 +13,5 @@ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true #Sun Jan 24 18:50:31 CST 2016 +android.useAndroidX=true +android.enableJetifier=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 52aba3d..1be1c62 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip diff --git a/sample/build.gradle b/sample/build.gradle index 4347fad..10c364b 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,13 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 27 - buildToolsVersion "27.0.3" + compileSdkVersion 28 defaultConfig { applicationId "co.lujun.sample" minSdkVersion 21 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 1 versionName "1.0" } @@ -23,6 +22,6 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(':androidtagview') testImplementation 'junit:junit:4.12' - implementation 'com.android.support:appcompat-v7:27.1.1' - implementation 'com.android.support:design:27.1.1' + implementation 'androidx.appcompat:appcompat:1.0.1' + implementation 'com.google.android.material:material:1.0.0' } diff --git a/sample/src/main/java/co/lujun/sample/MainActivity.java b/sample/src/main/java/co/lujun/sample/MainActivity.java index 5efb065..8008611 100644 --- a/sample/src/main/java/co/lujun/sample/MainActivity.java +++ b/sample/src/main/java/co/lujun/sample/MainActivity.java @@ -6,9 +6,6 @@ import android.content.DialogInterface; import android.graphics.Color; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -19,6 +16,9 @@ import java.util.ArrayList; import java.util.List; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.RecyclerView; import co.lujun.androidtagview.TagContainerLayout; import co.lujun.androidtagview.TagView; @@ -182,8 +182,8 @@ public void onTagCrossClick(int position) { List colors = new ArrayList(); //int[]color = {backgroundColor, tagBorderColor, tagTextColor} - int[] col1 = {Color.parseColor("#ff0000"), Color.parseColor("#000000"), Color.parseColor("#ffffff")}; - int[] col2 = {Color.parseColor("#0000ff"), Color.parseColor("#000000"), Color.parseColor("#ffffff")}; + int[] col1 = {Color.parseColor("#ff0000"), Color.parseColor("#000000"), Color.parseColor("#ffffff"), Color.parseColor("#999999")}; + int[] col2 = {Color.parseColor("#0000ff"), Color.parseColor("#000000"), Color.parseColor("#ffffff"), Color.parseColor("#999999")}; colors.add(col1); colors.add(col2); diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index a440a0b..12311a8 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -1,5 +1,5 @@ - - - - + - + diff --git a/sample/src/main/res/layout/content_main.xml b/sample/src/main/res/layout/content_main.xml index 24d98fd..bb89e68 100644 --- a/sample/src/main/res/layout/content_main.xml +++ b/sample/src/main/res/layout/content_main.xml @@ -13,12 +13,11 @@ tools:context="co.lujun.sample.MainActivity" tools:showIn="@layout/activity_main"> - + android:visibility="gone" /> Date: Mon, 12 Nov 2018 15:52:48 +0700 Subject: [PATCH 46/53] [F] bug on android P only INTERSECT and DIFFERENCE are allowed https://github.com/whilu/AndroidTagView/issues/88 --- .../src/main/java/co/lujun/androidtagview/TagView.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java index 48fe5ab..b09102f 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/TagView.java @@ -385,7 +385,13 @@ private void drawRipple(Canvas canvas){ canvas.clipPath(mPath); mPath.addRoundRect(mRectF, mBorderRadius, mBorderRadius, Path.Direction.CCW); - canvas.clipPath(mPath, Region.Op.REPLACE); +// bug: https://github.com/whilu/AndroidTagView/issues/88 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + canvas.clipPath(mPath); + } else { + canvas.clipPath(mPath, Region.Op.REPLACE); + } + canvas.drawCircle(mTouchX, mTouchY, mRippleRadius, mRipplePaint); canvas.restore(); }catch (UnsupportedOperationException e){ From 5500007c8d2f0946a1a395eff6f2b093f9a4c57f Mon Sep 17 00:00:00 2001 From: whilu Date: Wed, 28 Nov 2018 21:50:13 +0800 Subject: [PATCH 47/53] New: v1.1.5 --- README.md | 5 ++++- androidtagview/build.gradle | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1c2a557..bd1e26e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add below dependency in your **build.gradle** file. ```groovy dependencies { - compile 'co.lujun:androidtagview:1.1.4' + compile 'co.lujun:androidtagview:1.1.5' } ``` @@ -209,6 +209,9 @@ mTagcontainerLayout.setTags(tags, colors); ## Change logs +### 1.1.5(2018-8-20) +- Allow images on tags (in LTR languages). + ### 1.1.4(2017-6-1) - Add attribute for TagView background. diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index 62e5883..343a70d 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 9 targetSdkVersion 25 - versionCode 114 - versionName "1.1.4" + versionCode 115 + versionName "1.1.5" } buildTypes { release { From 49863ad5e93a7522a8071493fc5f61e3a42fed88 Mon Sep 17 00:00:00 2001 From: whilu Date: Thu, 29 Nov 2018 22:00:43 +0800 Subject: [PATCH 48/53] Update: gradle-bintray-plugin to version 1.4 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index dfdaff1..49aef8e 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files From c188c32c74fd86528d498f53bc4cedfb3e1e8d04 Mon Sep 17 00:00:00 2001 From: whilu Date: Sat, 1 Dec 2018 21:43:37 +0800 Subject: [PATCH 49/53] Release: v1.1.6 --- README.md | 13 +++++++++++-- androidtagview/build.gradle | 8 +++----- .../main/java/co/lujun/androidtagview/Utils.java | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bd1e26e..a7c9a39 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add below dependency in your **build.gradle** file. ```groovy dependencies { - compile 'co.lujun:androidtagview:1.1.5' + compile 'co.lujun:androidtagview:1.1.6' } ``` @@ -72,7 +72,8 @@ Now, you have successfully created some TagViews. The following will show some m | tag_border_color | color | TagView border color(default #88F44336) | tag_background_color | color | TagView background color(default #33F44336) | tag_max_length | integer | The max length for TagView(default max length 23) -| tag_clickable | boolean | Whether TagView can clickable(default unclickable) +| tag_clickable | boolean | Whether TagView can clickable(default false) +| tag_selectable | boolean | Whether TagView can be selectable(default false) | tag_theme | enum | The TagView [theme](#themes) | tag_text_direction | enum | The TagView text [direction](#directions) | tag_ripple_color | color | The ripple effect color(default #EEEEEE) @@ -127,6 +128,11 @@ mTagContainerLayout.setOnTagClickListener(new TagView.OnTagClickListener() { public void onTagLongClick(final int position, String text) { // ... } + + @Override + public void onSelectedTagDrag(int position, String text){ + // ... + } @Override public void onTagCrossClick(int position) { @@ -209,6 +215,9 @@ mTagcontainerLayout.setTags(tags, colors); ## Change logs +### 1.1.6(2018-12-1) +- Support tag selectable + ### 1.1.5(2018-8-20) - Allow images on tags (in LTR languages). diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index c1af273..3ff997c 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -6,8 +6,8 @@ android { defaultConfig { minSdkVersion 21 targetSdkVersion 28 - versionCode 115 - versionName "1.1.5" + versionCode 116 + versionName "1.1.6" } buildTypes { release { @@ -22,6 +22,4 @@ dependencies { testImplementation 'junit:junit:4.12' implementation 'androidx.appcompat:appcompat:1.0.1' } -//TODO fix bug apply from: 'https://raw.githubusercontent.com/whilu/AndroidPublishLibrary/master/project/library/bintray_publish.gradle' -//https://github.com/google/ExoPlayer/commit/13592dfb53ec99ce1fdb2744e34717dbdec9dea8 -//https://github.com/davideas/FlexibleAdapter/issues/579 \ No newline at end of file +apply from: 'https://raw.githubusercontent.com/whilu/AndroidPublishLibrary/master/project/library/bintray_publish.gradle' \ No newline at end of file diff --git a/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java b/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java index 012b6ab..c2b68de 100644 --- a/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java +++ b/androidtagview/src/main/java/co/lujun/androidtagview/Utils.java @@ -37,10 +37,10 @@ public static float sp2px(Context context, float sp) { } /** - * If the color is Dark -> make it lighter and vice versa + * If the color is Dark, make it lighter and vice versa * * @param color in int, - * @param factor 0.0 < factor < 1.0 + * @param factor The factor greater than 0.0 and smaller than 1.0 * @return int */ public static int manipulateColorBrightness(int color, float factor) { From a903e5fccc63bfa60bffd0d6b2bf1ba1772b0d94 Mon Sep 17 00:00:00 2001 From: whilu Date: Sat, 1 Dec 2018 21:59:59 +0800 Subject: [PATCH 50/53] Update: .travis.yml --- .travis.yml | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 20bba8e..a3a152b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,26 +1,32 @@ language: android -android: - components: - # Uncomment the lines below if you want to - # use the latest revision of Android SDK Tools - # - platform-tools - # - tools - - # The BuildTools version used by your project - - build-tools-25.0.0 +jdk: oraclejdk8 - # The SDK version used to compile your project - - android-25 +env: + global: + - ANDROID_ABI=armeabi-v7a - # Additional components - - extra-google-google_play_services - - extra-google-m2repository +android: + components: + - tools + - android-22 + - android-28 + - sys-img-armeabi-v7a-android-22 - extra-android-m2repository - - addon-google_apis-google-19 + - extra-android-support + - extra + licenses: + - android-sdk-license-.+ + +before_install: + - mkdir "$ANDROID_HOME/licenses" || true + - echo "d56f5187479451eabf01fb78af6dfcb131a6481e" > "$ANDROID_HOME/licenses/android-sdk-license" - # Specify at least one system image, - # if you need to run emulator(s) during your tests - - sys-img-armeabi-v7a-android-19 - - sys-img-x86-android-17 +before_script: + - chmod +x gradlew + - echo no | android create avd --force -n test -t android-22 --abi $ANDROID_ABI + - emulator -avd test -no-window & + - android-wait-for-emulator + - adb shell input keyevent 82 & -script: ./gradlew assembleDebug \ No newline at end of file +script: + - ./gradlew clean connectedAndroidTest \ No newline at end of file From 4168951ffa65fed11cff40d3ee71285e54c173e9 Mon Sep 17 00:00:00 2001 From: whilu Date: Mon, 21 Jan 2019 21:34:32 +0800 Subject: [PATCH 51/53] Release: v1.1.7 --- README.md | 5 ++++- androidtagview/build.gradle | 6 +++--- sample/build.gradle | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a7c9a39..a45cf78 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add below dependency in your **build.gradle** file. ```groovy dependencies { - compile 'co.lujun:androidtagview:1.1.6' + compile 'co.lujun:androidtagview:1.1.7' } ``` @@ -215,6 +215,9 @@ mTagcontainerLayout.setTags(tags, colors); ## Change logs +### 1.1.7(2019-01-21) +- Fix bugs + ### 1.1.6(2018-12-1) - Support tag selectable diff --git a/androidtagview/build.gradle b/androidtagview/build.gradle index 3ff997c..a04e40a 100644 --- a/androidtagview/build.gradle +++ b/androidtagview/build.gradle @@ -4,10 +4,10 @@ android { compileSdkVersion 28 defaultConfig { - minSdkVersion 21 + minSdkVersion 14 targetSdkVersion 28 - versionCode 116 - versionName "1.1.6" + versionCode 117 + versionName "1.1.7" } buildTypes { release { diff --git a/sample/build.gradle b/sample/build.gradle index a38b08a..db7ac6a 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -5,7 +5,7 @@ android { defaultConfig { applicationId "co.lujun.sample" - minSdkVersion 21 + minSdkVersion 14 targetSdkVersion 28 versionCode 1 versionName "1.0" From 079dd64c34a7872a87db11d8b5b6625a3ec1249c Mon Sep 17 00:00:00 2001 From: whilu Date: Tue, 12 Mar 2019 00:04:03 +0800 Subject: [PATCH 52/53] Update: README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a45cf78..427ab31 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ Add below dependency in your **build.gradle** file. ```groovy dependencies { - compile 'co.lujun:androidtagview:1.1.7' + implementation 'co.lujun:androidtagview:1.1.7' + implementation 'androidx.appcompat:appcompat:1.0.1' } ``` From 75a3bbadf572a25ad2763f0df9546523dac82027 Mon Sep 17 00:00:00 2001 From: whilu Date: Sat, 16 Mar 2019 23:35:54 +0800 Subject: [PATCH 53/53] Update: README.md --- README.md | 6 +++--- androidtagview/project.properties | 10 ++++++++++ .../src/main/java/co/lujun/sample/MainActivity.java | 12 ++++++------ 3 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 androidtagview/project.properties diff --git a/README.md b/README.md index 427ab31..6acc61b 100644 --- a/README.md +++ b/README.md @@ -206,9 +206,9 @@ mTagContainerLayout.getTagView(int position); * Set color for each TagView. ```java List colors = new ArrayList(); -//int[] color = {TagBackgroundColor, TabBorderColor, TagTextColor} -int[] color1 = {Color.RED, Color.BLACK, Color.WHITE}; -int[] color2 = {Color.BLUE, Color.BLACK, Color.WHITE}; +//int[] color = {TagBackgroundColor, TabBorderColor, TagTextColor, TagSelectedBackgroundColor} +int[] color1 = {Color.RED, Color.BLACK, Color.WHITE, Color.YELLOW}; +int[] color2 = {Color.BLUE, Color.BLACK, Color.WHITE, Color.YELLOW}; colors.add(color1); colors.add(color2); mTagcontainerLayout.setTags(tags, colors); diff --git a/androidtagview/project.properties b/androidtagview/project.properties new file mode 100644 index 0000000..1a8d96f --- /dev/null +++ b/androidtagview/project.properties @@ -0,0 +1,10 @@ +#project +project.name=AndroidTagView +project.groupId=co.lujun +project.artifactId=androidtagview +project.packaging=aar +project.siteUrl=https://github.com/whilu/AndroidTagView +project.gitUrl=https://github.com/whilu/AndroidTagView.git + +#javadoc +javadoc.name=AndroidTagView \ No newline at end of file diff --git a/sample/src/main/java/co/lujun/sample/MainActivity.java b/sample/src/main/java/co/lujun/sample/MainActivity.java index 7d85640..9399ad4 100644 --- a/sample/src/main/java/co/lujun/sample/MainActivity.java +++ b/sample/src/main/java/co/lujun/sample/MainActivity.java @@ -14,6 +14,11 @@ import android.widget.EditText; import android.widget.Toast; +import com.bumptech.glide.Glide; +import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.request.target.SimpleTarget; +import com.bumptech.glide.request.transition.Transition; + import java.util.ArrayList; import java.util.List; @@ -23,11 +28,6 @@ import co.lujun.androidtagview.TagContainerLayout; import co.lujun.androidtagview.TagView; -import com.bumptech.glide.Glide; -import com.bumptech.glide.request.RequestOptions; -import com.bumptech.glide.request.transition.Transition; -import com.bumptech.glide.request.target.SimpleTarget; - public class MainActivity extends AppCompatActivity { private TagContainerLayout mTagContainerLayout1, mTagContainerLayout2, @@ -189,7 +189,7 @@ public void onTagCrossClick(int position) { mTagContainerLayout4.setTags(list4); List colors = new ArrayList(); - //int[]color = {backgroundColor, tagBorderColor, tagTextColor} + //int[]color = {backgroundColor, tagBorderColor, tagTextColor, tagSelectedBackgroundColor} int[] col1 = {Color.parseColor("#ff0000"), Color.parseColor("#000000"), Color.parseColor("#ffffff"), Color.parseColor("#999999")}; int[] col2 = {Color.parseColor("#0000ff"), Color.parseColor("#000000"), Color.parseColor("#ffffff"), Color.parseColor("#999999")};