use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testDivider_directionRow_verticalEnd.
@Test
@FlakyTest
public void testDivider_directionRow_verticalEnd() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_divider_test_direction_row, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.setShowDividerVertical(FlexboxLayout.SHOW_DIVIDER_END);
}
});
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
assertThat(flexboxLayout.getShowDividerVertical(), is(FlexboxLayout.SHOW_DIVIDER_END));
TextView text1 = (TextView) activity.findViewById(R.id.text1);
TextView text2 = (TextView) activity.findViewById(R.id.text2);
TextView text3 = (TextView) activity.findViewById(R.id.text3);
Drawable divider = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.divider, null);
assertNotNull(divider);
// Three text views are placed in the first row, thus two vertical middle dividers should
// be placed
int widthSumFirstRow = text1.getWidth() + text2.getWidth() + text3.getWidth() + divider.getIntrinsicWidth();
assertThat(text3.getRight() + divider.getIntrinsicWidth(), is(widthSumFirstRow));
assertThat(text1.getLeft(), is(flexboxLayout.getLeft()));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testDivider_directionColumn_vertical_horizontal_All.
@Test
@FlakyTest
public void testDivider_directionColumn_vertical_horizontal_All() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_divider_test_direction_column, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
Drawable divider = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.divider, null);
flexboxLayout.setDividerDrawable(divider);
flexboxLayout.setShowDivider(FlexboxLayout.SHOW_DIVIDER_BEGINNING | FlexboxLayout.SHOW_DIVIDER_MIDDLE | FlexboxLayout.SHOW_DIVIDER_END);
}
});
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
assertThat(flexboxLayout.getShowDividerVertical(), is(FlexboxLayout.SHOW_DIVIDER_BEGINNING | FlexboxLayout.SHOW_DIVIDER_MIDDLE | FlexboxLayout.SHOW_DIVIDER_END));
assertThat(flexboxLayout.getShowDividerHorizontal(), is(FlexboxLayout.SHOW_DIVIDER_BEGINNING | FlexboxLayout.SHOW_DIVIDER_MIDDLE | FlexboxLayout.SHOW_DIVIDER_END));
TextView text1 = (TextView) activity.findViewById(R.id.text1);
TextView text2 = (TextView) activity.findViewById(R.id.text2);
TextView text3 = (TextView) activity.findViewById(R.id.text3);
TextView text4 = (TextView) activity.findViewById(R.id.text4);
Drawable divider = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.divider, null);
assertNotNull(divider);
int heightSum = text1.getHeight() + text2.getHeight() + text3.getHeight() + divider.getIntrinsicHeight() * 4;
int widthSum = text1.getWidth() + text4.getWidth() + divider.getIntrinsicWidth() * 3;
assertThat(text3.getBottom() + divider.getIntrinsicHeight(), is(heightSum));
assertThat(text4.getRight() + divider.getIntrinsicWidth(), is(widthSum));
assertThat(text1.getLeft(), is(not(flexboxLayout.getLeft())));
assertThat(text1.getTop(), is(not(flexboxLayout.getTop())));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testAlignContent_stretch_parentWrapContent_flexDirection_column.
@Test
@FlakyTest
public void testAlignContent_stretch_parentWrapContent_flexDirection_column() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_align_content_test, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
ViewGroup.LayoutParams parentLp = flexboxLayout.getLayoutParams();
parentLp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
flexboxLayout.setLayoutParams(parentLp);
flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
}
});
assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_STRETCH));
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)));
// the third TextView is wrapped to the next flex line
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)));
// alignContent is only effective if the parent's height/width mode is MeasureSpec.EXACTLY.
// The size of the flex lines don't change even if the alingContent is set to
// ALIGN_CONTENT_STRETCH
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView3 = (TextView) activity.findViewById(R.id.text3);
assertThat(textView3.getLeft(), is(textView1.getWidth()));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testJustifyContent_spaceBetween_including_gone_views.
@Test
@FlakyTest
public void testJustifyContent_spaceBetween_including_gone_views() 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.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_SPACE_BETWEEN);
}
});
assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_BETWEEN));
onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text3)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView3 = (TextView) activity.findViewById(R.id.text3);
int space = flexboxLayout.getWidth() - textView1.getWidth() - textView3.getWidth();
assertThat(textView3.getLeft() - textView1.getRight(), isEqualAllowingError(space));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testAlignContent_center_flexDirection_column.
@Test
@FlakyTest
public void testAlignContent_center_flexDirection_column() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_align_content_test, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_CENTER);
flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
}
});
assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_CENTER));
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(isRightOf(withId(R.id.text1)));
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView3 = (TextView) activity.findViewById(R.id.text3);
int spaceLeftAndRight = flexboxLayout.getWidth() - textView1.getWidth() - textView3.getWidth();
spaceLeftAndRight /= 2;
assertThat(textView1.getLeft(), isEqualAllowingError(spaceLeftAndRight));
assertThat(textView3.getRight(), isEqualAllowingError(flexboxLayout.getRight() - spaceLeftAndRight));
}
Aggregations