Search in sources :

Example 11 with ResourceFile

use of com.android.ide.common.res2.ResourceFile in project android by JetBrains.

the class LocalResourceRepository method getMatchingFiles.

@NonNull
public List<VirtualFile> getMatchingFiles(@NonNull VirtualFile file, @NonNull ResourceType type, @NonNull FolderConfiguration config) {
    List<ResourceFile> matches = super.getMatchingFiles(ResourceHelper.getResourceName(file), type, config);
    List<VirtualFile> matchesFiles = new ArrayList<VirtualFile>(matches.size());
    for (ResourceFile match : matches) {
        if (match != null) {
            if (match instanceof PsiResourceFile) {
                matchesFiles.add(((PsiResourceFile) match).getPsiFile().getVirtualFile());
            } else {
                matchesFiles.add(LocalFileSystem.getInstance().findFileByIoFile(match.getFile()));
            }
        }
    }
    return matchesFiles;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ResourceFile(com.android.ide.common.res2.ResourceFile) ArrayList(java.util.ArrayList) NonNull(com.android.annotations.NonNull)

Example 12 with ResourceFile

use of com.android.ide.common.res2.ResourceFile in project android by JetBrains.

the class ResourceFolderRepositoryTest method testMoveResourceFileBetweenDensityFolders.

public void testMoveResourceFileBetweenDensityFolders() throws Exception {
    // Regression test for https://code.google.com/p/android/issues/detail?id=61648
    // Make sure we flush resource values when reusing resource items incrementally
    // Move a file-based resource file from one configuration to another; verify that
    // items are preserved, generation changed (since it can affect config matching),
    // and resource files updated.
    final VirtualFile file1 = myFixture.copyFileToProject(DRAWABLE, "res/drawable-mdpi/picture.png");
    final VirtualFile file2 = myFixture.copyFileToProject(DRAWABLE, "res/drawable-hdpi/dummy.ignore");
    PsiFile psiFile1 = PsiManager.getInstance(getProject()).findFile(file1);
    assertNotNull(psiFile1);
    ResourceFolderRepository resources = createRepository();
    assertNotNull(resources);
    ResourceItem item = getOnlyItem(resources, ResourceType.DRAWABLE, "picture");
    ResourceFile source = item.getSource();
    assertNotNull(source);
    assertEquals("mdpi", source.getQualifiers());
    ResourceValue resourceValue = item.getResourceValue(false);
    assertNotNull(resourceValue);
    String valuePath = resourceValue.getValue().replace(File.separatorChar, '/');
    assertTrue(valuePath, valuePath.endsWith("res/drawable-mdpi/picture.png"));
    long generation = resources.getModificationCount();
    WriteCommandAction.runWriteCommandAction(null, new Runnable() {

        @Override
        public void run() {
            try {
                // Move file from one location to another
                file1.move(this, file2.getParent());
            } catch (IOException e) {
                fail(e.toString());
            }
        }
    });
    assertTrue(generation < resources.getModificationCount());
    assertTrue(resources.hasResourceItem(ResourceType.DRAWABLE, "picture"));
    item = getOnlyItem(resources, ResourceType.DRAWABLE, "picture");
    source = item.getSource();
    assertNotNull(source);
    assertEquals("hdpi", source.getQualifiers());
    resourceValue = item.getResourceValue(false);
    assertNotNull(resourceValue);
    valuePath = resourceValue.getValue().replace(File.separatorChar, '/');
    assertTrue(valuePath, valuePath.endsWith("res/drawable-hdpi/picture.png"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ResourceFile(com.android.ide.common.res2.ResourceFile) PsiFile(com.intellij.psi.PsiFile) IOException(java.io.IOException) ResourceItem(com.android.ide.common.res2.ResourceItem)

Aggregations

ResourceFile (com.android.ide.common.res2.ResourceFile)8 ResourceItem (com.android.ide.common.res2.ResourceItem)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)4 File (java.io.File)4 Nullable (org.jetbrains.annotations.Nullable)4 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)3 ResourceFile (com.android.ide.common.resources.ResourceFile)3 IAndroidTarget (com.android.sdklib.IAndroidTarget)2 PsiFile (com.intellij.psi.PsiFile)2 XmlFile (com.intellij.psi.xml.XmlFile)2 IOException (java.io.IOException)2 NotNull (org.jetbrains.annotations.NotNull)2 NonNull (com.android.annotations.NonNull)1 Nullable (com.android.annotations.Nullable)1 AndroidLibrary (com.android.builder.model.AndroidLibrary)1 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)1 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 AbstractResourceRepository (com.android.ide.common.res2.AbstractResourceRepository)1 ResourceFolderType (com.android.resources.ResourceFolderType)1