CompoundButton getVisibleViewBeforeChildAt(int index) { index--; while (index >= 0) { final CompoundButton previous = (CompoundButton) getChildAt(index); if (previous.getVisibility() != GONE) return previous; index--; } return null; }
void drawDividersVertical(Canvas canvas) { final int count = getChildCount(); for (int i = 0; i < count; i++) { final CompoundButton child = (CompoundButton) getChildAt(i); if (hasDividerBeforeChildAt(i)) { final LinearLayoutCompat.LayoutParams lp = (LinearLayoutCompat.LayoutParams) child.getLayoutParams(); final int top = child.getTop() - lp.topMargin - mDividerHeight; drawHorizontalDivider(canvas, top); } } }
void drawDividersHorizontal(Canvas canvas) { final int count = getChildCount(); for (int i = 0; i < count; i++) { final CompoundButton child = (CompoundButton) getChildAt(i); if (hasDividerBeforeChildAt(i)) { final LinearLayoutCompat.LayoutParams lp = (LinearLayoutCompat.LayoutParams) child.getLayoutParams(); final int left = child.getLeft() - lp.leftMargin - mDividerWidth; drawVerticalDivider(canvas, left); } } }
/** * Determines where to position dividers between children. Note: this is an 'illegal' override * of a hidden method. * * @param childIndex Index of child to check for preceding divider * @return true if there should be a divider before the child at childIndex */ protected boolean hasDividerBeforeChildAt(int childIndex) { final CompoundButton child = (CompoundButton) getChildAt(childIndex); if (child == null) return false; if (child.getVisibility() == GONE) return false; final CompoundButton previous = getVisibleViewBeforeChildAt(childIndex); if (previous == null) return false; // If both are checked, add a divider return child.isChecked() && previous.isChecked(); }