| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.widget; |
| 18 |
|
| 19 |
import java.util.ArrayList; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
class ExpandableListPosition { |
| 29 |
|
| 30 |
private static final int MAX_POOL_SIZE = 5; |
| 31 |
private static ArrayList<ExpandableListPosition> sPool = |
| 32 |
new ArrayList<ExpandableListPosition>(MAX_POOL_SIZE); |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public final static int CHILD = 1; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public final static int GROUP = 2; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public int groupPos; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public int childPos; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
int flatListPos; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public int type; |
| 65 |
|
| 66 |
private void resetState() { |
| 67 |
groupPos = 0; |
| 68 |
childPos = 0; |
| 69 |
flatListPos = 0; |
| 70 |
type = 0; |
| 71 |
} |
| 72 |
|
| 73 |
private ExpandableListPosition() { |
| 74 |
} |
| 75 |
|
| 76 |
long getPackedPosition() { |
| 77 |
if (type == CHILD) return ExpandableListView.getPackedPositionForChild(groupPos, childPos); |
| 78 |
else return ExpandableListView.getPackedPositionForGroup(groupPos); |
| 79 |
} |
| 80 |
|
| 81 |
static ExpandableListPosition obtainGroupPosition(int groupPosition) { |
| 82 |
return obtain(GROUP, groupPosition, 0, 0); |
| 83 |
} |
| 84 |
|
| 85 |
static ExpandableListPosition obtainChildPosition(int groupPosition, int childPosition) { |
| 86 |
return obtain(CHILD, groupPosition, childPosition, 0); |
| 87 |
} |
| 88 |
|
| 89 |
static ExpandableListPosition obtainPosition(long packedPosition) { |
| 90 |
if (packedPosition == ExpandableListView.PACKED_POSITION_VALUE_NULL) { |
| 91 |
return null; |
| 92 |
} |
| 93 |
|
| 94 |
ExpandableListPosition elp = getRecycledOrCreate(); |
| 95 |
elp.groupPos = ExpandableListView.getPackedPositionGroup(packedPosition); |
| 96 |
if (ExpandableListView.getPackedPositionType(packedPosition) == |
| 97 |
ExpandableListView.PACKED_POSITION_TYPE_CHILD) { |
| 98 |
elp.type = CHILD; |
| 99 |
elp.childPos = ExpandableListView.getPackedPositionChild(packedPosition); |
| 100 |
} else { |
| 101 |
elp.type = GROUP; |
| 102 |
} |
| 103 |
return elp; |
| 104 |
} |
| 105 |
|
| 106 |
static ExpandableListPosition obtain(int type, int groupPos, int childPos, int flatListPos) { |
| 107 |
ExpandableListPosition elp = getRecycledOrCreate(); |
| 108 |
elp.type = type; |
| 109 |
elp.groupPos = groupPos; |
| 110 |
elp.childPos = childPos; |
| 111 |
elp.flatListPos = flatListPos; |
| 112 |
return elp; |
| 113 |
} |
| 114 |
|
| 115 |
private static ExpandableListPosition getRecycledOrCreate() { |
| 116 |
ExpandableListPosition elp; |
| 117 |
synchronized (sPool) { |
| 118 |
if (sPool.size() > 0) { |
| 119 |
elp = sPool.remove(0); |
| 120 |
} else { |
| 121 |
return new ExpandableListPosition(); |
| 122 |
} |
| 123 |
} |
| 124 |
elp.resetState(); |
| 125 |
return elp; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public void recycle() { |
| 133 |
synchronized (sPool) { |
| 134 |
if (sPool.size() < MAX_POOL_SIZE) { |
| 135 |
sPool.add(this); |
| 136 |
} |
| 137 |
} |
| 138 |
} |
| 139 |
} |