code: public static int getDefaultSize(final int size, final int measureSpec) {
          final int result;
          final int specMode = MeasureSpec.getMode(measureSpec);
          final int specSize = MeasureSpec.getSize(measureSpec);
  
          switch (specMode) {
              case MeasureSpec.AT_MOST:
                  result = Math.min(size, specSize);
                  break;
              case MeasureSpec.EXACTLY:
                  result = specSize;
                  break;
              default:
                  result = size;
                  break;
          }
          return result;
      }
docs: Utility to return a default size. Uses the supplied size if the
  MeasureSpec imposed no constraints. Will get larger if allowed
  by the MeasureSpec.
  
  @param size        Default size for this view
  @param measureSpec Constraints imposed by the parent
  @return The size this view should be.