use of com.android.ide.common.res2.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.res2.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);
}
use of com.android.ide.common.res2.ResourceFile in project android by JetBrains.
the class StringsWriteUtils method createItem.
/**
* Creates a string resource in the specified locale.
*
* @return the resource item that was created, null if it wasn't created or could not be read back
*/
@Nullable
public static ResourceItem createItem(@NotNull final AndroidFacet facet, @NotNull VirtualFile resFolder, @Nullable final Locale locale, @NotNull final String name, @NotNull final String value, final boolean translatable) {
Project project = facet.getModule().getProject();
XmlFile resourceFile = getStringResourceFile(project, resFolder, locale);
if (resourceFile == null) {
return null;
}
final XmlTag root = resourceFile.getRootTag();
if (root == null) {
return null;
}
new WriteCommandAction.Simple(project, "Creating string " + name, resourceFile) {
@Override
public void run() {
XmlTag child = root.createChildTag(ResourceType.STRING.getName(), root.getNamespace(), escapeResourceStringAsXml(value), false);
child.setAttribute(SdkConstants.ATTR_NAME, name);
// XmlTagImpl handles a null value by deleting the attribute, which is our desired behavior
//noinspection ConstantConditions
child.setAttribute(SdkConstants.ATTR_TRANSLATABLE, translatable ? null : SdkConstants.VALUE_FALSE);
root.addSubTag(child, false);
}
}.execute();
if (ApplicationManager.getApplication().isReadAccessAllowed()) {
return getStringResourceItem(facet, name, locale);
} else {
return ApplicationManager.getApplication().runReadAction(new Computable<ResourceItem>() {
@Override
public ResourceItem compute() {
return getStringResourceItem(facet, name, locale);
}
});
}
}
use of com.android.ide.common.res2.ResourceFile in project android by JetBrains.
the class AndroidResourceRenameResourceProcessor method appendUnhandledReferences.
/** Writes into the given {@link HtmlBuilder} a set of references
* that are defined in a library (and may or may not also be defined locally) */
private static void appendUnhandledReferences(@NotNull Project project, @NotNull AndroidFacet facet, @NotNull List<ResourceItem> all, @NotNull List<ResourceItem> local, @NotNull HtmlBuilder builder) {
File root = VfsUtilCore.virtualToIoFile(project.getBaseDir());
Collection<AndroidLibrary> libraries = null;
// Write a set of descriptions to library references. Put them in a list first such that we can
// sort the (to for example make test output stable.)
List<String> descriptions = Lists.newArrayList();
for (ResourceItem item : all) {
if (!local.contains(item)) {
ResourceFile source = item.getSource();
if (libraries == null) {
libraries = AppResourceRepository.findAarLibraries(facet);
}
if (source != null) {
File sourceFile = source.getFile();
// TODO: Look up the corresponding AAR artifact, and then use library.getRequestedCoordinates() or
// library.getResolvedCoordinates() here and append the coordinate. However, until b.android.com/77341
// is fixed this doesn't work.
/*
// Attempt to find the corresponding AAR artifact
AndroidLibrary library = null;
for (AndroidLibrary l : libraries) {
File res = l.getResFolder();
if (res.exists() && FileUtil.isAncestor(res, sourceFile, true)) {
library = l;
break;
}
}
*/
// Look for exploded-aar and strip off the prefix path to it
File localRoot = root;
File prev = sourceFile;
File current = sourceFile.getParentFile();
while (current != null) {
String name = current.getName();
if (EXPLODED_AAR.equals(name)) {
localRoot = prev;
break;
}
prev = current;
current = current.getParentFile();
}
if (FileUtil.isAncestor(localRoot, sourceFile, true)) {
descriptions.add(FileUtil.getRelativePath(localRoot, sourceFile));
} else {
descriptions.add(sourceFile.getPath());
}
}
}
}
Collections.sort(descriptions);
builder.newline().newline();
builder.add("Unhandled references:");
builder.newline();
int count = 0;
for (String s : descriptions) {
builder.add(s).newline();
count++;
if (count == 10) {
builder.add("...").newline();
builder.add("(Additional results truncated)");
break;
}
}
}
use of com.android.ide.common.res2.ResourceFile in project android by JetBrains.
the class ModuleResourceRepositoryTest method assertItemIsInDir.
// Unit test support methods
static void assertItemIsInDir(VirtualFile dir, ResourceItem item) {
ResourceFile resourceFile = item.getSource();
assertNotNull(resourceFile);
VirtualFile parent = VfsUtil.findFileByIoFile(resourceFile.getFile(), false);
assertNotNull(parent);
assertEquals(dir, parent.getParent().getParent());
}
Aggregations