@Override
  public PromotionBadge isMet(PromotionProcess promotionProcess, AbstractBuild<?, ?> build) {
    Badge badge = new Badge();

    Set<String> requiredPromotions = getRequiredPromotionNamesAsSet();
    if (requiredPromotions.isEmpty()) {
      return badge;
    }

    PromotedBuildAction pba = build.getAction(PromotedBuildAction.class);

    if (pba == null) {
      return null;
    }

    for (Status status : pba.getPromotions()) {
      if (status.isPromotionSuccessful()) {
        requiredPromotions.remove(status.getName());
        badge.add(status.getName());

        // short circuit for loop if
        if (requiredPromotions.isEmpty()) break;
      }
    }

    return requiredPromotions.isEmpty() ? badge : null;
  }
Пример #2
0
  private static void store(Bundle bundle, HashSet<Badge> badges) {
    int count = 0;
    String names[] = new String[badges.size()];

    for (Badge badge : badges) {
      names[count++] = badge.toString();
    }
    bundle.put(BADGES, names);
  }
  public void testValidateSimpleTypeIDException() throws Exception {
    boolean caughtException = false;

    try {
      Badge badge = new Badge();
      badge.setNumber("11");
      validator.validate(badge);
    } catch (ValidationException xmlpe) {
      caughtException = true;
    } catch (Exception ex) {
    }
    assertTrue("JAXBValidator did not throw ValidationException as expected.", caughtException);
  }
Пример #4
0
  private static HashSet<Badge> restore(Bundle bundle) {
    HashSet<Badge> badges = new HashSet<Badge>();

    String[] names = bundle.getStringArray(BADGES);
    for (int i = 0; i < names.length; i++) {
      try {
        badges.add(Badge.valueOf(names[i]));
      } catch (Exception e) {
      }
    }

    return badges;
  }
Пример #5
0
  /**
   * Draw badge
   *
   * @param canvas The canvas
   */
  private void drawBadge(Canvas canvas) {
    if (mBadgesMap != null && !mBadgesMap.isEmpty()) {
      int badgeLeft = 0, badgeRight = 0, badgeBottom, badgeWidth;
      int badgeHeight;
      float textWidth = 0, textHeight = 0;
      Rect textBounds = new Rect();

      for (int i : mBadgesMap.keySet()) {
        final View child = getChildAt(i);
        final Badge badge = mBadgesMap.get(i);
        String text = badge.getText();

        if (badge.isSmall()) {
          badgeWidth = mBadgeSmallSize;
          badgeHeight = mBadgeSmallSize;
        } else {
          badgeHeight = mBadgeHeight;
          if (text != null) {
            mBadgeTextPaint.getTextBounds(text, 0, text.length(), textBounds);
            textWidth = mBadgeTextPaint.measureText(text); // Use measureText to calculate width
            textHeight = textBounds.height(); // Use height from getTextBounds()
          } else {
            textWidth = 0;
            textHeight = 0;
          }

          if (textWidth > 0) {
            if (textWidth > (mBadgeMaxWidth - mBadgePaddingLeftRight * 2)) {
              textWidth = mBadgeMaxWidth - mBadgePaddingLeftRight * 2;
              text =
                  TextUtils.ellipsize(text, mBadgeTextPaint, textWidth, TextUtils.TruncateAt.END)
                      .toString();
              badgeWidth = mBadgeMaxWidth;
            } else {
              badgeWidth =
                  Math.max(Math.round((mBadgePaddingLeftRight * 2) + textWidth), mBadgeMinWidth);
            }
          } else {
            badgeWidth = mBadgeMinWidth;
          }
        }

        badgeBottom = mBadgeMarginTop + badgeHeight;

        switch (mBadgeGravity) {
          case LEFT:
            {
              badgeLeft = child.getLeft() + mBadgeMarginLeft;
              badgeRight = badgeLeft + badgeWidth;
              break;
            }
          case CENTER_LEFT:
            {
              final int center = child.getRight() - child.getMeasuredWidth() / 2;
              badgeRight = center - mBadgeMarginRight;
              badgeLeft = badgeRight - badgeWidth;
              break;
            }
          case CENTER_RIGHT:
            {
              final int center = child.getRight() - child.getMeasuredWidth() / 2;
              badgeLeft = center + mBadgeMarginLeft;
              badgeRight = badgeLeft + badgeWidth;
              break;
            }
          case RIGHT:
            {
              badgeRight = child.getRight() - mBadgeMarginRight;
              badgeLeft = badgeRight - badgeWidth;
              break;
            }
        }

        mBadgeBackground.setBounds(badgeLeft, mBadgeMarginTop, badgeRight, badgeBottom);
        mBadgeBackground.draw(canvas);

        if (text != null && textWidth > 0) {
          canvas.drawText(
              text,
              mBadgeBackground.getBounds().centerX() - (textWidth / 2f),
              mBadgeBackground.getBounds().centerY() + (textHeight / 2f),
              mBadgeTextPaint);
        }
      }
    }
  }