Rework adapter setup
Moves Toast code into SongSelector and media field code into Song and builds media intents in AbstractAdapter
This commit is contained in:
parent
da087bd3ac
commit
1cc008181e
@ -25,6 +25,7 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
@ -48,15 +49,15 @@ public abstract class AbstractAdapter extends BaseAdapter implements Filterable
|
|||||||
private float mSize;
|
private float mSize;
|
||||||
private int mPadding;
|
private int mPadding;
|
||||||
private int mDrawFlags;
|
private int mDrawFlags;
|
||||||
private int mFieldCount;
|
private int mMediaField;
|
||||||
private OnClickListener mExpanderListener;
|
private OnClickListener mExpanderListener;
|
||||||
|
|
||||||
public AbstractAdapter(Context context, Song[] allObjects, int drawFlags, int numFields)
|
public AbstractAdapter(Context context, Song[] allObjects, int drawFlags, int mediaField)
|
||||||
{
|
{
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mAllObjects = allObjects;
|
mAllObjects = allObjects;
|
||||||
mDrawFlags = drawFlags;
|
mDrawFlags = drawFlags;
|
||||||
mFieldCount = numFields;
|
mMediaField = mediaField;
|
||||||
|
|
||||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||||
mSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, metrics);
|
mSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, metrics);
|
||||||
@ -99,7 +100,7 @@ public abstract class AbstractAdapter extends BaseAdapter implements Filterable
|
|||||||
button.setImageResource(R.drawable.expander_arrow);
|
button.setImageResource(R.drawable.expander_arrow);
|
||||||
button.setId(3);
|
button.setId(3);
|
||||||
button.setLayoutParams(params);
|
button.setLayoutParams(params);
|
||||||
button.setTag(R.id.list, mFieldCount);
|
button.setTag(R.id.list, mMediaField);
|
||||||
button.setTag(R.id.song, get(position));
|
button.setTag(R.id.song, get(position));
|
||||||
button.setOnClickListener(mExpanderListener);
|
button.setOnClickListener(mExpanderListener);
|
||||||
|
|
||||||
@ -187,9 +188,9 @@ public abstract class AbstractAdapter extends BaseAdapter implements Filterable
|
|||||||
for (int j = matchers.length; --j != -1; ) {
|
for (int j = matchers.length; --j != -1; ) {
|
||||||
if (matchers[j].reset(song.artist).find())
|
if (matchers[j].reset(song.artist).find())
|
||||||
continue;
|
continue;
|
||||||
if (mFieldCount > 1 && matchers[j].reset(song.album).find())
|
if (mMediaField > 1 && matchers[j].reset(song.album).find())
|
||||||
continue;
|
continue;
|
||||||
if (mFieldCount > 2 && matchers[j].reset(song.title).find())
|
if (mMediaField > 2 && matchers[j].reset(song.title).find())
|
||||||
continue;
|
continue;
|
||||||
continue outer;
|
continue outer;
|
||||||
}
|
}
|
||||||
@ -244,4 +245,26 @@ public abstract class AbstractAdapter extends BaseAdapter implements Filterable
|
|||||||
{
|
{
|
||||||
return get(i);
|
return get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getItemId(int i)
|
||||||
|
{
|
||||||
|
Song song = get(i);
|
||||||
|
if (song == null)
|
||||||
|
return 0;
|
||||||
|
return song.getFieldId(mMediaField);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Intent buildSongIntent(int action, int pos)
|
||||||
|
{
|
||||||
|
Song song = get(pos);
|
||||||
|
if (song == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Intent intent = new Intent(mContext, PlaybackService.class);
|
||||||
|
intent.putExtra("type", mMediaField);
|
||||||
|
intent.putExtra("action", action);
|
||||||
|
intent.putExtra("id", song.getFieldId(mMediaField));
|
||||||
|
intent.putExtra("title", song.getField(mMediaField));
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ import android.widget.TextView;
|
|||||||
public class AlbumAdapter extends AbstractAdapter {
|
public class AlbumAdapter extends AbstractAdapter {
|
||||||
public AlbumAdapter(Context context, Song[] allSongs)
|
public AlbumAdapter(Context context, Song[] allSongs)
|
||||||
{
|
{
|
||||||
super(context, Song.filter(allSongs, new Song.AlbumComparator()), 0, 2);
|
super(context, Song.filter(allSongs, new Song.AlbumComparator()), 0, Song.FIELD_ALBUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -16,12 +16,4 @@ public class AlbumAdapter extends AbstractAdapter {
|
|||||||
upper.setText(song.album);
|
upper.setText(song.album);
|
||||||
lower.setText(song.artist);
|
lower.setText(song.artist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getItemId(int i)
|
|
||||||
{
|
|
||||||
Song song = get(i);
|
|
||||||
if (song == null)
|
|
||||||
return 0;
|
|
||||||
return song.albumId;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ import android.widget.TextView;
|
|||||||
public class ArtistAdapter extends AbstractAdapter {
|
public class ArtistAdapter extends AbstractAdapter {
|
||||||
public ArtistAdapter(Context context, Song[] allSongs)
|
public ArtistAdapter(Context context, Song[] allSongs)
|
||||||
{
|
{
|
||||||
super(context, Song.filter(allSongs, new Song.ArtistComparator()), ONE_LINE, 1);
|
super(context, Song.filter(allSongs, new Song.ArtistComparator()), ONE_LINE, Song.FIELD_ARTIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -33,12 +33,4 @@ public class ArtistAdapter extends AbstractAdapter {
|
|||||||
Song song = get(position);
|
Song song = get(position);
|
||||||
upper.setText(song.artist);
|
upper.setText(song.artist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getItemId(int i)
|
|
||||||
{
|
|
||||||
Song song = get(i);
|
|
||||||
if (song == null)
|
|
||||||
return 0;
|
|
||||||
return song.artistId;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -49,12 +49,10 @@ import android.os.Looper;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.provider.MediaStore;
|
|
||||||
import android.telephony.PhoneStateListener;
|
import android.telephony.PhoneStateListener;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
public class PlaybackService extends Service implements Runnable, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
public class PlaybackService extends Service implements Runnable, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
private static final int NOTIFICATION_ID = 2;
|
private static final int NOTIFICATION_ID = 2;
|
||||||
@ -70,10 +68,6 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
|||||||
public static final int ACTION_PLAY = 0;
|
public static final int ACTION_PLAY = 0;
|
||||||
public static final int ACTION_ENQUEUE = 1;
|
public static final int ACTION_ENQUEUE = 1;
|
||||||
|
|
||||||
public static final int TYPE_SONG = 0;
|
|
||||||
public static final int TYPE_ALBUM = 1;
|
|
||||||
public static final int TYPE_ARTIST = 2;
|
|
||||||
|
|
||||||
public static final int STATE_NORMAL = 0;
|
public static final int STATE_NORMAL = 0;
|
||||||
public static final int STATE_NO_MEDIA = 1;
|
public static final int STATE_NO_MEDIA = 1;
|
||||||
public static final int STATE_PLAYING = 2;
|
public static final int STATE_PLAYING = 2;
|
||||||
@ -722,22 +716,10 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
|||||||
if (id == -1) {
|
if (id == -1) {
|
||||||
mQueuePos = 0;
|
mQueuePos = 0;
|
||||||
} else {
|
} else {
|
||||||
int type = intent.getIntExtra("type", TYPE_SONG);
|
|
||||||
boolean enqueue = intent.getIntExtra("action", ACTION_PLAY) == ACTION_ENQUEUE;
|
boolean enqueue = intent.getIntExtra("action", ACTION_PLAY) == ACTION_ENQUEUE;
|
||||||
|
|
||||||
int[] songs;
|
int[] songs = Song.getAllSongIdsWith(intent.getIntExtra("type", Song.FIELD_TITLE), id);
|
||||||
Song first;
|
if (songs == null || songs.length == 0)
|
||||||
|
|
||||||
if (type == TYPE_SONG)
|
|
||||||
songs = new int[] { id };
|
|
||||||
else if (type == TYPE_ALBUM)
|
|
||||||
songs = Song.getAllSongIds(MediaStore.Audio.Media.ALBUM_ID + "=" + id);
|
|
||||||
else if (type == TYPE_ARTIST)
|
|
||||||
songs = Song.getAllSongIds(MediaStore.Audio.Media.ARTIST_ID + "=" + id);
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (songs.length == 0)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
for (int i = songs.length; --i != 0; ) {
|
for (int i = songs.length; --i != 0; ) {
|
||||||
@ -759,8 +741,6 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
|||||||
mSongTimeline.add(song);
|
mSongTimeline.add(song);
|
||||||
}
|
}
|
||||||
|
|
||||||
first = mSongTimeline.get(mCurrentSong + mQueuePos + 1);
|
|
||||||
|
|
||||||
mQueuePos += songs.length;
|
mQueuePos += songs.length;
|
||||||
} else {
|
} else {
|
||||||
List<Song> view = mSongTimeline.subList(mCurrentSong + 1, mSongTimeline.size());
|
List<Song> view = mSongTimeline.subList(mCurrentSong + 1, mSongTimeline.size());
|
||||||
@ -774,30 +754,9 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
|||||||
mSongTimeline.addAll(queue);
|
mSongTimeline.addAll(queue);
|
||||||
|
|
||||||
mQueuePos += songs.length - 1;
|
mQueuePos += songs.length - 1;
|
||||||
|
|
||||||
first = mSongTimeline.get(mCurrentSong + 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
first.populate();
|
|
||||||
String title;
|
|
||||||
switch (type) {
|
|
||||||
case TYPE_ARTIST:
|
|
||||||
title = first.artist;
|
|
||||||
break;
|
|
||||||
case TYPE_SONG:
|
|
||||||
title = first.title;
|
|
||||||
break;
|
|
||||||
case TYPE_ALBUM:
|
|
||||||
title = first.album;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
title = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String text = getResources().getString(enqueue ? R.string.enqueued : R.string.playing, title);
|
|
||||||
Toast.makeText(PlaybackService.this, text, Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
if (!enqueue)
|
if (!enqueue)
|
||||||
mHandler.sendEmptyMessage(TRACK_CHANGED);
|
mHandler.sendEmptyMessage(TRACK_CHANGED);
|
||||||
|
|
||||||
|
@ -30,6 +30,10 @@ import android.provider.MediaStore;
|
|||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
public class Song implements Parcelable {
|
public class Song implements Parcelable {
|
||||||
|
public static final int FIELD_ARTIST = 1;
|
||||||
|
public static final int FIELD_ALBUM = 2;
|
||||||
|
public static final int FIELD_TITLE = 3;
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
int albumId;
|
int albumId;
|
||||||
int artistId;
|
int artistId;
|
||||||
@ -132,6 +136,17 @@ public class Song implements Parcelable {
|
|||||||
return songs;
|
return songs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int[] getAllSongIdsWith(int type, int id)
|
||||||
|
{
|
||||||
|
if (type == FIELD_TITLE)
|
||||||
|
return new int[] { id };
|
||||||
|
else if (type == FIELD_ALBUM)
|
||||||
|
return Song.getAllSongIds(MediaStore.Audio.Media.ALBUM_ID + "=" + id);
|
||||||
|
else if (type == FIELD_ARTIST)
|
||||||
|
return Song.getAllSongIds(MediaStore.Audio.Media.ARTIST_ID + "=" + id);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static Song[] getAllSongMetadata()
|
public static Song[] getAllSongMetadata()
|
||||||
{
|
{
|
||||||
Uri media = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
Uri media = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
||||||
@ -164,6 +179,32 @@ public class Song implements Parcelable {
|
|||||||
return songs;
|
return songs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getField(int field)
|
||||||
|
{
|
||||||
|
switch (field) {
|
||||||
|
case FIELD_TITLE:
|
||||||
|
return title;
|
||||||
|
case FIELD_ARTIST:
|
||||||
|
return artist;
|
||||||
|
case FIELD_ALBUM:
|
||||||
|
return album;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFieldId(int field)
|
||||||
|
{
|
||||||
|
switch (field) {
|
||||||
|
case FIELD_TITLE:
|
||||||
|
return id;
|
||||||
|
case FIELD_ARTIST:
|
||||||
|
return artistId;
|
||||||
|
case FIELD_ALBUM:
|
||||||
|
return albumId;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean equals(Song other)
|
public boolean equals(Song other)
|
||||||
{
|
{
|
||||||
if (other == null)
|
if (other == null)
|
||||||
|
@ -32,7 +32,7 @@ public class SongAdapter extends AbstractAdapter {
|
|||||||
|
|
||||||
public SongAdapter(Context context, Song[] allSongs)
|
public SongAdapter(Context context, Song[] allSongs)
|
||||||
{
|
{
|
||||||
super(ContextApplication.getContext(), sort(allSongs), 0, 3);
|
super(ContextApplication.getContext(), sort(allSongs), 0, Song.FIELD_TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -42,12 +42,4 @@ public class SongAdapter extends AbstractAdapter {
|
|||||||
upper.setText(song.title);
|
upper.setText(song.title);
|
||||||
lower.setText(song.artist);
|
lower.setText(song.artist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getItemId(int i)
|
|
||||||
{
|
|
||||||
Song song = get(i);
|
|
||||||
if (song == null)
|
|
||||||
return 0;
|
|
||||||
return song.id;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -41,31 +41,19 @@ import android.widget.BaseAdapter;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TabHost;
|
import android.widget.TabHost;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class SongSelector extends TabActivity implements AdapterView.OnItemClickListener, TextWatcher, View.OnClickListener {
|
public class SongSelector extends TabActivity implements AdapterView.OnItemClickListener, TextWatcher, View.OnClickListener {
|
||||||
private TabHost mTabHost;
|
private TabHost mTabHost;
|
||||||
private TextView mTextFilter;
|
private TextView mTextFilter;
|
||||||
private AbstractAdapter[] mAdapters = new AbstractAdapter[3];
|
private AbstractAdapter[] mAdapters = new AbstractAdapter[3];
|
||||||
|
|
||||||
private ListView mArtistView;
|
private void initializeListView(int id, BaseAdapter adapter)
|
||||||
private ListView mAlbumView;
|
|
||||||
|
|
||||||
private int listToMediaType(Object list)
|
|
||||||
{
|
|
||||||
if (list == mArtistView)
|
|
||||||
return PlaybackService.TYPE_ARTIST;
|
|
||||||
if (list == mAlbumView)
|
|
||||||
return PlaybackService.TYPE_ALBUM;
|
|
||||||
return PlaybackService.TYPE_SONG;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ListView initializeListView(int id, BaseAdapter adapter)
|
|
||||||
{
|
{
|
||||||
ListView view = (ListView)findViewById(id);
|
ListView view = (ListView)findViewById(id);
|
||||||
view.setOnItemClickListener(this);
|
view.setOnItemClickListener(this);
|
||||||
view.setOnCreateContextMenuListener(this);
|
view.setOnCreateContextMenuListener(this);
|
||||||
view.setAdapter(adapter);
|
view.setAdapter(adapter);
|
||||||
return view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -88,7 +76,7 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
|||||||
mAdapters[0] = new ArtistAdapter(this, songs);
|
mAdapters[0] = new ArtistAdapter(this, songs);
|
||||||
mAdapters[0].setExpanderListener(this);
|
mAdapters[0].setExpanderListener(this);
|
||||||
|
|
||||||
mArtistView = initializeListView(R.id.artist_list, mAdapters[0]);
|
initializeListView(R.id.artist_list, mAdapters[0]);
|
||||||
|
|
||||||
mTextFilter = (TextView)findViewById(R.id.filter_text);
|
mTextFilter = (TextView)findViewById(R.id.filter_text);
|
||||||
mTextFilter.addTextChangedListener(this);
|
mTextFilter.addTextChangedListener(this);
|
||||||
@ -111,7 +99,7 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
|||||||
{
|
{
|
||||||
mAdapters[1] = new AlbumAdapter(SongSelector.this, songs);
|
mAdapters[1] = new AlbumAdapter(SongSelector.this, songs);
|
||||||
mAdapters[1].setExpanderListener(SongSelector.this);
|
mAdapters[1].setExpanderListener(SongSelector.this);
|
||||||
mAlbumView = initializeListView(R.id.album_list, mAdapters[1]);
|
initializeListView(R.id.album_list, mAdapters[1]);
|
||||||
|
|
||||||
mAdapters[2] = new SongAdapter(SongSelector.this, songs);
|
mAdapters[2] = new SongAdapter(SongSelector.this, songs);
|
||||||
initializeListView(R.id.song_list, mAdapters[2]);
|
initializeListView(R.id.song_list, mAdapters[2]);
|
||||||
@ -129,23 +117,25 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
|||||||
return mTextFilter.onKeyDown(keyCode, event);
|
return mTextFilter.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Intent buildSongIntent(int action, int type, int id)
|
private void sendSongIntent(Intent intent)
|
||||||
{
|
{
|
||||||
Intent intent = new Intent(this, PlaybackService.class);
|
int action = intent.getIntExtra("action", PlaybackService.ACTION_PLAY) == PlaybackService.ACTION_PLAY ? R.string.playing : R.string.enqueued;
|
||||||
intent.putExtra("type", type);
|
String title = intent.getStringExtra("title");
|
||||||
intent.putExtra("action", action);
|
String text = getResources().getString(action, title);
|
||||||
intent.putExtra("id", id);
|
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
|
||||||
return intent;
|
|
||||||
|
intent.removeExtra("title");
|
||||||
|
startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onItemClick(AdapterView<?> list, View view, int pos, long id)
|
public void onItemClick(AdapterView<?> list, View view, int pos, long id)
|
||||||
{
|
{
|
||||||
if (mHandler.hasMessages(MSG_ITEM_CLICK, view)) {
|
if (mHandler.hasMessages(MSG_ITEM_CLICK, list)) {
|
||||||
mHandler.removeMessages(MSG_ITEM_CLICK, view);
|
mHandler.removeMessages(MSG_ITEM_CLICK, list);
|
||||||
startService(buildSongIntent(PlaybackService.ACTION_ENQUEUE, listToMediaType(list), (int)id));
|
sendSongIntent(((AbstractAdapter)list.getAdapter()).buildSongIntent(PlaybackService.ACTION_ENQUEUE, pos));
|
||||||
} else {
|
} else {
|
||||||
Message message = mHandler.obtainMessage(MSG_ITEM_CLICK, view);
|
Message message = mHandler.obtainMessage(MSG_ITEM_CLICK, list);
|
||||||
message.arg1 = (int)id;
|
message.arg1 = pos;
|
||||||
mHandler.sendMessageDelayed(message, 333);
|
mHandler.sendMessageDelayed(message, 333);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,9 +174,8 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
|||||||
{
|
{
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
case MSG_ITEM_CLICK:
|
case MSG_ITEM_CLICK:
|
||||||
int type = listToMediaType(((View)message.obj).getParent());
|
AbstractAdapter adapter = (AbstractAdapter)((ListView)message.obj).getAdapter();
|
||||||
int id = message.arg1;
|
sendSongIntent(adapter.buildSongIntent(PlaybackService.ACTION_PLAY, message.arg1));
|
||||||
startService(buildSongIntent(PlaybackService.ACTION_PLAY, type, id));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -198,16 +187,16 @@ public class SongSelector extends TabActivity implements AdapterView.OnItemClick
|
|||||||
@Override
|
@Override
|
||||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo info)
|
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo info)
|
||||||
{
|
{
|
||||||
int type = listToMediaType(view);
|
AbstractAdapter adapter = (AbstractAdapter)((ListView)view).getAdapter();
|
||||||
int id = (int)((AdapterView.AdapterContextMenuInfo)info).id;
|
int pos = (int)((AdapterView.AdapterContextMenuInfo)info).position;
|
||||||
menu.add(0, MENU_PLAY, 0, R.string.play).setIntent(buildSongIntent(PlaybackService.ACTION_PLAY, type, id));
|
menu.add(0, MENU_PLAY, 0, R.string.play).setIntent(adapter.buildSongIntent(PlaybackService.ACTION_PLAY, pos));
|
||||||
menu.add(0, MENU_ENQUEUE, 0, R.string.enqueue).setIntent(buildSongIntent(PlaybackService.ACTION_ENQUEUE, type, id));
|
menu.add(0, MENU_ENQUEUE, 0, R.string.enqueue).setIntent(adapter.buildSongIntent(PlaybackService.ACTION_ENQUEUE, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item)
|
public boolean onContextItemSelected(MenuItem item)
|
||||||
{
|
{
|
||||||
startService(item.getIntent());
|
sendSongIntent(item.getIntent());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user