コード例 #1
0
ファイル: IconItem.java プロジェクト: Rainer-Lang/FastAdapter
  /**
   * binds the data of this item onto the viewHolder
   *
   * @param viewHolder the viewHolder of this item
   */
  @Override
  public void bindView(ViewHolder viewHolder, List payloads) {
    super.bindView(viewHolder, payloads);

    // define our data for the view
    viewHolder.image.setIcon(mIcon);
    viewHolder.name.setText(mIcon.getName());
  }
コード例 #2
0
ファイル: Iconics.java プロジェクト: conseweb/Android-Iconics
  private static SpannableString style(
      Context ctx,
      HashMap<String, ITypeface> fonts,
      SpannableString textSpanned,
      List<CharacterStyle> styles,
      HashMap<String, List<CharacterStyle>> stylesFor) {
    if (fonts == null || fonts.size() == 0) {
      fonts = FONTS;
    }

    int startIndex = -1;
    String fontKey = "";

    // remember the position of removed chars
    ArrayList<RemoveInfo> removed = new ArrayList<RemoveInfo>();

    // StringBuilder text = new StringBuilder(textSpanned.toString());
    StringBuilder text = new StringBuilder(textSpanned);

    // find the first "{"
    while ((startIndex = text.indexOf("{", startIndex + 1)) != -1) {
      // make sure we are still within the bounds of the text
      if (text.length() < startIndex + 5) {
        startIndex = -1;
        break;
      }
      // make sure the found text is a real fontKey
      if (!text.substring(startIndex + 4, startIndex + 5).equals("-")) {
        break;
      }
      // get the fontKey
      fontKey = text.substring(startIndex + 1, startIndex + 4);
      // check if the fontKey is a registeredFont
      if (fonts.containsKey(fontKey)) {
        break;
      }
    }
    if (startIndex == -1) {
      return new SpannableString(text);
    }

    // remember total removed chars
    int removedChars = 0;

    LinkedList<StyleContainer> styleContainers = new LinkedList<StyleContainer>();
    do {
      // get the information from the iconString
      int endIndex = text.substring(startIndex).indexOf("}") + startIndex + 1;
      String iconString = text.substring(startIndex + 1, endIndex - 1);
      iconString = iconString.replaceAll("-", "_");
      try {
        // get the correct character for this Font and Icon
        IIcon icon = fonts.get(fontKey).getIcon(iconString);
        // we can only add an icon which is a font
        if (icon != null) {
          char fontChar = icon.getCharacter();
          String iconValue = String.valueOf(fontChar);

          // get just the icon identifier
          text = text.replace(startIndex, endIndex, iconValue);

          // store some info about the removed chars
          removedChars = removedChars + (endIndex - startIndex);
          removed.add(new RemoveInfo(startIndex, (endIndex - startIndex - 1), removedChars));

          // add the current icon to the container
          styleContainers.add(
              new StyleContainer(startIndex, startIndex + 1, iconString, fonts.get(fontKey)));
        }
      } catch (IllegalArgumentException e) {
        Log.w(Iconics.TAG, "Wrong icon name: " + iconString);
      }

      // reset fontKey so we can react if we are at the end but haven't found any more matches
      fontKey = null;

      // check the rest of the text for matches
      while ((startIndex = text.indexOf("{", startIndex + 1)) != -1) {
        // make sure we are still within the bounds
        if (text.length() < startIndex + 5) {
          startIndex = -1;
          break;
        }
        // check if the 5. char is a "-"
        if (text.substring(startIndex + 4, startIndex + 5).equals("-")) {
          // get the fontKey
          fontKey = text.substring(startIndex + 1, startIndex + 4);
          // check if the fontKey is registered
          if (fonts.containsKey(fontKey)) {
            break;
          }
        }
      }
    } while (startIndex != -1 && fontKey != null);

    SpannableString sb = new SpannableString(text);

    // reapply all previous styles
    for (StyleSpan span : textSpanned.getSpans(0, textSpanned.length(), StyleSpan.class)) {
      int spanStart = newSpanPoint(textSpanned.getSpanStart(span), removed);
      int spanEnd = newSpanPoint(textSpanned.getSpanEnd(span), removed);
      if (spanStart >= 0 && spanEnd > 0) {
        sb.setSpan(span, spanStart, spanEnd, textSpanned.getSpanFlags(span));
      }
    }

    // set all the icons and styles
    for (StyleContainer styleContainer : styleContainers) {
      sb.setSpan(
          new IconicsTypefaceSpan("sans-serif", styleContainer.getFont().getTypeface(ctx)),
          styleContainer.getStartIndex(),
          styleContainer.getEndIndex(),
          Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

      if (stylesFor.containsKey(styleContainer.getIcon())) {
        for (CharacterStyle style : stylesFor.get(styleContainer.getIcon())) {
          sb.setSpan(
              CharacterStyle.wrap(style),
              styleContainer.getStartIndex(),
              styleContainer.getEndIndex(),
              Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
      } else if (styles != null) {
        for (CharacterStyle style : styles) {
          sb.setSpan(
              CharacterStyle.wrap(style),
              styleContainer.getStartIndex(),
              styleContainer.getEndIndex(),
              Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
      }
    }

    // sb = applyKerning(sb, 1);

    return sb;
  }
コード例 #3
0
ファイル: Iconics.java プロジェクト: conseweb/Android-Iconics
 public static ITypeface findFont(IIcon icon) {
   return icon.getTypeface();
 }
コード例 #4
0
ファイル: Iconics.java プロジェクト: conseweb/Android-Iconics
 public IconicsBuilder styleFor(IIcon styleFor, CharacterStyle... styles) {
   return styleFor(styleFor.getName(), styles);
 }