Search in sources :

Example 16 with ViewDefinition

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

the class CommonLogicTests method GravityApplyUseAllAvailableSpaceVertically.

@Test
public void GravityApplyUseAllAvailableSpaceVertically() {
    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).getHeight());
    Assert.assertEquals(10, lines.get(1).getViews().get(0).getHeight());
}
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 17 with ViewDefinition

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

the class CommonLogicTests method MaxLinesNotSetAllLinesAddedWhenNotSet.

@Test
public void MaxLinesNotSetAllLinesAddedWhenNotSet() {
    ConfigDefinition config = new ConfigDefinition();
    config.setMaxWidth(20);
    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(5, lines.size());
    Assert.assertEquals(2, lines.get(0).getViews().size());
    Assert.assertEquals(2, lines.get(1).getViews().size());
    Assert.assertEquals(2, lines.get(2).getViews().size());
    Assert.assertEquals(2, lines.get(3).getViews().size());
    Assert.assertEquals(1, lines.get(4).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 18 with ViewDefinition

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

the class CommonLogicTests method GravityApplyUseAllAvailableSpaceVerticallyWithLastPixel.

@Test
public void GravityApplyUseAllAvailableSpaceVerticallyWithLastPixel() {
    ConfigDefinition config = new ConfigDefinition();
    config.setMaxWidth(30);
    config.setMaxHeight(21);
    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, 21, config);
    Assert.assertEquals(2, lines.size());
    Assert.assertEquals(10, lines.get(0).getViews().get(0).getHeight());
    Assert.assertEquals(11, lines.get(1).getViews().get(0).getHeight());
}
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 19 with ViewDefinition

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

the class CommonLogicTests method GravityApplyUseAllAvailableSpaceHorizontallyWithLastPixel.

@Test
public void GravityApplyUseAllAvailableSpaceHorizontallyWithLastPixel() {
    ConfigDefinition config = new ConfigDefinition();
    config.setMaxWidth(31);
    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, 31, 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(11, 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)

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