當前位置: 首頁>>代碼示例>>Java>>正文


Java ClickableSpan.onClick方法代碼示例

本文整理匯總了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);
}
 
開發者ID:yombunker,項目名稱:SpanEZ,代碼行數:8,代碼來源:ClickableSpanEZTest.java

示例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());
}
 
開發者ID:RyPope,項目名稱:TagEditText,代碼行數:16,代碼來源:TagEditTextTest.java

示例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);
            }

    }
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:29,代碼來源:DialogsActivity.java

示例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();

        }
    };
}
 
開發者ID:charafau,項目名稱:TurboChat,代碼行數:51,代碼來源:EspressoTestUtils.java


注:本文中的android.text.style.ClickableSpan.onClick方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。