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) {
    int[] attrs = new int[] { android.R.attr.actionBarSize };
    TypedArray styledAttributes = context.getTheme().obtainStyledAttributes(attrs);
    int actionBarHeight = (int) styledAttributes.getDimension(0, 0);
    styledAttributes.recycle();
    return actionBarHeight;
}

From source file:Main.java

public static TypedValue getValue(Context context, int attr) {
    TypedArray ta = context.obtainStyledAttributes(new int[] { attr });
    TypedValue tv = new TypedValue();
    boolean bool = ta.getValue(0, tv);
    ta.recycle();
    if (bool == true)
        return tv;

    return null;//  w w  w.  j  ava 2s.  com
}

From source file:Main.java

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

From source file:Main.java

public static int getColor(Context context, @AttrRes int attr) {
    final TypedArray styledAttributes = context.obtainStyledAttributes(new int[] { attr });
    final int result = styledAttributes.getColor(0, -1);
    styledAttributes.recycle();
    return result;
}

From source file:Main.java

public static int resolveColor(Context context, int attr, int fallback) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attr });
    try {//from w  w  w .  j a v a2 s.c om
        return a.getColor(0, fallback);
    } finally {
        a.recycle();
    }
}

From source file:Main.java

public static int resolveColor(Context context, @AttrRes int attr, int fallback) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attr });
    try {//ww  w.  j a  v a 2  s .  com
        return a.getColor(0, fallback);
    } finally {
        a.recycle();
    }
}

From source file:Main.java

public static boolean getWindowTranslucentStatus(Context context) {
    final TypedArray a = context.obtainStyledAttributes(THEME_ATTRS);

    try {/*from w ww  .ja  v  a2s  . com*/
        return a.getBoolean(1, false);
    } finally {
        a.recycle();
    }
}

From source file:Main.java

/**
 * //  w  w  w . ja  v a 2  s  . co  m
 * @param context
 * @param view
 * @param resid
 * @return
 */
public static View addBackgroundIndicator(Context context, View view, int resid) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        TypedArray attributes = context.obtainStyledAttributes(new int[] { resid });
        int resource = attributes.getResourceId(0, 0);
        attributes.recycle();

        // setBackgroundResource resets padding
        int paddingLeft = view.getPaddingLeft();
        int paddingTop = view.getPaddingTop();
        int paddingRight = view.getPaddingRight();
        int paddingBottom = view.getPaddingBottom();
        view.setBackgroundResource(resource);
        view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
    }
    return view;
}

From source file:Main.java

public static boolean resolveBoolean(Context context, @AttrRes int attr, boolean fallback) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attr });
    try {/* ww  w .jav a2 s. co  m*/
        return a.getBoolean(0, fallback);
    } finally {
        a.recycle();
    }
}

From source file:Main.java

/**
 * Get a color value from a theme attribute.
 * @param context used for getting the color.
 * @param attribute theme attribute.//from   w  ww .j  av a2s.  c o m
 * @param defaultColor default to use.
 * @return color value
 */
public static int getThemeColor(Context context, int attribute, int defaultColor) {
    int themeColor = 0;
    String packageName = context.getPackageName();
    try {
        Context packageContext = context.createPackageContext(packageName, 0);
        ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(packageName, 0);
        packageContext.setTheme(applicationInfo.theme);
        Resources.Theme theme = packageContext.getTheme();
        TypedArray ta = theme.obtainStyledAttributes(new int[] { attribute });
        themeColor = ta.getColor(0, defaultColor);
        ta.recycle();
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return themeColor;
}