use of android.widget.ExpandableListConnector.PositionMetadata in project android_frameworks_base by DirtyUnicorns.
the class ExpandableListView method getExpandableListPosition.
/**
* Converts a flat list position (the raw position of an item (child or group)
* in the list) to a group and/or child position (represented in a
* packed position). This is useful in situations where the caller needs to
* use the underlying {@link ListView}'s methods. Use
* {@link ExpandableListView#getPackedPositionType} ,
* {@link ExpandableListView#getPackedPositionChild},
* {@link ExpandableListView#getPackedPositionGroup} to unpack.
*
* @param flatListPosition The flat list position to be converted.
* @return The group and/or child position for the given flat list position
* in packed position representation. #PACKED_POSITION_VALUE_NULL if
* the position corresponds to a header or a footer item.
*/
public long getExpandableListPosition(int flatListPosition) {
if (isHeaderOrFooterPosition(flatListPosition)) {
return PACKED_POSITION_VALUE_NULL;
}
final int adjustedPosition = getFlatPositionForConnector(flatListPosition);
PositionMetadata pm = mConnector.getUnflattenedPos(adjustedPosition);
long packedPos = pm.position.getPackedPosition();
pm.recycle();
return packedPos;
}
use of android.widget.ExpandableListConnector.PositionMetadata in project android_frameworks_base by DirtyUnicorns.
the class ExpandableListView method expandGroup.
/**
* Expand a group in the grouped list view
*
* @param groupPos the group to be expanded
* @param animate true if the expanding group should be animated in
* @return True if the group was expanded, false otherwise (if the group
* was already expanded, this will return false)
*/
public boolean expandGroup(int groupPos, boolean animate) {
ExpandableListPosition elGroupPos = ExpandableListPosition.obtain(ExpandableListPosition.GROUP, groupPos, -1, -1);
PositionMetadata pm = mConnector.getFlattenedPos(elGroupPos);
elGroupPos.recycle();
boolean retValue = mConnector.expandGroup(pm);
if (mOnGroupExpandListener != null) {
mOnGroupExpandListener.onGroupExpand(groupPos);
}
if (animate) {
final int groupFlatPos = pm.position.flatListPos;
final int shiftedGroupPosition = groupFlatPos + getHeaderViewsCount();
smoothScrollToPosition(shiftedGroupPosition + mAdapter.getChildrenCount(groupPos), shiftedGroupPosition);
}
pm.recycle();
return retValue;
}
use of android.widget.ExpandableListConnector.PositionMetadata in project android_frameworks_base by DirtyUnicorns.
the class ExpandableListView method getFlatListPosition.
/**
* Converts a group and/or child position to a flat list position. This is
* useful in situations where the caller needs to use the underlying
* {@link ListView}'s methods.
*
* @param packedPosition The group and/or child positions to be converted in
* packed position representation. Use
* {@link #getPackedPositionForChild(int, int)} or
* {@link #getPackedPositionForGroup(int)}.
* @return The flat list position for the given child or group.
*/
public int getFlatListPosition(long packedPosition) {
ExpandableListPosition elPackedPos = ExpandableListPosition.obtainPosition(packedPosition);
PositionMetadata pm = mConnector.getFlattenedPos(elPackedPos);
elPackedPos.recycle();
final int flatListPosition = pm.position.flatListPos;
pm.recycle();
return getAbsoluteFlatPosition(flatListPosition);
}
use of android.widget.ExpandableListConnector.PositionMetadata in project platform_frameworks_base by android.
the class ExpandableListView method handleItemClick.
/**
* This will either expand/collapse groups (if a group was clicked) or pass
* on the click to the proper child (if a child was clicked)
*
* @param position The flat list position. This has already been factored to
* remove the header/footer.
* @param id The ListAdapter ID, not the group or child ID.
*/
boolean handleItemClick(View v, int position, long id) {
final PositionMetadata posMetadata = mConnector.getUnflattenedPos(position);
id = getChildOrGroupId(posMetadata.position);
boolean returnValue;
if (posMetadata.position.type == ExpandableListPosition.GROUP) {
/* It's a group click, so pass on event */
if (mOnGroupClickListener != null) {
if (mOnGroupClickListener.onGroupClick(this, v, posMetadata.position.groupPos, id)) {
posMetadata.recycle();
return true;
}
}
if (posMetadata.isExpanded()) {
/* Collapse it */
mConnector.collapseGroup(posMetadata);
playSoundEffect(SoundEffectConstants.CLICK);
if (mOnGroupCollapseListener != null) {
mOnGroupCollapseListener.onGroupCollapse(posMetadata.position.groupPos);
}
} else {
/* Expand it */
mConnector.expandGroup(posMetadata);
playSoundEffect(SoundEffectConstants.CLICK);
if (mOnGroupExpandListener != null) {
mOnGroupExpandListener.onGroupExpand(posMetadata.position.groupPos);
}
final int groupPos = posMetadata.position.groupPos;
final int groupFlatPos = posMetadata.position.flatListPos;
final int shiftedGroupPosition = groupFlatPos + getHeaderViewsCount();
smoothScrollToPosition(shiftedGroupPosition + mAdapter.getChildrenCount(groupPos), shiftedGroupPosition);
}
returnValue = true;
} else {
/* It's a child, so pass on event */
if (mOnChildClickListener != null) {
playSoundEffect(SoundEffectConstants.CLICK);
return mOnChildClickListener.onChildClick(this, v, posMetadata.position.groupPos, posMetadata.position.childPos, id);
}
returnValue = false;
}
posMetadata.recycle();
return returnValue;
}
use of android.widget.ExpandableListConnector.PositionMetadata in project android_frameworks_base by ParanoidAndroid.
the class ExpandableListView method createContextMenuInfo.
@Override
ContextMenuInfo createContextMenuInfo(View view, int flatListPosition, long id) {
if (isHeaderOrFooterPosition(flatListPosition)) {
// Return normal info for header/footer view context menus
return new AdapterContextMenuInfo(view, flatListPosition, id);
}
final int adjustedPosition = getFlatPositionForConnector(flatListPosition);
PositionMetadata pm = mConnector.getUnflattenedPos(adjustedPosition);
ExpandableListPosition pos = pm.position;
id = getChildOrGroupId(pos);
long packedPosition = pos.getPackedPosition();
pm.recycle();
return new ExpandableListContextMenuInfo(view, packedPosition, id);
}
Aggregations