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

public static int dp(Context context, float dp) {
    Resources resources = context.getResources();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics());
}

From source file:Main.java

/**
 *  Converts 1 dip (device independent pixel) into its equivalent physical pixels
 *///from   ww  w. ja v  a2 s  .c om
public static float getDpiToPix(Context ctx) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, ctx.getResources().getDisplayMetrics());
}

From source file:Main.java

public static float convertDpToFloatPixel(Context context, float dp) {
    Resources r = context.getResources();
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
}

From source file:Main.java

/**
 * Convert Dp to Pixel/*from   w w w.  ja v a 2 s . c  om*/
 */
public static int dpToPx(float dp, Resources resources) {
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics());
    return (int) px;
}

From source file:Main.java

public static int dipToPix(Context context, int dip) {
    int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip,
            context.getResources().getDisplayMetrics());
    return size;//from w ww .  ja va  2 s.co  m
}

From source file:Main.java

public static float getRawSize(Context context, int unit, float size) {
    return TypedValue.applyDimension(unit, size, context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int convertDpToPixels(Context context, int dp) {
    Resources res = context.getResources();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, res.getDisplayMetrics());
}

From source file:Main.java

public static int getPixels(Context context, int dipValue) {
    Resources r = context.getResources();
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, r.getDisplayMetrics());
    return px;//  ww  w  .j  a  v  a2  s  .co  m
}

From source file:Main.java

/**
 * dp to px//from www  . j  ava  2 s  .com
 * @param dip
 * @param context
 * @return
 */
public static int dipTopx(float dip, Context context) {
    int num = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip,
            context.getResources().getDisplayMetrics());
    return num;
}

From source file:Main.java

/**
 * spTopx/*from   ww  w  .ja v a2 s .  c om*/
 * 
 * @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());
}