From 591bd6e46a0c10138fe0ea466c42378c030fbc89 Mon Sep 17 00:00:00 2001 From: tonihei Date: Tue, 6 Aug 2019 10:34:15 +0100 Subject: [PATCH] Fix UI module API nullability annotations and make non-null-by-default. PiperOrigin-RevId: 261872025 --- .../exoplayer2/ui/PlayerControlView.java | 10 ++++---- .../android/exoplayer2/ui/PlayerView.java | 23 ++++++++++++------- .../android/exoplayer2/ui/package-info.java | 19 +++++++++++++++ .../exoplayer2/ui/spherical/package-info.java | 19 +++++++++++++++ 4 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 library/ui/src/main/java/com/google/android/exoplayer2/ui/package-info.java create mode 100644 library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/package-info.java diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java index e408035e98..3a194e091a 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java @@ -285,7 +285,7 @@ public class PlayerControlView extends FrameLayout { } public PlayerControlView(Context context, @Nullable AttributeSet attrs) { - this(context, attrs, 0); + this(context, attrs, /* defStyleAttr= */ 0); } public PlayerControlView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { @@ -494,9 +494,10 @@ public class PlayerControlView extends FrameLayout { /** * Sets the {@link VisibilityListener}. * - * @param listener The listener to be notified about visibility changes. + * @param listener The listener to be notified about visibility changes, or null to remove the + * current listener. */ - public void setVisibilityListener(VisibilityListener listener) { + public void setVisibilityListener(@Nullable VisibilityListener listener) { this.visibilityListener = listener; } @@ -512,7 +513,8 @@ public class PlayerControlView extends FrameLayout { /** * Sets the {@link PlaybackPreparer}. * - * @param playbackPreparer The {@link PlaybackPreparer}. + * @param playbackPreparer The {@link PlaybackPreparer}, or null to remove the current playback + * preparer. */ public void setPlaybackPreparer(@Nullable PlaybackPreparer playbackPreparer) { this.playbackPreparer = playbackPreparer; diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java index ec6e94e042..0d66922cab 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java @@ -308,14 +308,14 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider private static final int PICTURE_TYPE_NOT_SET = -1; public PlayerView(Context context) { - this(context, null); + this(context, /* attrs= */ null); } - public PlayerView(Context context, AttributeSet attrs) { - this(context, attrs, 0); + public PlayerView(Context context, @Nullable AttributeSet attrs) { + this(context, attrs, /* defStyleAttr= */ 0); } - public PlayerView(Context context, AttributeSet attrs, int defStyleAttr) { + public PlayerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); if (isInEditMode()) { @@ -505,6 +505,7 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider } /** Returns the player currently set on this view, or null if no player is set. */ + @Nullable public Player getPlayer() { return player; } @@ -904,9 +905,11 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider /** * Set the {@link PlayerControlView.VisibilityListener}. * - * @param listener The listener to be notified about visibility changes. + * @param listener The listener to be notified about visibility changes, or null to remove the + * current listener. */ - public void setControllerVisibilityListener(PlayerControlView.VisibilityListener listener) { + public void setControllerVisibilityListener( + @Nullable PlayerControlView.VisibilityListener listener) { Assertions.checkState(controller != null); controller.setVisibilityListener(listener); } @@ -914,7 +917,8 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider /** * Sets the {@link PlaybackPreparer}. * - * @param playbackPreparer The {@link PlaybackPreparer}. + * @param playbackPreparer The {@link PlaybackPreparer}, or null to remove the current playback + * preparer. */ public void setPlaybackPreparer(@Nullable PlaybackPreparer playbackPreparer) { Assertions.checkState(controller != null); @@ -1006,7 +1010,8 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider * @param listener The listener to be notified about aspect ratios changes of the video content or * the content frame. */ - public void setAspectRatioListener(AspectRatioFrameLayout.AspectRatioListener listener) { + public void setAspectRatioListener( + @Nullable AspectRatioFrameLayout.AspectRatioListener listener) { Assertions.checkState(contentFrame != null); contentFrame.setAspectRatioListener(listener); } @@ -1025,6 +1030,7 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider * @return The {@link SurfaceView}, {@link TextureView}, {@link SphericalSurfaceView} or {@code * null}. */ + @Nullable public View getVideoSurfaceView() { return surfaceView; } @@ -1047,6 +1053,7 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider * @return The {@link SubtitleView}, or {@code null} if the layout has been customized and the * subtitle view is not present. */ + @Nullable public SubtitleView getSubtitleView() { return subtitleView; } diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/package-info.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/package-info.java new file mode 100644 index 0000000000..85903f4659 --- /dev/null +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@NonNullApi +package com.google.android.exoplayer2.ui; + +import com.google.android.exoplayer2.util.NonNullApi; diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/package-info.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/package-info.java new file mode 100644 index 0000000000..bbbffc7a44 --- /dev/null +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@NonNullApi +package com.google.android.exoplayer2.ui.spherical; + +import com.google.android.exoplayer2.util.NonNullApi;