|
@@ -1,8 +1,11 @@
|
1
|
1
|
package com.reactnativenavigation.utils;
|
2
|
2
|
|
|
3
|
+import android.content.Context;
|
|
4
|
+import android.content.res.Resources;
|
3
|
5
|
import android.graphics.PorterDuff;
|
4
|
6
|
import android.graphics.PorterDuffColorFilter;
|
5
|
7
|
import android.graphics.drawable.Drawable;
|
|
8
|
+import android.util.DisplayMetrics;
|
6
|
9
|
|
7
|
10
|
/**
|
8
|
11
|
* Created by guyc on 23/04/16.
|
|
@@ -13,4 +16,17 @@ public class ImageUtils {
|
13
|
16
|
drawable.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.SRC_IN));
|
14
|
17
|
}
|
15
|
18
|
|
|
19
|
+ /**
|
|
20
|
+ * This method converts dp unit to equivalent pixels, depending on device density.
|
|
21
|
+ *
|
|
22
|
+ * @param dp A value in dp (density independent pixels) unit. Which we need to convert into pixels
|
|
23
|
+ * @param context Context to get resources and device specific display metrics
|
|
24
|
+ * @return A float value to represent px equivalent to dp depending on device density
|
|
25
|
+ */
|
|
26
|
+ public static float convertDpToPixel(float dp, Context context){
|
|
27
|
+ Resources resources = context.getResources();
|
|
28
|
+ DisplayMetrics metrics = resources.getDisplayMetrics();
|
|
29
|
+ float px = dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
|
|
30
|
+ return px;
|
|
31
|
+ }
|
16
|
32
|
}
|