TypedArray getResourceId - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for TypedArray getResourceId method.

This code example shows how to use the following methods:getIndex, getResourceId, recycle
This code example shows how to use the following methods:getBoolean, getIndex, getResourceId, recycle
        mContext=context;
        mVisibilityController = new VisibilityController(this);
        TypedArray a = context.obtainStyledAttributes(attrs, new int[] {
        		android.R.attr.windowTitleStyle,
                android.R.attr.defaultValue });
        mIsLegacy = a.getBoolean(a.getIndex(1 /* defaultValue */), false);
        if (mIsLegacy) {
            mTitleResource = a.getResourceId(a.getIndex(0 /* windowTitleStyle */), 0);
        } else { 
            a.recycle();
            a = context.obtainStyledAttributes(null,
                    new int[] { android.R.attr.titleTextStyle,
                            android.R.attr.subtitleTextStyle },
                    android.R.attr.actionBarStyle,
                    0); 
            mTitleResource = a.getResourceId(a.getIndex(0 /* titleTextStyle */), 0);
            mSubtitleResource = a.getResourceId(a.getIndex(1 /* subtitleTextStyle */), 0);
        } 
        a.recycle();
    } 

8
CodeRank
This code example shows how to use the following methods:getResourceId, recycle
 
	public ActionBarTitleView(final Context context, final AttributeSet attrs, final int defStyle) {
		super(context, attrs, defStyle);
		final TypedArray a = context.obtainStyledAttributes(null, new int[] { android.R.attr.titleTextStyle },
				android.R.attr.actionBarStyle, android.R.style.Widget_Holo_ActionBar);
		final int textAppearance = a.getResourceId(0, android.R.style.Widget_Holo_ActionBar);
		a.recycle();
		setTextAppearance(context, textAppearance);
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:getBoolean, getIndex, getResourceId, recycle
        mContext=context;
        mVisibilityController = new VisibilityController(this);
        TypedArray a = context.obtainStyledAttributes(attrs, new int[] {
        		android.R.attr.windowTitleStyle,
                android.R.attr.defaultValue });
        mIsLegacy = a.getBoolean(a.getIndex(1 /* defaultValue */), false);
        if (mIsLegacy) {
            mTitleResource = a.getResourceId(a.getIndex(0 /* windowTitleStyle */), 0);
        } else { 
            a.recycle();
            a = context.obtainStyledAttributes(null,
                    new int[] { android.R.attr.titleTextStyle,
                            android.R.attr.subtitleTextStyle },
                    android.R.attr.actionBarStyle,
                    0); 
            mTitleResource = a.getResourceId(a.getIndex(0 /* titleTextStyle */), 0);
            mSubtitleResource = a.getResourceId(a.getIndex(1 /* subtitleTextStyle */), 0);
        } 
        a.recycle();
    } 

8
CodeRank
This code example shows how to use the following methods:getIndex, getResourceId, recycle
This code example shows how to use the following methods:getBoolean, getResourceId, getString, recycle
    public AuthenticatorDescription parseServiceAttributes(Resources res,
            String packageName, AttributeSet attrs) {
        TypedArray sa = res.obtainAttributes(attrs,
                com.android.internal.R.styleable.AccountAuthenticator); 
        try { 
            final String accountType =
                    sa.getString(com.android.internal.R.styleable.AccountAuthenticator_accountType);
            final int labelId = sa.getResourceId(
                    com.android.internal.R.styleable.AccountAuthenticator_label, 0); 
            final int iconId = sa.getResourceId(
                    com.android.internal.R.styleable.AccountAuthenticator_icon, 0); 
            final int smallIconId = sa.getResourceId(
                    com.android.internal.R.styleable.AccountAuthenticator_smallIcon, 0); 
            final int prefId = sa.getResourceId(
                    com.android.internal.R.styleable.AccountAuthenticator_accountPreferences, 0); 
            final boolean customTokens = sa.getBoolean(
                    com.android.internal.R.styleable.AccountAuthenticator_customTokens, false); 
            if (TextUtils.isEmpty(accountType)) {
                return null; 
            } 

7
CodeRank
This code example shows how to use the following methods:getResourceId, recycle
 
	public ActionBarSubtitleView(final Context context, final AttributeSet attrs, final int defStyle) {
		super(context, attrs, defStyle);
		final TypedArray a = context.obtainStyledAttributes(null, new int[] { android.R.attr.subtitleTextStyle },
				android.R.attr.actionBarStyle, android.R.style.Widget_Holo_ActionBar);
		final int textAppearance = a.getResourceId(0, android.R.style.Widget_Holo_ActionBar);
		a.recycle();
		setTextAppearance(context, textAppearance);
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:getResourceId, getString
 
        array.recycle();
    } 
 
    private String getStringOrReference(TypedArray array, int index) {
        String value = array.getString(index);
        if (value == null) {
            int valueResId = array.getResourceId(index, 0);
            if (valueResId == 0)
                return null; 
            else 
                return getContext().getString(valueResId);
        } else { 
            return value;
        } 
    } 
 
 
    @Override 
    protected View onCreateView(ViewGroup parent) {
6
CodeRank
This code example shows how to use the following methods:getResourceId
    /** 
     * @return The resource ID for an account color. 
     * Otherwise, {@value #UNDEFINED_RESOURCE_ID} if color was not specified via ID. 
     */ 
    public int getAccountColorId(long accountId) {
        return mAccountColorArray.getResourceId(getAccountColorIndex(accountId),
                UNDEFINED_RESOURCE_ID);
    } 
 
    /** 
     * @return {@link Paint} equivalent to {@link #getAccountColor}. 
     */ 
    public Paint getAccountColorPaint(long accountId) {
        return mAccountColorPaints[getAccountColorIndex(accountId)];
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getBoolean, getIndex, getResourceId, recycle
		super(context, attrs, 0);
		mContext = context;
		mVisibilityController = new VisibilityController(this);
		TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.windowTitleStyle,
				android.R.attr.defaultValue });
		mIsLegacy = a.getBoolean(a.getIndex(1 /* defaultValue */), false);
		if (mIsLegacy) {
			mTitleResource = a.getResourceId(a.getIndex(0 /* windowTitleStyle */), 0);
		} else { 
			a.recycle();
			a = context.obtainStyledAttributes(null, new int[] { android.R.attr.titleTextStyle,
					android.R.attr.subtitleTextStyle }, android.R.attr.actionBarStyle, 0);
			mTitleResource = a.getResourceId(a.getIndex(0 /* titleTextStyle */), 0);
			mSubtitleResource = a.getResourceId(a.getIndex(1 /* subtitleTextStyle */), 0);
		} 
		a.recycle();
	} 
	 
	@Override 
	protected void onFinishInflate() { 
		super.onFinishInflate(); 
6
CodeRank
This code example shows how to use the following methods:getResourceId
	public Drawable buildDrawable() {
		return mTheme.getPackageContext().getResources().getDrawable(mDrawableResourceId);
	} 
	 
	public static DrawableBuilder build(KeyboardTheme theme, TypedArray a, final int attr) {
		int resId = a.getResourceId(attr, 0);
		return new DrawableBuilder(theme, resId);
	} 
} 
5
CodeRank
This code example shows how to use the following methods:getResourceId, recycle
 
	public int getResourceId(String attrName, int defaultValue) {
		int[] attr = ThemeUtils.getAttributeIds(mContext,
				new String[] { attrName }, mPackageName);
		TypedArray a = mContext.obtainStyledAttributes(mThemeId, attr);
		int i = a.getResourceId(0, defaultValue);
		a.recycle();
		return i;
	} 
 
	public String getString(String attrName) {
		int[] attr = ThemeUtils.getAttributeIds(mContext,
				new String[] { attrName }, mPackageName);
		TypedArray a = mContext.obtainStyledAttributes(mThemeId, attr);
		String s = a.getString(0);
		a.recycle();
		return s;
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:getResourceId, recycle
 
    public ComparePictureGalleryAdapter(Context c, Collection<Picture> pictures, int[] r_Styleable, int r_Styleable_bg) {
 
        mContext = c;
        TypedArray attr = mContext.obtainStyledAttributes(r_Styleable);
        mGalleryItemBackground = attr.getResourceId(
                r_Styleable_bg, 0);
        this.pictures = new ArrayList<Picture>(pictures);
        attr.recycle();
    } 
 
    public int getCount() { 
        return pictures.size();
    } 
 
    public Picture getItem(int position) {
        return pictures.get(position);
    } 
 
    public long getItemId(int position) {
5
CodeRank
This code example shows how to use the following methods:getResourceId, recycle
 
    public HorizontalGalleryAdapter(Context c, Collection<Picture> pictures, int[] r_Styleable, int r_Styleable_bg) {
 
        mContext = c;
        TypedArray attr = mContext.obtainStyledAttributes(r_Styleable);
        mGalleryItemBackground = attr.getResourceId(
                r_Styleable_bg, 0);
        this.pictures = new ArrayList<Picture>(pictures);
        attr.recycle();
    } 
 
    public int getCount() { 
        return pictures.size();
    } 
 
    public Picture getItem(int position) {
        return pictures.get(position);
    } 
 
    public long getItemId(int position) {
5
CodeRank
This code example shows how to use the following methods:getResourceId, getString
		setOnClickListener(this);
    } 
 
    private int parseColor(final Context context, final TypedArray a, final int index, final int defaultColorRes){
        //try to get as a resource 
        final int resId = a.getResourceId(index,-1);
        if(resId > -1) return context.getResources().getColor(resId);
        //try to get as a hex string 
        final String str = a.getString(index);
        if(null != str) return Color.parseColor(str);
        //return default 
        return context.getResources().getColor(defaultColorRes);
    } 
 
    private Paint backgroundPaint() {
        Paint p = new Paint();
        p.setColor(mTagBackground);
        p.setAntiAlias(true);
        p.setFilterBitmap(true);
        p.setDither(true);
5
CodeRank
This code example shows how to use the following methods:getResourceId, recycle
     * @return 
     */ 
    public static View addBackgroundIndicator(Context context, View view, int resid) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            TypedArray attributes = context.obtainStyledAttributes(new int[] { resid });
            int resource = attributes.getResourceId(0, 0);
            attributes.recycle();
 
            // setBackgroundResource resets padding 
            int paddingLeft = view.getPaddingLeft();
            int paddingTop = view.getPaddingTop();
            int paddingRight = view.getPaddingRight();
            int paddingBottom = view.getPaddingBottom();
            view.setBackgroundResource(resource);
            view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
        } 
        return view;
    } 
 
    /** 
5
CodeRank
This code example shows how to use the following methods:getBoolean, getDimensionPixelSize, getDrawable, getInt, getInteger
        TypedArray a =
            context.obtainStyledAttributes(attrs, /*R.styleable.*/ProgressBar, defStyle, styleRes);
 
        mNoInvalidate = true;
 
        Drawable drawable = a.getDrawable(/*R.styleable.*/ProgressBar_progressDrawable);
        if (drawable != null) {
            drawable = tileify(drawable, false);
            // Calling this method can set mMaxHeight, make sure the corresponding 
            // XML attribute for mMaxHeight is read after calling this method 
            setProgressDrawable(drawable);
        } 
 
 
        mDuration = a.getInt(/*R.styleable.*/ProgressBar_indeterminateDuration, mDuration);
 
        mMinWidth = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_minWidth, mMinWidth);
        mMaxWidth = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_maxWidth, mMaxWidth);
        mMinHeight = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_minHeight, mMinHeight);
        mMaxHeight = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_maxHeight, mMaxHeight);

-2
CodeRank

Related TypedArray getResourceId Questions & Answers:

Other TypedArray getResourceId Examples

59:			// adding nav drawer items to array
60:			// Home
61:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
62:			// Find People
63:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
-
61:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
62:			// Find People
63:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
64:			// Photos
65:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
-
63:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
64:			// Photos
65:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
66:			// Communities, Will add a counter here
67:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1), true, "22"));
-
65:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
66:			// Communities, Will add a counter here
67:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1), true, "22"));
68:			// Pages
69:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
-
67:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1), true, "22"));
68:			// Pages
69:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
70:			// What's hot, We  will add a counter here
71:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1), true, "50+"));
-
69:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
70:			// What's hot, We  will add a counter here
71:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1), true, "50+"));
72:			
73:

Read More

37:			// adding nav drawer items to array
38:			// Home
39:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
40:			// Find People
41:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
-
39:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
40:			// Find People
41:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
42:			// Photos
43:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
-
41:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
42:			// Photos
43:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
44:			// Communities, Will add a counter here
45:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1), true, "22"));
-
43:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
44:			// Communities, Will add a counter here
45:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1), true, "22"));
46:			// Pages
47:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
-
45:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1), true, "22"));
46:			// Pages
47:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
48:			// What's hot, We  will add a counter here
49:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1), true, "50+"));
-
47:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
48:			// What's hot, We  will add a counter here
49:			navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1), true, "50+"));
50:			
51:

Read More

getResourceId Method Overview
Retrieve the resource identifier for the attribute at index.
See Code Examples for other Android TypedArray Methods: