code: public static float pixelToDip(WindowManager windowManager, int pixel) {
          DisplayMetrics metrics = new DisplayMetrics();
          windowManager.getDefaultDisplay().getMetrics(metrics);
          return metrics.scaledDensity * pixel;
      }
docs: Convert the pixels to dips, based on density scale
  @param windowManager the window manager of the display to use the scale density of.
  @param pixel to be converted value.
  @return converted value(dip).