Example usage for android.content.res TypedArray getResourceId

List of usage examples for android.content.res TypedArray getResourceId

Introduction

In this page you can find the example usage for android.content.res TypedArray getResourceId.

Prototype

@AnyRes
public int getResourceId(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieves the resource identifier for the attribute at index.

Usage

From source file:am.widget.tabstrip.TabStripView.java

private void initView(Context context, @Nullable AttributeSet attrs) {
    final TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.TabStripView);
    mHelper.set(custom.getResourceId(R.styleable.TabStripView_tsvViewPager, NO_ID),
            custom.getBoolean(R.styleable.TabStripView_tsvAutoFindViewPager, true),
            custom.getBoolean(R.styleable.TabStripView_tsvClickSmoothScroll, false));
    custom.recycle();/*  ww w.  jav a 2s.  com*/
}

From source file:am.widget.tabstrip.TabStripViewGroup.java

private void initView(Context context, @Nullable AttributeSet attrs) {
    final TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.TabStripViewGroup);
    mHelper.set(custom.getResourceId(R.styleable.TabStripViewGroup_tsgViewPager, NO_ID),
            custom.getBoolean(R.styleable.TabStripViewGroup_tsgAutoFindViewPager, true),
            custom.getBoolean(R.styleable.TabStripViewGroup_tsgClickSmoothScroll, false));
    custom.recycle();/*from   w w w .  ja  va 2s  .c  o m*/
}

From source file:com.gelakinetic.mtgfam.helpers.ResultListAdapter.java

/**
 * This helper function translates an attribute into a resource ID
 *
 * @param attr The attribute ID/*from  ww  w.  ja  va 2 s. com*/
 * @return the resource ID
 */
private int getResourceIdFromAttr(int attr) {
    TypedArray ta = mTheme.obtainStyledAttributes(new int[] { attr });
    assert ta != null;
    int resId = ta.getResourceId(0, 0);
    ta.recycle();
    return resId;
}

From source file:android.support.v7.widget.AppCompatCompoundButtonHelper.java

void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
    TypedArray a = mView.getContext().obtainStyledAttributes(attrs, R.styleable.CompoundButton, defStyleAttr,
            0);//  ww  w.j  a v a  2 s. c o  m
    try {
        if (a.hasValue(R.styleable.CompoundButton_android_button)) {
            final int resourceId = a.getResourceId(R.styleable.CompoundButton_android_button, 0);
            if (resourceId != 0) {
                mView.setButtonDrawable(mDrawableManager.getDrawable(mView.getContext(), resourceId));
            }
        }
        if (a.hasValue(R.styleable.CompoundButton_buttonTint)) {
            CompoundButtonCompat.setButtonTintList(mView,
                    a.getColorStateList(R.styleable.CompoundButton_buttonTint));
        }
        if (a.hasValue(R.styleable.CompoundButton_buttonTintMode)) {
            CompoundButtonCompat.setButtonTintMode(mView,
                    DrawableUtils.parseTintMode(a.getInt(R.styleable.CompoundButton_buttonTintMode, -1), null));
        }
    } finally {
        a.recycle();
    }
}

From source file:androidx.navigation.fragment.NavHostFragment.java

@Override
public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(context, attrs, savedInstanceState);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NavHostFragment);
    final int graphId = a.getResourceId(R.styleable.NavHostFragment_navGraph, 0);
    final boolean defaultHost = a.getBoolean(R.styleable.NavHostFragment_defaultNavHost, false);

    if (graphId != 0) {
        setGraph(graphId);//from   ww  w.  jav a 2  s . c om
    }
    if (defaultHost) {
        mDefaultNavHost = true;
    }
    a.recycle();
}

From source file:com.augustopicciani.drawablepageindicator.widget.DrawablePagerIndicator.java

public DrawablePagerIndicator(Context context, AttributeSet attrs) {

    super(context, attrs);
    this.mContext = context;
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DrawablePagerIndicator, 0, 0);
    drawableSelectedId = a.getResourceId(R.styleable.DrawablePagerIndicator_drawableSelected,
            R.drawable.ic_slider_on);//w w w .j  av  a  2  s  . c o  m
    drawableDefaultId = a.getResourceId(R.styleable.DrawablePagerIndicator_drawableDefault,
            R.drawable.ic_slider_off);
    imageSpacing = a.getInteger(R.styleable.DrawablePagerIndicator_imageSpacing, 0);
    this.mCentered = a.getBoolean(R.styleable.DrawablePagerIndicator_centered, false);
    a.recycle();

}

From source file:github.daneren2005.dsub.util.Util.java

public static int getAttribute(Context context, int attr) {
    int res;/*  ww w.  jav a2 s  .  c  o  m*/
    int[] attrs = new int[] { attr };
    TypedArray typedArray = context.obtainStyledAttributes(attrs);
    res = typedArray.getResourceId(0, 0);
    typedArray.recycle();
    return res;
}

From source file:com.android.dokdo.NavigationDrawerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_drawer);

    setBehindContentView(R.layout.activity_navigation_drawer);

    mTitle = mDrawerTitle = getTitle();/*from  ww w  .  j  ava 2  s . com*/
    mCityNames = getResources().getStringArray(R.array.drawer_items);
    TypedArray typedArray = getResources().obtainTypedArray(R.array.city_images);
    mCityImages = new int[typedArray.length()];
    for (int i = 0; i < typedArray.length(); ++i) {
        mCityImages[i] = typedArray.getResourceId(i, 0);
    }
    typedArray.recycle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mCityNames));
    mDrawerList.setOnItemClickListener(new ListView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if (position == 0) {
                Intent intent = new Intent(NavigationDrawerActivity.this, NavigationDrawerActivity.class);
                startActivity(intent);
                finish();
            } else if (position == 1) {
                Intent intent = new Intent(NavigationDrawerActivity.this, Developer.class);
                startActivity(intent);
            }
        }
    });
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    mDrawerToggle = new ActionBarDrawerToggleCompat(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        selectItem(0);
    }
}

From source file:cafe.com.navigationdrawer.NavigationDrawerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_drawer);

    mTitle = mDrawerTitle = getTitle();/*from www  . j av a  2 s . c  o m*/

    mMenuNames = getResources().getStringArray(R.array.drawer_items);
    TypedArray typedArray = getResources().obtainTypedArray(R.array.menu_images);
    mMenuImages = new int[typedArray.length()];
    for (int i = 0; i < typedArray.length(); ++i) {
        mMenuImages[i] = typedArray.getResourceId(i, 0);
    }
    typedArray.recycle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    //mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mMenuNames));
    mDrawerList.setOnItemClickListener(this);

    // enable ActionBar app icon to behave as action to toggle
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        selectItem(0);
    }
}

From source file:com.birdgang.viewpagerheader.indicator.SpringIndicator.java

private void initAttrs(AttributeSet attrs) {
    textColorId = R.color.si_default_text_color;
    selectedTextColorId = R.color.si_default_text_color_selected;
    indicatorColorId = R.color.si_default_indicator_bg;
    textSize = getResources().getDimension(R.dimen.si_default_text_size);
    radiusMax = getResources().getDimension(R.dimen.si_default_radius_max);
    radiusMin = getResources().getDimension(R.dimen.si_default_radius_min);

    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SpringIndicator);
    textColorId = a.getResourceId(R.styleable.SpringIndicator_siTextColor, textColorId);
    selectedTextColorId = a.getResourceId(R.styleable.SpringIndicator_siSelectedTextColor, selectedTextColorId);
    textSize = a.getDimension(R.styleable.SpringIndicator_siTextSize, textSize);
    textBgResId = a.getResourceId(R.styleable.SpringIndicator_siTextBg, 0);
    indicatorColorId = a.getResourceId(R.styleable.SpringIndicator_siIndicatorColor, indicatorColorId);
    indicatorColorsId = a.getResourceId(R.styleable.SpringIndicator_siIndicatorColors, 0);
    radiusMax = a.getDimension(R.styleable.SpringIndicator_siRadiusMax, radiusMax);
    radiusMin = a.getDimension(R.styleable.SpringIndicator_siRadiusMin, radiusMin);
    a.recycle();/*ww  w.j av a 2 s  .  c om*/

    if (indicatorColorsId != 0) {
        indicatorColorArray = getResources().getIntArray(indicatorColorsId);
    }
    radiusOffset = radiusMax - radiusMin;
}