diff options
author | Michael Jurka <mikejurka@google.com> | 2012-06-06 10:05:46 -0700 |
---|---|---|
committer | Michael Jurka <mikejurka@google.com> | 2012-06-06 10:14:34 -0700 |
commit | d1a040c3e1dc30b26f4dfee8c9de2c802ac134b8 (patch) | |
tree | c0058367b652ad55e922625dce5d48284d324d9d /packages/SystemUI | |
parent | 72d6835c7cea35d0faf5f1584bf2c475fcbf93c8 (diff) | |
download | frameworks_base-d1a040c3e1dc30b26f4dfee8c9de2c802ac134b8.zip frameworks_base-d1a040c3e1dc30b26f4dfee8c9de2c802ac134b8.tar.gz frameworks_base-d1a040c3e1dc30b26f4dfee8c9de2c802ac134b8.tar.bz2 |
Fix bug 6499508
Using a HashSet for the recycled views, instead of an ArrayList, to ensure items are not double-added
Diffstat (limited to 'packages/SystemUI')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java | 28 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java | 38 |
2 files changed, 17 insertions, 49 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java index e1abb23..f85007e 100644 --- a/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java +++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java @@ -41,7 +41,8 @@ import com.android.systemui.R; import com.android.systemui.SwipeHelper; import com.android.systemui.recent.RecentsPanelView.TaskDescriptionAdapter; -import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; public class RecentsHorizontalScrollView extends HorizontalScrollView implements SwipeHelper.Callback, RecentsPanelView.RecentsScrollView { @@ -53,7 +54,7 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView protected int mLastScrollPosition; private SwipeHelper mSwipeHelper; private RecentsScrollViewPerformanceHelper mPerformanceHelper; - private ArrayList<View> mRecycledViews; + private HashSet<View> mRecycledViews; private int mNumItemsInOneScreenful; public RecentsHorizontalScrollView(Context context, AttributeSet attrs) { @@ -62,7 +63,7 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView float pagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop(); mSwipeHelper = new SwipeHelper(SwipeHelper.Y, this, densityScale, pagingTouchSlop); mPerformanceHelper = RecentsScrollViewPerformanceHelper.create(context, attrs, this, false); - mRecycledViews = new ArrayList<View>(); + mRecycledViews = new HashSet<View>(); } public void setMinSwipeAlpha(float minAlpha) { @@ -89,16 +90,12 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView setLayoutTransition(null); mLinearLayout.removeAllViews(); - for (int i = 0; i < mRecycledViews.size(); i++) { - View child = mRecycledViews.get(i); - if (child.getParent() != null) { - throw new RuntimeException("Recycled child has a parent"); - } - } + Iterator<View> recycledViews = mRecycledViews.iterator(); for (int i = 0; i < mAdapter.getCount(); i++) { View old = null; - if (mRecycledViews.size() != 0) { - old = mRecycledViews.remove(mRecycledViews.size() - 1); + if (recycledViews.hasNext()) { + old = recycledViews.next(); + recycledViews.remove(); old.setVisibility(VISIBLE); } @@ -195,9 +192,6 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView public void onChildDismissed(View v) { addToRecycledViews(v); mLinearLayout.removeView(v); - if (v.getParent() != null) { - throw new RuntimeException("Recycled child has parent"); - } mCallback.handleSwipe(v); // Restore the alpha/translation parameters to what they were before swiping // (for when these items are recycled) @@ -369,15 +363,9 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView mNumItemsInOneScreenful = (int) FloatMath.ceil(dm.widthPixels / (float) child.getMeasuredWidth()); addToRecycledViews(child); - if (child.getParent() != null) { - throw new RuntimeException("First recycled child has parent"); - } for (int i = 0; i < mNumItemsInOneScreenful - 1; i++) { addToRecycledViews(mAdapter.createView(mLinearLayout)); - if (mRecycledViews.get(mRecycledViews.size() - 1).getParent() != null) { - throw new RuntimeException("Recycled child has parent"); - } } } diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java index 33d2a75..ef21067 100644 --- a/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java +++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java @@ -41,7 +41,8 @@ import com.android.systemui.R; import com.android.systemui.SwipeHelper; import com.android.systemui.recent.RecentsPanelView.TaskDescriptionAdapter; -import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; public class RecentsVerticalScrollView extends ScrollView implements SwipeHelper.Callback, RecentsPanelView.RecentsScrollView { @@ -53,7 +54,7 @@ public class RecentsVerticalScrollView extends ScrollView protected int mLastScrollPosition; private SwipeHelper mSwipeHelper; private RecentsScrollViewPerformanceHelper mPerformanceHelper; - private ArrayList<View> mRecycledViews; + private HashSet<View> mRecycledViews; private int mNumItemsInOneScreenful; public RecentsVerticalScrollView(Context context, AttributeSet attrs) { @@ -63,7 +64,7 @@ public class RecentsVerticalScrollView extends ScrollView mSwipeHelper = new SwipeHelper(SwipeHelper.X, this, densityScale, pagingTouchSlop); mPerformanceHelper = RecentsScrollViewPerformanceHelper.create(context, attrs, this, true); - mRecycledViews = new ArrayList<View>(); + mRecycledViews = new HashSet<View>(); } public void setMinSwipeAlpha(float minAlpha) { @@ -90,26 +91,20 @@ public class RecentsVerticalScrollView extends ScrollView setLayoutTransition(null); mLinearLayout.removeAllViews(); - for (int i = 0; i < mRecycledViews.size(); i++) { - View child = mRecycledViews.get(i); - if (child.getParent() != null) { - throw new RuntimeException("Recycled child has parent"); - } - } + // Once we can clear the data associated with individual item views, // we can get rid of the removeAllViews() and the code below will // recycle them. + Iterator<View> recycledViews = mRecycledViews.iterator(); for (int i = 0; i < mAdapter.getCount(); i++) { View old = null; - if (mRecycledViews.size() != 0) { - old = mRecycledViews.remove(mRecycledViews.size() - 1); + if (recycledViews.hasNext()) { + old = recycledViews.next(); + recycledViews.remove(); old.setVisibility(VISIBLE); } final View view = mAdapter.getView(i, old, mLinearLayout); - if (view.getParent() != null) { - throw new RuntimeException("Recycled child has parent"); - } if (mPerformanceHelper != null) { mPerformanceHelper.addViewCallback(view); @@ -148,9 +143,6 @@ public class RecentsVerticalScrollView extends ScrollView thumbnailView.setClickable(true); thumbnailView.setOnClickListener(launchAppListener); thumbnailView.setOnLongClickListener(longClickListener); - if (view.getParent() != null) { - throw new RuntimeException("Recycled child has parent"); - } // We don't want to dismiss recents if a user clicks on the app title // (we also don't want to launch the app either, though, because the @@ -160,9 +152,6 @@ public class RecentsVerticalScrollView extends ScrollView appTitle.setOnTouchListener(noOpListener); final View calloutLine = view.findViewById(R.id.recents_callout_line); calloutLine.setOnTouchListener(noOpListener); - if (view.getParent() != null) { - throw new RuntimeException("Recycled child has parent"); - } mLinearLayout.addView(view); } @@ -211,9 +200,6 @@ public class RecentsVerticalScrollView extends ScrollView public void onChildDismissed(View v) { addToRecycledViews(v); mLinearLayout.removeView(v); - if (v.getParent() != null) { - throw new RuntimeException("Recycled child has parent"); - } mCallback.handleSwipe(v); // Restore the alpha/translation parameters to what they were before swiping // (for when these items are recycled) @@ -387,15 +373,9 @@ public class RecentsVerticalScrollView extends ScrollView mNumItemsInOneScreenful = (int) FloatMath.ceil(dm.heightPixels / (float) child.getMeasuredHeight()); addToRecycledViews(child); - if (child.getParent() != null) { - throw new RuntimeException("First recycled child has parent"); - } for (int i = 0; i < mNumItemsInOneScreenful - 1; i++) { addToRecycledViews(mAdapter.createView(mLinearLayout)); - if (mRecycledViews.get(mRecycledViews.size() - 1).getParent() != null) { - throw new RuntimeException("Recycled child has parent"); - } } } |