mirror of
https://github.com/samsonjs/media.git
synced 2026-04-14 12:45:47 +00:00
Modify the SsaColor to be more similar to the Optional class.
This commit is contained in:
parent
2241320535
commit
f8a47bc86d
3 changed files with 19 additions and 7 deletions
|
|
@ -308,8 +308,8 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
|
|||
|
||||
// Apply primary color.
|
||||
if (style != null) {
|
||||
if (style.primaryColor.isSet) {
|
||||
spannableText.setSpan(new ForegroundColorSpan(style.primaryColor.value),
|
||||
if (style.primaryColor.isSet()) {
|
||||
spannableText.setSpan(new ForegroundColorSpan(style.primaryColor.getColor()),
|
||||
0, spannableText.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import com.google.android.exoplayer2.util.Log;
|
|||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
|
@ -166,14 +167,25 @@ import java.util.regex.Pattern;
|
|||
|
||||
public static SsaColor UNSET = new SsaColor(0, false);
|
||||
|
||||
public final @ColorInt int value;
|
||||
public final boolean isSet;
|
||||
private final @ColorInt int color;
|
||||
private final boolean isSet;
|
||||
|
||||
private SsaColor(@ColorInt int value, boolean isSet) {
|
||||
this.value = value;
|
||||
private SsaColor(@ColorInt int color, boolean isSet) {
|
||||
this.color = color;
|
||||
this.isSet = isSet;
|
||||
}
|
||||
|
||||
public @ColorInt int getColor() {
|
||||
if (!isSet) {
|
||||
throw new NoSuchElementException("No color is present");
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
public boolean isSet() {
|
||||
return isSet;
|
||||
}
|
||||
|
||||
public static SsaColor from(@ColorInt int value) {
|
||||
return new SsaColor(value, true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public final class ColorParser {
|
|||
rgbaStringBuilder.insert(2, "0");
|
||||
}
|
||||
}
|
||||
abgr = (int) Long.parseLong(colorExpression.substring(2), 16);
|
||||
abgr = (int) Long.parseLong(rgbaStringBuilder.substring(2), 16);
|
||||
} else {
|
||||
// Parse color from decimal format (bytes order AABBGGRR).
|
||||
abgr = (int) Long.parseLong(colorExpression);
|
||||
|
|
|
|||
Loading…
Reference in a new issue