List of usage examples for android.content.res Resources getDisplayMetrics
public DisplayMetrics getDisplayMetrics()
From source file:Main.java
public static DisplayMetrics getScreenInfo(Context context) { Resources resources = context.getResources(); DisplayMetrics dm = resources.getDisplayMetrics(); return dm;/*w w w . j a v a2 s. c o m*/ }
From source file:Main.java
public static float pixelsToSp(float px, Context context) { Resources resources = context.getResources(); float scaledDensity = resources.getDisplayMetrics().scaledDensity; return px / scaledDensity; }
From source file:Main.java
public static int screenWidth(Context context) { Resources resources = context.getResources(); DisplayMetrics dm = resources.getDisplayMetrics(); return dm.widthPixels; }
From source file:Main.java
public static int screenHeight(Context context) { Resources resources = context.getResources(); DisplayMetrics dm = resources.getDisplayMetrics(); return dm.heightPixels; }
From source file:Main.java
public static float convertDpToPixel(Context context, float densityPixel) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return densityPixel * (metrics.densityDpi / 160f); }
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 int sp2px(Context context, float spValue) { Resources resources = context.getResources(); final float fontScale = resources.getDisplayMetrics().scaledDensity; resources = null;//from ww w. ja v a 2 s.c o m return (int) (spValue * fontScale + 0.5f); }
From source file:Main.java
public static int getScreenHeight(Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return metrics.heightPixels; }
From source file:Main.java
public static int px2sp(Context context, float pxValue) { Resources resources = context.getResources(); final float fontScale = resources.getDisplayMetrics().scaledDensity; resources = null;//from w w w. j av a 2 s.c o m return (int) (pxValue / fontScale + 0.5f); }
From source file:Main.java
public static int convertSpToPixel(int sp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return Math.round(sp * metrics.scaledDensity); }