Skip to content

Commit

Permalink
Unwrap all nested IntDef values
Browse files Browse the repository at this point in the history
This seems to work with R8 but interact badly with ProGuard.

issue:#6771
PiperOrigin-RevId: 286215262
  • Loading branch information
icbaker authored and ojw28 committed Dec 18, 2019
1 parent 1106aba commit 5d2ca02
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@
*/
public abstract class MediaCodecRenderer extends BaseRenderer {

/**
* Thrown when a failure occurs instantiating a decoder.
*/
/** Thrown when a failure occurs instantiating a decoder. */
public static class DecoderInitializationException extends Exception {

private static final int CUSTOM_ERROR_CODE_BASE = -50000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ private static Cue createCue(
float screenWidth,
float screenHeight) {
@SsaStyle.SsaAlignment int alignment;
if (styleOverrides.alignment != SsaStyle.SsaAlignment.UNKNOWN) {
if (styleOverrides.alignment != SsaStyle.SSA_ALIGNMENT_UNKNOWN) {
alignment = styleOverrides.alignment;
} else if (style != null) {
alignment = style.alignment;
} else {
alignment = SsaStyle.SsaAlignment.UNKNOWN;
alignment = SsaStyle.SSA_ALIGNMENT_UNKNOWN;
}
@Cue.AnchorType int positionAnchor = toPositionAnchor(alignment);
@Cue.AnchorType int lineAnchor = toLineAnchor(alignment);
Expand Down Expand Up @@ -337,19 +337,19 @@ private static Cue createCue(
@Nullable
private static Layout.Alignment toTextAlignment(@SsaStyle.SsaAlignment int alignment) {
switch (alignment) {
case SsaStyle.SsaAlignment.BOTTOM_LEFT:
case SsaStyle.SsaAlignment.MIDDLE_LEFT:
case SsaStyle.SsaAlignment.TOP_LEFT:
case SsaStyle.SSA_ALIGNMENT_BOTTOM_LEFT:
case SsaStyle.SSA_ALIGNMENT_MIDDLE_LEFT:
case SsaStyle.SSA_ALIGNMENT_TOP_LEFT:
return Layout.Alignment.ALIGN_NORMAL;
case SsaStyle.SsaAlignment.BOTTOM_CENTER:
case SsaStyle.SsaAlignment.MIDDLE_CENTER:
case SsaStyle.SsaAlignment.TOP_CENTER:
case SsaStyle.SSA_ALIGNMENT_BOTTOM_CENTER:
case SsaStyle.SSA_ALIGNMENT_MIDDLE_CENTER:
case SsaStyle.SSA_ALIGNMENT_TOP_CENTER:
return Layout.Alignment.ALIGN_CENTER;
case SsaStyle.SsaAlignment.BOTTOM_RIGHT:
case SsaStyle.SsaAlignment.MIDDLE_RIGHT:
case SsaStyle.SsaAlignment.TOP_RIGHT:
case SsaStyle.SSA_ALIGNMENT_BOTTOM_RIGHT:
case SsaStyle.SSA_ALIGNMENT_MIDDLE_RIGHT:
case SsaStyle.SSA_ALIGNMENT_TOP_RIGHT:
return Layout.Alignment.ALIGN_OPPOSITE;
case SsaStyle.SsaAlignment.UNKNOWN:
case SsaStyle.SSA_ALIGNMENT_UNKNOWN:
return null;
default:
Log.w(TAG, "Unknown alignment: " + alignment);
Expand All @@ -360,19 +360,19 @@ private static Layout.Alignment toTextAlignment(@SsaStyle.SsaAlignment int align
@Cue.AnchorType
private static int toLineAnchor(@SsaStyle.SsaAlignment int alignment) {
switch (alignment) {
case SsaStyle.SsaAlignment.BOTTOM_LEFT:
case SsaStyle.SsaAlignment.BOTTOM_CENTER:
case SsaStyle.SsaAlignment.BOTTOM_RIGHT:
case SsaStyle.SSA_ALIGNMENT_BOTTOM_LEFT:
case SsaStyle.SSA_ALIGNMENT_BOTTOM_CENTER:
case SsaStyle.SSA_ALIGNMENT_BOTTOM_RIGHT:
return Cue.ANCHOR_TYPE_END;
case SsaStyle.SsaAlignment.MIDDLE_LEFT:
case SsaStyle.SsaAlignment.MIDDLE_CENTER:
case SsaStyle.SsaAlignment.MIDDLE_RIGHT:
case SsaStyle.SSA_ALIGNMENT_MIDDLE_LEFT:
case SsaStyle.SSA_ALIGNMENT_MIDDLE_CENTER:
case SsaStyle.SSA_ALIGNMENT_MIDDLE_RIGHT:
return Cue.ANCHOR_TYPE_MIDDLE;
case SsaStyle.SsaAlignment.TOP_LEFT:
case SsaStyle.SsaAlignment.TOP_CENTER:
case SsaStyle.SsaAlignment.TOP_RIGHT:
case SsaStyle.SSA_ALIGNMENT_TOP_LEFT:
case SsaStyle.SSA_ALIGNMENT_TOP_CENTER:
case SsaStyle.SSA_ALIGNMENT_TOP_RIGHT:
return Cue.ANCHOR_TYPE_START;
case SsaStyle.SsaAlignment.UNKNOWN:
case SsaStyle.SSA_ALIGNMENT_UNKNOWN:
return Cue.TYPE_UNSET;
default:
Log.w(TAG, "Unknown alignment: " + alignment);
Expand All @@ -383,19 +383,19 @@ private static int toLineAnchor(@SsaStyle.SsaAlignment int alignment) {
@Cue.AnchorType
private static int toPositionAnchor(@SsaStyle.SsaAlignment int alignment) {
switch (alignment) {
case SsaStyle.SsaAlignment.BOTTOM_LEFT:
case SsaStyle.SsaAlignment.MIDDLE_LEFT:
case SsaStyle.SsaAlignment.TOP_LEFT:
case SsaStyle.SSA_ALIGNMENT_BOTTOM_LEFT:
case SsaStyle.SSA_ALIGNMENT_MIDDLE_LEFT:
case SsaStyle.SSA_ALIGNMENT_TOP_LEFT:
return Cue.ANCHOR_TYPE_START;
case SsaStyle.SsaAlignment.BOTTOM_CENTER:
case SsaStyle.SsaAlignment.MIDDLE_CENTER:
case SsaStyle.SsaAlignment.TOP_CENTER:
case SsaStyle.SSA_ALIGNMENT_BOTTOM_CENTER:
case SsaStyle.SSA_ALIGNMENT_MIDDLE_CENTER:
case SsaStyle.SSA_ALIGNMENT_TOP_CENTER:
return Cue.ANCHOR_TYPE_MIDDLE;
case SsaStyle.SsaAlignment.BOTTOM_RIGHT:
case SsaStyle.SsaAlignment.MIDDLE_RIGHT:
case SsaStyle.SsaAlignment.TOP_RIGHT:
case SsaStyle.SSA_ALIGNMENT_BOTTOM_RIGHT:
case SsaStyle.SSA_ALIGNMENT_MIDDLE_RIGHT:
case SsaStyle.SSA_ALIGNMENT_TOP_RIGHT:
return Cue.ANCHOR_TYPE_END;
case SsaStyle.SsaAlignment.UNKNOWN:
case SsaStyle.SSA_ALIGNMENT_UNKNOWN:
return Cue.TYPE_UNSET;
default:
Log.w(TAG, "Unknown alignment: " + alignment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,52 @@

private static final String TAG = "SsaStyle";

/**
* The SSA/ASS alignments.
*
* <p>Allowed values:
*
* <ul>
* <li>{@link #SSA_ALIGNMENT_UNKNOWN}
* <li>{@link #SSA_ALIGNMENT_BOTTOM_LEFT}
* <li>{@link #SSA_ALIGNMENT_BOTTOM_CENTER}
* <li>{@link #SSA_ALIGNMENT_BOTTOM_RIGHT}
* <li>{@link #SSA_ALIGNMENT_MIDDLE_LEFT}
* <li>{@link #SSA_ALIGNMENT_MIDDLE_CENTER}
* <li>{@link #SSA_ALIGNMENT_MIDDLE_RIGHT}
* <li>{@link #SSA_ALIGNMENT_TOP_LEFT}
* <li>{@link #SSA_ALIGNMENT_TOP_CENTER}
* <li>{@link #SSA_ALIGNMENT_TOP_RIGHT}
* </ul>
*/
@IntDef({
SSA_ALIGNMENT_UNKNOWN,
SSA_ALIGNMENT_BOTTOM_LEFT,
SSA_ALIGNMENT_BOTTOM_CENTER,
SSA_ALIGNMENT_BOTTOM_RIGHT,
SSA_ALIGNMENT_MIDDLE_LEFT,
SSA_ALIGNMENT_MIDDLE_CENTER,
SSA_ALIGNMENT_MIDDLE_RIGHT,
SSA_ALIGNMENT_TOP_LEFT,
SSA_ALIGNMENT_TOP_CENTER,
SSA_ALIGNMENT_TOP_RIGHT,
})
@Documented
@Retention(SOURCE)
public @interface SsaAlignment {}

// The numbering follows the ASS (v4+) spec (i.e. the points on the number pad).
public static final int SSA_ALIGNMENT_UNKNOWN = -1;
public static final int SSA_ALIGNMENT_BOTTOM_LEFT = 1;
public static final int SSA_ALIGNMENT_BOTTOM_CENTER = 2;
public static final int SSA_ALIGNMENT_BOTTOM_RIGHT = 3;
public static final int SSA_ALIGNMENT_MIDDLE_LEFT = 4;
public static final int SSA_ALIGNMENT_MIDDLE_CENTER = 5;
public static final int SSA_ALIGNMENT_MIDDLE_RIGHT = 6;
public static final int SSA_ALIGNMENT_TOP_LEFT = 7;
public static final int SSA_ALIGNMENT_TOP_CENTER = 8;
public static final int SSA_ALIGNMENT_TOP_RIGHT = 9;

public final String name;
@SsaAlignment public final int alignment;

Expand Down Expand Up @@ -77,22 +123,22 @@ private static int parseAlignment(String alignmentStr) {
// Swallow the exception and return UNKNOWN below.
}
Log.w(TAG, "Ignoring unknown alignment: " + alignmentStr);
return SsaAlignment.UNKNOWN;
return SSA_ALIGNMENT_UNKNOWN;
}

private static boolean isValidAlignment(@SsaAlignment int alignment) {
switch (alignment) {
case SsaAlignment.BOTTOM_CENTER:
case SsaAlignment.BOTTOM_LEFT:
case SsaAlignment.BOTTOM_RIGHT:
case SsaAlignment.MIDDLE_CENTER:
case SsaAlignment.MIDDLE_LEFT:
case SsaAlignment.MIDDLE_RIGHT:
case SsaAlignment.TOP_CENTER:
case SsaAlignment.TOP_LEFT:
case SsaAlignment.TOP_RIGHT:
case SSA_ALIGNMENT_BOTTOM_CENTER:
case SSA_ALIGNMENT_BOTTOM_LEFT:
case SSA_ALIGNMENT_BOTTOM_RIGHT:
case SSA_ALIGNMENT_MIDDLE_CENTER:
case SSA_ALIGNMENT_MIDDLE_LEFT:
case SSA_ALIGNMENT_MIDDLE_RIGHT:
case SSA_ALIGNMENT_TOP_CENTER:
case SSA_ALIGNMENT_TOP_LEFT:
case SSA_ALIGNMENT_TOP_RIGHT:
return true;
case SsaAlignment.UNKNOWN:
case SSA_ALIGNMENT_UNKNOWN:
default:
return false;
}
Expand Down Expand Up @@ -177,7 +223,7 @@ private Overrides(@SsaAlignment int alignment, @Nullable PointF position) {
}

public static Overrides parseFromDialogue(String text) {
@SsaAlignment int alignment = SsaAlignment.UNKNOWN;
@SsaAlignment int alignment = SSA_ALIGNMENT_UNKNOWN;
PointF position = null;
Matcher matcher = BRACES_PATTERN.matcher(text);
while (matcher.find()) {
Expand All @@ -192,7 +238,7 @@ public static Overrides parseFromDialogue(String text) {
}
try {
@SsaAlignment int parsedAlignment = parseAlignmentOverride(braceContents);
if (parsedAlignment != SsaAlignment.UNKNOWN) {
if (parsedAlignment != SSA_ALIGNMENT_UNKNOWN) {
alignment = parsedAlignment;
}
} catch (RuntimeException e) {
Expand Down Expand Up @@ -249,36 +295,7 @@ private static PointF parsePosition(String styleOverride) {
@SsaAlignment
private static int parseAlignmentOverride(String braceContents) {
Matcher matcher = ALIGNMENT_OVERRIDE_PATTERN.matcher(braceContents);
return matcher.find() ? parseAlignment(matcher.group(1)) : SsaAlignment.UNKNOWN;
return matcher.find() ? parseAlignment(matcher.group(1)) : SSA_ALIGNMENT_UNKNOWN;
}
}

/** The SSA/ASS alignments. */
@IntDef({
SsaAlignment.UNKNOWN,
SsaAlignment.BOTTOM_LEFT,
SsaAlignment.BOTTOM_CENTER,
SsaAlignment.BOTTOM_RIGHT,
SsaAlignment.MIDDLE_LEFT,
SsaAlignment.MIDDLE_CENTER,
SsaAlignment.MIDDLE_RIGHT,
SsaAlignment.TOP_LEFT,
SsaAlignment.TOP_CENTER,
SsaAlignment.TOP_RIGHT,
})
@Documented
@Retention(SOURCE)
/* package */ @interface SsaAlignment {
// The numbering follows the ASS (v4+) spec (i.e. the points on the number pad).
int UNKNOWN = -1;
int BOTTOM_LEFT = 1;
int BOTTOM_CENTER = 2;
int BOTTOM_RIGHT = 3;
int MIDDLE_LEFT = 4;
int MIDDLE_CENTER = 5;
int MIDDLE_RIGHT = 6;
int TOP_LEFT = 7;
int TOP_CENTER = 8;
int TOP_RIGHT = 9;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,39 +77,40 @@ public static class Builder {
@Documented
@Retention(SOURCE)
@IntDef({
TextAlignment.START,
TextAlignment.CENTER,
TextAlignment.END,
TextAlignment.LEFT,
TextAlignment.RIGHT
TEXT_ALIGNMENT_START,
TEXT_ALIGNMENT_CENTER,
TEXT_ALIGNMENT_END,
TEXT_ALIGNMENT_LEFT,
TEXT_ALIGNMENT_RIGHT
})
public @interface TextAlignment {
/**
* See WebVTT's <a
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-start-alignment">align:start</a>.
*/
int START = 1;
/**
* See WebVTT's <a
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-center-alignment">align:center</a>.
*/
int CENTER = 2;
/**
* See WebVTT's <a
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-end-alignment">align:end</a>.
*/
int END = 3;
/**
* See WebVTT's <a
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-left-alignment">align:left</a>.
*/
int LEFT = 4;
/**
* See WebVTT's <a
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-right-alignment">align:right</a>.
*/
int RIGHT = 5;
}
public @interface TextAlignment {}
/**
* See WebVTT's <a
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-start-alignment">align:start</a>.
*/
public static final int TEXT_ALIGNMENT_START = 1;

/**
* See WebVTT's <a
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-center-alignment">align:center</a>.
*/
public static final int TEXT_ALIGNMENT_CENTER = 2;

/**
* See WebVTT's <a href="https://www.w3.org/TR/webvtt1/#webvtt-cue-end-alignment">align:end</a>.
*/
public static final int TEXT_ALIGNMENT_END = 3;

/**
* See WebVTT's <a href="https://www.w3.org/TR/webvtt1/#webvtt-cue-left-alignment">align:left</a>.
*/
public static final int TEXT_ALIGNMENT_LEFT = 4;

/**
* See WebVTT's <a
* href="https://www.w3.org/TR/webvtt1/#webvtt-cue-right-alignment">align:right</a>.
*/
public static final int TEXT_ALIGNMENT_RIGHT = 5;

private static final String TAG = "WebvttCueBuilder";

Expand Down Expand Up @@ -140,7 +141,7 @@ public void reset() {
endTime = 0;
text = null;
// Default: https://www.w3.org/TR/webvtt1/#webvtt-cue-text-alignment
textAlignment = TextAlignment.CENTER;
textAlignment = TEXT_ALIGNMENT_CENTER;
line = Cue.DIMEN_UNSET;
// Defaults to NUMBER (true): https://www.w3.org/TR/webvtt1/#webvtt-cue-snap-to-lines-flag
lineType = Cue.LINE_TYPE_NUMBER;
Expand Down Expand Up @@ -251,13 +252,13 @@ private static float computeLine(float line, @LineType int lineType) {
// https://www.w3.org/TR/webvtt1/#webvtt-cue-position
private static float derivePosition(@TextAlignment int textAlignment) {
switch (textAlignment) {
case TextAlignment.LEFT:
case TEXT_ALIGNMENT_LEFT:
return 0.0f;
case TextAlignment.RIGHT:
case TEXT_ALIGNMENT_RIGHT:
return 1.0f;
case TextAlignment.START:
case TextAlignment.CENTER:
case TextAlignment.END:
case TEXT_ALIGNMENT_START:
case TEXT_ALIGNMENT_CENTER:
case TEXT_ALIGNMENT_END:
default:
return DEFAULT_POSITION;
}
Expand All @@ -267,13 +268,13 @@ private static float derivePosition(@TextAlignment int textAlignment) {
@AnchorType
private static int derivePositionAnchor(@TextAlignment int textAlignment) {
switch (textAlignment) {
case TextAlignment.LEFT:
case TextAlignment.START:
case TEXT_ALIGNMENT_LEFT:
case TEXT_ALIGNMENT_START:
return Cue.ANCHOR_TYPE_START;
case TextAlignment.RIGHT:
case TextAlignment.END:
case TEXT_ALIGNMENT_RIGHT:
case TEXT_ALIGNMENT_END:
return Cue.ANCHOR_TYPE_END;
case TextAlignment.CENTER:
case TEXT_ALIGNMENT_CENTER:
default:
return Cue.ANCHOR_TYPE_MIDDLE;
}
Expand All @@ -282,13 +283,13 @@ private static int derivePositionAnchor(@TextAlignment int textAlignment) {
@Nullable
private static Alignment convertTextAlignment(@TextAlignment int textAlignment) {
switch (textAlignment) {
case TextAlignment.START:
case TextAlignment.LEFT:
case TEXT_ALIGNMENT_START:
case TEXT_ALIGNMENT_LEFT:
return Alignment.ALIGN_NORMAL;
case TextAlignment.CENTER:
case TEXT_ALIGNMENT_CENTER:
return Alignment.ALIGN_CENTER;
case TextAlignment.END:
case TextAlignment.RIGHT:
case TEXT_ALIGNMENT_END:
case TEXT_ALIGNMENT_RIGHT:
return Alignment.ALIGN_OPPOSITE;
default:
Log.w(TAG, "Unknown textAlignment: " + textAlignment);
Expand Down
Loading

0 comments on commit 5d2ca02

Please sign in to comment.