Search in sources :

Example 31 with DocumentInfo

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();
}
Also used : DialogInterface(android.content.DialogInterface) TextView(android.widget.TextView) Point(android.graphics.Point) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 32 with DocumentInfo

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);
    }
}
Also used : FragmentManager(android.app.FragmentManager) RootInfo(com.android.documentsui.model.RootInfo) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 33 with DocumentInfo

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.");
    }
}
Also used : DocumentInfo.getCursorString(com.android.documentsui.model.DocumentInfo.getCursorString) Cursor(android.database.Cursor) 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 34 with DocumentInfo

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);
}
Also used : DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 35 with DocumentInfo

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);
}
Also used : 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