use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.
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);
}
}
use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.
the class DocumentClipper method getDocumentsFromClipData.
/**
* Returns a list of Documents as decoded in clipData.
* This should be run from inside an AsyncTask.
*/
public List<DocumentInfo> getDocumentsFromClipData(ClipData clipData) {
assert (clipData != null);
final List<DocumentInfo> srcDocs = new ArrayList<>();
int count = clipData.getItemCount();
if (count == 0) {
return srcDocs;
}
ContentResolver resolver = mContext.getContentResolver();
for (int i = 0; i < count; ++i) {
ClipData.Item item = clipData.getItemAt(i);
Uri itemUri = item.getUri();
if (itemUri != null && DocumentsContract.isDocumentUri(mContext, itemUri)) {
ContentProviderClient client = null;
Cursor cursor = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, itemUri.getAuthority());
cursor = client.query(itemUri, null, null, null, null);
cursor.moveToPosition(0);
srcDocs.add(DocumentInfo.fromCursor(cursor, itemUri.getAuthority()));
} catch (Exception e) {
Log.e(TAG, e.getMessage());
} finally {
IoUtils.closeQuietly(cursor);
ContentProviderClient.releaseQuietly(client);
}
}
}
return srcDocs;
}
use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.
the class BaseActivity method reloadSearch.
private void reloadSearch(String query) {
FragmentManager fm = getFragmentManager();
RootInfo root = getCurrentRoot();
DocumentInfo cwd = getCurrentDirectory();
DirectoryFragment.reloadSearch(fm, root, cwd, query);
}
use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.
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;
}
use of com.android.documentsui.model.DocumentInfo in project platform_frameworks_base by android.
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();
}
Aggregations