@Override public boolean onContextItemSelected(MenuItem item) { MPDApplication app = (MPDApplication) getApplication(); AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int songId = (Integer) songlist.get(info.position).get("songid"); switch (item.getItemId()) { case R.id.PLCX_SkipToHere: // skip to selected Song try { app.oMPDAsyncHelper.oMPD.skipToId(songId); } catch (MPDServerException e) { } return true; case R.id.PLCX_playNext: try { // Move song to next in playlist MPDStatus status = app.oMPDAsyncHelper.oMPD.getStatus(); if (info.id < status.getSongPos()) { app.oMPDAsyncHelper.oMPD.getPlaylist().move(songId, status.getSongPos()); } else { app.oMPDAsyncHelper.oMPD.getPlaylist().move(songId, status.getSongPos() + 1); } Tools.notifyUser("Song moved to next in list", this); } catch (MPDServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; case R.id.PLCX_moveFirst: try { // Move song to first in playlist app.oMPDAsyncHelper.oMPD.getPlaylist().move(songId, 0); Tools.notifyUser("Song moved to first in list", this); } catch (MPDServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; case R.id.PLCX_moveLast: try { // Move song to last in playlist MPDStatus status = app.oMPDAsyncHelper.oMPD.getStatus(); app.oMPDAsyncHelper.oMPD.getPlaylist().move(songId, status.getPlaylistLength() - 1); Tools.notifyUser("Song moved to last in list", this); } catch (MPDServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; case R.id.PLCX_removeFromPlaylist: try { app.oMPDAsyncHelper.oMPD.getPlaylist().removeById(songId); Tools.notifyUser(getResources().getString(R.string.deletedSongFromPlaylist), this); } catch (MPDServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; default: return super.onContextItemSelected(item); } }
@Override protected void onCreate(Bundle arg0) { if (!Tools.isHoneycombOrBetter()) { setTheme(android.R.style.Theme_Black_NoTitleBar); } super.onCreate(arg0); setContentView(R.layout.songs_activity); }
@Override protected void add(Item item, String playlist) { try { app.oMPDAsyncHelper.oMPD.addToPlaylist(playlist, (Music) item); Tools.notifyUser(String.format(getResources().getString(irAdded), item), getActivity()); } catch (MPDServerException e) { e.printStackTrace(); } }
@Override protected void add(Item item, String playlist) { try { app.oMPDAsyncHelper.oMPD.addToPlaylist( playlist, app.oMPDAsyncHelper.oMPD.find("genre", item.getName())); Tools.notifyUser(irAdded, item); } catch (MPDServerException e) { e.printStackTrace(); } }
@Override protected void add(final Artist item, final PlaylistFile playlist) { try { mApp.getMPD().addToPlaylist(playlist, item); if (isAdded()) { Tools.notifyUser(mIrAdded, item); } } catch (final IOException | MPDException e) { Log.e(TAG, "Failed to add to playlist.", e); } }
@Override protected void add(final Artist item, final boolean replace, final boolean play) { try { mApp.getMPD().add(item, replace, play); if (isAdded()) { Tools.notifyUser(mIrAdded, item); } } catch (final IOException | MPDException e) { Log.e(TAG, "Failed to add to queue.", e); } }
@Override protected void add(Item item, boolean replace, boolean play) { try { app.oMPDAsyncHelper .oMPD .getPlaylist() .addAll(app.oMPDAsyncHelper.oMPD.find("genre", item.getName())); Tools.notifyUser(irAdded, item); } catch (MPDServerException e) { e.printStackTrace(); } }
@Override protected void Add(String item) { try { MPDApplication app = (MPDApplication) getActivity().getApplication(); Directory ToAdd = currentDirectory.getDirectory(item); if (ToAdd != null) { // Valid directory app.oMPDAsyncHelper.oMPD.getPlaylist().add(ToAdd); Tools.notifyUser( String.format(getResources().getString(R.string.addedDirectoryToPlaylist), item), FSFragment.this.getActivity()); } else { Music music = currentDirectory.getFileByTitle(item); if (music != null) { app.oMPDAsyncHelper.oMPD.getPlaylist().add(music); Tools.notifyUser( getResources().getString(R.string.songAdded, item), FSFragment.this.getActivity()); } } } catch (MPDServerException e) { e.printStackTrace(); } }
@Override protected void add(Item item, boolean replace, boolean play) { Music music = (Music) item; try { app.oMPDAsyncHelper.oMPD.add(music, replace, play); Tools.notifyUser( String.format( getResources().getString(R.string.songAdded, music.getTitle()), music.getName()), getActivity()); } catch (MPDServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { MPDApplication app = (MPDApplication) getApplication(); // Menu actions... switch (item.getItemId()) { case R.id.PLM_MainMenu: Intent i = new Intent(this, MainMenuActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); return true; case R.id.PLM_LibTab: i = new Intent(this, LibraryTabActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); return true; case R.id.PLM_Clear: try { app.oMPDAsyncHelper.oMPD.getPlaylist().clear(); songlist.clear(); Tools.notifyUser(getResources().getString(R.string.playlistCleared), this); ((SimpleAdapter) getListAdapter()).notifyDataSetChanged(); } catch (MPDServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; case R.id.PLM_EditPL: i = new Intent(this, PlaylistRemoveActivity.class); startActivity(i); return true; case R.id.PLM_Manage: i = new Intent(this, PlaylistManagerActivity.class); startActivity(i); return true; case R.id.PLM_Save: i = new Intent(this, PlaylistSaveActivity.class); startActivity(i); return true; case android.R.id.home: finish(); return true; default: return false; } }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.Remove: MPDApplication app = (MPDApplication) getApplicationContext(); int count = 0; try { ArrayList<HashMap<String, Object>> copy = new ArrayList<HashMap<String, Object>>(); copy.addAll(songlist); List<Integer> positions = new LinkedList<Integer>(); for (HashMap<String, Object> item : copy) { if (item.get("marked").equals(true)) { positions.add((Integer) item.get("songid")); songlist.remove(copy.indexOf(item) - count); count++; } } Collections.sort(positions); if (isPlayQueue) { for (count = 0; count < positions.size(); ++count) { app.oMPDAsyncHelper.oMPD.getPlaylist().removeById(positions.get(count)); } } else { for (count = 0; count < positions.size(); ++count) { app.oMPDAsyncHelper.oMPD.removeFromPlaylist( playlistName, positions.get(count) - count); } } if (copy.size() != songlist.size()) { ((SimpleAdapter) getListAdapter()).notifyDataSetChanged(); } Tools.notifyUser( String.format(getResources().getString(R.string.removeCountSongs), count), this); } catch (Exception e) { Log.e("MPDroid", "General: " + e.toString()); update(); } break; default: break; } }
@Override public void onCreate(Bundle icicle) { if (!Tools.isTabletMode(this)) { setTheme(android.R.style.Theme_Black_NoTitleBar); } super.onCreate(icicle); app = (MPDApplication) getApplication(); setContentView(R.layout.playlist_activity); this.setTitle(R.string.nowPlaying); ListView list = getListView(); /* * LinearLayout test = (LinearLayout)list.getChildAt(1); ImageView img = (ImageView)test.findViewById(R.id.picture); //ImageView img * = (ImageView)((LinearLayout)list.getItemAtPosition(3)).findViewById(R.id.picture); * img.setImageDrawable(getResources().getDrawable(R.drawable.gmpcnocover)); */ registerForContextMenu(list); try { Activity activity = this; ActionBar actionBar = activity.getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); } catch (NoClassDefFoundError e) { // Older android } catch (NullPointerException e) { } catch (NoSuchMethodError e) { } final View tmpView = findViewById(R.id.compatActionbar); if (tmpView != null) { // We are on a phone compatActionBar = (com.namelessdev.mpdroid.ActionBar) tmpView; compatActionBar.setTitle(R.string.nowPlaying); compatActionBar.setTextButtonParams(true, R.string.edit, this); compatActionBar.setBackActionEnabled(true); compatActionBar.showBottomSeparator(true); } }
public void drop(int from, int to) { if (from == to) { return; } HashMap<String, Object> itemFrom = songlist.get(from); Integer songID = (Integer) itemFrom.get("songid"); MPDApplication app = (MPDApplication) getApplication(); try { // looks like it's not necessary /* * if (from < to) { app.oMPDAsyncHelper.oMPD.getPlaylist().move(songID, to - 1); } else { */ if (isPlayQueue) { app.oMPDAsyncHelper.oMPD.getPlaylist().move(songID, to); } else { app.oMPDAsyncHelper.oMPD.movePlaylistSong(playlistName, from, to); update(); } // } } catch (MPDServerException e) { } Tools.notifyUser("Updating ...", getApplication()); }