Exemplo n.º 1
0
 private String formatWeight(Weight weight, int significance) {
   String string = "";
   switch (mSettings.getUnits()) {
     case IMPERIAL:
       string = Util.formatImperialWeight(weight, significance);
       break;
     case METRIC:
       string = Util.formatMetricWeight(weight, significance);
       break;
   }
   return string;
 }
Exemplo n.º 2
0
  private void addRecipeInfo(Document document) throws DocumentException {
    int iconRes = mRecipe.getStyle().getIconDrawable();
    Image image = loadDrawable(iconRes, 40);

    Paragraph namePara = new Paragraph();
    namePara.setSpacingBefore(0);
    namePara.add(new Phrase(mRecipe.getName() + "\n", HEADER_FONT));
    namePara.add(new Phrase("\n", new Font(Font.FontFamily.TIMES_ROMAN, 2)));
    namePara.add(new Phrase(mRecipe.getStyle().getDisplayName(), SMALL_FONT));

    PdfPTable table = new PdfPTable(new float[] {50, 400});
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    PdfPCell cellOne = new PdfPCell(image);
    cellOne.setBorder(Rectangle.NO_BORDER);
    PdfPCell cellTwo = new PdfPCell(namePara);
    cellTwo.setBorder(Rectangle.NO_BORDER);

    table.addCell(cellOne);
    table.addCell(cellTwo);
    document.add(table);

    addLineSeparator(document);

    Paragraph setupPara = new Paragraph();
    setupPara.add(
        new Phrase(
            "Batch Volume: " + mConverter.fromGallonsWithUnits(mRecipe.getBatchVolume(), 1),
            NORMAL_FONT));
    setupPara.add(new Phrase("\n\n", SPACING_FONT));
    setupPara.add(
        new Phrase(
            "Boil Volume: " + mConverter.fromGallonsWithUnits(mRecipe.getBoilVolume(), 1),
            NORMAL_FONT));
    setupPara.add(new Phrase("\n\n", SPACING_FONT));
    setupPara.add(
        new Phrase(
            "Boil Time: " + Util.fromDouble(mRecipe.getBoilTime(), 0) + " minutes", NORMAL_FONT));
    setupPara.add(new Phrase("\n\n", SPACING_FONT));
    setupPara.add(
        new Phrase(
            "Efficiency: " + Util.fromDouble(mRecipe.getEfficiency(), 1) + "%", NORMAL_FONT));

    Paragraph para = new Paragraph();
    String og = "";
    switch (mSettings.getExtractUnits()) {
      case SPECIFIC_GRAVITY:
        og = Util.fromDouble(mRecipe.getOg(), 3, false);
        break;
      case DEGREES_PLATO:
        og = Util.fromDouble(mRecipe.getOgPlato(), 1, false) + "°P";
        break;
    }
    para.add(new Phrase("OG: " + og, NORMAL_FONT));
    para.add(new Phrase("\n\n", SPACING_FONT));

    para.add(new Phrase("IBU: " + Util.fromDouble(mRecipe.getTotalIbu(), 1), NORMAL_FONT));
    para.add(new Phrase("\n\n", SPACING_FONT));
    para.add(new Phrase("SRM: " + Util.fromDouble(mRecipe.getSrm(), 1), NORMAL_FONT));
    para.add(new Phrase("\n\n", SPACING_FONT));

    String fg = "n/a";
    if (mRecipe.hasYeast()) {
      switch (mSettings.getExtractUnits()) {
        case SPECIFIC_GRAVITY:
          fg = Util.fromDouble(mRecipe.getFg(), 3, false);
          break;
        case DEGREES_PLATO:
          fg = Util.fromDouble(mRecipe.getFgPlato(), 1, false) + "°P";
          break;
      }
    }
    para.add(new Phrase("Estimated FG: " + fg, NORMAL_FONT));
    para.add(new Phrase("\n\n", SPACING_FONT));

    String abv = "n/a";
    if (mRecipe.hasYeast()) {
      abv = Util.fromDouble(mRecipe.getAbv(), 1) + "%";
    }
    para.add(new Phrase("Estimated ABV: " + abv, NORMAL_FONT));

    PdfPTable statsTable = new PdfPTable(new float[] {200, 200});
    statsTable.setHorizontalAlignment(Element.ALIGN_LEFT);
    PdfPCell statsCellOne = new PdfPCell(para);
    statsCellOne.setBorder(Rectangle.NO_BORDER);
    PdfPCell statsCellTwo = new PdfPCell(setupPara);
    statsCellTwo.setBorder(Rectangle.NO_BORDER);

    statsTable.addCell(statsCellOne);
    statsTable.addCell(statsCellTwo);
    document.add(statsTable);
  }