use of android.widget.ExpandableListConnector.PositionMetadata in project android_frameworks_base by ParanoidAndroid.
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 ParanoidAndroid.
the class ExpandableListView method drawDivider.
@Override
void drawDivider(Canvas canvas, Rect bounds, int childIndex) {
int flatListPosition = childIndex + mFirstPosition;
// all items, then the item below it has to be a group)
if (flatListPosition >= 0) {
final int adjustedPosition = getFlatPositionForConnector(flatListPosition);
PositionMetadata pos = mConnector.getUnflattenedPos(adjustedPosition);
// If this item is a child, or it is a non-empty group that is expanded
if ((pos.position.type == ExpandableListPosition.CHILD) || (pos.isExpanded() && pos.groupMetadata.lastChildFlPos != pos.groupMetadata.flPos)) {
// These are the cases where we draw the child divider
final Drawable divider = mChildDivider;
divider.setBounds(bounds);
divider.draw(canvas);
pos.recycle();
return;
}
pos.recycle();
}
// Otherwise draw the default divider
super.drawDivider(canvas, bounds, flatListPosition);
}
use of android.widget.ExpandableListConnector.PositionMetadata in project android_frameworks_base by ParanoidAndroid.
the class ExpandableListView method setSelectedChild.
/**
* Sets the selection to the specified child. If the child is in a collapsed
* group, the group will only be expanded and child subsequently selected if
* shouldExpandGroup is set to true, otherwise the method will return false.
*
* @param groupPosition The position of the group that contains the child.
* @param childPosition The position of the child within the group.
* @param shouldExpandGroup Whether the child's group should be expanded if
* it is collapsed.
* @return Whether the selection was successfully set on the child.
*/
public boolean setSelectedChild(int groupPosition, int childPosition, boolean shouldExpandGroup) {
ExpandableListPosition elChildPos = ExpandableListPosition.obtainChildPosition(groupPosition, childPosition);
PositionMetadata flatChildPos = mConnector.getFlattenedPos(elChildPos);
if (flatChildPos == null) {
// Shouldn't expand the group, so return false for we didn't set the selection
if (!shouldExpandGroup)
return false;
expandGroup(groupPosition);
flatChildPos = mConnector.getFlattenedPos(elChildPos);
// Sanity check
if (flatChildPos == null) {
throw new IllegalStateException("Could not find child");
}
}
int absoluteFlatPosition = getAbsoluteFlatPosition(flatChildPos.position.flatListPos);
super.setSelection(absoluteFlatPosition);
elChildPos.recycle();
flatChildPos.recycle();
return true;
}
use of android.widget.ExpandableListConnector.PositionMetadata in project XobotOS by xamarin.
the class ExpandableListView method dispatchDraw.
@Override
protected void dispatchDraw(Canvas canvas) {
// Draw children, etc.
super.dispatchDraw(canvas);
// If we have any indicators to draw, we do it here
if ((mChildIndicator == null) && (mGroupIndicator == null)) {
return;
}
int saveCount = 0;
final boolean clipToPadding = (mGroupFlags & CLIP_TO_PADDING_MASK) == CLIP_TO_PADDING_MASK;
if (clipToPadding) {
saveCount = canvas.save();
final int scrollX = mScrollX;
final int scrollY = mScrollY;
canvas.clipRect(scrollX + mPaddingLeft, scrollY + mPaddingTop, scrollX + mRight - mLeft - mPaddingRight, scrollY + mBottom - mTop - mPaddingBottom);
}
final int headerViewsCount = getHeaderViewsCount();
final int lastChildFlPos = mItemCount - getFooterViewsCount() - headerViewsCount - 1;
final int myB = mBottom;
PositionMetadata pos;
View item;
Drawable indicator;
int t, b;
// Start at a value that is neither child nor group
int lastItemType = ~(ExpandableListPosition.CHILD | ExpandableListPosition.GROUP);
final Rect indicatorRect = mIndicatorRect;
// The "child" mentioned in the following two lines is this
// View's child, not referring to an expandable list's
// notion of a child (as opposed to a group)
final int childCount = getChildCount();
for (int i = 0, childFlPos = mFirstPosition - headerViewsCount; i < childCount; i++, childFlPos++) {
if (childFlPos < 0) {
// This child is header
continue;
} else if (childFlPos > lastChildFlPos) {
// This child is footer, so are all subsequent children
break;
}
item = getChildAt(i);
t = item.getTop();
b = item.getBottom();
// This item isn't on the screen
if ((b < 0) || (t > myB))
continue;
// Get more expandable list-related info for this item
pos = mConnector.getUnflattenedPos(childFlPos);
// the left & right bounds
if (pos.position.type != lastItemType) {
if (pos.position.type == ExpandableListPosition.CHILD) {
indicatorRect.left = (mChildIndicatorLeft == CHILD_INDICATOR_INHERIT) ? mIndicatorLeft : mChildIndicatorLeft;
indicatorRect.right = (mChildIndicatorRight == CHILD_INDICATOR_INHERIT) ? mIndicatorRight : mChildIndicatorRight;
} else {
indicatorRect.left = mIndicatorLeft;
indicatorRect.right = mIndicatorRight;
}
indicatorRect.left += mPaddingLeft;
indicatorRect.right += mPaddingLeft;
lastItemType = pos.position.type;
}
if (indicatorRect.left != indicatorRect.right) {
// Use item's full height + the divider height
if (mStackFromBottom) {
// See ListView#dispatchDraw
// - mDividerHeight;
indicatorRect.top = t;
indicatorRect.bottom = b;
} else {
indicatorRect.top = t;
// + mDividerHeight;
indicatorRect.bottom = b;
}
// Get the indicator (with its state set to the item's state)
indicator = getIndicator(pos);
if (indicator != null) {
// Draw the indicator
indicator.setBounds(indicatorRect);
indicator.draw(canvas);
}
}
pos.recycle();
}
if (clipToPadding) {
canvas.restoreToCount(saveCount);
}
}
use of android.widget.ExpandableListConnector.PositionMetadata in project XobotOS by xamarin.
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) {
PositionMetadata pm = mConnector.getFlattenedPos(ExpandableListPosition.obtain(ExpandableListPosition.GROUP, groupPos, -1, -1));
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;
}
Aggregations