Change nested ternary to switch in SubtitlePainter

The nested ternary is quite hard to read imo, and I believe this is a
no-op change that captures the intent more clearly.

PiperOrigin-RevId: 277320461
This commit is contained in:
ibaker 2019-10-29 18:01:16 +00:00 committed by Oliver Woodman
parent a3d1ab6900
commit e922f83401

View File

@ -304,9 +304,19 @@ import com.google.android.exoplayer2.util.Util;
int textRight; int textRight;
if (cuePosition != Cue.DIMEN_UNSET) { if (cuePosition != Cue.DIMEN_UNSET) {
int anchorPosition = Math.round(parentWidth * cuePosition) + parentLeft; int anchorPosition = Math.round(parentWidth * cuePosition) + parentLeft;
textLeft = cuePositionAnchor == Cue.ANCHOR_TYPE_END ? anchorPosition - textWidth switch (cuePositionAnchor) {
: cuePositionAnchor == Cue.ANCHOR_TYPE_MIDDLE ? (anchorPosition * 2 - textWidth) / 2 case Cue.ANCHOR_TYPE_END:
: anchorPosition; textLeft = anchorPosition - textWidth;
break;
case Cue.ANCHOR_TYPE_MIDDLE:
textLeft = (anchorPosition * 2 - textWidth) / 2;
break;
case Cue.ANCHOR_TYPE_START:
case Cue.TYPE_UNSET:
default:
textLeft = anchorPosition;
}
textLeft = Math.max(textLeft, parentLeft); textLeft = Math.max(textLeft, parentLeft);
textRight = Math.min(textLeft + textWidth, parentRight); textRight = Math.min(textLeft + textWidth, parentRight);
} else { } else {