Search in sources :

Example 11 with PositionMetadata

use of android.widget.ExpandableListConnector.PositionMetadata in project XobotOS by xamarin.

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;
    pm.recycle();
    id = getChildOrGroupId(pos);
    long packedPosition = pos.getPackedPosition();
    pos.recycle();
    return new ExpandableListContextMenuInfo(view, packedPosition, id);
}
Also used : PositionMetadata(android.widget.ExpandableListConnector.PositionMetadata)

Example 12 with PositionMetadata

use of android.widget.ExpandableListConnector.PositionMetadata in project XobotOS by xamarin.

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

Example 13 with PositionMetadata

use of android.widget.ExpandableListConnector.PositionMetadata in project XobotOS by xamarin.

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

Example 14 with PositionMetadata

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

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 15 with PositionMetadata

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

the class ExpandableListView method setSelectedGroup.

/**
     * Sets the selection to the specified group.
     * @param groupPosition The position of the group that should be selected.
     */
public void setSelectedGroup(int groupPosition) {
    ExpandableListPosition elGroupPos = ExpandableListPosition.obtainGroupPosition(groupPosition);
    PositionMetadata pm = mConnector.getFlattenedPos(elGroupPos);
    elGroupPos.recycle();
    final int absoluteFlatPosition = getAbsoluteFlatPosition(pm.position.flatListPos);
    super.setSelection(absoluteFlatPosition);
    pm.recycle();
}
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