示例#1
0
  public static SpannableStringBuilder generateMultiColoredString(GCSavedSet savedSet) {
    SpannableStringBuilder builder = new SpannableStringBuilder();

    String shortenedColorString = convertColorListToShortenedColorString(savedSet.getColors());

    List<String> stringParts = getParts(shortenedColorString, 3);
    int index = 0;
    for (String colorAbbrev : stringParts) {
      String colorString = colorAbbrev.substring(0, 2);
      String powerString = colorAbbrev.substring(2, 3);
      GCColor color = GCColorUtil.getColorUsingAbbrev(colorString);
      GCPowerLevel powerLevel = GCPowerLevelUtil.getPowerLevelUsingAbbrev(powerString);
      int[] rgbValues;
      if (color.getTitle().equalsIgnoreCase(GCConstants.COLOR_CUSTOM)) {
        rgbValues = convertRgbToPowerLevel(savedSet.getCustomColors().get(index), powerLevel);
      } else {
        rgbValues = convertRgbToPowerLevel(color.getRGBValues(), powerLevel);
      }

      if (colorString.equalsIgnoreCase("--")) {
        SpannableString spannableString = new SpannableString(colorString);
        spannableString.setSpan(
            new ForegroundColorSpan(Color.argb(255, 255, 255, 255)), 0, colorString.length(), 0);
        builder.append(spannableString);
      } else {
        SpannableString spannableString = new SpannableString(colorAbbrev);
        spannableString.setSpan(
            new ForegroundColorSpan(Color.argb(255, rgbValues[0], rgbValues[1], rgbValues[2])),
            0,
            3,
            0);
        spannableString.setSpan(
            new SuperscriptSpan(),
            colorAbbrev.length() - 1,
            colorAbbrev.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(
            new RelativeSizeSpan(0.75f),
            colorAbbrev.length() - 1,
            colorAbbrev.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.append(spannableString);
      }
      index++;
    }

    return builder;
  }
示例#2
0
  public static ArrayList<GCPoweredColor> convertShortenedColorStringToColorList(
      String shortenedColorString) {
    ArrayList<GCPoweredColor> colorList = new ArrayList<>();

    List<String> stringParts = getParts(shortenedColorString, 3);

    for (String colorAbbrev : stringParts) {
      try {
        String colorString = colorAbbrev.substring(0, 2);
        String powerString = colorAbbrev.substring(2, 3);
        GCColor color = GCColorUtil.getColorUsingAbbrev(colorString);
        GCPowerLevel powerLevel = GCPowerLevelUtil.getPowerLevelUsingAbbrev(powerString);
        colorList.add(new GCPoweredColor(color, powerLevel.getTitle()));
      } catch (Exception e) {
        return null;
      }
    }

    return colorList;
  }