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 float convertDpToPixel(float dp, Context context) {
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    return dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}

From source file:Main.java

public static float getRateDpToPixel(Context context) {
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    float rateDpToPixel = ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
    return rateDpToPixel;
}

From source file:Main.java

private static float convertDpToPixel(float dp, Context context) {
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    float px = dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
    return px;//  w w w. j a  v a2  s. c o  m
}

From source file:Main.java

public static int convertDpToPixel(float dp, Context context) {
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    int px = (int) (dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;/*from   w  ww .  ja  v a  2s .co m*/
}

From source file:Main.java

/**
 * dp to px/*from   w  ww. j  a  v  a  2s. c o m*/
 * @param dp
 * @param mContext
 * @return
 */
public static int dp2px(int dp, Context mContext) {
    DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;
}

From source file:Main.java

private static float getPixelScaleFactor(Context context) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    return displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT;
}

From source file:Main.java

private static float getPixelScaleFactor(Context context) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    return (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT);
}

From source file:Main.java

private static int getResourceDisplayDensityDPI(Context context) {
    try {/*from w  ww .j a v a2 s  . com*/
        Resources resources = context.getResources();
        DisplayMetrics displayMetrics = resources.getDisplayMetrics();
        return displayMetrics.densityDpi;
    } catch (NullPointerException expected) {
        return DisplayMetrics.DENSITY_DEFAULT;
    }
}

From source file:Main.java

public static int dpToPx(int dp, Context ctx) {
    DisplayMetrics displayMetrics = ctx.getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;/*www .  j ava  2  s . co m*/
}

From source file:Main.java

/**
 * Get a mirror Bitmap//from w w  w  .jav a 2 s. c om
 *
 * @param sourceBitmap Bitmap to Change
 * @return Mirror bitmap
 */
public static Bitmap getMirrorBitmap(Bitmap sourceBitmap) {
    Matrix m = new Matrix();
    m.preScale(-1, 1);
    Bitmap dst = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight(), m,
            false);
    dst.setDensity(DisplayMetrics.DENSITY_DEFAULT);
    return dst;
}