GridItemView extends FrameLayout { public void setVariant(@GridItemVariant int variant) { this.variant = variant; @LayoutRes int layout = getLayoutFromVariant(variant); removeAllViews(); LayoutInflater inflater = LayoutInflater.from(getContext()); inflater.inflate(layout, this); findChildViews(); setTexts(); setIcon(icon); } GridItemView(Context context);  GridItemView(Context context, AttributeSet attrs);  GridItemView(Context context, AttributeSet attrs, int defStyleAttr); @TargetApi(21)  GridItemView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes); @GridItemVariant int getVariant(); void setVariant(@GridItemVariant int variant); CharSequence getPrimaryText(); void setPrimaryText(@StringRes int textRes); void setPrimaryText(CharSequence text); ColorStateList getPrimaryTextColors(); @ColorInt int getCurrentPrimaryTextColor(); void setPrimaryTextColor(ColorStateList color); void setPrimaryTextColor(@ColorInt int color); void setPrimaryTextColorRes(@ColorRes int colorRes); CharSequence getSecondaryText(); void setSecondaryText(@StringRes int textRes); void setSecondaryText(CharSequence text); ColorStateList getSecondaryTextColors(); @ColorInt int getCurrentSecondaryTextColor(); void setSecondaryTextColor(ColorStateList color); void setSecondaryTextColor(@ColorInt int color); void setSecondaryTextColorRes(@ColorRes int colorRes); Drawable getIcon(); void setIcon(@DrawableRes int iconRes); void setIcon(Drawable icon); @IconGravity int getIconGravity(); void setIconGravity(@IconGravity int iconGravity); static final int VARIANT_ONE_LINE_TEXT; static final int VARIANT_ONE_LINE_TEXT_ICON; static final int VARIANT_TWO_LINE_TEXT; static final int VARIANT_TWO_LINE_TEXT_ICON; static final int ICON_GRAVITY_START; static final int ICON_GRAVITY_END; }
@Test public void givenOneLineText_whenSetVariant_thenVariantChanged() { gridItemView.setVariant(GridItemView.VARIANT_ONE_LINE_TEXT); assertThat(gridItemView) .hasVariant(GridItemView.VARIANT_ONE_LINE_TEXT) .doesNotHaveSecondaryTextView() .doesNotHaveIconView(); }
@Test public void givenOneLineTextIcon_whenSetVariant_thenVariantChanged() { gridItemView.setVariant(GridItemView.VARIANT_ONE_LINE_TEXT_ICON); assertThat(gridItemView) .hasVariant(GridItemView.VARIANT_ONE_LINE_TEXT_ICON) .hasIconView() .doesNotHaveSecondaryTextView(); }
@Test public void givenTwoLineText_whenSetVariant_thenVariantChanged() { gridItemView.setVariant(GridItemView.VARIANT_TWO_LINE_TEXT); assertThat(gridItemView) .hasVariant(GridItemView.VARIANT_TWO_LINE_TEXT) .hasSecondaryTextView() .doesNotHaveIconView(); }
@Test public void givenTwoLineTextIcon_whenSetVariant_thenVariantChanged() { gridItemView.setVariant(GridItemView.VARIANT_TWO_LINE_TEXT_ICON); assertThat(gridItemView) .hasVariant(GridItemView.VARIANT_TWO_LINE_TEXT_ICON) .hasSecondaryTextView() .hasIconView(); }
@Test @SuppressWarnings("WrongConstant") public void givenInvalidVariant_whenSetVariant_thenHasDefaultVariant() { gridItemView.setVariant(10000); assertThat(gridItemView) .doesNotHaveSecondaryTextView() .doesNotHaveIconView(); }