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