Fix SubtitleView.ViewType IntDef

PiperOrigin-RevId: 300067502
This commit is contained in:
olly 2020-03-10 12:20:29 +00:00 committed by Oliver Woodman
parent a5f0eb1e10
commit b83041a6f5

View File

@ -80,9 +80,9 @@ public final class SubtitleView extends ViewGroup implements TextOutput {
* <li>{@link #VIEW_TYPE_WEB} * <li>{@link #VIEW_TYPE_WEB}
* </ul> * </ul>
*/ */
@IntDef
@Documented @Documented
@Retention(SOURCE) @Retention(SOURCE)
@IntDef({VIEW_TYPE_TEXT, VIEW_TYPE_WEB})
public @interface ViewType {} public @interface ViewType {}
private @ViewType int viewType; private @ViewType int viewType;
@ -128,19 +128,24 @@ public final class SubtitleView extends ViewGroup implements TextOutput {
* *
* <p>NOTE: {@link #VIEW_TYPE_WEB} is currently very experimental, and doesn't support most * <p>NOTE: {@link #VIEW_TYPE_WEB} is currently very experimental, and doesn't support most
* styling and layout properties of {@link Cue}. * styling and layout properties of {@link Cue}.
*
* @param viewType The {@link ViewType} to use.
*/ */
public void setViewType(@ViewType int newViewType) { public void setViewType(@ViewType int viewType) {
if (viewType == newViewType) { if (this.viewType == viewType) {
return; return;
} }
if (newViewType == VIEW_TYPE_TEXT) { switch (viewType) {
case VIEW_TYPE_TEXT:
setView(new SubtitleTextView(getContext())); setView(new SubtitleTextView(getContext()));
} else if (newViewType == VIEW_TYPE_WEB) { break;
case VIEW_TYPE_WEB:
setView(new SubtitleWebView(getContext())); setView(new SubtitleWebView(getContext()));
} else { break;
default:
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
viewType = newViewType; this.viewType = viewType;
} }
private <T extends View & Output> void setView(T view) { private <T extends View & Output> void setView(T view) {