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 getActionBarHeight(Context context) {

    if (mActionBarHeight != -1) {
        return mActionBarHeight;
    }/*from w  w w  . j  a  v  a 2  s  . c o  m*/

    TypedArray typedArray = context.obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
    mActionBarHeight = (int) typedArray.getDimension(0, 0);
    typedArray.recycle();

    return mActionBarHeight;
}

From source file:Main.java

public static int getDefaultStatusBarBackground(Context context) {
    final TypedArray a = context.obtainStyledAttributes(THEME_ATTRS);
    try {/*from w w  w  . ja v  a 2  s  .  c  o  m*/
        return a.getColor(0, Color.TRANSPARENT);
    } finally {
        a.recycle();
    }
}

From source file:Main.java

private static int resolveDimension(Context context, @AttrRes int attr, int fallback) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attr });
    try {//from   ww w.  j  av  a 2  s  . co m
        return a.getDimensionPixelSize(0, fallback);
    } finally {
        a.recycle();
    }
}

From source file:Main.java

public static Drawable getActionBarBackground(Context context) {
    TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.actionBarStyle, outValue, true);
    TypedArray typedArray = context.obtainStyledAttributes(outValue.resourceId,
            new int[] { android.R.attr.background });
    Drawable background = typedArray.getDrawable(0);
    typedArray.recycle();
    return background;
}

From source file:Main.java

public static Drawable getSplitActionBarBackground(Context context) {
    TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.actionBarStyle, outValue, true);
    TypedArray typedArray = context.obtainStyledAttributes(outValue.resourceId,
            new int[] { android.R.attr.backgroundSplit });
    Drawable background = typedArray.getDrawable(0);
    typedArray.recycle();
    return background;
}

From source file:Main.java

static public int getAccentColor(Context context) {
    int identifier = context.getResources().getIdentifier("colorAccent", "attr", context.getPackageName());
    if (identifier == 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        identifier = android.R.attr.colorAccent;
    }//w  w  w  .ja va  2s.  c  o  m
    if (identifier > 0) {
        TypedValue typedValue = new TypedValue();
        TypedArray a = context.obtainStyledAttributes(typedValue.data, new int[] { identifier });
        if (a != null) {
            int color = a.getColor(0, 0);
            a.recycle();
            return color;
        }
    }
    return Color.BLACK;
}

From source file:Main.java

@SuppressLint("UseSparseArrays")
@SuppressWarnings("ResourceType")
public static Map<Integer, Pair<String, String>> obtainBadgeMap(Context context, @ArrayRes int id) {

    TypedArray badgeArray = context.getResources().obtainTypedArray(id);

    Map<Integer, Pair<String, String>> badgeMap = new HashMap<>();
    for (int i = 0; i < badgeArray.length(); i++) {
        int resId = badgeArray.getResourceId(i, -1);
        if (resId != -1) {
            TypedArray array = context.getResources().obtainTypedArray(resId);
            badgeMap.put(resId, new Pair<>(array.getString(0), array.getString(1)));
            array.recycle();
        }/*from w  ww. ja  va  2s  .  com*/
    }
    badgeArray.recycle();
    return badgeMap;
}

From source file:Main.java

public static int getActionBarHeight(Context context) {
    final TypedArray styledAttributes = context.getTheme()
            .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
    int mActionBarSize = (int) styledAttributes.getDimension(0, 0);
    styledAttributes.recycle();
    return mActionBarSize;
}

From source file:Main.java

public static int getToolBarHeight(Context context) {
    final TypedArray styledAttributes = context.getTheme()
            .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
    int mActionBarSize = (int) styledAttributes.getDimension(0, 0);
    styledAttributes.recycle();
    return mActionBarSize;
}

From source file:Main.java

public static int getActionBarHeight(Context c) {

    int mActionBarSize;

    final TypedArray styledAttributes = c.getTheme()
            .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
    mActionBarSize = (int) styledAttributes.getDimension(0, 0);
    styledAttributes.recycle();

    return mActionBarSize;

}