Demo apps: Annotate @NonNull where necessary

Because we now annotate not-null by default in ExoPlayer
library modules, we're seeing warnings in the demo apps where
we override a method and don't explicitly specify an equivalent
@NotNull annotation.

It's probably confusing to use not-null by default for the
demo apps, so this change uses @NonNull where necessary to fix
the warnings.

PiperOrigin-RevId: 296000044
This commit is contained in:
olly 2020-02-19 18:28:42 +00:00 committed by Oliver Woodman
parent 72f4b964a5
commit 7e6a1418e3
9 changed files with 42 additions and 27 deletions

View File

@ -171,8 +171,6 @@ public class MainActivity extends AppCompatActivity
showToast(R.string.error_unsupported_audio);
} else if (trackType == C.TRACK_TYPE_VIDEO) {
showToast(R.string.error_unsupported_video);
} else {
// Do nothing.
}
}
@ -199,6 +197,7 @@ public class MainActivity extends AppCompatActivity
private class MediaQueueListAdapter extends RecyclerView.Adapter<QueueItemViewHolder> {
@Override
@NonNull
public QueueItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
TextView v = (TextView) LayoutInflater.from(parent.getContext())
.inflate(android.R.layout.simple_list_item_1, parent, false);
@ -236,7 +235,9 @@ public class MainActivity extends AppCompatActivity
}
@Override
public boolean onMove(RecyclerView list, RecyclerView.ViewHolder origin,
public boolean onMove(
@NonNull RecyclerView list,
RecyclerView.ViewHolder origin,
RecyclerView.ViewHolder target) {
int fromPosition = origin.getAdapterPosition();
int toPosition = target.getAdapterPosition();
@ -261,7 +262,7 @@ public class MainActivity extends AppCompatActivity
}
@Override
public void clearView(RecyclerView recyclerView, ViewHolder viewHolder) {
public void clearView(@NonNull RecyclerView recyclerView, @NonNull ViewHolder viewHolder) {
super.clearView(recyclerView, viewHolder);
if (draggingFromPosition != C.INDEX_UNSET) {
QueueItemViewHolder queueItemHolder = (QueueItemViewHolder) viewHolder;
@ -300,8 +301,8 @@ public class MainActivity extends AppCompatActivity
super(context, android.R.layout.simple_list_item_1, DemoUtil.SAMPLES);
}
@NonNull
@Override
@NonNull
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View view = super.getView(position, convertView, parent);
((TextView) view).setText(getItem(position).title);

View File

@ -19,6 +19,7 @@ import android.content.Context;
import android.net.Uri;
import android.view.KeyEvent;
import android.view.View;
import androidx.annotation.NonNull;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Player.DiscontinuityReason;
@ -277,12 +278,13 @@ import java.util.Map;
}
@Override
public void onTimelineChanged(Timeline timeline, @TimelineChangeReason int reason) {
public void onTimelineChanged(@NonNull Timeline timeline, @TimelineChangeReason int reason) {
updateCurrentItemIndex();
}
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
public void onTracksChanged(
@NonNull TrackGroupArray trackGroups, @NonNull TrackSelectionArray trackSelections) {
if (currentPlayer == exoPlayer && trackGroups != lastSeenTrackGroupArray) {
MappingTrackSelector.MappedTrackInfo mappedTrackInfo =
trackSelector.getCurrentMappedTrackInfo();

View File

@ -23,6 +23,7 @@ import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.os.Handler;
import android.view.Surface;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.Player;
@ -283,7 +284,7 @@ public final class VideoProcessingGLSurfaceView extends GLSurfaceView {
public void onVideoFrameAboutToBeRendered(
long presentationTimeUs,
long releaseTimeNs,
Format format,
@NonNull Format format,
@Nullable MediaFormat mediaFormat) {
sampleTimestampQueue.add(releaseTimeNs, presentationTimeUs);
}

View File

@ -19,6 +19,7 @@ import static com.google.android.exoplayer2.demo.DemoApplication.DOWNLOAD_NOTIFI
import android.app.Notification;
import android.content.Context;
import androidx.annotation.NonNull;
import com.google.android.exoplayer2.offline.Download;
import com.google.android.exoplayer2.offline.DownloadManager;
import com.google.android.exoplayer2.offline.DownloadService;
@ -44,6 +45,7 @@ public class DemoDownloadService extends DownloadService {
}
@Override
@NonNull
protected DownloadManager getDownloadManager() {
// This will only happen once, because getDownloadManager is guaranteed to be called only once
// in the life cycle of the process.
@ -63,7 +65,8 @@ public class DemoDownloadService extends DownloadService {
}
@Override
protected Notification getForegroundNotification(List<Download> downloads) {
@NonNull
protected Notification getForegroundNotification(@NonNull List<Download> downloads) {
return ((DemoApplication) getApplication())
.getDownloadNotificationHelper()
.buildProgressNotification(
@ -91,7 +94,7 @@ public class DemoDownloadService extends DownloadService {
}
@Override
public void onDownloadChanged(DownloadManager manager, Download download) {
public void onDownloadChanged(@NonNull DownloadManager manager, @NonNull Download download) {
Notification notification;
if (download.state == Download.STATE_COMPLETED) {
notification =

View File

@ -19,6 +19,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import com.google.android.exoplayer2.C;
@ -141,7 +142,8 @@ public class DownloadTracker {
private class DownloadManagerListener implements DownloadManager.Listener {
@Override
public void onDownloadChanged(DownloadManager downloadManager, Download download) {
public void onDownloadChanged(
@NonNull DownloadManager downloadManager, @NonNull Download download) {
downloads.put(download.request.uri, download);
for (Listener listener : listeners) {
listener.onDownloadsChanged();
@ -149,7 +151,8 @@ public class DownloadTracker {
}
@Override
public void onDownloadRemoved(DownloadManager downloadManager, Download download) {
public void onDownloadRemoved(
@NonNull DownloadManager downloadManager, @NonNull Download download) {
downloads.remove(download.request.uri);
for (Listener listener : listeners) {
listener.onDownloadsChanged();
@ -187,7 +190,7 @@ public class DownloadTracker {
// DownloadHelper.Callback implementation.
@Override
public void onPrepared(DownloadHelper helper) {
public void onPrepared(@NonNull DownloadHelper helper) {
if (helper.getPeriodCount() == 0) {
Log.d(TAG, "No periods found. Downloading entire stream.");
startDownload();
@ -214,7 +217,7 @@ public class DownloadTracker {
}
@Override
public void onPrepareError(DownloadHelper helper, IOException e) {
public void onPrepareError(@NonNull DownloadHelper helper, @NonNull IOException e) {
Toast.makeText(context, R.string.download_start_error, Toast.LENGTH_LONG).show();
Log.e(
TAG,

View File

@ -298,7 +298,7 @@ public class PlayerActivity extends AppCompatActivity
}
@Override
public void onSaveInstanceState(Bundle outState) {
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
updateTrackSelectorParameters();
updateStartPosition();
@ -628,13 +628,15 @@ public class PlayerActivity extends AppCompatActivity
DrmSessionManager.getDummyDrmSessionManager();
@Override
@NonNull
public MediaSourceFactory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
this.drmSessionManager = drmSessionManager;
return this;
}
@Override
public MediaSource createMediaSource(Uri uri) {
@NonNull
public MediaSource createMediaSource(@NonNull Uri uri) {
return PlayerActivity.this.createLeafMediaSource(
uri, /* extension=*/ null, drmSessionManager);
}
@ -697,7 +699,7 @@ public class PlayerActivity extends AppCompatActivity
}
@Override
public void onPlayerError(ExoPlaybackException e) {
public void onPlayerError(@NonNull ExoPlaybackException e) {
if (isBehindLiveWindow(e)) {
clearStartPosition();
initializePlayer();
@ -709,7 +711,8 @@ public class PlayerActivity extends AppCompatActivity
@Override
@SuppressWarnings("ReferenceEquality")
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
public void onTracksChanged(
@NonNull TrackGroupArray trackGroups, @NonNull TrackSelectionArray trackSelections) {
updateButtonVisibility();
if (trackGroups != lastSeenTrackGroupArray) {
MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
@ -731,7 +734,8 @@ public class PlayerActivity extends AppCompatActivity
private class PlayerErrorMessageProvider implements ErrorMessageProvider<ExoPlaybackException> {
@Override
public Pair<Integer, String> getErrorMessage(ExoPlaybackException e) {
@NonNull
public Pair<Integer, String> getErrorMessage(@NonNull ExoPlaybackException e) {
String errorString = getString(R.string.error_generic);
if (e.type == ExoPlaybackException.TYPE_RENDERER) {
Exception cause = e.getRendererException();

View File

@ -267,7 +267,7 @@ import java.util.UUID;
}
}
@Nullable public final String name;
public final String name;
public Sample(String name) {
this.name = name;

View File

@ -24,6 +24,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDialog;
import androidx.fragment.app.DialogFragment;
@ -212,6 +213,7 @@ public final class TrackSelectionDialog extends DialogFragment {
}
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
// We need to own the view to let tab layout work correctly on all API levels. We can't use
// AlertDialog because it owns the view itself, so we use AppCompatDialog instead, themed using
@ -223,16 +225,14 @@ public final class TrackSelectionDialog extends DialogFragment {
}
@Override
public void onDismiss(DialogInterface dialog) {
public void onDismiss(@NonNull DialogInterface dialog) {
super.onDismiss(dialog);
onDismissListener.onDismiss(dialog);
}
@Nullable
@Override
public View onCreateView(
LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View dialogView = inflater.inflate(R.layout.track_selection_dialog, container, false);
TabLayout tabLayout = dialogView.findViewById(R.id.track_selection_dialog_tab_layout);
ViewPager viewPager = dialogView.findViewById(R.id.track_selection_dialog_view_pager);
@ -290,6 +290,7 @@ public final class TrackSelectionDialog extends DialogFragment {
}
@Override
@NonNull
public Fragment getItem(int position) {
return tabFragments.valueAt(position);
}
@ -299,7 +300,6 @@ public final class TrackSelectionDialog extends DialogFragment {
return tabFragments.size();
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return getTrackTypeString(getResources(), tabTrackTypes.get(position));
@ -341,7 +341,6 @@ public final class TrackSelectionDialog extends DialogFragment {
this.allowMultipleOverrides = allowMultipleOverrides;
}
@Nullable
@Override
public View onCreateView(
LayoutInflater inflater,
@ -360,7 +359,8 @@ public final class TrackSelectionDialog extends DialogFragment {
}
@Override
public void onTrackSelectionChanged(boolean isDisabled, List<SelectionOverride> overrides) {
public void onTrackSelectionChanged(
boolean isDisabled, @NonNull List<SelectionOverride> overrides) {
this.isDisabled = isDisabled;
this.overrides = overrides;
}

View File

@ -220,7 +220,8 @@ public final class MainActivity extends Activity {
throw new IllegalStateException();
}
SimpleExoPlayer player = new SimpleExoPlayer.Builder(getApplicationContext()).build();
player.prepare(mediaSource);
player.setMediaSource(mediaSource);
player.prepare();
player.play();
player.setRepeatMode(Player.REPEAT_MODE_ALL);