use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class TextInspectorProviderTest method testTextAppearanceResetsOtherStyles.
public void testTextAppearanceResetsOtherStyles() {
List<NlComponent> components = ImmutableList.of(myTextView);
Map<String, NlProperty> properties = getPropertyMap(components);
properties.get(ATTR_FONT_FAMILY).setValue("serif");
properties.get(ATTR_TYPEFACE).setValue("sans");
properties.get(ATTR_TEXT_SIZE).setValue("24sp");
properties.get(ATTR_LINE_SPACING_EXTRA).setValue("24sp");
properties.get(ATTR_TEXT_COLOR).setValue("@android:color/holo_blue_dark");
properties.get(ATTR_TEXT_STYLE).setValue("bold|italic");
properties.get(ATTR_TEXT_ALL_CAPS).setValue("true");
properties.get(ATTR_TEXT_ALIGNMENT).setValue("textStart");
assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
TextInspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
inspector.refresh();
Optional<NlComponentEditor> textAppearanceEditor = inspector.getEditors().stream().filter(editor -> editor.getProperty() != null && editor.getProperty().getName().equals(ATTR_TEXT_APPEARANCE)).findFirst();
assertThat(textAppearanceEditor.isPresent()).isTrue();
assert textAppearanceEditor.isPresent();
assertThat(textAppearanceEditor.get()).isInstanceOf(NlBaseComponentEditor.class);
NlBaseComponentEditor editor = (NlBaseComponentEditor) textAppearanceEditor.get();
editor.stopEditing("Material.Display1");
assertThat(properties.get(ATTR_TEXT_APPEARANCE).getValue()).isEqualTo("Material.Display1");
assertThat(properties.get(ATTR_FONT_FAMILY).getValue()).isNull();
assertThat(properties.get(ATTR_TYPEFACE).getValue()).isNull();
assertThat(properties.get(ATTR_TEXT_SIZE).getValue()).isNull();
assertThat(properties.get(ATTR_LINE_SPACING_EXTRA).getValue()).isNull();
assertThat(properties.get(ATTR_TEXT_COLOR).getValue()).isNull();
assertThat(properties.get(ATTR_TEXT_STYLE).getValue()).isNull();
assertThat(properties.get(ATTR_TEXT_ALL_CAPS).getValue()).isNull();
assertThat(properties.get(ATTR_TEXT_ALIGNMENT).getValue()).isNull();
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class PropertyTestCase method clearSnapshots.
protected static void clearSnapshots(@NotNull List<NlComponent> components) {
for (NlComponent component : components) {
component.setSnapshot(null);
clearSnapshots(component.getChildren());
}
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class IdAnalyzerTest method testButton1And2.
public void testButton1And2() {
ModelBuilder modelBuilder = createRelativeLayout();
NlModel model = modelBuilder.build();
NlComponent button1 = findById(model, "button1");
NlComponent button2 = findById(model, "button2");
NlProperty accessibility = new NlPropertyItem(ImmutableList.of(button1, button2), ANDROID_URI, new AttributeDefinition(ATTR_ACCESSIBILITY_TRAVERSAL_BEFORE));
IdAnalyzer analyzer = new IdAnalyzer(accessibility);
List<String> ids = analyzer.findIds();
assertEquals(ImmutableList.of("button3", "button4", "button5", "group1", "radio_button1", "radio_button2", "radio_button3", "text_view1"), ids);
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class IdAnalyzerTest method testRadioGroup.
public void testRadioGroup() {
ModelBuilder modelBuilder = createRelativeLayout();
NlModel model = modelBuilder.build();
NlComponent group = findById(model, "group1");
NlProperty property = new NlPropertyItem(ImmutableList.of(group), ANDROID_URI, new AttributeDefinition(ATTR_CHECKED_BUTTON));
IdAnalyzer analyzer = new IdAnalyzer(property);
List<String> ids = analyzer.findIds();
assertEquals(ImmutableList.of("radio_button1", "radio_button2", "radio_button3"), ids);
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class IdInspectorProviderTest method testInspectorComponent.
public void testInspectorComponent() {
List<NlComponent> components = ImmutableList.of(myTextView);
Map<String, NlProperty> properties = getPropertyMap(components);
assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
IdInspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
List<NlComponentEditor> editors = inspector.getEditors();
assertThat(editors.size()).isEqualTo(3);
assertThat(inspector.getMaxNumberOfRows()).isEqualTo(4);
InspectorPanel panel = mock(InspectorPanel.class);
when(panel.addComponent(anyString(), anyString(), any())).thenAnswer(invocation -> new JLabel());
inspector.attachToInspector(panel);
for (NlComponentEditor editor : editors) {
NlProperty property = editor.getProperty();
assertThat(property).isNotNull();
String propertyName = property.getName();
if (propertyName.equals(ATTR_ID)) {
propertyName = "ID";
}
verify(panel).addComponent(eq(propertyName), eq(null), eq(editor.getComponent()));
}
verify(panel, never()).addPanel(inspector.getConstraintPanel());
}
Aggregations