From 838faf8e8cc9720fcab0e3fe5e36051ddb1839d9 Mon Sep 17 00:00:00 2001 From: gorodeckii Date: Tue, 4 Jul 2017 12:35:17 +0300 Subject: [PATCH 1/2] added ColoredUrlSpan --- .../utils/spans/ColoredUrlSpan.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/ru/touchin/roboswag/components/utils/spans/ColoredUrlSpan.java diff --git a/src/main/java/ru/touchin/roboswag/components/utils/spans/ColoredUrlSpan.java b/src/main/java/ru/touchin/roboswag/components/utils/spans/ColoredUrlSpan.java new file mode 100644 index 0000000..2c77ae9 --- /dev/null +++ b/src/main/java/ru/touchin/roboswag/components/utils/spans/ColoredUrlSpan.java @@ -0,0 +1,32 @@ +package ru.touchin.roboswag.components.utils.spans; + +import android.support.annotation.ColorInt; +import android.support.annotation.NonNull; +import android.text.TextPaint; +import android.text.style.URLSpan; + +/** + * URLSpan that takes custom color and doesn't have the default underline. + * Don't forget to use + * textView.setMovementMethod(LinkMovementMethod.getInstance()); + * and + * textView.setText(spannableString, TextView.BufferType.SPANNABLE); + */ +public class ColoredUrlSpan extends URLSpan { + + @ColorInt + private final int textColor; + + public ColoredUrlSpan(@ColorInt final int textColor, @NonNull final String url) { + super(url); + this.textColor = textColor; + } + + @Override + public void updateDrawState(@NonNull final TextPaint ds) { + super.updateDrawState(ds); + ds.setUnderlineText(false); + ds.setColor(textColor); + } + +} From 3cc9baa7bad35b9b3fc3adf5773c16ef6854b9d6 Mon Sep 17 00:00:00 2001 From: gorodeckii Date: Wed, 5 Jul 2017 14:30:52 +0300 Subject: [PATCH 2/2] header comments --- .../utils/spans/ColoredUrlSpan.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/ru/touchin/roboswag/components/utils/spans/ColoredUrlSpan.java b/src/main/java/ru/touchin/roboswag/components/utils/spans/ColoredUrlSpan.java index 2c77ae9..6e815e0 100644 --- a/src/main/java/ru/touchin/roboswag/components/utils/spans/ColoredUrlSpan.java +++ b/src/main/java/ru/touchin/roboswag/components/utils/spans/ColoredUrlSpan.java @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2017 RoboSwag (Gavriil Sitnikov, Vsevolod Ivanov) + * + * This file is part of RoboSwag library. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + package ru.touchin.roboswag.components.utils.spans; import android.support.annotation.ColorInt; @@ -6,6 +25,7 @@ import android.text.TextPaint; import android.text.style.URLSpan; /** + * Created by Anton Arhipov on 05/07/2017. * URLSpan that takes custom color and doesn't have the default underline. * Don't forget to use * textView.setMovementMethod(LinkMovementMethod.getInstance());