Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Some Feature #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions library/src/main/java/me/kaede/tagview/TagView.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public class TagView extends RelativeLayout {
private LayoutInflater mInflater;
private OnTagClickListener mClickListener;
private OnTagDeleteListener mDeleteListener;

//For save state write parcable
private SparseBooleanArray mCheckedTagArray = new SparseBooleanArray();
public TagView(Context context) {
super(context, null);
LogUtil.v(TAG,"[TagView]constructor 1");
Expand Down Expand Up @@ -146,6 +147,7 @@ private void drawTags() {
// inflate tag layout
View tagLayout = mInflater.inflate(R.layout.tagview_item, null);
tagLayout.setId(listIndex);
mCheckedTagArray.put(position, false);
tagLayout.setBackgroundDrawable(getSelector(tag));
// tag text
TextView tagView = (TextView) tagLayout.findViewById(R.id.tv_tag_item_contain);
Expand All @@ -159,8 +161,29 @@ private void drawTags() {
tagLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mClickListener != null) {
mClickListener.onTagClick(position, tag);
//if (mClickListener != null) {
// mClickListener.onTagClick(position, tag);
// }
//For Mange Clickabe and Click Single mode Tag:
if (mClickListener != null && tagLayout.isEnabled() && tagLayout.isClickable() ) {
Tag mTag1 =getTags().get(position);
if (!mCheckedTagArray.get(position)){

for (int i = 0; i <mCheckedTagArray.size() ; i++) {
if (mCheckedTagArray.get(i)){
mTag1.layoutColor= Color.BLUE;
getChildAt(i).setBackgroundDrawable(getSelector(mTag1));
}
mCheckedTagArray.put(i,false);
}
mCheckedTagArray.put(position, true);
mTag1.layoutColor= Color.GREEN;
tagLayout.setBackgroundDrawable(getSelector(mTag1));
}


mClickListener.onTagClick(position, mTag1);
// invalidate();
}
}
});
Expand Down Expand Up @@ -192,6 +215,11 @@ public void onClick(View v) {
// deletableView Padding (left & right)
} else {
deletableView.setVisibility(View.GONE);
}
//For Clickable Layout Tag
if (!tag.clickable){
tagLayout.setEnabled(false);
tagLayout.setClickable(false);
}
LayoutParams tagParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//tagParams.setMargins(0, 0, 0, 0);
Expand All @@ -200,13 +228,19 @@ public void onClick(View v) {
if (mWidth <= total + tagMargin + tagWidth + ResolutionUtil.dpToPx(this.getContext(), Constants.LAYOUT_WIDTH_OFFSET)) {
//need to add in new line
tagParams.addRule(RelativeLayout.BELOW, index_bottom);
//For Support RTL Language
tagParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, index_header);
// initialize total param (layout padding left & layout padding right)
total = getPaddingLeft() + getPaddingRight();
index_bottom = listIndex;
index_header = listIndex;
} else {
//no need to new line
tagParams.addRule(RelativeLayout.ALIGN_TOP, index_header);
//For Support RTL Language
if (listIndex==1){
tagParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, index_header);
}
//not header of the line
if (listIndex != index_header) {
tagParams.addRule(RelativeLayout.RIGHT_OF, listIndex - 1);
Expand Down