diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:43 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:43 -0800 |
commit | f013e1afd1e68af5e3b868c26a653bbfb39538f8 (patch) | |
tree | 7ad6c8fd9c7b55f4b4017171dec1cb760bbd26bf /core/java/android/widget/ExpandableListPosition.java | |
parent | e70cfafe580c6f2994c4827cd8a534aabf3eb05c (diff) | |
download | frameworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.zip frameworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.tar.gz frameworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.tar.bz2 |
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'core/java/android/widget/ExpandableListPosition.java')
-rw-r--r-- | core/java/android/widget/ExpandableListPosition.java | 77 |
1 files changed, 55 insertions, 22 deletions
diff --git a/core/java/android/widget/ExpandableListPosition.java b/core/java/android/widget/ExpandableListPosition.java index 71e970c..e8d6113 100644 --- a/core/java/android/widget/ExpandableListPosition.java +++ b/core/java/android/widget/ExpandableListPosition.java @@ -16,6 +16,8 @@ package android.widget; +import java.util.ArrayList; + /** * ExpandableListPosition can refer to either a group's position or a child's * position. Referring to a child's position requires both a group position (the @@ -24,6 +26,11 @@ package android.widget; * {@link #obtainGroupPosition(int)}. */ class ExpandableListPosition { + + private static final int MAX_POOL_SIZE = 5; + private static ArrayList<ExpandableListPosition> sPool = + new ArrayList<ExpandableListPosition>(MAX_POOL_SIZE); + /** * This data type represents a child position */ @@ -56,21 +63,14 @@ class ExpandableListPosition { */ public int type; - ExpandableListPosition(int type, int groupPos, int childPos, int flatListPos) { - this.type = type; - this.flatListPos = flatListPos; - this.groupPos = groupPos; - this.childPos = childPos; + private void resetState() { + groupPos = 0; + childPos = 0; + flatListPos = 0; + type = 0; } - - /** - * Used internally by the {@link #obtainChildPosition} and - * {@link #obtainGroupPosition} methods to construct a new object. - */ - private ExpandableListPosition(int type, int groupPos, int childPos) { - this.type = type; - this.groupPos = groupPos; - this.childPos = childPos; + + private ExpandableListPosition() { } long getPackedPosition() { @@ -79,11 +79,11 @@ class ExpandableListPosition { } static ExpandableListPosition obtainGroupPosition(int groupPosition) { - return new ExpandableListPosition(GROUP, groupPosition, 0); + return obtain(GROUP, groupPosition, 0, 0); } static ExpandableListPosition obtainChildPosition(int groupPosition, int childPosition) { - return new ExpandableListPosition(CHILD, groupPosition, childPosition); + return obtain(CHILD, groupPosition, childPosition, 0); } static ExpandableListPosition obtainPosition(long packedPosition) { @@ -91,12 +91,45 @@ class ExpandableListPosition { return null; } - final int type = ExpandableListView.getPackedPositionType(packedPosition) == - ExpandableListView.PACKED_POSITION_TYPE_CHILD ? CHILD : GROUP; - - return new ExpandableListPosition(type, ExpandableListView - .getPackedPositionGroup(packedPosition), ExpandableListView - .getPackedPositionChild(packedPosition)); + ExpandableListPosition elp = getRecycledOrCreate(); + elp.groupPos = ExpandableListView.getPackedPositionGroup(packedPosition); + if (ExpandableListView.getPackedPositionType(packedPosition) == + ExpandableListView.PACKED_POSITION_TYPE_CHILD) { + elp.type = CHILD; + elp.childPos = ExpandableListView.getPackedPositionChild(packedPosition); + } else { + elp.type = GROUP; + } + return elp; + } + + static ExpandableListPosition obtain(int type, int groupPos, int childPos, int flatListPos) { + ExpandableListPosition elp = getRecycledOrCreate(); + elp.type = type; + elp.groupPos = groupPos; + elp.childPos = childPos; + elp.flatListPos = flatListPos; + return elp; + } + + private static ExpandableListPosition getRecycledOrCreate() { + ExpandableListPosition elp; + synchronized (sPool) { + if (sPool.size() > 0) { + elp = sPool.remove(0); + } else { + return new ExpandableListPosition(); + } + } + elp.resetState(); + return elp; } + public void recycle() { + synchronized (sPool) { + if (sPool.size() < MAX_POOL_SIZE) { + sPool.add(this); + } + } + } } |