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:android.view.SpringIndicator.java

private void initAttrs(final AttributeSet attrs) {
    textColorId = R.color.springIndicator_default_text_color;
    selectedTextColorId = R.color.springIndicator_default_text_color_selected;
    indicatorColorId = R.color.springIndicator_default_indicator_bg;
    textSize = getResources().getDimension(R.dimen.springIndicator_default_text_size);
    radiusMax = getResources().getDimension(R.dimen.springIndicator_default_radius_max);
    radiusMin = getResources().getDimension(R.dimen.springIndicator_default_radius_min);

    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SpringIndicator);
    textColorId = a.getResourceId(R.styleable.SpringIndicator_textColor, textColorId);
    selectedTextColorId = a.getResourceId(R.styleable.SpringIndicator_selectedTextColor, selectedTextColorId);
    textSize = a.getDimension(R.styleable.SpringIndicator_textSize, textSize);
    textBgResId = a.getResourceId(R.styleable.SpringIndicator_textBackground, 0);
    indicatorColorId = a.getResourceId(R.styleable.SpringIndicator_indicatorColor, indicatorColorId);
    indicatorColorsId = a.getResourceId(R.styleable.SpringIndicator_indicatorColors, 0);
    radiusMax = a.getDimension(R.styleable.SpringIndicator_maxRadius, radiusMax);
    radiusMin = a.getDimension(R.styleable.SpringIndicator_minRadius, radiusMin);
    a.recycle();/*from w  w w  .j a  va  2s . c o  m*/

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

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

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public DrawablePagerIndicator(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {

    super(context, attrs, defStyleAttr, defStyleRes);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DrawablePagerIndicator, defStyleAttr, 0);
    drawableSelectedId = a.getResourceId(R.styleable.DrawablePagerIndicator_drawableSelected,
            R.drawable.ic_slider_on);/*from   w  w w.  j  a  va  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);
    a.recycle();
}

From source file:com.android.volley.ui.NetworkImageView.java

public NetworkImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    final TypedArray a = context.obtainStyledAttributes(attrs, attrsArray);
    setDefaultImageResId(a.getResourceId(0, 0));
    a.recycle();// www . ja v a  2  s  .  c  o m
}

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

public DrawablePagerIndicator(Context context, AttributeSet attrs, int defStyleAttr) {

    super(context, attrs, defStyleAttr);
    this.mContext = context;
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DrawablePagerIndicator, defStyleAttr, 0);
    drawableSelectedId = a.getResourceId(R.styleable.DrawablePagerIndicator_drawableSelected,
            R.drawable.ic_slider_on);//w w  w  . ja  v 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:com.frozendevs.periodictable.view.ViewPagerTabs.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ViewPagerTabs(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);//  ww  w  .ja v  a2s  .c om

    mSidePadding = getResources().getDimensionPixelOffset(R.dimen.tab_side_padding);

    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    mTextSize = a.getDimensionPixelSize(0, 0);
    mTextStyle = a.getInt(1, 0);
    mTextColor = a.getColorStateList(2);
    a.recycle();

    Resources.Theme theme = getContext().getTheme();
    TypedValue typedValue = new TypedValue();
    theme.resolveAttribute(R.attr.theme, typedValue, true);
    TypedArray typedArray = theme.obtainStyledAttributes(typedValue.resourceId,
            new int[] { R.attr.selectableItemBackground });
    mTextBackground = typedArray.getResourceId(0, 0);
    typedArray.recycle();

    mTabStrip = new ViewPagerTabStrip(context);
    addView(mTabStrip, new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // enable shadow casting from view bounds
        setOutlineProvider(new ViewOutlineProvider() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRect(0, 0, view.getWidth(), view.getHeight());
            }
        });
    }
}

From source file:net.sf.sprockets.app.ui.SprocketsPreferenceFragment.java

@Override
public void onInflate(Activity a, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(a, attrs, savedInstanceState);
    TypedArray array = a.obtainStyledAttributes(attrs, R.styleable.SprocketsPreferenceFragment);
    Bundle args = Fragments.arguments(this);
    args.putInt(PREFS, array.getResourceId(R.styleable.SprocketsPreferenceFragment_preferences, 0));
    args.putBoolean(TRACK_CHANGES,/*from w  ww  .j  a  v  a  2s  .c om*/
            array.getBoolean(R.styleable.SprocketsPreferenceFragment_trackChanges, false));
    array.recycle();
}

From source file:es.uniovi.imovil.fcrtrainer.highscores.HighscoresFragment.java

private void addExerciseModule(ArrayList<Exercise> exercises, int arrayResourceId) {
    TypedArray array = getResources().obtainTypedArray(arrayResourceId);

    for (int i = 0; i < array.length(); i++) {
        int defaultId = 0;
        int resourceId = array.getResourceId(i, defaultId);

        Exercise exercise = new Exercise(getResources().getString(resourceId), resourceId);
        exercises.add(exercise);//  ww w  .ja  v a 2 s .  co  m
    }

    array.recycle();
}

From source file:com.bilibili.magicasakura.widgets.AppCompatCompoundDrawableHelper.java

@SuppressWarnings("ResourceType")
@Override/*from www.j  a  v  a  2  s .  c  o  m*/
void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
    Context context = mView.getContext();
    TypedArray a = context.obtainStyledAttributes(attrs, ATTR, defStyleAttr, 0);
    for (int tintIndex = 0; tintIndex < 4; tintIndex++) {
        int modeIndex = tintIndex + 4;
        mCompoundDrawableResIds[tintIndex] = a.getResourceId(tintIndex, 0);
        mCompoundDrawableTintResIds[tintIndex] = a.getResourceId(tintIndex, 0);
        if (a.hasValue(modeIndex)) {
            mCompoundDrawableTintModes[tintIndex] = DrawableUtils.parseTintMode(a.getInt(modeIndex, 0), null);
        }
    }
    mCompoundDrawableResIds[0] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableLeft);
    mCompoundDrawableResIds[1] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableTop);
    mCompoundDrawableResIds[2] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableRight);
    mCompoundDrawableResIds[3] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableBottom);
    a.recycle();

    setCompoundDrawablesWithIntrinsicBounds(getCompoundDrawableByPosition(0), getCompoundDrawableByPosition(1),
            getCompoundDrawableByPosition(2), getCompoundDrawableByPosition(3));
}

From source file:com.givewaygames.transition.TransitionInflater.java

private void loadTransition(AttributeSet attrs, ViewGroup sceneRoot, TransitionManager transitionManager)
        throws Resources.NotFoundException {

    TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.TransitionManager);
    int transitionId = a.getResourceId(R.styleable.TransitionManager_transition, -1);
    Scene fromScene = null, toScene = null;
    int fromId = a.getResourceId(R.styleable.TransitionManager_fromScene, -1);
    if (fromId >= 0)
        fromScene = Scene.getSceneForLayout(sceneRoot, fromId, mContext);
    int toId = a.getResourceId(R.styleable.TransitionManager_toScene, -1);
    if (toId >= 0)
        toScene = Scene.getSceneForLayout(sceneRoot, toId, mContext);
    if (transitionId >= 0) {
        Transition transition = inflateTransition(transitionId);
        if (transition != null) {
            if (fromScene != null) {
                if (toScene == null) {
                    throw new RuntimeException(
                            "No matching toScene for given fromScene " + "for transition ID " + transitionId);
                } else {
                    transitionManager.setTransition(fromScene, toScene, transition);
                }//from  w  w w .j  a v  a2 s.  com
            } else if (toId >= 0) {
                transitionManager.setTransition(toScene, transition);
            }
        }
    }
    a.recycle();
}

From source file:com.givewaygames.transition.TransitionInflater.java

private void getTargetIds(XmlPullParser parser, AttributeSet attrs, Transition transition)
        throws XmlPullParserException, IOException {

    // Make sure we are on a start tag.
    int type;//from   www  .  jav a  2 s  .  c  o  m
    int depth = parser.getDepth();

    ArrayList<Integer> targetIds = new ArrayList<Integer>();
    while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
            && type != XmlPullParser.END_DOCUMENT) {

        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        String name = parser.getName();
        if (name.equals("target")) {
            TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.TransitionTarget);
            int id = a.getResourceId(R.styleable.TransitionTarget_targetId, -1);
            if (id >= 0) {
                targetIds.add(id);
            }
        } else {
            throw new RuntimeException("Unknown scene name: " + parser.getName());
        }
    }
    int numTargets = targetIds.size();
    if (numTargets > 0) {
        for (int i = 0; i < numTargets; ++i) {
            transition.addTarget(targetIds.get(i));
        }
    }
}