use of com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration in project android by JetBrains.
the class ThemeAttributeResolver method resolveFromInheritance.
private void resolveFromInheritance(@NotNull ThemeEditorStyle themeEditorStyle, @NotNull FolderConfiguration configuration, @NotNull RestrictedConfiguration restricted, @NotNull Set<String> seenAttributes) {
RestrictedConfiguration styleRestricted = getRestrictedConfiguration(themeEditorStyle, configuration);
if (styleRestricted == null) {
LOG.warn(configuration + " is unreachable");
return;
}
styleRestricted = restricted.intersect(styleRestricted);
if (styleRestricted == null) {
return;
}
Set<String> newSeenAttributes = new HashSet<String>(seenAttributes);
for (ItemResourceValue item : themeEditorStyle.getValues(configuration)) {
String itemName = ResolutionUtils.getQualifiedItemName(item);
if (!newSeenAttributes.contains(itemName)) {
myItemValueMap.putValue(itemName, ConfiguredElement.create(styleRestricted.getAny(), item));
newSeenAttributes.add(itemName);
}
}
String parentName = themeEditorStyle.getParentName(configuration);
if (parentName == null) {
// We have reached the top of the theme hierarchy (i.e "android:Theme")
return;
}
ThemeEditorStyle parent = new ThemeEditorStyle(myManager, parentName);
for (FolderConfiguration folder : parent.getFolders()) {
resolveFromInheritance(parent, folder, styleRestricted, newSeenAttributes);
}
}
use of com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration in project android by JetBrains.
the class ThemeAttributeResolver method resolveAll.
@NotNull
private List<EditedStyleItem> resolveAll() {
ThemeEditorStyle theme = new ThemeEditorStyle(myManager, myStyle.getQualifiedName());
for (FolderConfiguration folder : theme.getFolders()) {
resolveFromInheritance(myStyle, folder, new RestrictedConfiguration(), new HashSet<String>());
}
List<EditedStyleItem> result = Lists.newArrayList();
FolderConfiguration configuration = myStyle.getConfiguration().getFullConfig();
for (String key : myItemValueMap.keySet()) {
Collection<ConfiguredElement<ItemResourceValue>> itemValues = myItemValueMap.get(key);
final ConfiguredElement<ItemResourceValue> selectedValue = (ConfiguredElement<ItemResourceValue>) configuration.findMatchingConfigurable(Lists.<Configurable>newArrayList(itemValues));
if (selectedValue == null) {
// TODO: there is NO value for this attribute in the current config,so instead we need to show "no value for current device"
result.add(new EditedStyleItem(itemValues.iterator().next(), itemValues, myStyle));
} else {
itemValues.remove(selectedValue);
assert !itemValues.contains(selectedValue);
result.add(new EditedStyleItem(selectedValue, itemValues, myStyle));
}
}
return result;
}
use of com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration in project android by JetBrains.
the class AndroidThemePreviewToolWindowManager method getBestConfiguration.
@Nullable
private static /*if there is no available configuration that would select the passed file*/
Configuration getBestConfiguration(@Nullable PsiFile psiFile) {
Module module = psiFile != null ? ModuleUtilCore.findModuleForPsiElement(psiFile) : null;
if (module == null) {
return null;
}
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
return null;
}
VirtualFile virtualFile = psiFile.getVirtualFile();
ConfigurationManager manager = facet.getConfigurationManager();
List<VirtualFile> variations = ResourceHelper.getResourceVariations(virtualFile, false);
if (variations.isEmpty()) {
return manager.getConfiguration(virtualFile);
}
// There is more than one resource folder available so make sure we select a configuration that only matches the current file.
Collection<FolderConfiguration> incompatible = Collections2.transform(variations, new Function<VirtualFile, FolderConfiguration>() {
@Nullable
@Override
public FolderConfiguration apply(VirtualFile input) {
assert input != null;
return ResourceHelper.getFolderConfiguration(input);
}
});
FolderConfiguration selectedFileFolderConfiguration = ResourceHelper.getFolderConfiguration(psiFile);
if (selectedFileFolderConfiguration == null) {
// This folder probably has invalid qualifiers or they are in the wrong order
return null;
}
RestrictedConfiguration restrictedConfiguration = RestrictedConfiguration.restrict(selectedFileFolderConfiguration, incompatible);
if (restrictedConfiguration == null) {
// Unable to create a configuration that only matches this file
return null;
}
FolderConfiguration restricted = restrictedConfiguration.getAny();
Configuration newConfiguration = Configuration.create(manager, virtualFile, null, restricted);
VersionQualifier newVersionQualifier = restricted.getVersionQualifier();
if (newVersionQualifier != null) {
IAndroidTarget realTarget = manager.getHighestApiTarget() != null ? manager.getHighestApiTarget() : manager.getTarget();
assert realTarget != null;
newConfiguration.setTarget(new CompatibilityRenderTarget(realTarget, newVersionQualifier.getVersion(), null));
}
return newConfiguration;
}
Aggregations