code: public static float convertPixelToDp(Context context, float px) {
          Resources resources = context.getResources();
          DisplayMetrics metrics = resources.getDisplayMetrics();
          return px / (metrics.densityDpi / 160f);
      }
docs: This method converts device specific pixels to density independent pixels.
  
  @param px      A value in px (pixels) unit. Which we need to convert into db
  @param context Context to get resources and device specific display metrics
  @return A float value to represent dp equivalent to px value