Search in sources :

Example 61 with DocumentInfo

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

the class DirectoryFragment method copySelectionToClipboard.

void copySelectionToClipboard(Selection selected) {
    assert (!selected.isEmpty());
    // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
    List<DocumentInfo> docs = mModel.getDocuments(selected);
    mClipper.clipDocuments(docs);
    Activity activity = getActivity();
    Snackbars.makeSnackbar(activity, activity.getResources().getQuantityString(R.plurals.clipboard_files_clipped, docs.size(), docs.size()), Snackbar.LENGTH_SHORT).show();
}
Also used : BaseActivity(com.android.documentsui.BaseActivity) DocumentsActivity(com.android.documentsui.DocumentsActivity) Activity(android.app.Activity) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 62 with DocumentInfo

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

the class FileOperationServiceTest method createDoc.

private static DocumentInfo createDoc(Uri destination) {
    DocumentInfo destDoc = new DocumentInfo();
    destDoc.derivedUri = destination;
    return destDoc;
}
Also used : DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 63 with DocumentInfo

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

the class AbstractJobTest method createJob.

final T createJob(List<Uri> srcs, Uri srcParent, Uri destination) throws Exception {
    DocumentStack stack = new DocumentStack();
    stack.push(DocumentInfo.fromUri(mResolver, destination));
    List<DocumentInfo> srcDocs = Lists.newArrayList();
    for (Uri src : srcs) {
        srcDocs.add(DocumentInfo.fromUri(mResolver, src));
    }
    return createJob(srcDocs, DocumentInfo.fromUri(mResolver, srcParent), stack);
}
Also used : DocumentStack(com.android.documentsui.model.DocumentStack) Uri(android.net.Uri) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 64 with DocumentInfo

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

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 65 with DocumentInfo

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

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)

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