title: Resolving resource values in custom lint rule
body: <p>I have a large Android codebase and I am writing a custom lint rule that checks whether the values of certain attributes fall within a given range.</p>
  
  <p>For example, I have this component:</p>
  
  <pre><code>&lt;MyCustomComponent
      my:animation_factor="0.7"
      ...&gt;
  &lt;/MyCustomComponent&gt;
  </code></pre>
  
  <p>and I want to write a lint rule that alerts developers that values of <code>my:animation_factor</code> >= 1 should be used with caution.</p>
  
  <p>I followed the instructions at <a href="http://tools.android.com/tips/lint-custom-rules">http://tools.android.com/tips/lint-custom-rules</a> and managed to retrieve the value of <code>my:animation_factor</code> using this code:</p>
  
  <pre><code>import com.android.tools.lint.detector.api.*;
  
  public class XmlInterpolatorFactorTooHighDetector {
  
      ....
      @Override
      public Collection&lt;String&gt; getApplicableElements() {
          return ImmutableList.of("MyCustomComponent");
      }
  
      @Override
      public void visitElement(XmlContext context, Element element) {
          String factor = element.getAttribute("my:animation_factor");
          ...
          if (value.startsWith("@dimen/")) {
              // How do I resolve @dimen/xyz to 1.85?
          } else {
              String value = Float.parseFloat(factor);
          }
      }
  }
  </code></pre>
  
  <p>This code works fine when attributes such as <code>my:animation_factor</code> have literal values (e.g. <code>0.7</code>).</p>
  
  <p>However, when the attribute value is a resources (e.g. <code>@dimen/standard_anim_factor</code>) then <code>element.getAttribute(...)</code> returns the string value of the attribute instead of the actual resolved value.</p>
  
  <p>For example, when I have a <code>MyCustomComponent</code> that looks like this:</p>
  
  <pre><code>&lt;MyCustomComponent
      my:animation_factor="@dimen/standard_anim_factory"
      ...&gt;
  &lt;/MyCustomComponent&gt;
  </code></pre>
  
  <p>and <code>@dimen/standard_anim_factor</code> is defined elsewhere:</p>
  
  <pre><code>&lt;dimen name="standard_anim_factor"&gt;1.85&lt;/dimen&gt;
  </code></pre>
  
  <p>then the string <code>factor</code> becomes "@dimen/standard_anim_factor" instead of "1.85".</p>
  
  <p>Is there a way to resolve "@dimen/standard_anim_factor" to the actual value of resource (i.e. "1.85") while processing the <code>MyCustomComponent</code> element?</p>