use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.
the class DataBindingXmlReferenceContributor method getDataBindingInfo.
@Nullable
public static DataBindingInfo getDataBindingInfo(PsiElement element) {
DataBindingInfo dataBindingInfo = null;
Module module = ModuleUtilCore.findModuleForPsiElement(element);
if (module != null) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null && facet.isDataBindingEnabled()) {
LocalResourceRepository moduleResources = facet.getModuleResources(true);
PsiFile topLevelFile = InjectedLanguageUtil.getTopLevelFile(element);
if (topLevelFile != null) {
String name = topLevelFile.getName();
name = name.substring(0, name.lastIndexOf('.'));
dataBindingInfo = moduleResources.getDataBindingInfoForLayout(name);
}
}
}
return dataBindingInfo;
}
use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.
the class ResourceResolverCacheTest method test.
public void test() throws Exception {
VirtualFile file1 = myFixture.copyFileToProject("render/layout1.xml", "res/layout/layout1.xml");
VirtualFile file2 = myFixture.copyFileToProject("render/layout2.xml", "res/layout/layout2.xml");
VirtualFile file3 = myFixture.copyFileToProject("javadoc/strings/strings.xml", "res/values/strings.xml");
assertNotNull(file1);
assertNotNull(file2);
assertNotNull(file3);
AndroidFacet facet = AndroidFacet.getInstance(myModule);
assertNotNull(facet);
Project project = getProject();
PsiFile psiFile1 = PsiManager.getInstance(project).findFile(file1);
assertNotNull(psiFile1);
PsiFile psiFile2 = PsiManager.getInstance(project).findFile(file2);
assertNotNull(psiFile2);
final PsiFile psiFile3 = PsiManager.getInstance(project).findFile(file3);
assertNotNull(psiFile3);
ConfigurationManager configurationManager = facet.getConfigurationManager();
assertNotNull(configurationManager);
final Configuration configuration1 = configurationManager.getConfiguration(file1);
Configuration configuration2 = configurationManager.getConfiguration(file2);
assertNotNull(configuration1.getTheme());
assertEquals(configuration2.getTheme(), configuration1.getTheme());
ResourceResolver resolver1 = configuration1.getResourceResolver();
ResourceResolver resolver2 = configuration2.getResourceResolver();
assertSame(resolver1, resolver2);
assertSame(resolver1, configuration1.getResourceResolver());
configuration1.setTheme("Theme.Light");
final ResourceResolver resolver1b = configuration1.getResourceResolver();
assertNotSame(resolver1b, resolver1);
assertNotSame(resolver1b, resolver2);
assertSame(resolver1b, configuration1.getResourceResolver());
configuration2.setTheme("Theme.Light");
assertSame(resolver1b, configuration2.getResourceResolver());
// Test project resource changes, should invalidate
final LocalResourceRepository resources = myFacet.getModuleResources(true);
assertNotNull(resources);
final long generation = resources.getModificationCount();
assertEquals("Cancel", configuration1.getResourceResolver().findResValue("@string/cancel", false).getValue());
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
@Override
public void run() {
//noinspection ConstantConditions
XmlTagValue value = ((XmlFile) psiFile3).getRootTag().getSubTags()[1].getValue();
assertEquals("Cancel", value.getTrimmedText());
value.setText("\"FooBar\"");
}
});
assertTrue(resources.isScanPending(psiFile3));
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
assertTrue(generation < resources.getModificationCount());
assertNotSame(resolver1b, configuration1.getResourceResolver());
assertEquals("FooBar", configuration1.getResourceResolver().findResValue("@string/cancel", false).getValue());
}
});
ResourceResolverCache cache = configuration1.getConfigurationManager().getResolverCache();
assertSame(cache, configuration2.getConfigurationManager().getResolverCache());
ResourceRepository frameworkResources = cache.getFrameworkResources(configuration1.getFullConfig(), configuration1.getTarget());
assertTrue(frameworkResources instanceof FrameworkResourceLoader.IdeFrameworkResources);
assertTrue(((FrameworkResourceLoader.IdeFrameworkResources) frameworkResources).getSkippedLocales());
}
use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.
the class ThemeEditorUtilsTest method testResourceResolverVisitor.
public void testResourceResolverVisitor() {
myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi-v14.xml", "res/values-v14/styles.xml");
myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi-v19.xml", "res/values-v19/styles.xml");
myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi-v21.xml", "res/values-v21/styles.xml");
final AtomicInteger visitedRepos = new AtomicInteger(0);
// With only one source set, this should be called just once.
ThemeEditorUtils.acceptResourceResolverVisitor(myFacet, new ThemeEditorUtils.ResourceFolderVisitor() {
@Override
public void visitResourceFolder(@NotNull LocalResourceRepository resources, String moduleName, @NotNull String variantName, boolean isSelected) {
assertEquals("main", variantName);
visitedRepos.incrementAndGet();
}
});
assertEquals(1, visitedRepos.get());
// TODO: Test variants
}
use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.
the class ThemeEditorUtilsTest method testCopyTheme.
public void testCopyTheme() {
myFixture.copyFileToProject("themeEditor/styles_1.xml", "res/values/styles.xml");
myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi-v19.xml", "res/values-v19/styles.xml");
LocalResourceRepository repository = AppResourceRepository.getAppResources(myModule, true);
assertNotNull(repository);
List<ResourceItem> resources = repository.getResourceItem(ResourceType.STYLE, "AppTheme");
assertNotNull(resources);
assertFalse(resources.isEmpty());
final XmlTag sourceXml = LocalResourceRepository.getItemTag(getProject(), resources.get(0));
assertNotNull(sourceXml);
new WriteCommandAction.Simple(myModule.getProject(), "Copy a theme") {
@Override
protected void run() throws Throwable {
ThemeEditorUtils.copyTheme(16, sourceXml);
ThemeEditorUtils.copyTheme(19, sourceXml);
}
}.execute();
myFixture.checkResultByFile("res/values-v16/styles.xml", "themeEditor/testCopyTheme/styles-v16.xml", true);
myFixture.checkResultByFile("res/values-v19/styles.xml", "themeEditor/testCopyTheme/styles-v19.xml", true);
}
use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.
the class StringsCellEditorTest method testIsCellEditable.
public void testIsCellEditable() {
Collection<VirtualFile> directories = Collections.singletonList(myFixture.copyDirectoryToProject("stringsEditor/base/res", "res"));
LocalResourceRepository repository = ModuleResourceRepository.createForTest(myFacet, directories);
JTable table = new JBTable(new StringResourceTableModel(StringResourceParser.parse(myFacet, repository)));
TableUtils.selectCellAt(table, 0, StringResourceTableModel.DEFAULT_VALUE_COLUMN);
assertTrue(new StringsCellEditor().isCellEditable(new ActionEvent(table, 0, null)));
}
Aggregations