Cleanup PositionMetadata recycles

Bug: 6360817

Change-Id: I428014be20447d074d378901a289e090b4e4e777
This commit is contained in:
John Reck
2012-04-18 10:41:19 -07:00
parent 3cdfcdc1c4
commit 820b236adc
3 changed files with 33 additions and 16 deletions

View File

@@ -372,7 +372,8 @@ class ExpandableListConnector extends BaseAdapter implements Filterable {
@Override
public boolean isEnabled(int flatListPos) {
final ExpandableListPosition pos = getUnflattenedPos(flatListPos).position;
final PositionMetadata metadata = getUnflattenedPos(flatListPos);
final ExpandableListPosition pos = metadata.position;
boolean retValue;
if (pos.type == ExpandableListPosition.CHILD) {
@@ -382,7 +383,7 @@ class ExpandableListConnector extends BaseAdapter implements Filterable {
retValue = true;
}
pos.recycle();
metadata.recycle();
return retValue;
}
@@ -461,7 +462,8 @@ class ExpandableListConnector extends BaseAdapter implements Filterable {
@Override
public int getItemViewType(int flatListPos) {
final ExpandableListPosition pos = getUnflattenedPos(flatListPos).position;
final PositionMetadata metadata = getUnflattenedPos(flatListPos);
final ExpandableListPosition pos = metadata.position;
int retValue;
if (mExpandableListAdapter instanceof HeterogeneousExpandableList) {
@@ -481,7 +483,7 @@ class ExpandableListConnector extends BaseAdapter implements Filterable {
}
}
pos.recycle();
metadata.recycle();
return retValue;
}
@@ -590,8 +592,10 @@ class ExpandableListConnector extends BaseAdapter implements Filterable {
* @param groupPos position of the group to collapse
*/
boolean collapseGroup(int groupPos) {
PositionMetadata pm = getFlattenedPos(ExpandableListPosition.obtain(
ExpandableListPosition.GROUP, groupPos, -1, -1));
ExpandableListPosition elGroupPos = ExpandableListPosition.obtain(
ExpandableListPosition.GROUP, groupPos, -1, -1);
PositionMetadata pm = getFlattenedPos(elGroupPos);
elGroupPos.recycle();
if (pm == null) return false;
boolean retValue = collapseGroup(pm);
@@ -631,8 +635,10 @@ class ExpandableListConnector extends BaseAdapter implements Filterable {
* @param groupPos the group to be expanded
*/
boolean expandGroup(int groupPos) {
PositionMetadata pm = getFlattenedPos(ExpandableListPosition.obtain(
ExpandableListPosition.GROUP, groupPos, -1, -1));
ExpandableListPosition elGroupPos = ExpandableListPosition.obtain(
ExpandableListPosition.GROUP, groupPos, -1, -1);
PositionMetadata pm = getFlattenedPos(elGroupPos);
elGroupPos.recycle();
boolean retValue = expandGroup(pm);
pm.recycle();
return retValue;
@@ -971,7 +977,10 @@ class ExpandableListConnector extends BaseAdapter implements Filterable {
public int groupInsertIndex;
private void resetState() {
position = null;
if (position != null) {
position.recycle();
position = null;
}
groupMetadata = null;
groupInsertIndex = 0;
}
@@ -1005,6 +1014,7 @@ class ExpandableListConnector extends BaseAdapter implements Filterable {
}
public void recycle() {
resetState();
synchronized (sPool) {
if (sPool.size() < MAX_POOL_SIZE) {
sPool.add(this);

View File

@@ -125,6 +125,10 @@ class ExpandableListPosition {
return elp;
}
/**
* Do not call this unless you obtained this via ExpandableListPosition.obtain().
* PositionMetadata will handle recycling its own children.
*/
public void recycle() {
synchronized (sPool) {
if (sPool.size() < MAX_POOL_SIZE) {

View File

@@ -326,7 +326,6 @@ public class ExpandableListView extends ListView {
indicator.draw(canvas);
}
}
pos.recycle();
}
@@ -613,8 +612,10 @@ public class ExpandableListView extends ListView {
* was already expanded, this will return false)
*/
public boolean expandGroup(int groupPos, boolean animate) {
PositionMetadata pm = mConnector.getFlattenedPos(ExpandableListPosition.obtain(
ExpandableListPosition.GROUP, groupPos, -1, -1));
ExpandableListPosition elGroupPos = ExpandableListPosition.obtain(
ExpandableListPosition.GROUP, groupPos, -1, -1);
PositionMetadata pm = mConnector.getFlattenedPos(elGroupPos);
elGroupPos.recycle();
boolean retValue = mConnector.expandGroup(pm);
if (mOnGroupExpandListener != null) {
@@ -776,8 +777,10 @@ public class ExpandableListView extends ListView {
* @return The flat list position for the given child or group.
*/
public int getFlatListPosition(long packedPosition) {
PositionMetadata pm = mConnector.getFlattenedPos(ExpandableListPosition
.obtainPosition(packedPosition));
ExpandableListPosition elPackedPos = ExpandableListPosition
.obtainPosition(packedPosition);
PositionMetadata pm = mConnector.getFlattenedPos(elPackedPos);
elPackedPos.recycle();
final int flatListPosition = pm.position.flatListPos;
pm.recycle();
return getAbsoluteFlatPosition(flatListPosition);
@@ -988,11 +991,11 @@ public class ExpandableListView extends ListView {
final int adjustedPosition = getFlatPositionForConnector(flatListPosition);
PositionMetadata pm = mConnector.getUnflattenedPos(adjustedPosition);
ExpandableListPosition pos = pm.position;
pm.recycle();
id = getChildOrGroupId(pos);
long packedPosition = pos.getPackedPosition();
pos.recycle();
pm.recycle();
return new ExpandableListContextMenuInfo(view, packedPosition, id);
}