Search in sources :

Example 51 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project c-geo by just-radovan.

the class cgCacheListAdapter method getView.

@Override
public View getView(int position, View rowView, ViewGroup parent) {
    if (inflater == null) {
        inflater = ((Activity) getContext()).getLayoutInflater();
    }
    if (position > getCount()) {
        Log.w(cgSettings.tag, "cgCacheListAdapter.getView: Attempt to access missing item #" + position);
        return null;
    }
    cgCache cache = getItem(position);
    if (rowView == null) {
        rowView = (View) inflater.inflate(R.layout.cache, null);
        holder = new cgCacheView();
        holder.oneCache = (RelativeLayout) rowView.findViewById(R.id.one_cache);
        holder.checkbox = (CheckBox) rowView.findViewById(R.id.checkbox);
        holder.oneInfo = (RelativeLayout) rowView.findViewById(R.id.one_info);
        holder.oneCheckbox = (RelativeLayout) rowView.findViewById(R.id.one_checkbox);
        holder.foundMark = (ImageView) rowView.findViewById(R.id.found_mark);
        holder.offlineMark = (ImageView) rowView.findViewById(R.id.offline_mark);
        holder.oneCache = (RelativeLayout) rowView.findViewById(R.id.one_cache);
        holder.text = (TextView) rowView.findViewById(R.id.text);
        holder.directionLayout = (RelativeLayout) rowView.findViewById(R.id.direction_layout);
        holder.distance = (cgDistanceView) rowView.findViewById(R.id.distance);
        holder.direction = (cgCompassMini) rowView.findViewById(R.id.direction);
        holder.dirImgLayout = (RelativeLayout) rowView.findViewById(R.id.dirimg_layout);
        holder.dirImg = (ImageView) rowView.findViewById(R.id.dirimg);
        holder.inventory = (RelativeLayout) rowView.findViewById(R.id.inventory);
        holder.favourite = (TextView) rowView.findViewById(R.id.favourite);
        holder.info = (TextView) rowView.findViewById(R.id.info);
        rowView.setTag(holder);
    } else {
        holder = (cgCacheView) rowView.getTag();
    }
    if (cache.own == true) {
        if (settings.skin == 1) {
            holder.oneInfo.setBackgroundResource(R.color.owncache_background_light);
            holder.oneCheckbox.setBackgroundResource(R.color.owncache_background_light);
        } else {
            holder.oneInfo.setBackgroundResource(R.color.owncache_background_dark);
            holder.oneCheckbox.setBackgroundResource(R.color.owncache_background_dark);
        }
    } else {
        if (settings.skin == 1) {
            holder.oneInfo.setBackgroundResource(R.color.background_light);
            holder.oneCheckbox.setBackgroundResource(R.color.background_light);
        } else {
            holder.oneInfo.setBackgroundResource(R.color.background_dark);
            holder.oneCheckbox.setBackgroundResource(R.color.background_dark);
        }
    }
    final touchListener touchLst = new touchListener(cache.geocode, cache.name, cache);
    rowView.setOnClickListener(touchLst);
    rowView.setOnLongClickListener(touchLst);
    rowView.setOnTouchListener(touchLst);
    rowView.setLongClickable(true);
    if (selectMode == true) {
        if (cache.statusCheckedView == true) {
            // move fast when already slided
            moveRight(holder, cache, true);
        } else {
            moveRight(holder, cache, false);
        }
    } else if (cache.statusChecked == true) {
        holder.checkbox.setChecked(true);
        if (cache.statusCheckedView == true) {
            // move fast when already slided
            moveRight(holder, cache, true);
        } else {
            moveRight(holder, cache, false);
        }
    } else {
        holder.checkbox.setChecked(false);
        if (cache.statusCheckedView == false) {
            holder.oneInfo.clearAnimation();
        } else {
            moveLeft(holder, cache, false);
        }
    }
    holder.checkbox.setOnClickListener(new checkBoxListener(cache));
    if (distances.contains(holder.distance) == false) {
        distances.add(holder.distance);
    }
    holder.distance.setContent(base, cache.latitude, cache.longitude);
    if (compasses.contains(holder.direction) == false) {
        compasses.add(holder.direction);
    }
    holder.direction.setContent(base, cache.latitude, cache.longitude);
    if (cache.logOffline == true) {
        holder.offlineMark.setVisibility(View.VISIBLE);
        holder.foundMark.setVisibility(View.GONE);
    } else if (cache.found == true) {
        holder.offlineMark.setVisibility(View.GONE);
        holder.foundMark.setVisibility(View.VISIBLE);
    } else {
        holder.offlineMark.setVisibility(View.GONE);
        holder.foundMark.setVisibility(View.GONE);
    }
    if (cache.nameSp == null) {
        cache.nameSp = (new Spannable.Factory()).newSpannable(cache.name);
        if (cache.disabled == true || cache.archived == true) {
            // strike
            cache.nameSp.setSpan(new StrikethroughSpan(), 0, cache.nameSp.toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    holder.text.setText(cache.nameSp, TextView.BufferType.SPANNABLE);
    if (gcIcons.containsKey(cache.type) == true) {
        // cache icon
        holder.text.setCompoundDrawablesWithIntrinsicBounds(gcIcons.get(cache.type), null, null, null);
    } else {
        // unknown cache type, "mystery" icon
        holder.text.setCompoundDrawablesWithIntrinsicBounds(gcIcons.get("mystery"), null, null, null);
    }
    if (holder.inventory.getChildCount() > 0) {
        holder.inventory.removeAllViews();
    }
    ImageView tbIcon = null;
    if (cache.inventoryItems > 0) {
        tbIcon = (ImageView) inflater.inflate(R.layout.trackable_icon, null);
        tbIcon.setImageResource(R.drawable.trackable_all);
        holder.inventory.addView(tbIcon);
        holder.inventory.setVisibility(View.VISIBLE);
    } else {
        holder.inventory.setVisibility(View.GONE);
    }
    boolean setDiDi = false;
    if (cache.latitude != null && cache.longitude != null) {
        holder.direction.setVisibility(View.VISIBLE);
        holder.direction.updateAzimuth(azimuth);
        if (latitude != null && longitude != null) {
            holder.distance.update(latitude, longitude);
            holder.direction.updateCoords(latitude, longitude);
        }
        setDiDi = true;
    } else {
        if (cache.distance != null) {
            holder.distance.setDistance(cache.distance);
            setDiDi = true;
        }
        if (cache.direction != null) {
            holder.direction.setVisibility(View.VISIBLE);
            holder.direction.updateAzimuth(azimuth);
            holder.direction.updateHeading(cache.direction);
            setDiDi = true;
        }
    }
    if (setDiDi == true) {
        holder.directionLayout.setVisibility(View.VISIBLE);
        holder.dirImgLayout.setVisibility(View.GONE);
    } else {
        holder.directionLayout.setVisibility(View.GONE);
        holder.distance.clear();
        Bitmap dirImgPre = null;
        Bitmap dirImg = null;
        try {
            dirImgPre = BitmapFactory.decodeFile(settings.getStorage() + cache.geocode + "/direction.png");
            dirImg = dirImgPre.copy(Bitmap.Config.ARGB_8888, true);
            dirImgPre.recycle();
            dirImgPre = null;
        } catch (Exception e) {
        // nothing
        }
        if (dirImg != null) {
            if (settings.skin == 0) {
                int length = dirImg.getWidth() * dirImg.getHeight();
                int[] pixels = new int[length];
                dirImg.getPixels(pixels, 0, dirImg.getWidth(), 0, 0, dirImg.getWidth(), dirImg.getHeight());
                for (int i = 0; i < length; i++) {
                    if (pixels[i] == 0xff000000) {
                        // replace black with white
                        pixels[i] = 0xffffffff;
                    }
                }
                dirImg.setPixels(pixels, 0, dirImg.getWidth(), 0, 0, dirImg.getWidth(), dirImg.getHeight());
            }
            holder.dirImg.setImageBitmap(dirImg);
            holder.dirImgLayout.setVisibility(View.VISIBLE);
        } else {
            holder.dirImg.setImageBitmap(null);
            holder.dirImgLayout.setVisibility(View.GONE);
        }
    }
    if (cache.favouriteCnt != null) {
        holder.favourite.setText(String.format("%d", cache.favouriteCnt));
    } else {
        holder.favourite.setText("---");
    }
    int favoriteBack;
    // set default background, neither vote nor rating may be available
    if (settings.skin == 1) {
        favoriteBack = R.drawable.favourite_background_light;
    } else {
        favoriteBack = R.drawable.favourite_background_dark;
    }
    if (cache.myVote != null && cache.myVote > 0) {
        if (cache.myVote >= 4) {
            favoriteBack = ratingBcgs[2];
        } else if (cache.myVote >= 3) {
            favoriteBack = ratingBcgs[1];
        } else if (cache.myVote > 0) {
            favoriteBack = ratingBcgs[0];
        }
    } else if (cache.rating != null && cache.rating > 0) {
        if (cache.rating >= 3.5) {
            favoriteBack = ratingBcgs[2];
        } else if (cache.rating >= 2.1) {
            favoriteBack = ratingBcgs[1];
        } else if (cache.rating > 0.0) {
            favoriteBack = ratingBcgs[0];
        }
    }
    holder.favourite.setBackgroundResource(favoriteBack);
    StringBuilder cacheInfo = new StringBuilder();
    if (historic == true && cache.visitedDate != null) {
        cacheInfo.append(cgBase.timeOut.format(cache.visitedDate));
        cacheInfo.append("; ");
        cacheInfo.append(cgBase.dateOut.format(cache.visitedDate));
    } else {
        if (cache.geocode != null && cache.geocode.length() > 0) {
            cacheInfo.append(cache.geocode);
        }
        if (cache.size != null && cache.size.length() > 0) {
            if (cacheInfo.length() > 0) {
                cacheInfo.append(" | ");
            }
            cacheInfo.append(cache.size);
        }
        if ((cache.difficulty != null && cache.difficulty > 0f) || (cache.terrain != null && cache.terrain > 0f) || (cache.rating != null && cache.rating > 0f)) {
            if (cacheInfo.length() > 0 && ((cache.difficulty != null && cache.difficulty > 0f) || (cache.terrain != null && cache.terrain > 0f))) {
                cacheInfo.append(" |");
            }
            if (cache.difficulty != null && cache.difficulty > 0f) {
                cacheInfo.append(" D:");
                cacheInfo.append(String.format(Locale.getDefault(), "%.1f", cache.difficulty));
            }
            if (cache.terrain != null && cache.terrain > 0f) {
                cacheInfo.append(" T:");
                cacheInfo.append(String.format(Locale.getDefault(), "%.1f", cache.terrain));
            }
        }
        if (cache.members == true) {
            if (cacheInfo.length() > 0) {
                cacheInfo.append(" | ");
            }
            cacheInfo.append(res.getString(R.string.cache_premium));
        }
        if (cache.reason != null && cache.reason == 1) {
            if (cacheInfo.length() > 0) {
                cacheInfo.append(" | ");
            }
            cacheInfo.append(res.getString(R.string.cache_offline));
        }
    }
    holder.info.setText(cacheInfo.toString());
    return rowView;
}
Also used : Bitmap(android.graphics.Bitmap) ImageView(android.widget.ImageView) Spannable(android.text.Spannable) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 52 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project EnableHands by LeviWGG.

the class SpanUtils method updateCharCharSequence.

private void updateCharCharSequence() {
    if (mText.length() == 0)
        return;
    int start = mBuilder.length();
    mBuilder.append(mText);
    int end = mBuilder.length();
    if (foregroundColor != COLOR_DEFAULT) {
        mBuilder.setSpan(new ForegroundColorSpan(foregroundColor), start, end, flag);
    }
    if (backgroundColor != COLOR_DEFAULT) {
        mBuilder.setSpan(new BackgroundColorSpan(backgroundColor), start, end, flag);
    }
    if (first != -1) {
        mBuilder.setSpan(new LeadingMarginSpan.Standard(first, rest), start, end, flag);
    }
    if (quoteColor != COLOR_DEFAULT) {
        mBuilder.setSpan(new CustomQuoteSpan(quoteColor, stripeWidth, quoteGapWidth), start, end, flag);
    }
    if (bulletColor != COLOR_DEFAULT) {
        mBuilder.setSpan(new CustomBulletSpan(bulletColor, bulletRadius, bulletGapWidth), start, end, flag);
    }
    // }
    if (fontSize != -1) {
        mBuilder.setSpan(new AbsoluteSizeSpan(fontSize, fontSizeIsDp), start, end, flag);
    }
    if (proportion != -1) {
        mBuilder.setSpan(new RelativeSizeSpan(proportion), start, end, flag);
    }
    if (xProportion != -1) {
        mBuilder.setSpan(new ScaleXSpan(xProportion), start, end, flag);
    }
    if (lineHeight != -1) {
        mBuilder.setSpan(new CustomLineHeightSpan(lineHeight, alignLine), start, end, flag);
    }
    if (isStrikethrough) {
        mBuilder.setSpan(new StrikethroughSpan(), start, end, flag);
    }
    if (isUnderline) {
        mBuilder.setSpan(new UnderlineSpan(), start, end, flag);
    }
    if (isSuperscript) {
        mBuilder.setSpan(new SuperscriptSpan(), start, end, flag);
    }
    if (isSubscript) {
        mBuilder.setSpan(new SubscriptSpan(), start, end, flag);
    }
    if (isBold) {
        mBuilder.setSpan(new StyleSpan(Typeface.BOLD), start, end, flag);
    }
    if (isItalic) {
        mBuilder.setSpan(new StyleSpan(Typeface.ITALIC), start, end, flag);
    }
    if (isBoldItalic) {
        mBuilder.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), start, end, flag);
    }
    if (fontFamily != null) {
        mBuilder.setSpan(new TypefaceSpan(fontFamily), start, end, flag);
    }
    if (typeface != null) {
        mBuilder.setSpan(new CustomTypefaceSpan(typeface), start, end, flag);
    }
    if (alignment != null) {
        mBuilder.setSpan(new AlignmentSpan.Standard(alignment), start, end, flag);
    }
    if (clickSpan != null) {
        mBuilder.setSpan(clickSpan, start, end, flag);
    }
    if (url != null) {
        mBuilder.setSpan(new URLSpan(url), start, end, flag);
    }
    if (blurRadius != -1) {
        mBuilder.setSpan(new MaskFilterSpan(new BlurMaskFilter(blurRadius, style)), start, end, flag);
    }
    if (shader != null) {
        mBuilder.setSpan(new ShaderSpan(shader), start, end, flag);
    }
    if (shadowRadius != -1) {
        mBuilder.setSpan(new ShadowSpan(shadowRadius, shadowDx, shadowDy, shadowColor), start, end, flag);
    }
    if (spans != null) {
        for (Object span : spans) {
            mBuilder.setSpan(span, start, end, flag);
        }
    }
}
Also used : AlignmentSpan(android.text.style.AlignmentSpan) SuperscriptSpan(android.text.style.SuperscriptSpan) ScaleXSpan(android.text.style.ScaleXSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) URLSpan(android.text.style.URLSpan) SubscriptSpan(android.text.style.SubscriptSpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) UnderlineSpan(android.text.style.UnderlineSpan) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan) MaskFilterSpan(android.text.style.MaskFilterSpan) StyleSpan(android.text.style.StyleSpan) LeadingMarginSpan(android.text.style.LeadingMarginSpan) BlurMaskFilter(android.graphics.BlurMaskFilter) BackgroundColorSpan(android.text.style.BackgroundColorSpan) StrikethroughSpan(android.text.style.StrikethroughSpan) TypefaceSpan(android.text.style.TypefaceSpan)

Example 53 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project sqlbrite by square.

the class ItemsAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = inflater.inflate(android.R.layout.simple_list_item_multiple_choice, parent, false);
    }
    TodoItem item = getItem(position);
    CheckedTextView textView = (CheckedTextView) convertView;
    textView.setChecked(item.complete());
    CharSequence description = item.description();
    if (item.complete()) {
        SpannableString spannable = new SpannableString(description);
        spannable.setSpan(new StrikethroughSpan(), 0, description.length(), 0);
        description = spannable;
    }
    textView.setText(description);
    return convertView;
}
Also used : SpannableString(android.text.SpannableString) TodoItem(com.example.sqlbrite.todo.db.TodoItem) CheckedTextView(android.widget.CheckedTextView) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 54 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project plaid by nickbutcher.

the class Bypass method recurseElement.

// The 'numberOfSiblings' parameters refers to the number of siblings within the parent, including
// the 'element' parameter, as in "How many siblings are you?" rather than "How many siblings do
// you have?".
private CharSequence recurseElement(Element element, int indexWithinParent, int numberOfSiblings, ColorStateList linksColors, int highlightColor, LoadImageCallback loadImageCallback) {
    Type type = element.getType();
    boolean isOrderedList = false;
    if (type == Type.LIST) {
        String flagsStr = element.getAttribute("flags");
        if (flagsStr != null) {
            int flags = Integer.parseInt(flagsStr);
            isOrderedList = (flags & Element.F_LIST_ORDERED) != 0;
            if (isOrderedList) {
                mOrderedListNumber.put(element, 1);
            }
        }
    }
    int size = element.size();
    CharSequence[] spans = new CharSequence[size];
    for (int i = 0; i < size; i++) {
        spans[i] = recurseElement(element.children[i], i, size, linksColors, highlightColor, loadImageCallback);
    }
    // Clean up after we're done
    if (isOrderedList) {
        mOrderedListNumber.remove(this);
    }
    CharSequence concat = TextUtils.concat(spans);
    SpannableStringBuilder builder = new ReverseSpannableStringBuilder();
    String text = element.getText();
    if (element.size() == 0 && element.getParent() != null && element.getParent().getType() != Type.BLOCK_CODE) {
        text = text.replace('\n', ' ');
    }
    switch(type) {
        case LIST:
            if (element.getParent() != null && element.getParent().getType() == Type.LIST_ITEM) {
                builder.append("\n");
            }
            break;
        case LINEBREAK:
            builder.append("\n");
            break;
        case LIST_ITEM:
            builder.append(" ");
            if (mOrderedListNumber.containsKey(element.getParent())) {
                int number = mOrderedListNumber.get(element.getParent());
                builder.append(Integer.toString(number) + ".");
                mOrderedListNumber.put(element.getParent(), number + 1);
            } else {
                builder.append(mOptions.mUnorderedListItem);
            }
            builder.append("  ");
            break;
        case AUTOLINK:
            builder.append(element.getAttribute("link"));
            break;
        case HRULE:
            // This ultimately gets drawn over by the line span, but
            // we need something here or the span isn't even drawn.
            builder.append("-");
            break;
        case IMAGE:
            if (loadImageCallback != null && !TextUtils.isEmpty(element.getAttribute("link"))) {
                // prepend a new line so that images are always on a new line
                builder.append("\n");
                // Display alt text (or title text) if there is no image
                String alt = element.getAttribute("alt");
                if (TextUtils.isEmpty(alt)) {
                    alt = element.getAttribute("title");
                }
                if (!TextUtils.isEmpty(alt)) {
                    alt = "[" + alt + "]";
                    builder.append(alt);
                } else {
                    // Character to be replaced
                    builder.append("\uFFFC");
                }
            } else {
                // Character to be replaced
                builder.append("\uFFFC");
            }
            break;
    }
    builder.append(text);
    builder.append(concat);
    // of the last child within the parent.
    if (element.getParent() != null || indexWithinParent < (numberOfSiblings - 1)) {
        if (type == Type.LIST_ITEM) {
            if (element.size() == 0 || !element.children[element.size() - 1].isBlockElement()) {
                builder.append("\n");
            }
        } else if (element.isBlockElement() && type != Type.BLOCK_QUOTE) {
            if (type == Type.LIST) {
                // If this is a nested list, don't include newlines
                if (element.getParent() == null || element.getParent().getType() != Type.LIST_ITEM) {
                    builder.append("\n");
                }
            } else if (element.getParent() != null && element.getParent().getType() == Type.LIST_ITEM) {
                // List items should never double-space their entries
                builder.append("\n");
            } else {
                builder.append("\n\n");
            }
        }
    }
    switch(type) {
        case HEADER:
            String levelStr = element.getAttribute("level");
            int level = Integer.parseInt(levelStr);
            setSpan(builder, new RelativeSizeSpan(mOptions.mHeaderSizes[level - 1]));
            setSpan(builder, new StyleSpan(Typeface.BOLD));
            break;
        case LIST:
            setBlockSpan(builder, new LeadingMarginSpan.Standard(mListItemIndent));
            break;
        case EMPHASIS:
            setSpan(builder, new StyleSpan(Typeface.ITALIC));
            break;
        case DOUBLE_EMPHASIS:
            setSpan(builder, new StyleSpan(Typeface.BOLD));
            break;
        case TRIPLE_EMPHASIS:
            setSpan(builder, new StyleSpan(Typeface.BOLD_ITALIC));
            break;
        case BLOCK_CODE:
            setSpan(builder, new LeadingMarginSpan.Standard(mCodeBlockIndent));
            setSpan(builder, new TypefaceSpan("monospace"));
            break;
        case CODE_SPAN:
            setSpan(builder, new TypefaceSpan("monospace"));
            break;
        case LINK:
        case AUTOLINK:
            String link = element.getAttribute("link");
            if (!TextUtils.isEmpty(link) && Patterns.EMAIL_ADDRESS.matcher(link).matches()) {
                link = "mailto:" + link;
            }
            setSpan(builder, new TouchableUrlSpan(link, linksColors, highlightColor));
            break;
        case BLOCK_QUOTE:
            // We add two leading margin spans so that when the order is reversed,
            // the QuoteSpan will always be in the same spot.
            setBlockSpan(builder, new LeadingMarginSpan.Standard(mBlockQuoteIndent));
            // setBlockSpan(builder, new QuoteSpan(mOptions.mBlockQuoteLineColor));
            setBlockSpan(builder, new FancyQuoteSpan(mBlockQuoteLineWidth, mBlockQuoteLineIndent, mOptions.mBlockQuoteLineColor));
            setBlockSpan(builder, new ForegroundColorSpan(mOptions.mBlockQuoteTextColor));
            setBlockSpan(builder, new LeadingMarginSpan.Standard(mBlockQuoteIndent));
            setBlockSpan(builder, new StyleSpan(Typeface.ITALIC));
            break;
        case STRIKETHROUGH:
            setSpan(builder, new StrikethroughSpan());
            break;
        case HRULE:
            setSpan(builder, new HorizontalLineSpan(mOptions.mHruleColor, mHruleSize, mHruleTopBottomPadding));
            break;
        case IMAGE:
            String url = element.getAttribute("link");
            if (loadImageCallback != null && !TextUtils.isEmpty(url)) {
                setPrependedNewlineSpan(builder, mOptions.mPreImageLinebreakHeight);
                ImageLoadingSpan loadingSpan = new ImageLoadingSpan();
                setSpanWithPrependedNewline(builder, loadingSpan);
                // make the (eventually loaded) image span clickable to open in browser
                setSpanWithPrependedNewline(builder, new TouchableUrlSpan(url, linksColors, highlightColor));
                loadImageCallback.loadImage(url, loadingSpan);
            }
            break;
    }
    return builder;
}
Also used : TouchableUrlSpan(in.uncod.android.bypass.style.TouchableUrlSpan) HorizontalLineSpan(in.uncod.android.bypass.style.HorizontalLineSpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) FancyQuoteSpan(in.uncod.android.bypass.style.FancyQuoteSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) Type(in.uncod.android.bypass.Element.Type) StyleSpan(android.text.style.StyleSpan) LeadingMarginSpan(android.text.style.LeadingMarginSpan) ImageLoadingSpan(in.uncod.android.bypass.style.ImageLoadingSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) TypefaceSpan(android.text.style.TypefaceSpan) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 55 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project BBS-Android by bdpqchen.

the class HtmlTagHandler method handleTag.

@Override
public void handleTag(final boolean opening, final String tag, Editable output, final XMLReader xmlReader) {
    if (opening) {
        // opening tag
        if (HtmlTextView.DEBUG) {
            Log.d(HtmlTextView.TAG, "opening, output: " + output.toString());
        }
        if (tag.equalsIgnoreCase(UNORDERED_LIST)) {
            lists.push(tag);
        } else if (tag.equalsIgnoreCase(ORDERED_LIST)) {
            lists.push(tag);
            olNextIndex.push(1);
        } else if (tag.equalsIgnoreCase(LIST_ITEM)) {
            if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                output.append("\n");
            }
            if (!lists.isEmpty()) {
                String parentList = lists.peek();
                if (parentList.equalsIgnoreCase(ORDERED_LIST)) {
                    start(output, new Ol());
                    olNextIndex.push(olNextIndex.pop() + 1);
                } else if (parentList.equalsIgnoreCase(UNORDERED_LIST)) {
                    start(output, new Ul());
                }
            }
        } else if (tag.equalsIgnoreCase("code")) {
            start(output, new Code());
        } else if (tag.equalsIgnoreCase("center")) {
            start(output, new Center());
        } else if (tag.equalsIgnoreCase("s") || tag.equalsIgnoreCase("strike")) {
            start(output, new Strike());
        } else if (tag.equalsIgnoreCase("table")) {
            start(output, new Table());
            if (tableTagLevel == 0) {
                tableHtmlBuilder = new StringBuilder();
                // We need some text for the table to be replaced by the span because
                // the other tags will remove their text when their text is extracted
                output.append("table placeholder");
            }
            tableTagLevel++;
        } else if (tag.equalsIgnoreCase("tr")) {
            start(output, new Tr());
        } else if (tag.equalsIgnoreCase("th")) {
            start(output, new Th());
        } else if (tag.equalsIgnoreCase("td")) {
            start(output, new Td());
        }
    } else {
        // closing tag
        if (HtmlTextView.DEBUG) {
            Log.d(HtmlTextView.TAG, "closing, output: " + output.toString());
        }
        if (tag.equalsIgnoreCase(UNORDERED_LIST)) {
            lists.pop();
        } else if (tag.equalsIgnoreCase(ORDERED_LIST)) {
            lists.pop();
            olNextIndex.pop();
        } else if (tag.equalsIgnoreCase(LIST_ITEM)) {
            if (!lists.isEmpty()) {
                if (lists.peek().equalsIgnoreCase(UNORDERED_LIST)) {
                    if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                        output.append("\n");
                    }
                    // Nested BulletSpans increases distance between bullet and text, so we must prevent it.
                    int bulletMargin = indent;
                    if (lists.size() > 1) {
                        bulletMargin = indent - bullet.getLeadingMargin(true);
                        if (lists.size() > 2) {
                            // This get's more complicated when we add a LeadingMarginSpan into the same line:
                            // we have also counter it's effect to BulletSpan
                            bulletMargin -= (lists.size() - 2) * listItemIndent;
                        }
                    }
                    BulletSpan newBullet = new BulletSpan(bulletMargin);
                    end(output, Ul.class, false, new LeadingMarginSpan.Standard(listItemIndent * (lists.size() - 1)), newBullet);
                } else if (lists.peek().equalsIgnoreCase(ORDERED_LIST)) {
                    if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                        output.append("\n");
                    }
                    int numberMargin = listItemIndent * (lists.size() - 1);
                    if (lists.size() > 2) {
                        // Same as in ordered lists: counter the effect of nested Spans
                        numberMargin -= (lists.size() - 2) * listItemIndent;
                    }
                    NumberSpan numberSpan = new NumberSpan(mTextPaint, olNextIndex.lastElement() - 1);
                    end(output, Ol.class, false, new LeadingMarginSpan.Standard(numberMargin), numberSpan);
                }
            }
        } else if (tag.equalsIgnoreCase("code")) {
            end(output, Code.class, false, new TypefaceSpan("monospace"));
        } else if (tag.equalsIgnoreCase("center")) {
            end(output, Center.class, true, new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER));
        } else if (tag.equalsIgnoreCase("s") || tag.equalsIgnoreCase("strike")) {
            end(output, Strike.class, false, new StrikethroughSpan());
        } else if (tag.equalsIgnoreCase("table")) {
            tableTagLevel--;
            // When we're back at the root-level table
            if (tableTagLevel == 0) {
                final String tableHtml = tableHtmlBuilder.toString();
                ClickableTableSpan myClickableTableSpan = null;
                if (clickableTableSpan != null) {
                    myClickableTableSpan = clickableTableSpan.newInstance();
                    myClickableTableSpan.setTableHtml(tableHtml);
                }
                DrawTableLinkSpan myDrawTableLinkSpan = null;
                if (drawTableLinkSpan != null) {
                    myDrawTableLinkSpan = drawTableLinkSpan.newInstance();
                }
                end(output, Table.class, false, myDrawTableLinkSpan, myClickableTableSpan);
            } else {
                end(output, Table.class, false);
            }
        } else if (tag.equalsIgnoreCase("tr")) {
            end(output, Tr.class, false);
        } else if (tag.equalsIgnoreCase("th")) {
            end(output, Th.class, false);
        } else if (tag.equalsIgnoreCase("td")) {
            end(output, Td.class, false);
        }
    }
    storeTableTags(opening, tag);
}
Also used : AlignmentSpan(android.text.style.AlignmentSpan) TextPaint(android.text.TextPaint) BulletSpan(android.text.style.BulletSpan) LeadingMarginSpan(android.text.style.LeadingMarginSpan) TypefaceSpan(android.text.style.TypefaceSpan) StrikethroughSpan(android.text.style.StrikethroughSpan)

Aggregations

StrikethroughSpan (android.text.style.StrikethroughSpan)59 ForegroundColorSpan (android.text.style.ForegroundColorSpan)27 StyleSpan (android.text.style.StyleSpan)27 TypefaceSpan (android.text.style.TypefaceSpan)24 BackgroundColorSpan (android.text.style.BackgroundColorSpan)23 UnderlineSpan (android.text.style.UnderlineSpan)20 RelativeSizeSpan (android.text.style.RelativeSizeSpan)19 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)16 SpannableString (android.text.SpannableString)15 SubscriptSpan (android.text.style.SubscriptSpan)15 SuperscriptSpan (android.text.style.SuperscriptSpan)15 URLSpan (android.text.style.URLSpan)14 LeadingMarginSpan (android.text.style.LeadingMarginSpan)11 CharacterStyle (android.text.style.CharacterStyle)9 ImageSpan (android.text.style.ImageSpan)9 SpannableStringBuilder (android.text.SpannableStringBuilder)8 TextPaint (android.text.TextPaint)7 QuoteSpan (android.text.style.QuoteSpan)7 Application (android.app.Application)6 AlignmentSpan (android.text.style.AlignmentSpan)6