Esempio n. 1
0
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   mEditText.setText(mAdapter.getItem(position).mTitle);
 }
  private boolean handleContextItemSelected(MenuItem item, int position) {
    ContextMenuInfo menuInfo = item.getMenuInfo();

    int startPosition;
    int groupPosition;
    List<String> medias;
    int id = item.getItemId();

    boolean useAllItems = id == R.id.audio_list_browser_play_all;
    boolean append = id == R.id.audio_list_browser_append;

    if (ExpandableListContextMenuInfo.class.isInstance(menuInfo)) {
      ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
      groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);
    } else groupPosition = position;

    if (id == R.id.audio_list_browser_delete) {
      AlertDialog alertDialog =
          CommonDialogs.deleteMedia(
              getActivity(),
              mSongsAdapter.getLocations(groupPosition).get(0),
              new VlcRunnable(mSongsAdapter.getItem(groupPosition)) {
                @Override
                public void run(Object o) {
                  AudioBrowserListAdapter.ListItem listItem = (AudioBrowserListAdapter.ListItem) o;
                  Media media = listItem.mMediaList.get(0);
                  mMediaLibrary.getMediaItems().remove(media);
                  mSongsAdapter.removeMedia(media);
                  mAlbumsAdapter.removeMedia(media);
                  mAudioController.removeLocation(media.getLocation());
                }
              });
      alertDialog.show();
      return true;
    }

    if (id == R.id.audio_list_browser_set_song) {
      AudioUtil.setRingtone(mSongsAdapter.getItem(groupPosition).mMediaList.get(0), getActivity());
      return true;
    }

    if (useAllItems) {
      medias = new ArrayList<String>();
      startPosition = mSongsAdapter.getListWithPosition(medias, groupPosition);
    } else {
      startPosition = 0;
      switch (mTabHost.getCurrentTab()) {
        case 0: // albums
          medias = mAlbumsAdapter.getLocations(groupPosition);
          break;
        case 1: // songs
          medias = mSongsAdapter.getLocations(groupPosition);
          break;
        default:
          return true;
      }
    }

    if (append) mAudioController.append(medias);
    else mAudioController.load(medias, startPosition);

    return super.onContextItemSelected(item);
  }