use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testJustifyContent_spaceAround_flexDirection_column.
@Test
@FlakyTest
public void testJustifyContent_spaceAround_flexDirection_column() 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);
flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
}
});
assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND));
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
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.text3)).check(isLeftAlignedWith(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.getHeight() - textView1.getHeight() - textView2.getHeight() - textView3.getHeight();
// Divide by the number of children * 2
space = space / 6;
assertThat(textView1.getTop(), isEqualAllowingError(space));
int spaceInMiddle = space * 2;
assertThat(textView2.getTop() - textView1.getBottom(), isEqualAllowingError(spaceInMiddle));
assertThat(textView3.getTop() - textView2.getBottom(), isEqualAllowingError(spaceInMiddle));
assertThat(flexboxLayout.getBottom() - textView3.getBottom(), isEqualAllowingError(space));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testAlignItems_flexStart_flexDirection_column.
@Test
@FlakyTest
public void testAlignItems_flexStart_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.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
}
});
assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_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(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.
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(), not(flexLineSize));
assertThat(textView2.getWidth(), not(flexLineSize));
assertThat(textView3.getWidth(), not(flexLineSize));
assertThat(textView3.getLeft(), isEqualAllowingError(flexLineSize));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testOrderAttribute_removeViewInMiddle.
@Test
@FlakyTest
public void testOrderAttribute_removeViewInMiddle() throws Throwable {
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_order_test, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.removeViewAt(2);
}
});
assertNotNull(flexboxLayout);
assertThat(flexboxLayout.getChildCount(), is(3));
// order: -1, index 1
assertThat(((TextView) flexboxLayout.getReorderedChildAt(0)).getText().toString(), is(String.valueOf(2)));
// order: 0, index 3
assertThat(((TextView) flexboxLayout.getReorderedChildAt(1)).getText().toString(), is(String.valueOf(4)));
// order: 2, index 0
assertThat(((TextView) flexboxLayout.getReorderedChildAt(2)).getText().toString(), is(String.valueOf(1)));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testView_visibility_gone.
@Test
@FlakyTest
public void testView_visibility_gone() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_views_visibility_gone);
// The text1 and text2's visibility are gone, so the visible view starts from text3
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text4)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text4)).check(isRightOf(withId(R.id.text3)));
onView(withId(R.id.text5)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text5)).check(isBelow(withId(R.id.text3)));
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView2 = (TextView) activity.findViewById(R.id.text2);
TextView textView3 = (TextView) activity.findViewById(R.id.text3);
TextView textView4 = (TextView) activity.findViewById(R.id.text4);
TextView textView5 = (TextView) activity.findViewById(R.id.text5);
assertThat(textView1.getVisibility(), is(View.GONE));
assertThat(textView2.getVisibility(), is(View.GONE));
assertThat(textView4.getLeft(), is(textView3.getRight()));
assertThat(textView5.getTop(), is(textView3.getBottom()));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testJustifyContent_spaceAround_including_gone_views_direction_column.
@Test
@FlakyTest
public void testJustifyContent_spaceAround_including_gone_views_direction_column() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_justify_content_with_gone, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND);
}
});
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND));
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView3 = (TextView) activity.findViewById(R.id.text3);
int space = flexboxLayout.getHeight() - textView1.getHeight() - textView3.getHeight();
// Divide by the number of visible children * 2
space = space / 4;
assertThat(textView1.getTop(), isEqualAllowingError(space));
int spaceInMiddle = space * 2;
assertThat(textView3.getTop() - textView1.getBottom(), isEqualAllowingError(spaceInMiddle));
assertThat(flexboxLayout.getBottom() - textView3.getBottom(), isEqualAllowingError(space));
}
Aggregations