Skip to content

Commit

Permalink
新增点击展开不真正执行展开操作的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
MZCretin committed Jul 4, 2019
1 parent 335d1c4 commit 6e74acd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class MainActivity extends AppCompatActivity {
};

private void initView() {
views = new ExpandableTextView[11];
views = new ExpandableTextView[12];
tips = new TextView[11];
views[0] = findViewById(R.id.ep_01);
views[1] = findViewById(R.id.ep_02);
Expand All @@ -80,6 +80,7 @@ private void initView() {
views[8] = findViewById(R.id.ep_09);
views[9] = findViewById(R.id.ep_10);
views[10] = findViewById(R.id.ep_11);
views[11] = findViewById(R.id.ep_12);
tips[0] = findViewById(R.id.tv_tips01);
tips[1] = findViewById(R.id.tv_tips02);
tips[2] = findViewById(R.id.tv_tips03);
Expand Down Expand Up @@ -135,6 +136,8 @@ private void setContent(String yourText, boolean d) {
//2、正常带链接,不带@用户,有展开和收回功能,有切换动画
views[1].setContent(yourText);
views[1].setLinkClickListener(linkClickListener);
views[11].setContent(yourText);
views[11].setLinkClickListener(linkClickListener);
//添加展开和收回操作
views[1].setExpandOrContractClickListener(type -> {
if (type.equals(StatusType.STATUS_CONTRACT)) {
Expand All @@ -143,6 +146,14 @@ private void setContent(String yourText, boolean d) {
Toast.makeText(MainActivity.this, "展开操作", Toast.LENGTH_SHORT).show();
}
});
//添加展开和收回操作 只触发点击 不真正触发展开和收回操作
views[11].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();
}
},false);

//3、正常不带链接,不带@用户,有展开和收回功能,有切换动画
views[2].setContent(yourText);
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@
app:ep_need_expand="true"
app:ep_need_mention="false" />

<com.ctetin.expandabletextviewlibrary.ExpandableTextView
android:id="@+id/ep_12"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:lineSpacingExtra="4dp"
android:textSize="14sp"
app:ep_max_line="5"
app:ep_need_contract="true"
app:ep_need_expand="true"
app:ep_need_mention="false" />

<TextView
android:id="@+id/tv_tips03"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public class ExpandableTextView extends AppCompatTextView {
*/
private OnLinkClickListener linkClickListener;

/**
* 点击展开或者收回按钮的时候 是否真的执行操作
*/
private boolean needRealExpandOrContract = true;

/**
* 展开或者收回事件监听
*/
Expand Down Expand Up @@ -464,11 +469,13 @@ private SpannableStringBuilder dealLink(FormatData formatData, boolean ignoreMor
ssb.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
if (mModel != null) {
mModel.setStatus(StatusType.STATUS_CONTRACT);
action(mModel.getStatus());
} else {
action();
if (needRealExpandOrContract) {
if (mModel != null) {
mModel.setStatus(StatusType.STATUS_CONTRACT);
action(mModel.getStatus());
} else {
action();
}
}
if (expandOrContractClickListener != null) {
expandOrContractClickListener.onClick(StatusType.STATUS_EXPAND);
Expand Down Expand Up @@ -1177,4 +1184,9 @@ public OnExpandOrContractClickListener getExpandOrContractClickListener() {
public void setExpandOrContractClickListener(OnExpandOrContractClickListener expandOrContractClickListener) {
this.expandOrContractClickListener = expandOrContractClickListener;
}

public void setExpandOrContractClickListener(OnExpandOrContractClickListener expandOrContractClickListener, boolean needRealExpandOrContract) {
this.expandOrContractClickListener = expandOrContractClickListener;
this.needRealExpandOrContract = needRealExpandOrContract;
}
}

0 comments on commit 6e74acd

Please sign in to comment.