Search in sources :

Example 26 with FlexboxLayout

use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.

the class FlexboxAndroidTest method testFlexBasisPercent_wrap_flexDirection_column.

@Test
@FlakyTest
public void testFlexBasisPercent_wrap_flexDirection_column() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_flex_basis_percent_test, new Configuration() {

        @Override
        public void apply(FlexboxLayout flexboxLayout) {
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    // The text1 length is 50%, the text2 length is 60% and the wrap property is FLEX_WRAP_WRAP,
    // the text2 should be on the second flex line.
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    FlexboxLayout.LayoutParams lp1 = (FlexboxLayout.LayoutParams) textView1.getLayoutParams();
    FlexboxLayout.LayoutParams lp2 = (FlexboxLayout.LayoutParams) textView2.getLayoutParams();
    assertThat(textView1.getHeight(), is(Math.round(flexboxLayout.getHeight() * lp1.flexBasisPercent)));
    assertThat(textView2.getHeight(), is(Math.round(flexboxLayout.getHeight() * lp2.flexBasisPercent)));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) TextView(android.widget.TextView) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 27 with FlexboxLayout

use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.

the class FlexboxAndroidTest method testFlexWrap_nowrap.

@Test
@FlakyTest
public void testFlexWrap_nowrap() throws Throwable {
    FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_flex_wrap_test, new Configuration() {

        @Override
        public void apply(FlexboxLayout flexboxLayout) {
            flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_NOWRAP);
        }
    });
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_NOWRAP));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    // The width of the FlexboxLayout is not enough for placing the three text views.
    // But the flexWrap attribute is set to FLEX_WRAP_NOWRAP, the third text view is placed
    // to the right of the second one and overflowing the parent FlexboxLayout.
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    assertThat(flexboxLayout.getFlexLines().size(), is(1));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 28 with FlexboxLayout

use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.

the class FlexboxAndroidTest method testJustifyContent_spaceAround_withPadding.

@Test
@FlakyTest
public void testJustifyContent_spaceAround_withPadding() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    final int padding = 40;
    FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_justify_content_test, new Configuration() {

        @Override
        public void apply(FlexboxLayout flexboxLayout) {
            flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND);
            flexboxLayout.setPadding(padding, padding, padding, padding);
        }
    });
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int space = flexboxLayout.getWidth() - textView1.getWidth() - textView2.getWidth() - textView3.getWidth() - padding * 2;
    // Divide by the number of children * 2
    space = space / 6;
    assertThat(textView1.getLeft() - padding, isEqualAllowingError(space));
    int spaceInMiddle = space * 2;
    assertThat(textView2.getLeft() - textView1.getRight(), isEqualAllowingError(spaceInMiddle));
    assertThat(textView3.getLeft() - textView2.getRight(), isEqualAllowingError(spaceInMiddle));
    assertThat(flexboxLayout.getRight() - textView3.getRight() - padding, isEqualAllowingError(space));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) TextView(android.widget.TextView) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 29 with FlexboxLayout

use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.

the class FlexboxAndroidTest method testWrap_childMargin_vertical.

@Test
@FlakyTest
public void testWrap_childMargin_vertical() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_wrap_child_margin_vertical_test);
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    // The sum of height of TextView1 and TextView2 is not enough for wrapping, but considering
    // the margin of the TextView2, the second TextView should be wrapped
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    TextView text1 = (TextView) activity.findViewById(R.id.text1);
    TextView text2 = (TextView) activity.findViewById(R.id.text2);
    FlexboxLayout.LayoutParams lp2 = (FlexboxLayout.LayoutParams) text2.getLayoutParams();
    assertThat(flexboxLayout.getWidth(), is(text1.getWidth() + text2.getWidth() + lp2.leftMargin + lp2.rightMargin));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) TextView(android.widget.TextView) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 30 with FlexboxLayout

use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.

the class FlexboxAndroidTest method testJustifyContent_flexEnd_withParentPadding.

@Test
@FlakyTest
public void testJustifyContent_flexEnd_withParentPadding() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_justify_content_with_parent_padding, new Configuration() {

        @Override
        public void apply(FlexboxLayout flexboxLayout) {
            flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_FLEX_END);
        }
    });
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_FLEX_END));
    onView(withId(R.id.text2)).check(isLeftOf(withId(R.id.text3)));
    onView(withId(R.id.text1)).check(isLeftOf(withId(R.id.text2)));
    TextView text3 = (TextView) activity.findViewById(R.id.text3);
    // Both the parent FrameLayout and the FlexboxLayout have different padding values
    // but the text3.getRight should be the padding value for the FlexboxLayout, not including
    // the parent's padding value
    assertThat(flexboxLayout.getWidth() - text3.getRight(), is(flexboxLayout.getPaddingRight()));
    assertThat(text3.getTop(), is(flexboxLayout.getPaddingTop()));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) TextView(android.widget.TextView) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Aggregations

FlexboxLayout (com.google.android.flexbox.FlexboxLayout)141 FlakyTest (android.support.test.filters.FlakyTest)140 MediumTest (android.support.test.filters.MediumTest)140 Test (org.junit.Test)140 TextView (android.widget.TextView)112 Drawable (android.graphics.drawable.Drawable)19 MainActivity (com.google.android.apps.flexbox.MainActivity)12 NavigationView (android.support.design.widget.NavigationView)6 Menu (android.view.Menu)6 ArrayAdapter (android.widget.ArrayAdapter)5 Spinner (android.widget.Spinner)5 View (android.view.View)3 Espresso.onView (android.support.test.espresso.Espresso.onView)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 Toolbar (android.support.v7.widget.Toolbar)1 AdapterView (android.widget.AdapterView)1