use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.
the class ResourceFoldingBuilder method createdInlinedResource.
private static InlinedResource createdInlinedResource(@NotNull ResourceType type, @NotNull String name, @NotNull PsiElement foldElement) {
// Not part of a call: just fold the R.string reference itself
LocalResourceRepository appResources = getAppResources(foldElement);
if (appResources != null && appResources.hasResourceItem(type, name)) {
ASTNode node = foldElement.getNode();
if (node != null) {
TextRange textRange = foldElement.getTextRange();
HashSet<Object> dependencies = new HashSet<Object>();
dependencies.add(foldElement);
FoldingDescriptor descriptor = new FoldingDescriptor(node, textRange, null, dependencies);
InlinedResource inlinedResource = new InlinedResource(type, name, appResources, descriptor, foldElement);
dependencies.add(inlinedResource);
return inlinedResource;
}
}
return NONE;
}
use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.
the class LintIdeViewTypeDetector method getViewTags.
@Nullable
@Override
protected Collection<String> getViewTags(@NonNull Context context, @NonNull ResourceItem item) {
AbstractResourceRepository projectResources = context.getClient().getProjectResources(context.getMainProject(), true);
assert projectResources instanceof LocalResourceRepository : projectResources;
LocalResourceRepository repository = (LocalResourceRepository) projectResources;
String viewTag = repository.getViewTag(item);
if (viewTag != null) {
return Collections.singleton(viewTag);
}
return super.getViewTags(context, item);
}
use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.
the class Configuration method create.
/**
* Creates a configuration suitable for the given file
*
* @param base the base configuration to base the file configuration off of
* @param file the file to look up a configuration for
* @return a suitable configuration
*/
@NotNull
public static Configuration create(@NotNull Configuration base, @NotNull VirtualFile file) {
// TODO: Figure out whether we need this, or if it should be replaced by
// a call to ConfigurationManager#createSimilar()
Configuration configuration = base.clone();
LocalResourceRepository resources = AppResourceRepository.getAppResources(base.getModule(), true);
ConfigurationMatcher matcher = new ConfigurationMatcher(configuration, resources, file);
configuration.getEditedConfig().set(FolderConfiguration.getConfigForFolder(file.getParent().getName()));
matcher.adaptConfigSelection(true);
return configuration;
}
use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.
the class Configuration method copyCompatible.
/**
* Copies attributes from the given source configuration into the given destination configuration,
* as long as the attributes are compatible with the folder of the destination file.
*
* @param source the original to copy from
* @return a new configuration copied from the original
*/
@NotNull
public static Configuration copyCompatible(@NotNull Configuration source, @NotNull Configuration destination) {
// This method is intended to sync configurations for resource variations
assert !Comparing.equal(source.myFile, destination.myFile);
FolderConfiguration editedConfig = destination.getEditedConfig();
if (editedConfig.getVersionQualifier() == null) {
// avoid getTarget() since it fetches project state
destination.myTarget = source.myTarget;
}
if (editedConfig.getScreenSizeQualifier() == null) {
// avoid getDevice() since it fetches project state
destination.mySpecificDevice = source.mySpecificDevice;
}
if (editedConfig.getScreenOrientationQualifier() == null && editedConfig.getSmallestScreenWidthQualifier() == null) {
destination.myStateName = source.myStateName;
destination.myState = source.myState;
}
if (editedConfig.getLocaleQualifier() == null) {
// avoid getLocale() since it fetches project state
destination.myLocale = source.myLocale;
}
if (editedConfig.getUiModeQualifier() == null) {
destination.myUiMode = source.getUiMode();
}
if (editedConfig.getNightModeQualifier() == null) {
destination.myNightMode = source.getNightMode();
}
destination.myActivity = source.getActivity();
destination.myTheme = source.getTheme();
//destination.myDisplayName = source.getDisplayName();
LocalResourceRepository resources = AppResourceRepository.getAppResources(source.myManager.getModule(), true);
ConfigurationMatcher matcher = new ConfigurationMatcher(destination, resources, destination.myFile);
//if (!matcher.isCurrentFileBestMatchFor(editedConfig)) {
matcher.adaptConfigSelection(true);
return destination;
}
use of com.android.tools.idea.res.LocalResourceRepository in project android by JetBrains.
the class ConfigurationManager method getLocales.
@NotNull
public List<Locale> getLocales() {
// Get locales from modules, but not libraries!
LocalResourceRepository projectResources = ProjectResourceRepository.getProjectResources(myModule, true);
assert projectResources != null;
if (projectResources.getModificationCount() != myLocaleCacheStamp) {
myLocales = null;
}
if (myLocales == null) {
List<Locale> locales = new ArrayList<Locale>();
for (LocaleQualifier locale : projectResources.getLocales()) {
locales.add(Locale.create(locale));
}
myLocales = locales;
myLocaleCacheStamp = projectResources.getModificationCount();
}
return myLocales;
}
Aggregations