@Override public void visitElement(@NonNull XmlContext context, @NonNull Element element) { int declaredRowCount = getInt(element, ATTR_ROW_COUNT, -1); int declaredColumnCount = getInt(element, ATTR_COLUMN_COUNT, -1); int column = getInt(child, ATTR_LAYOUT_COLUMN, -1); if (column >= declaredColumnCount) { Attr node = child.getAttributeNodeNS(ANDROID_URI, ATTR_LAYOUT_COLUMN); int row = getInt(child, ATTR_LAYOUT_ROW, -1); if (row > declaredRowCount) { Attr node = child.getAttributeNodeNS(ANDROID_URI, ATTR_LAYOUT_ROW); ensureAppNamespace(context, element, ATTR_COLUMN_COUNT); ensureAppNamespace(context, element, ATTR_ORIENTATION); ensureAppNamespace(context, element, ATTR_ROW_COUNT); ensureAppNamespace(context, element, ATTR_USE_DEFAULT_MARGINS); ensureAppNamespace(context, element, "alignmentMode"); ensureAppNamespace(context, element, "columnOrderPreserved"); ensureAppNamespace(context, element, "rowOrderPreserved"); ensureAppNamespace(context, child, ATTR_LAYOUT_COLUMN); ensureAppNamespace(context, child, ATTR_LAYOUT_COLUMN_SPAN); ensureAppNamespace(context, child, ATTR_LAYOUT_GRAVITY); ensureAppNamespace(context, child, ATTR_LAYOUT_ROW); ensureAppNamespace(context, child, ATTR_LAYOUT_ROW_SPAN); ensureAppNamespace(context, child, "layout_rowWeight"); ensureAppNamespace(context, child, "layout_columnWeight");
private static void ensureAppNamespace(XmlContext context, Element element, String name) { Attr attribute = element.getAttributeNodeNS(ANDROID_URI, name); if (attribute != null) { String prefix = getNamespacePrefix(element.getOwnerDocument(), AUTO_URI); boolean haveNamespace = prefix != null; if (!haveNamespace) { prefix = "app"; } StringBuilder sb = new StringBuilder(); sb.append("Wrong namespace; with v7 `GridLayout` you should use ").append(prefix) .append(":").append(name); if (!haveNamespace) { sb.append(" (and add `xmlns:app=\"").append(AUTO_URI) .append("\"` to your root element.)"); } String message = sb.toString(); context.report(ISSUE, attribute, context.getLocation(attribute), message); } }
@Override public void visitElement(Context context, Element element) { int declaredRowCount = getInt(element, ATTR_ROW_COUNT, -1); int declaredColumnCount = getInt(element, ATTR_COLUMN_COUNT, -1); if (declaredColumnCount != -1 || declaredRowCount != -1) { for (Element child : LintUtils.getChildren(element)) { if (declaredColumnCount != -1) { int column = getInt(child, ATTR_LAYOUT_COLUMN, -1); if (column >= declaredColumnCount) { Attr node = child.getAttributeNodeNS(ANDROID_URI, ATTR_LAYOUT_COLUMN); context.client.report(context, ISSUE, context.getLocation(node), String.format("Column attribute (%1$d) exceeds declared grid column count (%2$d)", column, declaredColumnCount), null); } } if (declaredRowCount != -1) { int row = getInt(child, ATTR_LAYOUT_ROW, -1); if (row > declaredRowCount) { Attr node = child.getAttributeNodeNS(ANDROID_URI, ATTR_LAYOUT_ROW); context.client.report(context, ISSUE, context.getLocation(node), String.format("Row attribute (%1$d) exceeds declared grid row count (%2$d)", row, declaredRowCount), null); } } } } } }
@Override public void visitElement(@NonNull XmlContext context, @NonNull Element element) { int declaredRowCount = getInt(element, ATTR_ROW_COUNT, -1); int declaredColumnCount = getInt(element, ATTR_COLUMN_COUNT, -1); int column = getInt(child, ATTR_LAYOUT_COLUMN, -1); if (column >= declaredColumnCount) { Attr node = child.getAttributeNodeNS(ANDROID_URI, ATTR_LAYOUT_COLUMN); int row = getInt(child, ATTR_LAYOUT_ROW, -1); if (row > declaredRowCount) { Attr node = child.getAttributeNodeNS(ANDROID_URI, ATTR_LAYOUT_ROW); ensureAppNamespace(context, element, ATTR_COLUMN_COUNT); ensureAppNamespace(context, element, ATTR_ORIENTATION); ensureAppNamespace(context, element, ATTR_ROW_COUNT); ensureAppNamespace(context, element, ATTR_USE_DEFAULT_MARGINS); ensureAppNamespace(context, element, "alignmentMode"); ensureAppNamespace(context, element, "columnOrderPreserved"); ensureAppNamespace(context, element, "rowOrderPreserved"); ensureAppNamespace(context, child, ATTR_LAYOUT_COLUMN); ensureAppNamespace(context, child, ATTR_LAYOUT_COLUMN_SPAN); ensureAppNamespace(context, child, ATTR_LAYOUT_GRAVITY); ensureAppNamespace(context, child, ATTR_LAYOUT_ROW); ensureAppNamespace(context, child, ATTR_LAYOUT_ROW_SPAN); ensureAppNamespace(context, child, "layout_rowWeight"); ensureAppNamespace(context, child, "layout_columnWeight");
private static void ensureAppNamespace(XmlContext context, Element element, String name) { Attr attribute = element.getAttributeNodeNS(ANDROID_URI, name); if (attribute != null) { String prefix = getNamespacePrefix(element.getOwnerDocument(), AUTO_URI); boolean haveNamespace = prefix != null; if (!haveNamespace) { prefix = "app"; } StringBuilder sb = new StringBuilder(); sb.append("Wrong namespace; with v7 `GridLayout` you should use ").append(prefix) .append(":").append(name); if (!haveNamespace) { sb.append(" (and add `xmlns:app=\"").append(AUTO_URI) .append("\"` to your root element.)"); } String message = sb.toString(); context.report(ISSUE, attribute, context.getLocation(attribute), message); } }