Add shuffle option
This commit is contained in:
parent
95fcbaff32
commit
003014945a
BIN
res/drawable/ic_menu_shuffle.png
Executable file
BIN
res/drawable/ic_menu_shuffle.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
@ -8,6 +8,10 @@
|
||||
<string name="library">Choose Songs</string>
|
||||
<string name="quit">Stop and Exit</string>
|
||||
<string name="display_mode">Display Mode</string>
|
||||
<string name="shuffle_enable">Enable Shuffle</string>
|
||||
<string name="shuffle_disable">Disable Shuffle</string>
|
||||
<string name="shuffle_enabling">Shuffle enabled for newly added songs</string>
|
||||
<string name="shuffle_disabling">Shuffle disabled</string>
|
||||
|
||||
<!-- Widgets -->
|
||||
<string name="starting">Starting up...</string>
|
||||
|
@ -40,6 +40,7 @@ import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class FullPlaybackActivity extends PlaybackActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, View.OnFocusChangeListener {
|
||||
private IPlaybackService mService;
|
||||
@ -62,6 +63,7 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
private static final int MENU_DISPLAY = 1;
|
||||
private static final int MENU_PREFS = 2;
|
||||
private static final int MENU_LIBRARY = 3;
|
||||
private static final int MENU_SHUFFLE = 4;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle)
|
||||
@ -177,11 +179,20 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
{
|
||||
menu.add(0, MENU_DISPLAY, 0, R.string.display_mode).setIcon(android.R.drawable.ic_menu_gallery);
|
||||
menu.add(0, MENU_LIBRARY, 0, R.string.library).setIcon(android.R.drawable.ic_menu_add);
|
||||
menu.add(0, MENU_SHUFFLE, 0, R.string.shuffle_enable).setIcon(R.drawable.ic_menu_shuffle);
|
||||
menu.add(0, MENU_PREFS, 0, R.string.settings).setIcon(android.R.drawable.ic_menu_preferences);
|
||||
menu.add(0, MENU_QUIT, 0, R.string.quit).setIcon(android.R.drawable.ic_menu_close_clear_cancel);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu)
|
||||
{
|
||||
boolean isShuffling = (mState & PlaybackService.FLAG_SHUFFLE) != 0;
|
||||
menu.findItem(MENU_SHUFFLE).setTitle(isShuffling ? R.string.shuffle_disable : R.string.shuffle_enable);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
@ -189,6 +200,9 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
case MENU_QUIT:
|
||||
ContextApplication.quit(this);
|
||||
break;
|
||||
case MENU_SHUFFLE:
|
||||
mHandler.sendMessage(mHandler.obtainMessage(TOGGLE_FLAG, PlaybackService.FLAG_SHUFFLE, 0));
|
||||
break;
|
||||
case MENU_PREFS:
|
||||
startActivity(new Intent(this, PreferencesActivity.class));
|
||||
break;
|
||||
@ -300,6 +314,7 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
private static final int HIDE = 0;
|
||||
private static final int UPDATE_PROGRESS = 1;
|
||||
private static final int SAVE_DISPLAY_MODE = 2;
|
||||
private static final int TOGGLE_FLAG = 3;
|
||||
|
||||
private Handler mHandler = new Handler() {
|
||||
public void handleMessage(Message message) {
|
||||
@ -318,6 +333,21 @@ public class FullPlaybackActivity extends PlaybackActivity implements View.OnCli
|
||||
editor.putBoolean("separate_info", mCoverView.hasSeparateInfo());
|
||||
editor.commit();
|
||||
break;
|
||||
case TOGGLE_FLAG:
|
||||
int flag = message.arg1;
|
||||
boolean enabling = (mState & flag) == 0;
|
||||
int text = -1;
|
||||
if (flag == PlaybackService.FLAG_SHUFFLE)
|
||||
text = enabling ? R.string.shuffle_enabling : R.string.shuffle_disabling;
|
||||
|
||||
if (text != -1)
|
||||
Toast.makeText(FullPlaybackActivity.this, text, Toast.LENGTH_SHORT).show();
|
||||
|
||||
try {
|
||||
mService.toggleFlag(flag);
|
||||
} catch (RemoteException e) {
|
||||
setService(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -70,7 +70,8 @@ public class PlaybackService extends Service implements Handler.Callback, MediaP
|
||||
|
||||
public static final int FLAG_NO_MEDIA = 0x2;
|
||||
public static final int FLAG_PLAYING = 0x1;
|
||||
public static final int ALL_FLAGS = FLAG_NO_MEDIA + FLAG_PLAYING;
|
||||
public static final int FLAG_SHUFFLE = 0x4;
|
||||
public static final int ALL_FLAGS = FLAG_NO_MEDIA + FLAG_PLAYING + FLAG_SHUFFLE;
|
||||
|
||||
public static final int NEVER = 0;
|
||||
public static final int WHEN_PLAYING = 1;
|
||||
@ -529,12 +530,14 @@ public class PlaybackService extends Service implements Handler.Callback, MediaP
|
||||
if (songs == null || songs.length == 0)
|
||||
return;
|
||||
|
||||
Random random = ContextApplication.getRandom();
|
||||
for (int i = songs.length; --i != 0; ) {
|
||||
int j = random.nextInt(i + 1);
|
||||
long tmp = songs[j];
|
||||
songs[j] = songs[i];
|
||||
songs[i] = tmp;
|
||||
if ((mState & FLAG_SHUFFLE) != 0) {
|
||||
Random random = ContextApplication.getRandom();
|
||||
for (int i = songs.length; --i != 0; ) {
|
||||
int j = random.nextInt(i + 1);
|
||||
long tmp = songs[j];
|
||||
songs[j] = songs[i];
|
||||
songs[i] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user