use of com.android.tools.idea.uibuilder.property.NlPropertyItem in project android by JetBrains.
the class FavoritesInspectorProviderTest method testIsApplicableChangesWithStarSettings.
public void testIsApplicableChangesWithStarSettings() {
NlPropertyItem elevation = createFrom(myTextView, ATTR_ELEVATION);
NlPropertyItem visibility = createFrom(myTextView, ATTR_VISIBILITY);
assertThat(myProvider.isApplicable(Collections.emptyList(), Collections.singletonMap(ATTR_ELEVATION, elevation), myPropertiesManager)).isFalse();
assertThat(myProvider.isApplicable(Collections.emptyList(), Collections.singletonMap(ATTR_VISIBILITY, visibility), myPropertiesManager)).isTrue();
myPropertiesComponent.setValue(STARRED_PROP, ATTR_ELEVATION);
assertThat(myProvider.isApplicable(Collections.emptyList(), Collections.singletonMap(ATTR_ELEVATION, elevation), myPropertiesManager)).isTrue();
assertThat(myProvider.isApplicable(Collections.emptyList(), Collections.singletonMap(ATTR_VISIBILITY, visibility), myPropertiesManager)).isFalse();
}
use of com.android.tools.idea.uibuilder.property.NlPropertyItem in project android by JetBrains.
the class FavoritesInspectorProviderTest method testIsApplicable.
public void testIsApplicable() {
NlPropertyItem elevation = createFrom(myTextView, ATTR_ELEVATION);
NlPropertyItem visibility = createFrom(myTextView, ATTR_VISIBILITY);
// If no starred properties are available for the current selection then this provider is not applicable:
assertThat(myProvider.isApplicable(Collections.emptyList(), Collections.emptyMap(), myPropertiesManager)).isFalse();
assertThat(myProvider.isApplicable(Collections.emptyList(), Collections.singletonMap(ATTR_ELEVATION, elevation), myPropertiesManager)).isFalse();
assertThat(myProvider.isApplicable(Collections.emptyList(), Collections.singletonMap(ATTR_VISIBILITY, visibility), myPropertiesManager)).isTrue();
}
use of com.android.tools.idea.uibuilder.property.NlPropertyItem in project android by JetBrains.
the class NlDefaultRendererTest method testSimple.
public void testSimple() {
@Language("XML") String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" >" + " <TextView android:id=\"@+id/textView\"/>" + "</RelativeLayout>";
XmlFile xmlFile = (XmlFile) myFixture.addFileToProject("res/layout/layout.xml", source);
XmlTag[] subTags = xmlFile.getRootTag().getSubTags();
assertEquals(1, subTags.length);
Table<String, String, NlPropertyItem> properties = NlProperties.getInstance().getProperties(ImmutableList.of(MockNlComponent.create(subTags[0])));
NlDefaultRenderer renderer = new NlDefaultRenderer();
NlPropertyItem property = properties.get(SdkConstants.ANDROID_URI, "id");
validateRendering(renderer, property, "id", "textView");
property = properties.get(SdkConstants.ANDROID_URI, "text");
validateRendering(renderer, property, "text", "");
property = properties.get(SdkConstants.ANDROID_URI, "focusable");
validateRendering(renderer, property, "focusable", "");
}
use of com.android.tools.idea.uibuilder.property.NlPropertyItem in project android by JetBrains.
the class ViewInspectorProviderTest method testUpdateProperties.
public void testUpdateProperties() {
List<NlComponent> components = ImmutableList.of(myImageView);
Map<String, NlProperty> properties = getPropertyMap(components);
assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
InspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
inspector.updateProperties(components, properties, myPropertiesManager);
NlComponentEditor srcEditor = inspector.getEditors().get(0);
assertThat(srcEditor.getProperty()).isNotNull();
assertThat(srcEditor.getProperty().getName()).isEqualTo(ATTR_SRC);
// Simulate the addition of appcompat library:
AttributeDefinition srcCompatDefinition = new AttributeDefinition(ATTR_SRC_COMPAT);
properties.put(ATTR_SRC_COMPAT, new NlPropertyItem(components, ANDROID_URI, srcCompatDefinition));
// Check that an update will replace the ATTR_SRC with ATTR_SRC_COMPAT
inspector.updateProperties(components, properties, myPropertiesManager);
srcEditor = inspector.getEditors().get(0);
assertThat(srcEditor.getProperty()).isNotNull();
assertThat(srcEditor.getProperty().getName()).isEqualTo(ATTR_SRC_COMPAT);
// Simulate the removal of appcompat library:
properties.remove(ATTR_SRC_COMPAT);
// Check that an update will replace the ATTR_SRC with ATTR_SRC_COMPAT
inspector.updateProperties(components, properties, myPropertiesManager);
srcEditor = inspector.getEditors().get(0);
assertThat(srcEditor.getProperty()).isNotNull();
assertThat(srcEditor.getProperty().getName()).isEqualTo(ATTR_SRC);
}
use of com.android.tools.idea.uibuilder.property.NlPropertyItem in project android by JetBrains.
the class FavoritesInspectorProviderTest method testInspectorComponent.
public void testInspectorComponent() {
NlPropertyItem elevation = createFrom(myTextView, ATTR_ELEVATION);
NlPropertyItem visibility = createFrom(myTextView, ATTR_VISIBILITY);
NlPropertyItem text = createFrom(myTextView, ATTR_TEXT);
myPropertiesComponent.setValue(STARRED_PROP, TOOLS_NS_NAME_PREFIX + ATTR_ELEVATION + ";" + ATTR_VISIBILITY);
List<NlComponent> components = Collections.singletonList(myTextView);
Map<String, NlProperty> properties = ImmutableMap.of(ATTR_TEXT, text, ATTR_ELEVATION, elevation, ATTR_VISIBILITY, visibility);
assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
InspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
List<NlComponentEditor> editors = inspector.getEditors();
assertThat(editors.size()).isEqualTo(2);
assertThat(inspector.getMaxNumberOfRows()).isEqualTo(3);
InspectorPanel panel = mock(InspectorPanel.class);
when(panel.addComponent(anyString(), anyString(), any())).thenAnswer(invocation -> new JLabel());
inspector.attachToInspector(panel);
verify(panel).addTitle(eq("Favorite Attributes"));
NlComponentEditor visibilityEditor = editors.get(1);
assertThat(visibilityEditor.getProperty()).isSameAs(visibility);
verify(panel).addComponent(eq(visibility.getName()), eq(visibility.getTooltipText()), eq(visibilityEditor.getComponent()));
JLabel visibilityLabel = visibilityEditor.getLabel();
assertThat(visibilityLabel).isNotNull();
assertThat(visibilityLabel.getIcon()).isNull();
NlComponentEditor elevationEditor = editors.get(0);
NlProperty elevationDesignProperty = elevationEditor.getProperty();
assertThat(elevationDesignProperty.getName()).isEqualTo(elevation.getName());
assertThat(elevationDesignProperty.getDefinition()).isSameAs(elevation.getDefinition());
assertThat(elevationDesignProperty.getNamespace()).isEqualTo(TOOLS_URI);
verify(panel).addComponent(eq(elevationDesignProperty.getName()), eq(elevationDesignProperty.getTooltipText()), eq(elevationEditor.getComponent()));
JLabel elevationLabel = elevationEditor.getLabel();
assertThat(elevationLabel).isNotNull();
assertThat(elevationLabel.getIcon()).isSameAs(AndroidIcons.NeleIcons.DesignProperty);
}
Aggregations