Skip to content

Commit a2c628f

Browse files
mikejurkaAndroid (Google) Code Review
authored andcommitted
Merge "Fix bug 6499508" into jb-dev
2 parents 533fce2 + d1a040c commit a2c628f

File tree

2 files changed

+17
-46
lines changed

2 files changed

+17
-46
lines changed

packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
import com.android.systemui.SwipeHelper;
4242
import com.android.systemui.recent.RecentsPanelView.TaskDescriptionAdapter;
4343

44-
import java.util.ArrayList;
44+
import java.util.HashSet;
45+
import java.util.Iterator;
4546

4647
public class RecentsHorizontalScrollView extends HorizontalScrollView
4748
implements SwipeHelper.Callback, RecentsPanelView.RecentsScrollView {
@@ -53,7 +54,7 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView
5354
protected int mLastScrollPosition;
5455
private SwipeHelper mSwipeHelper;
5556
private RecentsScrollViewPerformanceHelper mPerformanceHelper;
56-
private ArrayList<View> mRecycledViews;
57+
private HashSet<View> mRecycledViews;
5758
private int mNumItemsInOneScreenful;
5859

5960
public RecentsHorizontalScrollView(Context context, AttributeSet attrs) {
@@ -62,7 +63,7 @@ public RecentsHorizontalScrollView(Context context, AttributeSet attrs) {
6263
float pagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop();
6364
mSwipeHelper = new SwipeHelper(SwipeHelper.Y, this, densityScale, pagingTouchSlop);
6465
mPerformanceHelper = RecentsScrollViewPerformanceHelper.create(context, attrs, this, false);
65-
mRecycledViews = new ArrayList<View>();
66+
mRecycledViews = new HashSet<View>();
6667
}
6768

6869
public void setMinSwipeAlpha(float minAlpha) {
@@ -89,16 +90,12 @@ private void update() {
8990
setLayoutTransition(null);
9091

9192
mLinearLayout.removeAllViews();
92-
for (int i = 0; i < mRecycledViews.size(); i++) {
93-
View child = mRecycledViews.get(i);
94-
if (child.getParent() != null) {
95-
throw new RuntimeException("Recycled child has a parent");
96-
}
97-
}
93+
Iterator<View> recycledViews = mRecycledViews.iterator();
9894
for (int i = 0; i < mAdapter.getCount(); i++) {
9995
View old = null;
100-
if (mRecycledViews.size() != 0) {
101-
old = mRecycledViews.remove(mRecycledViews.size() - 1);
96+
if (recycledViews.hasNext()) {
97+
old = recycledViews.next();
98+
recycledViews.remove();
10299
old.setVisibility(VISIBLE);
103100
}
104101

@@ -195,9 +192,6 @@ public void dismissChild(View v) {
195192
public void onChildDismissed(View v) {
196193
addToRecycledViews(v);
197194
mLinearLayout.removeView(v);
198-
if (v.getParent() != null) {
199-
throw new RuntimeException("Recycled child has parent");
200-
}
201195
mCallback.handleSwipe(v);
202196
// Restore the alpha/translation parameters to what they were before swiping
203197
// (for when these items are recycled)
@@ -369,15 +363,9 @@ public void onInvalidated() {
369363
mNumItemsInOneScreenful =
370364
(int) FloatMath.ceil(dm.widthPixels / (float) child.getMeasuredWidth());
371365
addToRecycledViews(child);
372-
if (child.getParent() != null) {
373-
throw new RuntimeException("First recycled child has parent");
374-
}
375366

376367
for (int i = 0; i < mNumItemsInOneScreenful - 1; i++) {
377368
addToRecycledViews(mAdapter.createView(mLinearLayout));
378-
if (mRecycledViews.get(mRecycledViews.size() - 1).getParent() != null) {
379-
throw new RuntimeException("Recycled child has parent");
380-
}
381369
}
382370
}
383371

packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
import com.android.systemui.SwipeHelper;
4242
import com.android.systemui.recent.RecentsPanelView.TaskDescriptionAdapter;
4343

44-
import java.util.ArrayList;
44+
import java.util.HashSet;
45+
import java.util.Iterator;
4546

4647
public class RecentsVerticalScrollView extends ScrollView
4748
implements SwipeHelper.Callback, RecentsPanelView.RecentsScrollView {
@@ -53,7 +54,7 @@ public class RecentsVerticalScrollView extends ScrollView
5354
protected int mLastScrollPosition;
5455
private SwipeHelper mSwipeHelper;
5556
private RecentsScrollViewPerformanceHelper mPerformanceHelper;
56-
private ArrayList<View> mRecycledViews;
57+
private HashSet<View> mRecycledViews;
5758
private int mNumItemsInOneScreenful;
5859

5960
public RecentsVerticalScrollView(Context context, AttributeSet attrs) {
@@ -63,7 +64,7 @@ public RecentsVerticalScrollView(Context context, AttributeSet attrs) {
6364
mSwipeHelper = new SwipeHelper(SwipeHelper.X, this, densityScale, pagingTouchSlop);
6465

6566
mPerformanceHelper = RecentsScrollViewPerformanceHelper.create(context, attrs, this, true);
66-
mRecycledViews = new ArrayList<View>();
67+
mRecycledViews = new HashSet<View>();
6768
}
6869

6970
public void setMinSwipeAlpha(float minAlpha) {
@@ -93,19 +94,16 @@ private void update() {
9394
setLayoutTransition(null);
9495

9596
mLinearLayout.removeAllViews();
96-
for (int i = 0; i < mRecycledViews.size(); i++) {
97-
View child = mRecycledViews.get(i);
98-
if (child.getParent() != null) {
99-
throw new RuntimeException("Recycled child has parent");
100-
}
101-
}
97+
10298
// Once we can clear the data associated with individual item views,
10399
// we can get rid of the removeAllViews() and the code below will
104100
// recycle them.
101+
Iterator<View> recycledViews = mRecycledViews.iterator();
105102
for (int i = 0; i < mAdapter.getCount(); i++) {
106103
View old = null;
107-
if (mRecycledViews.size() != 0) {
108-
old = mRecycledViews.remove(mRecycledViews.size() - 1);
104+
if (recycledViews.hasNext()) {
105+
old = recycledViews.next();
106+
recycledViews.remove();
109107
old.setVisibility(VISIBLE);
110108
if (old.getParent() != null) {
111109
throw new RuntimeException("Recycled child has parent (i: " + i + ", recycled i: " + mRecycledViews.size());
@@ -150,9 +148,6 @@ public boolean onLongClick(View v) {
150148
thumbnailView.setClickable(true);
151149
thumbnailView.setOnClickListener(launchAppListener);
152150
thumbnailView.setOnLongClickListener(longClickListener);
153-
if (view.getParent() != null) {
154-
throw new RuntimeException("Recycled child has parent");
155-
}
156151

157152
// We don't want to dismiss recents if a user clicks on the app title
158153
// (we also don't want to launch the app either, though, because the
@@ -162,9 +157,6 @@ public boolean onLongClick(View v) {
162157
appTitle.setOnTouchListener(noOpListener);
163158
final View calloutLine = view.findViewById(R.id.recents_callout_line);
164159
calloutLine.setOnTouchListener(noOpListener);
165-
if (view.getParent() != null) {
166-
throw new RuntimeException("Recycled child has parent");
167-
}
168160

169161
mLinearLayout.addView(view);
170162
}
@@ -213,9 +205,6 @@ public void dismissChild(View v) {
213205
public void onChildDismissed(View v) {
214206
addToRecycledViews(v);
215207
mLinearLayout.removeView(v);
216-
if (v.getParent() != null) {
217-
throw new RuntimeException("Recycled child has parent");
218-
}
219208
mCallback.handleSwipe(v);
220209
// Restore the alpha/translation parameters to what they were before swiping
221210
// (for when these items are recycled)
@@ -389,15 +378,9 @@ public void onInvalidated() {
389378
mNumItemsInOneScreenful =
390379
(int) FloatMath.ceil(dm.heightPixels / (float) child.getMeasuredHeight());
391380
addToRecycledViews(child);
392-
if (child.getParent() != null) {
393-
throw new RuntimeException("First recycled child has parent");
394-
}
395381

396382
for (int i = 0; i < mNumItemsInOneScreenful - 1; i++) {
397383
addToRecycledViews(mAdapter.createView(mLinearLayout));
398-
if (mRecycledViews.get(mRecycledViews.size() - 1).getParent() != null) {
399-
throw new RuntimeException("Recycled child has parent");
400-
}
401384
}
402385
}
403386

0 commit comments

Comments
 (0)