Added Nullity Annotations

This commit is contained in:
Karim Abou Zeid 2015-07-10 02:37:10 +02:00
commit 5317c51400
102 changed files with 772 additions and 404 deletions

View file

@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.view.KeyEvent;
public class MediaButtonIntentReceiver extends BroadcastReceiver {
@ -12,7 +13,7 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
private static long mLastClickTime = 0;
@Override
public void onReceive(Context context, Intent intent) {
public void onReceive(@NonNull Context context, @NonNull Intent intent) {
if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) {
final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event == null)

View file

@ -7,6 +7,8 @@ import android.media.audiofx.AudioEffect;
import android.net.Uri;
import android.os.Handler;
import android.os.PowerManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.Toast;
@ -22,9 +24,12 @@ public class MultiPlayer implements MediaPlayer.OnErrorListener,
MediaPlayer.OnCompletionListener {
public static final String TAG = MultiPlayer.class.getSimpleName();
@NonNull
private final WeakReference<MusicService> mService;
@Nullable
private MediaPlayer mCurrentMediaPlayer = new MediaPlayer();
@Nullable
private MediaPlayer mNextMediaPlayer;
private Handler mHandler;
@ -45,7 +50,7 @@ public class MultiPlayer implements MediaPlayer.OnErrorListener,
* @return True if the <code>player</code> has been prepared and is
* ready to play, false otherwise
*/
public boolean setDataSource(final String path) {
public boolean setDataSource(@NonNull final String path) {
mIsInitialized = false;
mIsInitialized = setDataSourceImpl(mCurrentMediaPlayer, path);
if (mIsInitialized) {
@ -61,7 +66,7 @@ public class MultiPlayer implements MediaPlayer.OnErrorListener,
* @return True if the <code>player</code> has been prepared and is
* ready to play, false otherwise
*/
private boolean setDataSourceImpl(final MediaPlayer player, final String path) {
private boolean setDataSourceImpl(@NonNull final MediaPlayer player, @NonNull final String path) {
MusicService service = mService.get();
if (service == null) {
return false;
@ -95,7 +100,7 @@ public class MultiPlayer implements MediaPlayer.OnErrorListener,
* @param path The path of the file, or the http/rtsp URL of the stream
* you want to play
*/
public void setNextDataSource(final String path) {
public void setNextDataSource(@Nullable final String path) {
MusicService service = mService.get();
if (service == null) {
return;
@ -122,7 +127,7 @@ public class MultiPlayer implements MediaPlayer.OnErrorListener,
if (setDataSourceImpl(mNextMediaPlayer, path)) {
try {
mCurrentMediaPlayer.setNextMediaPlayer(mNextMediaPlayer);
} catch (IllegalArgumentException | IllegalStateException e) {
} catch (@NonNull IllegalArgumentException | IllegalStateException e) {
Log.e(TAG, "setNextDataSource: setNextMediaPlayer()", e);
if (mNextMediaPlayer != null) {
mNextMediaPlayer.release();
@ -269,7 +274,7 @@ public class MultiPlayer implements MediaPlayer.OnErrorListener,
try {
mCurrentMediaPlayer.setAudioSessionId(sessionId);
return true;
} catch (IllegalArgumentException | IllegalStateException e) {
} catch (@NonNull IllegalArgumentException | IllegalStateException e) {
return false;
}
}

View file

@ -23,6 +23,8 @@ import android.os.Message;
import android.os.PowerManager;
import android.os.Process;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Toast;
@ -95,8 +97,11 @@ public class MusicService extends Service {
private final IBinder musicBind = new MusicBinder();
@Nullable
private MultiPlayer player;
@Nullable
private ArrayList<Song> playingQueue;
@Nullable
private ArrayList<Song> originalPlayingQueue;
private int position = -1;
private int nextPosition = -1;
@ -113,14 +118,16 @@ public class MusicService extends Service {
private QueueSaveHandler queueSaveHandler;
private HandlerThread musicPlayerHandlerThread;
private HandlerThread queueSaveHandlerThread;
@Nullable
private RecentlyPlayedStore recentlyPlayedStore;
@Nullable
private SongPlayCountStore songPlayCountStore;
private boolean notNotifiedMetaChangedForCurrentTrack;
private boolean isServiceInUse;
private final BroadcastReceiver becomingNoisyReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
public void onReceive(Context context, @NonNull Intent intent) {
if (intent.getAction().equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
pause();
}
@ -129,7 +136,7 @@ public class MusicService extends Service {
private final BroadcastReceiver preferencesChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
public void onReceive(Context context, @NonNull Intent intent) {
switch (intent.getAction()) {
case SETTING_GAPLESS_PLAYBACK_CHANGED:
setGaplessPlaybackEnabled(intent.getBooleanExtra(SETTING_BOOLEAN_EXTRA, false));
@ -225,7 +232,7 @@ public class MusicService extends Service {
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
if (intent != null) {
if (intent.getAction() != null) {
String action = intent.getAction();
@ -438,7 +445,7 @@ public class MusicService extends Service {
final String currentAlbumArtUri = MusicUtil.getSongImageLoaderString(song);
ImageLoader.getInstance().displayImage(currentAlbumArtUri, new NonViewAware(new ImageSize(-1, -1), ViewScaleType.CROP), new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
public void onLoadingComplete(String imageUri, View view, @Nullable Bitmap loadedImage) {
if (currentAlbumArtUri.equals(imageUri)) {
if (loadedImage != null) {
// RemoteControlClient wants to recycle the bitmaps thrown at it, so we need
@ -495,7 +502,7 @@ public class MusicService extends Service {
WidgetMedium.updateWidgets(this, getCurrentSong(), isPlaying());
}
private static String getTrackUri(Song song) {
private static String getTrackUri(@NonNull Song song) {
return ContentUris.withAppendedId(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, song.id).toString();
}
@ -530,6 +537,7 @@ public class MusicService extends Service {
return getPosition() == getPlayingQueue().size() - 1;
}
@Nullable
public ArrayList<Song> getPlayingQueue() {
return playingQueue;
}
@ -553,7 +561,7 @@ public class MusicService extends Service {
}
}
public void openAndPlayQueue(final ArrayList<Song> playingQueue, final int startPosition, final boolean startPlaying) {
public void openAndPlayQueue(@Nullable final ArrayList<Song> playingQueue, final int startPosition, final boolean startPlaying) {
if (playingQueue != null && !playingQueue.isEmpty() && startPosition >= 0 && startPosition < playingQueue.size()) {
originalPlayingQueue = playingQueue;
this.playingQueue = new ArrayList<>(originalPlayingQueue);
@ -618,7 +626,7 @@ public class MusicService extends Service {
saveState();
}
public void removeSong(Song song) {
public void removeSong(@NonNull Song song) {
for (int i = 0; i < playingQueue.size(); i++) {
if (playingQueue.get(i).id == song.id) playingQueue.remove(i);
}
@ -796,7 +804,7 @@ public class MusicService extends Service {
notifyChange(SHUFFLE_MODE_CHANGED);
}
private void notifyChange(final String what) {
private void notifyChange(@NonNull final String what) {
final Intent internalIntent = new Intent(what);
final Song currentSong = getCurrentSong();
@ -857,21 +865,23 @@ public class MusicService extends Service {
}
public class MusicBinder extends Binder {
@NonNull
public MusicService getService() {
return MusicService.this;
}
}
private static final class QueueSaveHandler extends Handler {
@NonNull
private final WeakReference<MusicService> mService;
public QueueSaveHandler(final MusicService service, final Looper looper) {
public QueueSaveHandler(final MusicService service, @NonNull final Looper looper) {
super(looper);
mService = new WeakReference<>(service);
}
@Override
public void handleMessage(Message msg) {
public void handleMessage(@NonNull Message msg) {
final MusicService service = mService.get();
switch (msg.what) {
case SAVE_QUEUES:
@ -882,16 +892,17 @@ public class MusicService extends Service {
}
private static final class MusicPlayerHandler extends Handler {
@NonNull
private final WeakReference<MusicService> mService;
private float currentDuckVolume = 1.0f;
public MusicPlayerHandler(final MusicService service, final Looper looper) {
public MusicPlayerHandler(final MusicService service, @NonNull final Looper looper) {
super(looper);
mService = new WeakReference<>(service);
}
@Override
public void handleMessage(final Message msg) {
public void handleMessage(@NonNull final Message msg) {
final MusicService service = mService.get();
if (service == null) {
return;