Example usage for android.util TypedValue applyDimension

List of usage examples for android.util TypedValue applyDimension

Introduction

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

Prototype

public static float applyDimension(int unit, float value, DisplayMetrics metrics) 

Source Link

Document

Converts an unpacked complex data value holding a dimension to its final floating point value.

Usage

From source file:Main.java

/**
 * dpTopx//from  w  w  w  .j ava 2  s .  com
 * 
 * @param context
 * @param val
 * @return
 */
public static int dp2px(Context context, float dpVal) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpVal,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int dip2Px(Resources res, int dip) {

    DisplayMetrics dm = res.getDisplayMetrics();
    return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, dm));
}

From source file:Main.java

public static int dpToPx(Context c, float dipValue) {
    DisplayMetrics metrics = c.getResources().getDisplayMetrics();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, metrics);
}

From source file:Main.java

static int dipToPx(Context context, float value) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, metrics);
}

From source file:Main.java

public static float dipToPx(Context context, float value) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, metrics);
}

From source file:Main.java

/**
 * dp2Px/* ww  w.  ja v a2  s.  c om*/
 *
 * @param context context
 * @param dp      dp
 * @return float
 */
public static float dp2Px(Context context, int dp) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

/**
 * sp2Px//from www.  j  ava 2  s  .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

/**
 * Converts the gives DPs into pixels for rendering on the screen correctly
 *///  www.  ja  v a 2  s.c o m
protected static int convertDipsToPixels(Context context, float dps) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dps,
            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 getPixels(Context context, int dp) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics);
}