Search in sources :

Example 26 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project NoHttp by yanzhenjie.

the class ResCompat method getDeleteText.

public static SpannableString getDeleteText(CharSequence content, int start, int end) {
    SpannableString stringSpan = new SpannableString(content);
    stringSpan.setSpan(new StrikethroughSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return stringSpan;
}
Also used : SpannableString(android.text.SpannableString) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 27 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project android_frameworks_base by DirtyUnicorns.

the class HtmlToSpannedConverter method withinParagraph.

private static void withinParagraph(StringBuilder out, Spanned text, int start, int end) {
    int next;
    for (int i = start; i < end; i = next) {
        next = text.nextSpanTransition(i, end, CharacterStyle.class);
        CharacterStyle[] style = text.getSpans(i, next, CharacterStyle.class);
        for (int j = 0; j < style.length; j++) {
            if (style[j] instanceof StyleSpan) {
                int s = ((StyleSpan) style[j]).getStyle();
                if ((s & Typeface.BOLD) != 0) {
                    out.append("<b>");
                }
                if ((s & Typeface.ITALIC) != 0) {
                    out.append("<i>");
                }
            }
            if (style[j] instanceof TypefaceSpan) {
                String s = ((TypefaceSpan) style[j]).getFamily();
                if ("monospace".equals(s)) {
                    out.append("<tt>");
                }
            }
            if (style[j] instanceof SuperscriptSpan) {
                out.append("<sup>");
            }
            if (style[j] instanceof SubscriptSpan) {
                out.append("<sub>");
            }
            if (style[j] instanceof UnderlineSpan) {
                out.append("<u>");
            }
            if (style[j] instanceof StrikethroughSpan) {
                out.append("<span style=\"text-decoration:line-through;\">");
            }
            if (style[j] instanceof URLSpan) {
                out.append("<a href=\"");
                out.append(((URLSpan) style[j]).getURL());
                out.append("\">");
            }
            if (style[j] instanceof ImageSpan) {
                out.append("<img src=\"");
                out.append(((ImageSpan) style[j]).getSource());
                out.append("\">");
                // Don't output the dummy character underlying the image.
                i = next;
            }
            if (style[j] instanceof AbsoluteSizeSpan) {
                AbsoluteSizeSpan s = ((AbsoluteSizeSpan) style[j]);
                float sizeDip = s.getSize();
                if (!s.getDip()) {
                    Application application = ActivityThread.currentApplication();
                    sizeDip /= application.getResources().getDisplayMetrics().density;
                }
                // px in CSS is the equivalance of dip in Android
                out.append(String.format("<span style=\"font-size:%.0fpx\";>", sizeDip));
            }
            if (style[j] instanceof RelativeSizeSpan) {
                float sizeEm = ((RelativeSizeSpan) style[j]).getSizeChange();
                out.append(String.format("<span style=\"font-size:%.2fem;\">", sizeEm));
            }
            if (style[j] instanceof ForegroundColorSpan) {
                int color = ((ForegroundColorSpan) style[j]).getForegroundColor();
                out.append(String.format("<span style=\"color:#%06X;\">", 0xFFFFFF & color));
            }
            if (style[j] instanceof BackgroundColorSpan) {
                int color = ((BackgroundColorSpan) style[j]).getBackgroundColor();
                out.append(String.format("<span style=\"background-color:#%06X;\">", 0xFFFFFF & color));
            }
        }
        withinStyle(out, text, i, next);
        for (int j = style.length - 1; j >= 0; j--) {
            if (style[j] instanceof BackgroundColorSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof ForegroundColorSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof RelativeSizeSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof AbsoluteSizeSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof URLSpan) {
                out.append("</a>");
            }
            if (style[j] instanceof StrikethroughSpan) {
                out.append("</span>");
            }
            if (style[j] instanceof UnderlineSpan) {
                out.append("</u>");
            }
            if (style[j] instanceof SubscriptSpan) {
                out.append("</sub>");
            }
            if (style[j] instanceof SuperscriptSpan) {
                out.append("</sup>");
            }
            if (style[j] instanceof TypefaceSpan) {
                String s = ((TypefaceSpan) style[j]).getFamily();
                if (s.equals("monospace")) {
                    out.append("</tt>");
                }
            }
            if (style[j] instanceof StyleSpan) {
                int s = ((StyleSpan) style[j]).getStyle();
                if ((s & Typeface.BOLD) != 0) {
                    out.append("</b>");
                }
                if ((s & Typeface.ITALIC) != 0) {
                    out.append("</i>");
                }
            }
        }
    }
}
Also used : SuperscriptSpan(android.text.style.SuperscriptSpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) URLSpan(android.text.style.URLSpan) CharacterStyle(android.text.style.CharacterStyle) UnderlineSpan(android.text.style.UnderlineSpan) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan) StyleSpan(android.text.style.StyleSpan) SubscriptSpan(android.text.style.SubscriptSpan) Application(android.app.Application) BackgroundColorSpan(android.text.style.BackgroundColorSpan) TypefaceSpan(android.text.style.TypefaceSpan) StrikethroughSpan(android.text.style.StrikethroughSpan) ImageSpan(android.text.style.ImageSpan)

Example 28 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project android_frameworks_base by DirtyUnicorns.

the class HtmlToSpannedConverter method endCssStyle.

private static void endCssStyle(Editable text) {
    Strikethrough s = getLast(text, Strikethrough.class);
    if (s != null) {
        setSpanFromMark(text, s, new StrikethroughSpan());
    }
    Background b = getLast(text, Background.class);
    if (b != null) {
        setSpanFromMark(text, b, new BackgroundColorSpan(b.mBackgroundColor));
    }
    Foreground f = getLast(text, Foreground.class);
    if (f != null) {
        setSpanFromMark(text, f, new ForegroundColorSpan(f.mForegroundColor));
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) BackgroundColorSpan(android.text.style.BackgroundColorSpan) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 29 with StrikethroughSpan

use of android.text.style.StrikethroughSpan in project android_frameworks_base by ResurrectionRemix.

the class HtmlToSpannedConverter method endCssStyle.

private static void endCssStyle(Editable text) {
    Strikethrough s = getLast(text, Strikethrough.class);
    if (s != null) {
        setSpanFromMark(text, s, new StrikethroughSpan());
    }
    Background b = getLast(text, Background.class);
    if (b != null) {
        setSpanFromMark(text, b, new BackgroundColorSpan(b.mBackgroundColor));
    }
    Foreground f = getLast(text, Foreground.class);
    if (f != null) {
        setSpanFromMark(text, f, new ForegroundColorSpan(f.mForegroundColor));
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) BackgroundColorSpan(android.text.style.BackgroundColorSpan) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 30 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)31 ForegroundColorSpan (android.text.style.ForegroundColorSpan)14 StyleSpan (android.text.style.StyleSpan)12 BackgroundColorSpan (android.text.style.BackgroundColorSpan)11 TypefaceSpan (android.text.style.TypefaceSpan)10 SpannableString (android.text.SpannableString)8 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)8 SubscriptSpan (android.text.style.SubscriptSpan)8 SuperscriptSpan (android.text.style.SuperscriptSpan)8 UnderlineSpan (android.text.style.UnderlineSpan)8 RelativeSizeSpan (android.text.style.RelativeSizeSpan)7 URLSpan (android.text.style.URLSpan)7 CharacterStyle (android.text.style.CharacterStyle)6 Application (android.app.Application)5 ImageSpan (android.text.style.ImageSpan)5 SpannableStringBuilder (android.text.SpannableStringBuilder)4 WPUnderlineSpan (org.wordpress.android.util.helpers.WPUnderlineSpan)4 Spannable (android.text.Spannable)3 LeadingMarginSpan (android.text.style.LeadingMarginSpan)3 QuoteSpan (android.text.style.QuoteSpan)3