Example usage for android.content.res TypedArray recycle

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

Introduction

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

Prototype

public void recycle() 

Source Link

Document

Recycles the TypedArray, to be re-used by a later caller.

Usage

From source file:Main.java

public static int getStyledColor(Context context, int attrId) {
    TypedArray ta = getTypedArray(context, attrId);
    int color = ta.getColor(0, 0);
    ta.recycle();

    return color;
}

From source file:Main.java

public static int resolveResource(Context context, int attr) {
    int[] attribute = new int[] { attr };
    TypedArray array = context.obtainStyledAttributes(attribute);
    int reference = array.getResourceId(0, 0);
    array.recycle();
    return reference;
}

From source file:Main.java

private static int getTextColorFromStyle(Context ctx, int styleId) {
    TypedArray ta = ctx.obtainStyledAttributes(styleId, typeArray);
    int color = ta.getColor(0, DEFAULT_COLOR);
    ta.recycle();
    return color;
}

From source file:Main.java

public static Drawable getThemeUpIndicator(Object info, Activity activity) {
    final TypedArray a = activity.obtainStyledAttributes(THEME_ATTRS);
    final Drawable result = a.getDrawable(0);
    a.recycle();
    return result;
}

From source file:Main.java

public static int getAttributedColor(Context context, int attr) {
    int[] set = { attr };
    TypedValue typedValue = new TypedValue();
    TypedArray a = context.obtainStyledAttributes(typedValue.data, set);
    int color = a.getColor(0, Color.WHITE);
    a.recycle();
    return color;
}

From source file:Main.java

public static int getColorFromContext(Context context, int color_id) {
    int[] textSizeAttr = new int[] { color_id };
    TypedValue typedValue = new TypedValue();
    TypedArray a = context.obtainStyledAttributes(typedValue.data, textSizeAttr);
    int color = a.getColor(0, 0);
    a.recycle();
    return color;
}

From source file:Main.java

public static int getDimensionPixelSize(Activity activity, int attr, int defaultValue) {
    int[] attrs = new int[] { attr };
    TypedArray ta = activity.obtainStyledAttributes(attrs);
    int value = ta.getDimensionPixelSize(0, defaultValue);
    ta.recycle();
    return value;
}

From source file:Main.java

public static boolean getboolean(Context context, int attr, boolean defaultValue) {
    TypedArray ta = context.obtainStyledAttributes(new int[] { attr });
    boolean bool = ta.getBoolean(0, defaultValue);
    ta.recycle();

    return bool;//  w  w w.  j  a  v a2 s. c  o  m
}

From source file:Main.java

public static int getPixelDimension(Context context, int attr) {
    TypedArray ta = context.obtainStyledAttributes(new int[] { attr });
    int dimension = ta.getDimensionPixelSize(0, 0);
    ta.recycle();

    return dimension;
}

From source file:Main.java

/**
 * Gets an integer from an attribute or uses a default value if not present.
 * @param context context//from w  w  w .  ja  va 2  s .c om
 * @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;
}