Search in sources :

Example 11 with ViewDefinition

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));
    }
}
Also used : ViewDefinition(org.apmem.tools.layouts.logic.ViewDefinition) View(android.view.View) Paint(android.graphics.Paint)

Example 12 with ViewDefinition

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));
}
Also used : ViewDefinition(org.apmem.tools.layouts.logic.ViewDefinition) LineDefinition(org.apmem.tools.layouts.logic.LineDefinition) View(android.view.View) Paint(android.graphics.Paint)

Example 13 with ViewDefinition

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());
    }
}
Also used : ViewDefinition(org.apmem.tools.layouts.logic.ViewDefinition) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 14 with ViewDefinition

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);
}
Also used : ViewDefinition(org.apmem.tools.layouts.logic.ViewDefinition) LineDefinition(org.apmem.tools.layouts.logic.LineDefinition) ConfigDefinition(org.apmem.tools.layouts.logic.ConfigDefinition) Test(org.junit.Test)

Example 15 with ViewDefinition

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());
}
Also used : ViewDefinition(org.apmem.tools.layouts.logic.ViewDefinition) LineDefinition(org.apmem.tools.layouts.logic.LineDefinition) ConfigDefinition(org.apmem.tools.layouts.logic.ConfigDefinition) Test(org.junit.Test)

Aggregations

ViewDefinition (org.apmem.tools.layouts.logic.ViewDefinition)19 LineDefinition (org.apmem.tools.layouts.logic.LineDefinition)16 ConfigDefinition (org.apmem.tools.layouts.logic.ConfigDefinition)14 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)6 View (android.view.View)5 Paint (android.graphics.Paint)3 RecyclerView (android.support.v7.widget.RecyclerView)2