From 2fbb40eebd508b67e53f5a8590caf57a53cfb25d Mon Sep 17 00:00:00 2001 From: Steve McKay Date: Fri, 19 Feb 2016 10:57:08 -0800 Subject: [PATCH] Add CREATOR class to Selection. Bug: 27236334 Change-Id: I5f50cd63b850785194fec2db3eb68e40aa7af34f --- .../dirlist/MultiSelectManager.java | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/MultiSelectManager.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/MultiSelectManager.java index 19268d759a47b..4cf1048b6ab44 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/MultiSelectManager.java +++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/MultiSelectManager.java @@ -657,15 +657,22 @@ public final class MultiSelectManager { // item A is tapped (and selected), then an in-progress band select covers A then uncovers // A, A should still be selected as it has been saved. To ensure this behavior, the saved // selection must be tracked separately. - private Set mSelection = new HashSet<>(); - private Set mProvisionalSelection = new HashSet<>(); + private final Set mSelection; + private final Set mProvisionalSelection; private String mDirectoryKey; - @VisibleForTesting - public Selection(String... ids) { - for (int i = 0; i < ids.length; i++) { - add(ids[i]); - } + public Selection() { + mSelection = new HashSet(); + mProvisionalSelection = new HashSet(); + } + + /** + * Used by CREATOR. + */ + private Selection(String directoryKey, List selection) { + mDirectoryKey = directoryKey; + mSelection = new HashSet(selection); + mProvisionalSelection = new HashSet(); } /** @@ -810,8 +817,11 @@ public final class MultiSelectManager { @VisibleForTesting void copyFrom(Selection source) { - mSelection = new HashSet<>(source.mSelection); - mProvisionalSelection = new HashSet<>(source.mProvisionalSelection); + mSelection.clear(); + mSelection.addAll(source.mSelection); + + mProvisionalSelection.clear(); + mProvisionalSelection.addAll(source.mProvisionalSelection); } @Override @@ -878,6 +888,26 @@ public final class MultiSelectManager { // We don't include provisional selection since it is // typically coupled to some other runtime state (like a band). } + + public static final ClassLoaderCreator CREATOR = + new ClassLoaderCreator() { + @Override + public Selection createFromParcel(Parcel in) { + return createFromParcel(in, null); + } + + @Override + public Selection createFromParcel(Parcel in, ClassLoader loader) { + return new Selection( + in.readString(), + (ArrayList) in.readArrayList(loader)); + } + + @Override + public Selection[] newArray(int size) { + return new Selection[size]; + } + }; } /**