diff --git a/Label_README.md b/Label_README.md index d89d0ee..5ed80fb 100644 --- a/Label_README.md +++ b/Label_README.md @@ -63,8 +63,8 @@ flowLayout.setAdapter(adapter = new LabelFlowAdapter(R.layout.item_textv 其实只需要配置 flowLayout.setMaxSelectCount(3); 就可以了,然后adapter 中重写: ``` @Override -public void onReachMacCount(List ids, int count) { - super.onReachMacCount(ids, count); +public void onReachMaxCount(List ids, int count) { + super.onReachMaxCount(ids, count); Toast.makeText(LabelActivity.this, "最多只能选中 "+count+" 个"+" 已选中坐标: "+ids, Toast.LENGTH_SHORT).show(); } ``` diff --git a/README.md b/README.md index cb366cc..2ad2207 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ allprojects { ``` ``` -implementation 'com.github.LillteZheng:FlowHelper:v1.18' +implementation 'com.github.LillteZheng:FlowHelper:v1.19' ``` **如果要支持 AndroidX ,如果你的工程已经有以下代码,直接关联即可:** diff --git a/app/src/main/java/com/zhengsr/tabhelper/activity/LabelActivity.java b/app/src/main/java/com/zhengsr/tabhelper/activity/LabelActivity.java index 8d4e672..949a9a4 100644 --- a/app/src/main/java/com/zhengsr/tabhelper/activity/LabelActivity.java +++ b/app/src/main/java/com/zhengsr/tabhelper/activity/LabelActivity.java @@ -1,13 +1,9 @@ package com.zhengsr.tabhelper.activity; import android.graphics.Color; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.GradientDrawable; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.widget.TextView; import android.widget.Toast; import com.zhengsr.tabhelper.CommonUtils; @@ -20,7 +16,7 @@ import java.util.List; public class LabelActivity extends AppCompatActivity { - private List mTitle = new ArrayList<>(Arrays.asList("新闻", "娱乐", "学习", "测试后", "新闻", "娱乐", "学习", "测试后","新闻", "娱乐", "学习", "测试后", "新闻", "娱乐", "学习")); + private List mTitle = new ArrayList<>(Arrays.asList("新闻", "娱乐", "学习", "测试后", "新闻", "娱乐", "学习")); private List mTitle2 = new ArrayList<>(Arrays.asList("Life is like an ocean Only strong willed ".split(" "))); @Override protected void onCreate(Bundle savedInstanceState) { @@ -62,6 +58,8 @@ public void onClick(View view) { } }); + flowLayout.setSelects(6); + } @@ -75,6 +73,7 @@ public void bindView(View view, String data, int position) { view.setBackground(CommonUtils.getColorDrawable(10)); } }); + } private void multiFlow(){ @@ -89,8 +88,8 @@ public void bindView(View view, String data, int position) { @Override - public void onReachMacCount(List ids, int count) { - super.onReachMacCount(ids, count); + public void onReachMaxCount(List ids, int count) { + super.onReachMaxCount(ids, count); Toast.makeText(LabelActivity.this, "最多只能选中 "+count+" 个"+" 已选中坐标: "+ids, Toast.LENGTH_SHORT).show(); } diff --git a/tablib/src/main/java/com/zhengsr/tablib/view/adapter/LabelFlowAdapter.java b/tablib/src/main/java/com/zhengsr/tablib/view/adapter/LabelFlowAdapter.java index feba011..b32f24f 100644 --- a/tablib/src/main/java/com/zhengsr/tablib/view/adapter/LabelFlowAdapter.java +++ b/tablib/src/main/java/com/zhengsr/tablib/view/adapter/LabelFlowAdapter.java @@ -19,7 +19,7 @@ public LabelFlowAdapter(int layoutId, List data) { * @param ids * @param count */ - public void onReachMacCount(List ids, int count){} + public void onReachMaxCount(List ids, int count){} /** * 上个焦点和当前焦点的焦点情况,方便自定义动画,或者其他属性 diff --git a/tablib/src/main/java/com/zhengsr/tablib/view/flow/LabelFlowLayout.java b/tablib/src/main/java/com/zhengsr/tablib/view/flow/LabelFlowLayout.java index d9c7feb..00e72c5 100644 --- a/tablib/src/main/java/com/zhengsr/tablib/view/flow/LabelFlowLayout.java +++ b/tablib/src/main/java/com/zhengsr/tablib/view/flow/LabelFlowLayout.java @@ -10,7 +10,6 @@ import android.graphics.RectF; import android.graphics.Shader; import android.util.AttributeSet; -import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -140,7 +139,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { @Override public boolean onTouchEvent(MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_UP){ + if (event.getAction() == MotionEvent.ACTION_UP) { float x = event.getX(); float y = event.getY(); if (mBitRect.contains(x, y)) { @@ -256,7 +255,7 @@ public void onClick(View v) { if (getSelectedCount() > mMaxSelectCount) { v.setSelected(false); adapter.onItemSelectState(v, false); - adapter.onReachMacCount(getSelecteds(), mMaxSelectCount); + adapter.onReachMaxCount(getSelecteds(), mMaxSelectCount); return; } } @@ -319,6 +318,7 @@ public List getSelecteds() { View view = getChildAt(i); if (view.isSelected()) { indexs.add(i); + } } return indexs; @@ -332,12 +332,21 @@ public List getSelecteds() { */ public void setSelects(Integer... indexs) { if (indexs != null && indexs.length > 0) { + for (int i = 0; i < indexs.length; i++) { for (int j = 0; j < getChildCount(); j++) { View view = getChildAt(j); if (j == indexs[i]) { view.setSelected(true); + mLastPosition = j; + if (mAdapter != null) { + mAdapter.onItemSelectState(view, true); + } break; + } else { + if (mAdapter != null) { + mAdapter.onItemSelectState(view, false); + } } } } diff --git a/tablib/src/main/java/com/zhengsr/tablib/view/flow/TabFlowLayout.java b/tablib/src/main/java/com/zhengsr/tablib/view/flow/TabFlowLayout.java index 068e7e3..cd8748e 100644 --- a/tablib/src/main/java/com/zhengsr/tablib/view/flow/TabFlowLayout.java +++ b/tablib/src/main/java/com/zhengsr/tablib/view/flow/TabFlowLayout.java @@ -533,7 +533,6 @@ public void computeScroll() { } } - if (offset <= 0){ offset = 0; }