Commit 425d48b6 by ibaker Committed by Oliver Woodman

Migrate usages of Cue constructors to Cue.Builder

All the public Cue constructors are deprecated

PiperOrigin-RevId: 321122512
parent ff451608
...@@ -34,7 +34,7 @@ import java.lang.annotation.RetentionPolicy; ...@@ -34,7 +34,7 @@ import java.lang.annotation.RetentionPolicy;
public final class Cue { public final class Cue {
/** The empty cue. */ /** The empty cue. */
public static final Cue EMPTY = new Cue(""); public static final Cue EMPTY = new Cue.Builder().setText("").build();
/** An unset position, width or size. */ /** An unset position, width or size. */
// Note: We deliberately don't use Float.MIN_VALUE because it's positive & very close to zero. // Note: We deliberately don't use Float.MIN_VALUE because it's positive & very close to zero.
...@@ -276,6 +276,7 @@ public final class Cue { ...@@ -276,6 +276,7 @@ public final class Cue {
* @param text See {@link #text}. * @param text See {@link #text}.
* @deprecated Use {@link Builder}. * @deprecated Use {@link Builder}.
*/ */
@SuppressWarnings("deprecation")
@Deprecated @Deprecated
public Cue(CharSequence text) { public Cue(CharSequence text) {
this( this(
...@@ -302,6 +303,7 @@ public final class Cue { ...@@ -302,6 +303,7 @@ public final class Cue {
* @param size See {@link #size}. * @param size See {@link #size}.
* @deprecated Use {@link Builder}. * @deprecated Use {@link Builder}.
*/ */
@SuppressWarnings("deprecation")
@Deprecated @Deprecated
public Cue( public Cue(
CharSequence text, CharSequence text,
...@@ -340,6 +342,7 @@ public final class Cue { ...@@ -340,6 +342,7 @@ public final class Cue {
* @param textSize See {@link #textSize}. * @param textSize See {@link #textSize}.
* @deprecated Use {@link Builder}. * @deprecated Use {@link Builder}.
*/ */
@SuppressWarnings("deprecation")
@Deprecated @Deprecated
public Cue( public Cue(
CharSequence text, CharSequence text,
......
...@@ -906,7 +906,6 @@ public final class Cea608Decoder extends CeaDecoder { ...@@ -906,7 +906,6 @@ public final class Cea608Decoder extends CeaDecoder {
} }
int positionAnchor; int positionAnchor;
// The number of empty columns after the end of the text, in the same range. // The number of empty columns after the end of the text, in the same range.
int endPadding = SCREEN_CHARWIDTH - startPadding - cueString.length(); int endPadding = SCREEN_CHARWIDTH - startPadding - cueString.length();
int startEndPaddingDelta = startPadding - endPadding; int startEndPaddingDelta = startPadding - endPadding;
...@@ -960,15 +959,13 @@ public final class Cea608Decoder extends CeaDecoder { ...@@ -960,15 +959,13 @@ public final class Cea608Decoder extends CeaDecoder {
line = captionMode == CC_MODE_ROLL_UP ? row - (captionRowCount - 1) : row; line = captionMode == CC_MODE_ROLL_UP ? row - (captionRowCount - 1) : row;
} }
return new Cue( return new Cue.Builder()
cueString, .setText(cueString)
Alignment.ALIGN_NORMAL, .setTextAlignment(Alignment.ALIGN_NORMAL)
line, .setLine(line, Cue.LINE_TYPE_NUMBER)
Cue.LINE_TYPE_NUMBER, .setPosition(position)
/* lineAnchor= */ Cue.TYPE_UNSET, .setPositionAnchor(positionAnchor)
position, .build();
positionAnchor,
Cue.DIMEN_UNSET);
} }
private SpannableString buildCurrentLine() { private SpannableString buildCurrentLine() {
......
...@@ -1329,18 +1329,19 @@ public final class Cea708Decoder extends CeaDecoder { ...@@ -1329,18 +1329,19 @@ public final class Cea708Decoder extends CeaDecoder {
boolean windowColorSet, boolean windowColorSet,
int windowColor, int windowColor,
int priority) { int priority) {
this.cue = Cue.Builder cueBuilder =
new Cue( new Cue.Builder()
text, .setText(text)
textAlignment, .setTextAlignment(textAlignment)
line, .setLine(line, lineType)
lineType, .setLineAnchor(lineAnchor)
lineAnchor, .setPosition(position)
position, .setPositionAnchor(positionAnchor)
positionAnchor, .setSize(size);
size, if (windowColorSet) {
windowColorSet, cueBuilder.setWindowColor(windowColor);
windowColor); }
this.cue = cueBuilder.build();
this.priority = priority; this.priority = priority;
} }
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.text.ssa; package com.google.android.exoplayer2.text.ssa;
import static com.google.android.exoplayer2.text.Cue.LINE_TYPE_FRACTION;
import static com.google.android.exoplayer2.util.Util.castNonNull; import static com.google.android.exoplayer2.util.Util.castNonNull;
import android.text.Layout; import android.text.Layout;
...@@ -299,6 +300,8 @@ public final class SsaDecoder extends SimpleSubtitleDecoder { ...@@ -299,6 +300,8 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
SsaStyle.Overrides styleOverrides, SsaStyle.Overrides styleOverrides,
float screenWidth, float screenWidth,
float screenHeight) { float screenHeight) {
Cue.Builder cue = new Cue.Builder().setText(text);
@SsaStyle.SsaAlignment int alignment; @SsaStyle.SsaAlignment int alignment;
if (styleOverrides.alignment != SsaStyle.SSA_ALIGNMENT_UNKNOWN) { if (styleOverrides.alignment != SsaStyle.SSA_ALIGNMENT_UNKNOWN) {
alignment = styleOverrides.alignment; alignment = styleOverrides.alignment;
...@@ -307,31 +310,22 @@ public final class SsaDecoder extends SimpleSubtitleDecoder { ...@@ -307,31 +310,22 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
} else { } else {
alignment = SsaStyle.SSA_ALIGNMENT_UNKNOWN; alignment = SsaStyle.SSA_ALIGNMENT_UNKNOWN;
} }
@Cue.AnchorType int positionAnchor = toPositionAnchor(alignment); cue.setTextAlignment(toTextAlignment(alignment))
@Cue.AnchorType int lineAnchor = toLineAnchor(alignment); .setPositionAnchor(toPositionAnchor(alignment))
.setLineAnchor(toLineAnchor(alignment));
float position;
float line;
if (styleOverrides.position != null if (styleOverrides.position != null
&& screenHeight != Cue.DIMEN_UNSET && screenHeight != Cue.DIMEN_UNSET
&& screenWidth != Cue.DIMEN_UNSET) { && screenWidth != Cue.DIMEN_UNSET) {
position = styleOverrides.position.x / screenWidth; cue.setPosition(styleOverrides.position.x / screenWidth);
line = styleOverrides.position.y / screenHeight; cue.setLine(styleOverrides.position.y / screenHeight, LINE_TYPE_FRACTION);
} else { } else {
// TODO: Read the MarginL, MarginR and MarginV values from the Style & Dialogue lines. // TODO: Read the MarginL, MarginR and MarginV values from the Style & Dialogue lines.
position = computeDefaultLineOrPosition(positionAnchor); cue.setPosition(computeDefaultLineOrPosition(cue.getPositionAnchor()));
line = computeDefaultLineOrPosition(lineAnchor); cue.setLine(computeDefaultLineOrPosition(cue.getLineAnchor()), LINE_TYPE_FRACTION);
} }
return new Cue( return cue.build();
text,
toTextAlignment(alignment),
line,
Cue.LINE_TYPE_FRACTION,
lineAnchor,
position,
positionAnchor,
/* size= */ Cue.DIMEN_UNSET);
} }
@Nullable @Nullable
......
...@@ -173,61 +173,54 @@ public final class SubripDecoder extends SimpleSubtitleDecoder { ...@@ -173,61 +173,54 @@ public final class SubripDecoder extends SimpleSubtitleDecoder {
* @return Built cue * @return Built cue
*/ */
private Cue buildCue(Spanned text, @Nullable String alignmentTag) { private Cue buildCue(Spanned text, @Nullable String alignmentTag) {
Cue.Builder cue = new Cue.Builder().setText(text);
if (alignmentTag == null) { if (alignmentTag == null) {
return new Cue(text); return cue.build();
} }
// Horizontal alignment. // Horizontal alignment.
@Cue.AnchorType int positionAnchor;
switch (alignmentTag) { switch (alignmentTag) {
case ALIGN_BOTTOM_LEFT: case ALIGN_BOTTOM_LEFT:
case ALIGN_MID_LEFT: case ALIGN_MID_LEFT:
case ALIGN_TOP_LEFT: case ALIGN_TOP_LEFT:
positionAnchor = Cue.ANCHOR_TYPE_START; cue.setPositionAnchor(Cue.ANCHOR_TYPE_START);
break; break;
case ALIGN_BOTTOM_RIGHT: case ALIGN_BOTTOM_RIGHT:
case ALIGN_MID_RIGHT: case ALIGN_MID_RIGHT:
case ALIGN_TOP_RIGHT: case ALIGN_TOP_RIGHT:
positionAnchor = Cue.ANCHOR_TYPE_END; cue.setPositionAnchor(Cue.ANCHOR_TYPE_END);
break; break;
case ALIGN_BOTTOM_MID: case ALIGN_BOTTOM_MID:
case ALIGN_MID_MID: case ALIGN_MID_MID:
case ALIGN_TOP_MID: case ALIGN_TOP_MID:
default: default:
positionAnchor = Cue.ANCHOR_TYPE_MIDDLE; cue.setPositionAnchor(Cue.ANCHOR_TYPE_MIDDLE);
break; break;
} }
// Vertical alignment. // Vertical alignment.
@Cue.AnchorType int lineAnchor;
switch (alignmentTag) { switch (alignmentTag) {
case ALIGN_BOTTOM_LEFT: case ALIGN_BOTTOM_LEFT:
case ALIGN_BOTTOM_MID: case ALIGN_BOTTOM_MID:
case ALIGN_BOTTOM_RIGHT: case ALIGN_BOTTOM_RIGHT:
lineAnchor = Cue.ANCHOR_TYPE_END; cue.setLineAnchor(Cue.ANCHOR_TYPE_END);
break; break;
case ALIGN_TOP_LEFT: case ALIGN_TOP_LEFT:
case ALIGN_TOP_MID: case ALIGN_TOP_MID:
case ALIGN_TOP_RIGHT: case ALIGN_TOP_RIGHT:
lineAnchor = Cue.ANCHOR_TYPE_START; cue.setLineAnchor(Cue.ANCHOR_TYPE_START);
break; break;
case ALIGN_MID_LEFT: case ALIGN_MID_LEFT:
case ALIGN_MID_MID: case ALIGN_MID_MID:
case ALIGN_MID_RIGHT: case ALIGN_MID_RIGHT:
default: default:
lineAnchor = Cue.ANCHOR_TYPE_MIDDLE; cue.setLineAnchor(Cue.ANCHOR_TYPE_MIDDLE);
break; break;
} }
return new Cue( return cue.setPosition(getFractionalPositionForAnchorType(cue.getPositionAnchor()))
text, .setLine(getFractionalPositionForAnchorType(cue.getLineAnchor()), Cue.LINE_TYPE_FRACTION)
/* textAlignment= */ null, .build();
getFractionalPositionForAnchorType(lineAnchor),
Cue.LINE_TYPE_FRACTION,
lineAnchor,
getFractionalPositionForAnchorType(positionAnchor),
positionAnchor,
Cue.DIMEN_UNSET);
} }
private static long parseTimecode(Matcher matcher, int groupOffset) { private static long parseTimecode(Matcher matcher, int groupOffset) {
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
*/ */
package com.google.android.exoplayer2.text.tx3g; package com.google.android.exoplayer2.text.tx3g;
import static com.google.android.exoplayer2.text.Cue.ANCHOR_TYPE_START;
import static com.google.android.exoplayer2.text.Cue.LINE_TYPE_FRACTION;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
...@@ -150,15 +153,11 @@ public final class Tx3gDecoder extends SimpleSubtitleDecoder { ...@@ -150,15 +153,11 @@ public final class Tx3gDecoder extends SimpleSubtitleDecoder {
parsableByteArray.setPosition(position + atomSize); parsableByteArray.setPosition(position + atomSize);
} }
return new Tx3gSubtitle( return new Tx3gSubtitle(
new Cue( new Cue.Builder()
cueText, .setText(cueText)
/* textAlignment= */ null, .setLine(verticalPlacement, LINE_TYPE_FRACTION)
verticalPlacement, .setLineAnchor(ANCHOR_TYPE_START)
Cue.LINE_TYPE_FRACTION, .build());
Cue.ANCHOR_TYPE_START,
Cue.DIMEN_UNSET,
Cue.TYPE_UNSET,
Cue.DIMEN_UNSET));
} }
private static String readSubtitleText(ParsableByteArray parsableByteArray) private static String readSubtitleText(ParsableByteArray parsableByteArray)
......
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