use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class SceneKeepDimensTest method setFakeResource.
private void setFakeResource(String dimension, String value) {
Configuration configuration = Mockito.mock(Configuration.class);
ResourceResolver resolver = Mockito.mock(ResourceResolver.class);
ResourceValue resourceValue = Mockito.mock(ResourceValue.class);
when(configuration.getResourceResolver()).thenReturn(resolver);
when(configuration.getDensity()).thenReturn(Density.MEDIUM);
when(resolver.findResValue(dimension, false)).thenReturn(resourceValue);
when(resolver.resolveResValue(resourceValue)).thenReturn(resourceValue);
when(resourceValue.getValue()).thenReturn(value);
((SyncNlModel) myModel).setConfiguration(configuration);
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class ColorUtilsTest method testContrastColors.
public void testContrastColors() {
VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles_low_contrast.xml", "res/values/styles.xml");
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
ThemeEditorContext context = new ThemeEditorContext(configuration);
context.setCurrentTheme(context.getThemeResolver().getTheme("MyTheme"));
Collection<Color> color = ColorUtils.getContrastColorsWithDescription(context, "colorPrimary").values();
assertThat(color).containsExactly(Color.decode("#EEEEEE"), Color.decode("#DDDDDD"));
color = ColorUtils.getContrastColorsWithDescription(context, "colorPrimary").values();
assertThat(color).containsExactly(Color.decode("#EEEEEE"), Color.decode("#DDDDDD"));
color = ColorUtils.getContrastColorsWithDescription(context, "").values();
assertThat(color).isEmpty();
color = ColorUtils.getContrastColorsWithDescription(context, "notExistent").values();
assertThat(color).isEmpty();
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class ColorUtilsTest method testContrastWarning.
public void testContrastWarning() {
VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles_low_contrast.xml", "res/values/styles.xml");
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
ThemeEditorContext context = new ThemeEditorContext(configuration);
context.setCurrentTheme(context.getThemeResolver().getTheme("MyTheme"));
ImmutableMap<String, Color> textColorContrastColors = ColorUtils.getContrastColorsWithDescription(context, "textColor");
ImmutableMap<String, Color> colorPrimaryContrastColors = ColorUtils.getContrastColorsWithDescription(context, "colorPrimary");
assertEquals("<html>Not enough contrast with <b>colorPrimary</b>", ColorUtils.getContrastWarningMessage(textColorContrastColors, Color.WHITE, ColorUtils.isBackgroundAttribute("textColor")));
assertEquals("<html>Not enough contrast with <b>colorBackground</b>", ColorUtils.getContrastWarningMessage(textColorContrastColors, Color.BLACK, ColorUtils.isBackgroundAttribute("textColor")));
assertEquals("<html>Not enough contrast with <b>textColor</b> and <b>textColorPrimary</b>", ColorUtils.getContrastWarningMessage(colorPrimaryContrastColors, Color.WHITE, ColorUtils.isBackgroundAttribute("colorPrimary")));
assertEquals("", ColorUtils.getContrastWarningMessage(colorPrimaryContrastColors, Color.BLACK, ColorUtils.isBackgroundAttribute("colorPrimary")));
// Test non existing attribute names
assertEquals("", ColorUtils.getContrastWarningMessage(ColorUtils.getContrastColorsWithDescription(context, ""), Color.WHITE, false));
assertEquals("", ColorUtils.getContrastWarningMessage(ColorUtils.getContrastColorsWithDescription(context, "invented"), Color.WHITE, true));
// Test transparent colors
assertEquals("<html>Not enough contrast with <b>colorBackground</b>", ColorUtils.getContrastWarningMessage(textColorContrastColors, new Color(0, 0, 0, 50), ColorUtils.isBackgroundAttribute("textColor")));
assertEquals("<html>Not enough contrast with <b>colorBackground</b>", ColorUtils.getContrastWarningMessage(textColorContrastColors, new Color(0, 0, 0, 250), ColorUtils.isBackgroundAttribute("textColor")));
LinkedHashMap<String, Color> colorsWithDescription = new LinkedHashMap<>();
colorsWithDescription.put("color very transparent", new Color(0, 0, 0, 50));
colorsWithDescription.put("color a little transparent", new Color(0, 0, 0, 200));
assertEquals("<html>Not enough contrast with color very transparent", ColorUtils.getContrastWarningMessage(colorsWithDescription, new Color(255, 255, 255, 200), false));
assertEquals("<html>Not enough contrast with color very transparent and color a little transparent", ColorUtils.getContrastWarningMessage(colorsWithDescription, new Color(255, 0, 0, 200), false));
assertEquals("<html>Not enough contrast with color very transparent", ColorUtils.getContrastWarningMessage(colorsWithDescription, new Color(255, 0, 0), false));
assertEquals("<html>Not enough contrast with color very transparent", ColorUtils.getContrastWarningMessage(colorsWithDescription, new Color(0, 255, 0, 200), false));
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class ConfiguredThemeEditorStyleTest method checkSetValue.
private void checkSetValue(VirtualFile file, ItemResourceValue item, String... answerFolders) {
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(file);
ThemeResolver themeResolver = new ThemeResolver(configuration);
ConfiguredThemeEditorStyle style = themeResolver.getTheme("AppTheme");
assertNotNull(style);
style.setValue(ResolutionUtils.getQualifiedItemName(item), item.getValue());
// ResourceFolderRepository needs to rescan the files to pick up the changes.
UIUtil.dispatchAllInvocationEvents();
HashSet<String> modifiedFolders = new HashSet<>(Arrays.asList(answerFolders));
int valuesFound = 0;
for (ConfiguredElement<ItemResourceValue> value : style.getConfiguredValues()) {
if (item.equals(value.getElement())) {
valuesFound++;
assertTrue(modifiedFolders.contains(value.getConfiguration().getUniqueKey()));
}
}
assertEquals(modifiedFolders.size(), valuesFound);
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class ConfiguredThemeEditorStyleTest method testThemeOverride.
/**
* Test that the main theme will override the one from the library
*/
public void testThemeOverride() {
VirtualFile virtualFile = myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles.xml", "res/values/styles.xml");
myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_1.xml", "additionalModules/moduleA/res/values/styles.xml");
ConfigurationManager configurationManager = myFacet.getConfigurationManager();
Configuration configuration = configurationManager.getConfiguration(virtualFile);
ThemeResolver resolver = new ThemeResolver(configuration);
ConfiguredThemeEditorStyle theme = resolver.getTheme("AppTheme");
assertNotNull(theme);
assertEquals(1, theme.getParentNames().size());
// We expect only the main app parent to be available
assertEquals("ATheme", theme.getParentNames().iterator().next().getElement());
}
Aggregations