aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/utils/StylingHelper.java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-05-14 21:54:06 +0200
committerChristian Schneppe <christian@pix-art.de>2018-05-14 21:54:06 +0200
commit9a39f581a8b42d392bd98909b70f3923226d228c (patch)
tree7dabcecbb56b2225e4bba2f586be55a9be4c313a /src/main/java/de/pixart/messenger/utils/StylingHelper.java
parent5fe9daca6323da4c6f1a4a94cb8682355830d8e2 (diff)
apply styling helper to conversation overview
Diffstat (limited to 'src/main/java/de/pixart/messenger/utils/StylingHelper.java')
-rw-r--r--src/main/java/de/pixart/messenger/utils/StylingHelper.java41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/StylingHelper.java b/src/main/java/de/pixart/messenger/utils/StylingHelper.java
index 9db7b2b47..4412d935b 100644
--- a/src/main/java/de/pixart/messenger/utils/StylingHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/StylingHelper.java
@@ -36,6 +36,7 @@ import android.support.annotation.ColorInt;
import android.support.v4.content.ContextCompat;
import android.text.Editable;
import android.text.ParcelableSpan;
+import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextWatcher;
@@ -132,6 +133,44 @@ public class StylingHelper {
}
+ static CharSequence subSequence(CharSequence charSequence, int start, int end) {
+ if (start == 0 && charSequence.length() + 1 == end) {
+ return charSequence;
+ }
+ if (charSequence instanceof Spannable) {
+ Spannable spannable = (Spannable) charSequence;
+ Spannable sub = (Spannable) spannable.subSequence(start, end);
+ for (Class<? extends ParcelableSpan> clazz : SPAN_CLASSES) {
+ ParcelableSpan[] spannables = spannable.getSpans(start, end, clazz);
+ for (ParcelableSpan parcelableSpan : spannables) {
+ int beginSpan = spannable.getSpanStart(parcelableSpan);
+ int endSpan = spannable.getSpanEnd(parcelableSpan);
+ if (beginSpan >= start && endSpan <= end) {
+ continue;
+ }
+ sub.setSpan(clone(parcelableSpan), Math.max(beginSpan - start, 0), Math.min(sub.length() - 1, endSpan), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+ }
+ return sub;
+ } else {
+ return charSequence.subSequence(start, end);
+ }
+ }
+
+ private static ParcelableSpan clone(ParcelableSpan span) {
+ if (span instanceof ForegroundColorSpan) {
+ return new ForegroundColorSpan(((ForegroundColorSpan) span).getForegroundColor());
+ } else if (span instanceof TypefaceSpan) {
+ return new TypefaceSpan(((TypefaceSpan) span).getFamily());
+ } else if (span instanceof StyleSpan) {
+ return new StyleSpan(((StyleSpan) span).getStyle());
+ } else if (span instanceof StrikethroughSpan) {
+ return new StrikethroughSpan();
+ } else {
+ throw new AssertionError("Unknown Span");
+ }
+ }
+
public static boolean isDarkText(TextView textView) {
int argb = textView.getCurrentTextColor();
return Color.red(argb) + Color.green(argb) + Color.blue(argb) == 0;
@@ -163,7 +202,7 @@ public class StylingHelper {
private static
@ColorInt
int transformColor(@ColorInt int c) {
- return Color.argb(Math.round(Color.alpha(c) * 0.6f), Color.red(c), Color.green(c), Color.blue(c));
+ return Color.argb(Math.round(Color.alpha(c) * 0.45f), Color.red(c), Color.green(c), Color.blue(c));
}
private static int indexOfIgnoreCase(final String haystack, final String needle, final int start) {