Esempio n. 1
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   AdapterView.AdapterContextMenuInfo info =
       (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
   Playlist playlist = adapter.getItem(info.position);
   int menuItemIndex = item.getItemId();
   switch (menuItemIndex) {
     case 0:
       Intent intent = new Intent(this, EditPlaylistScreen.class);
       intent.putExtra(DatabaseHelper.FIELD_ID, playlist.getId());
       startActivityForResult(intent, EDIT_PLAYLIST_REQUEST_CODE);
       break;
     case 1:
       if (playlist.isSelected() && playlists.size() > 1) {
         Toast.makeText(this, R.string.playlist_is_selected, Toast.LENGTH_SHORT).show();
       } else {
         dbManager.deletePlaylist(playlist);
         playlists = dbManager.getPlaylists();
         adapter.setPlaylists(playlists);
         adapter.notifyDataSetChanged();
         if (playlists == null || playlists.isEmpty()) {
           preferences.putString(Preferences.KEY_PLAYLIST, Preferences.DEFAULT_PLAYLIST);
           setResult(RESULT_OK);
           finish();
         }
       }
       break;
   }
   return true;
 }
Esempio n. 2
0
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   Playlist playlist = adapter.getItem(position);
   dbManager.setSelectedPlaylist(playlist);
   preferences.putString(Preferences.KEY_PLAYLIST, playlist.getName());
   setResult(RESULT_OK);
   finish();
 }
Esempio n. 3
0
 @Override
 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
   if (v.getId() == R.id.list) {
     AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
     Playlist playlist = adapter.getItem(info.position);
     menu.setHeaderTitle(playlist.getName());
     String[] menuItems = {getString(R.string.edit), getString(R.string.delete)};
     for (int i = 0; i < menuItems.length; i++) {
       menu.add(Menu.NONE, i, i, menuItems[i]);
     }
   }
 }