Search in sources :

Example 46 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project ExoPlayer by google.

the class SpannedToHtmlConverter method getOpeningTag.

@Nullable
private static String getOpeningTag(Object span, float displayDensity) {
    if (span instanceof StrikethroughSpan) {
        return "<span style='text-decoration:line-through;'>";
    } else if (span instanceof ForegroundColorSpan) {
        ForegroundColorSpan colorSpan = (ForegroundColorSpan) span;
        return Util.formatInvariant("<span style='color:%s;'>", HtmlUtils.toCssRgba(colorSpan.getForegroundColor()));
    } else if (span instanceof BackgroundColorSpan) {
        BackgroundColorSpan colorSpan = (BackgroundColorSpan) span;
        return Util.formatInvariant("<span class='bg_%s'>", colorSpan.getBackgroundColor());
    } else if (span instanceof HorizontalTextInVerticalContextSpan) {
        return "<span style='text-combine-upright:all;'>";
    } else if (span instanceof AbsoluteSizeSpan) {
        AbsoluteSizeSpan absoluteSizeSpan = (AbsoluteSizeSpan) span;
        float sizeCssPx = absoluteSizeSpan.getDip() ? absoluteSizeSpan.getSize() : absoluteSizeSpan.getSize() / displayDensity;
        return Util.formatInvariant("<span style='font-size:%.2fpx;'>", sizeCssPx);
    } else if (span instanceof RelativeSizeSpan) {
        return Util.formatInvariant("<span style='font-size:%.2f%%;'>", ((RelativeSizeSpan) span).getSizeChange() * 100);
    } else if (span instanceof TypefaceSpan) {
        @Nullable String fontFamily = ((TypefaceSpan) span).getFamily();
        return fontFamily != null ? Util.formatInvariant("<span style='font-family:\"%s\";'>", fontFamily) : null;
    } else if (span instanceof StyleSpan) {
        switch(((StyleSpan) span).getStyle()) {
            case Typeface.BOLD:
                return "<b>";
            case Typeface.ITALIC:
                return "<i>";
            case Typeface.BOLD_ITALIC:
                return "<b><i>";
            default:
                return null;
        }
    } else if (span instanceof RubySpan) {
        RubySpan rubySpan = (RubySpan) span;
        switch(rubySpan.position) {
            case TextAnnotation.POSITION_BEFORE:
                return "<ruby style='ruby-position:over;'>";
            case TextAnnotation.POSITION_AFTER:
                return "<ruby style='ruby-position:under;'>";
            case TextAnnotation.POSITION_UNKNOWN:
                return "<ruby style='ruby-position:unset;'>";
            default:
                return null;
        }
    } else if (span instanceof UnderlineSpan) {
        return "<u>";
    } else if (span instanceof TextEmphasisSpan) {
        TextEmphasisSpan textEmphasisSpan = (TextEmphasisSpan) span;
        String style = getTextEmphasisStyle(textEmphasisSpan.markShape, textEmphasisSpan.markFill);
        String position = getTextEmphasisPosition(textEmphasisSpan.position);
        return Util.formatInvariant("<span style='-webkit-text-emphasis-style:%1$s;text-emphasis-style:%1$s;" + "-webkit-text-emphasis-position:%2$s;text-emphasis-position:%2$s;" + "display:inline-block;'>", style, position);
    } else {
        return null;
    }
}
Also used : RubySpan(com.google.android.exoplayer2.text.span.RubySpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TextEmphasisSpan(com.google.android.exoplayer2.text.span.TextEmphasisSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) UnderlineSpan(android.text.style.UnderlineSpan) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan) HorizontalTextInVerticalContextSpan(com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan) StyleSpan(android.text.style.StyleSpan) BackgroundColorSpan(android.text.style.BackgroundColorSpan) Nullable(androidx.annotation.Nullable) StrikethroughSpan(android.text.style.StrikethroughSpan) TypefaceSpan(android.text.style.TypefaceSpan) Nullable(androidx.annotation.Nullable)

Example 47 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project ExoPlayer by google.

the class SpannedToHtmlConverterTest method convert_supportsStrikethroughSpan.

@Test
public void convert_supportsStrikethroughSpan() {
    SpannableString spanned = new SpannableString("String with crossed-out section");
    spanned.setSpan(new StrikethroughSpan(), "String with ".length(), "String with crossed-out".length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    SpannedToHtmlConverter.HtmlAndCss htmlAndCss = SpannedToHtmlConverter.convert(spanned, displayDensity);
    assertThat(htmlAndCss.cssRuleSets).isEmpty();
    assertThat(htmlAndCss.html).isEqualTo("String with <span style='text-decoration:line-through;'>crossed-out</span> section");
}
Also used : SpannableString(android.text.SpannableString) StrikethroughSpan(android.text.style.StrikethroughSpan) Test(org.junit.Test)

Example 48 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project Reader by TheKeeperOfPie.

the class TagHandlerReddit method handleTag.

@Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
    if (tag.equalsIgnoreCase("del") || tag.equalsIgnoreCase("strike") || tag.equals("s")) {
        if (opening) {
            start(output, new Strike());
        } else {
            end(output, Strike.class, new StrikethroughSpan());
        }
    } else if (tag.equalsIgnoreCase("ul")) {
        if (opening) {
            lists.push(tag);
        } else {
            lists.pop();
        }
    } else if (tag.equalsIgnoreCase("ol")) {
        if (opening) {
            lists.push(tag);
            olNextIndex.push(1);
        } else {
            lists.pop();
            olNextIndex.pop();
        }
    } else if (tag.equalsIgnoreCase("li")) {
        if (opening) {
            if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                output.append("\n");
            }
            String parentList = lists.peek();
            if (parentList.equalsIgnoreCase("ol")) {
                start(output, new Ol());
                output.append(String.valueOf(olNextIndex.peek())).append(". ");
                olNextIndex.push(olNextIndex.pop() + 1);
            } else if (parentList.equalsIgnoreCase("ul")) {
                start(output, new Ul());
            }
        } else {
            if (lists.peek().equalsIgnoreCase("ul")) {
                if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                    output.append("\n");
                }
                int bulletMargin = indent;
                if (lists.size() > 1) {
                    bulletMargin = indent - bullet.getLeadingMargin(true);
                    if (lists.size() > 2) {
                        bulletMargin -= (lists.size() - 2) * listItemIndent;
                    }
                }
                BulletSpan newBullet = new BulletSpan(bulletMargin);
                end(output, Ul.class, new LeadingMarginSpan.Standard(listItemIndent * (lists.size() - 1)), newBullet);
            } else if (lists.peek().equalsIgnoreCase("ol")) {
                if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                    output.append("\n");
                }
                int numberMargin = listItemIndent * (lists.size() - 1);
                if (lists.size() > 2) {
                    numberMargin -= (lists.size() - 2) * listItemIndent;
                }
                end(output, Ol.class, new LeadingMarginSpan.Standard(numberMargin));
            }
        }
    }
}
Also used : BulletSpan(android.text.style.BulletSpan) LeadingMarginSpan(android.text.style.LeadingMarginSpan) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 49 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project weiciyuan by qii.

the class UpdateMessageTask method setTextViewDeleted.

private void setTextViewDeleted(TextView tv) {
    SpannableString ss = SpannableString.valueOf(tv.getText());
    ss.setSpan(new StrikethroughSpan(), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    tv.setText(ss);
}
Also used : SpannableString(android.text.SpannableString) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 50 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project JustAndroid by chinaltz.

the class ShopcartAdapter method getChildView.

@Override
public View getChildView(final int groupPosition, final int childPosition, final boolean isLastChild, View convertView, final ViewGroup parent) {
    final ChildViewHolder cholder;
    if (convertView == null) {
        convertView = View.inflate(context, R.layout.item_shopcart_product, null);
        // if(isLastChild&&getChild(groupPosition,childPosition)!=null)
        // {
        // View    v = View.inflate(context, R.layout.child_footer,null);
        // TextView txtFooter = (TextView)v.findViewById(R.id.txtFooter);
        // txtFooter.setText("店铺满99元包邮");
        // if(convertView instanceof ViewGroup){
        // ((ViewGroup) convertView).addView(v);
        // }
        // }
        cholder = new ChildViewHolder(convertView);
        convertView.setTag(cholder);
    } else {
        cholder = (ChildViewHolder) convertView.getTag();
    }
    if (groups.get(groupPosition).isEdtor() == true) {
        cholder.llEdtor.setVisibility(View.VISIBLE);
        cholder.rlNoEdtor.setVisibility(View.GONE);
    } else {
        cholder.llEdtor.setVisibility(View.GONE);
        cholder.rlNoEdtor.setVisibility(View.VISIBLE);
    }
    final GoodsInfo goodsInfo = (GoodsInfo) getChild(groupPosition, childPosition);
    if (isLastChild && getChild(groupPosition, childPosition) != null) {
    // cholder.stub.setVisibility(View.VISIBLE);
    // TextView tv= (TextView) cholder.stub.findViewById(R.id.txtFooter);//这里用来动态显示店铺满99元包邮文字内容
    } else {
    // cholder.stub.setVisibility(View.GONE);
    }
    if (goodsInfo != null) {
        cholder.tvIntro.setText(goodsInfo.getDesc());
        cholder.tvPrice.setText("¥" + goodsInfo.getPrice() + "");
        cholder.etNum.setText(goodsInfo.getCount() + "");
        cholder.ivAdapterListPic.setImageResource(goodsInfo.getGoodsImg());
        cholder.tvColorsize.setText("颜色:" + goodsInfo.getColor() + "," + "尺码:" + goodsInfo.getSize() + "瓶/斤");
        SpannableString spanString = new SpannableString("¥" + String.valueOf(goodsInfo.getDiscountPrice()));
        StrikethroughSpan span = new StrikethroughSpan();
        spanString.setSpan(span, 0, String.valueOf(goodsInfo.getDiscountPrice()).length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        // 避免无限次的appand
        if (cholder.tvDiscountPrice.getText().toString().length() > 0) {
            cholder.tvDiscountPrice.setText("");
        }
        cholder.tvDiscountPrice.append(spanString);
        cholder.tvBuyNum.setText("x" + goodsInfo.getCount());
        cholder.checkBox.setChecked(goodsInfo.isChoosed());
        cholder.checkBox.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                goodsInfo.setChoosed(((CheckBox) v).isChecked());
                cholder.checkBox.setChecked(((CheckBox) v).isChecked());
                // 暴露子选接口
                checkInterface.checkChild(groupPosition, childPosition, ((CheckBox) v).isChecked());
            }
        });
        cholder.btAdd.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // 暴露增加接口
                modifyCountInterface.doIncrease(groupPosition, childPosition, cholder.etNum, cholder.checkBox.isChecked());
            }
        });
        cholder.btReduce.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // 暴露删减接口
                modifyCountInterface.doDecrease(groupPosition, childPosition, cholder.etNum, cholder.checkBox.isChecked());
            }
        });
        /**
         ******************方案一:弹出软键盘修改数量,应为又不知名的bug会使然键盘强行关闭**********************
         */
        /**
         **在清单文件的activity下设置键盘:
         *            android:windowSoftInputMode="adjustUnspecified|stateHidden|adjustPan"
         *            android:configChanges="orientation|keyboardHidden"***
         */
        // 监听文本输入框的文字变化,并且刷新数据
        cholder.etNum.addTextChangedListener(new GoodsNumWatcher(goodsInfo));
        notifyDataSetChanged();
        /**
         ******************方案一**************************************************************************
         */
        /**
         ******************方案二:让软键盘不能弹出,文本框不可编辑弹出dialog修改**********************
         */
        // cholder.etNum.setOnFocusChangeListener(new android.view.View.
        // OnFocusChangeListener() {
        // @Override
        // public void onFocusChange(View v, boolean hasFocus) {//监听焦点的变化
        // if (hasFocus) {//获取到焦点也就是文本框被点击修改了
        // // 1,先强制键盘不弹出
        // InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        // imm.hideSoftInputFromWindow(v.getWindowToken(), 0); //强制隐藏键盘
        // // 2.显示弹出dialog进行修改
        // showDialog(goodsInfo,cholder.etNum);
        // 3.清除焦点防止不断弹出dialog和软键盘
        // cholder.etNum.clearFocus();
        // 4. 数据刷型
        // ShopcartAdapter.this.notifyDataSetChanged();
        // }
        // }
        // });
        /**
         ******************方案二**********************
         */
        // 删除 购物车
        cholder.tvGoodsDelete.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                AlertDialog alert = new AlertDialog.Builder(context).create();
                alert.setTitle("操作提示");
                alert.setMessage("您确定要将这些商品从购物车中移除吗?");
                alert.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        return;
                    }
                });
                alert.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        modifyCountInterface.childDelete(groupPosition, childPosition);
                    }
                });
                alert.show();
            }
        });
    }
    return convertView;
}
Also used : SpannableString(android.text.SpannableString) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) CheckBox(android.widget.CheckBox) GoodsInfo(com.litingzhe.justandroid.main.model.GoodsInfo) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) 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