@Override
 public Drawable mutate() {
   if (!mMutated && super.mutate() == this) {
     mLevelListState.mLows = mLevelListState.mLows.clone();
     mLevelListState.mHighs = mLevelListState.mHighs.clone();
     mMutated = true;
   }
   return this;
 }
 public void addLevel(int low, int high, Drawable drawable) {
   if (drawable != null) {
     mLevelListState.addLevel(low, high, drawable);
     // in case the new state matches our current state...
     onLevelChange(getLevel());
   }
 }
 @Override
 protected boolean onLevelChange(int level) {
   int idx = mLevelListState.indexOfLevel(level);
   if (selectDrawable(idx)) {
     return true;
   }
   return super.onLevelChange(level);
 }
  @Override
  public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs)
      throws XmlPullParserException, IOException {

    super.inflate(r, parser, attrs);

    int type;

    int low = 0;

    final int innerDepth = parser.getDepth() + 1;
    int depth;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
        && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
      if (type != XmlPullParser.START_TAG) {
        continue;
      }

      if (depth > innerDepth || !parser.getName().equals("item")) {
        continue;
      }

      TypedArray a =
          r.obtainAttributes(attrs, com.android.internal.R.styleable.LevelListDrawableItem);

      low = a.getInt(com.android.internal.R.styleable.LevelListDrawableItem_minLevel, 0);
      int high = a.getInt(com.android.internal.R.styleable.LevelListDrawableItem_maxLevel, 0);
      int drawableRes =
          a.getResourceId(com.android.internal.R.styleable.LevelListDrawableItem_drawable, 0);

      a.recycle();

      if (high < 0) {
        throw new XmlPullParserException(
            parser.getPositionDescription() + ": <item> tag requires a 'maxLevel' attribute");
      }

      Drawable dr;
      if (drawableRes != 0) {
        dr = r.getDrawable(drawableRes);
      } else {
        while ((type = parser.next()) == XmlPullParser.TEXT) {}
        if (type != XmlPullParser.START_TAG) {
          throw new XmlPullParserException(
              parser.getPositionDescription()
                  + ": <item> tag requires a 'drawable' attribute or "
                  + "child tag defining a drawable");
        }
        dr = Drawable.createFromXmlInner(r, parser, attrs);
      }

      mLevelListState.addLevel(low, high, dr);
    }

    onLevelChange(getLevel());
  }