Example usage for android.util TypedValue TypedValue

List of usage examples for android.util TypedValue TypedValue

Introduction

In this page you can find the example usage for android.util TypedValue TypedValue.

Prototype

TypedValue

Source Link

Usage

From source file:Main.java

/**
 * get action bar height//  w ww . java  2  s . c  o m
 *
 * @param context
 * @return
 */
public static int getActionBarHeight(Context context) {
    int actionBarHeight = 0;
    if (context instanceof Activity && ((Activity) context).getActionBar() != null) {
        actionBarHeight = ((Activity) context).getActionBar().getHeight();
    }

    if (actionBarHeight == 0) {
        final TypedValue tv = new TypedValue();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && (context.getTheme() != null
                && context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                    context.getResources().getDisplayMetrics());
        }
    }
    return actionBarHeight;
}

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;
    }/*from   w  w  w  . jav a 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

public static long resKey(Context context, int resId) {
    TypedValue value = new TypedValue();
    context.getResources().getValue(resId, value, true);
    return (((long) value.assetCookie) << 32) | value.data;
}

From source file:Main.java

/**
 * Last but not least, try to pull the Font Path from the Theme, which is defined.
 *
 * @param context     Activity Context//from  ww w  . j  av a2s . com
 * @param styleId     Theme style id
 * @param attributeId if -1 returns null.
 * @return null if no theme or attribute defined.
 */
static String pullFontPathFromTheme(Context context, int styleId, int attributeId) {
    if (styleId == -1 || attributeId == -1)
        return null;

    final Resources.Theme theme = context.getTheme();
    final TypedValue value = new TypedValue();

    theme.resolveAttribute(styleId, value, true);
    final TypedArray typedArray = theme.obtainStyledAttributes(value.resourceId, new int[] { attributeId });
    try {
        return typedArray.getString(0);
    } catch (Exception ignore) {
        // Failed for some reason.
        return null;
    } finally {
        typedArray.recycle();
    }
}

From source file:Main.java

public static int getActionBarSize(Context context) {
    TypedValue tv = new TypedValue();
    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        int actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                context.getResources().getDisplayMetrics());
        return actionBarHeight;
    }//from   ww  w  .  java  2 s  . co m
    return 0;
}

From source file:Main.java

/**
 * Last but not least, try to pull the Font Path from the Theme, which is defined.
 *
 * @param context     Activity Context//from   ww  w.ja v a 2 s . c  om
 * @param styleAttrId Theme style id
 * @param attributeId if -1 returns null.
 * @return null if no theme or attribute defined.
 */
static String pullFontPathFromTheme(Context context, int styleAttrId, int[] attributeId) {
    if (styleAttrId == -1 || attributeId == null)
        return null;

    final Resources.Theme theme = context.getTheme();
    final TypedValue value = new TypedValue();

    theme.resolveAttribute(styleAttrId, value, true);
    final TypedArray typedArray = theme.obtainStyledAttributes(value.resourceId, attributeId);
    try {
        String font = typedArray.getString(0);
        return font;
    } catch (Exception ignore) {
        // Failed for some reason.
        return null;
    } finally {
        typedArray.recycle();
    }
}

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();/*from   w  w w  . j  av  a2 s.  co  m*/
    return accent;
}

From source file:Main.java

public static int getABHeight(Context context) {

    int actionBarHeight = 0;
    TypedValue tva = new TypedValue();
    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tva, true))
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tva.data,
                context.getResources().getDisplayMetrics());
    return actionBarHeight;
}

From source file:Main.java

/**
 * Last but not least, try to pull the Font Path from the Theme, which is defined.
 *
 * @param context     Activity Context/*w w w  . jav a2s  .  c om*/
 * @param styleAttrId Theme style id
 * @param attributeId if -1 returns null.
 * @return null if no theme or attribute defined.
 */
static String pullFontPathFromTheme(Context context, int styleAttrId, int attributeId) {
    if (styleAttrId == -1 || attributeId == -1)
        return null;

    final Resources.Theme theme = context.getTheme();
    final TypedValue value = new TypedValue();

    theme.resolveAttribute(styleAttrId, value, true);
    final TypedArray typedArray = theme.obtainStyledAttributes(value.resourceId, new int[] { attributeId });
    try {
        String font = typedArray.getString(0);
        return font;
    } catch (Exception ignore) {
        // Failed for some reason.
        return null;
    } finally {
        typedArray.recycle();
    }
}

From source file:Main.java

public static TypedValue resolveThemeAttribute(Context context, int attrId) {
    TypedValue value = new TypedValue();
    context.getTheme().resolveAttribute(attrId, value, true);
    return value;
}