Example usage for android.text.style StrikethroughSpan StrikethroughSpan

List of usage examples for android.text.style StrikethroughSpan StrikethroughSpan

Introduction

In this page you can find the example usage for android.text.style StrikethroughSpan StrikethroughSpan.

Prototype

public StrikethroughSpan() 

Source Link

Document

Creates a StrikethroughSpan .

Usage

From source file:Main.java

public static SpannableString getDeleteStr(String content) {
    SpannableString sps = new SpannableString(content);
    sps.setSpan(new StrikethroughSpan(), 0, content.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return sps;/*from  w w  w .j ava 2 s. c  o m*/
}

From source file:Main.java

/**
 * // w ww. j a  v a2  s  .  c  o  m
 * 
 * @param text
 * @return
 */
public static SpannableString strickout(String text) {
    SpannableString ss = new SpannableString(text);
    ss.setSpan(new StrikethroughSpan(), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return ss;
}

From source file:Main.java

public static SpannableString setTextStrikethrough(String content, int startIndex, int endIndex) {
    if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length()
            || startIndex >= endIndex) {
        return null;
    }// w  w  w  .j av  a  2 s  .c  o  m

    SpannableString spannableString = new SpannableString(content);
    spannableString.setSpan(new StrikethroughSpan(), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spannableString;
}

From source file:Main.java

public static SpannableStringBuilder getSpannableStringFromList(List<HashMap<String, Object>> list) {
    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    int position = 0;
    for (int i = 0; i < list.size(); i++) {
        HashMap<String, Object> map = list.get(i);
        try {/*  w  ww  .  ja  v a  2  s . co  m*/
            String st = (String) map.get(RICHTEXT_STRING);
            ssb.append(st);
            int len = st.length();
            if (map.containsKey(RICHTEXT_COLOR)) {
                int color = ((Integer) map.get(RICHTEXT_COLOR)).intValue();
                ssb.setSpan(new ForegroundColorSpan(color), position, position + len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (map.containsKey(RICHTEXT_SIZE)) {
                int size = ((Integer) map.get(RICHTEXT_SIZE)).intValue();
                ssb.setSpan(new AbsoluteSizeSpan(size), position, position + len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (map.containsKey(RICHTEXT_RSIZE)) {
                float size = ((Float) map.get(RICHTEXT_RSIZE)).floatValue();
                ssb.setSpan(new RelativeSizeSpan(size), position, position + len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (map.containsKey(RICHTEXT_DELETE)) {
                ssb.setSpan(new StrikethroughSpan(), position, position + len,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            //              android.text.style.RelativeSizeSpan
            position = position + len;
        } catch (Exception e) {
            return null;
        }
    }
    return ssb;
}

From source file:ayushi.view.adapter.ShoppingListAdapter.java

@Override
public void onBindViewHolder(final ItemViewHolder holder, final int position) {
    holder.itemName.setText(productList.get(position).getItemName());

    holder.itemDesc.setText(productList.get(position).getItemShortDesc());

    String sellCostString = Money
            .rupees(BigDecimal.valueOf(Long.valueOf(productList.get(position).getSellMRP()))).toString() + "  ";

    String buyMRP = Money.rupees(BigDecimal.valueOf(Long.valueOf(productList.get(position).getMRP())))
            .toString();// ww w.  ja  va2 s  . c  om

    String costString = sellCostString + buyMRP;

    holder.itemCost.setText(costString, BufferType.SPANNABLE);

    Spannable spannable = (Spannable) holder.itemCost.getText();

    spannable.setSpan(new StrikethroughSpan(), sellCostString.length(), costString.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    mDrawableBuilder = TextDrawable.builder().beginConfig().withBorder(4).endConfig().roundRect(10);

    drawable = mDrawableBuilder.build(String.valueOf(productList.get(position).getItemName().charAt(0)),
            mColorGenerator.getColor(productList.get(position).getItemName()));

    ImageUrl = productList.get(position).getImageURL();

    holder.quanitity
            .setText(GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getQuantity());

    Glide.with(context).load(ImageUrl).placeholder(drawable).error(drawable).animate(R.anim.base_slide_right_in)
            .centerCrop().into(holder.imagView);

    // Start a drag whenever the handle view it touched
    holder.imagView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                mDragStartListener.onStartDrag(holder);
            }
            return false;
        }
    });

    holder.addItem.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).setQuantity(String.valueOf(

                    Integer.valueOf(
                            GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getQuantity())
                            + 1));

            holder.quanitity.setText(
                    GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getQuantity());

            Utils.vibrate(context);

            ((ECartHomeActivity) context).updateCheckOutAmount(
                    BigDecimal.valueOf(Long.valueOf(
                            GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getSellMRP())),
                    true);

        }
    });

    holder.removeItem.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (Integer.valueOf(
                    GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getQuantity()) > 2) {

                GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).setQuantity(String.valueOf(

                        Integer.valueOf(GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position)
                                .getQuantity()) - 1));

                holder.quanitity.setText(
                        GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getQuantity());

                ((ECartHomeActivity) context).updateCheckOutAmount(BigDecimal.valueOf(Long.valueOf(
                        GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getSellMRP())),
                        false);

                Utils.vibrate(context);
            }

            else if (Integer.valueOf(
                    GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getQuantity()) == 1) {
                ((ECartHomeActivity) context).updateItemCount(false);

                ((ECartHomeActivity) context).updateCheckOutAmount(BigDecimal.valueOf(Long.valueOf(
                        GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(position).getSellMRP())),
                        false);

                GlobaDataHolder.getGlobaDataHolder().getShoppingList().remove(position);

                if (Integer.valueOf(((ECartHomeActivity) context).getItemCount()) == 0) {

                    MyCartFragment.updateMyCartFragment(false);

                }

                Utils.vibrate(context);

            }

        }
    });
}

From source file:com.hitesh_sahu.retailapp.view.adapter.ShoppingListAdapter.java

@Override
public void onBindViewHolder(final ItemViewHolder holder, final int position) {
    holder.itemName.setText(productList.get(position).getItemName());

    holder.itemDesc.setText(productList.get(position).getItemShortDesc());

    String sellCostString = Money
            .rupees(BigDecimal.valueOf(Long.valueOf(productList.get(position).getSellMRP()))).toString() + "  ";

    String buyMRP = Money.rupees(BigDecimal.valueOf(Long.valueOf(productList.get(position).getMRP())))
            .toString();/* www .  j av a 2s .  c o  m*/

    String costString = sellCostString + buyMRP;

    holder.itemCost.setText(costString, BufferType.SPANNABLE);

    Spannable spannable = (Spannable) holder.itemCost.getText();

    spannable.setSpan(new StrikethroughSpan(), sellCostString.length(), costString.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    mDrawableBuilder = TextDrawable.builder().beginConfig().withBorder(4).endConfig().roundRect(10);

    drawable = mDrawableBuilder.build(String.valueOf(productList.get(position).getItemName().charAt(0)),
            mColorGenerator.getColor(productList.get(position).getItemName()));

    ImageUrl = productList.get(position).getImageURL();

    holder.quanitity.setText(CenterRepository.getCenterRepository().getListOfProductsInShoppingList()
            .get(position).getQuantity());

    Glide.with(context).load(ImageUrl).placeholder(drawable).error(drawable).animate(R.anim.base_slide_right_in)
            .centerCrop().into(holder.imagView);

    // Start a drag whenever the handle view it touched
    holder.imagView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                mDragStartListener.onStartDrag(holder);
            }
            return false;
        }
    });

    holder.addItem.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            CenterRepository.getCenterRepository().getListOfProductsInShoppingList().get(position)
                    .setQuantity(String.valueOf(

                            Integer.valueOf(CenterRepository.getCenterRepository()
                                    .getListOfProductsInShoppingList().get(position).getQuantity()) + 1));

            holder.quanitity.setText(CenterRepository.getCenterRepository().getListOfProductsInShoppingList()
                    .get(position).getQuantity());

            Utils.vibrate(context);

            ((ECartHomeActivity) context).updateCheckOutAmount(BigDecimal.valueOf(Long.valueOf(CenterRepository
                    .getCenterRepository().getListOfProductsInShoppingList().get(position).getSellMRP())),
                    true);

        }
    });

    holder.removeItem.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (Integer.valueOf(CenterRepository.getCenterRepository().getListOfProductsInShoppingList()
                    .get(position).getQuantity()) > 2) {

                CenterRepository.getCenterRepository().getListOfProductsInShoppingList().get(position)
                        .setQuantity(String.valueOf(

                                Integer.valueOf(CenterRepository.getCenterRepository()
                                        .getListOfProductsInShoppingList().get(position).getQuantity()) - 1));

                holder.quanitity.setText(CenterRepository.getCenterRepository()
                        .getListOfProductsInShoppingList().get(position).getQuantity());

                ((ECartHomeActivity) context).updateCheckOutAmount(
                        BigDecimal.valueOf(Long.valueOf(CenterRepository.getCenterRepository()
                                .getListOfProductsInShoppingList().get(position).getSellMRP())),
                        false);

                Utils.vibrate(context);
            }

            else if (Integer.valueOf(CenterRepository.getCenterRepository().getListOfProductsInShoppingList()
                    .get(position).getQuantity()) == 1) {
                ((ECartHomeActivity) context).updateItemCount(false);

                ((ECartHomeActivity) context).updateCheckOutAmount(
                        BigDecimal.valueOf(Long.valueOf(CenterRepository.getCenterRepository()
                                .getListOfProductsInShoppingList().get(position).getSellMRP())),
                        false);

                CenterRepository.getCenterRepository().getListOfProductsInShoppingList().remove(position);

                if (Integer.valueOf(((ECartHomeActivity) context).getItemCount()) == 0) {

                    MyCartFragment.updateMyCartFragment(false);

                }

                Utils.vibrate(context);

            }

        }
    });
}

From source file:com.inter.trade.ui.fragment.buylicensekey.BuyLicenseKeyMainFragment.java

private void initView(View view) {
    btn_buy_licensekey = (Button) view.findViewById(R.id.btn_buy_licensekey);
    tv_bind = (TextView) view.findViewById(R.id.tv_bind);

    product_price = (TextView) view.findViewById(R.id.product_price);

    // /*  w w w  .  j  a v a  2 s.  co  m*/
    SpannableString sp = new SpannableString(product_price.getText().toString());
    sp.setSpan(new StrikethroughSpan(), 0, product_price.getText().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    product_price.setText(sp);

    btn_buy_licensekey.setOnClickListener(this);
    tv_bind.setOnClickListener(this);
}

From source file:com.microsoft.azure.engagement.ProductDiscountActivity.java

/**
 * Method that adds or removes a strike from a TextView object
 *
 * @param textView The textView to manage
 *//* w w  w  . j  a v a2 s  .c om*/
private final void addOrRemoveStrikeTextView(TextView textView, boolean toAdd) {
    textView.setText(textView.getText().toString(), TextView.BufferType.SPANNABLE);
    final Spannable spannable = (Spannable) textView.getText();

    if (toAdd == true) {
        // Add a StrikethroughSpan style
        final StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
        spannable.setSpan(strikethroughSpan, 0, textView.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        // Remove only StrikethroughSpan style
        final Object spans[] = spannable.getSpans(0, textView.length(), Object.class);
        for (final Object span : spans) {
            if (span instanceof StrikethroughSpan == true) {
                spannable.removeSpan(span);
                return;
            }
        }
    }
}

From source file:se.anyro.tagtider.TransferActivity.java

private void setupTransferData(final Bundle extras) {
    TextView trainView = (TextView) findViewById(R.id.train);

    ViewGroup originGroup = (ViewGroup) findViewById(R.id.origin_group);
    TextView originView = (TextView) findViewById(R.id.origin);
    TextView arrivalView = (TextView) findViewById(R.id.arrival);

    TextView stationTrackView = (TextView) findViewById(R.id.station_track);

    ViewGroup destinationGroup = (ViewGroup) findViewById(R.id.destination_group);
    TextView destinationView = (TextView) findViewById(R.id.destination);
    TextView departureView = (TextView) findViewById(R.id.departure);

    TextView commentView = (TextView) findViewById(R.id.comment);
    mEmptyView = (TextView) findViewById(android.R.id.empty);

    trainView.setText("Tg " + extras.getString("train") + " (" + extras.getString("type") + ")");

    String origin = extras.getString("origin");
    if (origin != null && origin.length() > 0) {
        originView.setText("Frn " + origin);
        originGroup.setVisibility(View.VISIBLE);
    } else {// ww w.  j av  a  2 s  . com
        originGroup.setVisibility(View.GONE);
    }

    String track = extras.getString("track");
    if (track == null || track.equalsIgnoreCase("x") || track.equalsIgnoreCase("null"))
        track = "";

    String arrival = extras.getString("arrival");
    if (arrival != null && !arrival.startsWith("0000")) {
        arrivalView.setText("Ankommer " + StringUtils.extractTime(arrival));
        String newArrival = extras.getString("newArrival");
        if (newArrival != null) {
            newArrival = StringUtils.extractTime(newArrival);
            SpannableString strike = new SpannableString(arrivalView.getText() + " " + newArrival);
            strike.setSpan(new StrikethroughSpan(), strike.length() - 11, strike.length() - 6, 0);
            arrivalView.setText(strike, TextView.BufferType.SPANNABLE);
        }
        if (track.length() == 0) {
            SpannableString strike = new SpannableString(arrivalView.getText());
            strike.setSpan(new StrikethroughSpan(), strike.length() - 5, strike.length(), 0);
            arrivalView.setText(strike, TextView.BufferType.SPANNABLE);
        }
    }

    if (extras.getString("stationName") != null) {
        mStationName = extras.getString("stationName");
    }

    if (track.length() > 0 && mStationName != null)
        stationTrackView.setText(mStationName + ", spr " + track);
    else if (mStationName != null)
        stationTrackView.setText(mStationName);
    else if (track.length() > 0)
        stationTrackView.setText("Spr " + track);
    else
        stationTrackView.setText("");

    String destination = extras.getString("destination");
    if (destination != null && destination.length() > 0) {
        destinationView.setText("Till " + destination);
        destinationGroup.setVisibility(View.VISIBLE);
    } else {
        destinationGroup.setVisibility(View.GONE);
    }

    String departure = extras.getString("departure");
    if (departure != null && !departure.startsWith("0000")) {
        departureView.setText("Avgr " + StringUtils.extractTime(departure));
        String newDeparture = extras.getString("newDeparture");
        if (newDeparture != null) {
            newDeparture = StringUtils.extractTime(newDeparture);
            SpannableString strike = new SpannableString(departureView.getText() + " " + newDeparture);
            strike.setSpan(new StrikethroughSpan(), strike.length() - 11, strike.length() - 6, 0);
            departureView.setText(strike, TextView.BufferType.SPANNABLE);
        }
        if (track.length() == 0) {
            SpannableString strike = new SpannableString(departureView.getText());
            strike.setSpan(new StrikethroughSpan(), strike.length() - 5, strike.length(), 0);
            departureView.setText(strike, TextView.BufferType.SPANNABLE);
        }
    }

    String comment = extras.getString("comment");
    if ((comment == null || comment.length() == 0) && track.length() == 0)
        comment = "Instllt";
    if (comment != null && comment.length() > 0) {
        commentView.setText(comment);
        commentView.setVisibility(View.VISIBLE);
    } else {
        commentView.setVisibility(View.GONE);
    }

    mTrain = extras.getString("train");
    mStationId = extras.getString("stationId");

    mTransferId = extras.getString("id");
}

From source file:io.github.hidroh.materialistic.data.HackerNewsItem.java

@Override
public Spannable getDisplayedTime(Context context) {
    if (displayedTime == null) {
        SpannableStringBuilder builder = new SpannableStringBuilder(
                dead ? context.getString(R.string.dead_prefix) + " " : "");
        SpannableString timeSpannable = new SpannableString(AppUtils.getAbbreviatedTimeSpan(time * 1000));
        if (deleted) {
            timeSpannable.setSpan(new StrikethroughSpan(), 0, timeSpannable.length(),
                    Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        }//from  w ww .  j av a 2 s.co  m
        builder.append(timeSpannable);
        displayedTime = builder;
    }
    return displayedTime;
}