Commit a58fd0fc authored by Sébastien Toque's avatar Sébastien Toque
Browse files

add a contextmenu in audio browser: play, append, play all, append all

parent 23033f7b
......@@ -18,7 +18,10 @@
<string name="search_found_results">%1$d résultats trouvés</string>
<string name="show_player">Afficher Lecteur</string>
<string name="hide_mini_player">Cacher Mini-lecteur</string>
<string name="play">Lecture</string>
<string name="play">Lire</string>
<string name="append">Lire à la suite</string>
<string name="play_all">Lire tout</string>
<string name="append_all">Lire tout à la suite</string>
<string name="pause">Pause</string>
<string name="close">Fermer</string>
<string name="not_show_again">Ne plus afficher ce message.</string>
......
......@@ -20,6 +20,9 @@
<string name="show_player">Show Player</string>
<string name="hide_mini_player">Hide Mini-Player</string>
<string name="play">Play</string>
<string name="append">Append</string>
<string name="play_all">Play all</string>
<string name="append_all">Append all</string>
<string name="pause">Pause</string>
<string name="close">Close</string>
<string name="not_show_again">"Don't show this Message again."</string>
......
......@@ -33,8 +33,14 @@ import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
......@@ -59,6 +65,14 @@ public class AudioBrowserActivity extends Activity {
public final static int SORT_BY_LENGTH = 1;
private boolean mSortReverse = false;
private int mSortBy = SORT_BY_TITLE;
public final static int MODE_SONG = 0;
public final static int MODE_ARTIST = 1;
public final static int MODE_ALBUM = 2;
public final static int MODE_GENRE = 3;
public final static int MENU_PLAY = Menu.FIRST;
public final static int MENU_APPEND = Menu.FIRST + 1;
public final static int MENU_PLAY_ALL = Menu.FIRST + 2;
public final static int MENU_APPEND_ALL = Menu.FIRST + 3;
private static AudioBrowserActivity mInstance;
......@@ -93,6 +107,10 @@ public class AudioBrowserActivity extends Activity {
artistList.setOnItemClickListener(playlistListener);
albumList.setOnItemClickListener(playlistListener);
genreList.setOnItemClickListener(playlistListener);
songsList.setOnCreateContextMenuListener(contextMenuListener);
artistList.setOnCreateContextMenuListener(contextMenuListener);
albumList.setOnCreateContextMenuListener(contextMenuListener);
genreList.setOnCreateContextMenuListener(contextMenuListener);
updateLists();
}
......@@ -124,6 +142,63 @@ public class AudioBrowserActivity extends Activity {
}
};
OnCreateContextMenuListener contextMenuListener = new OnCreateContextMenuListener()
{
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
menu.add(Menu.NONE, MENU_PLAY, Menu.NONE, R.string.play);
menu.add(Menu.NONE, MENU_APPEND, Menu.NONE, R.string.append);
if (v.getId() == R.id.songs_list) {
menu.add(Menu.NONE, MENU_PLAY_ALL, Menu.NONE, R.string.play_all);
menu.add(Menu.NONE, MENU_APPEND_ALL, Menu.NONE, R.string.append_all);
}
}
};
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
int id = item.getItemId();
boolean play_all = id == MENU_PLAY_ALL || id == MENU_APPEND_ALL;
boolean play_append = id == MENU_APPEND || id == MENU_APPEND_ALL;
int start_position;
List<String> medias;
if (play_all) {
start_position = menuInfo.position;
medias = mSongsAdapter.getPaths();
}
else {
start_position = 0;
switch (mFlingViewGroup.getPosition())
{
case MODE_SONG:
medias = mSongsAdapter.getPath(menuInfo.position);
break;
case MODE_ARTIST:
medias = mArtistsAdapter.getPlaylist(menuInfo.position);
break;
case MODE_ALBUM:
medias = mAlbumsAdapter.getPlaylist(menuInfo.position);
break;
case MODE_GENRE:
medias = mGenresAdapter.getPlaylist(menuInfo.position);
break;
default:
return true;
}
}
if (play_append)
mAudioController.append(medias);
else
mAudioController.load(medias, start_position);
Intent intent = new Intent(AudioBrowserActivity.this, AudioPlayerActivity.class);
startActivity(intent);
return super.onContextItemSelected(item);
}
@Override
protected void onDestroy() {
mMediaLibrary.removeUpdateHandler(mHandler);
......
......@@ -29,7 +29,13 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
import android.widget.TextView;
......@@ -64,6 +70,7 @@ public class AudioListActivity extends ListActivity {
mSongsAdapter = new AudioSongsListAdapter(this, R.layout.audio_browser_item);
setListAdapter(mSongsAdapter);
getListView().setOnCreateContextMenuListener(contextMenuListener);
updateList();
}
......@@ -75,13 +82,51 @@ public class AudioListActivity extends ListActivity {
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
mAudioController.load(mSongsAdapter.getPaths(), position);
Intent intent = new Intent(AudioListActivity.this, AudioPlayerActivity.class);
startActivity(intent);
super.onListItemClick(l, v, position, id);
}
OnCreateContextMenuListener contextMenuListener = new OnCreateContextMenuListener()
{
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
menu.add(Menu.NONE, AudioBrowserActivity.MENU_PLAY, Menu.NONE, R.string.play);
menu.add(Menu.NONE, AudioBrowserActivity.MENU_APPEND, Menu.NONE, R.string.append);
menu.add(Menu.NONE, AudioBrowserActivity.MENU_PLAY_ALL, Menu.NONE, R.string.play_all);
menu.add(Menu.NONE, AudioBrowserActivity.MENU_APPEND_ALL, Menu.NONE, R.string.append_all);
}
};
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
int id = item.getItemId();
boolean play_all = id == AudioBrowserActivity.MENU_PLAY_ALL || id == AudioBrowserActivity.MENU_APPEND_ALL;
boolean play_append = id == AudioBrowserActivity.MENU_APPEND || id == AudioBrowserActivity.MENU_APPEND_ALL;
int start_position;
List<String> medias;
if (play_all) {
start_position = menuInfo.position;
medias = mSongsAdapter.getPaths();
}
else {
start_position = 0;
medias = mSongsAdapter.getPath(menuInfo.position);
}
if (play_append)
mAudioController.append(medias);
else
mAudioController.load(medias, start_position);
Intent intent = new Intent(AudioListActivity.this, AudioPlayerActivity.class);
startActivity(intent);
return super.onContextItemSelected(item);
}
@Override
protected void onDestroy() {
mMediaLibrary.removeUpdateHandler(mHandler);
......
......@@ -71,6 +71,13 @@ public class AudioSongsListAdapter extends ArrayAdapter<Media> {
return v;
}
public List<String> getPath(int position) {
List<String> paths = new ArrayList<String>();
if (position >= 0 && position < mMediaList.size())
paths.add(mMediaList.get(position).getPath());
return paths;
}
public List<String> getPaths() {
List<String> paths = new ArrayList<String>();
for (int i = 0; i < mMediaList.size(); i++) {
......
......@@ -38,9 +38,6 @@ public class MediaLibrary {
public final static String TAG = "VLC/MediaLibrary";
protected static final int MEDIA_ITEMS_UPDATED = 100;
public final static int MODE_ARTIST = 1;
public final static int MODE_ALBUM = 2;
public final static int MODE_GENRE = 3;
private static MediaLibrary mInstance;
private DatabaseManager mDBManager;
......@@ -108,13 +105,13 @@ public class MediaLibrary {
boolean valid = false;
switch (mode) {
case MODE_ARTIST:
case AudioBrowserActivity.MODE_ARTIST:
valid = name.equals(item.getArtist());
break;
case MODE_ALBUM:
case AudioBrowserActivity.MODE_ALBUM:
valid = name.equals(item.getAlbum());
break;
case MODE_GENRE:
case AudioBrowserActivity.MODE_GENRE:
valid = name.equals(item.getGenre());
break;
default:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment