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.example.gaurav.calculator.Calculator.java

private void onDelete() {
    // Delete works like backspace; remove the last character from the expression.
    final Editable formulaText = mFormulaEditText.getEditableText();
    final int formulaLength = formulaText.length();
    if (formulaLength > 0) {
        formulaText.delete(formulaLength - 1, formulaLength);
    }//from  ww  w.j  a  va 2 s.c  om
}

From source file:com.forrestguice.suntimeswidget.settings.ColorChooser.java

private void changeColor() {
    Editable editable = edit.getText();
    int i = editable.toString().indexOf('#');
    if (i != -1) // should start with a #
    {/*from w w w.j  a  va  2  s.c  om*/
        editable.delete(i, i + 1);
    }
    editable.insert(0, "#");

    while (editable.length() < 3) // supply an alpha value (FF)
    {
        editable.insert(1, "F");
    }
    if (editable.length() == 7) {
        editable.insert(1, "FF");
    }

    while (editable.length() < 9) // fill rest with "0"
    {
        editable.append("0");
    }

    //Log.d("DEBUG", "color is " + editable.toString());
    edit.setText(editable);
    setColor(editable.toString());
    onColorChanged(getColor());
}

From source file:com.hamzahrmalik.calculator2.Calculator.java

private void onDelete() {
    // Delete works like backspace; remove the last character from the
    // expression.
    final Editable formulaText = mFormulaEditText.getEditableText();
    final int formulaLength = formulaText.length();
    if (formulaLength > 0) {
        formulaText.delete(formulaLength - 1, formulaLength);
    }/*  ww w .  j av  a2s.com*/
}

From source file:de.dmxcontrol.fragment.PanelSelectorFragment.java

private void removeLastCharFromActive() {
    Editable et;

    if (mActiveInputType == ACTIVE_INPUT_TYPE_DEVICE) {
        et = mEditDevice.getEditableText();
    } else {//from  w w w  .jav  a  2 s  .  c  o m
        et = mEditGroup.getEditableText();
    }

    if (et.length() > 0) {
        Log.d(TAG, "deleting from " + (et.length() - 1) + " - " + et.length());
        et.delete(et.length() - 1, et.length());
    }

    mIsEditing = true;
    updateEntitySelection(et);
    mIsEditing = false;
}

From source file:com.forrestguice.suntimeswidget.settings.ColorChooser.java

@Override
public void afterTextChanged(Editable editable) {
    if (isRunning || isRemoving)
        return;/*from ww w  .j av  a2 s.  c om*/
    isRunning = true;

    String text = editable.toString(); // should consist of [#][0-9][a-f]
    for (int j = text.length() - 1; j >= 0; j--) {
        if (!inputSet.contains(text.charAt(j))) {
            editable.delete(j, j + 1);
        }
    }

    text = editable.toString(); // should start with a #
    int i = text.indexOf('#');
    if (i != -1) {
        editable.delete(i, i + 1);
    }
    editable.insert(0, "#");

    if (editable.length() > 8) // should be no longer than 8
    {
        editable.delete(9, editable.length());
    }

    text = editable.toString();
    String toCaps = text.toUpperCase(Locale.US);
    editable.clear();
    editable.append(toCaps);

    isRunning = false;
}

From source file:com.app.jdy.ui.CashAdvanceActivity.java

public void initView() {
    backBtn = (ImageView) findViewById(R.id.back_img);
    right_img = (ImageView) findViewById(R.id.right_img);
    backBtn.setVisibility(View.VISIBLE);
    right_img.setVisibility(View.VISIBLE);
    right_img.setBackgroundResource(R.drawable.withdrawcash_history);
    backBtn.setOnClickListener(new OnClickListener() {
        @Override//from w w  w.  j  av a  2s  . c om
        public void onClick(View v) {
            finish();
        }
    });
    right_img.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(getBaseContext(), MyRecordActivity.class));
        }
    });
    textView = (TextView) findViewById(R.id.title_tv);
    textView.setText("??");
    textView1 = (TextView) findViewById(R.id.cash_textView1);
    textView2 = (TextView) findViewById(R.id.cash_textView2);
    textView1.setText("????()");
    textView4 = (TextView) findViewById(R.id.cash_textView4);
    textView5 = (TextView) findViewById(R.id.cash_textView5);
    textView3 = (TextView) findViewById(R.id.cash_textView6);
    editText = (EditText) findViewById(R.id.cash_editext1);

    // ???????
    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable edt) {
            String temp = edt.toString();
            int posDot = temp.indexOf(".");
            if (posDot <= 0)
                return;
            if (temp.length() - posDot - 1 > 2) {
                edt.delete(posDot + 3, posDot + 4);
            }
        }

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

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

    });

    button = (Button) findViewById(R.id.cash_button1);
    // ???
    if (HttpUtils.isNetworkConnected(CashAdvanceActivity.this)) {
        getData();
    } else {
        Toast.makeText(CashAdvanceActivity.this, Constants.NO_INTENT_TIPS, Toast.LENGTH_LONG).show();
    }

}

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

private static boolean delete(final Editable content, final KeyEvent event, final boolean forwardDelete) {
    if (hasModifiers(event)) {
        return false;
    }// ww w.  j  a  v  a 2  s .  c o  m

    final int start = Selection.getSelectionStart(content);
    final int end = Selection.getSelectionEnd(content);
    if (hasInvalidSelection(start, end)) {
        return false;
    }

    final EmojiSpan[] spans = content.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];
            final int spanStart = content.getSpanStart(span);
            final int spanEnd = content.getSpanEnd(span);
            if ((forwardDelete && spanStart == start) || (!forwardDelete && spanEnd == start)
                    || (start > spanStart && start < spanEnd)) {
                content.delete(spanStart, spanEnd);
                return true;
            }
        }
    }

    return false;
}

From source file:com.pitchedapps.primenumbercalculator.Calculator.java

License:asdf

private void onDelete() {
    // Delete works like backspace; remove the last character from the expression.
    final Editable inputText = mInputEditText.getEditableText();
    final int inputLength = inputText.length();
    if (inputLength > 0) {
        inputText.delete(inputLength - 1, inputLength);
    }//from  w ww  . j a  va2s  .c  om
}

From source file:org.mozilla.focus.widget.InlineAutocompleteEditText.java

/**
 * Remove any autocomplete text/* w w  w  .  j a  v a 2 s.  c  o m*/
 *
 * @param text Current text content that may include autocomplete text
 */
private boolean removeAutocomplete(final Editable text) {
    final int start = text.getSpanStart(AUTOCOMPLETE_SPAN);
    if (start < 0) {
        // No autocomplete text
        return false;
    }

    beginSettingAutocomplete();

    // When we call delete() here, the autocomplete spans we set are removed as well.
    text.delete(start, text.length());

    // Keep mAutoCompletePrefixLength the same because the prefix has not changed.
    // Clear mAutoCompleteResult to make sure we get fresh autocomplete text next time.
    mAutoCompleteResult = "";

    // Reshow the cursor.
    setCursorVisible(true);

    endSettingAutocomplete();
    return true;
}

From source file:tv.acfun.a63.CommentsActivity.java

void removeQuote(Editable text) {
    Quote quote = TextViewUtils.getLast(text, Quote.class);
    int start = text.getSpanStart(quote);
    int end = text.getSpanEnd(quote);
    // Log.d(TAG, String.format("start=%d, end=%d", start, end));
    if (start >= 0) {
        // Log.d(TAG, text.subSequence(start, end).toString());
        text.delete(start, end);
    }/*from  w  w  w .  j av a2 s.  co  m*/
}