Esempio n. 1
0
        /// <summary>Retrieve the color value for the attribute at <var>index</var>.</summary>
        /// <remarks>
        /// Retrieve the color value for the attribute at <var>index</var>.  If
        /// the attribute references a color resource holding a complex
        /// <see cref="ColorStateList">ColorStateList</see>
        /// , then the default color from
        /// the set is returned.
        /// </remarks>
        /// <param name="index">Index of attribute to retrieve.</param>
        /// <param name="defValue">
        /// Value to return if the attribute is not defined or
        /// not a resource.
        /// </param>
        /// <returns>Attribute color value, or defValue if not defined.</returns>
        public virtual int getColor(int index, int defValue)
        {
            index *= android.content.res.AssetManager.STYLE_NUM_ENTRIES;
            int[] data = mData;
            int   type = data[index + android.content.res.AssetManager.STYLE_TYPE];

            if (type == android.util.TypedValue.TYPE_NULL)
            {
                return(defValue);
            }
            else
            {
                if (type >= android.util.TypedValue.TYPE_FIRST_INT && type <= android.util.TypedValue
                    .TYPE_LAST_INT)
                {
                    return(data[index + android.content.res.AssetManager.STYLE_DATA]);
                }
                else
                {
                    if (type == android.util.TypedValue.TYPE_STRING)
                    {
                        android.util.TypedValue value = mValue;
                        if (getValueAt(index, value))
                        {
                            android.content.res.ColorStateList csl = mResources.loadColorStateList(value, value
                                                                                                   .resourceId);
                            return(csl.getDefaultColor());
                        }
                        return(defValue);
                    }
                }
            }
            throw new System.NotSupportedException("Can't convert to color: type=0x" + Sharpen.Util.IntToHexString
                                                       (type));
        }