From 1ea54b8d7f53c22df8fc86bab8c95f2ce33f916b Mon Sep 17 00:00:00 2001 From: Jordane Quincy Date: Mon, 7 Oct 2019 16:14:48 +0200 Subject: [PATCH] Add color support to UIUtils.applyMarkup (#667) --- .../favourites/FavouritesListFragment.java | 2 +- .../sections/remote/NowPlayingFragment.java | 2 +- .../ui/sections/remote/PlaylistFragment.java | 2 +- .../ui/sections/remote/RemoteFragment.java | 2 +- .../video/PVRChannelsListFragment.java | 2 +- .../xbmc/kore/ui/widgets/NowPlayingPanel.java | 2 +- .../java/org/xbmc/kore/utils/UIUtils.java | 25 ++- app/src/main/res/values/colors.xml | 149 ++++++++++++++++++ 8 files changed, 175 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/xbmc/kore/ui/sections/favourites/FavouritesListFragment.java b/app/src/main/java/org/xbmc/kore/ui/sections/favourites/FavouritesListFragment.java index b16b139..397c66e 100644 --- a/app/src/main/java/org/xbmc/kore/ui/sections/favourites/FavouritesListFragment.java +++ b/app/src/main/java/org/xbmc/kore/ui/sections/favourites/FavouritesListFragment.java @@ -210,7 +210,7 @@ public class FavouritesListFragment extends AbstractListFragment implements Swip } void bindView(FavouriteType.DetailsFavourite favouriteDetail) { - titleView.setText(favouriteDetail.title); + titleView.setText(UIUtils.applyMarkup(context, favouriteDetail.title)); @StringRes final int typeRes; switch (favouriteDetail.type) { diff --git a/app/src/main/java/org/xbmc/kore/ui/sections/remote/NowPlayingFragment.java b/app/src/main/java/org/xbmc/kore/ui/sections/remote/NowPlayingFragment.java index a79c2cc..92cd94a 100644 --- a/app/src/main/java/org/xbmc/kore/ui/sections/remote/NowPlayingFragment.java +++ b/app/src/main/java/org/xbmc/kore/ui/sections/remote/NowPlayingFragment.java @@ -751,7 +751,7 @@ public class NowPlayingFragment extends Fragment break; } - mediaTitle.setText(title); + mediaTitle.setText(UIUtils.applyMarkup(getContext(), title)); mediaTitle.post(UIUtils.getMarqueeToggleableAction(mediaTitle)); mediaUndertitle.setText(underTitle); diff --git a/app/src/main/java/org/xbmc/kore/ui/sections/remote/PlaylistFragment.java b/app/src/main/java/org/xbmc/kore/ui/sections/remote/PlaylistFragment.java index ce42da9..b931c1e 100644 --- a/app/src/main/java/org/xbmc/kore/ui/sections/remote/PlaylistFragment.java +++ b/app/src/main/java/org/xbmc/kore/ui/sections/remote/PlaylistFragment.java @@ -718,7 +718,7 @@ public class PlaylistFragment extends Fragment break; } - viewHolder.title.setText(title); + viewHolder.title.setText(UIUtils.applyMarkup(getContext(), title)); viewHolder.details.setText(details); viewHolder.duration.setText((duration > 0) ? UIUtils.formatTime(duration) : ""); viewHolder.position = position; diff --git a/app/src/main/java/org/xbmc/kore/ui/sections/remote/RemoteFragment.java b/app/src/main/java/org/xbmc/kore/ui/sections/remote/RemoteFragment.java index f484d5a..cff5453 100644 --- a/app/src/main/java/org/xbmc/kore/ui/sections/remote/RemoteFragment.java +++ b/app/src/main/java/org/xbmc/kore/ui/sections/remote/RemoteFragment.java @@ -540,7 +540,7 @@ public class RemoteFragment extends Fragment break; } - nowPlayingTitle.setText(title); + nowPlayingTitle.setText(UIUtils.applyMarkup(getContext(), title)); nowPlayingDetails.setText(underTitle); fastForwardButton.setImageResource(currentFastForwardIcon); diff --git a/app/src/main/java/org/xbmc/kore/ui/sections/video/PVRChannelsListFragment.java b/app/src/main/java/org/xbmc/kore/ui/sections/video/PVRChannelsListFragment.java index 41a2ce1..dcb5804 100644 --- a/app/src/main/java/org/xbmc/kore/ui/sections/video/PVRChannelsListFragment.java +++ b/app/src/main/java/org/xbmc/kore/ui/sections/video/PVRChannelsListFragment.java @@ -389,7 +389,7 @@ public class PVRChannelsListFragment extends Fragment viewHolder.channelGroupId = channelGroupDetails.channelgroupid; viewHolder.channelGroupName = channelGroupDetails.label; - viewHolder.titleView.setText(viewHolder.channelGroupName); + viewHolder.titleView.setText(UIUtils.applyMarkup(getContext(), viewHolder.channelGroupName)); return convertView; } } diff --git a/app/src/main/java/org/xbmc/kore/ui/widgets/NowPlayingPanel.java b/app/src/main/java/org/xbmc/kore/ui/widgets/NowPlayingPanel.java index eca4181..15aa6de 100644 --- a/app/src/main/java/org/xbmc/kore/ui/widgets/NowPlayingPanel.java +++ b/app/src/main/java/org/xbmc/kore/ui/widgets/NowPlayingPanel.java @@ -165,7 +165,7 @@ public class NowPlayingPanel extends SlidingUpPanelLayout { } public void setTitle(String title) { - this.title.setText(title); + this.title.setText(UIUtils.applyMarkup(getContext(), title)); } public void setDetails(String details) { diff --git a/app/src/main/java/org/xbmc/kore/utils/UIUtils.java b/app/src/main/java/org/xbmc/kore/utils/UIUtils.java index 28182dd..cfb7f87 100644 --- a/app/src/main/java/org/xbmc/kore/utils/UIUtils.java +++ b/app/src/main/java/org/xbmc/kore/utils/UIUtils.java @@ -23,6 +23,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; import android.content.res.TypedArray; +import android.graphics.Color; import android.graphics.Rect; import android.os.Handler; import android.os.Vibrator; @@ -31,8 +32,10 @@ import android.support.annotation.NonNull; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.TextViewCompat; import android.support.v7.app.AlertDialog; +import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.TextUtils; +import android.text.style.ForegroundColorSpan; import android.text.style.TextAppearanceSpan; import android.util.DisplayMetrics; import android.view.LayoutInflater; @@ -652,8 +655,8 @@ public class UIUtils { /** * Replaces some BBCode-ish tagged text with styled spans. *

- * Recognizes and styles CR, B, I, UPPERCASE, LOWERCASE and CAPITALIZE; recognizes - * and strips out LIGHT and COLOR. This is very strict/dumb, it only recognizes + * Recognizes and styles COLOR, CR, B, I, UPPERCASE, LOWERCASE and CAPITALIZE; recognizes + * and strips out LIGHT. This is very strict/dumb, it only recognizes * uppercase tags with no spaces around them. * * @param context Activity context needed to resolve the style resources @@ -681,7 +684,8 @@ public class UIUtils { Nestable italic = new Nestable(); Nestable light = new Nestable(); Nestable color = new Nestable(); - Pattern colorTag = Pattern.compile("^\\[COLOR [^\\]]+\\]"); + Pattern colorTag = Pattern.compile("^\\[COLOR ([^\\]]+)\\]"); + String colorName = "white"; for (int i = start, length = src.length(); i < length;) { String s = src.substring(i); int nextTag = s.indexOf('['); @@ -770,8 +774,17 @@ public class UIUtils { } i += 8; } else if (s.startsWith("[/COLOR]")) { - color.end(); - if (color.imbalanced()) { + if(color.end()) { + int colorId = context.getResources().getIdentifier(colorName, "color", context.getPackageName()); + ForegroundColorSpan foregroundColorSpan; + try{ + foregroundColorSpan = new ForegroundColorSpan(context.getResources().getColor(colorId)); + }catch (Resources.NotFoundException nfe){ + foregroundColorSpan = new ForegroundColorSpan(Color.WHITE); + } + sb.setSpan(foregroundColorSpan, color.index, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } + else if (color.imbalanced()) { sb.append("[/COLOR]"); } i += 8; @@ -779,6 +792,8 @@ public class UIUtils { Matcher m = colorTag.matcher(s); if (m.find()) { color.start(); + colorName = m.group(1); + color.index = sb.length(); i += m.end(); } else { sb.append('['); diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ce3cd2e..1a798dd 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -136,4 +136,153 @@ #ff669900 #ffcc0000 + + #f0f8ff + #faebd7 + #00ffff + #7fffd4 + #f0ffff + #f5f5dc + #ffe4c4 + #000000 + #ffebcd + #0000ff + #8a2be2 + #a52a2a + #deb887 + #5f9ea0 + #7fff00 + #d2691e + #ff7f50 + #6495ed + #fff8dc + #dc143c + #00ffff + #00008b + #008b8b + #b8860b + #a9a9a9 + #006400 + #a9a9a9 + #bdb76b + #8b008b + #556b2f + #ff8c00 + #9932cc + #8b0000 + #e9967a + #8fbc8f + #483d8b + #2f4f4f + #2f4f4f + #00ced1 + #9400d3 + #ff1493 + #00bfff + #696969 + #696969 + #1e90ff + #b22222 + #fffaf0 + #228b22 + #ff00ff + #dcdcdc + #f8f8ff + #ffd700 + #daa520 + #808080 + #008000 + #adff2f + #808080 + #f0fff0 + #ff69b4 + #cd5c5c + #4b0082 + #fffff0 + #f0e68c + #e6e6fa + #fff0f5 + #7cfc00 + #fffacd + #add8e6 + #f08080 + #e0ffff + #fafad2 + #d3d3d3 + #90ee90 + #d3d3d3 + #ffb6c1 + #ffa07a + #20b2aa + #87cefa + #778899 + #778899 + #b0c4de + #ffffe0 + #00ff00 + #32cd32 + #faf0e6 + #ff00ff + #800000 + #66cdaa + #0000cd + #ba55d3 + #9370db + #3cb371 + #7b68ee + #00fa9a + #48d1cc + #c71585 + #191970 + #f5fffa + #ffe4e1 + #ffe4b5 + #ffdead + #000080 + #fdf5e6 + #808000 + #6b8e23 + #ffa500 + #ff4500 + #da70d6 + #eee8aa + #98fb98 + #afeeee + #db7093 + #ffefd5 + #ffdab9 + #cd853f + #ffc0cb + #dda0dd + #b0e0e6 + #800080 + #ff0000 + #bc8f8f + #4169e1 + #8b4513 + #fa8072 + #f4a460 + #2e8b57 + #fff5ee + #a0522d + #c0c0c0 + #87ceeb + #6a5acd + #708090 + #708090 + #fffafa + #00ff7f + #4682b4 + #d2b48c + #008080 + #d8bfd8 + #ff6347 + #40e0d0 + #ee82ee + #f5deb3 + + #f5f5f5 + #ffff00 + #9acd32 + \ No newline at end of file