From e922f834010a8e8fafceca98a2c918ca75b1a1ca Mon Sep 17 00:00:00 2001 From: ibaker Date: Tue, 29 Oct 2019 18:01:16 +0000 Subject: [PATCH] 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 --- .../android/exoplayer2/ui/SubtitlePainter.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitlePainter.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitlePainter.java index 9ed1bbd006..cbece8a59c 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitlePainter.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitlePainter.java @@ -304,9 +304,19 @@ import com.google.android.exoplayer2.util.Util; int textRight; if (cuePosition != Cue.DIMEN_UNSET) { int anchorPosition = Math.round(parentWidth * cuePosition) + parentLeft; - textLeft = cuePositionAnchor == Cue.ANCHOR_TYPE_END ? anchorPosition - textWidth - : cuePositionAnchor == Cue.ANCHOR_TYPE_MIDDLE ? (anchorPosition * 2 - textWidth) / 2 - : anchorPosition; + switch (cuePositionAnchor) { + case Cue.ANCHOR_TYPE_END: + 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); textRight = Math.min(textLeft + textWidth, parentRight); } else {