Search in sources :

Example 71 with FlexboxLayout

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

the class FlexboxAndroidTest method testAlignItems_flexEnd.

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

        @Override
        public void apply(FlexboxLayout flexboxLayout) {
            flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_FLEX_END);
        }
    });
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_END));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
    // There should be 2 flex lines in the layout with the given layout.
    int flexLineSize = flexboxLayout.getHeight() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView1.getHeight(), not(flexLineSize));
    assertThat(textView2.getHeight(), not(flexLineSize));
    assertThat(textView3.getHeight(), not(flexLineSize));
    assertThat(textView1.getBottom(), isEqualAllowingError(flexLineSize));
    assertThat(textView2.getBottom(), isEqualAllowingError(flexLineSize));
    assertThat(textView3.getBottom(), is(flexboxLayout.getBottom()));
}
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 72 with FlexboxLayout

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

the class FlexboxAndroidTest method testOrderAttribute_fromLayoutXml.

@Test
@FlakyTest
public void testOrderAttribute_fromLayoutXml() throws Throwable {
    FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_order_test);
    assertNotNull(flexboxLayout);
    assertThat(flexboxLayout.getChildCount(), is(4));
    // order: -1, index 1
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(0)).getText().toString(), is(String.valueOf(2)));
    // order: 0, index 2
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(1)).getText().toString(), is(String.valueOf(3)));
    // order: 1, index 3
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(2)).getText().toString(), is(String.valueOf(4)));
    // order: 2, index 0
    assertThat(((TextView) flexboxLayout.getReorderedChildAt(3)).getText().toString(), is(String.valueOf(1)));
}
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 73 with FlexboxLayout

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

the class FlexboxAndroidTest method testAlignItems_flexEnd_flexDirection_column.

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

        @Override
        public void apply(FlexboxLayout flexboxLayout) {
            flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_FLEX_END);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_END));
    assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
    // There should be 2 flex lines in the layout with the given layout.
    int flexLineSize = flexboxLayout.getHeight() / 2;
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    assertThat(textView1.getWidth(), not(flexLineSize));
    assertThat(textView2.getWidth(), not(flexLineSize));
    assertThat(textView3.getWidth(), not(flexLineSize));
    assertThat(textView1.getRight(), isEqualAllowingError(flexLineSize));
    assertThat(textView2.getRight(), isEqualAllowingError(flexLineSize));
    assertThat(textView3.getRight(), is(flexboxLayout.getRight()));
}
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 74 with FlexboxLayout

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

the class FlexboxAndroidTest method testFlexBasisPercent_nowrap_flexDirection_column.

@Test
@FlakyTest
public void testFlexBasisPercent_nowrap_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.setFlexWrap(FlexboxLayout.FLEX_WRAP_NOWRAP);
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    // The text1 length is 50%, the text2 length is 60% and the text3 has the fixed height,
    // but the flex wrap attribute is FLEX_WRAP_NOWRAP, and flexShrink attributes for all
    // children are the default value (1), three text views are shrank to fit in a single
    // flex line.
    assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_NOWRAP));
    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(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    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);
    TextView textView3 = (TextView) activity.findViewById(R.id.text3);
    int totalHeight = textView1.getHeight() + textView2.getHeight() + textView3.getHeight();
    // Allowing minor different length with the flex container since the sum of the three text
    // views width is not always the same as the flex container's main size caused by round
    // errors in calculating the percent lengths.
    assertThat(flexboxLayout.getHeight(), isEqualAllowingError(totalHeight));
}
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 75 with FlexboxLayout

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

the class FlexboxAndroidTest method testEmptyChildren.

@Test
@FlakyTest
public void testEmptyChildren() throws Throwable {
    FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_empty_children);
    assertThat(flexboxLayout.getChildCount(), is(0));
}
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)

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