Example usage for android.support.v4.provider DocumentFile length

List of usage examples for android.support.v4.provider DocumentFile length

Introduction

In this page you can find the example usage for android.support.v4.provider DocumentFile length.

Prototype

public abstract long length();

Source Link

Usage

From source file:com.amaze.filemanager.filesystem.RootHelper.java

public static HybridFileParcelable generateBaseFile(DocumentFile file, boolean showHidden) {
    long size = 0;
    if (!file.isDirectory())
        size = file.length();
    HybridFileParcelable baseFile = new HybridFileParcelable(file.getName(), parseDocumentFilePermission(file),
            file.lastModified(), size, file.isDirectory());
    baseFile.setName(file.getName());/*from   w  w  w .  j a  v  a 2  s  . c o m*/
    baseFile.setMode(OpenMode.OTG);

    return baseFile;
}

From source file:com.amaze.carbonfilemanager.filesystem.RootHelper.java

public static BaseFile generateBaseFile(DocumentFile file, boolean showHidden) {
    long size = 0;
    if (!file.isDirectory())
        size = file.length();
    BaseFile baseFile = new BaseFile(file.getName(), parseDocumentFilePermission(file), file.lastModified(),
            size, file.isDirectory());// w  w w  . j  a  v  a 2  s  . co m
    baseFile.setName(file.getName());
    baseFile.setMode(OpenMode.OTG);

    return baseFile;
}

From source file:com.commonsware.android.documents.consumer.DurablizerService.java

@Override
protected void onHandleIntent(Intent intent) {
    Uri document = intent.getData();/*w w w.  ja  va 2s . co  m*/
    boolean weHaveDurablePermission = obtainDurablePermission(document);

    if (!weHaveDurablePermission) {
        document = makeLocalCopy(document);
    }

    if (weHaveDurablePermission || document != null) {
        Log.d(getClass().getSimpleName(), document.toString());

        DocumentFile docFile = buildDocFileForUri(document);

        Log.d(getClass().getSimpleName(), "Display name: " + docFile.getName());
        Log.d(getClass().getSimpleName(), "Size: " + Long.toString(docFile.length()));

        EventBus.getDefault().post(new ContentReadyEvent(docFile));
    }
}

From source file:com.frostwire.android.LollipopFileSystem.java

@Override
public long length(File file) {
    long r = file.length();
    if (r > 0) {
        return r;
    }//from w  w  w  .  ja  v a2 s  . c  o  m

    DocumentFile f = getDocument(app, file);

    return f != null ? f.length() : 0;
}

From source file:com.maskyn.fileeditorpro.dialogfragment.FileInfoDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    View view = new DialogHelper.Builder(getActivity()).setTitle(R.string.info)
            .setView(R.layout.dialog_fragment_file_info).createSkeletonView();
    //final View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_fragment_file_info, null);

    ListView list = (ListView) view.findViewById(android.R.id.list);

    DocumentFile file = DocumentFile.fromFile(
            new File(AccessStorageApi.getPath(getActivity(), (Uri) getArguments().getParcelable("uri"))));

    if (file == null && Device.hasKitKatApi()) {
        file = DocumentFile.fromSingleUri(getActivity(), (Uri) getArguments().getParcelable("uri"));
    }/*from  ww w  .ja  v a 2  s.  c o  m*/

    // Get the last modification information.
    Long lastModified = file.lastModified();

    // Create a new date object and pass last modified information
    // to the date object.
    Date date = new Date(lastModified);

    String[] lines1 = { getString(R.string.name),
            //getString(R.string.folder),
            getString(R.string.size), getString(R.string.modification_date) };
    String[] lines2 = { file.getName(),
            //file.getParent(),
            FileUtils.byteCountToDisplaySize(file.length()), date.toString() };

    list.setAdapter(new AdapterTwoItem(getActivity(), lines1, lines2));

    return new AlertDialog.Builder(getActivity()).setView(view)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create();
}

From source file:com.osama.cryptofm.tasks.DecryptTask.java

private void decryptDocumentFiles(DocumentFile f) throws Exception {
    Log.d(TAG, "decryptDocumentFiles: Running decryption on document file");
    //first always check if task is canceled
    if (!isCancelled()) {
        if (f.isDirectory()) {
            for (DocumentFile tmpFile : f.listFiles()) {
                decryptDocumentFiles(tmpFile);
            }/*ww  w.  j  a va  2 s  .  co  m*/
        } else {
            File out = new File(rootPath + "/", f.getName().substring(0, f.getName().lastIndexOf('.')));
            // add the file in created files. top remove the files later of user cancels the task
            mCreatedFiles.add(out.getAbsoluteFile());
            publishProgress(f.getName(), "" + ((FileUtils.getReadableSize((f.length())))));

            DocumentFileEncryption.decryptFile(
                    CryptoFM.getContext().getContentResolver().openInputStream(f.getUri()), getSecretKey(),
                    mKeyPass, new BufferedOutputStream(new FileOutputStream(out))

            );

        }
    }
}

From source file:com.osama.cryptofm.tasks.EncryptTask.java

private void encryptDocumentFile(DocumentFile file) throws FileNotFoundException {
    Log.d(TAG, "encryptDocumentFile: encrypting document file");
    if (file.isDirectory()) {
        rootDocumentFile = file;//from  w  w w  .  java2 s  .  c o  m
        for (DocumentFile f : file.listFiles()) {
            encryptDocumentFile(f);
        }
    } else {
        //check if root document is not null
        if (rootDocumentFile == null) {
            String path = mFilePaths.get(0).substring(0, mFilePaths.get(0).lastIndexOf('/'));

            Log.d(TAG, "encryptDocumentFile: Getting the root document: " + path);
            rootDocumentFile = FileDocumentUtils.getDocumentFile(new File(path));
        }
        DocumentFile temp = rootDocumentFile.createFile("pgp", file.getName() + ".pgp");
        mCreatedDocumentFiles.add(temp);
        publishProgress(file.getName(), "" + ((FileUtils.getReadableSize((file.length())))));

        InputStream in = CryptoFM.getContext().getContentResolver().openInputStream(file.getUri());
        OutputStream out = CryptoFM.getContext().getContentResolver().openOutputStream(temp.getUri());
        DocumentFileEncryption.encryptFile(in, out, pubKeyFile, true, new Date(file.lastModified()),
                file.getName());

    }
}

From source file:com.osama.cryptofm.tasks.MoveTask.java

private void moveDocumentFile(DocumentFile file) throws Exception {
    if (file.isDirectory()) {
        Log.d(TAG, "moveDocumentFile: Yes document file is directory");
        //change the destination folder
        mDestinationFolder = mDestinationFolder + file.getName() + "/";
        //check if destination folder is not document file
        if (FileUtils.isDocumentFile(mDestinationFolder)) {
            rootDocumentFile = rootDocumentFile.createDirectory(file.getName());
        } else {//from   w  w w. j a  va 2 s  .c  o m
            File tmp = new File(mDestinationFolder);
            if (!tmp.exists()) {
                tmp.mkdir();
            } else {
                return;
            }
        }
        for (DocumentFile f : file.listFiles()) {
            moveDocumentFile(f);
        }
    } else {
        isNextFile = true;
        publishProgress(file.getName());
        publishProgress("" + 0);
        //check if pasting in internal storage
        if (!FileUtils.isDocumentFile(mDestinationFolder)) {
            Log.d(TAG, "moveDocumentFile: moving document file in internal storage");
            File destinationFile = new File(mDestinationFolder + file.getName());
            innerMove(CryptoFM.getContext().getContentResolver().openInputStream(file.getUri()),
                    new BufferedOutputStream(new FileOutputStream(destinationFile)), file.length());
        } else {
            Log.d(TAG, "moveDocumentFile: Moving document file honey");
            DocumentFile destFile = rootDocumentFile.createFile(file.getType(), file.getName());

            innerMove(CryptoFM.getContext().getContentResolver().openInputStream(file.getUri()),
                    CryptoFM.getContext().getContentResolver().openOutputStream(destFile.getUri()),
                    file.length());
        }
    }

    //delete the input file
    //if copying then don't
    if (SharedData.IS_COPYING_NOT_MOVING) {
        return;
    }
    if (!file.delete()) {
        throw new IOException("cannot move files");
    }
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

/**
 * Appends mp4 audio/video from {@code anotherFileDescriptor} to
 * {@code mainFileDescriptor}.//w w w .jav a  2s .  co  m
 */
public static DocumentFile appendNew(DocumentFile[] inputFiles) {
    try {
        DocumentFile targetFile = inputFiles[0];
        int[] inputFilesFds = new int[inputFiles.length];
        ArrayList<ParcelFileDescriptor> pfdsList = new ArrayList<ParcelFileDescriptor>();

        int i = 0;
        for (DocumentFile f : inputFiles) {
            ParcelFileDescriptor pfd = ApplicationScreen.instance.getContentResolver()
                    .openFileDescriptor(f.getUri(), "rw");
            pfdsList.add(pfd);
            inputFilesFds[i] = pfd.getFd();
            i++;
        }

        if (targetFile.exists() && targetFile.length() > 0) {
            String tmpFileName = targetFile.getName() + ".tmp";
            DocumentFile tmpTargetFile = targetFile.getParentFile().createFile("video/mp4", tmpFileName);
            ParcelFileDescriptor targetFilePfd = ApplicationScreen.instance.getContentResolver()
                    .openFileDescriptor(tmpTargetFile.getUri(), "rw");

            Mp4Editor.appendFds(inputFilesFds, targetFilePfd.getFd());

            targetFilePfd.close();
            for (ParcelFileDescriptor pfd : pfdsList) {
                pfd.close();
            }

            return tmpTargetFile;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}