use of android.support.design.widget.TextInputLayout in project android-design-support-lib-demo by sagar-viradiya.
the class MainActivity method setupDialog.
private void setupDialog() {
dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_layout, null, false);
final TextInputLayout titleInputLayout = (TextInputLayout) dialogView.findViewById(R.id.text_input_title);
final TextInputLayout contentInputLayout = (TextInputLayout) dialogView.findViewById(R.id.text_input_content);
titleInputLayout.setErrorEnabled(true);
contentInputLayout.setErrorEnabled(true);
EditText titleInput = (EditText) dialogView.findViewById(R.id.title_text_input);
EditText contentInput = (EditText) dialogView.findViewById(R.id.content_text_input);
titleInput.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (charSequence == null || charSequence.toString().equals("")) {
titleInputLayout.setError(getString(R.string.edittext_error));
} else {
titleInputLayout.setError(null);
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
contentInput.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (charSequence == null || charSequence.toString().equals("")) {
contentInputLayout.setError(getString(R.string.edittext_error));
} else {
contentInputLayout.setError(null);
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
}
use of android.support.design.widget.TextInputLayout in project android-edittext-validator by vekexasia.
the class DefaultEditTextValidator method showUIError.
@Override
public void showUIError() {
if (mValidator.hasErrorMessage()) {
try {
TextInputLayout parent = (TextInputLayout) editText.getParent();
parent.setErrorEnabled(true);
parent.setError(mValidator.getErrorMessage());
} catch (Throwable e) {
editText.setError(mValidator.getErrorMessage());
}
}
}
use of android.support.design.widget.TextInputLayout in project Shuttle by timusus.
the class ThemeUtils method themeEditText.
public static void themeEditText(EditText editText) {
int accentColor = ColorUtils.getAccentColor();
//Not sure if this check is necessary..
if (editText instanceof AppCompatEditText) {
//Theme the background
((AppCompatEditText) editText).setSupportBackgroundTintList(ColorUtils.createEditTextColorStateList(editText.getContext()));
}
//Theme the cursor & handles
setEditTextDrawablesColor(editText, accentColor);
//If the parent is a TextInputLayout, theme that too
if (editText.getParent() != null && editText.getParent() instanceof TextInputLayout) {
setInputTextLayoutColor((TextInputLayout) editText.getParent(), accentColor);
}
}
use of android.support.design.widget.TextInputLayout in project wire-android by wireapp.
the class VerifyPhoneNumberPreferenceFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final String number = PhoneNumberUtils.formatNumber(getArguments().getString(ARG_PHONE, ""));
final View view = inflater.inflate(R.layout.fragment_preference_phone_number_verification, container, false);
final TextInputLayout verificationCodeInputLayout = ViewUtils.getView(view, R.id.til__verification_code);
verificationCodeInputLayout.setErrorEnabled(true);
final View backButton = ViewUtils.getView(view, R.id.tv__back_button);
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
final View okButton = ViewUtils.getView(view, R.id.tv__ok_button);
okButton.setEnabled(false);
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String code = getVerificationCode();
getStoreFactory().getProfileStore().submitCode(number, code, new ZMessagingApi.PhoneNumberVerificationListener() {
@Override
public void onVerified(KindOfVerification kindOfVerification) {
dismiss();
}
@Override
public void onVerificationFailed(KindOfVerification kindOfVerification, int errorCode, String message, String label) {
if (AppEntryError.PHONE_INVALID_REGISTRATION_CODE.correspondsTo(errorCode, label)) {
verificationCodeInputLayout.setError(getString(AppEntryError.PHONE_INVALID_REGISTRATION_CODE.headerResource));
} else {
verificationCodeInputLayout.setError(getString(AppEntryError.PHONE_REGISTER_GENERIC_ERROR.headerResource));
}
}
});
}
});
final TextView changeNumberButton = ViewUtils.getView(view, R.id.tv__change_number_button);
changeNumberButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getContainer() == null) {
return;
}
dismiss();
getContainer().changePhoneNumber(number);
}
});
final TextView resendButton = ViewUtils.getView(view, R.id.tv__resend_button);
resendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
resendButton.animate().alpha(0f).start();
getStoreFactory().getProfileStore().resendPhoneVerificationCode(number, new ZMessagingApi.PhoneConfirmationCodeRequestListener() {
@Override
public void onConfirmationCodeSent(KindOfAccess kindOfAccess) {
resendButton.animate().alpha(1f).start();
}
@Override
public void onPasswordExists(KindOfAccess kindOfAccess) {
}
@Override
public void onConfirmationCodeSendingFailed(KindOfAccess kindOfAccess, int code, String message, String label) {
resendButton.animate().alpha(1f).start();
AppEntryUtil.showErrorDialog(getActivity(), AppEntryError.PHONE_REGISTER_GENERIC_ERROR, null);
}
});
}
});
final TextView verificationDescription = ViewUtils.getView(view, R.id.tv__verification_description);
verificationDescription.setText(getString(R.string.pref__account_action__phone_verification__description, number));
final EditText firstNumberEditText = ViewUtils.getView(view, R.id.et__verification_code__1);
final EditText secondNumberEditText = ViewUtils.getView(view, R.id.et__verification_code__2);
final EditText thirdNumberEditText = ViewUtils.getView(view, R.id.et__verification_code__3);
final EditText fourthNumberEditText = ViewUtils.getView(view, R.id.et__verification_code__4);
final EditText fifthNumberEditText = ViewUtils.getView(view, R.id.et__verification_code__5);
final EditText sixthNumberEditText = ViewUtils.getView(view, R.id.et__verification_code__6);
textBoxes = new LinkedList<>(Arrays.asList(firstNumberEditText, secondNumberEditText, thirdNumberEditText, fourthNumberEditText, fifthNumberEditText, sixthNumberEditText));
for (int i = 0; i < textBoxes.size(); i++) {
final EditText textBox = textBoxes.get(i);
final int finalI = i;
textBox.setTypeface(TypefaceUtils.getTypeface(getString(R.string.wire__typeface__bold)));
textBox.addTextChangedListener(new OnTextChangedListener() {
@Override
public void afterTextChanged(Editable s) {
final String val = textBox.getText().toString().trim();
final char c;
if (TextUtils.isEmpty(val)) {
c = ' ';
} else {
c = val.charAt(0);
}
verificationCode[finalI] = c;
final boolean wasDelete = c == ' ';
if (!jumpToNextEmptyTextBox(wasDelete)) {
okButton.setEnabled(true);
if (finalI == textBoxes.size()) {
okButton.requestFocus();
}
} else {
okButton.setEnabled(false);
}
}
});
}
return view;
}
Aggregations