Add repeat current song mode
This commit is contained in:
parent
5341772d0c
commit
84f0e02882
@ -34,8 +34,10 @@ THE SOFTWARE.
|
||||
<string name="shuffle_enabling">Shuffle enabled</string>
|
||||
<string name="shuffle_disabling">Shuffle disabled</string>
|
||||
<string name="repeat_enable">Enable Repeat</string>
|
||||
<string name="repeat_current">Repeat Song</string>
|
||||
<string name="repeat_disable">Disable Repeat</string>
|
||||
<string name="repeat_enabling">Repeat enabled</string>
|
||||
<string name="repeat_enabling">Repeating all songs</string>
|
||||
<string name="repeat_current_enabling">Repeating current song</string>
|
||||
<string name="repeat_disabling">Repeat disabled</string>
|
||||
<string name="random_enable">Enable Random</string>
|
||||
<string name="random_disable">Disable Random</string>
|
||||
|
@ -302,8 +302,14 @@ public class PlaybackActivity extends Activity implements Handler.Callback, View
|
||||
int state = mState;
|
||||
boolean isShuffling = (state & PlaybackService.FLAG_SHUFFLE) != 0;
|
||||
menu.findItem(MENU_SHUFFLE).setTitle(isShuffling ? R.string.shuffle_disable : R.string.shuffle_enable);
|
||||
boolean isRepeating = (state & PlaybackService.FLAG_REPEAT) != 0;
|
||||
menu.findItem(MENU_REPEAT).setTitle(isRepeating ? R.string.repeat_disable : R.string.repeat_enable);
|
||||
int repeatRes;
|
||||
if ((state & PlaybackService.FLAG_REPEAT) != 0)
|
||||
repeatRes = R.string.repeat_current;
|
||||
else if ((state & PlaybackService.FLAG_REPEAT_CURRENT) != 0)
|
||||
repeatRes = R.string.repeat_disable;
|
||||
else
|
||||
repeatRes = R.string.repeat_enable;
|
||||
menu.findItem(MENU_REPEAT).setTitle(repeatRes);
|
||||
boolean isRandom = (state & PlaybackService.FLAG_RANDOM) != 0;
|
||||
// TODO: find icon (dice? arrow pointing in many directions?)
|
||||
menu.findItem(MENU_RANDOM).setTitle(isRandom ? R.string.random_disable : R.string.random_enable);
|
||||
@ -318,7 +324,7 @@ public class PlaybackActivity extends Activity implements Handler.Callback, View
|
||||
toggleShuffle();
|
||||
return true;
|
||||
case MENU_REPEAT:
|
||||
toggleRepeat();
|
||||
cycleRepeat();
|
||||
return true;
|
||||
case MENU_RANDOM:
|
||||
toggleRandom();
|
||||
@ -349,12 +355,18 @@ public class PlaybackActivity extends Activity implements Handler.Callback, View
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle repeat mode on/off
|
||||
* Cycle repeat mode.
|
||||
*/
|
||||
public void toggleRepeat()
|
||||
public void cycleRepeat()
|
||||
{
|
||||
int state = PlaybackService.get(this).toggleRepeat();
|
||||
int res = (state & PlaybackService.FLAG_REPEAT) == 0 ? R.string.repeat_disabling : R.string.repeat_enabling;
|
||||
int state = PlaybackService.get(this).cycleRepeat();
|
||||
int res;
|
||||
if ((state & PlaybackService.FLAG_REPEAT) != 0)
|
||||
res = R.string.repeat_enabling;
|
||||
else if ((state & PlaybackService.FLAG_REPEAT_CURRENT) != 0)
|
||||
res = R.string.repeat_current_enabling;
|
||||
else
|
||||
res = R.string.repeat_disabling;
|
||||
Toast.makeText(this, res, Toast.LENGTH_SHORT).show();
|
||||
setState(state);
|
||||
}
|
||||
@ -401,7 +413,7 @@ public class PlaybackActivity extends Activity implements Handler.Callback, View
|
||||
previousSong();
|
||||
break;
|
||||
case ACTION_REPEAT:
|
||||
toggleRepeat();
|
||||
cycleRepeat();
|
||||
break;
|
||||
case ACTION_SHUFFLE:
|
||||
toggleShuffle();
|
||||
|
@ -65,7 +65,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
/**
|
||||
* State file version that indicates data order.
|
||||
*/
|
||||
private static final int STATE_VERSION = 1;
|
||||
private static final int STATE_VERSION = 2;
|
||||
|
||||
private static final int NOTIFICATION_ID = 2;
|
||||
|
||||
@ -145,6 +145,11 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
* Set when the user needs to select songs to play.
|
||||
*/
|
||||
public static final int FLAG_EMPTY_QUEUE = 0x40;
|
||||
/**
|
||||
* If set, replay the current song when the end of the song is reached
|
||||
* instead of advancing to the next song.
|
||||
*/
|
||||
public static final int FLAG_REPEAT_CURRENT = 0x80;
|
||||
|
||||
public static final int NEVER = 0;
|
||||
public static final int WHEN_PLAYING = 1;
|
||||
@ -573,14 +578,21 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle repeat mode. Disables random mode.
|
||||
* Cycle repeat mode. Disables random mode.
|
||||
*
|
||||
* @return The new state after this is called.
|
||||
*/
|
||||
public int toggleRepeat()
|
||||
public int cycleRepeat()
|
||||
{
|
||||
synchronized (mStateLock) {
|
||||
return updateState((mState ^ FLAG_REPEAT) & ~FLAG_RANDOM);
|
||||
int state = mState & ~FLAG_RANDOM;
|
||||
if ((state & FLAG_REPEAT_CURRENT) != 0)
|
||||
state &= ~(FLAG_REPEAT|FLAG_REPEAT_CURRENT);
|
||||
else if ((state & FLAG_REPEAT) == 0)
|
||||
state |= FLAG_REPEAT;
|
||||
else if ((state & FLAG_REPEAT) != 0)
|
||||
state = (state | FLAG_REPEAT_CURRENT) & ~FLAG_REPEAT;;
|
||||
return updateState(state);
|
||||
}
|
||||
}
|
||||
|
||||
@ -678,6 +690,8 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
{
|
||||
if (mTimeline.isEndOfQueue())
|
||||
unsetFlag(FLAG_PLAYING);
|
||||
else if ((mState & FLAG_REPEAT_CURRENT) != 0)
|
||||
setCurrentSong(0);
|
||||
else
|
||||
setCurrentSong(+1);
|
||||
}
|
||||
@ -1160,6 +1174,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
|
||||
if (in.readLong() == STATE_FILE_MAGIC && in.readInt() == STATE_VERSION) {
|
||||
mPendingSeek = in.readInt();
|
||||
int savedState = in.readInt();
|
||||
mTimeline.readState(in);
|
||||
|
||||
int finishAction = mTimeline.getFinishAction();
|
||||
@ -1169,6 +1184,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
state |= FLAG_REPEAT;
|
||||
if (mTimeline.isShuffling())
|
||||
state |= FLAG_SHUFFLE;
|
||||
state |= savedState & FLAG_REPEAT_CURRENT;
|
||||
}
|
||||
|
||||
in.close();
|
||||
@ -1194,6 +1210,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
out.writeLong(STATE_FILE_MAGIC);
|
||||
out.writeInt(STATE_VERSION);
|
||||
out.writeInt(pendingSeek);
|
||||
out.writeInt(mState);
|
||||
mTimeline.writeState(out);
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user