Example usage for android.content.res TypedArray getInteger

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

Introduction

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

Prototype

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

Source Link

Document

Retrieve the integer value for the attribute at index.

Usage

From source file:Main.java

/**
 * Gets an integer from an attribute or uses a default value if not present.
 * @param context context/*from  ww w .  ja  v  a2 s . c  o m*/
 * @param attrResId resource ID of the attribute
 * @param defaultValue fallback value
 * @return integer
 */
public static int getIntegerFromAttribute(Context context, @AttrRes int attrResId, int defaultValue) {
    int[] attrs = new int[] { attrResId };
    TypedArray ta = context.obtainStyledAttributes(attrs);
    final int value = ta.getInteger(0, defaultValue);
    ta.recycle();

    return value;
}

From source file:org.bubenheimer.android.preference.EditNonNegIntPreference.java

private static Pair<Integer, Integer> extractMinMax(final Context context, final AttributeSet attrs) {
    final int min;
    final int max;
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.EditNonNegIntPreference,
            0, 0);// ww w . j ava  2  s. c  om
    try {
        min = a.getInteger(R.styleable.EditNonNegIntPreference_min, 0);
        max = a.getInteger(R.styleable.EditNonNegIntPreference_max, Integer.MAX_VALUE);
    } finally {
        a.recycle();
    }
    return new Pair<>(min, max);
}

From source file:de.mrapp.android.util.ThemeUtil.java

/**
 * Obtains the integer value, which corresponds to a specific resource id, from a specific
 * theme.//from ww  w  .  j  a  va  2s. co  m
 *
 * @param context
 *         The context, which should be used, as an instance of the class {@link Context}. The
 *         context may not be null
 * @param themeResourceId
 *         The resource id of the theme, the attribute should be obtained from, as an {@link
 *         Integer} value or -1, if the attribute should be obtained from the given context's
 *         theme
 * @param resourceId
 *         The resource id of the attribute, which should be obtained, as an {@link Integer}
 *         value. The resource id must corresponds to a valid theme attribute
 * @return The integer value, which has been obtained, as an {@link Integer} value or 0, if the
 * given resource id is invalid
 */
public static int getInteger(@NonNull final Context context, @StyleRes final int themeResourceId,
        @AttrRes final int resourceId) {
    TypedArray typedArray = null;

    try {
        typedArray = obtainStyledAttributes(context, themeResourceId, resourceId);
        return typedArray.getInteger(0, 0);
    } finally {
        if (typedArray != null) {
            typedArray.recycle();
        }
    }
}

From source file:arun.com.chromer.settings.widgets.ColorPreference.java

@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
    return a.getInteger(index, DEFAULT_COLOR);
}

From source file:com.jakewharton.behavior.drawer.DrawerBehavior.java

@Keep
@SuppressWarnings("unused") // Instantiated reflectively from layout XML.
public DrawerBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DrawerBehavior);
    int gravity = a.getInteger(R.styleable.DrawerBehavior_android_layout_gravity, GravityCompat.END);
    a.recycle();//  ww  w .j av  a 2  s.c  o m

    validateGravity(gravity);
    this.gravity = gravity;
}

From source file:se.johan.wendler.ui.view.DragGripView.java

public DragGripView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    mGravity = a.getInteger(0, mGravity);
    int mColor = a.getColor(1, 0x33333333);
    a.recycle();//from   ww w . jav  a 2 s  .  c om

    final Resources res = getResources();
    mRidgeSize = res.getDimensionPixelSize(R.dimen.drag_grip_ridge_size);
    mRidgeGap = res.getDimensionPixelSize(R.dimen.drag_grip_ridge_gap);

    mRidgePaint = new Paint();
    mRidgePaint.setColor(mColor);
}

From source file:org.bubenheimer.android.preference.ConstrainedEditTextPreference.java

@SuppressWarnings("WeakerAccess")
protected ConstrainedEditTextPreference(final Context context, final AttributeSet attrs,
        final Pair<Integer, Integer> defaults) {
    super(context, attrs);

    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
            R.styleable.ConstrainedEditTextPreference, 0, 0);
    try {/*from w  w w . j a va  2s. c o  m*/
        this.minLength = a.getInteger(R.styleable.ConstrainedEditTextPreference_minLen, defaults.first);
        this.maxLength = a.getInteger(R.styleable.ConstrainedEditTextPreference_maxLen, defaults.second);
    } finally {
        a.recycle();
    }
}

From source file:org.bubenheimer.android.preference.EditIntPreference.java

@SuppressWarnings("WeakerAccess")
protected EditIntPreference(final Context context, final AttributeSet attrs,
        final Pair<Integer, Integer> defaults) {
    super(context, attrs);

    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.EditIntPreference, 0, 0);
    try {//from ww w  . j av a  2 s . co m
        this.min = a.getInteger(R.styleable.EditIntPreference_min, defaults.first);
        this.max = a.getInteger(R.styleable.EditIntPreference_max, defaults.second);
    } finally {
        a.recycle();
    }
}

From source file:individual.leobert.calendar.CalendarDateView.java

public CalendarDateView(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CalendarDateView);
    row = a.getInteger(R.styleable.CalendarDateView_ilc_calendar_row, 6);
    a.recycle();//from   www . ja va 2  s .co m
    init();
}

From source file:com.inmobi.nativead.sample.photopages.CustomViewPager.java

private void applyXmlAttributes(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CustomViewPager);

    this.actionDistance = a.getInteger(R.styleable.CustomViewPager_actionDistance, ACTION_DISTANCE_AUTO);
    this.scaleDownGravity = a.getFloat(R.styleable.CustomViewPager_scaleDownGravity, 1.0f);
    this.maxRotation = a.getInteger(R.styleable.CustomViewPager_maxRotation, 45);
    this.unselectedAlpha = a.getFloat(R.styleable.CustomViewPager_unselectedAlpha, 0.3f);
    this.unselectedSaturation = a.getFloat(R.styleable.CustomViewPager_unselectedSaturation, 0.0f);
    this.unselectedScale = a.getFloat(R.styleable.CustomViewPager_unselectedScale, 0.75f);

    a.recycle();//from  w  w  w  .java 2  s. c o m
}