public static float convertDpToPixel(float dp, Context context) {
        Resources resources = context.getResources();
        DisplayMetrics metrics = resources.getDisplayMetrics();
        return dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
    }
This method converts dp unit to equivalent pixels, depending on device density.

@param dp      A value in dp (density independent pixels) unit. Which we need to convert into pixels
@param context Context to get resources and device specific display metrics
@return A float value to represent px equivalent to dp depending on device density
android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/util/ResUtils.java