|
5 | 5 |
|
6 | 6 | import android.graphics.Color; |
7 | 7 | import android.graphics.Paint; |
| 8 | +import android.text.Spannable; |
| 9 | +import android.text.SpannableString; |
8 | 10 | import android.text.TextUtils; |
9 | 11 |
|
| 12 | +import android.text.style.ForegroundColorSpan; |
| 13 | +import android.text.style.RelativeSizeSpan; |
10 | 14 | import androidx.annotation.ColorInt; |
11 | 15 | import androidx.annotation.NonNull; |
12 | 16 | import androidx.annotation.Nullable; |
@@ -83,6 +87,8 @@ public enum SegmentCategory { |
83 | 87 | MUSIC_OFFTOPIC, |
84 | 88 | }; |
85 | 89 |
|
| 90 | + public static final String COLOR_DOT_STRING = "⬤"; |
| 91 | + |
86 | 92 | public static final float CATEGORY_DEFAULT_OPACITY = 0.7f; |
87 | 93 |
|
88 | 94 | private static final Map<String, SegmentCategory> mValuesMap = new HashMap<>(2 * categoriesWithoutUnsubmitted.length); |
@@ -324,6 +330,32 @@ public StringRef getTitle() { |
324 | 330 | return title; |
325 | 331 | } |
326 | 332 |
|
| 333 | + /** |
| 334 | + * Creates a {@link SpannableString} that starts with a colored dot followed by the provided text. |
| 335 | + */ |
| 336 | + private static SpannableString getCategoryColorDotSpan(String text, @ColorInt int color) { |
| 337 | + SpannableString dotSpan = new SpannableString(COLOR_DOT_STRING + text); |
| 338 | + dotSpan.setSpan(new ForegroundColorSpan(color), 0, 1, |
| 339 | + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); |
| 340 | + dotSpan.setSpan(new RelativeSizeSpan(1.5f), 0, 1, |
| 341 | + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); |
| 342 | + return dotSpan; |
| 343 | + } |
| 344 | + |
| 345 | + /** |
| 346 | + * Returns the category title with a colored dot. |
| 347 | + */ |
| 348 | + public SpannableString getTitleWithColorDot(@ColorInt int categoryColor) { |
| 349 | + return getCategoryColorDotSpan(" " + title, categoryColor); |
| 350 | + } |
| 351 | + |
| 352 | + /** |
| 353 | + * Returns the category title with a colored dot. |
| 354 | + */ |
| 355 | + public SpannableString getTitleWithColorDot() { |
| 356 | + return getTitleWithColorDot(color); |
| 357 | + } |
| 358 | + |
327 | 359 | /** |
328 | 360 | * Gets the skip button text based on segment position. |
329 | 361 | * |
|
0 commit comments