Example usage for android.util TypedValue COMPLEX_UNIT_DIP

List of usage examples for android.util TypedValue COMPLEX_UNIT_DIP

Introduction

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

Prototype

int COMPLEX_UNIT_DIP

To view the source code for android.util TypedValue COMPLEX_UNIT_DIP.

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is Device Independent Pixels.

Usage

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static float pxFromDp(final Context context, final int dp) {
    if (context != null)
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
                context.getResources().getDisplayMetrics());
    else/*from www .j  a  v a2  s  . c  o m*/
        return 0;
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

static int getPixelForDp(Context context, int displayPixels) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, displayPixels,
            context.getResources().getDisplayMetrics());
}

From source file:Main.java

public static int convertDipToPx(int dip, Resources resources) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, resources.getDisplayMetrics());
}

From source file:Main.java

private static boolean canFit(Resources res, int adWidth) {
    int adWidthPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, adWidth,
            res.getDisplayMetrics());//from   w ww  .ja v a  2s . c o m
    DisplayMetrics metrics = res.getDisplayMetrics();
    return metrics.widthPixels >= adWidthPx;
}

From source file:Main.java

public static int dpToPx(int dp, Context ctx) {
    Resources r = ctx.getResources();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
}

From source file:Main.java

/**
 * @param context//from  w  w  w .  j  a v  a2  s.  c o  m
 * @param dp
 * @return
 */
public static int dp2px(Context context, int dp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics());
}