Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Commit

Permalink
Only get specified span in LinkifyTextView
Browse files Browse the repository at this point in the history
  • Loading branch information
seven332 committed Feb 23, 2020
1 parent a099830 commit 806cb0f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions app/src/main/java/com/hippo/nimingban/widget/LinkifyTextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,21 @@
import android.support.annotation.NonNull;
import android.text.Layout;
import android.text.Spanned;
import android.text.style.URLSpan;
import android.util.AttributeSet;
import android.view.MotionEvent;
import com.hippo.nimingban.client.ReferenceSpan;
import com.hippo.nimingban.client.ac.data.ACItemUtils;
import com.hippo.yorozuya.Utilities;

public class LinkifyTextView extends FontTextView {

private static final Class<?>[] SUPPORTED_SPAN_TYPE = {
URLSpan.class,
ReferenceSpan.class,
ACItemUtils.HideSpan.class,
};

private Object mCurrentSpan;

public LinkifyTextView(Context context) {
Expand Down Expand Up @@ -75,8 +85,11 @@ public boolean onTouchEvent(@NonNull MotionEvent event) {

Object[] spans = ((Spanned)getText()).getSpans(off, off, Object.class);

if (spans.length > 0) {
mCurrentSpan = spans[0];
for (Object span : spans) {
if (Utilities.contain(SUPPORTED_SPAN_TYPE, span.getClass())) {
mCurrentSpan = span;
break;
}
}
}
}
Expand Down

0 comments on commit 806cb0f

Please sign in to comment.