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 typeValueToSp(Context context, int sp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static float dipToPx(Resources res, float dip) {
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, res.getDisplayMetrics());
    return px;//from   ww  w . j  a va  2  s  . c  o m
}

From source file:Main.java

public static float dp2px(Resources resources, float dp) {
    float v = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics());
    return (int) (v + 0.5f);
}

From source file:Main.java

public static int pixelsToDpi(Resources resources, int i) {
    return (int) TypedValue.applyDimension(1, (float) i, resources.getDisplayMetrics());
}

From source file:Main.java

static public int getPixelFromDip(DisplayMetrics dm, float dip) {
    return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, dm) + 0.5f);
}

From source file:Main.java

public static int getSpToPx(Resources res, int dip) {
    int pixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, dip, res.getDisplayMetrics());
    return pixel;
}

From source file:Main.java

public static int getDipToPx(Resources res, int dip) {
    int pixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, res.getDisplayMetrics());
    return pixel;
}

From source file:Main.java

public static int convertDPIntoPixel(int dp, Context context) {
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics());
    return px;/* ww  w.j  a  v  a 2  s . c om*/
}

From source file:Main.java

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

From source file:Main.java

public static int sp2px(int spValue, DisplayMetrics displayMetrics) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue, displayMetrics);
}