Search in sources :

Example 41 with DocumentInfo

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

the class DocumentsActivity method onPrepareOptionsMenu.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    final DocumentInfo cwd = getCurrentDirectory();
    boolean picking = mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE || mState.action == ACTION_PICK_COPY_DESTINATION;
    if (picking) {
        // May already be hidden because the root
        // doesn't support search.
        mSearchManager.showMenu(false);
    }
    final MenuItem createDir = menu.findItem(R.id.menu_create_dir);
    final MenuItem grid = menu.findItem(R.id.menu_grid);
    final MenuItem list = menu.findItem(R.id.menu_list);
    final MenuItem fileSize = menu.findItem(R.id.menu_file_size);
    createDir.setVisible(picking);
    createDir.setEnabled(canCreateDirectory());
    // No display options in recent directories
    boolean inRecents = cwd == null;
    if (picking && inRecents) {
        grid.setVisible(false);
        list.setVisible(false);
    }
    fileSize.setVisible(fileSize.isVisible() && !picking);
    if (mState.action == ACTION_CREATE) {
        final FragmentManager fm = getFragmentManager();
        SaveFragment.get(fm).prepareForDirectory(cwd);
    }
    Menus.disableHiddenItems(menu);
    return true;
}
Also used : FragmentManager(android.app.FragmentManager) MenuItem(android.view.MenuItem) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 42 with DocumentInfo

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

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)

Example 43 with DocumentInfo

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

the class FilesActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mClipper = new DocumentClipper(this);
    RootsFragment.show(getFragmentManager(), null);
    final Intent intent = getIntent();
    final Uri uri = intent.getData();
    if (mState.restored) {
        if (DEBUG)
            Log.d(TAG, "Stack already resolved for uri: " + intent.getData());
    } else if (!mState.stack.isEmpty()) {
        // in downloads.
        if (uri != null && uri.getAuthority() != null && !uri.equals(mState.stack.peek()) && !LauncherActivity.isLaunchUri(uri)) {
            if (DEBUG)
                Log.w(TAG, "Launching with non-empty stack. Ignoring unexpected uri: " + uri);
        } else {
            if (DEBUG)
                Log.d(TAG, "Launching with non-empty stack.");
        }
        refreshCurrentRootAndDirectory(AnimationView.ANIM_NONE);
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        assert (uri != null);
        new OpenUriForViewTask(this).executeOnExecutor(ProviderExecutor.forAuthority(uri.getAuthority()), uri);
    } else if (DocumentsContract.isRootUri(this, uri)) {
        if (DEBUG)
            Log.d(TAG, "Launching with root URI.");
        // If we've got a specific root to display, restore that root using a dedicated
        // authority. That way a misbehaving provider won't result in an ANR.
        loadRoot(uri);
    } else {
        if (DEBUG)
            Log.d(TAG, "All other means skipped. Launching into default directory.");
        loadRoot(getDefaultRoot());
    }
    @DialogType final int dialogType = intent.getIntExtra(FileOperationService.EXTRA_DIALOG_TYPE, DIALOG_TYPE_UNKNOWN);
    // Only show it manually for the first time (icicle is null).
    if (icicle == null && dialogType != DIALOG_TYPE_UNKNOWN) {
        final int opType = intent.getIntExtra(FileOperationService.EXTRA_OPERATION, FileOperationService.OPERATION_COPY);
        final ArrayList<DocumentInfo> srcList = intent.getParcelableArrayListExtra(FileOperationService.EXTRA_SRC_LIST);
        OperationDialogFragment.show(getFragmentManager(), dialogType, srcList, mState.stack, opType);
    }
}
Also used : DialogType(com.android.documentsui.OperationDialogFragment.DialogType) Intent(android.content.Intent) Uri(android.net.Uri) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 44 with DocumentInfo

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

the class FileOperationServiceTest method createDoc.

private static DocumentInfo createDoc(Uri destination) {
    DocumentInfo destDoc = new DocumentInfo();
    destDoc.derivedUri = destination;
    return destDoc;
}
Also used : DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 45 with DocumentInfo

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

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)

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