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 getThemeColorPrimaryDark(Context ctx) {
    TypedValue typedValue = new TypedValue();
    ctx.getTheme().resolveAttribute(android.R.attr.theme, typedValue, true);
    int[] attribute = new int[] { android.R.attr.colorPrimaryDark };
    TypedArray array = ctx.obtainStyledAttributes(typedValue.resourceId, attribute);
    int color = array.getColor(0, -1);
    array.recycle();
    return color;
}

From source file:Main.java

public static int getResourceId(Context context, int attr, int defaultValue) {
    TypedArray ta = context.obtainStyledAttributes(new int[] { attr });
    int resourceId = ta.getResourceId(0, defaultValue);
    ta.recycle();

    return resourceId;
}

From source file:Main.java

public static int getThemeColor(Context context, int attrRes) {
    TypedArray typedArray = context.obtainStyledAttributes(new int[] { attrRes });
    int color = typedArray.getColor(0, 0xffffff);
    typedArray.recycle();
    return color;
}

From source file:Main.java

public static int getAccentColor(Context context) {
    TypedValue typedValue = new TypedValue();
    TypedArray typedArray = context.obtainStyledAttributes(typedValue.data, new int[] { 16843829 });
    int accent = typedArray.getColor(0, 0);
    typedArray.recycle();
    return accent;
}

From source file:Main.java

public static int getTextColorPrimary(Context context) {
    TypedValue typedValue = new TypedValue();
    TypedArray typedArray = context.obtainStyledAttributes(typedValue.data, new int[] { 16842806 });
    int accent = typedArray.getColor(0, 0);
    typedArray.recycle();
    return accent;
}

From source file:Main.java

public static int getPrimaryColor(Context context) {
    TypedValue typedValue = new TypedValue();
    TypedArray typedArray = context.obtainStyledAttributes(typedValue.data, new int[] { 16843827 });
    int accent = typedArray.getColor(0, 0);
    typedArray.recycle();
    return accent;
}

From source file:Main.java

/**
 * Get a resource id from an attribute id.
 * @param context//from  w w w . j  av  a 2s.  c om
 * @param attrId
 * @return the resource id
 */
public static int getResourceFromAttribute(Context context, int attrId) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attrId });
    int resId = a.getResourceId(0, 0);
    a.recycle();
    return resId;
}

From source file:Main.java

public static int getThemeAttrColor(@NonNull Context context, @AttrRes int attr) {
    TypedArray a = context.obtainStyledAttributes(null, new int[] { attr });
    try {//from   ww w .  ja v  a  2s.c o m
        return a.getColor(0, 0);
    } finally {
        a.recycle();
    }
}

From source file:Main.java

public static float getDimension(Context context, @StyleRes int styleResId, @AttrRes int attr) {
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(styleResId, new int[] { attr });
    float size = typedArray.getDimension(0, 0);
    typedArray.recycle();
    return size;//  w w w.j  ava2  s . c o m
}

From source file:Main.java

@SuppressWarnings("ConstantConditions")
public static float resolveFloat(Context context, int attr) {
    TypedArray a = context.obtainStyledAttributes(null, new int[] { attr });
    try {//  w w  w.  j  a  va2 s .  com
        return a.getFloat(0, 0);
    } finally {
        a.recycle();
    }
}