use of carbon.internal.SimpleTextWatcher in project Carbon by ZieIony.
the class AutoCompleteEditText method initAutoCompleteEditText.
private void initAutoCompleteEditText() {
autoCompleteTextWatcher = new SimpleTextWatcher() {
@Override
public void afterTextChanged(Editable text) {
if (!prevText.equals(text.toString()))
autoComplete();
prevText = text.toString();
}
};
addTextChangedListener(autoCompleteTextWatcher);
setOnEditorActionListener((textView, actionId, keyEvent) -> {
if (actionId == EditorInfo.IME_ACTION_DONE) {
autoCompleting = true;
Editable text = getText();
HintSpan[] spans = text.getSpans(0, length(), HintSpan.class);
if (spans.length > 1) {
throw new IllegalStateException("more than one HintSpan");
}
int cursorPosition = getSelectionStart();
for (HintSpan span : spans) {
if (cursorPosition == text.getSpanStart(span)) {
text.removeSpan(span);
break;
}
}
setSelection(cursorPosition);
AutoCompleteEditText.super.setImeOptions(prevOptions);
autoCompleting = false;
}
return false;
});
}
use of carbon.internal.SimpleTextWatcher in project Carbon by ZieIony.
the class SearchEditText method initSearchEditText.
private void initSearchEditText() {
searchTextWatcher = new SimpleTextWatcher() {
@Override
public void afterTextChanged(Editable text) {
if (!prevText.equals(text.toString()))
search();
prevText = text.toString();
}
};
addTextChangedListener(searchTextWatcher);
}
use of carbon.internal.SimpleTextWatcher in project Carbon by ZieIony.
the class EditText method initEditText.
private void initEditText(AttributeSet attrs, int defStyleAttr) {
if (isInEditMode())
return;
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.EditText, defStyleAttr, R.style.carbon_EditText);
int ap = a.getResourceId(R.styleable.EditText_android_textAppearance, -1);
if (ap != -1)
setTextAppearanceInternal(ap);
for (int i = 0; i < a.getIndexCount(); i++) {
int attr = a.getIndex(i);
if (attr == R.styleable.EditText_carbon_textAllCaps) {
setAllCaps(a.getBoolean(attr, false));
} else if (!isInEditMode() && attr == R.styleable.EditText_carbon_fontPath) {
String path = a.getString(attr);
Typeface typeface = TypefaceUtils.getTypeface(getContext(), path);
setTypeface(typeface);
} else if (attr == R.styleable.EditText_carbon_fontFamily) {
int textStyle = a.getInt(R.styleable.EditText_android_textStyle, 0);
Typeface typeface = TypefaceUtils.getTypeface(getContext(), a.getString(attr), textStyle);
setTypeface(typeface);
}
}
setCursorColor(a.getColor(R.styleable.EditText_carbon_cursorColor, 0));
setPattern(a.getString(R.styleable.EditText_carbon_pattern));
DIVIDER_PADDING = (int) getResources().getDimension(R.dimen.carbon_paddingHalf);
setMatchingView(a.getResourceId(R.styleable.EditText_carbon_matchingView, 0));
setUnderline(a.getBoolean(R.styleable.EditText_carbon_underline, true));
Carbon.initRippleDrawable(this, a, rippleIds);
Carbon.initTint(this, a, tintIds);
Carbon.initElevation(this, a, elevationIds);
Carbon.initAnimations(this, a, animationIds);
Carbon.initTouchMargin(this, a, touchMarginIds);
setCornerRadius(a.getDimension(R.styleable.EditText_carbon_cornerRadius, 0));
Carbon.initHtmlText(this, a, R.styleable.EditText_carbon_htmlText);
a.recycle();
try {
Field mHighlightPaintField = android.widget.TextView.class.getDeclaredField("mHighlightPaint");
mHighlightPaintField.setAccessible(true);
mHighlightPaintField.set(this, new Paint() {
@Override
public void setColor(int color) {
if (getSelectionStart() == getSelectionEnd()) {
super.setColor(cursorColor);
} else {
super.setColor(color);
}
}
});
} catch (Exception e) {
}
int underlineWidth = getResources().getDimensionPixelSize(R.dimen.carbon_1dip);
Bitmap dashPathBitmap = Bitmap.createBitmap(underlineWidth * 4, underlineWidth, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(dashPathBitmap);
paint.setColor(0xffffffff);
paint.setAlpha(255);
c.drawCircle(dashPathBitmap.getHeight() / 2.0f, dashPathBitmap.getHeight() / 2.0f, dashPathBitmap.getHeight() / 2.0f, paint);
dashPathShader = new BitmapShader(dashPathBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
initSelectionHandle();
addTextChangedListener(new SimpleTextWatcher() {
@Override
public void afterTextChanged(Editable editable) {
validateInternalEvent();
}
});
validateInternalEvent();
if (getElevation() > 0)
AnimUtils.setupElevationAnimator(stateAnimator, this);
}
Aggregations