/** * Converts a child position to a flat list position. * * @param packedPosition The child positions to be converted in it's * packed position representation. * @return The flat list position for the given child */ public int getFlattenedChildIndex(long packedPosition) { ExpandableListPosition listPosition = ExpandableListPosition.obtainPosition(packedPosition); return getFlattenedChildIndex(listPosition); }
/** * @param flatPos the flattened position of an item in the list * @return true if {@code group} is expanded, false if it is collapsed */ public boolean isGroupExpanded(int flatPos) { ExpandableListPosition listPosition = expandableList.getUnflattenedPosition(flatPos); return expandableList.expandedGroupIndexes[listPosition.groupPos]; }
/** * @param groupIndex The index of a group within {@link #groups} * @return The flat list position for the first child in a group */ public int getFlattenedFirstChildIndex(int groupIndex) { return getFlattenedGroupIndex(groupIndex) + 1; }
public boolean toggleGroup(ExpandableGroup group) { ExpandableListPosition listPos = expandableList.getUnflattenedPosition(expandableList.getFlattenedGroupIndex(group)); boolean expanded = expandableList.expandedGroupIndexes[listPos.groupPos]; if (expanded) { collapseGroup(listPos); } else { expandGroup(listPos); } return expanded; }
/** * Collapse a group * * @param listPosition position of the group to collapse */ private void collapseGroup(ExpandableListPosition listPosition) { expandableList.expandedGroupIndexes[listPosition.groupPos] = false; if (listener != null) { listener.onGroupCollapsed(expandableList.getFlattenedGroupIndex(listPosition) + 1, expandableList.groups.get(listPosition.groupPos).getItemCount()); } }
/** * @param listPosition An {@link ExpandableListPosition} representing either a child or group * @return the total number of children within the group associated with the @param listPosition */ public int getExpandableGroupItemCount(ExpandableListPosition listPosition) { return groups.get(listPosition.groupPos).getItemCount(); }
static ExpandableListPosition obtainGroupPosition(int groupPosition) { return obtain(GROUP, groupPosition, 0, 0); }
/** * @return the number of group and child objects currently expanded * @see ExpandableList#getVisibleItemCount() */ @Override public int getItemCount() { return expandableList.getVisibleItemCount(); }
@Override public ExpandableGroup createFromParcel(Parcel in) { return new ExpandableGroup(in); }
/** * @param groupIndex representing the index of a group within {@link #groups} * @return the index of a group within the {@link #getVisibleItemCount()} */ public int getFlattenedGroupIndex(int groupIndex) { int runningTotal = 0; for (int i = 0; i < groupIndex; i++) { runningTotal += numberOfVisibleItemsInGroup(i); } return runningTotal; }
public static ExpandableListPosition obtain(int type, int groupPos, int childPos, int flatListPos) { ExpandableListPosition elp = getRecycledOrCreate(); elp.type = type; elp.groupPos = groupPos; elp.childPos = childPos; elp.flatListPos = flatListPos; return elp; }
@Override public void writeToParcel(Parcel dest, int flags) { super.writeToParcel(dest, flags); dest.writeBooleanArray(selectedChildren); }
/** * Gets the view type of the item at the given position. * * @param position The flat position in the list to get the view type of * @return {@value ExpandableListPosition#CHILD} or {@value ExpandableListPosition#GROUP} * @throws RuntimeException if the item at the given position in the list is not found */ @Override public int getItemViewType(int position) { return expandableList.getUnflattenedPosition(position).type; }
/** * Expand a group * * @param listPosition the group to be expanded */ private void expandGroup(ExpandableListPosition listPosition) { expandableList.expandedGroupIndexes[listPosition.groupPos] = true; if (listener != null) { listener.onGroupExpanded(expandableList.getFlattenedGroupIndex(listPosition) + 1, expandableList.groups.get(listPosition.groupPos).getItemCount()); } }
static ExpandableListPosition obtainChildPosition(int groupPosition, int childPosition) { return obtain(CHILD, groupPosition, childPosition, 0); }
/** * @param listPosition representing either a child or a group * @return the index of a group within the {@link #getVisibleItemCount()} */ public int getFlattenedGroupIndex(ExpandableListPosition listPosition) { int groupIndex = listPosition.groupPos; int runningTotal = 0; for (int i = 0; i < groupIndex; i++) { runningTotal += numberOfVisibleItemsInGroup(i); } return runningTotal; }
/** * @param listPosition The child positions to be converted in it's * {@link ExpandableListPosition} representation. * @return The flat list position for the first child in a group */ public int getFlattenedFirstChildIndex(ExpandableListPosition listPosition) { return getFlattenedGroupIndex(listPosition) + 1; }
/** * Converts the details of a child's position to a flat list position. * * @param groupIndex The index of a group within {@link #groups} * @param childIndex the index of a child within it's {@link ExpandableGroup} * @return The flat list position for the given child */ public int getFlattenedChildIndex(int groupIndex, int childIndex) { int runningTotal = 0; for (int i = 0; i < groupIndex; i++) { runningTotal += numberOfVisibleItemsInGroup(i); } return runningTotal + childIndex + 1; }
/** * Converts a child position to a flat list position. * * @param listPosition The child positions to be converted in it's * {@link ExpandableListPosition} representation. * @return The flat list position for the given child */ public int getFlattenedChildIndex(ExpandableListPosition listPosition) { int groupIndex = listPosition.groupPos; int childIndex = listPosition.childPos; int runningTotal = 0; for (int i = 0; i < groupIndex; i++) { runningTotal += numberOfVisibleItemsInGroup(i); } return runningTotal + childIndex + 1; }
/** * @return the total number visible rows */ public int getVisibleItemCount() { int count = 0; for (int i = 0; i < groups.size(); i++) { count += numberOfVisibleItemsInGroup(i); } return count; }