From 43c01562d15782d68c06b9d438f96e05780833ea Mon Sep 17 00:00:00 2001 From: tonihei Date: Wed, 3 Oct 2018 02:33:50 -0700 Subject: [PATCH] Fix positioning of subtitles. SubtitleView forwards the cue box position to SubtitlePainter. This should be the position relative to the canvas of the SubtitleView. Currently, however, we forward the position relative to the parent of SubtitleView. That causes problems if SubtitleView has a non-zero offset position to its parent. Issue:#4788 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=215535281 --- RELEASENOTES.md | 3 +++ .../google/android/exoplayer2/ui/SubtitleView.java | 14 ++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 2e42b9a7097..9d9d1fa0c62 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -14,6 +14,9 @@ * Fix an issue with blind seeking to windows with non-zero offset in a `ConcatenatingMediaSource` ([#4873](https://github.com/google/ExoPlayer/issues/4873)). +* Fix issue where subtitles have a wrong position if SubtitleView has a non-zero + offset to its parent + ([#4788](https://github.com/google/ExoPlayer/issues/4788)). ### 2.9.0 ### diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitleView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitleView.java index 74266710410..50a923bced1 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitleView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitleView.java @@ -247,19 +247,17 @@ public void setBottomPaddingFraction(float bottomPaddingFraction) { @Override public void dispatchDraw(Canvas canvas) { int cueCount = (cues == null) ? 0 : cues.size(); - int rawTop = getTop(); - int rawBottom = getBottom(); + int rawViewHeight = getHeight(); - // Calculate the bounds after padding is taken into account. - int left = getLeft() + getPaddingLeft(); - int top = rawTop + getPaddingTop(); - int right = getRight() - getPaddingRight(); - int bottom = rawBottom - getPaddingBottom(); + // Calculate the cue box bounds relative to the canvas after padding is taken into account. + int left = getPaddingLeft(); + int top = getPaddingTop(); + int right = getWidth() - getPaddingRight(); + int bottom = rawViewHeight - getPaddingBottom(); if (bottom <= top || right <= left) { // No space to draw subtitles. return; } - int rawViewHeight = rawBottom - rawTop; int viewHeightMinusPadding = bottom - top; float defaultViewTextSizePx =