Show shuffle/repeat buttons in library and mini activity
This commit is contained in:
parent
d43dcc14ae
commit
0ff18ca932
Binary file not shown.
Before Width: | Height: | Size: 273 B After Width: | Height: | Size: 273 B |
Binary file not shown.
Before Width: | Height: | Size: 268 B After Width: | Height: | Size: 198 B |
@ -38,6 +38,29 @@ THE SOFTWARE.
|
||||
android:layout_width="80dip"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_gravity="center" />
|
||||
<LinearLayout
|
||||
android:id="@+id/state_buttons"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_alignParentRight="true">
|
||||
<ImageButton
|
||||
android:id="@+id/shuffle"
|
||||
android:layout_height="0px"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@null"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/shuffle_inactive" />
|
||||
<ImageButton
|
||||
android:id="@+id/end_action"
|
||||
android:layout_height="0px"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@null"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/repeat_inactive" />
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/status_text"
|
||||
android:text="@string/none"
|
||||
@ -48,15 +71,15 @@ THE SOFTWARE.
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@id/cover"
|
||||
android:layout_alignParentRight="true" />
|
||||
android:layout_toLeftOf="@id/state_buttons" />
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/status_text"
|
||||
android:layout_toRightOf="@id/cover"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentBottom="true">
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_toLeftOf="@id/state_buttons" >
|
||||
<ImageButton
|
||||
android:id="@+id/previous"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -36,6 +36,14 @@ THE SOFTWARE.
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="horizontal">
|
||||
<ImageButton
|
||||
android:id="@+id/shuffle"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0px"
|
||||
android:layout_weight="1"
|
||||
android:background="@null"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/shuffle_inactive" />
|
||||
<ImageButton
|
||||
android:id="@+id/previous"
|
||||
android:layout_height="wrap_content"
|
||||
@ -60,5 +68,13 @@ THE SOFTWARE.
|
||||
android:background="@null"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/next" />
|
||||
<ImageButton
|
||||
android:id="@+id/end_action"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0px"
|
||||
android:layout_weight="1"
|
||||
android:background="@null"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/repeat_inactive" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
@ -30,7 +30,6 @@ import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
@ -71,9 +70,6 @@ public class FullPlaybackActivity extends PlaybackActivity
|
||||
private TextView mAlbum;
|
||||
private TextView mArtist;
|
||||
|
||||
private ImageButton mShuffleButton;
|
||||
private ImageButton mEndButton;
|
||||
|
||||
/**
|
||||
* True if the controls are visible (play, next, seek bar, etc).
|
||||
*/
|
||||
@ -251,37 +247,6 @@ public class FullPlaybackActivity extends PlaybackActivity
|
||||
|
||||
if ((state & PlaybackService.FLAG_PLAYING) != 0)
|
||||
updateProgress();
|
||||
|
||||
if ((toggled & PlaybackService.MASK_FINISH) != 0) {
|
||||
switch (PlaybackService.finishAction(state)) {
|
||||
case SongTimeline.FINISH_STOP:
|
||||
mEndButton.setImageResource(R.drawable.repeat_inactive);
|
||||
break;
|
||||
case SongTimeline.FINISH_REPEAT:
|
||||
mEndButton.setImageResource(R.drawable.repeat_active);
|
||||
break;
|
||||
case SongTimeline.FINISH_REPEAT_CURRENT:
|
||||
mEndButton.setImageResource(R.drawable.repeat_current_active);
|
||||
break;
|
||||
case SongTimeline.FINISH_RANDOM:
|
||||
mEndButton.setImageResource(R.drawable.random_active);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((toggled & PlaybackService.MASK_SHUFFLE) != 0) {
|
||||
switch (PlaybackService.shuffleMode(state)) {
|
||||
case SongTimeline.SHUFFLE_NONE:
|
||||
mShuffleButton.setImageResource(R.drawable.shuffle_inactive);
|
||||
break;
|
||||
case SongTimeline.SHUFFLE_SONGS:
|
||||
mShuffleButton.setImageResource(R.drawable.shuffle_active);
|
||||
break;
|
||||
case SongTimeline.SHUFFLE_ALBUMS:
|
||||
mShuffleButton.setImageResource(R.drawable.shuffle_album_active);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -477,22 +442,10 @@ public class FullPlaybackActivity extends PlaybackActivity
|
||||
{
|
||||
if (view == mOverlayText && (mState & PlaybackService.FLAG_EMPTY_QUEUE) != 0) {
|
||||
setState(PlaybackService.get(this).setFinishAction(SongTimeline.FINISH_RANDOM));
|
||||
return;
|
||||
}
|
||||
|
||||
switch (view.getId()) {
|
||||
case R.id.cover_view:
|
||||
} else if (view == mCoverView) {
|
||||
performAction(mCoverPressAction);
|
||||
break;
|
||||
case R.id.end_action:
|
||||
cycleFinishAction();
|
||||
break;
|
||||
case R.id.shuffle:
|
||||
cycleShuffle();
|
||||
break;
|
||||
default:
|
||||
} else {
|
||||
super.onClick(view);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -506,34 +459,4 @@ public class FullPlaybackActivity extends PlaybackActivity
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final int GROUP_SHUFFLE = 0;
|
||||
private static final int GROUP_FINISH = 1;
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo)
|
||||
{
|
||||
if (view == mShuffleButton) {
|
||||
menu.add(GROUP_SHUFFLE, SongTimeline.SHUFFLE_NONE, 0, R.string.no_shuffle);
|
||||
menu.add(GROUP_SHUFFLE, SongTimeline.SHUFFLE_SONGS, 0, R.string.shuffle_songs);
|
||||
menu.add(GROUP_SHUFFLE, SongTimeline.SHUFFLE_ALBUMS, 0, R.string.shuffle_albums);
|
||||
} else if (view == mEndButton) {
|
||||
menu.add(GROUP_FINISH, SongTimeline.FINISH_STOP, 0, R.string.no_repeat);
|
||||
menu.add(GROUP_FINISH, SongTimeline.FINISH_REPEAT, 0, R.string.repeat);
|
||||
menu.add(GROUP_FINISH, SongTimeline.FINISH_REPEAT_CURRENT, 0, R.string.repeat_current_song);
|
||||
menu.add(GROUP_FINISH, SongTimeline.FINISH_RANDOM, 0, R.string.random);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item)
|
||||
{
|
||||
int group = item.getGroupId();
|
||||
int id = item.getItemId();
|
||||
if (group == GROUP_SHUFFLE)
|
||||
setState(PlaybackService.get(this).setShuffleMode(id));
|
||||
else if (group == GROUP_FINISH)
|
||||
setState(PlaybackService.get(this).setFinishAction(id));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -131,6 +131,13 @@ public class LibraryActivity
|
||||
previous.setOnClickListener(this);
|
||||
mPlayPauseButton.setOnClickListener(this);
|
||||
next.setOnClickListener(this);
|
||||
|
||||
mShuffleButton = (ImageButton)findViewById(R.id.shuffle);
|
||||
mShuffleButton.setOnClickListener(this);
|
||||
registerForContextMenu(mShuffleButton);
|
||||
mEndButton = (ImageButton)findViewById(R.id.end_action);
|
||||
mEndButton.setOnClickListener(this);
|
||||
registerForContextMenu(mEndButton);
|
||||
} else {
|
||||
setContentView(R.layout.library_content);
|
||||
}
|
||||
@ -527,6 +534,11 @@ public class LibraryActivity
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View listView, ContextMenu.ContextMenuInfo absInfo)
|
||||
{
|
||||
if (!(listView instanceof ListView)) {
|
||||
super.onCreateContextMenu(menu, listView, absInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
MediaAdapter adapter = (MediaAdapter)((ListView)listView).getAdapter();
|
||||
MediaView view = (MediaView)((AdapterView.AdapterContextMenuInfo)absInfo).targetView;
|
||||
|
||||
@ -613,6 +625,9 @@ public class LibraryActivity
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item)
|
||||
{
|
||||
if (item.getGroupId() != 0)
|
||||
return super.onContextItemSelected(item);
|
||||
|
||||
Intent intent = item.getIntent();
|
||||
|
||||
switch (item.getItemId()) {
|
||||
|
@ -52,6 +52,13 @@ public class MiniPlaybackActivity extends PlaybackActivity {
|
||||
mPlayPauseButton.setOnClickListener(this);
|
||||
View nextButton = findViewById(R.id.next);
|
||||
nextButton.setOnClickListener(this);
|
||||
|
||||
mShuffleButton = (ImageButton)findViewById(R.id.shuffle);
|
||||
mShuffleButton.setOnClickListener(this);
|
||||
registerForContextMenu(mShuffleButton);
|
||||
mEndButton = (ImageButton)findViewById(R.id.end_action);
|
||||
mEndButton.setOnClickListener(this);
|
||||
registerForContextMenu(mEndButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,6 +32,7 @@ import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.SystemClock;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@ -74,6 +75,8 @@ public class PlaybackActivity extends Activity
|
||||
|
||||
protected CoverView mCoverView;
|
||||
protected ImageButton mPlayPauseButton;
|
||||
protected ImageButton mShuffleButton;
|
||||
protected ImageButton mEndButton;
|
||||
|
||||
protected int mState;
|
||||
private long mLastStateEvent;
|
||||
@ -216,6 +219,12 @@ public class PlaybackActivity extends Activity
|
||||
case R.id.previous:
|
||||
previousSong();
|
||||
break;
|
||||
case R.id.end_action:
|
||||
cycleFinishAction();
|
||||
break;
|
||||
case R.id.shuffle:
|
||||
cycleShuffle();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,6 +238,37 @@ public class PlaybackActivity extends Activity
|
||||
{
|
||||
if ((toggled & PlaybackService.FLAG_PLAYING) != 0 && mPlayPauseButton != null)
|
||||
mPlayPauseButton.setImageResource((state & PlaybackService.FLAG_PLAYING) == 0 ? R.drawable.play : R.drawable.pause);
|
||||
|
||||
if ((toggled & PlaybackService.MASK_FINISH) != 0 && mShuffleButton != null) {
|
||||
switch (PlaybackService.finishAction(state)) {
|
||||
case SongTimeline.FINISH_STOP:
|
||||
mEndButton.setImageResource(R.drawable.repeat_inactive);
|
||||
break;
|
||||
case SongTimeline.FINISH_REPEAT:
|
||||
mEndButton.setImageResource(R.drawable.repeat_active);
|
||||
break;
|
||||
case SongTimeline.FINISH_REPEAT_CURRENT:
|
||||
mEndButton.setImageResource(R.drawable.repeat_current_active);
|
||||
break;
|
||||
case SongTimeline.FINISH_RANDOM:
|
||||
mEndButton.setImageResource(R.drawable.random_active);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((toggled & PlaybackService.MASK_SHUFFLE) != 0 && mEndButton != null) {
|
||||
switch (PlaybackService.shuffleMode(state)) {
|
||||
case SongTimeline.SHUFFLE_NONE:
|
||||
mShuffleButton.setImageResource(R.drawable.shuffle_inactive);
|
||||
break;
|
||||
case SongTimeline.SHUFFLE_SONGS:
|
||||
mShuffleButton.setImageResource(R.drawable.shuffle_active);
|
||||
break;
|
||||
case SongTimeline.SHUFFLE_ALBUMS:
|
||||
mShuffleButton.setImageResource(R.drawable.shuffle_album_active);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void setState(final int state)
|
||||
@ -426,4 +466,34 @@ public class PlaybackActivity extends Activity
|
||||
{
|
||||
performAction(mDownAction);
|
||||
}
|
||||
|
||||
private static final int GROUP_SHUFFLE = 100;
|
||||
private static final int GROUP_FINISH = 101;
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo)
|
||||
{
|
||||
if (view == mShuffleButton) {
|
||||
menu.add(GROUP_SHUFFLE, SongTimeline.SHUFFLE_NONE, 0, R.string.no_shuffle);
|
||||
menu.add(GROUP_SHUFFLE, SongTimeline.SHUFFLE_SONGS, 0, R.string.shuffle_songs);
|
||||
menu.add(GROUP_SHUFFLE, SongTimeline.SHUFFLE_ALBUMS, 0, R.string.shuffle_albums);
|
||||
} else if (view == mEndButton) {
|
||||
menu.add(GROUP_FINISH, SongTimeline.FINISH_STOP, 0, R.string.no_repeat);
|
||||
menu.add(GROUP_FINISH, SongTimeline.FINISH_REPEAT, 0, R.string.repeat);
|
||||
menu.add(GROUP_FINISH, SongTimeline.FINISH_REPEAT_CURRENT, 0, R.string.repeat_current_song);
|
||||
menu.add(GROUP_FINISH, SongTimeline.FINISH_RANDOM, 0, R.string.random);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item)
|
||||
{
|
||||
int group = item.getGroupId();
|
||||
int id = item.getItemId();
|
||||
if (group == GROUP_SHUFFLE)
|
||||
setState(PlaybackService.get(this).setShuffleMode(id));
|
||||
else if (group == GROUP_FINISH)
|
||||
setState(PlaybackService.get(this).setFinishAction(id));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user