From 81101942f55ae76824d244ef0cbf579fb84922fe Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Wed, 9 Mar 2011 10:43:28 -0800 Subject: multiple bug fixes when handling ExpandableListView bug:3511180 can't select items from non-adjacent groups bug:3510769 Long-pressing on section headers causes strange behavior bug:4065226 Downloads list switch sorting button has wrong width Change-Id: If7dd36078224766555f1d2cf18ec364812dcdeb9 --- ui/res/layout/download_list.xml | 2 +- .../downloads/ui/DateSortedDownloadAdapter.java | 8 +++++-- .../ui/DateSortedExpandableListAdapter.java | 13 ----------- .../providers/downloads/ui/DownloadList.java | 26 ++++++++++++++++++++-- 4 files changed, 31 insertions(+), 18 deletions(-) (limited to 'ui') diff --git a/ui/res/layout/download_list.xml b/ui/res/layout/download_list.xml index a49cf22a..18f44d10 100644 --- a/ui/res/layout/download_list.xml +++ b/ui/res/layout/download_list.xml @@ -55,7 +55,7 @@ diff --git a/ui/src/com/android/providers/downloads/ui/DateSortedDownloadAdapter.java b/ui/src/com/android/providers/downloads/ui/DateSortedDownloadAdapter.java index 8e93eab6..b69fb8b8 100644 --- a/ui/src/com/android/providers/downloads/ui/DateSortedDownloadAdapter.java +++ b/ui/src/com/android/providers/downloads/ui/DateSortedDownloadAdapter.java @@ -21,6 +21,7 @@ import android.app.DownloadManager; import android.database.Cursor; import android.view.View; import android.view.ViewGroup; +import android.widget.ExpandableListView; import android.widget.RelativeLayout; /** @@ -28,12 +29,14 @@ import android.widget.RelativeLayout; * {@link DownloadAdapter}. */ public class DateSortedDownloadAdapter extends DateSortedExpandableListAdapter { - private DownloadAdapter mDelegate; + private final DownloadAdapter mDelegate; + private final DownloadList mDownloadList; public DateSortedDownloadAdapter(DownloadList downloadList, Cursor cursor) { super(downloadList, cursor, cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP)); mDelegate = new DownloadAdapter(downloadList, cursor); + mDownloadList = downloadList; } @Override @@ -49,7 +52,8 @@ public class DateSortedDownloadAdapter extends DateSortedExpandableListAdapter { return convertView; } - int pos = getAbsolutePositionForGroupAndChildPositions(groupPosition, childPosition); + int pos = mDownloadList.getExpandableListView().getFlatListPosition( + ExpandableListView.getPackedPositionForChild(groupPosition, childPosition)); mDelegate.bindView(convertView, pos); return convertView; } diff --git a/ui/src/com/android/providers/downloads/ui/DateSortedExpandableListAdapter.java b/ui/src/com/android/providers/downloads/ui/DateSortedExpandableListAdapter.java index 73c51aef..19132a11 100644 --- a/ui/src/com/android/providers/downloads/ui/DateSortedExpandableListAdapter.java +++ b/ui/src/com/android/providers/downloads/ui/DateSortedExpandableListAdapter.java @@ -226,19 +226,6 @@ public class DateSortedExpandableListAdapter implements ExpandableListAdapter { return arrayPosition; } - int getAbsolutePositionForGroupAndChildPositions(int groupPosition, - int childPosition) { - int bin = groupPositionToBin(groupPosition); - int absolutePosition = 0; - for (int j = 0; j < bin; j++) { - if (mItemMap[j] > 0) { - absolutePosition += mItemMap[j] + 1; - } - } - absolutePosition += childPosition + 1; - return absolutePosition; - } - /** * Move the cursor to the position indicated. * @param packedPosition Position in packed position representation. diff --git a/ui/src/com/android/providers/downloads/ui/DownloadList.java b/ui/src/com/android/providers/downloads/ui/DownloadList.java index 978416c7..c6bd219b 100644 --- a/ui/src/com/android/providers/downloads/ui/DownloadList.java +++ b/ui/src/com/android/providers/downloads/ui/DownloadList.java @@ -103,8 +103,9 @@ public class DownloadList extends Activity { return mMimeType; } } - ListView mCurrentView; - Cursor mCurrentCursor; + private ListView mCurrentView; + private Cursor mCurrentCursor; + private boolean mCurrentViewIsExpandableListView = false; private boolean mIsSortedBySize = false; /** @@ -315,6 +316,17 @@ public class DownloadList extends Activity { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { + // ignore long clicks on groups + if (mDownloadList.isCurrentViewExpandableListView()) { + ExpandableListView ev = mDownloadList.getExpandableListView(); + long pos = ev.getExpandableListPosition(position); + if (checked && (ExpandableListView.getPackedPositionType(pos) == + ExpandableListView.PACKED_POSITION_TYPE_GROUP)) { + // ignore this click + ev.setItemChecked(position, false); + return; + } + } mDownloadList.setActionModeTitle(mode); } } @@ -420,17 +432,27 @@ public class DownloadList extends Activity { return mCurrentView; } + ExpandableListView getExpandableListView() { + return mDateOrderedListView; + } + + boolean isCurrentViewExpandableListView() { + return mCurrentViewIsExpandableListView; + } + private ListView activeListView() { if (mIsSortedBySize) { mCurrentCursor = mSizeSortedCursor; mCurrentView = mSizeOrderedListView; setTitle(R.string.download_title_sorted_by_size); mSortOption.setText(R.string.button_sort_by_date); + mCurrentViewIsExpandableListView = false; } else { mCurrentCursor = mDateSortedCursor; mCurrentView = mDateOrderedListView; setTitle(R.string.download_title_sorted_by_date); mSortOption.setText(R.string.button_sort_by_size); + mCurrentViewIsExpandableListView = true; } if (mActionMode != null) { mActionMode.finish(); -- cgit v1.2.3