Search in sources :

Example 11 with ResourceFolderType

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

the class ResourceManager method processFileResources.

public boolean processFileResources(@NotNull ResourceFolderType folderType, @NotNull FileResourceProcessor processor, boolean withDependencies, boolean publicOnly) {
    final VirtualFile[] resDirs;
    if (withDependencies) {
        resDirs = getAllResourceDirs();
    } else {
        List<VirtualFile> resourceDirs = getResourceDirs();
        resDirs = resourceDirs.toArray(new VirtualFile[resourceDirs.size()]);
    }
    for (VirtualFile resSubdir : AndroidResourceUtil.getResourceSubdirs(folderType, resDirs)) {
        final ResourceFolderType resType = ResourceFolderType.getFolderType(resSubdir.getName());
        if (resType != null) {
            assert folderType.equals(resType);
            String resTypeName = resType.getName();
            for (VirtualFile resFile : resSubdir.getChildren()) {
                final String resName = AndroidCommonUtils.getResourceName(resTypeName, resFile.getName());
                if (!resFile.isDirectory() && (!publicOnly || isResourcePublic(resTypeName, resName))) {
                    if (!processor.process(resFile, resName)) {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ResourceFolderType(com.android.resources.ResourceFolderType)

Example 12 with ResourceFolderType

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

the class AndroidLintNewApiInspection method getApiDetectorFixes.

public static AndroidLintQuickFix[] getApiDetectorFixes(@NotNull Issue issue, @NotNull PsiElement startElement, @SuppressWarnings("UnusedParameters") @NotNull PsiElement endElement, @NotNull String message) {
    // TODO: Return one for each parent context (declaration, method, class, outer class(es)
    int api = ApiDetector.getRequiredVersion(issue, message, RAW);
    if (api != -1) {
        List<AndroidLintQuickFix> list = Lists.newArrayList();
        PsiFile file = startElement.getContainingFile();
        boolean isXml = false;
        if (file instanceof XmlFile) {
            isXml = true;
            ResourceFolderType folderType = ResourceHelper.getFolderType(file);
            if (folderType != null) {
                FolderConfiguration config = ResourceHelper.getFolderConfiguration(file);
                if (config != null) {
                    config.setVersionQualifier(new VersionQualifier(api));
                    String folder = config.getFolderName(folderType);
                    list.add(OverrideResourceAction.createFix(folder));
                }
            }
        }
        list.add(new AddTargetVersionCheckQuickFix(api));
        list.add(new AddTargetApiQuickFix(api, false, startElement));
        ApplicationManager.getApplication().assertReadAccessAllowed();
        Project project = startElement.getProject();
        if (!isXml && JavaPsiFacade.getInstance(project).findClass(REQUIRES_API_ANNOTATION, GlobalSearchScope.allScope(project)) != null) {
            list.add(new AddTargetApiQuickFix(api, true, startElement));
        }
        return list.toArray(new AndroidLintQuickFix[list.size()]);
    }
    return AndroidLintQuickFix.EMPTY_ARRAY;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) AndroidLintQuickFix(org.jetbrains.android.inspections.lint.AndroidLintQuickFix) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Project(com.intellij.openapi.project.Project) ResourceFolderType(com.android.resources.ResourceFolderType) PsiFile(com.intellij.psi.PsiFile)

Example 13 with ResourceFolderType

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

the class ChooseResourceDialog method createNewResourcePopupMenu.

private ActionPopupMenu createNewResourcePopupMenu() {
    ActionManager actionManager = ActionManager.getInstance();
    DefaultActionGroup actionGroup = new DefaultActionGroup();
    ResourcePanel panel = getSelectedPanel();
    ResourceType resourceType = panel.getType();
    ResourceFolderType folderType = AndroidResourceUtil.XML_FILE_RESOURCE_TYPES.get(resourceType);
    if (folderType != null) {
        AnAction newFileAction = createNewResourceFileAction();
        newFileAction.getTemplatePresentation().setText("New " + folderType.getName() + " File...");
        newFileAction.getTemplatePresentation().putClientProperty(FOLDER_TYPE_KEY, folderType);
        actionGroup.add(newFileAction);
    }
    if (AndroidResourceUtil.VALUE_RESOURCE_TYPES.contains(resourceType)) {
        String title = "New " + resourceType + " Value...";
        if (resourceType == ResourceType.LAYOUT) {
            title = "New Layout Alias";
        }
        AnAction newValueAction = createNewResourceValueAction();
        newValueAction.getTemplatePresentation().setText(title);
        newValueAction.getTemplatePresentation().putClientProperty(TYPE_KEY, resourceType);
        actionGroup.add(newValueAction);
    }
    if (myTag != null && ResourceType.STYLE.equals(resourceType)) {
        final boolean enabled = AndroidBaseLayoutRefactoringAction.getLayoutViewElement(myTag) != null && AndroidExtractStyleAction.doIsEnabled(myTag);
        AnAction extractStyleAction = createExtractStyleAction();
        extractStyleAction.getTemplatePresentation().setEnabled(enabled);
        actionGroup.add(extractStyleAction);
    }
    if (GraphicalResourceRendererEditor.COLORS_AND_DRAWABLES.contains(resourceType)) {
        AnAction newReferenceAction = createNewResourceReferenceAction();
        newReferenceAction.getTemplatePresentation().setText("New " + resourceType + " Reference...");
        actionGroup.add(newReferenceAction);
    }
    return actionManager.createActionPopupMenu(ActionPlaces.UNKNOWN, actionGroup);
}
Also used : CreateXmlResourcePanel(org.jetbrains.android.actions.CreateXmlResourcePanel) ResourceFolderType(com.android.resources.ResourceFolderType) ResourceType(com.android.resources.ResourceType)

Example 14 with ResourceFolderType

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

the class CreateResourceFileDialogBase method setupDeviceConfigurationPanel.

protected DeviceConfiguratorPanel setupDeviceConfigurationPanel(final JTextField directoryNameTextField, final TemplateKindCombo resourceTypeCombo, final JBLabel errorLabel) {
    return new DeviceConfiguratorPanel() {

        @Override
        public void applyEditors() {
            try {
                doApplyEditors();
                final FolderConfiguration config = this.getConfiguration();
                final CreateTypedResourceFileAction selectedAction = getSelectedAction(resourceTypeCombo);
                errorLabel.setText("");
                directoryNameTextField.setText("");
                if (selectedAction != null) {
                    final ResourceFolderType resFolderType = selectedAction.getResourceFolderType();
                    directoryNameTextField.setText(config.getFolderName(resFolderType));
                }
            } catch (InvalidOptionValueException e) {
                errorLabel.setText(new HtmlBuilder().openHtmlBody().coloredText(JBColor.RED, e.getMessage()).closeHtmlBody().getHtml());
                directoryNameTextField.setText("");
            }
            updateOkAction();
        }
    };
}
Also used : ResourceFolderType(com.android.resources.ResourceFolderType) HtmlBuilder(com.android.utils.HtmlBuilder) InvalidOptionValueException(org.jetbrains.android.uipreview.InvalidOptionValueException) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) DeviceConfiguratorPanel(org.jetbrains.android.uipreview.DeviceConfiguratorPanel)

Example 15 with ResourceFolderType

use of com.android.resources.ResourceFolderType 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)

Aggregations

ResourceFolderType (com.android.resources.ResourceFolderType)46 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)10 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 NotNull (org.jetbrains.annotations.NotNull)10 ResourceType (com.android.resources.ResourceType)8 XmlFile (com.intellij.psi.xml.XmlFile)8 File (java.io.File)8 PsiFile (com.intellij.psi.PsiFile)7 Nullable (org.jetbrains.annotations.Nullable)7 PsiDirectory (com.intellij.psi.PsiDirectory)6 Module (com.intellij.openapi.module.Module)5 XmlTag (com.intellij.psi.xml.XmlTag)5 Configuration (com.android.tools.idea.configurations.Configuration)3 PsiElement (com.intellij.psi.PsiElement)3 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)2 VersionQualifier (com.android.ide.common.resources.configuration.VersionQualifier)2 HtmlBuilder (com.android.utils.HtmlBuilder)2 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 Project (com.intellij.openapi.project.Project)2