本文整理匯總了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();
}
};
}