mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
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:
parent
72f4b964a5
commit
7e6a1418e3
@ -171,8 +171,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
showToast(R.string.error_unsupported_audio);
|
showToast(R.string.error_unsupported_audio);
|
||||||
} else if (trackType == C.TRACK_TYPE_VIDEO) {
|
} else if (trackType == C.TRACK_TYPE_VIDEO) {
|
||||||
showToast(R.string.error_unsupported_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> {
|
private class MediaQueueListAdapter extends RecyclerView.Adapter<QueueItemViewHolder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public QueueItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public QueueItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
TextView v = (TextView) LayoutInflater.from(parent.getContext())
|
TextView v = (TextView) LayoutInflater.from(parent.getContext())
|
||||||
.inflate(android.R.layout.simple_list_item_1, parent, false);
|
.inflate(android.R.layout.simple_list_item_1, parent, false);
|
||||||
@ -236,7 +235,9 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMove(RecyclerView list, RecyclerView.ViewHolder origin,
|
public boolean onMove(
|
||||||
|
@NonNull RecyclerView list,
|
||||||
|
RecyclerView.ViewHolder origin,
|
||||||
RecyclerView.ViewHolder target) {
|
RecyclerView.ViewHolder target) {
|
||||||
int fromPosition = origin.getAdapterPosition();
|
int fromPosition = origin.getAdapterPosition();
|
||||||
int toPosition = target.getAdapterPosition();
|
int toPosition = target.getAdapterPosition();
|
||||||
@ -261,7 +262,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearView(RecyclerView recyclerView, ViewHolder viewHolder) {
|
public void clearView(@NonNull RecyclerView recyclerView, @NonNull ViewHolder viewHolder) {
|
||||||
super.clearView(recyclerView, viewHolder);
|
super.clearView(recyclerView, viewHolder);
|
||||||
if (draggingFromPosition != C.INDEX_UNSET) {
|
if (draggingFromPosition != C.INDEX_UNSET) {
|
||||||
QueueItemViewHolder queueItemHolder = (QueueItemViewHolder) viewHolder;
|
QueueItemViewHolder queueItemHolder = (QueueItemViewHolder) viewHolder;
|
||||||
@ -300,8 +301,8 @@ public class MainActivity extends AppCompatActivity
|
|||||||
super(context, android.R.layout.simple_list_item_1, DemoUtil.SAMPLES);
|
super(context, android.R.layout.simple_list_item_1, DemoUtil.SAMPLES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||||
View view = super.getView(position, convertView, parent);
|
View view = super.getView(position, convertView, parent);
|
||||||
((TextView) view).setText(getItem(position).title);
|
((TextView) view).setText(getItem(position).title);
|
||||||
|
@ -19,6 +19,7 @@ import android.content.Context;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.Player.DiscontinuityReason;
|
import com.google.android.exoplayer2.Player.DiscontinuityReason;
|
||||||
@ -277,12 +278,13 @@ import java.util.Map;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTimelineChanged(Timeline timeline, @TimelineChangeReason int reason) {
|
public void onTimelineChanged(@NonNull Timeline timeline, @TimelineChangeReason int reason) {
|
||||||
updateCurrentItemIndex();
|
updateCurrentItemIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
|
public void onTracksChanged(
|
||||||
|
@NonNull TrackGroupArray trackGroups, @NonNull TrackSelectionArray trackSelections) {
|
||||||
if (currentPlayer == exoPlayer && trackGroups != lastSeenTrackGroupArray) {
|
if (currentPlayer == exoPlayer && trackGroups != lastSeenTrackGroupArray) {
|
||||||
MappingTrackSelector.MappedTrackInfo mappedTrackInfo =
|
MappingTrackSelector.MappedTrackInfo mappedTrackInfo =
|
||||||
trackSelector.getCurrentMappedTrackInfo();
|
trackSelector.getCurrentMappedTrackInfo();
|
||||||
|
@ -23,6 +23,7 @@ import android.opengl.GLES20;
|
|||||||
import android.opengl.GLSurfaceView;
|
import android.opengl.GLSurfaceView;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
@ -283,7 +284,7 @@ public final class VideoProcessingGLSurfaceView extends GLSurfaceView {
|
|||||||
public void onVideoFrameAboutToBeRendered(
|
public void onVideoFrameAboutToBeRendered(
|
||||||
long presentationTimeUs,
|
long presentationTimeUs,
|
||||||
long releaseTimeNs,
|
long releaseTimeNs,
|
||||||
Format format,
|
@NonNull Format format,
|
||||||
@Nullable MediaFormat mediaFormat) {
|
@Nullable MediaFormat mediaFormat) {
|
||||||
sampleTimestampQueue.add(releaseTimeNs, presentationTimeUs);
|
sampleTimestampQueue.add(releaseTimeNs, presentationTimeUs);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import static com.google.android.exoplayer2.demo.DemoApplication.DOWNLOAD_NOTIFI
|
|||||||
|
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import com.google.android.exoplayer2.offline.Download;
|
import com.google.android.exoplayer2.offline.Download;
|
||||||
import com.google.android.exoplayer2.offline.DownloadManager;
|
import com.google.android.exoplayer2.offline.DownloadManager;
|
||||||
import com.google.android.exoplayer2.offline.DownloadService;
|
import com.google.android.exoplayer2.offline.DownloadService;
|
||||||
@ -44,6 +45,7 @@ public class DemoDownloadService extends DownloadService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
protected DownloadManager getDownloadManager() {
|
protected DownloadManager getDownloadManager() {
|
||||||
// This will only happen once, because getDownloadManager is guaranteed to be called only once
|
// This will only happen once, because getDownloadManager is guaranteed to be called only once
|
||||||
// in the life cycle of the process.
|
// in the life cycle of the process.
|
||||||
@ -63,7 +65,8 @@ public class DemoDownloadService extends DownloadService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Notification getForegroundNotification(List<Download> downloads) {
|
@NonNull
|
||||||
|
protected Notification getForegroundNotification(@NonNull List<Download> downloads) {
|
||||||
return ((DemoApplication) getApplication())
|
return ((DemoApplication) getApplication())
|
||||||
.getDownloadNotificationHelper()
|
.getDownloadNotificationHelper()
|
||||||
.buildProgressNotification(
|
.buildProgressNotification(
|
||||||
@ -91,7 +94,7 @@ public class DemoDownloadService extends DownloadService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadChanged(DownloadManager manager, Download download) {
|
public void onDownloadChanged(@NonNull DownloadManager manager, @NonNull Download download) {
|
||||||
Notification notification;
|
Notification notification;
|
||||||
if (download.state == Download.STATE_COMPLETED) {
|
if (download.state == Download.STATE_COMPLETED) {
|
||||||
notification =
|
notification =
|
||||||
|
@ -19,6 +19,7 @@ import android.content.Context;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
@ -141,7 +142,8 @@ public class DownloadTracker {
|
|||||||
private class DownloadManagerListener implements DownloadManager.Listener {
|
private class DownloadManagerListener implements DownloadManager.Listener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadChanged(DownloadManager downloadManager, Download download) {
|
public void onDownloadChanged(
|
||||||
|
@NonNull DownloadManager downloadManager, @NonNull Download download) {
|
||||||
downloads.put(download.request.uri, download);
|
downloads.put(download.request.uri, download);
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
listener.onDownloadsChanged();
|
listener.onDownloadsChanged();
|
||||||
@ -149,7 +151,8 @@ public class DownloadTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadRemoved(DownloadManager downloadManager, Download download) {
|
public void onDownloadRemoved(
|
||||||
|
@NonNull DownloadManager downloadManager, @NonNull Download download) {
|
||||||
downloads.remove(download.request.uri);
|
downloads.remove(download.request.uri);
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
listener.onDownloadsChanged();
|
listener.onDownloadsChanged();
|
||||||
@ -187,7 +190,7 @@ public class DownloadTracker {
|
|||||||
// DownloadHelper.Callback implementation.
|
// DownloadHelper.Callback implementation.
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrepared(DownloadHelper helper) {
|
public void onPrepared(@NonNull DownloadHelper helper) {
|
||||||
if (helper.getPeriodCount() == 0) {
|
if (helper.getPeriodCount() == 0) {
|
||||||
Log.d(TAG, "No periods found. Downloading entire stream.");
|
Log.d(TAG, "No periods found. Downloading entire stream.");
|
||||||
startDownload();
|
startDownload();
|
||||||
@ -214,7 +217,7 @@ public class DownloadTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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();
|
Toast.makeText(context, R.string.download_start_error, Toast.LENGTH_LONG).show();
|
||||||
Log.e(
|
Log.e(
|
||||||
TAG,
|
TAG,
|
||||||
|
@ -298,7 +298,7 @@ public class PlayerActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
updateTrackSelectorParameters();
|
updateTrackSelectorParameters();
|
||||||
updateStartPosition();
|
updateStartPosition();
|
||||||
@ -628,13 +628,15 @@ public class PlayerActivity extends AppCompatActivity
|
|||||||
DrmSessionManager.getDummyDrmSessionManager();
|
DrmSessionManager.getDummyDrmSessionManager();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public MediaSourceFactory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
|
public MediaSourceFactory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
|
||||||
this.drmSessionManager = drmSessionManager;
|
this.drmSessionManager = drmSessionManager;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MediaSource createMediaSource(Uri uri) {
|
@NonNull
|
||||||
|
public MediaSource createMediaSource(@NonNull Uri uri) {
|
||||||
return PlayerActivity.this.createLeafMediaSource(
|
return PlayerActivity.this.createLeafMediaSource(
|
||||||
uri, /* extension=*/ null, drmSessionManager);
|
uri, /* extension=*/ null, drmSessionManager);
|
||||||
}
|
}
|
||||||
@ -697,7 +699,7 @@ public class PlayerActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerError(ExoPlaybackException e) {
|
public void onPlayerError(@NonNull ExoPlaybackException e) {
|
||||||
if (isBehindLiveWindow(e)) {
|
if (isBehindLiveWindow(e)) {
|
||||||
clearStartPosition();
|
clearStartPosition();
|
||||||
initializePlayer();
|
initializePlayer();
|
||||||
@ -709,7 +711,8 @@ public class PlayerActivity extends AppCompatActivity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("ReferenceEquality")
|
@SuppressWarnings("ReferenceEquality")
|
||||||
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
|
public void onTracksChanged(
|
||||||
|
@NonNull TrackGroupArray trackGroups, @NonNull TrackSelectionArray trackSelections) {
|
||||||
updateButtonVisibility();
|
updateButtonVisibility();
|
||||||
if (trackGroups != lastSeenTrackGroupArray) {
|
if (trackGroups != lastSeenTrackGroupArray) {
|
||||||
MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
|
MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
|
||||||
@ -731,7 +734,8 @@ public class PlayerActivity extends AppCompatActivity
|
|||||||
private class PlayerErrorMessageProvider implements ErrorMessageProvider<ExoPlaybackException> {
|
private class PlayerErrorMessageProvider implements ErrorMessageProvider<ExoPlaybackException> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Integer, String> getErrorMessage(ExoPlaybackException e) {
|
@NonNull
|
||||||
|
public Pair<Integer, String> getErrorMessage(@NonNull ExoPlaybackException e) {
|
||||||
String errorString = getString(R.string.error_generic);
|
String errorString = getString(R.string.error_generic);
|
||||||
if (e.type == ExoPlaybackException.TYPE_RENDERER) {
|
if (e.type == ExoPlaybackException.TYPE_RENDERER) {
|
||||||
Exception cause = e.getRendererException();
|
Exception cause = e.getRendererException();
|
||||||
|
@ -267,7 +267,7 @@ import java.util.UUID;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable public final String name;
|
public final String name;
|
||||||
|
|
||||||
public Sample(String name) {
|
public Sample(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -24,6 +24,7 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatDialog;
|
import androidx.appcompat.app.AppCompatDialog;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
@ -212,6 +213,7 @@ public final class TrackSelectionDialog extends DialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
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
|
// 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
|
// 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
|
@Override
|
||||||
public void onDismiss(DialogInterface dialog) {
|
public void onDismiss(@NonNull DialogInterface dialog) {
|
||||||
super.onDismiss(dialog);
|
super.onDismiss(dialog);
|
||||||
onDismissListener.onDismiss(dialog);
|
onDismissListener.onDismiss(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(
|
public View onCreateView(
|
||||||
LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
|
|
||||||
View dialogView = inflater.inflate(R.layout.track_selection_dialog, container, false);
|
View dialogView = inflater.inflate(R.layout.track_selection_dialog, container, false);
|
||||||
TabLayout tabLayout = dialogView.findViewById(R.id.track_selection_dialog_tab_layout);
|
TabLayout tabLayout = dialogView.findViewById(R.id.track_selection_dialog_tab_layout);
|
||||||
ViewPager viewPager = dialogView.findViewById(R.id.track_selection_dialog_view_pager);
|
ViewPager viewPager = dialogView.findViewById(R.id.track_selection_dialog_view_pager);
|
||||||
@ -290,6 +290,7 @@ public final class TrackSelectionDialog extends DialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public Fragment getItem(int position) {
|
public Fragment getItem(int position) {
|
||||||
return tabFragments.valueAt(position);
|
return tabFragments.valueAt(position);
|
||||||
}
|
}
|
||||||
@ -299,7 +300,6 @@ public final class TrackSelectionDialog extends DialogFragment {
|
|||||||
return tabFragments.size();
|
return tabFragments.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getPageTitle(int position) {
|
public CharSequence getPageTitle(int position) {
|
||||||
return getTrackTypeString(getResources(), tabTrackTypes.get(position));
|
return getTrackTypeString(getResources(), tabTrackTypes.get(position));
|
||||||
@ -341,7 +341,6 @@ public final class TrackSelectionDialog extends DialogFragment {
|
|||||||
this.allowMultipleOverrides = allowMultipleOverrides;
|
this.allowMultipleOverrides = allowMultipleOverrides;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(
|
public View onCreateView(
|
||||||
LayoutInflater inflater,
|
LayoutInflater inflater,
|
||||||
@ -360,7 +359,8 @@ public final class TrackSelectionDialog extends DialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrackSelectionChanged(boolean isDisabled, List<SelectionOverride> overrides) {
|
public void onTrackSelectionChanged(
|
||||||
|
boolean isDisabled, @NonNull List<SelectionOverride> overrides) {
|
||||||
this.isDisabled = isDisabled;
|
this.isDisabled = isDisabled;
|
||||||
this.overrides = overrides;
|
this.overrides = overrides;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,8 @@ public final class MainActivity extends Activity {
|
|||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
SimpleExoPlayer player = new SimpleExoPlayer.Builder(getApplicationContext()).build();
|
SimpleExoPlayer player = new SimpleExoPlayer.Builder(getApplicationContext()).build();
|
||||||
player.prepare(mediaSource);
|
player.setMediaSource(mediaSource);
|
||||||
|
player.prepare();
|
||||||
player.play();
|
player.play();
|
||||||
player.setRepeatMode(Player.REPEAT_MODE_ALL);
|
player.setRepeatMode(Player.REPEAT_MODE_ALL);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user