コード例 #1
0
  public void deleteMedia(int position) {
    final MediaWrapper media = mVideoAdapter.getItem(position);
    final String path = media.getUri().getPath();
    new Thread(
            new Runnable() {
              public void run() {
                Util.recursiveDelete(VLCApplication.getAppContext(), new File(path));
              }
            })
        .start();
    mMediaLibrary.getMediaItems().remove(media);
    mVideoAdapter.remove(media);
    PlaybackServiceClient.getMediaLocations(
        getActivity(),
        new PlaybackServiceClient.ResultCallback<List<String>>() {
          @Override
          public void onResult(PlaybackServiceClient client, List<String> result) {
            if (result != null && result.contains(media.getLocation()))
              client.removeLocation(media.getLocation());
          }

          @Override
          public void onError(PlaybackServiceClient client) {}
        });
  }
コード例 #2
0
 private boolean handleContextItemSelected(MenuItem menu, int position) {
   if (position >= mVideoAdapter.getCount()) return false;
   MediaWrapper media = mVideoAdapter.getItem(position);
   if (media == null) return false;
   switch (menu.getItemId()) {
     case R.id.video_list_play_from_start:
       playVideo(media, true);
       return true;
     case R.id.video_list_play_audio:
       playAudio(media);
       return true;
     case R.id.video_list_info:
       Activity activity = getActivity();
       if (activity instanceof MainActivity)
         ((MainActivity) activity)
             .showSecondaryFragment(SecondaryActivity.MEDIA_INFO, media.getLocation());
       else {
         Intent i = new Intent(activity, SecondaryActivity.class);
         i.putExtra("fragment", "mediaInfo");
         i.putExtra("param", media.getLocation());
         startActivity(i);
       }
       return true;
     case R.id.video_list_delete:
       Snackbar.make(getView(), getString(R.string.file_deleted), Snackbar.LENGTH_LONG)
           .setAction(android.R.string.cancel, mCancelDeleteMediaListener)
           .show();
       Message msg = mDeleteHandler.obtainMessage(DELETE_MEDIA, position, 0);
       mDeleteHandler.sendMessageDelayed(msg, DELETE_DURATION);
       return true;
   }
   return false;
 }
コード例 #3
0
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   MediaWrapper media = mVideoAdapter.getItem(position);
   if (media == null) return;
   if (media instanceof MediaGroup) {
     MainActivity activity = (MainActivity) getActivity();
     activity.showSecondaryFragment(SecondaryActivity.VIDEO_GROUP_LIST, media.getTitle());
   } else playVideo(media, false);
 }
コード例 #4
0
 @Override
 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
   // Do not show the menu of media group.
   AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
   MediaWrapper media = mVideoAdapter.getItem(info.position);
   if (media == null || media instanceof MediaGroup) return;
   MenuInflater inflater = getActivity().getMenuInflater();
   inflater.inflate(R.menu.video_list, menu);
   setContextMenuItems(menu, media);
 }
コード例 #5
0
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  public void onContextPopupMenu(View anchor, final int position) {
    if (!AndroidUtil.isHoneycombOrLater()) {
      // Call the "classic" context menu
      anchor.performLongClick();
      return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.video_list, popupMenu.getMenu());
    MediaWrapper media = mVideoAdapter.getItem(position);
    if (media == null) return;
    setContextMenuItems(popupMenu.getMenu(), media);
    popupMenu.setOnMenuItemClickListener(
        new OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
          }
        });
    popupMenu.show();
  }