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());
}
}
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;
}
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;
}
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);
}
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) {
}
});
}
}
Aggregations