Пример #1
0
        /// <summary>Retrieve the styled string value for the attribute at <var>index</var>.</summary>
        /// <remarks>Retrieve the styled string value for the attribute at <var>index</var>.</remarks>
        /// <param name="index">Index of attribute to retrieve.</param>
        /// <returns>
        /// CharSequence holding string data.  May be styled.  Returns
        /// null if the attribute is not defined.
        /// </returns>
        public virtual java.lang.CharSequence getText(int index)
        {
            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(null);
            }
            else
            {
                if (type == android.util.TypedValue.TYPE_STRING)
                {
                    return(loadStringValueAt(index));
                }
            }
            android.util.TypedValue v = mValue;
            if (getValueAt(index, v))
            {
                android.util.Log.w(android.content.res.Resources.TAG, "Converting to string: " +
                                   v);
                return(v.coerceToString());
            }
            android.util.Log.w(android.content.res.Resources.TAG, "getString of bad type: 0x"
                               + Sharpen.Util.IntToHexString(type));
            return(null);
        }
Пример #2
0
        /// <summary>Retrieve the integer value for the attribute at <var>index</var>.</summary>
        /// <remarks>Retrieve the integer value for the attribute at <var>index</var>.</remarks>
        /// <param name="index">Index of attribute to retrieve.</param>
        /// <param name="defValue">Value to return if the attribute is not defined.</param>
        /// <returns>Attribute int value, or defValue if not defined.</returns>
        public virtual int getInt(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]);
                }
            }
            android.util.TypedValue v = mValue;
            if (getValueAt(index, v))
            {
                android.util.Log.w(android.content.res.Resources.TAG, "Converting to int: " + v);
                return([email protected](v.coerceToString(), defValue
                                                                         ));
            }
            android.util.Log.w(android.content.res.Resources.TAG, "getInt of bad type: 0x" +
                               Sharpen.Util.IntToHexString(type));
            return(defValue);
        }
Пример #3
0
        /// <hide>
        /// Retrieve the string value for the attribute at <var>index</var> that is
        /// not allowed to change with the given configurations.
        /// </hide>
        /// <param name="index">Index of attribute to retrieve.</param>
        /// <param name="allowedChangingConfigs">
        /// Bit mask of configurations from
        /// ActivityInfo that are allowed to change.
        /// </param>
        /// <returns>
        /// String holding string data.  Any styling information is
        /// removed.  Returns null if the attribute is not defined.
        /// </returns>
        public virtual string getNonConfigurationString(int index, int allowedChangingConfigs
                                                        )
        {
            index *= android.content.res.AssetManager.STYLE_NUM_ENTRIES;
            int[] data = mData;
            int   type = data[index + android.content.res.AssetManager.STYLE_TYPE];

            if ((data[index + android.content.res.AssetManager.STYLE_CHANGING_CONFIGURATIONS]
                 & ~allowedChangingConfigs) != 0)
            {
                return(null);
            }
            if (type == android.util.TypedValue.TYPE_NULL)
            {
                return(null);
            }
            else
            {
                if (type == android.util.TypedValue.TYPE_STRING)
                {
                    return(loadStringValueAt(index).ToString());
                }
            }
            android.util.TypedValue v = mValue;
            if (getValueAt(index, v))
            {
                android.util.Log.w(android.content.res.Resources.TAG, "Converting to string: " +
                                   v);
                java.lang.CharSequence cs = v.coerceToString();
                return(cs != null?cs.ToString() : null);
            }
            android.util.Log.w(android.content.res.Resources.TAG, "getString of bad type: 0x"
                               + Sharpen.Util.IntToHexString(type));
            return(null);
        }
Пример #4
0
        /// <summary>Retrieve the float value for the attribute at <var>index</var>.</summary>
        /// <remarks>Retrieve the float value for the attribute at <var>index</var>.</remarks>
        /// <param name="index">Index of attribute to retrieve.</param>
        /// <returns>Attribute float value, or defValue if not defined..</returns>
        public virtual float getFloat(int index, float 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_FLOAT)
                {
                    return(Sharpen.Util.IntBitsToFloat(data[index + android.content.res.AssetManager.
                                                            STYLE_DATA]));
                }
                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]);
                    }
                }
            }
            android.util.TypedValue v = mValue;
            if (getValueAt(index, v))
            {
                android.util.Log.w(android.content.res.Resources.TAG, "Converting to float: " + v
                                   );
                java.lang.CharSequence str = v.coerceToString();
                if (str != null)
                {
                    return(float.Parse(str.ToString()));
                }
            }
            android.util.Log.w(android.content.res.Resources.TAG, "getFloat of bad type: 0x"
                               + Sharpen.Util.IntToHexString(type));
            return(defValue);
        }