Example usage for android.content Context obtainStyledAttributes

List of usage examples for android.content Context obtainStyledAttributes

Introduction

In this page you can find the example usage for android.content Context obtainStyledAttributes.

Prototype

public final TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) 

Source Link

Document

Retrieve styled attribute information in this Context's theme.

Usage

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();/*from   w  w  w  .  j av a 2  s.c om*/

    return dimension;
}

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();/*from  w w w .  j a  va 2 s .  com*/
    if (bool == true)
        return tv;

    return null;
}

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();//from   w  ww.j  a  v a  2  s .  c o m
    return color;
}

From source file:Main.java

public static int getDefaultStatusBarBackground(Context context) {
    final TypedArray a = context.obtainStyledAttributes(THEME_ATTRS);
    try {/*ww  w  .j  a  va  2 s.  co m*/
        return a.getColor(0, Color.TRANSPARENT);
    } finally {
        a.recycle();
    }
}

From source file:Main.java

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

    try {// www. j  ava  2  s. c  om
        return a.getBoolean(1, false);
    } finally {
        a.recycle();
    }
}

From source file:Main.java

public static int[] getColorsFromAttributes(Context context, int... attr) {
    final TypedArray a = context.obtainStyledAttributes(attr);
    int[] colors = new int[a.getIndexCount()];
    for (int i = 0; i < a.getIndexCount(); i++) {
        colors[i] = a.getColor(i, 0);//  w  ww  .  j  a v a2 s  .c  om
    }
    a.recycle();
    return colors;
}

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();//from w  w w.j a  v a 2  s  .  c  o  m

    return bool;
}

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();// w ww .  j a va 2 s . c  o  m

    return resourceId;
}

From source file:Main.java

private static TypedArray getTypedArray(Context context, int attrId) {
    int[] attrs = new int[] { attrId };
    return context.obtainStyledAttributes(attrs);
}

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();/*from   w w  w. jav  a 2  s . co m*/
    return result;
}