Search in sources :

Example 46 with URLSpan

use of android.text.style.URLSpan in project XposedInstaller by rovo89.

the class LinkTransformationMethod method getTransformation.

@Override
public CharSequence getTransformation(CharSequence source, View view) {
    if (view instanceof TextView) {
        TextView textView = (TextView) view;
        Linkify.addLinks(textView, Linkify.WEB_URLS);
        if (textView.getText() == null || !(textView.getText() instanceof Spannable)) {
            return source;
        }
        Spannable text = (Spannable) textView.getText();
        URLSpan[] spans = text.getSpans(0, textView.length(), URLSpan.class);
        for (int i = spans.length - 1; i >= 0; i--) {
            URLSpan oldSpan = spans[i];
            int start = text.getSpanStart(oldSpan);
            int end = text.getSpanEnd(oldSpan);
            String url = oldSpan.getURL();
            text.removeSpan(oldSpan);
            text.setSpan(new CustomTabsURLSpan(activity, url), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return text;
    }
    return source;
}
Also used : TextView(android.widget.TextView) URLSpan(android.text.style.URLSpan) Spannable(android.text.Spannable)

Example 47 with URLSpan

use of android.text.style.URLSpan in project MarqueeView by sfsheng0322.

the class CommonFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_tab, container, false);
    marqueeView = view.findViewById(R.id.marqueeView);
    marqueeView1 = view.findViewById(R.id.marqueeView1);
    marqueeView2 = view.findViewById(R.id.marqueeView2);
    marqueeView3 = view.findViewById(R.id.marqueeView3);
    marqueeView4 = view.findViewById(R.id.marqueeView4);
    List<CharSequence> list = new ArrayList<>();
    SpannableString ss1 = new SpannableString("1、MarqueeView开源项目");
    ss1.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.red)), 2, 13, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    list.add(ss1);
    SpannableString ss2 = new SpannableString("2、GitHub:sunfusheng");
    ss2.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.blue)), 9, 19, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    list.add(ss2);
    SpannableString ss3 = new SpannableString("3、个人博客:sunfusheng.com");
    ss3.setSpan(new URLSpan("http://sunfusheng.com/"), 7, 21, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    list.add(ss3);
    list.add("4、新浪微博:@孙福生微博");
    // set Custom font
    marqueeView.setTypeface(ResourcesCompat.getFont(getContext(), R.font.huawenxinwei));
    marqueeView.startWithList(list);
    marqueeView.setOnItemClickListener((position, textView) -> Toast.makeText(getContext(), textView.getText() + "", Toast.LENGTH_SHORT).show());
    marqueeView1.startWithText(getString(R.string.marquee_texts), R.anim.anim_top_in, R.anim.anim_bottom_out);
    marqueeView1.setOnItemClickListener((position, textView) -> Toast.makeText(getContext(), String.valueOf(position) + ". " + textView.getText(), Toast.LENGTH_SHORT).show());
    marqueeView2.startWithText(getString(R.string.marquee_text));
    marqueeView3.startWithText(getString(R.string.marquee_texts));
    marqueeView3.setOnItemClickListener((position, textView) -> {
        CharSequence model = (CharSequence) marqueeView3.getMessages().get(position);
        Toast.makeText(getContext(), model, Toast.LENGTH_SHORT).show();
    });
    List<CustomModel> models = new ArrayList<>();
    models.add(new CustomModel(10000, "增加了新功能:", "设置自定义的Model数据类型"));
    models.add(new CustomModel(10001, "GitHub:sunfusheng", "新浪微博:@孙福生微博"));
    models.add(new CustomModel(10002, "MarqueeView开源项目", "个人博客:sunfusheng.com"));
    marqueeView4.startWithList(models);
    marqueeView4.setOnItemClickListener((position, textView) -> {
        CustomModel model = (CustomModel) marqueeView4.getMessages().get(position);
        Toast.makeText(getContext(), "ID:" + model.id, Toast.LENGTH_SHORT).show();
    });
    return view;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ArrayList(java.util.ArrayList) URLSpan(android.text.style.URLSpan) MarqueeView(com.sunfusheng.marqueeview.MarqueeView) View(android.view.View) CustomModel(com.sunfusheng.marqueeview.demo.model.CustomModel) Nullable(android.support.annotation.Nullable)

Example 48 with URLSpan

use of android.text.style.URLSpan in project robolectric by robolectric.

the class ShadowSpannableStringTest method testSetSpan.

@Test
public void testSetSpan() {
    URLSpan s1 = new URLSpan("http://www.foobar.com");
    UnderlineSpan s2 = new UnderlineSpan();
    spanStr.setSpan(s1, 12, 33, 0);
    spanStr.setSpan(s2, 1, 10, 0);
    assertBothSpans(s1, s2);
}
Also used : URLSpan(android.text.style.URLSpan) UnderlineSpan(android.text.style.UnderlineSpan) Test(org.junit.Test)

Example 49 with URLSpan

use of android.text.style.URLSpan in project robolectric by robolectric.

the class ShadowSpannableStringTest method testGetSpans.

@Test
public void testGetSpans() {
    URLSpan s1 = new URLSpan("http://www.foobar.com");
    UnderlineSpan s2 = new UnderlineSpan();
    spanStr.setSpan(s1, 1, 10, 0);
    spanStr.setSpan(s2, 20, 30, 0);
    Object[] spans = spanStr.getSpans(0, TEST_STRING.length(), Object.class);
    assertThat(spans).isNotNull();
    assertThat(spans.length).isEqualTo(2);
    assertBothSpans(s1, s2);
    spans = spanStr.getSpans(0, TEST_STRING.length(), URLSpan.class);
    assertThat(spans).isNotNull();
    assertThat(spans.length).isEqualTo(1);
    assertThat(spans[0]).isSameInstanceAs(s1);
    spans = spanStr.getSpans(11, 35, Object.class);
    assertThat(spans).isNotNull();
    assertThat(spans.length).isEqualTo(1);
    assertThat(spans[0]).isSameInstanceAs(s2);
    spans = spanStr.getSpans(21, 35, Object.class);
    assertThat(spans).isNotNull();
    assertThat(spans.length).isEqualTo(1);
    assertThat(spans[0]).isSameInstanceAs(s2);
    spans = spanStr.getSpans(5, 15, Object.class);
    assertThat(spans).isNotNull();
    assertThat(spans.length).isEqualTo(1);
    assertThat(spans[0]).isSameInstanceAs(s1);
}
Also used : URLSpan(android.text.style.URLSpan) UnderlineSpan(android.text.style.UnderlineSpan) Test(org.junit.Test)

Example 50 with URLSpan

use of android.text.style.URLSpan in project Conductor by bluelinelabs.

the class HomeController method onFabClicked.

private void onFabClicked(boolean fromFab) {
    SpannableString details = new SpannableString("A small, yet full-featured framework that allows building View-based Android applications");
    details.setSpan(new AbsoluteSizeSpan(16, true), 0, details.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    final String url = "https://github.com/bluelinelabs/Conductor";
    SpannableString link = new SpannableString(url);
    link.setSpan(new URLSpan(url) {

        @Override
        public void onClick(View widget) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
        }
    }, 0, link.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    SpannableStringBuilder description = new SpannableStringBuilder();
    description.append(details);
    description.append("\n\n");
    description.append(link);
    ControllerChangeHandler pushHandler = fromFab ? new TransitionChangeHandlerCompat(new FabToDialogTransitionChangeHandler(), new FadeChangeHandler(false)) : new FadeChangeHandler(false);
    ControllerChangeHandler popHandler = fromFab ? new TransitionChangeHandlerCompat(new FabToDialogTransitionChangeHandler(), new FadeChangeHandler()) : new FadeChangeHandler();
    getRouter().pushController(RouterTransaction.with(new DialogController("Conductor", description)).pushChangeHandler(pushHandler).popChangeHandler(popHandler));
}
Also used : ControllerChangeHandler(com.bluelinelabs.conductor.ControllerChangeHandler) FadeChangeHandler(com.bluelinelabs.conductor.changehandler.FadeChangeHandler) Intent(android.content.Intent) FabToDialogTransitionChangeHandler(com.bluelinelabs.conductor.demo.changehandler.FabToDialogTransitionChangeHandler) SpannableString(android.text.SpannableString) URLSpan(android.text.style.URLSpan) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan) SpannableString(android.text.SpannableString) TransitionChangeHandlerCompat(com.bluelinelabs.conductor.changehandler.TransitionChangeHandlerCompat) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

URLSpan (android.text.style.URLSpan)134 SpannableString (android.text.SpannableString)36 Spannable (android.text.Spannable)22 SpannableStringBuilder (android.text.SpannableStringBuilder)21 TextPaint (android.text.TextPaint)21 Spanned (android.text.Spanned)20 TextView (android.widget.TextView)19 ForegroundColorSpan (android.text.style.ForegroundColorSpan)16 StyleSpan (android.text.style.StyleSpan)16 UnderlineSpan (android.text.style.UnderlineSpan)14 Paint (android.graphics.Paint)13 ImageSpan (android.text.style.ImageSpan)13 StrikethroughSpan (android.text.style.StrikethroughSpan)13 TypefaceSpan (android.text.style.TypefaceSpan)13 View (android.view.View)13 Intent (android.content.Intent)12 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)12 BackgroundColorSpan (android.text.style.BackgroundColorSpan)12 ClickableSpan (android.text.style.ClickableSpan)12 SubscriptSpan (android.text.style.SubscriptSpan)12