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

static int dp(float dp, DisplayMetrics metrics) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics);
}

From source file:Main.java

private static int dpToPx(Context context, int dp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static float dip2px(Context context, float value) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int dp2px(Context context, float dpVal) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpVal, getDM(context));
}

From source file:Main.java

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

From source file:Main.java

public static float dpToPx(Context context, float dp) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics()) + 0.5f;
}

From source file:Main.java

public static int pxToDp(int px, Context context) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, px,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int getDimensionSize(int size) {
    return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, size,
            Resources.getSystem().getDisplayMetrics()));
}

From source file:Main.java

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

From source file:Main.java

public static int dpToPx(Context context, int dp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics());
}