Пример #1
0
 /**
  * Retrieve the ColorStateList for the attribute at <var>index</var>. The value may be either a
  * single solid color or a reference to a color or complex {@link
  * android.content.res.ColorStateList} description.
  *
  * @param index Index of attribute to retrieve.
  * @return ColorStateList for the attribute, or null if not defined.
  */
 public ColorStateList getColorStateList(int index) {
   final TypedValue value = mValue;
   if (getValueAt(index * AssetManager.STYLE_NUM_ENTRIES, value)) {
     return mResources.loadColorStateList(value, value.resourceId);
   }
   return null;
 }
Пример #2
0
  /**
   * Retrieve the color value for the attribute at <var>index</var>. If the attribute references a
   * color resource holding a complex {@link android.content.res.ColorStateList}, then the default
   * color from the set is returned.
   *
   * @param index Index of attribute to retrieve.
   * @param defValue Value to return if the attribute is not defined or not a resource.
   * @return Attribute color value, or defValue if not defined.
   */
  public int getColor(int index, int defValue) {
    index *= AssetManager.STYLE_NUM_ENTRIES;
    final int[] data = mData;
    final int type = data[index + AssetManager.STYLE_TYPE];
    if (type == TypedValue.TYPE_NULL) {
      return defValue;
    } else if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
      return data[index + AssetManager.STYLE_DATA];
    } else if (type == TypedValue.TYPE_STRING) {
      final TypedValue value = mValue;
      if (getValueAt(index, value)) {
        ColorStateList csl = mResources.loadColorStateList(value, value.resourceId);
        return csl.getDefaultColor();
      }
      return defValue;
    }

    throw new UnsupportedOperationException(
        "Can't convert to color: type=0x" + Integer.toHexString(type));
  }