Search in sources :

Example 1 with Configurable

use of com.android.ide.common.resources.configuration.Configurable in project android by JetBrains.

the class ResolutionUtils method getFolderConfiguration.

/**
   * Gets the {@link FolderConfiguration} of a ResourceValue
   * e.g. if we resolve a drawable using a mdpi configuration, yet that drawable only exists inside xhdpi, this method will return xhdpi
   * @param configuration the FolderConfiguration that was used for resolving the ResourceValue
   * @return the FolderConfiguration of the ResourceValue
   */
@NotNull
public static FolderConfiguration getFolderConfiguration(@NotNull AndroidFacet facet, @NotNull ResourceValue resolvedValue, @NotNull FolderConfiguration configuration) {
    List<? extends Configurable> configurables;
    if (resolvedValue.isFramework()) {
        ConfigurationManager configurationManager = facet.getConfigurationManager();
        // same as getHighestApiTarget();
        IAndroidTarget target = configurationManager.getDefaultTarget();
        assert target != null;
        ResourceRepository resourceRepository = configurationManager.getResolverCache().getFrameworkResources(configuration, target);
        assert resourceRepository != null;
        ResourceItem resourceItem = resourceRepository.getResourceItem(resolvedValue.getResourceType(), resolvedValue.getName());
        configurables = resourceItem.getSourceFileList();
    } else {
        AppResourceRepository appResourceRepository = facet.getAppResources(true);
        configurables = appResourceRepository.getResourceItem(resolvedValue.getResourceType(), resolvedValue.getName());
    }
    Configurable configurable = configuration.findMatchingConfigurable(configurables);
    assert configurable != null;
    return configurable.getConfiguration();
}
Also used : AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) IAndroidTarget(com.android.sdklib.IAndroidTarget) Configurable(com.android.ide.common.resources.configuration.Configurable) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) ResourceRepository(com.android.ide.common.resources.ResourceRepository) ResourceItem(com.android.ide.common.resources.ResourceItem) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Configurable

use of com.android.ide.common.resources.configuration.Configurable in project android by JetBrains.

the class ThemeAttributeResolver method resolveAll.

@NotNull
private List<EditedStyleItem> resolveAll() {
    ThemeEditorStyle theme = new ThemeEditorStyle(myManager, myStyle.getQualifiedName());
    for (FolderConfiguration folder : theme.getFolders()) {
        resolveFromInheritance(myStyle, folder, new RestrictedConfiguration(), new HashSet<String>());
    }
    List<EditedStyleItem> result = Lists.newArrayList();
    FolderConfiguration configuration = myStyle.getConfiguration().getFullConfig();
    for (String key : myItemValueMap.keySet()) {
        Collection<ConfiguredElement<ItemResourceValue>> itemValues = myItemValueMap.get(key);
        final ConfiguredElement<ItemResourceValue> selectedValue = (ConfiguredElement<ItemResourceValue>) configuration.findMatchingConfigurable(Lists.<Configurable>newArrayList(itemValues));
        if (selectedValue == null) {
            // TODO: there is NO value for this attribute in the current config,so instead we need to show "no value for current device"
            result.add(new EditedStyleItem(itemValues.iterator().next(), itemValues, myStyle));
        } else {
            itemValues.remove(selectedValue);
            assert !itemValues.contains(selectedValue);
            result.add(new EditedStyleItem(selectedValue, itemValues, myStyle));
        }
    }
    return result;
}
Also used : ConfiguredElement(com.android.tools.idea.editors.theme.datamodels.ConfiguredElement) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ThemeEditorStyle) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configurable(com.android.ide.common.resources.configuration.Configurable) RestrictedConfiguration(com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Configurable (com.android.ide.common.resources.configuration.Configurable)2 NotNull (org.jetbrains.annotations.NotNull)2 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)1 ResourceItem (com.android.ide.common.resources.ResourceItem)1 ResourceRepository (com.android.ide.common.resources.ResourceRepository)1 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)1 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)1 ConfiguredElement (com.android.tools.idea.editors.theme.datamodels.ConfiguredElement)1 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)1 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)1 ThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ThemeEditorStyle)1 RestrictedConfiguration (com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration)1 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)1