TextInputLayoutHandler extends LinearLayoutHandler { @Override @Language("XML") @NotNull public String getXml(@NotNull String tagName, @NotNull XmlType xmlType) { boolean isMaterial2 = tagName.startsWith(MATERIAL2_PKG); switch (xmlType) { case COMPONENT_CREATION: String textInputEditTextTag = isMaterial2 ? TEXT_INPUT_EDIT_TEXT.newName() : TEXT_INPUT_EDIT_TEXT.oldName(); return new XmlBuilder() .startTag(tagName) .androidAttribute(ATTR_LAYOUT_WIDTH, VALUE_MATCH_PARENT) .androidAttribute(ATTR_LAYOUT_HEIGHT, VALUE_WRAP_CONTENT) .startTag(textInputEditTextTag) .androidAttribute(ATTR_LAYOUT_WIDTH, VALUE_MATCH_PARENT) .androidAttribute(ATTR_LAYOUT_HEIGHT, VALUE_WRAP_CONTENT) .androidAttribute(ATTR_HINT, "hint") .endTag(textInputEditTextTag) .endTag(tagName) .toString(); default: return super.getXml(tagName, xmlType); } }  @Override @NotNull List<String> getInspectorProperties(); @Override @Language("XML") @NotNull String getXml(@NotNull String tagName, @NotNull XmlType xmlType);  }
@Test public void testGetXmlForM1() { @Language("XML") String expected = "<android.support.design.widget.TextInputLayout\n" + " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"wrap_content\">\n" + "\n" + " <android.support.design.widget.TextInputEditText\n" + " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:hint=\"hint\" />\n" + "</android.support.design.widget.TextInputLayout>\n"; TextInputLayoutHandler handler = new TextInputLayoutHandler(); assertThat(handler.getXml(SdkConstants.TEXT_INPUT_LAYOUT.oldName(), XmlType.COMPONENT_CREATION)).isEqualTo(expected); }
@Test public void testGetXmlForM2() { @Language("XML") String expected = "<com.google.android.material.textfield.TextInputLayout\n" + " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"wrap_content\">\n" + "\n" + " <com.google.android.material.textfield.TextInputEditText\n" + " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:hint=\"hint\" />\n" + "</com.google.android.material.textfield.TextInputLayout>\n"; TextInputLayoutHandler handler = new TextInputLayoutHandler(); assertThat(handler.getXml(SdkConstants.TEXT_INPUT_LAYOUT.newName(), XmlType.COMPONENT_CREATION)).isEqualTo(expected); }