code: private int getScaledSize(int screenSize, float density, int noPaddingSize, int maxPaddingSize) {
          int scaledSize = (int) ((float) screenSize / density);
          double scaleFactor;
          if (scaledSize <= noPaddingSize) {
              scaleFactor = 1.0;
          } else if (scaledSize >= maxPaddingSize) {
              scaleFactor = MIN_SCALE_FACTOR;
          } else {
              // between the noPadding and maxPadding widths, we take a linear reduction to go from 100%
              // of screen size down to MIN_SCALE_FACTOR
              scaleFactor = MIN_SCALE_FACTOR +
                      ((double) (maxPaddingSize - scaledSize))
                              / ((double) (maxPaddingSize - noPaddingSize))
                              * (1.0 - MIN_SCALE_FACTOR);
          }
          return (int) (screenSize * scaleFactor);
      }
docs: Returns a scaled size (either width or height) based on the parameters passed.
  @param screenSize a pixel dimension of the screen (either width or height)
  @param density density of the screen
  @param noPaddingSize the size at which there's no padding for the dialog
  @param maxPaddingSize the size at which to apply maximum padding for the dialog
  @return a scaled size.