Search in sources :

Example 56 with DocumentInfo

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

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

Example 57 with DocumentInfo

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

the class DirectoryFragment method shareDocuments.

private void shareDocuments(final Selection selected) {
    Metrics.logUserAction(getContext(), Metrics.USER_ACTION_SHARE);
    // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
    List<DocumentInfo> docs = mModel.getDocuments(selected);
    Intent intent;
    // Filter out directories and virtual files - those can't be shared.
    List<DocumentInfo> docsForSend = new ArrayList<>();
    for (DocumentInfo doc : docs) {
        if (!doc.isDirectory() && !doc.isVirtualDocument()) {
            docsForSend.add(doc);
        }
    }
    if (docsForSend.size() == 1) {
        final DocumentInfo doc = docsForSend.get(0);
        intent = new Intent(Intent.ACTION_SEND);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setType(doc.mimeType);
        intent.putExtra(Intent.EXTRA_STREAM, doc.derivedUri);
    } else if (docsForSend.size() > 1) {
        intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        final ArrayList<String> mimeTypes = new ArrayList<>();
        final ArrayList<Uri> uris = new ArrayList<>();
        for (DocumentInfo doc : docsForSend) {
            mimeTypes.add(doc.mimeType);
            uris.add(doc.derivedUri);
        }
        intent.setType(findCommonMimeType(mimeTypes));
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    } else {
        return;
    }
    intent = Intent.createChooser(intent, getActivity().getText(R.string.share_via));
    startActivity(intent);
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 58 with DocumentInfo

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

the class DirectoryFragment method transferDocuments.

private void transferDocuments(final Selection selected, @OpType final int mode) {
    if (mode == FileOperationService.OPERATION_COPY) {
        Metrics.logUserAction(getContext(), Metrics.USER_ACTION_COPY_TO);
    } else if (mode == FileOperationService.OPERATION_MOVE) {
        Metrics.logUserAction(getContext(), Metrics.USER_ACTION_MOVE_TO);
    }
    // Pop up a dialog to pick a destination.  This is inadequate but works for now.
    // TODO: Implement a picker that is to spec.
    final Intent intent = new Intent(Shared.ACTION_PICK_COPY_DESTINATION, Uri.EMPTY, getActivity(), DocumentsActivity.class);
    // Relay any config overrides bits present in the original intent.
    Intent original = getActivity().getIntent();
    if (original != null && original.hasExtra(Shared.EXTRA_PRODUCTIVITY_MODE)) {
        intent.putExtra(Shared.EXTRA_PRODUCTIVITY_MODE, original.getBooleanExtra(Shared.EXTRA_PRODUCTIVITY_MODE, false));
    }
    // Set an appropriate title on the drawer when it is shown in the picker.
    // Coupled with the fact that we auto-open the drawer for copy/move operations
    // it should basically be the thing people see first.
    int drawerTitleId = mode == FileOperationService.OPERATION_MOVE ? R.string.menu_move : R.string.menu_copy;
    intent.putExtra(DocumentsContract.EXTRA_PROMPT, getResources().getString(drawerTitleId));
    // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
    List<DocumentInfo> docs = mModel.getDocuments(selected);
    // TODO: Can this move to Fragment bundle state?
    getDisplayState().selectedDocumentsForCopy = docs;
    // Determine if there is a directory in the set of documents
    // to be copied? Why? Directory creation isn't supported by some roots
    // (like Downloads). This informs DocumentsActivity (the "picker")
    // to restrict available roots to just those with support.
    intent.putExtra(Shared.EXTRA_DIRECTORY_COPY, hasDirectory(docs));
    intent.putExtra(FileOperationService.EXTRA_OPERATION, mode);
    // This just identifies the type of request...we'll check it
    // when we reveive a response.
    startActivityForResult(intent, REQUEST_COPY_DESTINATION);
}
Also used : Intent(android.content.Intent) Point(android.graphics.Point) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 59 with DocumentInfo

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

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

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

the class DirectoryFragment method handleViewItem.

private boolean handleViewItem(String id) {
    final Cursor cursor = mModel.getItem(id);
    if (cursor == null) {
        Log.w(TAG, "Can't view item. Can't obtain cursor for modeId" + id);
        return false;
    }
    final String docMimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
    final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
    if (mTuner.isDocumentEnabled(docMimeType, docFlags)) {
        final DocumentInfo doc = DocumentInfo.fromDirectoryCursor(cursor);
        ((BaseActivity) getActivity()).onDocumentPicked(doc, mModel);
        mSelectionManager.clearSelection();
        return true;
    }
    return false;
}
Also used : BaseActivity(com.android.documentsui.BaseActivity) DocumentInfo.getCursorString(com.android.documentsui.model.DocumentInfo.getCursorString) Cursor(android.database.Cursor) Point(android.graphics.Point) 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