From 954be0232655d316bc5decbbd35579af902c75c2 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Tue, 3 Sep 2013 15:25:52 -0700 Subject: [PATCH] Show loading, error, and info messages as footers. A provider can include extras in their Cursors to indicate that loading is ongoing, or include an error or informational message, which are now shown in footer views. Fix registration to always get change notifications. Test provider that verifies common provider behavior of holding a reference to "cloud" resources that are released by GC when the remote Cursor is closed. Also used to validate Recents behavior for slow providers. Bug: 10599268 Change-Id: I331c31058dbb80261e7d279b851197c65ac87e32 --- .../DocumentsUI/res/layout/item_loading.xml | 34 +++ .../res/layout/item_message_grid.xml | 59 +++++ .../res/layout/item_message_list.xml | 47 ++++ .../documentsui/DirectoryFragment.java | 108 +++++++- .../android/documentsui/DirectoryLoader.java | 3 +- .../documentsui/RootCursorWrapper.java | 7 +- .../documentsui/SortingCursorWrapper.java | 6 + .../AndroidManifest.xml | 15 +- .../TestDocumentsProvider.java | 244 ++++++++++++++++++ 9 files changed, 517 insertions(+), 6 deletions(-) create mode 100644 packages/DocumentsUI/res/layout/item_loading.xml create mode 100644 packages/DocumentsUI/res/layout/item_message_grid.xml create mode 100644 packages/DocumentsUI/res/layout/item_message_list.xml create mode 100644 packages/ExternalStorageProvider/src/com/android/externalstorage/TestDocumentsProvider.java diff --git a/packages/DocumentsUI/res/layout/item_loading.xml b/packages/DocumentsUI/res/layout/item_loading.xml new file mode 100644 index 0000000000000..7da71e3cb4f69 --- /dev/null +++ b/packages/DocumentsUI/res/layout/item_loading.xml @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/packages/DocumentsUI/res/layout/item_message_grid.xml b/packages/DocumentsUI/res/layout/item_message_grid.xml new file mode 100644 index 0000000000000..941340e9d720e --- /dev/null +++ b/packages/DocumentsUI/res/layout/item_message_grid.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + diff --git a/packages/DocumentsUI/res/layout/item_message_list.xml b/packages/DocumentsUI/res/layout/item_message_list.xml new file mode 100644 index 0000000000000..dda3c80f2baa3 --- /dev/null +++ b/packages/DocumentsUI/res/layout/item_message_list.xml @@ -0,0 +1,47 @@ + + + + + + + + + + diff --git a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java index 1220137f8e3e5..33d7d6afd18db 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java +++ b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java @@ -412,11 +412,83 @@ public class DirectoryFragment extends Fragment { return ((DocumentsActivity) fragment.getActivity()).getDisplayState(); } + private interface Footer { + public View getView(View convertView, ViewGroup parent); + } + + private static class LoadingFooter implements Footer { + @Override + public View getView(View convertView, ViewGroup parent) { + final Context context = parent.getContext(); + if (convertView == null) { + final LayoutInflater inflater = LayoutInflater.from(context); + convertView = inflater.inflate(R.layout.item_loading, parent, false); + } + return convertView; + } + } + + private class MessageFooter implements Footer { + private final int mIcon; + private final String mMessage; + + public MessageFooter(int icon, String message) { + mIcon = icon; + mMessage = message; + } + + @Override + public View getView(View convertView, ViewGroup parent) { + final Context context = parent.getContext(); + final State state = getDisplayState(DirectoryFragment.this); + + if (convertView == null) { + final LayoutInflater inflater = LayoutInflater.from(context); + if (state.mode == MODE_LIST) { + convertView = inflater.inflate(R.layout.item_message_list, parent, false); + } else if (state.mode == MODE_GRID) { + convertView = inflater.inflate(R.layout.item_message_grid, parent, false); + } else { + throw new IllegalStateException(); + } + } + + final ImageView icon = (ImageView) convertView.findViewById(android.R.id.icon); + final TextView title = (TextView) convertView.findViewById(android.R.id.title); + icon.setImageResource(mIcon); + title.setText(mMessage); + return convertView; + } + } + private class DocumentsAdapter extends BaseAdapter { private Cursor mCursor; + private int mCursorCount; + + private List