Example usage for android.util DisplayMetrics DENSITY_DEFAULT

List of usage examples for android.util DisplayMetrics DENSITY_DEFAULT

Introduction

In this page you can find the example usage for android.util DisplayMetrics DENSITY_DEFAULT.

Prototype

int DENSITY_DEFAULT

To view the source code for android.util DisplayMetrics DENSITY_DEFAULT.

Click Source Link

Document

The reference density used throughout the system.

Usage

From source file:Main.java

public static int getDPI(int size, DisplayMetrics metrics) {
    return (size * metrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT;
}

From source file:Main.java

static int dpToPx(float dp, float ppi, DisplayMetrics displayMetrics) {
    dp /= displayMetrics.density;/*from  www  .j a va  2s .co  m*/
    int px = Math.round(dp * (ppi / DisplayMetrics.DENSITY_DEFAULT));
    return px;
}

From source file:Main.java

public static int dpToPx(Context context, int dp) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;/*w w  w  .  j  a v a  2  s  .com*/
}

From source file:Main.java

public static int dpToPx(Context cx, int dp) {
    DisplayMetrics displayMetrics = cx.getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;/*www .j av a2 s. c o m*/
}

From source file:Main.java

public static int convertPxToDp(Context context, int px) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    int dp = Math.round(px / (metrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return dp;/*from   ww w .  jav  a2s .  c  o m*/
}

From source file:Main.java

public static int convertDpToPx(Context context, int dp) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    int px = Math.round(dp * (metrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;/*  w  w  w .jav  a 2 s. c om*/
}

From source file:Main.java

public static int convertDpToPixel(Context context, float dp) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    float px = dp * (metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
    return (int) px;
}

From source file:Main.java

public static int dpToPx(Activity context, int dp) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;//  w w  w .ja v  a  2 s.c  om
}

From source file:Main.java

public static int pxToDp(int px, Context context) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    int dp = Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return dp;/*from  w  w w.  ja  v a  2s . co m*/
}

From source file:Main.java

public static int pxFromDp(final Context context, final float dp) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;//from  www. j  a  v  a 2s  . c  o m
}