/** * Get the value as int. * * @param range the size that percent values are calculated from. * @return the resulting value rounded to the nearest integer. */ public int getValueAsInt(final float range) { if (isPercent()) { return Math.round((range / MAX_PERCENT) * value); } else if (isPixel()) { return Math.round (value); } else { return -1; } }
/** * Get the value as a float. WARNING: DO NOT CAST THE RETURN VALUE TO AN INTEGER - use {@link #getValueAsInt(float)} * or you will have off-by-one errors! * * @param range the size that percent values are calculated from. * @return the resulting value as a float. */ public float getValue(final float range) { if (isPercent()) { return (range / MAX_PERCENT) * value; } else if (isPixel()) { return value; } else { return -1; } }
@Nonnull private List<LayoutPart> getLayoutChildrenWithIndependentWidth() { if (children == null) { return Collections.emptyList(); } final int childrenCount = children.size(); List<LayoutPart> layoutPartChild = new ArrayList<LayoutPart>(childrenCount); for (int i = 0; i < childrenCount; i++) { Element e = children.get(i); SizeValue childWidth = e.getConstraintWidth(); if (childWidth.isPixel() && childWidth.isIndependentFromParent()) { layoutPartChild.add(e.layoutPart); } } return layoutPartChild; }
@Nonnull private List<LayoutPart> getLayoutChildrenWithIndependentHeight() { if (children == null) { return Collections.emptyList(); } final int childrenCount = children.size(); List<LayoutPart> layoutPartChild = new ArrayList<LayoutPart>(childrenCount); for (int i = 0; i < childrenCount; i++) { Element e = children.get(i); SizeValue childHeight = e.getConstraintHeight(); if (childHeight.isPixel() && childHeight.isIndependentFromParent()) { layoutPartChild.add(e.layoutPart); } } return layoutPartChild; }