code: public static int pxToDp(Context context, int px) {
      DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
      return (int) ((px / displayMetrics.density) + 0.5);
    }
docs: Converts pixel in dp
  
  @param context The context
  @param px the pixel value
  @return  value in dp