use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testFlexBasisPercent_nowrap.
@Test
@FlakyTest
public void testFlexBasisPercent_nowrap() 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);
}
});
// The text1 length is 50%, the text2 length is 60% and the text3 has the fixed width,
// 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));
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(isTopAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text3)).check(isRightOf(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 totalWidth = textView1.getWidth() + textView2.getWidth() + textView3.getWidth();
// 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.getWidth(), isEqualAllowingError(totalWidth));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testView_visibility_gone_first_item_in_flex_line_horizontal.
@Test
@FlakyTest
public void testView_visibility_gone_first_item_in_flex_line_horizontal() throws Throwable {
// This test verifies if the FlexboxLayout is visible when the visibility of the first
// flex item in the second flex line (or arbitrary flex lines other than the first flex
// line)
// is set to "gone"
// There was an issue reported for that
// https://github.com/google/flexbox-layout/issues/47
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_visibility_gone_first_item_in_flex_line_row);
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView3 = (TextView) activity.findViewById(R.id.text3);
assertTrue(flexboxLayout.getHeight() > 0);
assertThat(flexboxLayout.getHeight(), is(textView1.getHeight() + textView3.getHeight()));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testOrderAttribute_fromCode.
@Test
@FlakyTest
public void testOrderAttribute_fromCode() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_order_test, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
TextView fifth = createTextView(activity, String.valueOf(5), 0);
TextView sixth = createTextView(activity, String.valueOf(6), -10);
flexboxLayout.addView(fifth);
flexboxLayout.addView(sixth);
}
});
assertThat(flexboxLayout.getChildCount(), is(6));
// order: -10, index 5
assertThat(((TextView) flexboxLayout.getReorderedChildAt(0)).getText().toString(), is(String.valueOf(6)));
// order: -1, index 1
assertThat(((TextView) flexboxLayout.getReorderedChildAt(1)).getText().toString(), is(String.valueOf(2)));
// order: 0, index 2
assertThat(((TextView) flexboxLayout.getReorderedChildAt(2)).getText().toString(), is(String.valueOf(3)));
// order: 0, index 4
assertThat(((TextView) flexboxLayout.getReorderedChildAt(3)).getText().toString(), is(String.valueOf(5)));
// order: 1, index 3
assertThat(((TextView) flexboxLayout.getReorderedChildAt(4)).getText().toString(), is(String.valueOf(4)));
// order: 2, index 0
assertThat(((TextView) flexboxLayout.getReorderedChildAt(5)).getText().toString(), is(String.valueOf(1)));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testFlexWrap_wrap_reverse_flexDirection_column.
@Test
@FlakyTest
public void testFlexWrap_wrap_reverse_flexDirection_column() throws Throwable {
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_flex_wrap_test, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE);
}
});
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE));
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(isRightAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
// The width of the FlexboxLayout is not enough for placing the three text views.
// There should be two flex lines same as FLEX_WRAP_WRAP, but the layout starts from right
// to left in FLEX_WRAP_WRAP_REVERSE
onView(withId(R.id.text3)).check(isLeftOf(withId(R.id.text1)));
onView(withId(R.id.text3)).check(isLeftOf(withId(R.id.text2)));
onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
assertThat(flexboxLayout.getFlexLines().size(), is(2));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testDivider_directionRow_horizontalBeginning.
@Test
@FlakyTest
public void testDivider_directionRow_horizontalBeginning() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
final Drawable divider = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.divider, null);
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_divider_test_direction_row, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.setDividerDrawableHorizontal(divider);
flexboxLayout.setShowDividerHorizontal(FlexboxLayout.SHOW_DIVIDER_BEGINNING);
flexboxLayout.setShowDividerVertical(FlexboxLayout.SHOW_DIVIDER_NONE);
}
});
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
assertThat(flexboxLayout.getShowDividerHorizontal(), is(FlexboxLayout.SHOW_DIVIDER_BEGINNING));
assertThat(flexboxLayout.getShowDividerVertical(), is(FlexboxLayout.SHOW_DIVIDER_NONE));
TextView text1 = (TextView) activity.findViewById(R.id.text1);
TextView text4 = (TextView) activity.findViewById(R.id.text4);
assertNotNull(divider);
int heightSum = text1.getHeight() + text4.getHeight() + divider.getIntrinsicHeight();
assertThat(text4.getBottom(), is(heightSum));
assertThat(text1.getTop(), is(not(flexboxLayout.getTop())));
}
Aggregations