Search in sources :

Example 11 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.

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)

Example 12 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.

the class OperationDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle inState) {
    super.onCreate(inState);
    @DialogType final int dialogType = getArguments().getInt(FileOperationService.EXTRA_DIALOG_TYPE);
    @OpType final int operationType = getArguments().getInt(FileOperationService.EXTRA_OPERATION);
    final ArrayList<DocumentInfo> srcList = getArguments().getParcelableArrayList(FileOperationService.EXTRA_SRC_LIST);
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    String messageFormat;
    switch(dialogType) {
        case DIALOG_TYPE_CONVERTED:
            messageFormat = getString(R.string.copy_converted_warning_content);
            break;
        case DIALOG_TYPE_FAILURE:
            switch(operationType) {
                case FileOperationService.OPERATION_COPY:
                    messageFormat = getString(R.string.copy_failure_alert_content);
                    break;
                case FileOperationService.OPERATION_DELETE:
                    messageFormat = getString(R.string.delete_failure_alert_content);
                    break;
                case FileOperationService.OPERATION_MOVE:
                    messageFormat = getString(R.string.move_failure_alert_content);
                    break;
                default:
                    throw new UnsupportedOperationException();
            }
            break;
        default:
            throw new UnsupportedOperationException();
    }
    final StringBuilder list = new StringBuilder("<p>");
    for (DocumentInfo documentInfo : srcList) {
        list.append(String.format("&#8226; %s<br>", Html.escapeHtml(documentInfo.displayName)));
    }
    list.append("</p>");
    builder.setMessage(Html.fromHtml(String.format(messageFormat, list.toString())));
    builder.setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });
    return builder.create();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OpType(com.android.documentsui.services.FileOperationService.OpType) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 13 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.

the class CreateDirectoryFragment method createDirectory.

private void createDirectory(String name) {
    final BaseActivity activity = (BaseActivity) getActivity();
    final DocumentInfo cwd = activity.getCurrentDirectory();
    new CreateDirectoryTask(activity, cwd, name).executeOnExecutor(ProviderExecutor.forAuthority(cwd.authority));
}
Also used : DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 14 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.

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;
}
Also used : ClipData(android.content.ClipData) ContentResolver(android.content.ContentResolver) DocumentInfo(com.android.documentsui.model.DocumentInfo) Nullable(android.support.annotation.Nullable)

Example 15 with DocumentInfo

use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.

the class DocumentClipper method getMimeTypes.

private static String[] getMimeTypes(ContentResolver resolver, List<DocumentInfo> docs) {
    final HashSet<String> mimeTypes = new HashSet<>();
    for (DocumentInfo doc : docs) {
        assert (doc != null);
        assert (doc.derivedUri != null);
        final Uri uri = doc.derivedUri;
        if ("content".equals(uri.getScheme())) {
            mimeTypes.add(resolver.getType(uri));
            final String[] streamTypes = resolver.getStreamTypes(uri, "*/*");
            if (streamTypes != null) {
                mimeTypes.addAll(Arrays.asList(streamTypes));
            }
        }
    }
    return mimeTypes.toArray(new String[0]);
}
Also used : Uri(android.net.Uri) HashSet(java.util.HashSet) 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