use of com.android.resources.ResourceFolderType in project android by JetBrains.
the class ChooseResourceDialog method ensurePickersInitialized.
private void ensurePickersInitialized() {
boolean allowDrawables = allowDrawables();
boolean allowColors = allowColors();
if (allowColors || allowDrawables) {
if (myStateListPicker != null || myColorPicker != null) {
return;
}
Configuration configuration = getConfiguration();
ResourceResolver resolver = configuration.getResourceResolver();
assert resolver != null;
ResourceValue resValue = null;
if (myInitialValue != null) {
resValue = resolver.findResValue(myInitialValue, myInitialValueIsFramework);
}
final ResourceType stateListType;
final ResourceFolderType stateListFolderType;
if (allowDrawables) {
stateListType = ResourceType.DRAWABLE;
stateListFolderType = ResourceFolderType.DRAWABLE;
} else {
stateListType = ResourceType.COLOR;
stateListFolderType = ResourceFolderType.COLOR;
}
initializeStateListPicker(configuration, resolver, resValue, stateListType, stateListFolderType);
initializeColorPicker(myInitialValue, myResourceNameVisibility, resolver, resValue);
}
}
use of com.android.resources.ResourceFolderType in project android by JetBrains.
the class ChooseResourceDialog method createNewResourceFileAction.
@NotNull
private AnAction createNewResourceFileAction() {
return new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
ResourceFolderType type = (ResourceFolderType) getTemplatePresentation().getClientProperty(FOLDER_TYPE_KEY);
createNewResourceFile(type);
}
};
}
use of com.android.resources.ResourceFolderType in project android by JetBrains.
the class IncludeTagCreator method createNewIncludedLayout.
/**
* Create a new layout that will be included as a child of the mockup component
*/
private String createNewIncludedLayout() {
AndroidFacet facet = getMockup().getComponent().getModel().getFacet();
ResourceFolderType folderType = AndroidResourceUtil.XML_FILE_RESOURCE_TYPES.get(ResourceType.LAYOUT);
XmlFile newFile = CreateResourceFileAction.createFileResource(facet, folderType, null, null, null, true, null, null, null, false);
if (newFile == null) {
return null;
}
XmlTag rootTag = newFile.getRootTag();
if (rootTag == null) {
return null;
}
NlModel nlModel = NlModel.create(getScreenView().getSurface(), newFile.getProject(), facet, newFile);
ModelListener listener = new ModelListener() {
@Override
public void modelChanged(@NotNull NlModel model) {
}
@Override
public void modelRendered(@NotNull NlModel model) {
model.removeListener(this);
if (model.getComponents().isEmpty()) {
return;
}
NlComponent component = model.getComponents().get(0);
final AttributesTransaction transaction = component.startAttributeTransaction();
addShowInAttribute(transaction);
addSizeAttributes(transaction, getAndroidBounds());
addMockupAttributes(transaction, getSelectionBounds());
WriteCommandAction.runWriteCommandAction(model.getProject(), (Computable) transaction::commit);
}
@Override
public void modelChangedOnLayout(@NotNull NlModel model, boolean animate) {
// Do nothing
}
};
nlModel.addListener(listener);
nlModel.requestRender();
return getResourceName(newFile);
}
use of com.android.resources.ResourceFolderType in project kotlin by JetBrains.
the class ApiDetector method visitElement.
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
if (mApiDatabase == null) {
return;
}
String tag = element.getTagName();
ResourceFolderType folderType = context.getResourceFolderType();
if (folderType != ResourceFolderType.LAYOUT) {
if (folderType == ResourceFolderType.DRAWABLE) {
checkElement(context, element, TAG_VECTOR, 21, "1.4", UNSUPPORTED);
checkElement(context, element, TAG_RIPPLE, 21, null, UNSUPPORTED);
checkElement(context, element, TAG_ANIMATED_SELECTOR, 21, null, UNSUPPORTED);
checkElement(context, element, TAG_ANIMATED_VECTOR, 21, null, UNSUPPORTED);
checkElement(context, element, "drawable", 24, null, UNSUPPORTED);
if ("layer-list".equals(tag)) {
checkLevelList(context, element);
} else if (tag.contains(".")) {
checkElement(context, element, tag, 24, null, UNSUPPORTED);
}
}
if (element.getParentNode().getNodeType() != Node.ELEMENT_NODE) {
// Root node
return;
}
NodeList childNodes = element.getChildNodes();
for (int i = 0, n = childNodes.getLength(); i < n; i++) {
Node textNode = childNodes.item(i);
if (textNode.getNodeType() == Node.TEXT_NODE) {
String text = textNode.getNodeValue();
if (text.contains(ANDROID_PREFIX)) {
text = text.trim();
// Convert @android:type/foo into android/R$type and "foo"
int index = text.indexOf('/', ANDROID_PREFIX.length());
if (index != -1) {
String typeString = text.substring(ANDROID_PREFIX.length(), index);
if (ResourceType.getEnum(typeString) != null) {
String owner = "android/R$" + typeString;
String name = getResourceFieldName(text.substring(index + 1));
int api = mApiDatabase.getFieldVersion(owner, name);
int minSdk = getMinSdk(context);
if (api > minSdk && api > context.getFolderVersion() && api > getLocalMinSdk(element)) {
Location location = context.getLocation(textNode);
String message = String.format("`%1$s` requires API level %2$d (current min is %3$d)", text, api, minSdk);
context.report(UNSUPPORTED, element, location, message);
}
}
}
}
}
}
} else {
if (VIEW_TAG.equals(tag)) {
tag = element.getAttribute(ATTR_CLASS);
if (tag == null || tag.isEmpty()) {
return;
}
} else {
// TODO: Complain if <tag> is used at the root level!
checkElement(context, element, TAG, 21, null, UNUSED);
}
// Check widgets to make sure they're available in this version of the SDK.
if (tag.indexOf('.') != -1) {
// Custom views aren't in the index
return;
}
//$NON-NLS-1$
String fqn = "android/widget/" + tag;
if (tag.equals("TextureView")) {
//$NON-NLS-1$
//$NON-NLS-1$
fqn = "android/view/TextureView";
}
// TODO: Consider other widgets outside of android.widget.*
int api = mApiDatabase.getClassVersion(fqn);
int minSdk = getMinSdk(context);
if (api > minSdk && api > context.getFolderVersion() && api > getLocalMinSdk(element)) {
Location location = context.getLocation(element);
String message = String.format("View requires API level %1$d (current min is %2$d): `<%3$s>`", api, minSdk, tag);
context.report(UNSUPPORTED, element, location, message);
}
}
}
use of com.android.resources.ResourceFolderType in project kotlin by JetBrains.
the class OverdrawDetector method beforeCheckFile.
@Override
public void beforeCheckFile(@NonNull Context context) {
if (endsWith(context.file.getName(), DOT_XML)) {
// Drawable XML files should not be considered for overdraw, except for <bitmap>'s.
// The bitmap elements are handled in the scanBitmap() method; it will clear
// out anything added by this method.
File parent = context.file.getParentFile();
ResourceFolderType type = ResourceFolderType.getFolderType(parent.getName());
if (type == ResourceFolderType.DRAWABLE) {
if (mValidDrawables == null) {
mValidDrawables = new ArrayList<String>();
}
String resource = getDrawableResource(context.file);
mValidDrawables.add(resource);
}
}
}
Aggregations