use of org.apmem.tools.layouts.logic.ViewDefinition in project android-flowlayout by ApmeM.
the class FlowLayout method applyPositionsToViews.
private void applyPositionsToViews(LineDefinition line) {
final List<ViewDefinition> childViews = line.getViews();
final int childCount = childViews.size();
for (int i = 0; i < childCount; i++) {
final ViewDefinition child = childViews.get(i);
final View view = child.getView();
view.measure(MeasureSpec.makeMeasureSpec(child.getWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getHeight(), MeasureSpec.EXACTLY));
}
}
use of org.apmem.tools.layouts.logic.ViewDefinition in project android-flowlayout by ApmeM.
the class FlowLayout method onMeasure.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int count = this.getChildCount();
views.clear();
lines.clear();
for (int i = 0; i < count; i++) {
final View child = this.getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
child.measure(getChildMeasureSpec(widthMeasureSpec, this.getPaddingLeft() + this.getPaddingRight(), lp.width), getChildMeasureSpec(heightMeasureSpec, this.getPaddingTop() + this.getPaddingBottom(), lp.height));
ViewDefinition view = new ViewDefinition(this.config, child);
view.setWidth(child.getMeasuredWidth());
view.setHeight(child.getMeasuredHeight());
view.setNewLine(lp.isNewLine());
view.setGravity(lp.getGravity());
view.setWeight(lp.getWeight());
view.setMargins(lp.leftMargin, lp.topMargin, lp.rightMargin, lp.bottomMargin);
views.add(view);
}
this.config.setMaxWidth(MeasureSpec.getSize(widthMeasureSpec) - this.getPaddingRight() - this.getPaddingLeft());
this.config.setMaxHeight(MeasureSpec.getSize(heightMeasureSpec) - this.getPaddingTop() - this.getPaddingBottom());
this.config.setWidthMode(MeasureSpec.getMode(widthMeasureSpec));
this.config.setHeightMode(MeasureSpec.getMode(heightMeasureSpec));
this.config.setCheckCanFit(this.config.getLengthMode() != View.MeasureSpec.UNSPECIFIED);
CommonLogic.fillLines(views, lines, config);
CommonLogic.calculateLinesAndChildPosition(lines);
int contentLength = 0;
final int linesCount = lines.size();
for (int i = 0; i < linesCount; i++) {
LineDefinition l = lines.get(i);
contentLength = Math.max(contentLength, l.getLineLength());
}
LineDefinition currentLine = lines.get(lines.size() - 1);
int contentThickness = currentLine.getLineStartThickness() + currentLine.getLineThickness();
int realControlLength = CommonLogic.findSize(this.config.getLengthMode(), this.config.getMaxLength(), contentLength);
int realControlThickness = CommonLogic.findSize(this.config.getThicknessMode(), this.config.getMaxThickness(), contentThickness);
CommonLogic.applyGravityToLines(lines, realControlLength, realControlThickness, config);
for (int i = 0; i < linesCount; i++) {
LineDefinition line = lines.get(i);
applyPositionsToViews(line);
}
/* need to take padding into account */
int totalControlWidth = this.getPaddingLeft() + this.getPaddingRight();
int totalControlHeight = this.getPaddingBottom() + this.getPaddingTop();
if (this.config.getOrientation() == CommonLogic.HORIZONTAL) {
totalControlWidth += contentLength;
totalControlHeight += contentThickness;
} else {
totalControlWidth += contentThickness;
totalControlHeight += contentLength;
}
this.setMeasuredDimension(resolveSize(totalControlWidth, widthMeasureSpec), resolveSize(totalControlHeight, heightMeasureSpec));
}
use of org.apmem.tools.layouts.logic.ViewDefinition in project android-flowlayout by ApmeM.
the class FlowLayoutManager method applyPositionsToViews.
private void applyPositionsToViews(LineDefinition line) {
final List<ViewDefinition> childViews = line.getViews();
final int childCount = childViews.size();
for (int i = 0; i < childCount; i++) {
final ViewDefinition child = childViews.get(i);
final View view = child.getView();
measureChildWithMargins(view, child.getWidth(), child.getHeight());
layoutDecorated(view, this.getPaddingLeft() + line.getLineStartLength() + child.getInlineStartLength(), this.getPaddingTop() + line.getLineStartThickness() + child.getInlineStartThickness(), this.getPaddingLeft() + line.getLineStartLength() + child.getInlineStartLength() + child.getWidth(), this.getPaddingTop() + line.getLineStartThickness() + child.getInlineStartThickness() + child.getHeight());
}
}
use of org.apmem.tools.layouts.logic.ViewDefinition in project android-flowlayout by ApmeM.
the class LineDefinitionTests method CanFit_LengthLessThenRemainingIsOk.
@Test
public void CanFit_LengthLessThenRemainingIsOk() {
ViewDefinition view1 = CreateView(12, 34);
ViewDefinition view2 = CreateView(56, 78);
ConfigDefinition config = new ConfigDefinition();
config.setMaxWidth(100);
LineDefinition def = new LineDefinition(config);
def.addView(view1);
def.addView(view2);
boolean canFit = def.canFit(view1);
Assert.assertTrue(canFit);
}
use of org.apmem.tools.layouts.logic.ViewDefinition in project android-flowlayout by ApmeM.
the class LineDefinitionTests method AddView_TakesLayoutMarginsIntoAccount.
@Test
public void AddView_TakesLayoutMarginsIntoAccount() {
ViewDefinition view1 = CreateView(12, 34);
ViewDefinition view2 = CreateView(56, 78);
view1.setMargins(1, 1, 1, 1);
view2.setMargins(1, 1, 1, 1);
ConfigDefinition config = new ConfigDefinition();
config.setMaxWidth(100);
LineDefinition def = new LineDefinition(config);
def.addView(view1);
def.addView(view2);
Assert.assertEquals(72, def.getLineLength());
Assert.assertEquals(80, def.getLineThickness());
}
Aggregations