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();
}
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;
}
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);
}
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);
}
}
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));
}
Aggregations