Search in sources :

Example 1 with ResourceItemResolver

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

the class ResourceDrawablePanel method updateResolutionChain.

private void updateResolutionChain(@NotNull ResourceChooserItem item) {
    // Resource resolver
    myResolvedPanel.removeAll();
    ResourceValue resourceValue = item.getResourceValue();
    Configuration configuration = myDialog.getConfiguration();
    ResourceRepository frameworkResources = configuration.getFrameworkResources();
    if (frameworkResources != null) {
        AppResourceRepository appResources = AppResourceRepository.getAppResources(myDialog.geFacet(), true);
        ResourceItemResolver resolver = new ResourceItemResolver(configuration.getFullConfig(), frameworkResources, appResources, null);
        List<ResourceValue> lookupChain = Lists.newArrayList();
        lookupChain.add(resourceValue);
        resolver.setLookupChainList(lookupChain);
        resolver.resolveResValue(resourceValue);
        String prev = null;
        int indent = 0;
        if (lookupChain.size() >= 2) {
            for (ResourceValue element : lookupChain) {
                if (element == null) {
                    continue;
                }
                String value = element.getValue();
                if (value == null) {
                    continue;
                }
                String text = value;
                if (text.equals(prev)) {
                    continue;
                }
                // Strip paths
                if (!(text.startsWith(PREFIX_THEME_REF) || text.startsWith(PREFIX_RESOURCE_REF))) {
                    if (indent == 0) {
                        break;
                    }
                    int end = Math.max(text.lastIndexOf('/'), text.lastIndexOf('\\'));
                    if (end != -1) {
                        text = text.substring(end + 1);
                    }
                }
                if (indent > 0) {
                    // 21D2: Rightwards arrow
                    text = "⇒ " + text;
                }
                JBLabel label = new JBLabel(text);
                label.setBorder(IdeBorderFactory.createEmptyBorder(0, JBUI.scale(indent * 12), 0, 0));
                myResolvedPanel.add(label);
                indent++;
                prev = value;
            }
        }
    }
}
Also used : FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) JBLabel(com.intellij.ui.components.JBLabel) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) ResourceItemResolver(com.android.ide.common.resources.ResourceItemResolver) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) ResourceRepository(com.android.ide.common.resources.ResourceRepository)

Aggregations

ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 ResourceItemResolver (com.android.ide.common.resources.ResourceItemResolver)1 ResourceRepository (com.android.ide.common.resources.ResourceRepository)1 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)1 Configuration (com.android.tools.idea.configurations.Configuration)1 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)1 JBLabel (com.intellij.ui.components.JBLabel)1