Search in sources :

Example 46 with ResourceType

use of com.android.resources.ResourceType in project android by JetBrains.

the class ChooseResourceDialog method selectResourceValue.

private void selectResourceValue(@Nullable ResourceValue resValue) {
    // initial selection
    if (resValue != null) {
        ResourcePanel panel = getSelectedPanel();
        if (panel.select(resValue)) {
            return;
        }
        // Selection not found in the current panel: switch tab to show it
        ResourceType type;
        if (resValue instanceof ItemResourceValue) {
            // type is always null for ItemResourceValue
            type = ResolutionUtils.getAttrType((ItemResourceValue) resValue, myConfiguration);
        } else {
            type = resValue.getResourceType();
        }
        // panel is null if the reference is incorrect, e.g. "@sdfgsdfgs" (user error).
        if (type != null) {
            panel = getPanel(myTabbedPane, type);
            if (panel != null) {
                if (myTabbedPane != null) {
                    myTabbedPane.setSelectedComponent(panel.myComponent.getParent());
                }
                if (!panel.select(resValue) && type == ResourceType.COLOR) {
                    // You might have selected a private framework color; we *can* edit these
                    panel.showPreview(null, true);
                }
            }
        }
    }
}
Also used : CreateXmlResourcePanel(org.jetbrains.android.actions.CreateXmlResourcePanel) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ResourceType(com.android.resources.ResourceType)

Example 47 with ResourceType

use of com.android.resources.ResourceType in project android by JetBrains.

the class ChooseResourceDialog method getSelectedPanel.

@NotNull
private ResourcePanel getSelectedPanel() {
    if (myTabbedPane != null) {
        JPanel selectedComponent = (JPanel) myTabbedPane.getSelectedComponent();
        ResourceType type = (ResourceType) selectedComponent.getClientProperty(ResourceType.class);
        return getPanel(myTabbedPane, type);
    } else {
        // Just one type
        return getPanel(null, myTypes.iterator().next());
    }
}
Also used : ResourceType(com.android.resources.ResourceType) NotNull(org.jetbrains.annotations.NotNull)

Example 48 with ResourceType

use of com.android.resources.ResourceType in project android by JetBrains.

the class ChooseResourceDialog method createNewResourceValueAction.

@NotNull
private AnAction createNewResourceValueAction() {
    return new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            ResourceType type = (ResourceType) getTemplatePresentation().getClientProperty(TYPE_KEY);
            createNewResourceValue(type);
        }
    };
}
Also used : ResourceType(com.android.resources.ResourceType) NotNull(org.jetbrains.annotations.NotNull)

Example 49 with ResourceType

use of com.android.resources.ResourceType in project android by JetBrains.

the class AndroidResourceQuickFixProvider method registerFixes.

@Override
public void registerFixes(@NotNull PsiReferenceExpression exp, @NotNull QuickFixActionRegistrar registrar) {
    Module contextModule = ModuleUtilCore.findModuleForPsiElement(exp);
    if (contextModule == null) {
        return;
    }
    AndroidFacet facet = AndroidFacet.getInstance(contextModule);
    if (facet == null) {
        return;
    }
    final PsiFile contextFile = exp.getContainingFile();
    if (contextFile == null) {
        return;
    }
    AndroidResourceUtil.MyReferredResourceFieldInfo info = AndroidResourceUtil.getReferredResourceOrManifestField(facet, exp, true);
    if (info == null) {
        final PsiElement parent = exp.getParent();
        if (parent instanceof PsiReferenceExpression) {
            info = AndroidResourceUtil.getReferredResourceOrManifestField(facet, (PsiReferenceExpression) parent, true);
        }
    }
    if (info == null || info.isFromManifest()) {
        return;
    }
    final String resClassName = info.getClassName();
    final String resFieldName = info.getFieldName();
    Module resolvedModule = info.getResolvedModule();
    if (resolvedModule != null && resolvedModule != contextModule) {
        AndroidFacet resolvedFacet = AndroidFacet.getInstance(resolvedModule);
        if (resolvedFacet != null) {
            facet = resolvedFacet;
        }
    }
    ResourceType resourceType = ResourceType.getEnum(resClassName);
    if (AndroidResourceUtil.ALL_VALUE_RESOURCE_TYPES.contains(resourceType)) {
        registrar.register(new CreateValueResourceQuickFix(facet, resourceType, resFieldName, contextFile, true));
    }
    ResourceFolderType folderType = AndroidResourceUtil.XML_FILE_RESOURCE_TYPES.get(resourceType);
    if (folderType != null) {
        registrar.register(new CreateFileResourceQuickFix(facet, folderType, resFieldName, contextFile, true));
    }
}
Also used : AndroidResourceUtil(org.jetbrains.android.util.AndroidResourceUtil) ResourceFolderType(com.android.resources.ResourceFolderType) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiFile(com.intellij.psi.PsiFile) ResourceType(com.android.resources.ResourceType) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) PsiElement(com.intellij.psi.PsiElement)

Example 50 with ResourceType

use of com.android.resources.ResourceType in project android by JetBrains.

the class ResolutionUtils method getAttrType.

@Nullable
public static /*if we can't work out the type, e.g a 'reference' with a '@null' value or enum*/
ResourceType getAttrType(@NotNull ItemResourceValue item, @NotNull Configuration configuration) {
    ResourceResolver resolver = configuration.getResourceResolver();
    assert resolver != null;
    ResourceValue resolvedValue = resolver.resolveResValue(item);
    ResourceType attrType = resolvedValue.getResourceType();
    if (attrType != null) {
        return attrType;
    } else {
        AttributeDefinition def = getAttributeDefinition(configuration, item);
        if (def != null) {
            for (AttributeFormat attrFormat : def.getFormats()) {
                attrType = AndroidDomUtil.getResourceType(attrFormat);
                if (attrType != null) {
                    return attrType;
                }
            }
        }
    }
    // sometimes we won't find the type of the attr, this means it's either a reference that points to @null, or a enum
    return null;
}
Also used : AttributeFormat(org.jetbrains.android.dom.attrs.AttributeFormat) ResourceResolver(com.android.ide.common.resources.ResourceResolver) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) ResourceType(com.android.resources.ResourceType) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ResourceType (com.android.resources.ResourceType)137 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)31 NotNull (org.jetbrains.annotations.NotNull)16 Field (java.lang.reflect.Field)13 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)12 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 Map (java.util.Map)10 Nullable (org.jetbrains.annotations.Nullable)10 Nullable (com.android.annotations.Nullable)8 ResourceFolderType (com.android.resources.ResourceFolderType)8 File (java.io.File)8 EnumMap (java.util.EnumMap)7 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)7 Context (android.content.Context)6 View (android.view.View)6 AbsListView (android.widget.AbsListView)6 AdapterView (android.widget.AdapterView)6 ExpandableListView (android.widget.ExpandableListView)6 FrameLayout (android.widget.FrameLayout)6