Example usage for android.util TypedValue COMPLEX_UNIT_SP

List of usage examples for android.util TypedValue COMPLEX_UNIT_SP

Introduction

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

Prototype

int COMPLEX_UNIT_SP

To view the source code for android.util TypedValue COMPLEX_UNIT_SP.

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is a scaled pixel.

Usage

From source file:Main.java

public static int spToPx(Context context, int sp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int getPxFromSp(float sp, Context context) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

/**
 * spTopx/*  w w w.  j  a  va 2s.  c o m*/
 * 
 * @param context
 * @param val
 * @return
 */
public static int sp2px(Context context, float spVal) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spVal,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

/**
 * sp2Px/*from  www .  j  a  v  a  2s .  c  o  m*/
 *
 * @param context context
 * @param sp      sp
 * @return float
 */
public static float sp2Px(Context context, int sp) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int spToPx(Context context, float spValue) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue, metrics);
}

From source file:Main.java

public static int sp(Context context, float sp) {
    Resources resources = context.getResources();
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, resources.getDisplayMetrics());
    return px;/* w w w.j a v a  2  s.c o m*/
}

From source file:Main.java

/**
 * sp*ppi/160  =px/*from  w  ww. ja  va 2 s.  c o  m*/
 * 
 * @param ctx
 * @param dip
 * @return
 */
public static int spToPX(final Context ctx, float sp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,
            ctx.getResources().getDisplayMetrics());
}

From source file:Main.java

public static float sp2px(Context context, float sp) {
    if (context == null) {
        return sp;
    }/*from w  w w.j a  v  a  2 s .  c o m*/
    Resources r = context.getResources();
    float size = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, r.getDisplayMetrics());
    return size;
}

From source file:Main.java

public static int sp2px(Context context, float spVal) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spVal, displayMetrics);
}

From source file:Main.java

/**
 * Converts scale pixels to pixels -- used for setting text sizes
 *
 * @param context context for getResources()
 * @param sp      desired scale pixels pixels
 * @return converted sp to pixels//from  w  w  w. jav a 2 s.c  o m
 */
static int spToPx(Context context, final float sp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,
            context.getResources().getDisplayMetrics());
}