Search in sources :

Example 46 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class AndroidColorAnnotator method annotateResourceReference.

private static void annotateResourceReference(@NotNull ResourceType type, @NotNull AnnotationHolder holder, @NotNull PsiElement element, @NotNull String name, boolean isFramework) {
    Module module = ModuleUtilCore.findModuleForPsiElement(element);
    if (module == null) {
        return;
    }
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null) {
        return;
    }
    PsiFile file = PsiTreeUtil.getParentOfType(element, PsiFile.class);
    if (file == null) {
        return;
    }
    Configuration configuration = pickConfiguration(facet, module, file);
    if (configuration == null) {
        return;
    }
    ResourceValue value = findResourceValue(type, name, isFramework, module, configuration);
    if (value != null) {
        // TODO: Use a *shared* fallback resolver for this?
        ResourceResolver resourceResolver = configuration.getResourceResolver();
        if (resourceResolver != null) {
            annotateResourceValue(type, holder, element, value, resourceResolver, facet);
        }
    }
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ResourceResolver(com.android.ide.common.resources.ResourceResolver) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 47 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class RenderTestBase method getConfiguration.

protected Configuration getConfiguration(VirtualFile file, String deviceId, String themeStyle) {
    Configuration configuration = getConfiguration(file, deviceId);
    configuration.setTheme(themeStyle);
    return configuration;
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration)

Example 48 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class StyleListPaletteCellRenderer method customizeCellRenderer.

@Override
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
    super.customizeCellRenderer(list, value, index, selected, hasFocus);
    if (!(value instanceof String) || ThemesListModel.isSpecialOption((String) value)) {
        myColorPaletteComponent.reset();
        return;
    }
    ThemeResolver themeResolver = myContext.getThemeResolver();
    final ConfiguredThemeEditorStyle theme = themeResolver.getTheme((String) value);
    if (theme == null) {
        myColorPaletteComponent.reset();
        setIcon(null);
        return;
    }
    final boolean isFrameworkAttr = !ThemeEditorUtils.isAppCompatTheme(theme);
    ItemResourceValue primaryResourceValue = ThemeEditorUtils.resolveItemFromParents(theme, PRIMARY_MATERIAL, isFrameworkAttr);
    ItemResourceValue primaryDarkResourceValue = ThemeEditorUtils.resolveItemFromParents(theme, PRIMARY_DARK_MATERIAL, isFrameworkAttr);
    ItemResourceValue accentResourceValue = ThemeEditorUtils.resolveItemFromParents(theme, ACCENT_MATERIAL, isFrameworkAttr);
    //Check needed in case the xml files are inconsistent and have an item, but not a value
    if (primaryResourceValue != null && primaryDarkResourceValue != null && accentResourceValue != null) {
        Configuration configuration = theme.getConfiguration();
        ResourceResolver resourceResolver = configuration.getConfigurationManager().getResolverCache().getResourceResolver(configuration.getRealTarget(), theme.getStyleResourceUrl(), configuration.getFullConfig());
        Color primaryColor = ResourceHelper.resolveColor(resourceResolver, primaryResourceValue, myContext.getProject());
        Color primaryDarkColor = ResourceHelper.resolveColor(resourceResolver, primaryDarkResourceValue, myContext.getProject());
        Color accentColor = ResourceHelper.resolveColor(resourceResolver, accentResourceValue, myContext.getProject());
        if (primaryColor != null && primaryDarkColor != null && accentColor != null) {
            myColorPaletteComponent.setValues(primaryColor, primaryDarkColor, accentColor);
        }
        setIcon(myColorPaletteComponent);
    } else {
        myColorPaletteComponent.reset();
        setIcon(null);
    }
    if (selected) {
        myThemeChangedListener.themeChanged(theme.getQualifiedName());
    }
}
Also used : ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) Configuration(com.android.tools.idea.configurations.Configuration) ThemeResolver(com.android.tools.idea.editors.theme.ThemeResolver) ResourceResolver(com.android.ide.common.resources.ResourceResolver) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 49 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class AndroidThemePreviewPanel method refreshScale.

private void refreshScale() {
    Configuration configuration = myContext.getConfiguration();
    // Adjust the scale to the current config.
    if (configuration.getDeviceState() != null) {
        float reverseDeviceScale = Density.DEFAULT_DENSITY / (float) configuration.getDeviceState().getHardware().getScreen().getPixelDensity().getDpiValue();
        // we combine our scale, the reverse device scale, and the platform scale into 1 scale factor.
        myAndroidPreviewPanel.setScale(JBUI.scale(reverseDeviceScale * myScale));
    }
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration)

Example 50 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class ThemeEditorContext method updateThemeResolver.

public void updateThemeResolver() {
    // Disable listeners since we are not interested in the setTheme(null) update
    myEnabledListeners = false;
    // setTheme(null) is required since the configuration could have a link to a non existent theme (if it was removed).
    // If the configuration is pointing to a theme that does not exist anymore, the local resource resolution breaks so ThemeResolver
    // fails to find the local themes.
    Configuration resolverConfiguration = myConfiguration.clone();
    resolverConfiguration.setTheme(null);
    myEnabledListeners = true;
    myThemeResolver = new ThemeResolver(resolverConfiguration);
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration)

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