From e92ea31fcd19800c061f790cce37128b3fd754fd Mon Sep 17 00:00:00 2001 From: krocard Date: Tue, 28 Jan 2020 16:21:50 +0000 Subject: [PATCH] Do not throw on valid SubtitleView.setViewType Calling setViewType with the same view type as the subtitleView is using would throw InvalidArgumentException instead of being a noop. PiperOrigin-RevId: 291937202 --- .../google/android/exoplayer2/ui/SubtitleView.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 281ad7d1e3..c4bdd2ba74 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 @@ -84,6 +84,7 @@ public final class SubtitleView extends ViewGroup implements TextOutput { @Retention(SOURCE) public @interface ViewType {} + private @ViewType int viewType; private Output output; private View innerSubtitleView; @@ -97,6 +98,7 @@ public final class SubtitleView extends ViewGroup implements TextOutput { output = subtitleTextView; innerSubtitleView = subtitleTextView; addView(innerSubtitleView); + viewType = VIEW_TYPE_TEXT; } @Override @@ -126,14 +128,18 @@ public final class SubtitleView extends ViewGroup implements TextOutput { *

NOTE: {@link #VIEW_TYPE_WEB} is currently very experimental, and doesn't support most * styling and layout properties of {@link Cue}. */ - public void setViewType(@ViewType int viewType) { - if (viewType == VIEW_TYPE_TEXT && !(innerSubtitleView instanceof SubtitleTextView)) { + public void setViewType(@ViewType int newViewType) { + if (viewType == newViewType) { + return; + } + if (newViewType == VIEW_TYPE_TEXT) { setView(new SubtitleTextView(getContext())); - } else if (viewType == VIEW_TYPE_WEB && !(innerSubtitleView instanceof SubtitleWebView)) { + } else if (newViewType == VIEW_TYPE_WEB) { setView(new SubtitleWebView(getContext())); } else { throw new IllegalArgumentException(); } + viewType = newViewType; } private void setView(T view) {