Skip to content

Commit

Permalink
新增对展开和回收的事件监听
Browse files Browse the repository at this point in the history
  • Loading branch information
MZCretin committed Oct 9, 2018
1 parent a0091ca commit 25e4d9e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.ctetin.expandabletextviewlibrary.ExpandableTextView;
import com.ctetin.expandabletextviewlibrary.app.LinkType;
import com.ctetin.expandabletextviewlibrary.app.StatusType;


/**
Expand All @@ -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",
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public class ExpandableTextView extends AppCompatTextView {
*/
private OnLinkClickListener linkClickListener;

/**
* 展开或者收回事件监听
*/
private OnExpandOrContractClickListener expandOrContractClickListener;

/**
* 是否需要收起
*/
Expand Down Expand Up @@ -425,6 +430,9 @@ public void onClick(View widget) {
} else {
action();
}
if (expandOrContractClickListener != null) {
expandOrContractClickListener.onClick(StatusType.STATUS_EXPAND);
}
}

@Override
Expand Down Expand Up @@ -474,6 +482,9 @@ public void onClick(View widget) {
} else {
action();
}
if (expandOrContractClickListener != null) {
expandOrContractClickListener.onClick(StatusType.STATUS_CONTRACT);
}
}

@Override
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Binary file modified extra/demo.apk
Binary file not shown.
Binary file modified extra/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 25e4d9e

Please sign in to comment.