Search in sources :

Example 6 with LineDefinition

use of org.apmem.tools.layouts.logic.LineDefinition in project android-flowlayout by ApmeM.

the class LineDefinitionTests method AddView_AddViewIntoList.

@Test
public void AddView_AddViewIntoList() {
    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);
    Assert.assertEquals(view1, def.getViews().get(0));
    Assert.assertEquals(view2, def.getViews().get(1));
}
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 7 with LineDefinition

use of org.apmem.tools.layouts.logic.LineDefinition in project android-flowlayout by ApmeM.

the class LineDefinitionTests method AddView_SetThicknessToMaxBetweenThickness.

@Test
public void AddView_SetThicknessToMaxBetweenThickness() {
    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);
    Assert.assertEquals(78, 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)

Example 8 with LineDefinition

use of org.apmem.tools.layouts.logic.LineDefinition 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 9 with LineDefinition

use of org.apmem.tools.layouts.logic.LineDefinition 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 10 with LineDefinition

use of org.apmem.tools.layouts.logic.LineDefinition 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

LineDefinition (org.apmem.tools.layouts.logic.LineDefinition)10 ViewDefinition (org.apmem.tools.layouts.logic.ViewDefinition)10 ConfigDefinition (org.apmem.tools.layouts.logic.ConfigDefinition)7 Test (org.junit.Test)7 View (android.view.View)3 Paint (android.graphics.Paint)2 RecyclerView (android.support.v7.widget.RecyclerView)1