Search in sources :

Example 1 with ViewDefinition

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

the class FlowLayout method onLayout.

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int linesCount = this.lines.size();
    for (int i = 0; i < linesCount; i++) {
        final LineDefinition line = this.lines.get(i);
        final int count = line.getViews().size();
        for (int j = 0; j < count; j++) {
            ViewDefinition child = line.getViews().get(j);
            View view = child.getView();
            LayoutParams lp = (LayoutParams) view.getLayoutParams();
            view.layout(this.getPaddingLeft() + line.getX() + child.getInlineX() + lp.leftMargin, this.getPaddingTop() + line.getY() + child.getInlineY() + lp.topMargin, this.getPaddingLeft() + line.getX() + child.getInlineX() + lp.leftMargin + child.getWidth(), this.getPaddingTop() + line.getY() + child.getInlineY() + lp.topMargin + child.getHeight());
        }
    }
}
Also used : LineDefinition(org.apmem.tools.layouts.logic.LineDefinition) ViewDefinition(org.apmem.tools.layouts.logic.ViewDefinition) View(android.view.View) Paint(android.graphics.Paint)

Example 2 with ViewDefinition

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

the class LineDefinitionTests method CanFit_TakesMarginIntoAccount.

@Test
public void CanFit_TakesMarginIntoAccount() {
    ViewDefinition view1 = CreateView(12, 34);
    ViewDefinition view2 = CreateView(56, 78);
    view1.setMargins(8, 1, 1, 1);
    view2.setMargins(8, 1, 1, 1);
    ConfigDefinition config = new ConfigDefinition();
    config.setMaxWidth(100);
    LineDefinition def = new LineDefinition(config);
    def.addView(view1);
    def.addView(view2);
    boolean canFit = def.canFit(view1);
    Assert.assertFalse(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 3 with ViewDefinition

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

the class CommonLogicTests method GravityApplyUseAllAvailableSpaceHorizontally.

@Test
public void GravityApplyUseAllAvailableSpaceHorizontally() {
    ConfigDefinition config = new ConfigDefinition();
    config.setMaxWidth(30);
    config.setMaxHeight(20);
    config.setGravity(Gravity.FILL);
    ArrayList<LineDefinition> lines = new ArrayList<>();
    ArrayList<ViewDefinition> views = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        ViewDefinition view = new ViewDefinition(config, null);
        view.setWidth(10);
        view.setHeight(10);
        views.add(view);
    }
    CommonLogic.fillLines(views, lines, config);
    CommonLogic.calculateLinesAndChildPosition(lines);
    CommonLogic.applyGravityToLines(lines, 30, 20, config);
    Assert.assertEquals(2, lines.size());
    Assert.assertEquals(10, lines.get(0).getViews().get(0).getWidth());
    Assert.assertEquals(10, lines.get(0).getViews().get(1).getWidth());
    Assert.assertEquals(10, lines.get(0).getViews().get(2).getWidth());
}
Also used : LineDefinition(org.apmem.tools.layouts.logic.LineDefinition) ViewDefinition(org.apmem.tools.layouts.logic.ViewDefinition) ConfigDefinition(org.apmem.tools.layouts.logic.ConfigDefinition) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with ViewDefinition

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

the class CommonLogicTests method MaxLinesSetLinesCountEqualToMaxLines.

@Test
public void MaxLinesSetLinesCountEqualToMaxLines() {
    ConfigDefinition config = new ConfigDefinition();
    config.setMaxWidth(20);
    config.setMaxLines(2);
    ArrayList<LineDefinition> lines = new ArrayList<>();
    ArrayList<ViewDefinition> views = new ArrayList<>();
    for (int i = 0; i < 9; i++) {
        ViewDefinition view = new ViewDefinition(config, null);
        view.setWidth(10);
        view.setHeight(10);
        views.add(view);
    }
    CommonLogic.fillLines(views, lines, config);
    Assert.assertEquals(2, lines.size());
    Assert.assertEquals(2, lines.get(0).getViews().size());
    Assert.assertEquals(2, lines.get(1).getViews().size());
}
Also used : LineDefinition(org.apmem.tools.layouts.logic.LineDefinition) ViewDefinition(org.apmem.tools.layouts.logic.ViewDefinition) ConfigDefinition(org.apmem.tools.layouts.logic.ConfigDefinition) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with ViewDefinition

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

the class FlowLayoutManager method onLayoutChildren.

@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
    detachAndScrapAttachedViews(recycler);
    final int count = this.getItemCount();
    views.clear();
    lines.clear();
    for (int i = 0; i < count; i++) {
        View child = recycler.getViewForPosition(i);
        addView(child);
        measureChildWithMargins(child, 0, 0);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        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(this.getWidth() - this.getPaddingRight() - this.getPaddingLeft());
    this.config.setMaxHeight(this.getHeight() - this.getPaddingTop() - this.getPaddingBottom());
    this.config.setWidthMode(View.MeasureSpec.EXACTLY);
    this.config.setHeightMode(View.MeasureSpec.EXACTLY);
    this.config.setCheckCanFit(true);
    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);
    }
}
Also used : ViewDefinition(org.apmem.tools.layouts.logic.ViewDefinition) LineDefinition(org.apmem.tools.layouts.logic.LineDefinition) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

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