List of usage examples for android.content.res Resources getDisplayMetrics
public DisplayMetrics getDisplayMetrics()
From source file:Main.java
/** * Converts the passed float value (dip) into pixels based on the resource * @param res the Resources to use for retrieving display metrics * @param value the dip value to convert * @return the passed dip's pixel equivalent. * /*from w w w.ja v a 2 s . c o m*/ * @deprecated use getResources().getDimensionPixelSize(R.dimen.your_dimension_to_convert); */ @Deprecated public static float convertFromDip(final Resources res, final float value) { return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, res.getDisplayMetrics()); }
From source file:org.kaaproject.kaa.demo.notification.fragment.BaseListFragment.java
public static int convertDpToPixel(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); return (int) px; }
From source file:Main.java
public static int pixToDip(Context context, float pixValue) { Resources r = context.getResources(); float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, pixValue, r.getDisplayMetrics()); return (int) px; }
From source file:Main.java
/** * This method converts dp to pixels//from ww w.ja v a2 s . c o m * * @param dp * Oiringla dp * @param context * App context * * @return Dp value in pixels */ public static int dp2Pixels(int dp, Context context) { Resources r = context.getResources(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); }
From source file:Main.java
public static int getPixels(Context context, int dipValue) { Resources r = context.getResources(); int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, r.getDisplayMetrics()); return px;// ww w . j av a2 s .c om }
From source file:Main.java
public static int sp(Context context, float sp) { Resources resources = context.getResources(); int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, resources.getDisplayMetrics()); return px;//from w w w. ja va 2 s.co m }
From source file:Main.java
/** * Resize a {@link Drawable} to the given size.<br /> * Metrics and density are given by the {@link Resources} bount to this instance. * @param ctx Context.//from w ww . j a v a 2 s . c o m * @param drawable {@link Drawable} to resize. * @param width Desired width in {@code dp}. * @param height Desired height in {@code dp}. * @return A scaled {@link Drawable}. */ public static Drawable resizeDrawable(Context ctx, Drawable drawable, int width, int height) { Resources res = ctx.getResources(); float density = res.getDisplayMetrics().density; //Get a bitmap from the drawable Bitmap bmp = drawableToBitmap(drawable); //Create a scaled bitmap bmp = Bitmap.createScaledBitmap(bmp, (int) (width * density), (int) (height * density), true); //Convert bitmap to drawable return new BitmapDrawable(res, bmp); }
From source file:Main.java
public static int dp(Context context, float dp) { Resources resources = context.getResources(); int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics()); return px;/*from w w w .j av a 2 s . c o m*/ }
From source file:Main.java
public static int getPixels(Context context, int dipValue) { Resources r = context.getResources(); int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, r.getDisplayMetrics()); Log.d("getPixels", "" + px); return px;//from w w w .ja va 2 s . c o m }
From source file:Main.java
public static int dipToPixels(Context applicationContext, int dip) { Resources r = applicationContext.getResources(); float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, r.getDisplayMetrics()); return (int) px; }