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 float dipToPixels(float dip, Resources resource) {

    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, resource.getDisplayMetrics());
    return px;//from ww  w  .  j  a v  a 2 s .  co  m

}

From source file:Main.java

public static float getRawSize(Resources resources, int unit, float size) {
    return TypedValue.applyDimension(unit, size, resources.getDisplayMetrics());
}

From source file:Main.java

public static int pxToDp(Context context, int px) {
    int dp = 0;/*from w w w . j av a 2s  .c om*/
    dp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, px,
            context.getResources().getDisplayMetrics());
    return dp;
}

From source file:Main.java

public static final int getDpPx(int dp, DisplayMetrics displayMetrics) {
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, displayMetrics);
    return px;/*w  ww  . j a  v a  2  s .c  om*/
}

From source file:Main.java

static int dp2px(int dp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            Resources.getSystem().getDisplayMetrics());
}

From source file:Main.java

static int sp2px(int sp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,
            Resources.getSystem().getDisplayMetrics());
}

From source file:Main.java

public static float dimenToPixels(Context context, int complexUnit, float units) {
    float pixels = TypedValue.applyDimension(complexUnit, units, context.getResources().getDisplayMetrics());
    return pixels;
}

From source file:Main.java

public static int getPX(Context context, int dipValue) {
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue,
            context.getResources().getDisplayMetrics());
    return (int) px;
}

From source file:Main.java

public static float getPixelsFromDp(float dp) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            Resources.getSystem().getDisplayMetrics());
}

From source file:Main.java

static int sp(float sp, DisplayMetrics metrics) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, metrics);
}