diff --git a/README.md b/README.md index 5e4a5c9..5c72a10 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ **实现类似微博内容,@用户,链接高亮,@用户和链接可点击跳转,可展开和收回的TextView。觉得好用别忘了star哦,你的star是对我最大的激励** ### 更新日志 ++ 2018-10-09 17:20:45 更新,新增对展开和回收的点击事件监听,依赖版本请使用tag版本v1.5.2 + ``` + implementation 'com.github.MZCretin:ExpandableTextView:v1.5.2' + ``` + + 2018-09-28 09:37:28 更新,优化了将"展开"和"收回"固定最右显示时中间空格数量的计算方式,依赖版本请使用tag版本v1.5.1,[查看说明](#新特性额外说明) ``` implementation 'com.github.MZCretin:ExpandableTextView:v1.5.1' diff --git a/app/src/main/java/com/cretin/www/expandabletextview/MainActivity.java b/app/src/main/java/com/cretin/www/expandabletextview/MainActivity.java index 56e9258..9e992b2 100644 --- a/app/src/main/java/com/cretin/www/expandabletextview/MainActivity.java +++ b/app/src/main/java/com/cretin/www/expandabletextview/MainActivity.java @@ -24,6 +24,7 @@ import com.ctetin.expandabletextviewlibrary.ExpandableTextView; import com.ctetin.expandabletextviewlibrary.app.LinkType; +import com.ctetin.expandabletextviewlibrary.app.StatusType; /** @@ -41,7 +42,7 @@ public class MainActivity extends AppCompatActivity { private TextView[] tips; private String[] indexs = new String[]{ "3,5;6,9;10,12", - "3,5;6,11;12,13;21,22", + "3,5;6,11;12,13;21,22;27,28", "2,6;7,12;13,14;22,23", "3,5;6,9;10,11;19,20", "3,5;6,9;10,11;19,21", @@ -131,6 +132,14 @@ private void setContent(String yourText, boolean d) { //2、正常带链接,不带@用户,有展开和收回功能,有切换动画 views[1].setContent(yourText); views[1].setLinkClickListener(linkClickListener); + //添加展开和收回操作 + views[1].setExpandOrContractClickListener(type -> { + if (type.equals(StatusType.STATUS_CONTRACT)) { + Toast.makeText(MainActivity.this, "收回操作", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(MainActivity.this, "展开操作", Toast.LENGTH_SHORT).show(); + } + }); //3、正常不带链接,不带@用户,有展开和收回功能,有切换动画 views[2].setContent(yourText); @@ -174,7 +183,7 @@ private void setContent(String yourText, boolean d) { */ if (d) { yourText = " 我所认识的中国,强大、友好,[--习大大](schema_jump_userinfo)。@奥特曼 “一带一路”经济带带动了沿线国家的经济发展,促进我国与他国的友好往来和贸易发展,可谓“双赢”,[Github地址](https://github.com/MZCretin/ExpandableTextView)。http://www.baidu.com 自古以来,中国以和平、友好的面孔示人。汉武帝派张骞出使西域,开辟丝绸之路,增进与西域各国的友好往来。http://www.baidu.com 胡麻、胡豆、香料等食材也随之传入中国,汇集于中华美食。@RNG 漠漠古道,驼铃阵阵,这条路奠定了“一带一路”的基础,让世界认识了中国。"; - }else{ + } else { tips[9].setText("10、正常带链接和@用户,有展开,有收回功能,带自定义规则"); setTips(); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 812c20d..fd13907 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -97,7 +97,7 @@ android:paddingLeft="15dp" android:paddingRight="15dp" android:paddingTop="10dp" - android:text="2、正常带链接,不带@用户,有展开和收回功能,有切换动画" + android:text="2、正常带链接,不带@用户,有展开和收回功能,有切换动画,有展开和回收的动作监听" android:textColor="#666666" android:textSize="14sp" /> diff --git a/expandabletextviewlibrary/src/main/java/com/ctetin/expandabletextviewlibrary/ExpandableTextView.java b/expandabletextviewlibrary/src/main/java/com/ctetin/expandabletextviewlibrary/ExpandableTextView.java index 71e346d..7689f06 100644 --- a/expandabletextviewlibrary/src/main/java/com/ctetin/expandabletextviewlibrary/ExpandableTextView.java +++ b/expandabletextviewlibrary/src/main/java/com/ctetin/expandabletextviewlibrary/ExpandableTextView.java @@ -102,6 +102,11 @@ public class ExpandableTextView extends AppCompatTextView { */ private OnLinkClickListener linkClickListener; + /** + * 展开或者收回事件监听 + */ + private OnExpandOrContractClickListener expandOrContractClickListener; + /** * 是否需要收起 */ @@ -425,6 +430,9 @@ public void onClick(View widget) { } else { action(); } + if (expandOrContractClickListener != null) { + expandOrContractClickListener.onClick(StatusType.STATUS_EXPAND); + } } @Override @@ -474,6 +482,9 @@ public void onClick(View widget) { } else { action(); } + if (expandOrContractClickListener != null) { + expandOrContractClickListener.onClick(StatusType.STATUS_CONTRACT); + } } @Override @@ -944,6 +955,10 @@ public interface OnLinkClickListener { void onLinkClickListener(LinkType type, String content, String selfContent); } + public interface OnExpandOrContractClickListener { + void onClick(StatusType type); + } + public OnLinkClickListener getLinkClickListener() { return linkClickListener; } @@ -1079,4 +1094,12 @@ public boolean isNeedAlwaysShowRight() { public void setNeedAlwaysShowRight(boolean mNeedAlwaysShowRight) { this.mNeedAlwaysShowRight = mNeedAlwaysShowRight; } + + public OnExpandOrContractClickListener getExpandOrContractClickListener() { + return expandOrContractClickListener; + } + + public void setExpandOrContractClickListener(OnExpandOrContractClickListener expandOrContractClickListener) { + this.expandOrContractClickListener = expandOrContractClickListener; + } } diff --git a/extra/demo.apk b/extra/demo.apk index b5082d4..ac56543 100644 Binary files a/extra/demo.apk and b/extra/demo.apk differ diff --git a/extra/demo.png b/extra/demo.png index 73d0515..1a53035 100644 Binary files a/extra/demo.png and b/extra/demo.png differ