From 2622e40de0fa300a00d815f084ea6098f70f93e9 Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Wed, 2 Mar 2011 17:34:04 -0800 Subject: when moving from landscape to portrait, selections are getting lost when moving from landscape/portait to portrait/landscape mode, losing all the selections (and checkboxes too) Change-Id: Iefb1e0db00229fca68fc1080accb57b0ae3ca26e --- .../providers/downloads/ui/DownloadItem.java | 3 +++ .../providers/downloads/ui/DownloadList.java | 27 ++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) (limited to 'ui/src/com/android/providers/downloads/ui') diff --git a/ui/src/com/android/providers/downloads/ui/DownloadItem.java b/ui/src/com/android/providers/downloads/ui/DownloadItem.java index 2ab38ff5..4cbcd332 100644 --- a/ui/src/com/android/providers/downloads/ui/DownloadItem.java +++ b/ui/src/com/android/providers/downloads/ui/DownloadItem.java @@ -72,6 +72,9 @@ public class DownloadItem extends RelativeLayout implements Checkable { mPosition = position; mFileName = fileName; mMimeType = mimeType; + if (mDownloadList.isDownloadSelected(downloadId)) { + setChecked(true); + } } public void setDownloadListObj(DownloadList downloadList) { diff --git a/ui/src/com/android/providers/downloads/ui/DownloadList.java b/ui/src/com/android/providers/downloads/ui/DownloadList.java index ec24325e..b932b115 100644 --- a/ui/src/com/android/providers/downloads/ui/DownloadList.java +++ b/ui/src/com/android/providers/downloads/ui/DownloadList.java @@ -190,6 +190,8 @@ public class DownloadList extends Activity { public void onClick(View v) { // flip the view mIsSortedBySize = !mIsSortedBySize; + // clear all selections + mSelectedIds.clear(); chooseListToShow(); } }); @@ -312,14 +314,17 @@ public class DownloadList extends Activity { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { - ListView lv = mDownloadList.getCurrentView(); - int numChecked = lv.getCheckedItemCount(); - if (numChecked > 0) { - mode.setTitle(String.format(mDownloadList.mSelectedCountFormat, numChecked, - mDownloadList.mCurrentCursor.getCount())); - } else { - mode.setTitle(""); - } + mDownloadList.setActionModeTitle(mode); + } + } + + void setActionModeTitle(ActionMode mode) { + int numSelected = mSelectedIds.size(); + if (numSelected > 0) { + mode.setTitle(String.format(mSelectedCountFormat, numSelected, + mCurrentCursor.getCount())); + } else { + mode.setTitle(""); } } @@ -366,6 +371,7 @@ public class DownloadList extends Activity { SelectionObjAttrs obj = mSelectedIds.get(id); fileNames[i] = obj.getFileName(); mimeTypes[i] = obj.getMimeType(); + i++; } outState.putLongArray(BUNDLE_SAVED_DOWNLOAD_IDS, selectedIds); outState.putStringArray(BUNDLE_SAVED_FILENAMES, fileNames); @@ -403,7 +409,10 @@ public class DownloadList extends Activity { lv.setVisibility(View.VISIBLE); lv.invalidateViews(); // ensure checkboxes get updated } - mSelectedIds.clear(); + // restore the ActionMode title if there are selections + if (mActionMode != null) { + setActionModeTitle(mActionMode); + } } ListView getCurrentView() { -- cgit v1.2.3