diff options
author | Xavier Ducrohet <xav@google.com> | 2011-11-28 16:36:25 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-11-28 16:36:25 -0800 |
commit | 3162c11700e77c045aadaac8983716fcc779f290 (patch) | |
tree | be2473022322364d155ecb4281423cda517b2f8d /lint | |
parent | 02a5c958428a36bf54fd082723145a15d483de60 (diff) | |
parent | 078fab80c375a38ecaa9c0be80b90ab480e675c7 (diff) | |
download | sdk-3162c11700e77c045aadaac8983716fcc779f290.zip sdk-3162c11700e77c045aadaac8983716fcc779f290.tar.gz sdk-3162c11700e77c045aadaac8983716fcc779f290.tar.bz2 |
Merge "Don't flag selector states with custom attributes as unreachable"
Diffstat (limited to 'lint')
3 files changed, 25 insertions, 0 deletions
diff --git a/lint/libs/lint_checks/src/com/android/tools/lint/checks/StateListDetector.java b/lint/libs/lint_checks/src/com/android/tools/lint/checks/StateListDetector.java index e1f923e..ab42d03 100644 --- a/lint/libs/lint_checks/src/com/android/tools/lint/checks/StateListDetector.java +++ b/lint/libs/lint_checks/src/com/android/tools/lint/checks/StateListDetector.java @@ -16,6 +16,8 @@ package com.android.tools.lint.checks; +import static com.android.tools.lint.detector.api.LintConstants.ANDROID_URI; + import com.android.resources.ResourceFolderType; import com.android.tools.lint.detector.api.Category; import com.android.tools.lint.detector.api.Context; @@ -83,6 +85,16 @@ public class StateListDetector extends ResourceXmlDetector { if (attribute.getLocalName().startsWith("state_")) { hasState = true; break; + } else { + String namespaceUri = attribute.getNamespaceURI(); + if (namespaceUri != null && namespaceUri.length() > 0 && + !ANDROID_URI.equals(namespaceUri)) { + // There is a custom attribute on this item. + // This could be a state, see + // http://code.google.com/p/android/issues/detail?id=22339 + // so don't flag this one. + hasState = true; + } } } if (!hasState) { diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StateListDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StateListDetectorTest.java index da6bbf4..b0994fe 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StateListDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StateListDetectorTest.java @@ -31,4 +31,10 @@ public class StateListDetectorTest extends AbstractCheckTest { "later states not reachable", lintProject("res/drawable/states.xml")); } + + public void testCustomStates() throws Exception { + assertEquals( + "No warnings.", + lintProject("res/drawable/states2.xml")); + } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/drawable/states2.xml b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/drawable/states2.xml new file mode 100644 index 0000000..dac176d --- /dev/null +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/res/drawable/states2.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> +<selector xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res/com.domain.pkg"> +<item + app:mystate_custom="false" + android:drawable="@drawable/item" /> +</selector> |