Search in sources :

Example 16 with TextInputLayout

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) {
        }
    });
}
Also used : EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextInputLayout(android.support.design.widget.TextInputLayout)

Example 17 with TextInputLayout

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());
        }
    }
}
Also used : TextInputLayout(android.support.design.widget.TextInputLayout)

Example 18 with TextInputLayout

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);
    }
}
Also used : AppCompatEditText(android.support.v7.widget.AppCompatEditText) TextInputLayout(android.support.design.widget.TextInputLayout) SuppressLint(android.annotation.SuppressLint)

Example 19 with TextInputLayout

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;
}
Also used : EditText(android.widget.EditText) OnTextChangedListener(com.waz.zclient.pages.main.profile.views.OnTextChangedListener) KindOfVerification(com.waz.api.KindOfVerification) KindOfAccess(com.waz.api.KindOfAccess) View(android.view.View) TextView(android.widget.TextView) Editable(android.text.Editable) TextView(android.widget.TextView) TextInputLayout(android.support.design.widget.TextInputLayout) Nullable(android.support.annotation.Nullable)

Aggregations

TextInputLayout (android.support.design.widget.TextInputLayout)19 View (android.view.View)12 UiController (android.support.test.espresso.UiController)7 ViewAction (android.support.test.espresso.ViewAction)7 EditText (android.widget.EditText)5 Button (android.widget.Button)4 TextView (android.widget.TextView)4 Nullable (android.support.annotation.Nullable)3 Editable (android.text.Editable)3 TextWatcher (android.text.TextWatcher)2 EmailFieldValidator (com.firebase.ui.auth.ui.email.fieldvalidators.EmailFieldValidator)2 Test (org.junit.Test)2 SuppressLint (android.annotation.SuppressLint)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 AppCompatEditText (android.support.v7.widget.AppCompatEditText)1 AdapterView (android.widget.AdapterView)1 CheckBox (android.widget.CheckBox)1 CompoundButton (android.widget.CompoundButton)1 Spinner (android.widget.Spinner)1 WelcomeBackPasswordPrompt (com.firebase.ui.auth.ui.accountlink.WelcomeBackPasswordPrompt)1