Search in sources :

Example 41 with TextWatcher

use of android.text.TextWatcher in project Jota-Text-Editor-old by jiro-aqua.

the class SpannableStringBuilder method replace.

// Documentation from interface
public SpannableStringBuilder replace(final int start, final int end, CharSequence tb, int tbstart, int tbend) {
    int filtercount = mFilters.length;
    for (int i = 0; i < filtercount; i++) {
        CharSequence repl = mFilters[i].filter(tb, tbstart, tbend, this, start, end);
        if (repl != null) {
            tb = repl;
            tbstart = 0;
            tbend = repl.length();
        }
    }
    if (end == start && tbstart == tbend) {
        return this;
    }
    if (end == start || tbstart == tbend) {
        change(start, end, tb, tbstart, tbend);
    } else {
        int selstart = Selection.getSelectionStart(this);
        int selend = Selection.getSelectionEnd(this);
        // XXX just make the span fixups in change() do the right thing
        // instead of this madness!
        checkRange("replace", start, end);
        moveGapTo(end);
        TextWatcher[] recipients;
        recipients = sendTextWillChange(start, end - start, tbend - tbstart);
        int origlen = end - start;
        if (mGapLength < 2)
            resizeFor(length() + 1);
        for (int i = mSpanCount - 1; i >= 0; i--) {
            if (mSpanStarts[i] == mGapStart)
                mSpanStarts[i]++;
            if (mSpanEnds[i] == mGapStart)
                mSpanEnds[i]++;
        }
        mText[mGapStart] = ' ';
        mGapStart++;
        mGapLength--;
        if (mGapLength < 1)
            new Exception("mGapLength < 1").printStackTrace();
        int oldlen = (end + 1) - start;
        int inserted = change(false, start + 1, start + 1, tb, tbstart, tbend);
        change(false, start, start + 1, "", 0, 0);
        change(false, start + inserted, start + inserted + oldlen - 1, "", 0, 0);
        /*
             * Special case to keep the cursor in the same position
             * if it was somewhere in the middle of the replaced region.
             * If it was at the start or the end or crossing the whole
             * replacement, it should already be where it belongs.
             * TODO: Is there some more general mechanism that could
             * accomplish this?
             */
        if (selstart > start && selstart < end) {
            long off = selstart - start;
            off = off * inserted / (end - start);
            selstart = (int) off + start;
            setSpan(false, Selection.SELECTION_START, selstart, selstart, Spanned.SPAN_POINT_POINT);
        }
        if (selend > start && selend < end) {
            long off = selend - start;
            off = off * inserted / (end - start);
            selend = (int) off + start;
            setSpan(false, Selection.SELECTION_END, selend, selend, Spanned.SPAN_POINT_POINT);
        }
        sendTextChange(recipients, start, origlen, inserted);
        sendTextHasChanged(recipients);
    }
    return this;
}
Also used : TextWatcher(android.text.TextWatcher) Paint(android.graphics.Paint)

Example 42 with TextWatcher

use of android.text.TextWatcher in project Klyph by jonathangerbaud.

the class FriendPickerActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    singleChoice = getIntent().getBooleanExtra(KlyphBundleExtras.SINGLE_CHOICE, false);
    setTitle(singleChoice ? R.string.friend_picker_single_choice_title : R.string.friend_picker_title);
    setListAdapter(new MultiObjectAdapter(getListView(), singleChoice ? SpecialLayout.FRIEND_PICKER_SINGLE : SpecialLayout.FRIEND_PICKER));
    getListView().setItemsCanFocus(false);
    getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    searchText = (EditText) findViewById(R.id.search_text);
    searchText.addTextChangedListener(new TextWatcher() {

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

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

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    setRequestType(Query.ALL_FRIENDS);
    if (getIntent().hasExtra(KlyphBundleExtras.FRIEND_PICKER_IDS)) {
        ArrayList<String> ids = getIntent().getStringArrayListExtra(KlyphBundleExtras.FRIEND_PICKER_IDS);
        if (ids != null && ids.size() > 0) {
            initialIds = ids;
        }
    }
    if (FRIEND_LIST == null) {
        load();
    } else {
        // reset previously selected objects
        for (GraphObject graphObject : FRIEND_LIST) {
            graphObject.setSelected(false);
        }
        populate(FRIEND_LIST);
    }
}
Also used : MultiObjectAdapter(com.abewy.android.apps.klyph.adapter.MultiObjectAdapter) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Example 43 with TextWatcher

use of android.text.TextWatcher in project UltimateAndroid by cymcsg.

the class CalligraphyUtils method applyFontToTextView.

/**
     * Applies a Typeface to a TextView, its recommend you don't call this multiple times, as this
     * adds a TextWatcher.
     *
     * @param textView Not null, TextView or child of.
     * @param typeface Not null, Typeface to apply to the TextView.
     * @return true if applied otherwise false.
     */
public static boolean applyFontToTextView(final TextView textView, final Typeface typeface) {
    if (textView == null || typeface == null)
        return false;
    textView.setPaintFlags(textView.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    textView.setText(applyTypefaceSpan(textView.getText(), typeface), TextView.BufferType.SPANNABLE);
    textView.addTextChangedListener(new TextWatcher() {

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

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

        @Override
        public void afterTextChanged(Editable s) {
            applyTypefaceSpan(s, typeface);
        }
    });
    return true;
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Paint(android.graphics.Paint)

Example 44 with TextWatcher

use of android.text.TextWatcher in project philm by chrisbanes.

the class FloatLabelLayout method setEditText.

private void setEditText(EditText editText) {
    // If we already have an EditText, throw an exception
    if (mEditText != null) {
        throw new IllegalArgumentException("We already have an EditText, can only have one");
    }
    mEditText = editText;
    // Update the label visibility with no animation
    updateLabelVisibility(false);
    // Add a TextWatcher so that we know when the text input has changed
    mEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            updateLabelVisibility(true);
        }

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
    // Add focus listener to the EditText so that we can notify the label that it is activated.
    // Allows the use of a ColorStateList for the text color on the label
    mEditText.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View view, boolean focused) {
            updateLabelVisibility(true);
        }
    });
    // If we do not have a valid hint, try and retrieve it from the EditText
    if (TextUtils.isEmpty(mHint)) {
        setHint(mEditText.getHint());
    }
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) View(android.view.View)

Example 45 with TextWatcher

use of android.text.TextWatcher in project XobotOS by xamarin.

the class TextView method sendBeforeTextChanged.

private void sendBeforeTextChanged(CharSequence text, int start, int before, int after) {
    if (mListeners != null) {
        final ArrayList<TextWatcher> list = mListeners;
        final int count = list.size();
        for (int i = 0; i < count; i++) {
            list.get(i).beforeTextChanged(text, start, before, after);
        }
    }
    // The spans that are inside or intersect the modified region no longer make sense
    removeIntersectingSpans(start, start + before, SpellCheckSpan.class);
    removeIntersectingSpans(start, start + before, SuggestionSpan.class);
}
Also used : TextWatcher(android.text.TextWatcher) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Aggregations

TextWatcher (android.text.TextWatcher)192 Editable (android.text.Editable)158 View (android.view.View)96 TextView (android.widget.TextView)75 Paint (android.graphics.Paint)37 ImageView (android.widget.ImageView)30 TextPaint (android.text.TextPaint)28 EditText (android.widget.EditText)28 Intent (android.content.Intent)25 KeyEvent (android.view.KeyEvent)24 AdapterView (android.widget.AdapterView)21 ListView (android.widget.ListView)17 RecyclerView (android.support.v7.widget.RecyclerView)15 DialogInterface (android.content.DialogInterface)13 SuppressLint (android.annotation.SuppressLint)12 OnClickListener (android.view.View.OnClickListener)12 Button (android.widget.Button)12 InputMethodManager (android.view.inputmethod.InputMethodManager)11 AlertDialog (android.app.AlertDialog)10 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)9