当前位置: 首页>>代码示例>>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;未经允许,请勿转载。