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