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;
}
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;
}
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);
}
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);
}
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));
}
Aggregations