Search in sources :

Example 61 with PositionMetadata

use of android.widget.ExpandableListConnector.PositionMetadata in project android_frameworks_base by crdroidandroid.

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);
}
Also used : PositionMetadata(android.widget.ExpandableListConnector.PositionMetadata)

Example 62 with PositionMetadata

use of android.widget.ExpandableListConnector.PositionMetadata in project android_frameworks_base by crdroidandroid.

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);
        final boolean isLayoutRtl = isLayoutRtl();
        final int width = getWidth();
        // 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;
            }
            if (isLayoutRtl) {
                final int temp = indicatorRect.left;
                indicatorRect.left = width - indicatorRect.right;
                indicatorRect.right = width - temp;
                indicatorRect.left -= mPaddingRight;
                indicatorRect.right -= mPaddingRight;
            } else {
                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);
    }
}
Also used : Rect(android.graphics.Rect) PositionMetadata(android.widget.ExpandableListConnector.PositionMetadata) Drawable(android.graphics.drawable.Drawable) View(android.view.View)

Example 63 with PositionMetadata

use of android.widget.ExpandableListConnector.PositionMetadata in project android_frameworks_base by crdroidandroid.

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;
}
Also used : PositionMetadata(android.widget.ExpandableListConnector.PositionMetadata)

Aggregations

PositionMetadata (android.widget.ExpandableListConnector.PositionMetadata)63 Drawable (android.graphics.drawable.Drawable)14 Rect (android.graphics.Rect)7 View (android.view.View)7