Skip to content
This repository was archived by the owner on Sep 7, 2020. It is now read-only.

Commit 2fdde10

Browse files
author
Carter Hudson
committed
return tag click event consumption
1 parent ea7c90c commit 2fdde10

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

HtmlTextView/src/main/java/org/sufficientlysecure/htmltextview/HtmlTagHandler.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,13 @@ public boolean handleTag(boolean opening, String tag, Editable output, Attribute
271271
@Override
272272
public void onClick(View widget) {
273273
if (onClickATagListenerProvider != null) {
274-
onClickATagListenerProvider.provideTagClickListener()
275-
.onClick(widget, spannedText, getURL());
274+
boolean clickConsumed =
275+
onClickATagListenerProvider.provideTagClickListener()
276+
.onClick(widget, spannedText, getURL());
277+
if (!clickConsumed) {
278+
super.onClick(widget);
279+
}
276280
}
277-
super.onClick(widget);
278281
}
279282
});
280283
} else if (tag.equalsIgnoreCase("code")) {

HtmlTextView/src/main/java/org/sufficientlysecure/htmltextview/OnClickATagListener.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,12 @@
88
* This listener can define what happens when the a tag is clicked
99
*/
1010
public interface OnClickATagListener {
11-
void onClick(View widget, String spannedText, @Nullable String href);
11+
/**
12+
* Notifies of anchor tag click events.
13+
* @param widget - the {@link HtmlTextView} instance
14+
* @param spannedText - the string value of the text spanned
15+
* @param href - the url for the anchor tag
16+
* @return indicates whether the click event has been handled
17+
*/
18+
boolean onClick(View widget, String spannedText, @Nullable String href);
1219
}

example/src/main/java/org/sufficientlysecure/htmltextview/example/MainActivity.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ protected void onCreate(Bundle savedInstanceState) {
7676
// a tag click listener
7777
textView.setOnClickATagListener(new OnClickATagListener() {
7878
@Override
79-
public void onClick(View widget, String spannedText, @Nullable String href) {
79+
public boolean onClick(View widget, String spannedText, @Nullable String href) {
8080
final Toast toast = Toast.makeText(MainActivity.this, null, Toast.LENGTH_SHORT);
8181
toast.setText(href);
8282
toast.show();
83+
84+
return false;
8385
}
8486
});
8587
}

0 commit comments

Comments
 (0)