use of com.android.ide.common.resources.ResourceFile in project android by JetBrains.
the class ConfiguredThemeEditorStyle method getConfiguredValues.
/**
* Returns all the style attributes and its values. For each attribute, multiple {@link ConfiguredElement} can be returned
* representing the multiple values in different configurations for each item.
* TODO: needs to be deleted, as we don't use this method except tests
*/
@NotNull
public ImmutableCollection<ConfiguredElement<ItemResourceValue>> getConfiguredValues() {
// Get a list of all the items indexed by the item name. Each item contains a list of the
// possible values in this theme in different configurations.
//
// If item1 has multiple values in different configurations, there will be an
// item1 = {folderConfiguration1 -> value1, folderConfiguration2 -> value2}
final ImmutableList.Builder<ConfiguredElement<ItemResourceValue>> itemResourceValues = ImmutableList.builder();
if (isFramework()) {
assert myConfiguration.getFrameworkResources() != null;
com.android.ide.common.resources.ResourceItem styleItem = myConfiguration.getFrameworkResources().getResourceItem(ResourceType.STYLE, myStyleResourceValue.getName());
// Go over all the files containing the resource.
for (ResourceFile file : styleItem.getSourceFileList()) {
ResourceValue styleResourceValue = file.getValue(ResourceType.STYLE, styleItem.getName());
FolderConfiguration folderConfiguration = file.getConfiguration();
if (styleResourceValue instanceof StyleResourceValue) {
for (final ItemResourceValue value : ((StyleResourceValue) styleResourceValue).getValues()) {
itemResourceValues.add(ConfiguredElement.create(folderConfiguration, value));
}
}
}
} else {
for (ResourceItem styleDefinition : getStyleResourceItems()) {
ResourceValue styleResourceValue = styleDefinition.getResourceValue(isFramework());
FolderConfiguration folderConfiguration = styleDefinition.getConfiguration();
if (styleResourceValue instanceof StyleResourceValue) {
for (final ItemResourceValue value : ((StyleResourceValue) styleResourceValue).getValues()) {
// We use the qualified name since apps and libraries can use the same attribute name twice with and without "android:"
itemResourceValues.add(ConfiguredElement.create(folderConfiguration, value));
}
}
}
}
return itemResourceValues.build();
}
use of com.android.ide.common.resources.ResourceFile in project android by JetBrains.
the class ThemeEditorStyle method getParentName.
/**
* @param configuration FolderConfiguration of the style to lookup
* @return parent this style with a FolderConfiguration configuration
*/
@Nullable
public /*if there is no of this style*/
String getParentName(@NotNull FolderConfiguration configuration) {
if (isFramework()) {
IAndroidTarget target = myManager.getHighestApiTarget();
assert target != null;
com.android.ide.common.resources.ResourceItem styleItem = myManager.getResolverCache().getFrameworkResources(new FolderConfiguration(), target).getResourceItem(ResourceType.STYLE, getName());
for (ResourceFile file : styleItem.getSourceFileList()) {
if (file.getConfiguration().equals(configuration)) {
StyleResourceValue style = (StyleResourceValue) file.getValue(ResourceType.STYLE, getName());
return ResolutionUtils.getParentQualifiedName(style);
}
}
throw new IllegalArgumentException("bad folder config " + configuration);
}
for (final ResourceItem styleItem : getStyleResourceItems()) {
if (configuration.equals(styleItem.getConfiguration())) {
StyleResourceValue style = (StyleResourceValue) styleItem.getResourceValue(false);
assert style != null;
return ResolutionUtils.getParentQualifiedName(style);
}
}
throw new IllegalArgumentException("bad folder config " + configuration);
}
use of com.android.ide.common.resources.ResourceFile in project android by JetBrains.
the class ThemeEditorStyle method getValues.
/**
* @param configuration FolderConfiguration of the style to lookup
* @return all values defined in this style with a FolderConfiguration configuration
*/
@NotNull
public Collection<ItemResourceValue> getValues(@NotNull FolderConfiguration configuration) {
if (isFramework()) {
IAndroidTarget target = myManager.getHighestApiTarget();
assert target != null;
com.android.ide.common.resources.ResourceItem styleItem = myManager.getResolverCache().getFrameworkResources(new FolderConfiguration(), target).getResourceItem(ResourceType.STYLE, getName());
for (ResourceFile file : styleItem.getSourceFileList()) {
if (file.getConfiguration().equals(configuration)) {
StyleResourceValue style = (StyleResourceValue) file.getValue(ResourceType.STYLE, getName());
return style.getValues();
}
}
throw new IllegalArgumentException("bad folder config " + configuration);
}
for (final ResourceItem styleItem : getStyleResourceItems()) {
if (configuration.equals(styleItem.getConfiguration())) {
StyleResourceValue style = (StyleResourceValue) styleItem.getResourceValue(false);
if (style == null) {
// style might be null if the value fails to parse
continue;
}
return style.getValues();
}
}
throw new IllegalArgumentException("bad folder config " + configuration);
}
Aggregations