4141import com .android .systemui .SwipeHelper ;
4242import com .android .systemui .recent .RecentsPanelView .TaskDescriptionAdapter ;
4343
44- import java .util .ArrayList ;
44+ import java .util .HashSet ;
45+ import java .util .Iterator ;
4546
4647public 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