Search in sources :

Example 91 with TypedValue

use of android.util.TypedValue in project robolectric by robolectric.

the class ShadowAssetManager method getTypedArray.

private TypedArray getTypedArray(Resources resources, TypedResource[] typedResources, int resId) {
    final CharSequence[] stringData = new CharSequence[typedResources.length];
    final int totalLen = typedResources.length * ShadowAssetManager.STYLE_NUM_ENTRIES;
    final int[] data = new int[totalLen];
    for (int i = 0; i < typedResources.length; i++) {
        final int offset = i * ShadowAssetManager.STYLE_NUM_ENTRIES;
        TypedResource typedResource = typedResources[i];
        // Classify the item.
        int type = getResourceType(typedResource);
        if (type == -1) {
            // This type is unsupported; leave empty.
            continue;
        }
        final TypedValue typedValue = new TypedValue();
        if (type == TypedValue.TYPE_REFERENCE) {
            final String reference = typedResource.asString();
            ResName refResName = AttributeResource.getResourceReference(reference, typedResource.getXmlContext().getPackageName(), null);
            typedValue.resourceId = resourceTable.getResourceId(refResName);
            typedValue.data = typedValue.resourceId;
            typedResource = resolve(typedResource, RuntimeEnvironment.getQualifiers(), typedValue.resourceId);
            if (typedResource != null) {
                // Reclassify to a non-reference type.
                type = getResourceType(typedResource);
                if (type == TypedValue.TYPE_ATTRIBUTE) {
                    type = TypedValue.TYPE_REFERENCE;
                } else if (type == -1) {
                    // This type is unsupported; leave empty.
                    continue;
                }
            }
        }
        if (type == TypedValue.TYPE_ATTRIBUTE) {
            final String reference = typedResource.asString();
            final ResName attrResName = AttributeResource.getStyleReference(reference, typedResource.getXmlContext().getPackageName(), "attr");
            typedValue.data = resourceTable.getResourceId(attrResName);
        }
        if (typedResource != null && type != TypedValue.TYPE_NULL && type != TypedValue.TYPE_ATTRIBUTE) {
            getConverter(typedResource).fillTypedValue(typedResource.getData(), typedValue);
        }
        data[offset + ShadowAssetManager.STYLE_TYPE] = type;
        data[offset + ShadowAssetManager.STYLE_RESOURCE_ID] = typedValue.resourceId;
        data[offset + ShadowAssetManager.STYLE_DATA] = typedValue.data;
        data[offset + ShadowAssetManager.STYLE_ASSET_COOKIE] = typedValue.assetCookie;
        data[offset + ShadowAssetManager.STYLE_CHANGING_CONFIGURATIONS] = typedValue.changingConfigurations;
        data[offset + ShadowAssetManager.STYLE_DENSITY] = typedValue.density;
        stringData[i] = typedResource == null ? null : typedResource.asString();
    }
    int[] indices = new int[typedResources.length + 1];
    /* keep zeroed out */
    return ShadowTypedArray.create(resources, null, data, indices, typedResources.length, stringData);
}
Also used : FileTypedResource(org.robolectric.res.FileTypedResource) TypedResource(org.robolectric.res.TypedResource) ResName(org.robolectric.res.ResName) TypedValue(android.util.TypedValue)

Example 92 with TypedValue

use of android.util.TypedValue in project Libraries-for-Android-Developers by eoecn.

the class ActionBarSherlockCompat method initializePanelMenu.

private boolean initializePanelMenu() {
    //getContext();
    Context context = mActivity;
    // If we have an action bar, initialize the menu with a context themed for it.
    if (wActionBar != null) {
        TypedValue outValue = new TypedValue();
        Resources.Theme currentTheme = context.getTheme();
        currentTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
        final int targetThemeRes = outValue.resourceId;
        if (targetThemeRes != 0) /*&& context.getThemeResId() != targetThemeRes*/
        {
            context = new ContextThemeWrapper(context, targetThemeRes);
        }
    }
    mMenu = new MenuBuilder(context);
    mMenu.setCallback(this);
    return true;
}
Also used : Context(android.content.Context) ContextThemeWrapper(android.view.ContextThemeWrapper) Resources(android.content.res.Resources) MenuBuilder(com.actionbarsherlock.internal.view.menu.MenuBuilder) TypedValue(android.util.TypedValue)

Example 93 with TypedValue

use of android.util.TypedValue in project Libraries-for-Android-Developers by eoecn.

the class ActionBarSherlockNative method getThemedContext.

@Override
protected Context getThemedContext() {
    Context context = mActivity;
    TypedValue outValue = new TypedValue();
    mActivity.getTheme().resolveAttribute(android.R.attr.actionBarWidgetTheme, outValue, true);
    if (outValue.resourceId != 0) {
        //We are unable to test if this is the same as our current theme
        //so we just wrap it and hope that if the attribute was specified
        //then the user is intentionally specifying an alternate theme.
        context = new ContextThemeWrapper(context, outValue.resourceId);
    }
    return context;
}
Also used : Context(android.content.Context) ContextThemeWrapper(android.view.ContextThemeWrapper) TypedValue(android.util.TypedValue)

Example 94 with TypedValue

use of android.util.TypedValue in project Libraries-for-Android-Developers by eoecn.

the class ActionBarImpl method getThemedContext.

public Context getThemedContext() {
    if (mThemedContext == null) {
        TypedValue outValue = new TypedValue();
        Resources.Theme currentTheme = mContext.getTheme();
        currentTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
        final int targetThemeRes = outValue.resourceId;
        if (targetThemeRes != 0) {
            //XXX && 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)

Example 95 with TypedValue

use of android.util.TypedValue in project UltimateRecyclerView by cymcsg.

the class BaseActivity method getActionBarSize.

protected int getActionBarSize() {
    TypedValue typedValue = new TypedValue();
    int[] textSizeAttr = new int[] { R.attr.actionBarSize };
    int indexOfAttrTextSize = 0;
    TypedArray a = obtainStyledAttributes(typedValue.data, textSizeAttr);
    int actionBarSize = a.getDimensionPixelSize(indexOfAttrTextSize, -1);
    a.recycle();
    return actionBarSize;
}
Also used : TypedArray(android.content.res.TypedArray) 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