Search in sources :

Example 1 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 2 with TextWatcher

use of android.text.TextWatcher in project Calligraphy by chrisjenx.

the class CalligraphyUtils method applyFontToTextView.

/**
     * Applies a Typeface to a TextView, if deferred,its recommend you don't call this multiple
     * times, as this adds a TextWatcher.
     *
     * Deferring should really only be used on tricky views which get Typeface set by the system at
     * weird times.
     *
     * @param textView Not null, TextView or child of.
     * @param typeface Not null, Typeface to apply to the TextView.
     * @param deferred If true we use Typefaces and TextChange listener to make sure font is always
     *                 applied, but this sometimes conflicts with other
     *                 {@link android.text.Spannable}'s.
     * @return true if applied otherwise false.
     * @see #applyFontToTextView(android.widget.TextView, android.graphics.Typeface)
     */
public static boolean applyFontToTextView(final TextView textView, final Typeface typeface, boolean deferred) {
    if (textView == null || typeface == null)
        return false;
    textView.setPaintFlags(textView.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
    textView.setTypeface(typeface);
    if (deferred) {
        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 3 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 4 with TextWatcher

use of android.text.TextWatcher in project android_frameworks_base by ParanoidAndroid.

the class TextView method sendOnTextChanged.

/**
     * Not private so it can be called from an inner class without going
     * through a thunk.
     */
void sendOnTextChanged(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).onTextChanged(text, start, before, after);
        }
    }
    if (mEditor != null)
        mEditor.sendOnTextChanged(start, after);
}
Also used : TextWatcher(android.text.TextWatcher) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 5 with TextWatcher

use of android.text.TextWatcher in project Anki-Android by Ramblurr.

the class CardEditor method initFieldEditText.

private void initFieldEditText(FieldEditText editText, int index, String[] values, Typeface customTypeface) {
    String name = values[0];
    String content = values[1];
    if (mPrefFixArabic) {
        content = ArabicUtilities.reshapeSentence(content);
    }
    editText.init(index, name, content);
    if (customTypeface != null) {
        editText.setTypeface(customTypeface);
    }
    if (index == 0) {
        editText.addTextChangedListener(new TextWatcher() {

            @Override
            public void afterTextChanged(Editable arg0) {
                mTimerHandler.removeCallbacks(checkDuplicatesRunnable);
                mTimerHandler.postDelayed(checkDuplicatesRunnable, WAIT_TIME_UNTIL_UPDATE);
            }

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

            @Override
            public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            }
        });
    }
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable)

Aggregations

TextWatcher (android.text.TextWatcher)177 Editable (android.text.Editable)143 View (android.view.View)86 TextView (android.widget.TextView)67 Paint (android.graphics.Paint)37 TextPaint (android.text.TextPaint)28 ImageView (android.widget.ImageView)27 EditText (android.widget.EditText)26 Intent (android.content.Intent)24 KeyEvent (android.view.KeyEvent)21 AdapterView (android.widget.AdapterView)18 ListView (android.widget.ListView)15 DialogInterface (android.content.DialogInterface)12 Button (android.widget.Button)12 RecyclerView (android.support.v7.widget.RecyclerView)11 AlertDialog (android.app.AlertDialog)10 OnClickListener (android.view.View.OnClickListener)10 InputMethodManager (android.view.inputmethod.InputMethodManager)10 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)9 SuppressLint (android.annotation.SuppressLint)8