diff --git a/.gitignore b/.gitignore
index 31df7f6..9170674 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.gradle
+.idea
/local.properties
/.idea/workspace.xml
/.idea/libraries
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 25e8f3d..ced0a1d 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -3,6 +3,9 @@
-
-
+
+
-
-
-
-
+
+
+
-
-
-
-
+
+
+
+
@@ -56,6 +56,13 @@
+
+
+
+
+
+
+
@@ -63,13 +70,6 @@
-
-
-
-
-
-
-
@@ -77,39 +77,50 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/flowlayout-lib/src/androidTest/java/com/zhy/flowlayout_lib/ApplicationTest.java b/flowlayout-lib/src/androidTest/java/com/zhy/flowlayout_lib/ApplicationTest.java
deleted file mode 100644
index b44670e..0000000
--- a/flowlayout-lib/src/androidTest/java/com/zhy/flowlayout_lib/ApplicationTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.zhy.flowlayout_lib;
-
-import android.app.Application;
-import android.test.ApplicationTestCase;
-
-/**
- * Testing Fundamentals
- */
-public class ApplicationTest extends ApplicationTestCase
-{
- public ApplicationTest()
- {
- super(Application.class);
- }
-}
\ No newline at end of file
diff --git a/flowlayout-lib/src/main/AndroidManifest.xml b/flowlayout-lib/src/main/AndroidManifest.xml
index e92bbe1..cce61cf 100644
--- a/flowlayout-lib/src/main/AndroidManifest.xml
+++ b/flowlayout-lib/src/main/AndroidManifest.xml
@@ -1,6 +1 @@
-
-
-
-
-
+
diff --git a/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/FlowLayout.java b/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/FlowLayout.java
index 57850b5..a7fb9e1 100755
--- a/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/FlowLayout.java
+++ b/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/FlowLayout.java
@@ -1,215 +1,183 @@
-package com.zhy.view.flowlayout;
-
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.util.AttributeSet;
-import android.util.LayoutDirection;
-import android.view.View;
-import android.view.ViewGroup;
-import android.support.v4.text.TextUtilsCompat;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-
-public class FlowLayout extends ViewGroup {
- private static final String TAG = "FlowLayout";
- private static final int LEFT = -1;
- private static final int CENTER = 0;
- private static final int RIGHT = 1;
-
- protected List> mAllViews = new ArrayList>();
- protected List mLineHeight = new ArrayList();
- protected List mLineWidth = new ArrayList();
- private int mGravity;
- private List lineViews = new ArrayList<>();
-
- public FlowLayout(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TagFlowLayout);
- mGravity = ta.getInt(R.styleable.TagFlowLayout_tag_gravity, LEFT);
- int layoutDirection = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault());
- if (layoutDirection == LayoutDirection.RTL) {
- if (mGravity == LEFT) {
- mGravity = RIGHT;
- } else {
- mGravity = LEFT;
- }
- }
- ta.recycle();
- }
-
- public FlowLayout(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public FlowLayout(Context context) {
- this(context, null);
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);
- int modeWidth = MeasureSpec.getMode(widthMeasureSpec);
- int sizeHeight = MeasureSpec.getSize(heightMeasureSpec);
- int modeHeight = MeasureSpec.getMode(heightMeasureSpec);
-
- // wrap_content
- int width = 0;
- int height = 0;
-
- int lineWidth = 0;
- int lineHeight = 0;
-
- int cCount = getChildCount();
-
- for (int i = 0; i < cCount; i++) {
- View child = getChildAt(i);
- if (child.getVisibility() == View.GONE) {
- if (i == cCount - 1) {
- width = Math.max(lineWidth, width);
- height += lineHeight;
- }
- continue;
- }
- measureChild(child, widthMeasureSpec, heightMeasureSpec);
- MarginLayoutParams lp = (MarginLayoutParams) child
- .getLayoutParams();
-
- int childWidth = child.getMeasuredWidth() + lp.leftMargin
- + lp.rightMargin;
- int childHeight = child.getMeasuredHeight() + lp.topMargin
- + lp.bottomMargin;
-
- if (lineWidth + childWidth > sizeWidth - getPaddingLeft() - getPaddingRight()) {
- width = Math.max(width, lineWidth);
- lineWidth = childWidth;
- height += lineHeight;
- lineHeight = childHeight;
- } else {
- lineWidth += childWidth;
- lineHeight = Math.max(lineHeight, childHeight);
- }
- if (i == cCount - 1) {
- width = Math.max(lineWidth, width);
- height += lineHeight;
- }
- }
- setMeasuredDimension(
- //
- modeWidth == MeasureSpec.EXACTLY ? sizeWidth : width + getPaddingLeft() + getPaddingRight(),
- modeHeight == MeasureSpec.EXACTLY ? sizeHeight : height + getPaddingTop() + getPaddingBottom()//
- );
-
- }
-
-
- @Override
- protected void onLayout(boolean changed, int l, int t, int r, int b) {
- mAllViews.clear();
- mLineHeight.clear();
- mLineWidth.clear();
- lineViews.clear();
-
- int width = getWidth();
-
- int lineWidth = 0;
- int lineHeight = 0;
-
- int cCount = getChildCount();
-
- for (int i = 0; i < cCount; i++) {
- View child = getChildAt(i);
- if (child.getVisibility() == View.GONE) continue;
- MarginLayoutParams lp = (MarginLayoutParams) child
- .getLayoutParams();
-
- int childWidth = child.getMeasuredWidth();
- int childHeight = child.getMeasuredHeight();
-
- if (childWidth + lineWidth + lp.leftMargin + lp.rightMargin > width - getPaddingLeft() - getPaddingRight()) {
- mLineHeight.add(lineHeight);
- mAllViews.add(lineViews);
- mLineWidth.add(lineWidth);
-
- lineWidth = 0;
- lineHeight = childHeight + lp.topMargin + lp.bottomMargin;
- lineViews = new ArrayList();
- }
- lineWidth += childWidth + lp.leftMargin + lp.rightMargin;
- lineHeight = Math.max(lineHeight, childHeight + lp.topMargin
- + lp.bottomMargin);
- lineViews.add(child);
-
- }
- mLineHeight.add(lineHeight);
- mLineWidth.add(lineWidth);
- mAllViews.add(lineViews);
-
-
- int left = getPaddingLeft();
- int top = getPaddingTop();
-
- int lineNum = mAllViews.size();
-
- for (int i = 0; i < lineNum; i++) {
- lineViews = mAllViews.get(i);
- lineHeight = mLineHeight.get(i);
-
- // set gravity
- int currentLineWidth = this.mLineWidth.get(i);
- switch (this.mGravity) {
- case LEFT:
- left = getPaddingLeft();
- break;
- case CENTER:
- left = (width - currentLineWidth) / 2 + getPaddingLeft();
- break;
- case RIGHT:
- // 适配了rtl,需要补偿一个padding值
- left = width - (currentLineWidth + getPaddingLeft()) - getPaddingRight();
- // 适配了rtl,需要把lineViews里面的数组倒序排
- Collections.reverse(lineViews);
- break;
- }
-
- for (int j = 0; j < lineViews.size(); j++) {
- View child = lineViews.get(j);
- if (child.getVisibility() == View.GONE) {
- continue;
- }
-
- MarginLayoutParams lp = (MarginLayoutParams) child
- .getLayoutParams();
-
- int lc = left + lp.leftMargin;
- int tc = top + lp.topMargin;
- int rc = lc + child.getMeasuredWidth();
- int bc = tc + child.getMeasuredHeight();
-
- child.layout(lc, tc, rc, bc);
-
- left += child.getMeasuredWidth() + lp.leftMargin
- + lp.rightMargin;
- }
- top += lineHeight;
- }
-
- }
-
- @Override
- public LayoutParams generateLayoutParams(AttributeSet attrs) {
- return new MarginLayoutParams(getContext(), attrs);
- }
-
- @Override
- protected LayoutParams generateDefaultLayoutParams() {
- return new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
- }
-
- @Override
- protected LayoutParams generateLayoutParams(LayoutParams p) {
- return new MarginLayoutParams(p);
- }
-}
+package com.zhy.view.flowlayout;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+import android.util.LayoutDirection;
+import android.view.View;
+import android.view.ViewGroup;
+import androidx.core.text.TextUtilsCompat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+
+public class FlowLayout extends ViewGroup {
+ private static final String TAG = "FlowLayout";
+ private static final int LEFT = -1;
+ private static final int CENTER = 0;
+ private static final int RIGHT = 1;
+
+ protected List> mAllViews = new ArrayList>();
+ protected List mLineHeight = new ArrayList();
+ protected List mLineWidth = new ArrayList();
+ private int mGravity;
+ private List lineViews = new ArrayList<>();
+
+ public FlowLayout(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TagFlowLayout);
+ mGravity = ta.getInt(R.styleable.TagFlowLayout_tag_gravity, LEFT);
+ int layoutDirection = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault());
+ if (layoutDirection == LayoutDirection.RTL) {
+ if (mGravity == LEFT) {
+ mGravity = RIGHT;
+ } else {
+ mGravity = LEFT;
+ }
+ }
+ ta.recycle();
+ }
+
+ public FlowLayout(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public FlowLayout(Context context) {
+ this(context, null);
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);
+ int modeWidth = MeasureSpec.getMode(widthMeasureSpec);
+ int sizeHeight = MeasureSpec.getSize(heightMeasureSpec);
+ int modeHeight = MeasureSpec.getMode(heightMeasureSpec);
+ // wrap_content
+ int width = 0;
+ int height = 0;
+ int lineWidth = 0;
+ int lineHeight = 0;
+ int cCount = getChildCount();
+ for (int i = 0; i < cCount; i++) {
+ View child = getChildAt(i);
+ if (child.getVisibility() == View.GONE) {
+ if (i == cCount - 1) {
+ width = Math.max(lineWidth, width);
+ height += lineHeight;
+ }
+ continue;
+ }
+ measureChild(child, widthMeasureSpec, heightMeasureSpec);
+ MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
+
+ int childWidth = child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
+ int childHeight = child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
+
+ if (lineWidth + childWidth > sizeWidth - getPaddingLeft() - getPaddingRight()) {
+ width = Math.max(width, lineWidth);
+ lineWidth = childWidth;
+ height += lineHeight;
+ lineHeight = childHeight;
+ } else {
+ lineWidth += childWidth;
+ lineHeight = Math.max(lineHeight, childHeight);
+ }
+ if (i == cCount - 1) {
+ width = Math.max(lineWidth, width);
+ height += lineHeight;
+ }
+ }
+ setMeasuredDimension(modeWidth == MeasureSpec.EXACTLY ? sizeWidth : width + getPaddingLeft() + getPaddingRight(),
+ modeHeight == MeasureSpec.EXACTLY ? sizeHeight : height + getPaddingTop() + getPaddingBottom()
+ );
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int l, int t, int r, int b) {
+ mAllViews.clear();
+ mLineHeight.clear();
+ mLineWidth.clear();
+ lineViews.clear();
+ int width = getWidth();
+ int lineWidth = 0;
+ int lineHeight = 0;
+ int cCount = getChildCount();
+ for (int i = 0; i < cCount; i++) {
+ View child = getChildAt(i);
+ if (child.getVisibility() == View.GONE) {
+ continue;
+ }
+ MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
+ int childWidth = child.getMeasuredWidth();
+ int childHeight = child.getMeasuredHeight();
+ if (childWidth + lineWidth + lp.leftMargin + lp.rightMargin > width - getPaddingLeft() - getPaddingRight()) {
+ mLineHeight.add(lineHeight);
+ mAllViews.add(lineViews);
+ mLineWidth.add(lineWidth);
+ lineWidth = 0;
+ lineHeight = childHeight + lp.topMargin + lp.bottomMargin;
+ lineViews = new ArrayList();
+ }
+ lineWidth += childWidth + lp.leftMargin + lp.rightMargin;
+ lineHeight = Math.max(lineHeight, childHeight + lp.topMargin + lp.bottomMargin);
+ lineViews.add(child);
+ }
+ mLineHeight.add(lineHeight);
+ mLineWidth.add(lineWidth);
+ mAllViews.add(lineViews);
+ int left = getPaddingLeft();
+ int top = getPaddingTop();
+ int lineNum = mAllViews.size();
+ for (int i = 0; i < lineNum; i++) {
+ lineViews = mAllViews.get(i);
+ lineHeight = mLineHeight.get(i);
+ // set gravity
+ int currentLineWidth = this.mLineWidth.get(i);
+ switch (this.mGravity) {
+ case LEFT:
+ left = getPaddingLeft();
+ break;
+ case CENTER:
+ left = (width - currentLineWidth) / 2 + getPaddingLeft();
+ break;
+ case RIGHT:
+ // 适配了rtl,需要补偿一个padding值
+ left = width - (currentLineWidth + getPaddingLeft()) - getPaddingRight();
+ // 适配了rtl,需要把lineViews里面的数组倒序排
+ Collections.reverse(lineViews);
+ break;
+ }
+
+ for (int j = 0; j < lineViews.size(); j++) {
+ View child = lineViews.get(j);
+ if (child.getVisibility() == View.GONE) {
+ continue;
+ }
+ MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
+ int lc = left + lp.leftMargin;
+ int tc = top + lp.topMargin;
+ int rc = lc + child.getMeasuredWidth();
+ int bc = tc + child.getMeasuredHeight();
+ child.layout(lc, tc, rc, bc);
+ left += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
+ }
+ top += lineHeight;
+ }
+ }
+
+ @Override
+ public LayoutParams generateLayoutParams(AttributeSet attrs) {
+ return new MarginLayoutParams(getContext(), attrs);
+ }
+
+ @Override
+ protected LayoutParams generateDefaultLayoutParams() {
+ return new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+ }
+
+ @Override
+ protected LayoutParams generateLayoutParams(LayoutParams p) {
+ return new MarginLayoutParams(p);
+ }
+}
diff --git a/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/TagView.java b/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/FlowTagView.java
similarity index 71%
rename from flowlayout-lib/src/main/java/com/zhy/view/flowlayout/TagView.java
rename to flowlayout-lib/src/main/java/com/zhy/view/flowlayout/FlowTagView.java
index c95404c..6ccd7a1 100644
--- a/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/TagView.java
+++ b/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/FlowTagView.java
@@ -8,54 +8,40 @@
/**
* Created by zhy on 15/9/10.
*/
-public class TagView extends FrameLayout implements Checkable
-{
+public class FlowTagView extends FrameLayout implements Checkable {
private boolean isChecked;
private static final int[] CHECK_STATE = new int[]{android.R.attr.state_checked};
-
- public TagView(Context context)
- {
+ public FlowTagView(Context context) {
super(context);
}
-
- public View getTagView()
- {
+ public View getTagView() {
return getChildAt(0);
}
-
@Override
- public int[] onCreateDrawableState(int extraSpace)
- {
+ public int[] onCreateDrawableState(int extraSpace) {
int[] states = super.onCreateDrawableState(extraSpace + 1);
- if (isChecked())
- {
+ if (isChecked()) {
mergeDrawableStates(states, CHECK_STATE);
}
return states;
}
-
-
/**
* Change the checked state of the view
*
* @param checked The new checked state
*/
@Override
- public void setChecked(boolean checked)
- {
- if (this.isChecked != checked)
- {
+ public void setChecked(boolean checked) {
+ if (this.isChecked != checked) {
this.isChecked = checked;
refreshDrawableState();
}
}
-
/**
* @return The current checked state of the view
*/
@Override
- public boolean isChecked()
- {
+ public boolean isChecked() {
return isChecked;
}
@@ -63,10 +49,7 @@ public boolean isChecked()
* Change the checked state of the view to the inverse of its current state
*/
@Override
- public void toggle()
- {
+ public void toggle() {
setChecked(!isChecked);
}
-
-
}
diff --git a/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/TagAdapter.java b/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/TagAdapter.java
index 61b73a1..4c83de2 100644
--- a/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/TagAdapter.java
+++ b/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/TagAdapter.java
@@ -56,14 +56,14 @@ HashSet getPreCheckedList() {
return mCheckedPosList;
}
-
public int getCount() {
return mTagDatas == null ? 0 : mTagDatas.size();
}
public void notifyDataChanged() {
- if (mOnDataChangedListener != null)
+ if (mOnDataChangedListener != null) {
mOnDataChangedListener.onChanged();
+ }
}
public T getItem(int position) {
@@ -72,18 +72,15 @@ public T getItem(int position) {
public abstract View getView(FlowLayout parent, int position, T t);
-
- public void onSelected(int position, View view){
- Log.d("zhy","onSelected " + position);
+ public void onSelected(int position, View view) {
+ Log.d("zhy", "onSelected " + position);
}
- public void unSelected(int position, View view){
- Log.d("zhy","unSelected " + position);
+ public void unSelected(int position, View view) {
+ Log.d("zhy", "unSelected " + position);
}
public boolean setSelected(int position, T t) {
return false;
}
-
-
}
diff --git a/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/TagFlowLayout.java b/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/TagFlowLayout.java
index ba90897..d018ad7 100644
--- a/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/TagFlowLayout.java
+++ b/flowlayout-lib/src/main/java/com/zhy/view/flowlayout/TagFlowLayout.java
@@ -2,35 +2,32 @@
import android.content.Context;
import android.content.res.TypedArray;
-import android.graphics.Rect;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
-import android.view.MotionEvent;
import android.view.View;
-import android.view.ViewGroup;
-import android.widget.FrameLayout;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
-/**
- * Created by zhy on 15/9/10.
- */
public class TagFlowLayout extends FlowLayout
implements TagAdapter.OnDataChangedListener {
private TagAdapter mTagAdapter;
- private int mSelectedMax = -1;//-1为不限制数量
+ /**
+ * -1为不限制数量
+ */
+ private int mSelectedMax = -1;
private static final String TAG = "TagFlowLayout";
private Set mSelectedView = new HashSet();
private OnSelectListener mOnSelectListener;
private OnTagClickListener mOnTagClickListener;
+ private OnTagLongClickListener mOnTagLongClickListener;
public interface OnSelectListener {
void onSelected(Set selectPosSet);
@@ -40,6 +37,10 @@ public interface OnTagClickListener {
boolean onTagClick(View view, int position, FlowLayout parent);
}
+ public interface OnTagLongClickListener {
+ boolean onTagLongClick(View view, int position, FlowLayout parent);
+ }
+
public TagFlowLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TagFlowLayout);
@@ -60,12 +61,12 @@ public TagFlowLayout(Context context) {
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int cCount = getChildCount();
for (int i = 0; i < cCount; i++) {
- TagView tagView = (TagView) getChildAt(i);
- if (tagView.getVisibility() == View.GONE) {
+ FlowTagView flowTagView = (FlowTagView) getChildAt(i);
+ if (flowTagView.getVisibility() == View.GONE) {
continue;
}
- if (tagView.getTagView().getVisibility() == View.GONE) {
- tagView.setVisibility(View.GONE);
+ if (flowTagView.getTagView().getVisibility() == View.GONE) {
+ flowTagView.setVisibility(View.GONE);
}
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
@@ -81,6 +82,10 @@ public void setOnTagClickListener(OnTagClickListener onTagClickListener) {
mOnTagClickListener = onTagClickListener;
}
+ public void setOnTagLongClickListener(OnTagLongClickListener onTagLongClickListener) {
+ mOnTagLongClickListener = onTagLongClickListener;
+ }
+
public void setAdapter(TagAdapter adapter) {
mTagAdapter = adapter;
mTagAdapter.setOnDataChangedListener(this);
@@ -92,15 +97,15 @@ public void setAdapter(TagAdapter adapter) {
private void changeAdapter() {
removeAllViews();
TagAdapter adapter = mTagAdapter;
- TagView tagViewContainer = null;
+ FlowTagView flowTagViewContainer = null;
HashSet preCheckedList = mTagAdapter.getPreCheckedList();
for (int i = 0; i < adapter.getCount(); i++) {
View tagView = adapter.getView(this, i, adapter.getItem(i));
- tagViewContainer = new TagView(getContext());
+ flowTagViewContainer = new FlowTagView(getContext());
tagView.setDuplicateParentStateEnabled(true);
if (tagView.getLayoutParams() != null) {
- tagViewContainer.setLayoutParams(tagView.getLayoutParams());
+ flowTagViewContainer.setLayoutParams(tagView.getLayoutParams());
} else {
@@ -111,31 +116,42 @@ private void changeAdapter() {
dip2px(getContext(), 5),
dip2px(getContext(), 5),
dip2px(getContext(), 5));
- tagViewContainer.setLayoutParams(lp);
+ flowTagViewContainer.setLayoutParams(lp);
}
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
tagView.setLayoutParams(lp);
- tagViewContainer.addView(tagView);
- addView(tagViewContainer);
+ flowTagViewContainer.addView(tagView);
+ addView(flowTagViewContainer);
if (preCheckedList.contains(i)) {
- setChildChecked(i, tagViewContainer);
+ setChildChecked(i, flowTagViewContainer);
}
if (mTagAdapter.setSelected(i, adapter.getItem(i))) {
- setChildChecked(i, tagViewContainer);
+ setChildChecked(i, flowTagViewContainer);
}
tagView.setClickable(false);
- final TagView finalTagViewContainer = tagViewContainer;
+ final FlowTagView finalFlowTagViewContainer = flowTagViewContainer;
final int position = i;
- tagViewContainer.setOnClickListener(new OnClickListener() {
+ flowTagViewContainer.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- doSelect(finalTagViewContainer, position);
+ doSelect(finalFlowTagViewContainer, position);
if (mOnTagClickListener != null) {
- mOnTagClickListener.onTagClick(finalTagViewContainer, position,
+ mOnTagClickListener.onTagClick(finalFlowTagViewContainer, position,
+ TagFlowLayout.this);
+ }
+ }
+ });
+
+ flowTagViewContainer.setOnLongClickListener(new OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View view) {
+ if (mOnTagLongClickListener != null) {
+ mOnTagLongClickListener.onTagLongClick(finalFlowTagViewContainer, position,
TagFlowLayout.this);
}
+ return true;
}
});
}
@@ -154,23 +170,23 @@ public Set getSelectedList() {
return new HashSet(mSelectedView);
}
- private void setChildChecked(int position, TagView view) {
+ private void setChildChecked(int position, FlowTagView view) {
view.setChecked(true);
mTagAdapter.onSelected(position, view.getTagView());
}
- private void setChildUnChecked(int position, TagView view) {
+ private void setChildUnChecked(int position, FlowTagView view) {
view.setChecked(false);
mTagAdapter.unSelected(position, view.getTagView());
}
- private void doSelect(TagView child, int position) {
+ private void doSelect(FlowTagView child, int position) {
if (!child.isChecked()) {
//处理max_select=1的情况
if (mSelectedMax == 1 && mSelectedView.size() == 1) {
Iterator iterator = mSelectedView.iterator();
Integer preIndex = iterator.next();
- TagView pre = (TagView) getChildAt(preIndex);
+ FlowTagView pre = (FlowTagView) getChildAt(preIndex);
setChildUnChecked(preIndex, pre);
setChildChecked(position, child);
@@ -228,9 +244,9 @@ protected void onRestoreInstanceState(Parcelable state) {
int index = Integer.parseInt(pos);
mSelectedView.add(index);
- TagView tagView = (TagView) getChildAt(index);
- if (tagView != null) {
- setChildChecked(index, tagView);
+ FlowTagView flowTagView = (FlowTagView) getChildAt(index);
+ if (flowTagView != null) {
+ setChildChecked(index, flowTagView);
}
}
diff --git a/flowlayout-lib/src/main/res/values/attrs.xml b/flowlayout-lib/src/main/res/values/attrs.xml
index d1454ed..5c86039 100644
--- a/flowlayout-lib/src/main/res/values/attrs.xml
+++ b/flowlayout-lib/src/main/res/values/attrs.xml
@@ -1,7 +1,7 @@
-
+
diff --git a/flowlayout/build.gradle b/flowlayout/build.gradle
index 97325f6..47c2d25 100644
--- a/flowlayout/build.gradle
+++ b/flowlayout/build.gradle
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 25
- buildToolsVersion "25.0.3"
+ compileSdkVersion 29
+ buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.zhy.flowlayout"
- minSdkVersion 10
- targetSdkVersion 25
+ minSdkVersion 14
+ targetSdkVersion 29
versionCode 1
versionName "1.0"
}
@@ -20,9 +20,10 @@ android {
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.android.support:appcompat-v7:25.3.0'
- compile project(':flowlayout-lib')
- compile 'com.android.support:design:25.3.0'
- compile 'com.zhy:base-adapter:2.0.1'
+ api fileTree(dir: 'libs', include: ['*.jar'])
+ api 'androidx.appcompat:appcompat:1.0.2'
+ api project(':flowlayout-lib')
+// api 'androidx.appcompat:appcompat:1.0.2'
+ api 'com.zhy:base-adapter:2.0.1'
+ implementation 'com.google.android.material:material:1.0.0'
}
diff --git a/flowlayout/flowlayout.iml b/flowlayout/flowlayout.iml
index 33086c4..f6747f4 100644
--- a/flowlayout/flowlayout.iml
+++ b/flowlayout/flowlayout.iml
@@ -17,30 +17,30 @@
-
+
+
-
-
+
+
-
-
-
-
+
+
+
-
-
-
-
+
+
+
+
@@ -48,6 +48,13 @@
+
+
+
+
+
+
+
@@ -76,52 +83,78 @@
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/flowlayout/src/androidTest/java/com/zhy/flowlayout/ApplicationTest.java b/flowlayout/src/androidTest/java/com/zhy/flowlayout/ApplicationTest.java
deleted file mode 100644
index 0b7420a..0000000
--- a/flowlayout/src/androidTest/java/com/zhy/flowlayout/ApplicationTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.zhy.flowlayout;
-
-import android.app.Application;
-import android.test.ApplicationTestCase;
-
-/**
- * Testing Fundamentals
- */
-public class ApplicationTest extends ApplicationTestCase
-{
- public ApplicationTest()
- {
- super(Application.class);
- }
-}
\ No newline at end of file
diff --git a/flowlayout/src/main/java/com/zhy/flowlayout/CategoryActivity.java b/flowlayout/src/main/java/com/zhy/flowlayout/CategoryActivity.java
index fb6c41f..10e29f0 100644
--- a/flowlayout/src/main/java/com/zhy/flowlayout/CategoryActivity.java
+++ b/flowlayout/src/main/java/com/zhy/flowlayout/CategoryActivity.java
@@ -1,11 +1,13 @@
package com.zhy.flowlayout;
import android.os.Bundle;
-import android.support.design.widget.TabLayout;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentPagerAdapter;
-import android.support.v4.view.ViewPager;
-import android.support.v7.app.AppCompatActivity;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentPagerAdapter;
+import androidx.viewpager.widget.ViewPager;
+
+import com.google.android.material.tabs.TabLayout;
public class CategoryActivity extends AppCompatActivity
{
diff --git a/flowlayout/src/main/java/com/zhy/flowlayout/EventTestFragment.java b/flowlayout/src/main/java/com/zhy/flowlayout/EventTestFragment.java
index 2bb6985..200281e 100644
--- a/flowlayout/src/main/java/com/zhy/flowlayout/EventTestFragment.java
+++ b/flowlayout/src/main/java/com/zhy/flowlayout/EventTestFragment.java
@@ -1,14 +1,15 @@
package com.zhy.flowlayout;
import android.os.Bundle;
-import android.support.annotation.Nullable;
-import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;
@@ -64,12 +65,20 @@ public boolean setSelected(int position, String s)
@Override
public boolean onTagClick(View view, int position, FlowLayout parent)
{
- Toast.makeText(getActivity(), mVals[position], Toast.LENGTH_SHORT).show();
+ Toast.makeText(getActivity(), "onTagClick" + mVals[position], Toast.LENGTH_SHORT).show();
//view.setVisibility(View.GONE);
return true;
}
});
+ mFlowLayout.setOnTagLongClickListener(new TagFlowLayout.OnTagLongClickListener() {
+ @Override
+ public boolean onTagLongClick(View view, int position, FlowLayout parent) {
+ Toast.makeText(getActivity(), "onTagLongClick" + mVals[position], Toast.LENGTH_SHORT).show();
+ return false;
+ }
+ });
+
mFlowLayout.setOnSelectListener(new TagFlowLayout.OnSelectListener()
{
diff --git a/flowlayout/src/main/java/com/zhy/flowlayout/GravityFragment.java b/flowlayout/src/main/java/com/zhy/flowlayout/GravityFragment.java
index 0a1bfaf..76da94e 100644
--- a/flowlayout/src/main/java/com/zhy/flowlayout/GravityFragment.java
+++ b/flowlayout/src/main/java/com/zhy/flowlayout/GravityFragment.java
@@ -1,12 +1,13 @@
package com.zhy.flowlayout;
import android.os.Bundle;
-import android.support.annotation.Nullable;
-import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+
public class GravityFragment extends Fragment
{
@Nullable
diff --git a/flowlayout/src/main/java/com/zhy/flowlayout/LimitSelectedFragment.java b/flowlayout/src/main/java/com/zhy/flowlayout/LimitSelectedFragment.java
index 86636e1..ae22041 100644
--- a/flowlayout/src/main/java/com/zhy/flowlayout/LimitSelectedFragment.java
+++ b/flowlayout/src/main/java/com/zhy/flowlayout/LimitSelectedFragment.java
@@ -1,13 +1,14 @@
package com.zhy.flowlayout;
import android.os.Bundle;
-import android.support.annotation.Nullable;
-import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;
diff --git a/flowlayout/src/main/java/com/zhy/flowlayout/ListViewTestFragment.java b/flowlayout/src/main/java/com/zhy/flowlayout/ListViewTestFragment.java
index 8066f82..dc56a90 100644
--- a/flowlayout/src/main/java/com/zhy/flowlayout/ListViewTestFragment.java
+++ b/flowlayout/src/main/java/com/zhy/flowlayout/ListViewTestFragment.java
@@ -1,14 +1,15 @@
package com.zhy.flowlayout;
import android.os.Bundle;
-import android.support.annotation.Nullable;
-import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+
import com.zhy.base.adapter.ViewHolder;
import com.zhy.base.adapter.abslistview.CommonAdapter;
import com.zhy.view.flowlayout.FlowLayout;
diff --git a/flowlayout/src/main/java/com/zhy/flowlayout/ScrollViewTestFragment.java b/flowlayout/src/main/java/com/zhy/flowlayout/ScrollViewTestFragment.java
index 6f7de01..f25b4de 100644
--- a/flowlayout/src/main/java/com/zhy/flowlayout/ScrollViewTestFragment.java
+++ b/flowlayout/src/main/java/com/zhy/flowlayout/ScrollViewTestFragment.java
@@ -1,12 +1,14 @@
package com.zhy.flowlayout;
import android.os.Bundle;
-import android.support.annotation.Nullable;
-import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
@@ -71,11 +73,18 @@ public View getView(FlowLayout parent, int position, String s)
@Override
public boolean onTagClick(View view, int position, FlowLayout parent)
{
- //Toast.makeText(getActivity(), mVals[position], Toast.LENGTH_SHORT).show();
+ Toast.makeText(getActivity(), mVals[position], Toast.LENGTH_SHORT).show();
//view.setVisibility(View.GONE);
return true;
}
});
+ mFlowLayout.setOnTagLongClickListener(new TagFlowLayout.OnTagLongClickListener() {
+ @Override
+ public boolean onTagLongClick(View view, int position, FlowLayout parent) {
+ Toast.makeText(getActivity(), mVals[position], Toast.LENGTH_SHORT).show();
+ return false;
+ }
+ });
mFlowLayout.setOnSelectListener(new TagFlowLayout.OnSelectListener()
diff --git a/flowlayout/src/main/java/com/zhy/flowlayout/SimpleFragment.java b/flowlayout/src/main/java/com/zhy/flowlayout/SimpleFragment.java
index ec2d723..89bf4c7 100644
--- a/flowlayout/src/main/java/com/zhy/flowlayout/SimpleFragment.java
+++ b/flowlayout/src/main/java/com/zhy/flowlayout/SimpleFragment.java
@@ -1,14 +1,15 @@
package com.zhy.flowlayout;
import android.os.Bundle;
-import android.support.annotation.Nullable;
-import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;
diff --git a/flowlayout/src/main/java/com/zhy/flowlayout/SingleChooseFragment.java b/flowlayout/src/main/java/com/zhy/flowlayout/SingleChooseFragment.java
index 71f3368..323afe7 100644
--- a/flowlayout/src/main/java/com/zhy/flowlayout/SingleChooseFragment.java
+++ b/flowlayout/src/main/java/com/zhy/flowlayout/SingleChooseFragment.java
@@ -1,14 +1,15 @@
package com.zhy.flowlayout;
import android.os.Bundle;
-import android.support.annotation.Nullable;
-import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;
@@ -58,12 +59,22 @@ public View getView(FlowLayout parent, int position, String s)
@Override
public boolean onTagClick(View view, int position, FlowLayout parent)
{
- Toast.makeText(getActivity(), mVals[position], Toast.LENGTH_SHORT).show();
+ Toast.makeText(getActivity(), "onTagClick" + mVals[position], Toast.LENGTH_SHORT).show();
//view.setVisibility(View.GONE);
return true;
}
});
+ mFlowLayout.setOnTagLongClickListener(new TagFlowLayout.OnTagLongClickListener() {
+ @Override
+ public boolean onTagLongClick(View view, int position, FlowLayout parent) {
+ Toast.makeText(getActivity(), "onTagLongClick" + mVals[position], Toast.LENGTH_SHORT).show();
+ TextView textView =view.findViewById(R.id.tvv);
+ textView.setText(textView.getText().toString() + "onTagLongClick");
+ return false;
+ }
+ });
+
mFlowLayout.setOnSelectListener(new TagFlowLayout.OnSelectListener()
{
diff --git a/flowlayout/src/main/res/layout/activity_category.xml b/flowlayout/src/main/res/layout/activity_category.xml
index cc13802..7676659 100644
--- a/flowlayout/src/main/res/layout/activity_category.xml
+++ b/flowlayout/src/main/res/layout/activity_category.xml
@@ -6,7 +6,7 @@
android:orientation="vertical"
>
-
-
-
-
+
+
+
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
index 1d3591c..59d5aab 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -15,4 +15,6 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
\ No newline at end of file
+# org.gradle.parallel=true
+android.useAndroidX=true
+android.enableJetifier=true
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index b6cbdd5..7749539 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Tue Sep 12 16:51:04 CST 2017
+#Sat Jul 20 23:56:42 CST 2019
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-5.1.1-all.zip