Example usage for android.text Editable delete

List of usage examples for android.text Editable delete

Introduction

In this page you can find the example usage for android.text Editable delete.

Prototype

public Editable delete(int st, int en);

Source Link

Document

Convenience for replace(st, en, "", 0, 0)

Usage

From source file:com.ruesga.rview.widget.TagEditTextView.java

private void onTagRemoveClick(final Tag tag) {
    Editable s = mTagEdit.getEditableText();
    int position = mTagList.indexOf(tag);
    mLockEdit = true;/*from w  ww. ja va  2s .co m*/
    mTagList.remove(position);
    ImageSpan[] spans = s.getSpans(position, position + 1, ImageSpan.class);
    for (ImageSpan span : spans) {
        s.removeSpan(span);
    }
    s.delete(position, position + 1);
    mLockEdit = false;

    notifyTagRemoved(tag);
}

From source file:com.zhenlaidian.ui.InputCarNumberActivity.java

public void setView() {
    rl_delete_edtext.setOnClickListener(new Button.OnClickListener() {
        @Override/*from www  .ja  v a  2s  . com*/
        public void onClick(View arg0) {
            String carnumber = et_carnumber.getText().toString().trim();
            if (carnumber.length() >= 1) {
                int index = et_carnumber.getSelectionStart();
                Editable editable = et_carnumber.getText();
                if (index >= 1) {
                    editable.delete(index - 1, index);
                }
            }
        }
    });
    rl_delete_edtext.setOnLongClickListener(new Button.OnLongClickListener() {

        @Override
        public boolean onLongClick(View arg0) {
            et_carnumber.setText("");
            return false;
        }
    });
    findViewById(R.id.bt_input_carnumber_cancel).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //??
            RecogService.recogModel = false;
            Intent intent = new Intent(context, MemoryCameraActivity.class);
            //                Intent intent = new Intent(context, PosCaptureActivity.class);
            intent.putExtra("camera", true);
            intent.putExtra("from", getIntent().getStringExtra("from"));
            startActivity(intent);
            finish();
        }
    });
    bt_ok.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (CheckUtils.CarChecked(et_carnumber.getText().toString())) {
                //                    Toast.makeText(context, "", Toast.LENGTH_SHORT).show();
                //??? ???
                //???????
                //?????????step
                //                    CommontUtils.toast(context, "--" + getStringFromPreference("bowei"));
                try {
                    //?
                    getParkInfo(et_carnumber.getText().toString());
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }

            } else {
                Toast.makeText(context, "?!!!", Toast.LENGTH_SHORT).show();
            }

        }
    });
    if (CommontUtils.checkString(SharedPreferencesUtils.getIntance(context).getfirstprovince())
            && (!SharedPreferencesUtils.getIntance(context).getfirstprovince().equals("null"))) {
        et_carnumber.setText(SharedPreferencesUtils.getIntance(context).getfirstprovince());
        et_carnumber.setSelection(SharedPreferencesUtils.getIntance(context).getfirstprovince().length());
        viewPager.setCurrentItem(1);
    }

    et_carnumber.setInputType(InputType.TYPE_NULL);
    et_carnumber.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() == 1) {
                viewPager.setCurrentItem(1);
            }
        }
    });

}

From source file:com.fa.mastodon.activity.ComposeActivity.java

private void removeMediaFromQueue(QueuedMedia item) {
    mediaPreviewBar.removeView(item.preview);
    mediaQueued.remove(item);//from w  w w  .  j  a v  a 2  s.c o m
    if (mediaQueued.size() == 0) {
        showMarkSensitive(false);
        /* If there are no image previews to show, the extra padding that was added to the
         * EditText can be removed so there isn't unnecessary empty space. */
        textEditor.setPadding(textEditor.getPaddingLeft(), textEditor.getPaddingTop(),
                textEditor.getPaddingRight(), 0);
    }
    // Remove the text URL associated with this media.
    if (item.uploadUrl != null) {
        Editable text = textEditor.getText();
        int start = text.getSpanStart(item.uploadUrl);
        int end = text.getSpanEnd(item.uploadUrl);
        if (start != -1 && end != -1) {
            text.delete(start, end);
        }
    }
    enableMediaButtons();
    cancelReadyingMedia(item);
}

From source file:com.taobao.weex.dom.WXTextDomObject.java

/**
 * Truncate the source span to the specified lines.
 * Caller of this method must ensure that the lines of text is <strong>greater than desired lines and need truncate</strong>.
 * Otherwise, unexpected behavior may happen.
 * @param source The source span.//from   w  w w .j  a va2 s.  co  m
 * @param paint the textPaint
 * @param desired specified lines.
 * @param truncateAt truncate method, null value means clipping overflow text directly, non-null value means using ellipsis strategy to clip
 * @return The spans after clipped.
 */
private @NonNull Spanned truncate(@Nullable Editable source, @NonNull TextPaint paint, int desired,
        @Nullable TextUtils.TruncateAt truncateAt) {
    Spanned ret = new SpannedString("");
    if (!TextUtils.isEmpty(source) && source.length() > 0) {
        if (truncateAt != null) {
            source.append(ELLIPSIS);
            Object[] spans = source.getSpans(0, source.length(), Object.class);
            for (Object span : spans) {
                int start = source.getSpanStart(span);
                int end = source.getSpanEnd(span);
                if (start == 0 && end == source.length() - 1) {
                    source.removeSpan(span);
                    source.setSpan(span, 0, source.length(), source.getSpanFlags(span));
                }
            }
        }

        StaticLayout layout;
        int startOffset;

        while (source.length() > 1) {
            startOffset = source.length() - 1;
            if (truncateAt != null) {
                startOffset -= 1;
            }
            source.delete(startOffset, startOffset + 1);
            layout = new StaticLayout(source, paint, desired, Layout.Alignment.ALIGN_NORMAL, 1, 0, false);
            if (layout.getLineCount() <= 1) {
                ret = source;
                break;
            }
        }
    }
    return ret;
}

From source file:android.support.text.emoji.EmojiProcessor.java

/**
 * Handles deleteSurroundingText commands from {@link InputConnection} and tries to delete an
 * {@link EmojiSpan} from an {@link Editable}. Returns {@code true} if an {@link EmojiSpan} is
 * deleted./* ww w .  ja va  2s.  c o  m*/
 * <p/>
 * If there is a selection where selection start is not equal to selection end, does not
 * delete.
 *
 * @param inputConnection InputConnection instance
 * @param editable TextView.Editable instance
 * @param beforeLength the number of characters before the cursor to be deleted
 * @param afterLength the number of characters after the cursor to be deleted
 * @param inCodePoints {@code true} if length parameters are in codepoints
 *
 * @return {@code true} if an {@link EmojiSpan} is deleted
 */
static boolean handleDeleteSurroundingText(@NonNull final InputConnection inputConnection,
        @NonNull final Editable editable, @IntRange(from = 0) final int beforeLength,
        @IntRange(from = 0) final int afterLength, final boolean inCodePoints) {
    //noinspection ConstantConditions
    if (editable == null || inputConnection == null) {
        return false;
    }

    if (beforeLength < 0 || afterLength < 0) {
        return false;
    }

    final int selectionStart = Selection.getSelectionStart(editable);
    final int selectionEnd = Selection.getSelectionEnd(editable);

    if (hasInvalidSelection(selectionStart, selectionEnd)) {
        return false;
    }

    int start;
    int end;
    if (inCodePoints) {
        // go backwards in terms of codepoints
        start = CodepointIndexFinder.findIndexBackward(editable, selectionStart, Math.max(beforeLength, 0));
        end = CodepointIndexFinder.findIndexForward(editable, selectionEnd, Math.max(afterLength, 0));

        if (start == CodepointIndexFinder.INVALID_INDEX || end == CodepointIndexFinder.INVALID_INDEX) {
            return false;
        }
    } else {
        start = Math.max(selectionStart - beforeLength, 0);
        end = Math.min(selectionEnd + afterLength, editable.length());
    }

    final EmojiSpan[] spans = editable.getSpans(start, end, EmojiSpan.class);
    if (spans != null && spans.length > 0) {
        final int length = spans.length;
        for (int index = 0; index < length; index++) {
            final EmojiSpan span = spans[index];
            int spanStart = editable.getSpanStart(span);
            int spanEnd = editable.getSpanEnd(span);
            start = Math.min(spanStart, start);
            end = Math.max(spanEnd, end);
        }

        start = Math.max(start, 0);
        end = Math.min(end, editable.length());

        inputConnection.beginBatchEdit();
        editable.delete(start, end);
        inputConnection.endBatchEdit();
        return true;
    }

    return false;
}

From source file:com.df.dfcarchecker.CarCheck.CarCheckBasicInfoFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //        Random r=new Random();
    //        int uniqueNumber =(r.nextInt(999) + 100);
    //        uniqueId = Integer.toString(uniqueNumber);

    // ?uniqueId//from  www.j a v  a2s.  c o m
    UUID uuid = UUID.randomUUID();
    uniqueId = uuid.toString();

    this.inflater = inflater;
    rootView = inflater.inflate(R.layout.fragment_car_check_basic_info, container, false);

    // <editor-fold defaultstate="collapsed" desc="??View?">
    tableLayout = (TableLayout) rootView.findViewById(R.id.bi_content_table);

    contentLayout = (LinearLayout) rootView.findViewById(R.id.brand_input);

    Button vinButton = (Button) rootView.findViewById(R.id.bi_vin_button);
    vinButton.setOnClickListener(this);

    brandOkButton = (Button) rootView.findViewById(R.id.bi_brand_ok_button);
    brandOkButton.setEnabled(false);
    brandOkButton.setOnClickListener(this);

    brandSelectButton = (Button) rootView.findViewById(R.id.bi_brand_select_button);
    brandSelectButton.setEnabled(false);
    brandSelectButton.setOnClickListener(this);

    // ??
    sketchPhotoEntities = new ArrayList<PhotoEntity>();

    // 
    Button matchButton = (Button) rootView.findViewById(R.id.ct_licencePhotoMatch_button);
    matchButton.setOnClickListener(this);

    // vin???
    InputFilter alphaNumericFilter = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence arg0, int arg1, int arg2, Spanned arg3, int arg4, int arg5) {
            for (int k = arg1; k < arg2; k++) {
                if (!Character.isLetterOrDigit(arg0.charAt(k))) {
                    return "";
                }
            }
            return null;
        }
    };
    vin_edit = (EditText) rootView.findViewById(R.id.bi_vin_edit);
    vin_edit.setFilters(new InputFilter[] { alphaNumericFilter, new InputFilter.AllCaps() });

    brandEdit = (EditText) rootView.findViewById(R.id.bi_brand_edit);
    displacementEdit = (EditText) rootView.findViewById(R.id.csi_displacement_edit);
    transmissionEdit = (EditText) rootView.findViewById(R.id.csi_transmission_edit);
    runEdit = (EditText) rootView.findViewById(R.id.bi_mileage_edit);
    //
    //        transmissionSpinner = (Spinner)rootView.findViewById(R.id.csi_transmission_spinner);
    //        transmissionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    //            @Override
    //            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
    //                transmissionEdit.setText(adapterView.getSelectedItem().toString());
    //            }
    //
    //            @Override
    //            public void onNothingSelected(AdapterView<?> adapterView) {
    //
    //            }
    //        });

    // ??????
    ScrollView view = (ScrollView) rootView.findViewById(R.id.root);
    view.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.requestFocusFromTouch();
            return false;
        }
    });

    // ????????2?
    runEdit.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable edt) {
            String temp = edt.toString();

            if (temp.contains(".")) {
                int posDot = temp.indexOf(".");
                if (posDot <= 0)
                    return;
                if (temp.length() - posDot - 1 > 2) {
                    edt.delete(posDot + 3, posDot + 4);
                }
            } else {
                if (temp.length() > 2) {
                    edt.clear();
                    edt.append(temp.substring(0, 2));
                }
            }
        }

        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }

        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }
    });

    licencePhotoMatchEdit = (EditText) rootView.findViewById(R.id.ct_licencePhotoMatch_edit);
    licencePhotoMatchEdit.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            licencePhotoMatchEdit.setError(null);
        }

        @Override
        public void afterTextChanged(Editable editable) {
            licencePhotoMatchEdit.setError(null);
        }
    });

    // ??
    carNumberEdit = (EditText) rootView.findViewById(R.id.ci_plateNumber_edit);
    carNumberEdit.setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(10) });

    // ?
    portedProcedureRow = (TableRow) rootView.findViewById(R.id.ct_ported_procedure);

    // ?Spinner
    setRegLocationSpinner();
    setCarColorSpinner();
    setFirstLogTimeSpinner();
    setManufactureTimeSpinner();
    setTransferCountSpinner();
    setLastTransferTimeSpinner();
    setYearlyCheckAvailableDateSpinner();
    setAvailableDateYearSpinner();
    setBusinessInsuranceAvailableDateYearSpinner();
    setOtherSpinners();
    // </editor-fold>

    mCarSettings = new CarSettings();

    // ??xml
    if (vehicleModel == null) {
        mProgressDialog = ProgressDialog.show(rootView.getContext(), null, "?..", false, false);

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    ParseXml();

                    // jsonData??
                    if (!jsonData.equals("")) {
                        modifyMode = true;
                        letsEnterModifyMode();
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        thread.start();
    }

    return rootView;
}

From source file:com.android.ex.chips.RecipientEditTextView.java

/**
 * Show specified chip as selected. If the RecipientChip is just an email address, selecting the chip will take the
 * contents of the chip and place it at the end of the RecipientEditTextView for inline editing. If the
 * RecipientChip is a complete contact, then selecting the chip will change the background color of the chip, show
 * the delete icon, and a popup window with the address in use highlighted and any other alternate addresses for the
 * contact.// w  ww . j  av  a2 s  .co  m
 *
 * @param currentChip
 * Chip to select.
 * @return A RecipientChip in the selected state or null if the chip just contained an email address.
 */
private DrawableRecipientChip selectChip(final DrawableRecipientChip currentChip) {
    if (shouldShowEditableText(currentChip)) {
        final CharSequence text = currentChip.getValue();
        final Editable editable = getText();
        final Spannable spannable = getSpannable();
        final int spanStart = spannable.getSpanStart(currentChip);
        final int spanEnd = spannable.getSpanEnd(currentChip);
        spannable.removeSpan(currentChip);
        editable.delete(spanStart, spanEnd);
        setCursorVisible(true);
        setSelection(editable.length());
        editable.append(text);
        return constructChipSpan(RecipientEntry.constructFakeEntry((String) text, isValid(text.toString())),
                true, false);
    } else if (currentChip.getContactId() == RecipientEntry.GENERATED_CONTACT || currentChip.isGalContact()) {
        final int start = getChipStart(currentChip);
        final int end = getChipEnd(currentChip);
        getSpannable().removeSpan(currentChip);
        DrawableRecipientChip newChip;
        try {
            if (mNoChips)
                return null;
            newChip = constructChipSpan(currentChip.getEntry(), true, false);
        } catch (final NullPointerException e) {
            Log.e(TAG, e.getMessage(), e);
            return null;
        }
        final Editable editable = getText();
        QwertyKeyListener.markAsReplaced(editable, start, end, "");
        if (start == -1 || end == -1)
            Log.d(TAG, "The chip being selected no longer exists but should.");
        else
            editable.setSpan(newChip, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        newChip.setSelected(true);
        if (shouldShowEditableText(newChip))
            scrollLineIntoView(getLayout().getLineForOffset(getChipStart(newChip)));
        //showAddress(newChip,mAddressPopup,getWidth());
        setCursorVisible(false);
        return newChip;
    } else {
        final int start = getChipStart(currentChip);
        final int end = getChipEnd(currentChip);
        getSpannable().removeSpan(currentChip);
        DrawableRecipientChip newChip;
        try {
            newChip = constructChipSpan(currentChip.getEntry(), true, false);
        } catch (final NullPointerException e) {
            Log.e(TAG, e.getMessage(), e);
            return null;
        }
        final Editable editable = getText();
        QwertyKeyListener.markAsReplaced(editable, start, end, "");
        if (start == -1 || end == -1)
            Log.d(TAG, "The chip being selected no longer exists but should.");
        else
            editable.setSpan(newChip, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        newChip.setSelected(true);
        if (shouldShowEditableText(newChip))
            scrollLineIntoView(getLayout().getLineForOffset(getChipStart(newChip)));
        //showAlternates(newChip,mAlternatesPopup,getWidth());
        setCursorVisible(false);
        return newChip;
    }
}

From source file:com.android.ex.chips.RecipientEditTextView.java

/**
 * Remove any characters after the last valid chip.
 *//*from w  w w  .ja  v a 2s.c  o  m*/
// Visible for testing.
/* package */void sanitizeEnd() {
    // Don't sanitize while we are waiting for pending chips to complete.
    if (mPendingChipsCount > 0)
        return;
    // Find the last chip; eliminate any commit characters after it.
    final DrawableRecipientChip[] chips = getSortedRecipients();
    final Spannable spannable = getSpannable();
    if (chips != null && chips.length > 0) {
        int end;
        mMoreChip = getMoreChip();
        if (mMoreChip != null)
            end = spannable.getSpanEnd(mMoreChip);
        else
            end = getSpannable().getSpanEnd(getLastChip());
        final Editable editable = getText();
        final int length = editable.length();
        if (length > end) {
            // See what characters occur after that and eliminate them.
            if (Log.isLoggable(TAG, Log.DEBUG))
                Log.d(TAG, "There were extra characters after the last tokenizable entry." + editable);
            editable.delete(end + 1, length);
        }
    }
}

From source file:com.android.ex.chips.RecipientEditTextView.java

/**
 * Remove the chip and any text associated with it from the RecipientEditTextView.
 *
 * @param alsoNotifyAboutDataChanges//from   www.j  a va  2  s.c  o  m
 */
// Visible for testing.
/* package */void removeChip(final DrawableRecipientChip chip, final boolean alsoNotifyAboutDataChanges) {
    if (!alsoNotifyAboutDataChanges)
        --mPreviousChipsCount;
    final Spannable spannable = getSpannable();
    final int spanStart = spannable.getSpanStart(chip);
    final int spanEnd = spannable.getSpanEnd(chip);
    final Editable text = getText();
    int toDelete = spanEnd;
    final boolean wasSelected = chip == mSelectedChip;
    // Clear that there is a selected chip before updating any text.
    if (wasSelected)
        mSelectedChip = null;
    // Always remove trailing spaces when removing a chip.
    while (toDelete >= 0 && toDelete < text.length() && text.charAt(toDelete) == ' ')
        toDelete++;
    spannable.removeSpan(chip);
    if (spanStart >= 0 && toDelete > 0)
        text.delete(spanStart, toDelete);
    if (wasSelected)
        clearSelectedChip();
}