Commit 65490f52 by cdrolle Committed by Oliver Woodman

Added support for handling window/cue priority and fill color to Cue and SubtitlePainter.

Cue has been modified to optionally accept a fill color and a toggle specifying when to use the fill color. When the fill color toggle is set, then SubtitlePainter will use the fill color value instead of the color specified by the device's Accessibility settings. Cea708Decoder has also been modified to propagate that value, as well as cleaned up (in terms of documentation) to prepare it for inclusion in the open-source project.

There is also a new Cea708Cue, extending Cue, which holds the Cue's priority, which is used to sort potentially overlapping cues/windows.

Note that I've left the @ClosedSource annotation and logging in this CL. I intend to start testing the 608 and 708 functionality in the Fiber app to ensure that it works as expected on a wide-range of channels (as opposed to the single channel in ExoPlayer Demo) before removing these.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=142173264
parent 72097432
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.text;
import android.graphics.Color;
import android.support.annotation.IntDef;
import android.text.Layout.Alignment;
import java.lang.annotation.Retention;
......@@ -36,19 +37,23 @@ public class Cue {
@Retention(RetentionPolicy.SOURCE)
@IntDef({TYPE_UNSET, ANCHOR_TYPE_START, ANCHOR_TYPE_MIDDLE, ANCHOR_TYPE_END})
public @interface AnchorType {}
/**
* An unset anchor or line type value.
*/
public static final int TYPE_UNSET = Integer.MIN_VALUE;
/**
* Anchors the left (for horizontal positions) or top (for vertical positions) edge of the cue
* box.
*/
public static final int ANCHOR_TYPE_START = 0;
/**
* Anchors the middle of the cue box.
*/
public static final int ANCHOR_TYPE_MIDDLE = 1;
/**
* Anchors the right (for horizontal positions) or bottom (for vertical positions) edge of the cue
* box.
......@@ -61,10 +66,12 @@ public class Cue {
@Retention(RetentionPolicy.SOURCE)
@IntDef({TYPE_UNSET, LINE_TYPE_FRACTION, LINE_TYPE_NUMBER})
public @interface LineType {}
/**
* Value for {@link #lineType} when {@link #line} is a fractional position.
*/
public static final int LINE_TYPE_FRACTION = 0;
/**
* Value for {@link #lineType} when {@link #line} is a line number.
*/
......@@ -74,10 +81,12 @@ public class Cue {
* The cue text. Note the {@link CharSequence} may be decorated with styling spans.
*/
public final CharSequence text;
/**
* The alignment of the cue text within the cue box, or null if the alignment is undefined.
*/
public final Alignment textAlignment;
/**
* The position of the {@link #lineAnchor} of the cue box within the viewport in the direction
* orthogonal to the writing direction, or {@link #DIMEN_UNSET}. When set, the interpretation of
......@@ -86,6 +95,7 @@ public class Cue {
* For horizontal text and {@link #lineType} equal to {@link #LINE_TYPE_FRACTION}, this is the
* fractional vertical position relative to the top of the viewport.
*/
public final float line;
/**
* The type of the {@link #line} value.
......@@ -112,6 +122,7 @@ public class Cue {
* {@code (line == -2 && lineAnchor == ANCHOR_TYPE_START)} position a cue so that only its first
* line is visible at the bottom of the viewport.
*/
@LineType
public final int lineType;
/**
......@@ -122,6 +133,7 @@ public class Cue {
* and {@link #ANCHOR_TYPE_END} correspond to the top, middle and bottom of the cue box
* respectively.
*/
@AnchorType
public final int lineAnchor;
/**
......@@ -133,6 +145,7 @@ public class Cue {
* text.
*/
public final float position;
/**
* The cue box anchor positioned by {@link #position}. One of {@link #ANCHOR_TYPE_START},
* {@link #ANCHOR_TYPE_MIDDLE}, {@link #ANCHOR_TYPE_END} and {@link #TYPE_UNSET}.
......@@ -143,6 +156,7 @@ public class Cue {
*/
@AnchorType
public final int positionAnchor;
/**
* The size of the cue box in the writing direction specified as a fraction of the viewport size
* in that direction, or {@link #DIMEN_UNSET}.
......@@ -150,6 +164,16 @@ public class Cue {
public final float size;
/**
* Specifies whether or not the {@link #windowColor} property is set.
*/
public final boolean windowColorSet;
/**
* The fill color of the window.
*/
public final int windowColor;
/**
* Constructs a cue whose {@link #textAlignment} is null, whose type parameters are set to
* {@link #TYPE_UNSET} and whose dimension parameters are set to {@link #DIMEN_UNSET}.
*
......@@ -171,6 +195,25 @@ public class Cue {
*/
public Cue(CharSequence text, Alignment textAlignment, float line, @LineType int lineType,
@AnchorType int lineAnchor, float position, @AnchorType int positionAnchor, float size) {
this(text, textAlignment, line, lineType, lineAnchor, position, positionAnchor, size, false,
Color.BLACK);
}
/**
* @param text See {@link #text}.
* @param textAlignment See {@link #textAlignment}.
* @param line See {@link #line}.
* @param lineType See {@link #lineType}.
* @param lineAnchor See {@link #lineAnchor}.
* @param position See {@link #position}.
* @param positionAnchor See {@link #positionAnchor}.
* @param size See {@link #size}.
* @param windowColorSet See {@link #windowColorSet}.
* @param windowColor See {@link #windowColor}.
*/
public Cue(CharSequence text, Alignment textAlignment, float line, @LineType int lineType,
@AnchorType int lineAnchor, float position, @AnchorType int positionAnchor, float size,
boolean windowColorSet, int windowColor) {
this.text = text;
this.textAlignment = textAlignment;
this.line = line;
......@@ -179,6 +222,8 @@ public class Cue {
this.position = position;
this.positionAnchor = positionAnchor;
this.size = size;
this.windowColorSet = windowColorSet;
this.windowColor = windowColor;
}
}
......@@ -146,9 +146,13 @@ import com.google.android.exoplayer2.util.Util;
// Nothing to draw.
return;
}
int windowColor = cue.windowColorSet ? cue.windowColor : style.windowColor;
if (!applyEmbeddedStyles) {
// Strip out any embedded styling.
cueText = cueText.toString();
windowColor = style.windowColor;
}
if (areCharSequencesEqual(this.cueText, cueText)
&& Util.areEqual(this.cueTextAlignment, cue.textAlignment)
......@@ -161,7 +165,7 @@ import com.google.android.exoplayer2.util.Util;
&& this.applyEmbeddedStyles == applyEmbeddedStyles
&& this.foregroundColor == style.foregroundColor
&& this.backgroundColor == style.backgroundColor
&& this.windowColor == style.windowColor
&& this.windowColor == windowColor
&& this.edgeType == style.edgeType
&& this.edgeColor == style.edgeColor
&& Util.areEqual(this.textPaint.getTypeface(), style.typeface)
......@@ -187,7 +191,7 @@ import com.google.android.exoplayer2.util.Util;
this.applyEmbeddedStyles = applyEmbeddedStyles;
this.foregroundColor = style.foregroundColor;
this.backgroundColor = style.backgroundColor;
this.windowColor = style.windowColor;
this.windowColor = windowColor;
this.edgeType = style.edgeType;
this.edgeColor = style.edgeColor;
this.textPaint.setTypeface(style.typeface);
......
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