Search in sources :

Example 46 with TypedValue

use of android.util.TypedValue in project XobotOS by xamarin.

the class TypedArray method getText.

/**
     * Retrieve the styled string value for the attribute at <var>index</var>.
     * 
     * @param index Index of attribute to retrieve.
     * 
     * @return CharSequence holding string data.  May be styled.  Returns 
     *         null if the attribute is not defined.
     */
public CharSequence getText(int index) {
    index *= AssetManager.STYLE_NUM_ENTRIES;
    final int[] data = mData;
    final int type = data[index + AssetManager.STYLE_TYPE];
    if (type == TypedValue.TYPE_NULL) {
        return null;
    } else if (type == TypedValue.TYPE_STRING) {
        return loadStringValueAt(index);
    }
    TypedValue v = mValue;
    if (getValueAt(index, v)) {
        Log.w(Resources.TAG, "Converting to string: " + v);
        return v.coerceToString();
    }
    Log.w(Resources.TAG, "getString of bad type: 0x" + Integer.toHexString(type));
    return null;
}
Also used : TypedValue(android.util.TypedValue)

Example 47 with TypedValue

use of android.util.TypedValue in project XobotOS by xamarin.

the class TypedArray method getBoolean.

/**
     * Retrieve the boolean value for the attribute at <var>index</var>.
     * 
     * @param index Index of attribute to retrieve.
     * @param defValue Value to return if the attribute is not defined.
     * 
     * @return Attribute boolean value, or defValue if not defined.
     */
public boolean getBoolean(int index, boolean 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] != 0;
    }
    TypedValue v = mValue;
    if (getValueAt(index, v)) {
        Log.w(Resources.TAG, "Converting to boolean: " + v);
        return XmlUtils.convertValueToBoolean(v.coerceToString(), defValue);
    }
    Log.w(Resources.TAG, "getBoolean of bad type: 0x" + Integer.toHexString(type));
    return defValue;
}
Also used : TypedValue(android.util.TypedValue)

Example 48 with TypedValue

use of android.util.TypedValue in project XobotOS by xamarin.

the class TypedArray method getString.

/**
     * Retrieve the string value for the attribute at <var>index</var>.
     * 
     * @param index Index of attribute to retrieve.
     * 
     * @return String holding string data.  Any styling information is
     * removed.  Returns null if the attribute is not defined.
     */
public String getString(int index) {
    index *= AssetManager.STYLE_NUM_ENTRIES;
    final int[] data = mData;
    final int type = data[index + AssetManager.STYLE_TYPE];
    if (type == TypedValue.TYPE_NULL) {
        return null;
    } else if (type == TypedValue.TYPE_STRING) {
        return loadStringValueAt(index).toString();
    }
    TypedValue v = mValue;
    if (getValueAt(index, v)) {
        Log.w(Resources.TAG, "Converting to string: " + v);
        CharSequence cs = v.coerceToString();
        return cs != null ? cs.toString() : null;
    }
    Log.w(Resources.TAG, "getString of bad type: 0x" + Integer.toHexString(type));
    return null;
}
Also used : TypedValue(android.util.TypedValue)

Example 49 with TypedValue

use of android.util.TypedValue in project XobotOS by xamarin.

the class TypedArray method getTextArray.

/**
     * Retrieve the CharSequence[] for the attribute at <var>index</var>.
     * This gets the resource ID of the selected attribute, and uses
     * {@link Resources#getTextArray Resources.getTextArray} of the owning
     * Resources object to retrieve its String[].
     * 
     * @param index Index of attribute to retrieve.
     * 
     * @return CharSequence[] for the attribute, or null if not defined.
     */
public CharSequence[] getTextArray(int index) {
    final TypedValue value = mValue;
    if (getValueAt(index * AssetManager.STYLE_NUM_ENTRIES, value)) {
        if (false) {
            System.out.println("******************************************************************");
            System.out.println("Got drawable resource: type=" + value.type + " str=" + value.string + " int=0x" + Integer.toHexString(value.data) + " cookie=" + value.assetCookie);
            System.out.println("******************************************************************");
        }
        return mResources.getTextArray(value.resourceId);
    }
    return null;
}
Also used : TypedValue(android.util.TypedValue)

Example 50 with TypedValue

use of android.util.TypedValue in project XobotOS by xamarin.

the class ActionBarImpl method getThemedContext.

public Context getThemedContext() {
    if (mThemedContext == null) {
        TypedValue outValue = new TypedValue();
        Resources.Theme currentTheme = mContext.getTheme();
        currentTheme.resolveAttribute(com.android.internal.R.attr.actionBarWidgetTheme, outValue, true);
        final int targetThemeRes = outValue.resourceId;
        if (targetThemeRes != 0 && mContext.getThemeResId() != targetThemeRes) {
            mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes);
        } else {
            mThemedContext = mContext;
        }
    }
    return mThemedContext;
}
Also used : ContextThemeWrapper(android.view.ContextThemeWrapper) Resources(android.content.res.Resources) TypedValue(android.util.TypedValue)

Aggregations

TypedValue (android.util.TypedValue)844 TypedArray (android.content.res.TypedArray)190 Resources (android.content.res.Resources)92 ContextThemeWrapper (android.view.ContextThemeWrapper)52 Context (android.content.Context)50 Drawable (android.graphics.drawable.Drawable)49 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)46 TextView (android.widget.TextView)44 Paint (android.graphics.Paint)41 IOException (java.io.IOException)39 AttributeSet (android.util.AttributeSet)34 View (android.view.View)30 XmlResourceParser (android.content.res.XmlResourceParser)29 Point (android.graphics.Point)26 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)26 ColorStateList (android.content.res.ColorStateList)23 DisplayMetrics (android.util.DisplayMetrics)23 LinearLayout (android.widget.LinearLayout)20 Bundle (android.os.Bundle)19 SpannableString (android.text.SpannableString)19