Search in sources :

Example 86 with Configuration

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);
}
Also used : FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) ResourceResolver(com.android.ide.common.resources.ResourceResolver) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) SyncNlModel(com.android.tools.idea.uibuilder.SyncNlModel)

Example 87 with 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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration)

Example 88 with Configuration

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));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) LinkedHashMap(java.util.LinkedHashMap)

Example 89 with Configuration

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);
}
Also used : FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 90 with Configuration

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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Aggregations

Configuration (com.android.tools.idea.configurations.Configuration)95 VirtualFile (com.intellij.openapi.vfs.VirtualFile)38 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)23 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)21 ResourceResolver (com.android.ide.common.resources.ResourceResolver)16 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)14 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 Module (com.intellij.openapi.module.Module)9 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)8 IAndroidTarget (com.android.sdklib.IAndroidTarget)7 Device (com.android.sdklib.devices.Device)7 State (com.android.sdklib.devices.State)7 NotNull (org.jetbrains.annotations.NotNull)7 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)6 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)5 CompatibilityRenderTarget (com.android.tools.idea.rendering.multi.CompatibilityRenderTarget)5 NlModel (com.android.tools.idea.uibuilder.model.NlModel)4 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)4 PsiFile (com.intellij.psi.PsiFile)4 ResourceFolderType (com.android.resources.ResourceFolderType)3