Class OverView
//返回一个ExpandableListPosition,如果池中有对象则返回池中对象并且移除该对象(将被初始化),如果没有则新new一个对象返回 private static ExpandableListPosition getRecycledOrCreate() { ExpandableListPosition elp; synchronized (sPool) { if (sPool.size() > 0) { elp = sPool.remove(0); } else { return new ExpandableListPosition(); } } elp.resetState(); return elp; }//增加一个ExpandableListPosition对象到池中
ExpandbaleListPosition类可以指向group的位置或则child的位置。可通过obtainChildPosition(int,int)和obtainGroupPosition(int)获得实例
/***根据type返回groupPosition或则childPosition的格式为64位的数据**/long getPackedPosition() { if (type == CHILD) return ExpandableListView.getPackedPositionForChild(groupPos, childPos); else return ExpandableListView.getPackedPositionForGroup(groupPos); }//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 void resetState() {
groupPos = 0;
childPos = 0;
flatListPos = 0;
type = 0;
}//返回一个ExpandableListPosition,如果池中有对象则返回池中对象并且移除该对象(将被初始化),如果没有则新new一个对象返回 private static ExpandableListPosition getRecycledOrCreate() { ExpandableListPosition elp; synchronized (sPool) { if (sPool.size() > 0) { elp = sPool.remove(0); } else { return new ExpandableListPosition(); } } elp.resetState(); return elp; }//增加一个ExpandableListPosition对象到池中
public void recycle() {
synchronized (sPool) {
if (sPool.size() < MAX_POOL_SIZE) {
sPool.add(this);
}
}
}
//获得一个ExpandableListPosition对象
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;
}
//获得一个group类型的ExpandableListPosition对象static ExpandableListPosition obtainGroupPosition(int groupPosition) {
return obtain(GROUP, groupPosition, 0, 0);
}
//获得一个child类型的ExpandableListPosition对象
static ExpandableListPosition obtainChildPosition(int groupPosition, int childPosition) { return obtain(CHILD, groupPosition, childPosition, 0); }
//根据位置的封装数据得到位置的ExpandbaleListPostion static ExpandableListPosition obtainPosition(long packedPosition) { if (packedPosition == ExpandableListView.PACKED_POSITION_VALUE_NULL) { return null; } 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; }