本文整理汇总了Java中android.text.style.ClickableSpan.onClick方法的典型用法代码示例。如果您正苦于以下问题:Java ClickableSpan.onClick方法的具体用法?Java ClickableSpan.onClick怎么用?Java ClickableSpan.onClick使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.style.ClickableSpan
的用法示例。
在下文中一共展示了ClickableSpan.onClick方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clicking_the_span_trigger_the_callback
import android.text.style.ClickableSpan; //导入方法依赖的package包/类
@Test
public void clicking_the_span_trigger_the_callback() {
ClickableSpan clickableSpanEZ = ClickableSpanEZ.from(mockListener, FAKE_CONTENT);
clickableSpanEZ.onClick(null);
verify(mockListener, times(1)).onSpanClick(FAKE_CONTENT);
}
示例2: should_remove_tag_on_click
import android.text.style.ClickableSpan; //导入方法依赖的package包/类
@Test
public void should_remove_tag_on_click() {
// Given
final String testValue = "This is a test value.";
final String textToRemove = "test";
final String expectedValue = "This is a value.";
// When
mTagEditText.setText(testValue);
final ClickableSpan clickableSpan = (ClickableSpan) findSpanForString(textToRemove, ClickableSpan.class);
clickableSpan.onClick(null);
// Then
assertEquals(expectedValue, mTagEditText.getText().toString().trim());
}
示例3: didPressedUrl
import android.text.style.ClickableSpan; //导入方法依赖的package包/类
public void didPressedUrl(final ClickableSpan url) {
if (url == null) {
return;
}
if (url instanceof URLSpanUserMention) {
TLRPC.User user = MessagesController.getInstance().getUser(Utilities.parseInt(((URLSpanUserMention) url).getURL()));
if (user != null) {
MessagesController.openChatOrProfileWith(user, null, DialogsActivity.this, 0, false);
}
} else if (url instanceof URLSpanNoUnderline) {
String str = ((URLSpanNoUnderline) url).getURL();
if (str.startsWith("@")) {
MessagesController.openByUserName(str.substring(1), DialogsActivity.this, 0);
}
} else {
final String urlFinal = ((URLSpan) url).getURL();
if (((URLSpan) url).getURL().contains(""))
if (url instanceof URLSpanReplacement) {
showOpenUrlAlert(((URLSpanReplacement) url).getURL(), true);
} else if (url instanceof URLSpan) {
Browser.openUrl(getParentActivity(), urlFinal, true);
} else {
url.onClick(fragmentView);
}
}
}
示例4: clickClickableSpan
import android.text.style.ClickableSpan; //导入方法依赖的package包/类
public static ViewAction clickClickableSpan(final CharSequence textToClick) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return instanceOf(TextView.class);
}
@Override
public String getDescription() {
return "clicking on a ClickableSpan";
}
@Override
public void perform(UiController uiController, View view) {
TextView textView = (TextView) view;
SpannableString spannableString = (SpannableString) textView.getText();
if (spannableString.length() == 0) {
// TextView is empty, nothing to do
throw new NoMatchingViewException.Builder()
.includeViewHierarchy(true)
.withRootView(textView)
.build();
}
// Get the links inside the TextView and check if we find textToClick
ClickableSpan[] spans = spannableString.getSpans(0, spannableString.length(), ClickableSpan.class);
if (spans.length > 0) {
ClickableSpan spanCandidate;
for (ClickableSpan span : spans) {
spanCandidate = span;
int start = spannableString.getSpanStart(spanCandidate);
int end = spannableString.getSpanEnd(spanCandidate);
CharSequence sequence = spannableString.subSequence(start, end);
if (textToClick.toString().equals(sequence.toString())) {
span.onClick(textView);
return;
}
}
}
// textToClick not found in TextView
throw new NoMatchingViewException.Builder()
.includeViewHierarchy(true)
.withRootView(textView)
.build();
}
};
}