Java Code Examples for android.graphics.Typeface#ITALIC

The following examples show how to use android.graphics.Typeface#ITALIC . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomTypefaceSpan.java    From speech-android-sdk with Apache License 2.0 6 votes vote down vote up
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 2
Source File: Stylish.java    From Stylish-Widget-for-Android with Apache License 2.0 6 votes vote down vote up
public void setTextStyle(TextView textView, int style) {
        String font;
        switch (style) {
            case Typeface.BOLD:
                font = Stylish.FONT_BOLD;
                break;
            case Typeface.ITALIC:
                font = Stylish.FONT_ITALIC;
                break;
            case Typeface.NORMAL:
                font = Stylish.FONT_REGULAR;
                break;
            case Typeface.BOLD_ITALIC:
                font = Stylish.FONT_BOLD_ITALIC;
                break;
            default:
                font = Stylish.FONT_REGULAR;
        }

        try {

            textView.setTypeface(Stylish.getInstance().getTypeface(textView.getContext(), font, style));
        } catch (Exception e) {
//            e.printStackTrace();
        }
    }
 
Example 3
Source File: RobotoLightTypefaceSpan.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 4
Source File: SVGAndroidRenderer.java    From microMathematics with GNU General Public License v3.0 6 votes vote down vote up
private Typeface  checkGenericFont(String fontName, Integer fontWeight, FontStyle fontStyle)
{
   Typeface font = null;
   int      typefaceStyle;

   boolean  italic = (fontStyle == Style.FontStyle.Italic);
   typefaceStyle = (fontWeight > 500) ? (italic ? Typeface.BOLD_ITALIC : Typeface.BOLD)
                                      : (italic ? Typeface.ITALIC : Typeface.NORMAL);

   switch (fontName) {
      case "serif":
         font = Typeface.create(Typeface.SERIF, typefaceStyle); break;
      case "sans-serif":
         font = Typeface.create(Typeface.SANS_SERIF, typefaceStyle); break;
      case "monospace":
         font = Typeface.create(Typeface.MONOSPACE, typefaceStyle); break;
      case "cursive":
         font = Typeface.create(Typeface.SANS_SERIF, typefaceStyle); break;
      case "fantasy":
         font = Typeface.create(Typeface.SANS_SERIF, typefaceStyle); break;
   }
   return font;
}
 
Example 5
Source File: IconicsTypefaceSpan.java    From clear-todolist with GNU General Public License v3.0 6 votes vote down vote up
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 6
Source File: ParseHelper.java    From proteus with Apache License 2.0 6 votes vote down vote up
public static int parseTextStyle(String attributeValue) {
  int typeface = Typeface.NORMAL;
  if (attributeValue != null) {
    attributeValue = attributeValue.toLowerCase();
    switch (attributeValue) {
      case BOLD:
        typeface = Typeface.BOLD;
        break;
      case ITALIC:
        typeface = Typeface.ITALIC;
        break;
      case BOLD_ITALIC:
        typeface = Typeface.BOLD_ITALIC;
        break;
      default:
        typeface = Typeface.NORMAL;
        break;
    }
  }
  return typeface;
}
 
Example 7
Source File: CustomTypefaceSpan.java    From oneHookLibraryAndroid with Apache License 2.0 6 votes vote down vote up
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 8
Source File: ReactAztecManager.java    From react-native-aztec with GNU General Public License v2.0 6 votes vote down vote up
/**
 /* This code was taken from the method setFontStyle of the class ReactTextShadowNode
 /* TODO: Factor into a common place they can both use
 */
@ReactProp(name = ViewProps.FONT_STYLE)
public void setFontStyle(ReactAztecText view, @Nullable String fontStyleString) {
    int fontStyle = UNSET;
    if ("italic".equals(fontStyleString)) {
        fontStyle = Typeface.ITALIC;
    } else if ("normal".equals(fontStyleString)) {
        fontStyle = Typeface.NORMAL;
    }

    Typeface currentTypeface = view.getTypeface();
    if (currentTypeface == null) {
        currentTypeface = Typeface.DEFAULT;
    }
    if (fontStyle != currentTypeface.getStyle()) {
        view.setTypeface(currentTypeface, fontStyle);
    }
}
 
Example 9
Source File: BaseRichEditText.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param style Typeface of StyleSpan.
 * */
public void applyStyleSpan(int style){
    int selStart=getSelectionStart();
    int selEnd=getSelectionEnd();
    if(selEnd-selStart>0){
        StyleSpan[] ss = getEditableText().getSpans(selStart, selEnd, StyleSpan.class);
        for (StyleSpan span:ss) {
            if(span.getStyle()==style) {
                removeSpan(span, selStart, selEnd);
            }
        }
        if (style==Typeface.BOLD) {
            //toggleBold();
            if(isBold){
                setSpan(new StyleSpan(style),selStart,selEnd,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } else if (style==Typeface.ITALIC) {
            //toggleItalic();
            if(isItalic){
                setSpan(new StyleSpan(style),selStart,selEnd,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    //}else if(selEnd==selStart){
    //    if (style==Typeface.BOLD) {
    //        toggleBold();
    //    } else if (style==Typeface.ITALIC) {
    //        toggleItalic();
    //    }
    }
}
 
Example 10
Source File: KnifeText.java    From Knife with Apache License 2.0 5 votes vote down vote up
protected boolean containStyle(int style, int start, int end) {
    switch (style) {
        case Typeface.NORMAL:
        case Typeface.BOLD:
        case Typeface.ITALIC:
        case Typeface.BOLD_ITALIC:
            break;
        default:
            return false;
    }

    if (start > end) {
        return false;
    }

    if (start == end) {
        if (start - 1 < 0 || start + 1 > getEditableText().length()) {
            return false;
        } else {
            StyleSpan[] before = getEditableText().getSpans(start - 1, start, StyleSpan.class);
            StyleSpan[] after = getEditableText().getSpans(start, start + 1, StyleSpan.class);
            return before.length > 0 && after.length > 0 && before[0].getStyle() == style && after[0].getStyle() == style;
        }
    } else {
        StringBuilder builder = new StringBuilder();

        // Make sure no duplicate characters be added
        for (int i = start; i < end; i++) {
            StyleSpan[] spans = getEditableText().getSpans(i, i + 1, StyleSpan.class);
            for (StyleSpan span : spans) {
                if (span.getStyle() == style) {
                    builder.append(getEditableText().subSequence(i, i + 1).toString());
                    break;
                }
            }
        }

        return getEditableText().subSequence(start, end).toString().equals(builder.toString());
    }
}
 
Example 11
Source File: CustomTypefaceSpan.java    From custom-typeface with Apache License 2.0 5 votes vote down vote up
private void apply(Paint paint) {
    Typeface oldTypeface = paint.getTypeface();
    int oldStyle = oldTypeface != null ? oldTypeface.getStyle() : 0;
    int fakeStyle = oldStyle &~ mTypeface.getStyle();

    if ((fakeStyle & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fakeStyle & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(mTypeface);
}
 
Example 12
Source File: StyleSpan.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
private static void apply(Paint paint, int style) {
    int oldStyle;

    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int want = oldStyle | style;

    Typeface tf;
    if (old == null) {
        tf = Typeface.defaultFromStyle(want);
    } else {
        tf = Typeface.create(old, want);
    }

    int fake = want & ~tf.getStyle();

    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 13
Source File: TextAppearanceSpan.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateMeasureState(TextPaint ds) {
    if (mTypeface != null || mStyle != 0) {
        Typeface tf = ds.getTypeface();
        int style = 0;

        if (tf != null) {
            style = tf.getStyle();
        }

        style |= mStyle;

        if (mTypeface != null) {
            tf = Typeface.create(mTypeface, style);
        } else if (tf == null) {
            tf = Typeface.defaultFromStyle(style);
        } else {
            tf = Typeface.create(tf, style);
        }

        int fake = style & ~tf.getStyle();

        if ((fake & Typeface.BOLD) != 0) {
            ds.setFakeBoldText(true);
        }

        if ((fake & Typeface.ITALIC) != 0) {
            ds.setTextSkewX(-0.25f);
        }

        ds.setTypeface(tf);
    }

    if (mTextSize > 0) {
        ds.setTextSize(mTextSize);
    }
}
 
Example 14
Source File: CssConversion.java    From HtmlView2 with Apache License 2.0 5 votes vote down vote up
static int getTextStyle(CssStyleDeclaration style) {
  int flags = 0;
  if (style.get(CssProperty.FONT_WEIGHT, CssUnit.NUMBER) > 600) {
    flags |= Typeface.BOLD;
  }
  if (style.getEnum(CssProperty.FONT_STYLE) == CssEnum.ITALIC) {
    flags |= Typeface.ITALIC;
  }
  return flags;
}
 
Example 15
Source File: TypefaceLoader.java    From react-native-navigation with MIT License 5 votes vote down vote up
private int getStyle(String fontFamilyName) {
	int style = Typeface.NORMAL;
	if (fontFamilyName.toLowerCase().contains("bold")) {
		style = Typeface.BOLD;
	} else if (fontFamilyName.toLowerCase().contains("italic")) {
		style = Typeface.ITALIC;
	}
	return style;
}
 
Example 16
Source File: WhatsappViewCompat.java    From WhatsappFormatter with Apache License 2.0 4 votes vote down vote up
/**
 * Performs formatting on the given text.
 *
 * @param text - input sequence.
 * @return formatted sequence.
 */
public static CharSequence extractFlagsForEditText(CharSequence text) {

    char[] textChars = text.toString().toCharArray();
    ArrayList<Character> characters = new ArrayList<>();
    ArrayList<WhatsappUtil.Flag> flags = new ArrayList<>();

    WhatsappUtil.Flag boldFlag = new WhatsappUtil.Flag(INVALID_INDEX, INVALID_INDEX, BOLD_FLAG);
    WhatsappUtil.Flag strikeFlag = new WhatsappUtil.Flag(INVALID_INDEX, INVALID_INDEX, STRIKE_FLAG);
    WhatsappUtil.Flag italicFlag = new WhatsappUtil.Flag(INVALID_INDEX, INVALID_INDEX, ITALIC_FLAG);


    for (int i = 0, j = 0; i < textChars.length; i++) {
        char c = textChars[i];

        if (c == BOLD_FLAG) {
            if (boldFlag.start == INVALID_INDEX) {
                if (WhatsappUtil.hasFlagSameLine(text, BOLD_FLAG, i + 1)) {
                    boldFlag.start = j + 1;
                }
            } else {
                boldFlag.end = j;
                flags.add(boldFlag);
                boldFlag = new WhatsappUtil.Flag(INVALID_INDEX, INVALID_INDEX, BOLD_FLAG);
            }
        } else if (c == STRIKE_FLAG) {
            if (strikeFlag.start == INVALID_INDEX) {
                if (WhatsappUtil.hasFlagSameLine(text, STRIKE_FLAG, i + 1)) {
                    strikeFlag.start = j + 1;
                }
            } else {
                strikeFlag.end = j;
                flags.add(strikeFlag);
                strikeFlag = new WhatsappUtil.Flag(INVALID_INDEX, INVALID_INDEX, STRIKE_FLAG);
            }
        } else if (c == ITALIC_FLAG) {
            if (italicFlag.start == INVALID_INDEX) {
                if (WhatsappUtil.hasFlagSameLine(text, ITALIC_FLAG, i + 1)) {
                    italicFlag.start = j + 1;
                }
            } else {
                italicFlag.end = j;
                flags.add(italicFlag);
                italicFlag = new WhatsappUtil.Flag(INVALID_INDEX, INVALID_INDEX, ITALIC_FLAG);
            }
        }
        characters.add(c);
        j++;
    }

    String formatted = WhatsappUtil.getText(characters);
    SpannableStringBuilder builder = new SpannableStringBuilder(formatted);


    for (int i = 0; i < flags.size(); i++) {

        WhatsappUtil.Flag flag = flags.get(i);
        if (flag.flag == BOLD_FLAG) {
            StyleSpan bss = new StyleSpan(Typeface.BOLD);
            builder.setSpan(bss, flag.start, flag.end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            builder.setSpan(new ForegroundColorSpan(Color.GRAY), flag.start-1, flag.start, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            builder.setSpan(new ForegroundColorSpan(Color.GRAY), flag.end, flag.end+1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

        } else if (flag.flag == STRIKE_FLAG) {
            builder.setSpan(new StrikethroughSpan(), flag.start, flag.end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            builder.setSpan(new ForegroundColorSpan(Color.GRAY), flag.start-1, flag.start, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            builder.setSpan(new ForegroundColorSpan(Color.GRAY), flag.end, flag.end+1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

        } else if (flag.flag == ITALIC_FLAG) {
            StyleSpan iss = new StyleSpan(Typeface.ITALIC);
            builder.setSpan(iss, flag.start, flag.end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            builder.setSpan(new ForegroundColorSpan(Color.GRAY), flag.start-1, flag.start, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            builder.setSpan(new ForegroundColorSpan(Color.GRAY), flag.end, flag.end+1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

        }

    }

    return builder;
}
 
Example 17
Source File: Rows.java    From SMP with GNU General Public License v3.0 4 votes vote down vote up
private void initByArtist(Cursor musicCursor) {
    RowGroup.rowType = Filter.ARTIST;
    if (musicCursor != null && musicCursor.moveToFirst()) {
        int titleCol = musicCursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
        int idCol = musicCursor.getColumnIndex(MediaStore.Audio.Media._ID);
        int artistCol = musicCursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
        int albumCol = musicCursor.getColumnIndex(MediaStore.Audio.Media.ALBUM);
        int durationCol = musicCursor.getColumnIndex(MediaStore.Audio.Media.DURATION);
        int trackCol = musicCursor.getColumnIndex(MediaStore.Audio.Media.TRACK);
        int albumIdCol = musicCursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID);
        int yearCol = musicCursor.getColumnIndex(MediaStore.Audio.Media.YEAR);

        int RowGroupArtistBackground = 0;
        int RowGroupArtistAlbumBackground = 0;
        if (resources != null) {
            RowGroupArtistBackground = resources.getColor(R.color.RowGroupArtistBackground);
            RowGroupArtistAlbumBackground = resources.getColor(R.color.RowGroupArtistAlbumBackground);
        }

        RowGroup prevArtistGroup = null;
        RowGroup prevAlbumGroup = null;
        do {
            long id = musicCursor.getLong(idCol);
            String title = getDefaultStrIfNull(musicCursor.getString(titleCol));
            String artist = getDefaultStrIfNull(musicCursor.getString(artistCol));
            String album = getDefaultStrIfNull(musicCursor.getString(albumCol));
            int duration = musicCursor.getInt(durationCol);
            int track = musicCursor.getInt(trackCol);
            long albumId = musicCursor.getLong(albumIdCol);
            int year = musicCursor.getInt(yearCol);

            if (prevArtistGroup == null || artist.compareToIgnoreCase(prevArtistGroup.getName()) != 0) {
                RowGroup artistGroup = new RowGroup(rowsUnfolded.size(), 0, artist,
                        Typeface.BOLD, RowGroupArtistBackground);
                rowsUnfolded.add(artistGroup);
                prevArtistGroup = artistGroup;
                prevAlbumGroup = null;
            }

            if (prevAlbumGroup == null || album.compareToIgnoreCase(prevAlbumGroup.getName()) != 0) {
                RowGroup albumGroup = new RowGroup(rowsUnfolded.size(), 1, album,
                        Typeface.ITALIC, RowGroupArtistAlbumBackground);
                albumGroup.setParent(prevArtistGroup);
                rowsUnfolded.add(albumGroup);
                prevAlbumGroup = albumGroup;
            }

            RowSong rowSong = new RowSong(rowsUnfolded.size(), 2, id, title, artist, album,
                    duration / 1000, track, null, albumId, year);
            rowSong.setParent(prevAlbumGroup);

            if(id == savedID)
                currPos = rowsUnfolded.size();

            rowsUnfolded.add(rowSong);
            prevArtistGroup.incNbRowSong();
            prevAlbumGroup.incNbRowSong();
        }
        while (musicCursor.moveToNext());
        setGroupSelectedState(currPos, true);
    }
}
 
Example 18
Source File: WhatsappViewCompat.java    From WhatsappFormatter with Apache License 2.0 4 votes vote down vote up
/**
 * Performs formatting on the given text.
 *
 * @param text - input sequence.
 * @return formatted sequence.
 */
public static CharSequence extractFlagsForTextView(CharSequence text) {

    char[] textChars = text.toString().toCharArray();
    ArrayList<Character> characters = new ArrayList<>();
    ArrayList<WhatsappUtil.Flag> flags = new ArrayList<>();

    WhatsappUtil.Flag boldFlag = new WhatsappUtil.Flag(INVALID_INDEX, INVALID_INDEX, BOLD_FLAG);
    WhatsappUtil.Flag strikeFlag = new WhatsappUtil.Flag(INVALID_INDEX, INVALID_INDEX, STRIKE_FLAG);
    WhatsappUtil.Flag italicFlag = new WhatsappUtil.Flag(INVALID_INDEX, INVALID_INDEX, ITALIC_FLAG);


    for (int i = 0, j = 0; i < textChars.length; i++) {
        char c = textChars[i];

        if (c == BOLD_FLAG) {
            if (boldFlag.start == INVALID_INDEX) {
                if (WhatsappUtil.hasFlagSameLine(text, BOLD_FLAG, i + 1)) {
                    boldFlag.start = j;
                    continue;
                }
            } else {
                boldFlag.end = j;
                flags.add(boldFlag);
                boldFlag = new WhatsappUtil.Flag(INVALID_INDEX, INVALID_INDEX, BOLD_FLAG);
                continue;
            }
        }
        if (c == STRIKE_FLAG) {
            if (strikeFlag.start == INVALID_INDEX) {
                if (WhatsappUtil.hasFlagSameLine(text, STRIKE_FLAG, i + 1)) {
                    strikeFlag.start = j;
                    continue;
                }
            } else {
                strikeFlag.end = j;
                flags.add(strikeFlag);
                strikeFlag = new WhatsappUtil.Flag(INVALID_INDEX, INVALID_INDEX, STRIKE_FLAG);
                continue;
            }
        }
        if (c == ITALIC_FLAG) {
            if (italicFlag.start == INVALID_INDEX) {
                if (WhatsappUtil.hasFlagSameLine(text, ITALIC_FLAG, i + 1)) {
                    italicFlag.start = j;
                    continue;
                }
            } else {
                italicFlag.end = j;
                flags.add(italicFlag);
                italicFlag = new WhatsappUtil.Flag(INVALID_INDEX, INVALID_INDEX, ITALIC_FLAG);
                continue;
            }
        }
        characters.add(c);
        j++;
    }

    String formatted = WhatsappUtil.getText(characters);
    SpannableStringBuilder builder = new SpannableStringBuilder(formatted);


    for (int i = 0; i < flags.size(); i++) {

        WhatsappUtil.Flag flag = flags.get(i);

        if (flag.flag == BOLD_FLAG) {
            StyleSpan bss = new StyleSpan(Typeface.BOLD);
            builder.setSpan(bss, flag.start, flag.end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        } else if (flag.flag == STRIKE_FLAG) {
            builder.setSpan(new StrikethroughSpan(), flag.start, flag.end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        } else if (flag.flag == ITALIC_FLAG) {
            StyleSpan iss = new StyleSpan(Typeface.ITALIC);
            builder.setSpan(iss, flag.start, flag.end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        }
    }

    return builder;
}
 
Example 19
Source File: SpanFormatter.java    From tindroid with Apache License 2.0 4 votes vote down vote up
@Override
public TreeNode apply(final String tp, final Map<String,Object> data, final Object content) {
    if (tp != null) {
        TreeNode span = null;
        switch (tp) {
            case "ST":
                span = new TreeNode(new StyleSpan(Typeface.BOLD), content);
                break;
            case "EM":
                span = new TreeNode(new StyleSpan(Typeface.ITALIC), content);
                break;
            case "DL":
                span = new TreeNode(new StrikethroughSpan(), content);
                break;
            case "CO":
                span = new TreeNode(new TypefaceSpan("monospace"), content);
                break;
            case "BR":
                span = new TreeNode("\n");
                break;
            case "LN":
                try {
                    // We don't need to specify an URL for URLSpan
                    // as it's not going to be used.
                    span = new TreeNode(new URLSpan("") {
                        @Override
                        public void onClick(View widget) {
                            if (mClicker != null) {
                                mClicker.onClick("LN", data);
                            }
                        }
                    }, content);
                } catch (ClassCastException | NullPointerException ignored) {}
                break;
            case "MN":
            case "HT":
                break;
            case "HD":
                // Hidden text
                break;
            case "IM":
                // Additional processing for images
                span = handleImage(mContainer.getContext(), content, data);
                break;
            case "EX":
                // Attachments
                span = handleAttachment(mContainer.getContext(), content, data);
                break;
            case "BN":
                // Button
                span = handleButton(data, content);
                break;
            case "FM":
                // Form
                if (content instanceof List) {
                    // Add line breaks between form elements.
                    try {
                        @SuppressWarnings("unchecked")
                        List<TreeNode> children = (List<TreeNode>) content;
                        if (children.size() > 0) {
                            span = new TreeNode();
                            for (TreeNode child : children) {
                                span.addNode(child);
                                span.addNode("\n");
                            }
                        }
                    } catch (ClassCastException ex) {
                        Log.w(TAG, "Wrong type of content in Drafty", ex);
                    }

                    if (span != null && span.isEmpty()) {
                        span = null;
                    } else {
                        mContainer.setLineSpacing(0, FORM_LINE_SPACING);
                    }
                }
                break;
            case "RW":
                // Form element formatting is dependent on element content.
                span = new TreeNode(content);
                break;
        }
        return span;
    }
    return new TreeNode(content);
}
 
Example 20
Source File: BidiInfoActivity.java    From Tehreer-Android with Apache License 2.0 4 votes vote down vote up
private Object[] spansInlineHeading() {
    return new Object[] {
        new StyleSpan(Typeface.ITALIC),
        new UnderlineSpan()
    };
}