Example usage for android.content.res TypedArray getInt

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

Introduction

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

Prototype

public int getInt(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieve the integer value for the attribute at index.

Usage

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

@SuppressWarnings("ResourceType")
@Override/* ww  w  .ja  v  a 2 s.  c o  m*/
void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
    TypedArray array = mView.getContext().obtainStyledAttributes(attrs, ATTRS, defStyleAttr, 0);
    if (array.hasValue(1)) {
        mImageTintResId = array.getResourceId(1, 0);
        if (array.hasValue(2)) {
            setSupportImageTintMode(DrawableUtils.parseTintMode(array.getInt(2, 0), null));
        }
        setSupportImageTint(mImageTintResId);
    } else {
        Drawable image = mTintManager.getDrawable(mImageResId = array.getResourceId(0, 0));
        if (image != null) {
            setImageDrawable(image);
        }
    }
    array.recycle();
}

From source file:com.github.andrewlord1990.materialandroid.component.list.ListItemView.java

private void loadVariant(TypedArray typedAttrs) {
    @ListItemVariant/* w ww.jav a 2  s.  c o  m*/
    int variant = typedAttrs.getInt(R.styleable.MDListItemView_md_list_item_variant, VARIANT_ONE_LINE_TEXT);
    setVariant(variant);
}

From source file:cn.ieclipse.af.view.ScrollLayout.java

private void init(Context context, AttributeSet attrs) {
    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScrollLayout);
        debug = a.getBoolean(R.styleable.ScrollLayout_debug, false);
        mSnapVelocity = a.getInt(R.styleable.ScrollLayout_snapVelocity, SNAP_VELOCITY);

        a.recycle();//  ww w  . j a  v  a 2  s . co  m
    }

}

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

@SuppressWarnings("ResourceType")
@Override/*from  w ww  . ja  va 2s . co m*/
void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
    TypedArray array = mView.getContext().obtainStyledAttributes(attrs, ATTR, defStyleAttr, 0);
    if (array.hasValue(1)) {
        mForegroundResId = array.getResourceId(1, 0);
        if (array.hasValue(2)) {
            setSupportForegroundTintMode(DrawableUtils.parseTintMode(array.getInt(2, 0), null));
        }
        setSupportForegroundTint(mForegroundTintResId);
    } else {
        Drawable drawable = mTintManager.getDrawable(mForegroundResId = array.getResourceId(0, 0));
        if (drawable != null) {
            setForegroundDrawable(drawable);
        }
    }
    array.recycle();
}

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

@SuppressWarnings("ResourceType")
@Override/*w w  w.  j ava  2 s.  com*/
void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
    TypedArray array = mView.getContext().obtainStyledAttributes(attrs, ATTRS, defStyleAttr, 0);
    if (array.hasValue(1)) {
        mCompoundButtonTintResId = array.getResourceId(1, 0);
        if (array.hasValue(2)) {
            setSupportButtonDrawableTintMode(DrawableUtils.parseTintMode(array.getInt(2, 0), null));
        }
        setSupportButtonDrawableTint(mCompoundButtonTintResId);
    } else {
        Drawable drawable = mTintManager.getDrawable(mCompoundButtonResId = array.getResourceId(0, 0));
        if (drawable != null) {
            setButtonDrawable(drawable);
        }
    }
    array.recycle();
}

From source file:com.facebook.FacebookButtonBase.java

private void parseTextAttributes(final Context context, final AttributeSet attrs, final int defStyleAttr,
        final int defStyleRes) {
    final int colorResources[] = { android.R.attr.textColor, };
    final TypedArray colorAttrs = context.getTheme().obtainStyledAttributes(attrs, colorResources, defStyleAttr,
            defStyleRes);/*from   w w w .j a  v  a2 s . c  o m*/
    try {
        setTextColor(colorAttrs.getColor(0, Color.WHITE));
    } finally {
        colorAttrs.recycle();
    }
    final int gravityResources[] = { android.R.attr.gravity, };
    final TypedArray gravityAttrs = context.getTheme().obtainStyledAttributes(attrs, gravityResources,
            defStyleAttr, defStyleRes);
    try {
        setGravity(gravityAttrs.getInt(0, Gravity.CENTER));
    } finally {
        gravityAttrs.recycle();
    }
    final int attrsResources[] = { android.R.attr.textSize, android.R.attr.textStyle, android.R.attr.text, };
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr,
            defStyleRes);
    try {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, a.getDimensionPixelSize(0, 0));
        setTypeface(Typeface.defaultFromStyle(a.getInt(1, Typeface.BOLD)));
        setText(a.getString(2));
    } finally {
        a.recycle();
    }
}

From source file:com.google.blockly.android.FlyoutFragment.java

@Override
public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(context, attrs, savedInstanceState);
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.BlocklyFlyout, 0, 0);

    try {//from w  w w  .  j  a v  a2  s  .  c  om
        mCloseable = a.getBoolean(R.styleable.BlocklyFlyout_closeable, mCloseable);
        mScrollOrientation = a.getInt(R.styleable.BlocklyFlyout_scrollOrientation, mScrollOrientation);
    } finally {
        a.recycle();
    }
    // Store values in arguments, so fragment resume works (no inflation during resume).
    Bundle args = getArguments();
    if (args == null) {
        setArguments(args = new Bundle());
    }
    args.putBoolean(ARG_CLOSEABLE, mCloseable);
    args.putInt(ARG_SCROLL_ORIENTATION, mScrollOrientation);
}

From source file:com.alboteanu.android.sunshine.app.ForecastFragment.java

@Override
public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(activity, attrs, savedInstanceState);
    TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.ForecastFragment, 0, 0);
    mChoiceMode = a.getInt(R.styleable.ForecastFragment_android_choiceMode, AbsListView.CHOICE_MODE_NONE);
    mAutoSelectView = a.getBoolean(R.styleable.ForecastFragment_autoSelectView, false);
    mHoldForTransition = a.getBoolean(R.styleable.ForecastFragment_sharedElementTransitions, false);
    a.recycle();/*from w  w w .j  a  va 2  s. c  om*/
}

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

@SuppressWarnings("ResourceType")
@Override//from   www.j  a  v  a 2 s  .  c  om
void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
    initPadding();
    TypedArray array = mView.getContext().obtainStyledAttributes(attrs, ATTR, defStyleAttr, 0);
    if (array.hasValue(1)) {
        mBackgroundTintResId = array.getResourceId(1, 0);
        if (array.hasValue(2)) {
            setSupportBackgroundTintMode(DrawableUtils.parseTintMode(array.getInt(2, 0), null));
        }
        setSupportBackgroundTint(mBackgroundTintResId);
    } else {
        Drawable drawable = mTintManager.getDrawable(mBackgroundResId = array.getResourceId(0, 0));
        if (drawable != null) {
            setBackgroundDrawable(drawable);
        }
    }
    array.recycle();
}

From source file:com.actionbarsherlock.internal.widget.IcsLinearLayout.java

public IcsLinearLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs, /*com.android.internal.R.styleable.*/LinearLayout);

    setDividerDrawable(a.getDrawable(/*com.android.internal.R.styleable.*/LinearLayout_divider));
    mShowDividers = a.getInt(/*com.android.internal.R.styleable.*/LinearLayout_showDividers, SHOW_DIVIDER_NONE);
    mDividerPadding = a.getDimensionPixelSize(/*com.android.internal.R.styleable.*/LinearLayout_dividerPadding,
            0);/*from  ww  w.  java2s  .  c om*/

    a.recycle();
}