Commit f8a47bc8 by Arnold Szabo

Modify the SsaColor to be more similar to the Optional class.

parent 22413205
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment