Search in sources :

Example 36 with DocumentInfo

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

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

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

the class DirectoryFragment method deleteDocuments.

private void deleteDocuments(final Selection selected) {
    Metrics.logUserAction(getContext(), Metrics.USER_ACTION_DELETE);
    assert (!selected.isEmpty());
    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 38 with DocumentInfo

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

the class DirectoryFragment method generateDeleteMessage.

private String generateDeleteMessage(final List<DocumentInfo> docs) {
    String message;
    int dirsCount = 0;
    for (DocumentInfo doc : docs) {
        if (doc.isDirectory()) {
            ++dirsCount;
        }
    }
    if (docs.size() == 1) {
        // Deleteing 1 file xor 1 folder in cwd
        // Address b/28772371, where including user strings in message can result in
        // broken bidirectional support.
        String displayName = BidiFormatter.getInstance().unicodeWrap(docs.get(0).displayName);
        message = dirsCount == 0 ? getActivity().getString(R.string.delete_filename_confirmation_message, displayName) : getActivity().getString(R.string.delete_foldername_confirmation_message, displayName);
    } else if (dirsCount == 0) {
        // Deleting only files in cwd
        message = Shared.getQuantityString(getActivity(), R.plurals.delete_files_confirmation_message, docs.size());
    } else if (dirsCount == docs.size()) {
        // Deleting only folders in cwd
        message = Shared.getQuantityString(getActivity(), R.plurals.delete_folders_confirmation_message, docs.size());
    } else {
        // Deleting mixed items (files and folders) in cwd
        message = Shared.getQuantityString(getActivity(), R.plurals.delete_items_confirmation_message, docs.size());
    }
    return message;
}
Also used : DocumentInfo.getCursorString(com.android.documentsui.model.DocumentInfo.getCursorString) Point(android.graphics.Point) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 39 with DocumentInfo

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

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

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

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)

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