本文整理汇总了Java中com.android.tools.lint.detector.api.LintUtils.getChildren方法的典型用法代码示例。如果您正苦于以下问题:Java LintUtils.getChildren方法的具体用法?Java LintUtils.getChildren怎么用?Java LintUtils.getChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.tools.lint.detector.api.LintUtils
的用法示例。
在下文中一共展示了LintUtils.getChildren方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitElement
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
if (mPrefix == null || context.getResourceFolderType() != ResourceFolderType.VALUES) {
return;
}
for (Element item : LintUtils.getChildren(element)) {
Attr nameAttribute = item.getAttributeNode(ATTR_NAME);
if (nameAttribute != null) {
String name = nameAttribute.getValue();
if (!name.startsWith(mPrefix)) {
String message = getErrorMessage(name);
context.report(ISSUE, nameAttribute, context.getLocation(nameAttribute),
message);
}
}
}
}
示例2: isWearableBindListener
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
private static boolean isWearableBindListener(@NonNull Element element) {
// Checks whether a service has an Android Wear bind listener
for (Element child : LintUtils.getChildren(element)) {
if (child.getTagName().equals(TAG_INTENT_FILTER)) {
for (Element innerChild : LintUtils.getChildren(child)) {
if (innerChild.getTagName().equals(NODE_ACTION)) {
String name = innerChild.getAttributeNS(ANDROID_URI, ATTR_NAME);
if ("com.google.android.gms.wearable.BIND_LISTENER".equals(name)) {
return true;
}
}
}
}
}
return false;
}
示例3: isStandardReceiver
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
private static boolean isStandardReceiver(Element element) {
// Play Services also the following receiver which we'll consider standard
// in the sense that it doesn't require a separate permission
String name = element.getAttributeNS(ANDROID_URI, ATTR_NAME);
if ("com.google.android.gms.tagmanager.InstallReferrerReceiver".equals(name)) {
return true;
}
// Checks whether a broadcast receiver receives a standard Android action
for (Element child : LintUtils.getChildren(element)) {
if (child.getTagName().equals(TAG_INTENT_FILTER)) {
for (Element innerChild : LintUtils.getChildren(child)) {
if (innerChild.getTagName().equals(NODE_ACTION)) {
String categoryString = innerChild.getAttributeNS(ANDROID_URI, ATTR_NAME);
return categoryString.startsWith("android."); //$NON-NLS-1$
}
}
}
}
return false;
}
示例4: visitElement
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
List<Element> children = LintUtils.getChildren(element);
boolean isHorizontal = HORIZONTAL_SCROLL_VIEW.equals(element.getTagName());
String attributeName = isHorizontal ? ATTR_LAYOUT_WIDTH : ATTR_LAYOUT_HEIGHT;
for (Element child : children) {
Attr sizeNode = child.getAttributeNodeNS(ANDROID_URI, attributeName);
if (sizeNode == null) {
return;
}
String value = sizeNode.getValue();
if (VALUE_FILL_PARENT.equals(value) || VALUE_MATCH_PARENT.equals(value)) {
String msg = String.format("This %1$s should use `android:%2$s=\"wrap_content\"`",
child.getTagName(), attributeName);
context.report(ISSUE, sizeNode, context.getLocation(sizeNode), msg);
}
}
}
示例5: getExported
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
public static boolean getExported(Element element) {
// Used to check whether an activity, service or broadcast receiver is exported.
String exportValue = element.getAttributeNS(ANDROID_URI, ATTR_EXPORTED);
if (exportValue != null && !exportValue.isEmpty()) {
return Boolean.valueOf(exportValue);
} else {
for (Element child : LintUtils.getChildren(element)) {
if (child.getTagName().equals(TAG_INTENT_FILTER)) {
return true;
}
}
}
return false;
}
示例6: isButtonId
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
/** Is the given target id the id of a {@code <Button>} within this RelativeLayout? */
private static boolean isButtonId(Element parent, String targetId) {
for (Element child : LintUtils.getChildren(parent)) {
String id = child.getAttributeNS(ANDROID_URI, ATTR_ID);
if (LintUtils.idReferencesMatch(id, targetId)) {
return child.getTagName().equals(BUTTON);
}
}
return false;
}
示例7: visitElement
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
int childCount = LintUtils.getChildCount(element);
if (childCount == 2) {
List<Element> children = LintUtils.getChildren(element);
Element first = children.get(0);
Element second = children.get(1);
if ((first.getTagName().equals(IMAGE_VIEW) &&
second.getTagName().equals(TEXT_VIEW) &&
!first.hasAttributeNS(ANDROID_URI, ATTR_LAYOUT_WEIGHT)) ||
((second.getTagName().equals(IMAGE_VIEW) &&
first.getTagName().equals(TEXT_VIEW) &&
!second.hasAttributeNS(ANDROID_URI, ATTR_LAYOUT_WEIGHT)))) {
// If the layout has a background, ignore since it would disappear from
// the TextView
if (element.hasAttributeNS(ANDROID_URI, ATTR_BACKGROUND)) {
return;
}
// Certain scale types cannot be done with compound drawables
String scaleType = first.getTagName().equals(IMAGE_VIEW)
? first.getAttributeNS(ANDROID_URI, ATTR_SCALE_TYPE)
: second.getAttributeNS(ANDROID_URI, ATTR_SCALE_TYPE);
if (scaleType != null && !scaleType.isEmpty()) {
// For now, ignore if any scale type is set
return;
}
context.report(ISSUE, element, context.getLocation(element),
"This tag and its children can be replaced by one `<TextView/>` and " +
"a compound drawable");
}
}
}
示例8: visitElement
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
@Override
public void visitElement(XmlContext context, Element activityNode) {
boolean isMPReceiver = false;
boolean hasInstallReferrerIntentFilter = false;
if (TAG_RECEIVER.equals(activityNode.getNodeName())) {
String receiverName = activityNode.getAttributeNodeNS(ANDROID_URI, ATTR_NAME).getValue();
if (MP_RECEIVER_NAME.equals(receiverName)) {
isMPReceiver = true;
mMPReceiverCount++;
}
for (Element activityChild : LintUtils.getChildren(activityNode)) {
if (TAG_INTENT_FILTER.equals(activityChild.getNodeName())) {
for (Element intentFilterChild : LintUtils.getChildren(activityChild)) {
if (NODE_ACTION.equals(intentFilterChild.getNodeName())
&& ACTION_INSTALL_REFERRER.equals(
intentFilterChild.getAttributeNS(ANDROID_URI, ATTR_NAME))) {
hasInstallReferrerIntentFilter = true;
if (!isMPReceiver) {
context.report(ISSUE, context.getLocation(activityNode), MESSAGE_INTENT_FILTER_WRONG_RECEIVER);
}
}
}
}
}
if (isMPReceiver && !hasInstallReferrerIntentFilter) {
context.report(ISSUE, context.getLocation(activityNode), MESSAGE_MP_RECEIVER_MISSING_INTENT_FILTER);
}
}
}
示例9: isMainActivity
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
/**
* Returns true if the XML node is an activity with a launcher intent.
*
* @param node is the node to check.
* @return true if the node is an activity with a launcher intent, false if not.
*/
private boolean isMainActivity(XmlContext context, Node node) {
if (TAG_APPLICATION.equals(node.getNodeName())) {
mApplicationTagLocation = context.getLocation(node);
}
if (TAG_ACTIVITY.equals(node.getNodeName())) {
mHasActivity = true;
for (Element activityChild : LintUtils.getChildren(node)) {
if (TAG_INTENT_FILTER.equals(activityChild.getNodeName())) {
boolean hasLauncherCategory = false;
boolean hasMainAction = false;
for (Element intentFilterChild : LintUtils.getChildren(activityChild)) {
// Check for category tag)
if (NODE_CATEGORY.equals(intentFilterChild.getNodeName())
&& Constants.CATEGORY_NAME_LAUNCHER.equals(
intentFilterChild.getAttributeNS(ANDROID_URI, ATTR_NAME))) {
hasLauncherCategory = true;
}
// Check for action tag
if (NODE_ACTION.equals(intentFilterChild.getNodeName())
&& Constants.ACTION_NAME_MAIN.equals(
intentFilterChild.getAttributeNS(ANDROID_URI, ATTR_NAME))) {
hasMainAction = true;
}
}
if (hasLauncherCategory && hasMainAction) {
if (mHasLauncherActivity) {
context.report(ISSUE_MORE_THAN_ONE_LAUNCHER, context.getLocation(node),
"Expecting " + ANDROID_MANIFEST_XML + " to have only one activity with a launcher intent.");
}
// if it is a library
if (context.getProject() == context.getMainProject() && context.getMainProject().isLibrary()) {
context.report(ISSUE_LAUNCHER_ACTIVITY_IN_LIBRARY, context.getLocation(node),
"Expecting " + ANDROID_MANIFEST_XML + " not to have an activity with a launcher intent.");
}
return true;
}
}
}
}
return false;
}
示例10: checkProvider
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
private static void checkProvider(XmlContext context, Element element) {
String exportValue = element.getAttributeNS(ANDROID_URI, ATTR_EXPORTED);
// Content providers are exported by default
boolean exported = true;
if (exportValue != null && !exportValue.isEmpty()) {
exported = Boolean.valueOf(exportValue);
}
if (exported) {
// Just check for some use of permissions. Other Lint checks can check the saneness
// of the permissions. We'll accept the permission, readPermission, or writePermission
// attributes on the provider element, or a path-permission element.
String permission = element.getAttributeNS(ANDROID_URI, ATTR_READ_PERMISSION);
if (permission == null || permission.isEmpty()) {
permission = element.getAttributeNS(ANDROID_URI, ATTR_WRITE_PERMISSION);
if (permission == null || permission.isEmpty()) {
permission = element.getAttributeNS(ANDROID_URI, ATTR_PERMISSION);
if (permission == null || permission.isEmpty()) {
// No permission attributes? Check for path-permission.
// TODO: Add a Lint check to ensure the path-permission is good, similar to
// the grant-uri-permission check.
boolean hasPermission = false;
for (Element child : LintUtils.getChildren(element)) {
String tag = child.getTagName();
if (tag.equals(TAG_PATH_PERMISSION)) {
hasPermission = true;
break;
}
}
if (!hasPermission) {
context.report(EXPORTED_PROVIDER, element,
context.getLocation(element),
"Exported content providers can provide access to " +
"potentially sensitive data");
}
}
}
}
}
}
示例11: foundResource
import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
/**
* We've found a resource reference to some label we're interested in ("OK",
* "Cancel", "Back", ...). Record the corresponding name such that in the
* next pass through the layouts we can check the context (for OK/Cancel the
* button order etc).
*/
private void foundResource(XmlContext context, String name, Element element) {
if (!LintUtils.isEnglishResource(context, true)) {
return;
}
if (!context.getProject().getReportIssues()) {
// If this is a library project not being analyzed, ignore it
return;
}
if (mApplicableResources == null) {
mApplicableResources = new HashSet<String>();
}
mApplicableResources.add(STRING_PREFIX + name);
// ALSO record all the other string resources in this file to pick up other
// labels. If you define "OK" in one resource file and "Cancel" in another
// this won't work, but that's probably not common and has lower overhead.
Node parentNode = element.getParentNode();
List<Element> items = LintUtils.getChildren(parentNode);
if (mKeyToLabel == null) {
mKeyToLabel = new HashMap<String, String>(items.size());
}
for (Element item : items) {
String itemName = item.getAttribute(ATTR_NAME);
NodeList childNodes = item.getChildNodes();
for (int i = 0, n = childNodes.getLength(); i < n; i++) {
Node child = childNodes.item(i);
if (child.getNodeType() == Node.TEXT_NODE) {
String text = stripLabel(child.getNodeValue());
if (!text.isEmpty()) {
mKeyToLabel.put(itemName, text);
break;
}
}
}
}
}