use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.
the class DirectoryFragment method deleteDocuments.
private void deleteDocuments(final Selection selected) {
Metrics.logUserAction(getContext(), Metrics.USER_ACTION_DELETE);
if (selected.isEmpty()) {
return;
}
final DocumentInfo srcParent = getDisplayState().stack.peek();
// Model must be accessed in UI thread, since underlying cursor is not threadsafe.
List<DocumentInfo> docs = mModel.getDocuments(selected);
TextView message = (TextView) mInflater.inflate(R.layout.dialog_delete_confirmation, null);
message.setText(generateDeleteMessage(docs));
// This "insta-hides" files that are being deleted, because
// the delete operation may be not execute immediately (it
// may be queued up on the FileOperationService.)
// To hide the files locally, we call the hide method on the adapter
// ...which a live object...cannot be parceled.
// For that reason, for now, we implement this dialog NOT
// as a fragment (which can survive rotation and have its own state),
// but as a simple runtime dialog. So rotating a device with an
// active delete dialog...results in that dialog disappearing.
// We can do better, but don't have cycles for it now.
new AlertDialog.Builder(getActivity()).setView(message).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// the user cancels the delete.
if (mActionMode != null) {
mActionMode.finish();
} else {
Log.w(TAG, "Action mode is null before deleting documents.");
}
// Hide the files in the UI...since the operation
// might be queued up on FileOperationService.
// We're walking a line here.
mAdapter.hide(selected.getAll());
FileOperations.delete(getActivity(), docs, srcParent, getDisplayState().stack);
}
}).setNegativeButton(android.R.string.no, null).show();
}
use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.
the class FilesActivity method refreshDirectory.
@Override
void refreshDirectory(int anim) {
final FragmentManager fm = getFragmentManager();
final RootInfo root = getCurrentRoot();
final DocumentInfo cwd = getCurrentDirectory();
assert (!mSearchManager.isSearching());
if (cwd == null) {
DirectoryFragment.showRecentsOpen(fm, anim);
} else {
// Normal boring directory
DirectoryFragment.showDirectory(fm, root, cwd, anim);
}
}
use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by DirtyUnicorns.
the class CopyJob method copyDirectoryHelper.
/**
* Handles recursion into a directory and copying its contents. Note that in linux terms, this
* does the equivalent of "cp src/* dst", not "cp -r src dst".
*
* @param srcDir Info of the directory to copy from. The routine will copy the directory's
* contents, not the directory itself.
* @param destDir Info of the directory to copy to. Must be created beforehand.
* @throws ResourceException
*/
private void copyDirectoryHelper(DocumentInfo srcDir, DocumentInfo destDir) throws ResourceException {
// Recurse into directories. Copy children into the new subdirectory.
final String[] queryColumns = new String[] { Document.COLUMN_DISPLAY_NAME, Document.COLUMN_DOCUMENT_ID, Document.COLUMN_MIME_TYPE, Document.COLUMN_SIZE, Document.COLUMN_FLAGS };
Cursor cursor = null;
boolean success = true;
// Iterate over srcs in the directory; copy to the destination directory.
final Uri queryUri = buildChildDocumentsUri(srcDir.authority, srcDir.documentId);
try {
try {
cursor = getClient(srcDir).query(queryUri, queryColumns, null, null, null);
} catch (RemoteException | RuntimeException e) {
throw new ResourceException("Failed to query children of %s due to an exception.", srcDir.derivedUri, e);
}
DocumentInfo src;
while (cursor.moveToNext() && !isCanceled()) {
try {
src = DocumentInfo.fromCursor(cursor, srcDir.authority);
processDocument(src, srcDir, destDir);
} catch (RuntimeException e) {
Log.e(TAG, "Failed to recursively process a file %s due to an exception.".format(srcDir.derivedUri.toString()), e);
success = false;
}
}
} catch (RuntimeException e) {
Log.e(TAG, "Failed to copy a file %s to %s. ".format(srcDir.derivedUri.toString(), destDir.derivedUri.toString()), e);
success = false;
} finally {
IoUtils.closeQuietly(cursor);
}
if (!success) {
throw new RuntimeException("Some files failed to copy during a recursive " + "directory copy.");
}
}
use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by DirtyUnicorns.
the class CopyJob method start.
@Override
void start() {
mStartTime = elapsedRealtime();
try {
mBatchSize = calculateSize(mSrcs);
} catch (ResourceException e) {
Log.w(TAG, "Failed to calculate total size. Copying without progress.", e);
mBatchSize = -1;
}
DocumentInfo srcInfo;
DocumentInfo dstInfo = stack.peek();
for (int i = 0; i < mSrcs.size() && !isCanceled(); ++i) {
srcInfo = mSrcs.get(i);
if (DEBUG)
Log.d(TAG, "Copying " + srcInfo.displayName + " (" + srcInfo.derivedUri + ")" + " to " + dstInfo.displayName + " (" + dstInfo.derivedUri + ")");
try {
if (dstInfo.equals(srcInfo) || isDescendentOf(srcInfo, dstInfo)) {
Log.e(TAG, "Skipping recursive copy of " + srcInfo.derivedUri);
onFileFailed(srcInfo);
} else {
processDocument(srcInfo, null, dstInfo);
}
} catch (ResourceException e) {
Log.e(TAG, "Failed to copy " + srcInfo.derivedUri, e);
onFileFailed(srcInfo);
}
}
Metrics.logFileOperation(service, operationType, mSrcs, dstInfo);
}
use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by DirtyUnicorns.
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);
}
Aggregations