Ejemplo n.º 1
0
 public static boolean canWrite(String path) {
   if (path == null) return false;
   if (path.startsWith("file://")) path = path.substring(7);
   if (!path.startsWith("/")) return false;
   if (path.startsWith(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)) return true;
   if (AndroidUtil.isLolliPopOrLater()) return false;
   File file = new File(path);
   return (file.exists() && file.canWrite());
 }
Ejemplo n.º 2
0
  private void setContextMenuItems(Menu menu, MediaWrapper mediaWrapper) {
    long lastTime = mediaWrapper.getTime();
    if (lastTime > 0) menu.findItem(R.id.video_list_play_from_start).setVisible(true);

    boolean hasInfo = false;
    final Media media = new Media(VLCInstance.get(), mediaWrapper.getUri());
    media.parse();
    media.release();
    if (media.getMeta(Media.Meta.Title) != null) hasInfo = true;
    menu.findItem(R.id.video_list_info).setVisible(hasInfo);
    menu.findItem(R.id.video_list_delete)
        .setVisible(
            !AndroidUtil.isLolliPopOrLater()
                || mediaWrapper
                    .getLocation()
                    .startsWith("file://" + AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY));
  }
Ejemplo n.º 3
0
 @TargetApi(Build.VERSION_CODES.HONEYCOMB)
 public static boolean deleteFile(String path) {
   boolean deleted = false;
   path = Uri.decode(Strings.removeFileProtocole(path));
   // Delete from Android Medialib, for consistency with device MTP storing and other apps listing
   // content:// media
   if (AndroidUtil.isHoneycombOrLater()) {
     ContentResolver cr = VLCApplication.getAppContext().getContentResolver();
     String[] selectionArgs = {path};
     deleted =
         cr.delete(
                 MediaStore.Files.getContentUri("external"),
                 MediaStore.Files.FileColumns.DATA + "=?",
                 selectionArgs)
             > 0;
   }
   File file = new File(path);
   if (file.exists()) deleted |= file.delete();
   return deleted;
 }
Ejemplo n.º 4
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();
  }
Ejemplo n.º 5
0
 @TargetApi(android.os.Build.VERSION_CODES.GINGERBREAD)
 public static void commitPreferences(SharedPreferences.Editor editor) {
   if (AndroidUtil.isGingerbreadOrLater()) editor.apply();
   else editor.commit();
 }