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);
}
}
}
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;
}
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());
}
}
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));
}
}
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);
}
Aggregations