use of com.android.resources.ResourceFolderType in project android by JetBrains.
the class ResourceManager method getResourceNames.
@NotNull
public Collection<String> getResourceNames(@NotNull ResourceType resourceType, boolean publicOnly) {
final Set<String> result = new HashSet<String>();
result.addAll(getValueResourceNames(resourceType));
List<ResourceFolderType> folders = FolderTypeRelationship.getRelatedFolders(resourceType);
if (!folders.isEmpty()) {
for (ResourceFolderType folderType : folders) {
if (folderType != ResourceFolderType.VALUES) {
result.addAll(getFileResourcesNames(folderType.getName()));
}
}
}
if (resourceType == ResourceType.ID) {
result.addAll(getIds(true));
}
return result;
}
use of com.android.resources.ResourceFolderType in project android by JetBrains.
the class AndroidFindUsagesHandlerFactory method canFindUsages.
@Override
public boolean canFindUsages(@NotNull PsiElement element) {
PsiElement element1 = LazyValueResourceElementWrapper.computeLazyElement(element);
if (element1 == null) {
return false;
}
if (element1 instanceof XmlAttributeValue) {
XmlAttributeValue value = (XmlAttributeValue) element1;
if (AndroidResourceUtil.findIdFields(value).length > 0) {
return true;
}
}
element1 = correctResourceElement(element1);
if (element1 instanceof PsiField) {
return AndroidResourceUtil.isResourceField((PsiField) element1);
} else if (element1 instanceof PsiFile || element1 instanceof XmlTag) {
final AndroidFacet facet = AndroidFacet.getInstance(element1);
if (facet != null) {
if (element1 instanceof PsiFile) {
return facet.getLocalResourceManager().getFileResourceFolderType((PsiFile) element1) != null;
} else {
final ResourceFolderType fileResType = facet.getLocalResourceManager().getFileResourceFolderType(element1.getContainingFile());
if (ResourceFolderType.VALUES == fileResType) {
return AndroidResourceUtil.getResourceTypeByValueResourceTag((XmlTag) element1) != null;
}
}
}
}
return false;
}
use of com.android.resources.ResourceFolderType in project android by JetBrains.
the class ImportModule method copyInto.
public void copyInto(@NonNull File destDir) throws IOException {
ImportSummary summary = myImporter.getSummary();
Set<File> copied = Sets.newHashSet();
final File main = new File(destDir, FD_SOURCES + separator + FD_MAIN);
myImporter.mkdirs(main);
if (isAndroidProject()) {
File srcManifest = getManifestFile();
if (srcManifest != null && srcManifest.exists()) {
File destManifest = new File(main, ANDROID_MANIFEST_XML);
myImporter.copyTextFile(this, srcManifest, destManifest);
summary.reportMoved(this, srcManifest, destManifest);
recordCopiedFile(copied, srcManifest);
}
File srcRes = getResourceDir();
if (srcRes != null && srcRes.exists()) {
File destRes = new File(main, FD_RES);
myImporter.mkdirs(destRes);
myImporter.copyDir(srcRes, destRes, new GradleImport.CopyHandler() {
@Override
public boolean handle(@NonNull File source, @NonNull File dest, boolean updateEncoding, @Nullable ImportModule sourceModule) throws IOException {
// Resource files in non-value folders should use only lower case characters
if (hasUpperCaseExtension(dest) && !isIgnoredFile(source)) {
File parentFile = source.getParentFile();
if (parentFile != null) {
ResourceFolderType folderType = ResourceFolderType.getFolderType(parentFile.getName());
if (folderType != ResourceFolderType.VALUES) {
String name = dest.getName();
int dot = name.indexOf('.');
if (dot != -1) {
name = name.substring(0, dot) + name.substring(dot).toLowerCase(Locale.US);
File destParent = dest.getParentFile();
dest = destParent != null ? new File(destParent, name) : new File(name);
if (updateEncoding && isTextFile(source)) {
myImporter.copyTextFile(sourceModule, source, dest);
} else {
Files.copy(source, dest);
}
if (sourceModule != null) {
// Just use the names rather than the full paths to make it clear that this was just
// a file renaming (even though there is also a move happening for all resources including
// these. In other words, instead of displaying
// * res/drawable-hdpi/other_icon.PNG => app/src/main/res/drawable-hdpi/other_icon.png
// we display
// * other_icon.PNG => app/src/main/res/drawable-hdpi/other_icon.png
myImporter.getSummary().reportMoved(sourceModule, new File(source.getName()), new File(name));
}
return true;
}
}
}
}
return false;
}
}, true, this);
summary.reportMoved(this, srcRes, destRes);
recordCopiedFile(copied, srcRes);
}
File srcAssets = getAssetsDir();
if (srcAssets != null && srcAssets.exists()) {
File destAssets = new File(main, FD_ASSETS);
myImporter.mkdirs(destAssets);
myImporter.copyDir(srcAssets, destAssets, null, false, null);
summary.reportMoved(this, srcAssets, destAssets);
recordCopiedFile(copied, srcAssets);
}
File lintXml = getLintXml();
if (lintXml != null) {
File destLintXml = new File(destDir, lintXml.getName());
myImporter.copyTextFile(this, lintXml, destLintXml);
summary.reportMoved(this, lintXml, destLintXml);
recordCopiedFile(copied, lintXml);
}
}
for (final File src : getSourcePaths()) {
final File srcJava = resolveFile(src);
File destJava = new File(main, FD_JAVA);
if (srcJava.isDirectory()) {
// Merge all the separate source folders into a single one; they aren't allowed
// to contain source file conflicts anyway
myImporter.mkdirs(destJava);
} else {
destJava = new File(main, srcJava.getName());
}
myImporter.copyDir(srcJava, destJava, new GradleImport.CopyHandler() {
// Handle moving .rs/.rsh/.fs files to main/rs/ and .aidl files to the
// corresponding aidl package under main/aidl
@Override
public boolean handle(@NonNull File source, @NonNull File dest, boolean updateEncoding, @Nullable ImportModule sourceModule) throws IOException {
String sourcePath = source.getPath();
if (sourcePath.endsWith(DOT_AIDL)) {
File aidlDir = new File(main, FD_AIDL);
File relative = GradleImport.computeRelativePath(srcJava, source);
if (relative == null) {
relative = GradleImport.computeRelativePath(srcJava.getCanonicalFile(), source);
}
if (relative != null) {
File destAidl = new File(aidlDir, relative.getPath());
myImporter.mkdirs(destAidl.getParentFile());
myImporter.copyTextFile(ImportModule.this, source, destAidl);
myImporter.getSummary().reportMoved(ImportModule.this, source, destAidl);
return true;
}
} else if (sourcePath.endsWith(DOT_RS) || sourcePath.endsWith(DOT_RSH) || sourcePath.endsWith(DOT_FS)) {
// Copy to flattened rs dir
// TODO: Ensure the file names are unique!
File destRs = new File(main, FD_RENDERSCRIPT + separator + source.getName());
myImporter.mkdirs(destRs.getParentFile());
myImporter.copyTextFile(ImportModule.this, source, destRs);
myImporter.getSummary().reportMoved(ImportModule.this, source, destRs);
return true;
} else if (!sourcePath.endsWith(DOT_JAVA) && // in case Eclipse built .class into source dir
!sourcePath.endsWith(DOT_CLASS) && !sourcePath.endsWith(DOT_JAR) && // leave docs with their code
!sourcePath.equals("package.html") && !sourcePath.equals("overview.html") && source.isFile()) {
// Move resources over to the resource folder
File resourceDir = new File(main, FD_JAVA_RES);
File relative = GradleImport.computeRelativePath(srcJava, source);
if (relative == null) {
relative = GradleImport.computeRelativePath(srcJava.getCanonicalFile(), source);
}
if (relative != null) {
File destResource = new File(resourceDir, relative.getPath());
myImporter.mkdirs(destResource.getParentFile());
Files.copy(source, destResource);
myImporter.getSummary().reportMoved(ImportModule.this, source, destResource);
return true;
}
}
return false;
}
}, true, this);
summary.reportMoved(this, srcJava, destJava);
recordCopiedFile(copied, srcJava);
}
for (File jar : getJarPaths()) {
File srcJar = resolveFile(jar);
File destJar = new File(destDir, getJarOutputRelativePath(jar).getPath());
if (destJar.getParentFile() != null) {
myImporter.mkdirs(destJar.getParentFile());
}
Files.copy(srcJar, destJar);
summary.reportMoved(this, srcJar, destJar);
recordCopiedFile(copied, srcJar);
}
for (File lib : getNativeLibs()) {
File srcLib = resolveFile(lib);
String abi = lib.getParentFile().getName();
File destLib = new File(destDir, FD_SOURCES + separator + FD_MAIN + separator + "jniLibs" + separator + abi + separator + lib.getName());
if (destLib.getParentFile() != null) {
myImporter.mkdirs(destLib.getParentFile());
}
Files.copy(srcLib, destLib);
summary.reportMoved(this, srcLib, destLib);
recordCopiedFile(copied, srcLib);
}
File jni = getNativeSources();
if (jni != null) {
File srcJni = resolveFile(jni);
File destJni = new File(destDir, FD_SOURCES + separator + FD_MAIN + separator + "jni");
myImporter.copyDir(srcJni, destJni, null, true, this);
summary.reportMoved(this, srcJni, destJni);
recordCopiedFile(copied, srcJni);
}
File instrumentation = getInstrumentationDir();
if (instrumentation != null) {
final File test = new File(destDir, FD_SOURCES + separator + FD_TEST);
myImporter.mkdirs(test);
// We should NOT copy the Android manifest file. Don't mark it as "ignored"
// either since we'll pull everything we need out of it and put it into the
// Gradle file.
recordCopiedFile(copied, new File(instrumentation, ANDROID_MANIFEST_XML));
File srcRes = new File(instrumentation, FD_RES);
if (srcRes.isDirectory()) {
File destRes = new File(test, FD_RES);
myImporter.mkdirs(destRes);
myImporter.copyDir(srcRes, destRes, null, true, this);
summary.reportMoved(this, srcRes, destRes);
recordCopiedFile(copied, srcRes);
}
File srcJava = new File(instrumentation, FD_SOURCES);
if (srcJava.isDirectory()) {
File destRes = new File(test, FD_JAVA);
myImporter.mkdirs(destRes);
myImporter.copyDir(srcJava, destRes, null, true, this);
summary.reportMoved(this, srcJava, destRes);
recordCopiedFile(copied, srcJava);
}
for (File jar : getTestJarPaths()) {
File srcJar = resolveFile(jar);
File destJar = new File(destDir, getTestJarOutputRelativePath(jar).getPath());
if (destJar.exists()) {
continue;
}
if (destJar.getParentFile() != null) {
myImporter.mkdirs(destJar.getParentFile());
}
Files.copy(srcJar, destJar);
summary.reportMoved(this, srcJar, destJar);
recordCopiedFile(copied, srcJar);
}
}
if (isAndroidProject()) {
for (File srcProguard : getLocalProguardFiles()) {
File destProguard = new File(destDir, srcProguard.getName());
if (!destProguard.exists()) {
myImporter.copyTextFile(this, srcProguard, destProguard);
summary.reportMoved(this, srcProguard, destProguard);
recordCopiedFile(copied, srcProguard);
} else {
myImporter.reportWarning(this, destProguard, "Local proguard config file name is not unique");
}
}
}
reportIgnored(copied);
}
use of com.android.resources.ResourceFolderType in project android by JetBrains.
the class ResourceReferenceConverter method getQuickFixes.
@Override
public LocalQuickFix[] getQuickFixes(ConvertContext context) {
AndroidFacet facet = AndroidFacet.getInstance(context);
if (facet != null) {
final DomElement domElement = context.getInvocationElement();
if (domElement instanceof GenericDomValue) {
final String value = ((GenericDomValue) domElement).getStringValue();
if (value != null) {
ResourceValue resourceValue = ResourceValue.parse(value, false, myWithPrefix, true);
if (resourceValue != null) {
String aPackage = resourceValue.getNamespace();
ResourceType resType = resourceValue.getType();
if (resType == null && myResourceTypes.size() == 1) {
resType = myResourceTypes.iterator().next();
}
final String resourceName = resourceValue.getResourceName();
if (aPackage == null && resType != null && resourceName != null && AndroidResourceUtil.isCorrectAndroidResourceName(resourceName)) {
final List<LocalQuickFix> fixes = new ArrayList<>();
ResourceFolderType folderType = AndroidResourceUtil.XML_FILE_RESOURCE_TYPES.get(resType);
if (folderType != null) {
fixes.add(new CreateFileResourceQuickFix(facet, folderType, resourceName, context.getFile(), false));
}
if (VALUE_RESOURCE_TYPES.contains(resType) && resType != ResourceType.LAYOUT) {
// layouts: aliases only
fixes.add(new CreateValueResourceQuickFix(facet, resType, resourceName, context.getFile(), false));
}
return fixes.toArray(new LocalQuickFix[fixes.size()]);
}
}
}
}
}
return LocalQuickFix.EMPTY_ARRAY;
}
use of com.android.resources.ResourceFolderType in project android by JetBrains.
the class ResourceFolderRepository method scanResFolder.
private void scanResFolder(@NotNull VirtualFile resDir) {
for (VirtualFile subDir : resDir.getChildren()) {
if (subDir.isValid() && subDir.isDirectory()) {
String name = subDir.getName();
ResourceFolderType folderType = getFolderType(name);
if (folderType != null) {
FolderConfiguration folderConfiguration = FolderConfiguration.getConfigForFolder(name);
if (folderConfiguration == null) {
continue;
}
String qualifiers = getQualifiers(name);
if (folderType == VALUES) {
scanValueResFolder(subDir, qualifiers, folderConfiguration);
} else {
scanFileResourceFolder(subDir, folderType, qualifiers, folderConfiguration);
}
}
}
}
}
Aggregations