List of usage examples for android.util TypedValue applyDimension
public static float applyDimension(int unit, float value, DisplayMetrics metrics)
From source file:Main.java
public static float dipToPixels(Context context, int dipValue) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, metrics); }
From source file:Main.java
public static int getPixelSize(Context context, int dip) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, metrics); }
From source file:Main.java
public static int dpToPixels(int dp) { DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics(); return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, displayMetrics)); //return Math.round(dp * Resources.getSystem().getDisplayMetrics().density); }
From source file:Main.java
/** * Converteert DIP naar het bijbehorend aantal pixels * @param c//w w w . ja v a2 s. c om * @param dip * @return */ public static int DIPtoPX(Context c, int dip) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, c.getResources().getDisplayMetrics()); }
From source file:Main.java
public static int dip2px(Context context, float dp) { Resources r = context.getResources(); float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); return Math.round(px); }
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;/*www . j a v a2s.c o m*/ }
From source file:Main.java
/** dip to px */ public static int dip2px(Context context, int dip) { int finalPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, context.getResources().getDisplayMetrics()); // final float scale = context.getResources().getDisplayMetrics().density; // return (int) (dip * scale + 0.5f); return finalPx; }
From source file:Main.java
/** * Get dpi value from pixels./*w w w.j a va2 s .co m*/ * @param pixels * @param context * @return */ public static int getDpiFromInteger(int pixels, Context context) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, pixels, context.getResources().getDisplayMetrics()); }
From source file:Main.java
public static float getPixels(Context context, float dp) { Resources r = context.getResources(); return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); }
From source file:Main.java
public static void shake(View v) { final float distance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4.0f, v.getResources().getDisplayMetrics()); final ObjectAnimator animator = ObjectAnimator.ofFloat(v, "translationX", 0, distance, 0, -distance, 0); animator.setRepeatMode(ObjectAnimator.RESTART); animator.setInterpolator(new LinearInterpolator()); animator.setRepeatCount(4);/*from w w w.j ava 2 s. co m*/ animator.setDuration(150); animator.start(); }