use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.
the class AbstractCopyJobTest method runCopyDirRecursivelyTest.
public void runCopyDirRecursivelyTest() throws Exception {
Uri testDir1 = mDocs.createFolder(mSrcRoot, "dir1");
mDocs.createDocument(testDir1, "text/plain", "test1.txt");
Uri testDir2 = mDocs.createFolder(testDir1, "dir2");
mDocs.createDocument(testDir2, "text/plain", "test2.txt");
createJob(newArrayList(testDir1)).run();
mJobListener.waitForFinished();
DocumentInfo dir1Copy = mDocs.findDocument(mDestRoot.documentId, "dir1");
mDocs.assertChildCount(dir1Copy.derivedUri, 2);
mDocs.assertHasDirectory(dir1Copy.derivedUri, "dir2");
mDocs.assertHasFile(dir1Copy.derivedUri, "test1.txt");
DocumentInfo dir2Copy = mDocs.findDocument(dir1Copy.documentId, "dir2");
mDocs.assertChildCount(dir2Copy.derivedUri, 1);
mDocs.assertHasFile(dir2Copy.derivedUri, "test2.txt");
}
use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by DirtyUnicorns.
the class DocumentClipper method getDocumentsFromClipData.
/**
* Returns a list of Documents as decoded in clipData.
* This should be run from inside an AsyncTask.
*/
public List<DocumentInfo> getDocumentsFromClipData(ClipData clipData) {
assert (clipData != null);
final List<DocumentInfo> srcDocs = new ArrayList<>();
int count = clipData.getItemCount();
if (count == 0) {
return srcDocs;
}
ContentResolver resolver = mContext.getContentResolver();
for (int i = 0; i < count; ++i) {
ClipData.Item item = clipData.getItemAt(i);
Uri itemUri = item.getUri();
if (itemUri != null && DocumentsContract.isDocumentUri(mContext, itemUri)) {
ContentProviderClient client = null;
Cursor cursor = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, itemUri.getAuthority());
cursor = client.query(itemUri, null, null, null, null);
cursor.moveToPosition(0);
srcDocs.add(DocumentInfo.fromCursor(cursor, itemUri.getAuthority()));
} catch (Exception e) {
Log.e(TAG, e.getMessage());
} finally {
IoUtils.closeQuietly(cursor);
ContentProviderClient.releaseQuietly(client);
}
}
}
return srcDocs;
}
use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by DirtyUnicorns.
the class DocumentClipper method getClipDataForDocuments.
/**
* Returns ClipData representing the list of docs, or null if docs is empty,
* or docs cannot be converted.
*/
@Nullable
public ClipData getClipDataForDocuments(List<DocumentInfo> docs) {
final ContentResolver resolver = mContext.getContentResolver();
final String[] mimeTypes = getMimeTypes(resolver, docs);
ClipData clipData = null;
for (DocumentInfo doc : docs) {
if (clipData == null) {
// TODO: figure out what this string should be.
// Currently it is not displayed anywhere in the UI, but this might change.
final String label = "";
clipData = new ClipData(label, mimeTypes, new ClipData.Item(doc.derivedUri));
} else {
// TODO: update list of mime types in ClipData.
clipData.addItem(new ClipData.Item(doc.derivedUri));
}
}
return clipData;
}
use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by DirtyUnicorns.
the class DocumentsActivity method refreshDirectory.
@Override
void refreshDirectory(int anim) {
final FragmentManager fm = getFragmentManager();
final RootInfo root = getCurrentRoot();
final DocumentInfo cwd = getCurrentDirectory();
if (cwd == null) {
// No directory means recents
if (mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE || mState.action == ACTION_PICK_COPY_DESTINATION) {
RecentsCreateFragment.show(fm);
} else {
DirectoryFragment.showRecentsOpen(fm, anim);
// In recents we pick layout mode based on the mimetype,
// picking GRID for visual types. We intentionally don't
// consult a user's saved preferences here since they are
// set per root (not per root and per mimetype).
boolean visualMimes = MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, mState.acceptMimes);
mState.derivedMode = visualMimes ? State.MODE_GRID : State.MODE_LIST;
}
} else {
// Normal boring directory
DirectoryFragment.showDirectory(fm, root, cwd, anim);
}
// Forget any replacement target
if (mState.action == ACTION_CREATE) {
final SaveFragment save = SaveFragment.get(fm);
if (save != null) {
save.setReplaceTarget(null);
}
}
if (mState.action == ACTION_OPEN_TREE || mState.action == ACTION_PICK_COPY_DESTINATION) {
final PickFragment pick = PickFragment.get(fm);
if (pick != null) {
pick.setPickTarget(mState.action, mState.copyOperationSubType, cwd);
}
}
}
use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by DirtyUnicorns.
the class BaseActivity method canCreateDirectory.
/**
* Returns true if a directory can be created in the current location.
* @return
*/
boolean canCreateDirectory() {
final RootInfo root = getCurrentRoot();
final DocumentInfo cwd = getCurrentDirectory();
return cwd != null && cwd.isCreateSupported() && !mSearchManager.isSearching() && !root.isRecents() && !root.isDownloads();
}
Aggregations