Keep Random instance in ContextApplication
This commit is contained in:
parent
9183f01fc9
commit
6a32d69816
@ -19,6 +19,7 @@
|
||||
package org.kreed.vanilla;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
@ -28,12 +29,20 @@ import android.content.Intent;
|
||||
public class ContextApplication extends Application {
|
||||
private static ContextApplication mInstance;
|
||||
private static ArrayList<Activity> mActivities;
|
||||
private static Random mRandom;
|
||||
|
||||
public ContextApplication()
|
||||
{
|
||||
mInstance = this;
|
||||
}
|
||||
|
||||
|
||||
public static Random getRandom()
|
||||
{
|
||||
if (mRandom == null)
|
||||
mRandom = new Random();
|
||||
return mRandom;
|
||||
}
|
||||
|
||||
public static Context getContext()
|
||||
{
|
||||
return mInstance;
|
||||
|
@ -278,7 +278,6 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
||||
private Handler mHandler;
|
||||
private MediaPlayer mMediaPlayer;
|
||||
private boolean mMediaPlayerInitialized;
|
||||
private Random mRandom;
|
||||
private PowerManager.WakeLock mWakeLock;
|
||||
private Notification mNotification;
|
||||
private SharedPreferences mSettings;
|
||||
@ -315,8 +314,6 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
||||
{
|
||||
Looper.prepare();
|
||||
|
||||
mRandom = new Random();
|
||||
|
||||
boolean stateLoaded = true;
|
||||
|
||||
PlaybackServiceState state = new PlaybackServiceState();
|
||||
@ -598,7 +595,7 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
||||
|
||||
private int randomSong()
|
||||
{
|
||||
return mSongs[mRandom.nextInt(mSongs.length)];
|
||||
return mSongs[ContextApplication.getRandom().nextInt(mSongs.length)];
|
||||
}
|
||||
|
||||
private Song getSong(int delta)
|
||||
@ -662,8 +659,9 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
||||
if (songs == null || songs.length == 0)
|
||||
break;
|
||||
|
||||
Random random = ContextApplication.getRandom();
|
||||
for (int i = songs.length; --i != 0; ) {
|
||||
int j = mRandom.nextInt(i + 1);
|
||||
int j = random.nextInt(i + 1);
|
||||
int tmp = songs[j];
|
||||
songs[j] = songs[i];
|
||||
songs[i] = tmp;
|
||||
|
Loading…
x
Reference in New Issue
Block a user