List of usage examples for android.util TypedValue COMPLEX_UNIT_DIP
int COMPLEX_UNIT_DIP
To view the source code for android.util TypedValue COMPLEX_UNIT_DIP.
Click Source Link
From source file:Main.java
/** * Get dpi value from pixels.// w w w .ja v a2 s .c o 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 ww w .j a va 2s . c o m*/ animator.setDuration(150); animator.start(); }
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;/*w w w .jav a2 s . c o m*/ }
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
static int convertToPx(int dp, Resources resources) { DisplayMetrics dm = resources.getDisplayMetrics(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, dm); }
From source file:Main.java
public static int getPixelsInt(Context context, float dp) { Resources r = context.getResources(); return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics())); }
From source file:Main.java
public static int getSizeByGivenAbsSize(Context context, int givenAbsSize) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, givenAbsSize, context.getResources().getDisplayMetrics()); }
From source file:Main.java
/** * Converts the number in pixels to the number in dips *//*from w w w . j a va 2 s . c o m*/ public static int convertToDip(DisplayMetrics displayMetrics, int sizeInPixels) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sizeInPixels, displayMetrics); }
From source file:Main.java
/** * dp to pixels/*from www .j a va2 s . c o m*/ * @param val dp * @return pixels */ public static int dpToPx(float val) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, val, _dm); }