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;
}
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;
}
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);
}
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();
}
};
}
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));
}
}
Aggregations