Search in sources :

Example 91 with FlexboxLayout

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

the class FlexboxAndroidTest method testAlignItems_flexEnd_parentPadding.

@Test
@FlakyTest
public void testAlignItems_flexEnd_parentPadding() throws Throwable {
    final FlexboxTestActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_align_items_parent_padding_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.text2)).check(isRightOf(withId(R.id.text1)));
    TextView textView1 = (TextView) activity.findViewById(R.id.text1);
    TextView textView2 = (TextView) activity.findViewById(R.id.text2);
    assertThat(textView1.getBottom(), is(flexboxLayout.getBottom() - flexboxLayout.getPaddingBottom()));
    assertThat(textView2.getBottom(), is(flexboxLayout.getBottom() - flexboxLayout.getPaddingBottom()));
}
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 92 with FlexboxLayout

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

the class FlexboxAndroidTest method testJustifyContent_spaceAround.

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

        @Override
        public void apply(FlexboxLayout flexboxLayout) {
            flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND);
        }
    });
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND));
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    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();
    // Divide by the number of children * 2
    space = space / 6;
    assertTrue(space - 1 <= textView1.getLeft() && textView1.getLeft() <= space + 1);
    int spaceInMiddle = space * 2;
    assertThat(textView2.getLeft() - textView1.getRight(), isEqualAllowingError(spaceInMiddle));
    assertThat(textView3.getLeft() - textView2.getRight(), isEqualAllowingError(spaceInMiddle));
    assertThat(flexboxLayout.getRight() - textView3.getRight(), 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 93 with FlexboxLayout

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

the class FlexboxAndroidTest method testFlexGrow_including_view_gone.

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

        @Override
        public void apply(FlexboxLayout flexboxLayout) {
            TextView textView2 = (TextView) activity.findViewById(R.id.text2);
            textView2.setVisibility(View.GONE);
        }
    });
    onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    // the third TextView is expanded to the right edge of the FlexboxLayout
    onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
    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(textView2.getVisibility(), is(View.GONE));
    assertThat(textView3.getWidth(), is(flexboxLayout.getWidth() - textView1.getWidth()));
}
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 94 with FlexboxLayout

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

the class FlexboxAndroidTest method testJustifyContent_flexStart_flexDirection_column.

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

        @Override
        public void apply(FlexboxLayout flexboxLayout) {
            flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
        }
    });
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_FLEX_START));
    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(isBelow(withId(R.id.text1)));
    onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
    onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
    onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
}
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 95 with FlexboxLayout

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

the class FlexboxAndroidTest method testAlignSelf_stretch_flexDirection_column.

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

        @Override
        public void apply(FlexboxLayout flexboxLayout) {
            flexboxLayout.setFlexDirection(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(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)));
    // There should be 2 flex lines in the layout with the given layout.
    // Only the first TextView's alignSelf is set to ALIGN_SELF_STRETCH
    int flexLineSize = flexboxLayout.getWidth() / 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(), isEqualAllowingError(flexLineSize));
    assertThat(textView2.getWidth(), not(flexLineSize));
    assertThat(textView3.getWidth(), not(flexLineSize));
}
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