Loading packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java +114 −149 Original line number Diff line number Diff line Loading @@ -753,21 +753,17 @@ public class DirectoryFragment extends Fragment private void openDocuments(final Selection selected) { Metrics.logUserAction(getContext(), Metrics.USER_ACTION_OPEN); new GetDocumentsTask() { @Override void onDocumentsReady(List<DocumentInfo> docs) { // Model must be accessed in UI thread, since underlying cursor is not threadsafe. List<DocumentInfo> docs = mModel.getDocuments(selected); // TODO: Implement support in Files activity for opening multiple docs. BaseActivity.get(DirectoryFragment.this).onDocumentsPicked(docs); } }.execute(selected); } private void shareDocuments(final Selection selected) { Metrics.logUserAction(getContext(), Metrics.USER_ACTION_SHARE); new GetDocumentsTask() { @Override void onDocumentsReady(List<DocumentInfo> docs) { // 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. Loading Loading @@ -809,8 +805,6 @@ public class DirectoryFragment extends Fragment intent = Intent.createChooser(intent, getActivity().getText(R.string.share_via)); startActivity(intent); } }.execute(selected); } private String generateDeleteMessage(final List<DocumentInfo> docs) { String message; Loading Loading @@ -855,9 +849,9 @@ public class DirectoryFragment extends Fragment assert(!selected.isEmpty()); final DocumentInfo srcParent = getDisplayState().stack.peek(); new GetDocumentsTask() { @Override void onDocumentsReady(final List<DocumentInfo> docs) { // 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); Loading @@ -878,6 +872,7 @@ public class DirectoryFragment extends Fragment .setPositiveButton( android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // Finish selection mode first which clears selection so we // don't end up trying to deselect deleted documents. Loading @@ -900,8 +895,6 @@ public class DirectoryFragment extends Fragment .setNegativeButton(android.R.string.no, null) .show(); } }.execute(selected); } private void transferDocuments(final Selection selected, final @OpType int mode) { if(mode == FileOperationService.OPERATION_COPY) { Loading Loading @@ -934,9 +927,8 @@ public class DirectoryFragment extends Fragment ? R.string.menu_move : R.string.menu_copy; intent.putExtra(DocumentsContract.EXTRA_PROMPT, getResources().getString(drawerTitleId)); new GetDocumentsTask() { @Override void onDocumentsReady(List<DocumentInfo> docs) { // 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; Loading @@ -952,9 +944,6 @@ public class DirectoryFragment extends Fragment startActivityForResult(intent, REQUEST_COPY_DESTINATION); } }.execute(selected); } private static boolean hasDirectory(List<DocumentInfo> docs) { for (DocumentInfo info : docs) { if (Document.MIME_TYPE_DIR.equals(info.mimeType)) { Loading @@ -971,13 +960,10 @@ public class DirectoryFragment extends Fragment // Rename option is only available in menu when 1 document selected assert(selected.size() == 1); new GetDocumentsTask() { @Override void onDocumentsReady(List<DocumentInfo> docs) { // Model must be accessed in UI thread, since underlying cursor is not threadsafe. List<DocumentInfo> docs = mModel.getDocuments(selected); RenameDocumentFragment.show(getFragmentManager(), docs.get(0)); } }.execute(selected); } @Override public void initDocumentHolder(DocumentHolder holder) { Loading Loading @@ -1135,11 +1121,11 @@ public class DirectoryFragment extends Fragment } } void copySelectionToClipboard(Selection selection) { assert(!selection.isEmpty()); new GetDocumentsTask() { @Override void onDocumentsReady(List<DocumentInfo> docs) { void copySelectionToClipboard(Selection selected) { assert(!selected.isEmpty()); // Model must be accessed in UI thread, since underlying cursor is not threadsafe. List<DocumentInfo> docs = mModel.getDocuments(selected); mClipper.clipDocuments(docs); Activity activity = getActivity(); Snackbars.makeSnackbar(activity, Loading @@ -1147,8 +1133,6 @@ public class DirectoryFragment extends Fragment R.plurals.clipboard_files_clipped, docs.size(), docs.size()), Snackbar.LENGTH_SHORT).show(); } }.execute(selection); } public void pasteFromClipboard() { Metrics.logUserAction(getContext(), Metrics.USER_ACTION_PASTE_CLIPBOARD); Loading Loading @@ -1456,25 +1440,6 @@ public class DirectoryFragment extends Fragment mShadowView.draw(canvas); } } /** * Abstract task providing support for loading documents *off* * the main thread. And if it isn't obvious, creating a list * of documents (especially large lists) can be pretty expensive. */ private abstract class GetDocumentsTask extends AsyncTask<Selection, Void, List<DocumentInfo>> { @Override protected final List<DocumentInfo> doInBackground(Selection... selected) { return mModel.getDocuments(selected[0]); } @Override protected final void onPostExecute(List<DocumentInfo> docs) { onDocumentsReady(docs); } abstract void onDocumentsReady(List<DocumentInfo> docs); } @Override public boolean isSelected(String modelId) { Loading Loading
packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java +114 −149 Original line number Diff line number Diff line Loading @@ -753,21 +753,17 @@ public class DirectoryFragment extends Fragment private void openDocuments(final Selection selected) { Metrics.logUserAction(getContext(), Metrics.USER_ACTION_OPEN); new GetDocumentsTask() { @Override void onDocumentsReady(List<DocumentInfo> docs) { // Model must be accessed in UI thread, since underlying cursor is not threadsafe. List<DocumentInfo> docs = mModel.getDocuments(selected); // TODO: Implement support in Files activity for opening multiple docs. BaseActivity.get(DirectoryFragment.this).onDocumentsPicked(docs); } }.execute(selected); } private void shareDocuments(final Selection selected) { Metrics.logUserAction(getContext(), Metrics.USER_ACTION_SHARE); new GetDocumentsTask() { @Override void onDocumentsReady(List<DocumentInfo> docs) { // 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. Loading Loading @@ -809,8 +805,6 @@ public class DirectoryFragment extends Fragment intent = Intent.createChooser(intent, getActivity().getText(R.string.share_via)); startActivity(intent); } }.execute(selected); } private String generateDeleteMessage(final List<DocumentInfo> docs) { String message; Loading Loading @@ -855,9 +849,9 @@ public class DirectoryFragment extends Fragment assert(!selected.isEmpty()); final DocumentInfo srcParent = getDisplayState().stack.peek(); new GetDocumentsTask() { @Override void onDocumentsReady(final List<DocumentInfo> docs) { // 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); Loading @@ -878,6 +872,7 @@ public class DirectoryFragment extends Fragment .setPositiveButton( android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // Finish selection mode first which clears selection so we // don't end up trying to deselect deleted documents. Loading @@ -900,8 +895,6 @@ public class DirectoryFragment extends Fragment .setNegativeButton(android.R.string.no, null) .show(); } }.execute(selected); } private void transferDocuments(final Selection selected, final @OpType int mode) { if(mode == FileOperationService.OPERATION_COPY) { Loading Loading @@ -934,9 +927,8 @@ public class DirectoryFragment extends Fragment ? R.string.menu_move : R.string.menu_copy; intent.putExtra(DocumentsContract.EXTRA_PROMPT, getResources().getString(drawerTitleId)); new GetDocumentsTask() { @Override void onDocumentsReady(List<DocumentInfo> docs) { // 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; Loading @@ -952,9 +944,6 @@ public class DirectoryFragment extends Fragment startActivityForResult(intent, REQUEST_COPY_DESTINATION); } }.execute(selected); } private static boolean hasDirectory(List<DocumentInfo> docs) { for (DocumentInfo info : docs) { if (Document.MIME_TYPE_DIR.equals(info.mimeType)) { Loading @@ -971,13 +960,10 @@ public class DirectoryFragment extends Fragment // Rename option is only available in menu when 1 document selected assert(selected.size() == 1); new GetDocumentsTask() { @Override void onDocumentsReady(List<DocumentInfo> docs) { // Model must be accessed in UI thread, since underlying cursor is not threadsafe. List<DocumentInfo> docs = mModel.getDocuments(selected); RenameDocumentFragment.show(getFragmentManager(), docs.get(0)); } }.execute(selected); } @Override public void initDocumentHolder(DocumentHolder holder) { Loading Loading @@ -1135,11 +1121,11 @@ public class DirectoryFragment extends Fragment } } void copySelectionToClipboard(Selection selection) { assert(!selection.isEmpty()); new GetDocumentsTask() { @Override void onDocumentsReady(List<DocumentInfo> docs) { void copySelectionToClipboard(Selection selected) { assert(!selected.isEmpty()); // Model must be accessed in UI thread, since underlying cursor is not threadsafe. List<DocumentInfo> docs = mModel.getDocuments(selected); mClipper.clipDocuments(docs); Activity activity = getActivity(); Snackbars.makeSnackbar(activity, Loading @@ -1147,8 +1133,6 @@ public class DirectoryFragment extends Fragment R.plurals.clipboard_files_clipped, docs.size(), docs.size()), Snackbar.LENGTH_SHORT).show(); } }.execute(selection); } public void pasteFromClipboard() { Metrics.logUserAction(getContext(), Metrics.USER_ACTION_PASTE_CLIPBOARD); Loading Loading @@ -1456,25 +1440,6 @@ public class DirectoryFragment extends Fragment mShadowView.draw(canvas); } } /** * Abstract task providing support for loading documents *off* * the main thread. And if it isn't obvious, creating a list * of documents (especially large lists) can be pretty expensive. */ private abstract class GetDocumentsTask extends AsyncTask<Selection, Void, List<DocumentInfo>> { @Override protected final List<DocumentInfo> doInBackground(Selection... selected) { return mModel.getDocuments(selected[0]); } @Override protected final void onPostExecute(List<DocumentInfo> docs) { onDocumentsReady(docs); } abstract void onDocumentsReady(List<DocumentInfo> docs); } @Override public boolean isSelected(String modelId) { Loading