Search in sources :

Example 21 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.

the class CreateDirectoryFragment method createDirectory.

private void createDirectory(String name) {
    final BaseActivity activity = (BaseActivity) getActivity();
    final DocumentInfo cwd = activity.getCurrentDirectory();
    new CreateDirectoryTask(activity, cwd, name).executeOnExecutor(ProviderExecutor.forAuthority(cwd.authority));
}
Also used : DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 22 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.

the class CopyJob method byteCopyDocument.

void byteCopyDocument(DocumentInfo src, DocumentInfo dest) throws ResourceException {
    final String dstMimeType;
    final String dstDisplayName;
    if (DEBUG)
        Log.d(TAG, "Doing byte copy of document: " + src);
    // as such format. Also, append an extension for the target mime type (if known).
    if (src.isVirtualDocument()) {
        String[] streamTypes = null;
        try {
            streamTypes = getContentResolver().getStreamTypes(src.derivedUri, "*/*");
        } catch (RuntimeException e) {
            throw new ResourceException("Failed to obtain streamable types for %s due to an exception.", src.derivedUri, e);
        }
        if (streamTypes != null && streamTypes.length > 0) {
            dstMimeType = streamTypes[0];
            final String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(dstMimeType);
            dstDisplayName = src.displayName + (extension != null ? "." + extension : src.displayName);
        } else {
            throw new ResourceException("Cannot copy virtual file %s. No streamable formats " + "available.", src.derivedUri);
        }
    } else {
        dstMimeType = src.mimeType;
        dstDisplayName = src.displayName;
    }
    // Create the target document (either a file or a directory), then copy recursively the
    // contents (bytes or children).
    Uri dstUri = null;
    try {
        dstUri = DocumentsContract.createDocument(getClient(dest), dest.derivedUri, dstMimeType, dstDisplayName);
    } catch (RemoteException | RuntimeException e) {
        throw new ResourceException("Couldn't create destination document " + dstDisplayName + " in directory %s " + "due to an exception.", dest.derivedUri, e);
    }
    if (dstUri == null) {
        // If this is a directory, the entire subdir will not be copied over.
        throw new ResourceException("Couldn't create destination document " + dstDisplayName + " in directory %s.", dest.derivedUri);
    }
    DocumentInfo dstInfo = null;
    try {
        dstInfo = DocumentInfo.fromUri(getContentResolver(), dstUri);
    } catch (FileNotFoundException | RuntimeException e) {
        throw new ResourceException("Could not load DocumentInfo for newly created file %s.", dstUri);
    }
    if (Document.MIME_TYPE_DIR.equals(src.mimeType)) {
        copyDirectoryHelper(src, dstInfo);
    } else {
        copyFileHelper(src, dstInfo, dest, dstMimeType);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) DocumentInfo.getCursorString(com.android.documentsui.model.DocumentInfo.getCursorString) RemoteException(android.os.RemoteException) Uri(android.net.Uri) DocumentsContract.buildDocumentUri(android.provider.DocumentsContract.buildDocumentUri) DocumentsContract.buildChildDocumentsUri(android.provider.DocumentsContract.buildChildDocumentsUri) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 23 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.

the class FileOperationService method handleOperation.

private void handleOperation(Intent intent, int serviceId, String jobId, int operationType) {
    if (DEBUG)
        Log.d(TAG, "onStartCommand: " + jobId + " with serviceId " + serviceId);
    // Track the service supplied id so we can stop the service once we're out of work to do.
    mLastServiceId = serviceId;
    Job job = null;
    synchronized (mRunning) {
        if (mWakeLock == null) {
            mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
        }
        List<DocumentInfo> srcs = intent.getParcelableArrayListExtra(EXTRA_SRC_LIST);
        DocumentInfo srcParent = intent.getParcelableExtra(EXTRA_SRC_PARENT);
        DocumentStack stack = intent.getParcelableExtra(Shared.EXTRA_STACK);
        job = createJob(operationType, jobId, srcs, srcParent, stack);
        if (job == null) {
            return;
        }
        mWakeLock.acquire();
    }
    assert (job != null);
    int delay = intent.getIntExtra(EXTRA_DELAY, DEFAULT_DELAY);
    assert (delay <= MAX_DELAY);
    if (DEBUG)
        Log.d(TAG, "Scheduling job " + job.id + " to run in " + delay + " milliseconds.");
    ScheduledFuture<?> future = executor.schedule(job, delay, TimeUnit.MILLISECONDS);
    mRunning.put(jobId, new JobRecord(job, future));
}
Also used : DocumentStack(com.android.documentsui.model.DocumentStack) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 24 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.

the class DocumentsProviderHelper method assertHasDirectory.

public void assertHasDirectory(Uri parentUri, String name) throws Exception {
    List<DocumentInfo> children = listChildren(parentUri);
    for (DocumentInfo child : children) {
        if (name.equals(child.displayName) && child.isDirectory()) {
            return;
        }
    }
    fail("Could not find name=" + name + " in children " + children);
}
Also used : DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 25 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.

the class DocumentsProviderHelper method listChildren.

public List<DocumentInfo> listChildren(String documentId) throws Exception {
    Uri uri = buildChildDocumentsUri(mAuthority, documentId);
    List<DocumentInfo> children = new ArrayList<>();
    try (Cursor cursor = mClient.query(uri, null, null, null, null, null)) {
        Cursor wrapper = new RootCursorWrapper(mAuthority, "totally-fake", cursor, 100);
        while (wrapper.moveToNext()) {
            children.add(DocumentInfo.fromDirectoryCursor(wrapper));
        }
    }
    return children;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Uri(android.net.Uri) DocumentsContract.buildDocumentUri(android.provider.DocumentsContract.buildDocumentUri) DocumentsContract.buildChildDocumentsUri(android.provider.DocumentsContract.buildChildDocumentsUri) DocumentsContract.buildRootsUri(android.provider.DocumentsContract.buildRootsUri) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Aggregations

DocumentInfo (com.android.documentsui.model.DocumentInfo)150 Uri (android.net.Uri)40 Cursor (android.database.Cursor)30 DocumentInfo.getCursorString (com.android.documentsui.model.DocumentInfo.getCursorString)30 FragmentManager (android.app.FragmentManager)20 Point (android.graphics.Point)20 RootInfo (com.android.documentsui.model.RootInfo)20 ArrayList (java.util.ArrayList)20 Intent (android.content.Intent)15 DocumentsContract.buildChildDocumentsUri (android.provider.DocumentsContract.buildChildDocumentsUri)15 DocumentsContract.buildDocumentUri (android.provider.DocumentsContract.buildDocumentUri)15 ClipData (android.content.ClipData)10 ContentResolver (android.content.ContentResolver)10 DialogInterface (android.content.DialogInterface)10 RemoteException (android.os.RemoteException)10 BaseActivity (com.android.documentsui.BaseActivity)10 DocumentStack (com.android.documentsui.model.DocumentStack)10 Activity (android.app.Activity)5 AlertDialog (android.app.AlertDialog)5 ContentProviderClient (android.content.ContentProviderClient)5