Search in sources :

Example 6 with TextInputLayout

use of android.support.design.widget.TextInputLayout in project FirebaseUI-Android by firebase.

the class WelcomeBackPasswordPromptTest method testSignInButton_validatesFields.

@Test
public void testSignInButton_validatesFields() {
    WelcomeBackPasswordPrompt welcomeBack = createActivity();
    Button signIn = (Button) welcomeBack.findViewById(R.id.button_done);
    signIn.performClick();
    TextInputLayout passwordLayout = (TextInputLayout) welcomeBack.findViewById(R.id.password_layout);
    assertEquals(welcomeBack.getString(R.string.required_field), passwordLayout.getError().toString());
    // should block and not start a new activity
    ShadowActivity.IntentForResult nextIntent = Shadows.shadowOf(welcomeBack).getNextStartedActivityForResult();
    assertNull(nextIntent);
}
Also used : Button(android.widget.Button) ShadowActivity(org.robolectric.shadows.ShadowActivity) TextInputLayout(android.support.design.widget.TextInputLayout) WelcomeBackPasswordPrompt(com.firebase.ui.auth.ui.accountlink.WelcomeBackPasswordPrompt) Test(org.junit.Test)

Example 7 with TextInputLayout

use of android.support.design.widget.TextInputLayout in project flexbox-layout by google.

the class FlexItemEditFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_flex_item_edit, container, false);
    getDialog().setTitle(String.valueOf(mFlexItem.index + 1));
    final TextInputLayout orderTextInput = (TextInputLayout) view.findViewById(R.id.input_layout_order);
    EditText orderEdit = (EditText) view.findViewById(R.id.edit_text_order);
    orderEdit.setText(String.valueOf(mFlexItem.order));
    orderEdit.addTextChangedListener(new FlexEditTextWatcher(orderTextInput, new IntegerInputValidator(), R.string.must_be_integer));
    final TextInputLayout flexGrowInput = (TextInputLayout) view.findViewById(R.id.input_layout_flex_grow);
    final EditText flexGrowEdit = (EditText) view.findViewById(R.id.edit_text_flex_grow);
    flexGrowEdit.setText(String.valueOf(mFlexItem.flexGrow));
    flexGrowEdit.addTextChangedListener(new FlexEditTextWatcher(flexGrowInput, new NonNegativeDecimalInputValidator(), R.string.must_be_non_negative_float));
    final TextInputLayout flexShrinkInput = (TextInputLayout) view.findViewById(R.id.input_layout_flex_shrink);
    EditText flexShrinkEdit = (EditText) view.findViewById(R.id.edit_text_flex_shrink);
    flexShrinkEdit.setText(String.valueOf(mFlexItem.flexShrink));
    flexShrinkEdit.addTextChangedListener(new FlexEditTextWatcher(flexShrinkInput, new NonNegativeDecimalInputValidator(), R.string.must_be_non_negative_float));
    final TextInputLayout flexBasisPercentInput = (TextInputLayout) view.findViewById(R.id.input_layout_flex_basis_percent);
    EditText flexBasisPercentEdit = (EditText) view.findViewById(R.id.edit_text_flex_basis_percent);
    if (mFlexItem.flexBasisPercent != FlexboxLayout.LayoutParams.FLEX_BASIS_PERCENT_DEFAULT) {
        flexBasisPercentEdit.setText(String.valueOf(Math.round(mFlexItem.flexBasisPercent * 100)));
    } else {
        flexBasisPercentEdit.setText(String.valueOf((int) mFlexItem.flexBasisPercent));
    }
    flexBasisPercentEdit.addTextChangedListener(new FlexEditTextWatcher(flexBasisPercentInput, new FlexBasisPercentInputValidator(), R.string.must_be_minus_one_or_non_negative_integer));
    final TextInputLayout widthInput = (TextInputLayout) view.findViewById(R.id.input_layout_width);
    EditText widthEdit = (EditText) view.findViewById(R.id.edit_text_width);
    widthEdit.setText(String.valueOf(mFlexItem.width));
    widthEdit.addTextChangedListener(new FlexEditTextWatcher(widthInput, new DimensionInputValidator(), R.string.must_be_minus_one_or_minus_two_or_non_negative_integer));
    final TextInputLayout heightInput = (TextInputLayout) view.findViewById(R.id.input_layout_height);
    EditText heightEdit = (EditText) view.findViewById(R.id.edit_text_height);
    heightEdit.setText(String.valueOf(mFlexItem.height));
    heightEdit.addTextChangedListener(new FlexEditTextWatcher(heightInput, new DimensionInputValidator(), R.string.must_be_minus_one_or_minus_two_or_non_negative_integer));
    final TextInputLayout minWidthInput = (TextInputLayout) view.findViewById(R.id.input_layout_min_width);
    EditText minWidthEdit = (EditText) view.findViewById(R.id.edit_text_min_width);
    minWidthEdit.setText(String.valueOf(mFlexItem.minWidth));
    minWidthEdit.addTextChangedListener(new FlexEditTextWatcher(minWidthInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer));
    final TextInputLayout minHeightInput = (TextInputLayout) view.findViewById(R.id.input_layout_min_height);
    EditText minHeightEdit = (EditText) view.findViewById(R.id.edit_text_min_height);
    minHeightEdit.setText(String.valueOf(mFlexItem.minHeight));
    minHeightEdit.addTextChangedListener(new FlexEditTextWatcher(minHeightInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer));
    final TextInputLayout maxWidthInput = (TextInputLayout) view.findViewById(R.id.input_layout_max_width);
    EditText maxWidthEdit = (EditText) view.findViewById(R.id.edit_text_max_width);
    maxWidthEdit.setText(String.valueOf(mFlexItem.maxWidth));
    maxWidthEdit.addTextChangedListener(new FlexEditTextWatcher(maxWidthInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer));
    final TextInputLayout maxHeightInput = (TextInputLayout) view.findViewById(R.id.input_layout_max_height);
    EditText maxHeightEdit = (EditText) view.findViewById(R.id.edit_text_max_height);
    maxHeightEdit.setText(String.valueOf(mFlexItem.maxHeight));
    maxHeightEdit.addTextChangedListener(new FlexEditTextWatcher(maxHeightInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer));
    setNextFocusesOnEnterDown(orderEdit, flexGrowEdit, flexShrinkEdit, flexBasisPercentEdit, widthEdit, heightEdit, minWidthEdit, minHeightEdit, maxWidthEdit, maxHeightEdit);
    Spinner alignSelfSpinner = (Spinner) view.findViewById(R.id.spinner_align_self);
    ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.array_align_self, R.layout.spinner_item);
    alignSelfSpinner.setAdapter(arrayAdapter);
    alignSelfSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selected = parent.getItemAtPosition(position).toString();
            if (selected.equals(ALIGN_SELF_AUTO)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_AUTO;
            } else if (selected.equals(ALIGN_SELF_FLEX_START)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_FLEX_START;
            } else if (selected.equals(ALIGN_SELF_FLEX_END)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_FLEX_END;
            } else if (selected.equals(ALIGN_SELF_CENTER)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_CENTER;
            } else if (selected.equals(ALIGN_SELF_BASELINE)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_BASELINE;
            } else if (selected.equals(ALIGN_SELF_STRETCH)) {
                mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_STRETCH;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        // No op
        }
    });
    CheckBox wrapBeforeCheckBox = (CheckBox) view.findViewById(R.id.checkbox_wrap_before);
    wrapBeforeCheckBox.setChecked(mFlexItem.wrapBefore);
    wrapBeforeCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mFlexItem.wrapBefore = isChecked;
        }
    });
    int alignSelfPosition = arrayAdapter.getPosition(alignSelfAsString(mFlexItem.alignSelf));
    alignSelfSpinner.setSelection(alignSelfPosition);
    view.findViewById(R.id.button_cancel).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    final Button okButton = (Button) view.findViewById(R.id.button_ok);
    okButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (orderTextInput.isErrorEnabled() || flexGrowInput.isErrorEnabled() || flexBasisPercentInput.isErrorEnabled() || widthInput.isErrorEnabled() || heightInput.isErrorEnabled() || minWidthInput.isErrorEnabled() || minHeightInput.isErrorEnabled() || maxWidthInput.isErrorEnabled() || maxHeightInput.isErrorEnabled()) {
                Toast.makeText(getActivity(), R.string.invalid_values_exist, Toast.LENGTH_SHORT).show();
                return;
            }
            if (mFlexItemChangedListener != null) {
                mFlexItemChangedListener.onFlexItemChanged(mFlexItem);
            }
            dismiss();
        }
    });
    return view;
}
Also used : DimensionInputValidator(com.google.android.apps.flexbox.validators.DimensionInputValidator) FixedDimensionInputValidator(com.google.android.apps.flexbox.validators.FixedDimensionInputValidator) FixedDimensionInputValidator(com.google.android.apps.flexbox.validators.FixedDimensionInputValidator) Spinner(android.widget.Spinner) IntegerInputValidator(com.google.android.apps.flexbox.validators.IntegerInputValidator) NonNegativeDecimalInputValidator(com.google.android.apps.flexbox.validators.NonNegativeDecimalInputValidator) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) TextInputLayout(android.support.design.widget.TextInputLayout) EditText(android.widget.EditText) FlexBasisPercentInputValidator(com.google.android.apps.flexbox.validators.FlexBasisPercentInputValidator) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) CheckBox(android.widget.CheckBox) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) Nullable(android.support.annotation.Nullable)

Example 8 with TextInputLayout

use of android.support.design.widget.TextInputLayout in project TourGuide by worker8.

the class AdjustPaddingOverlayActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mActivity = this;
    setContentView(R.layout.activity_overlay_customization);
    final Button button = (Button) findViewById(R.id.button);
    Button next_button = (Button) findViewById(R.id.next_button);
    TextInputLayout textInputLayout = (TextInputLayout) findViewById(R.id.input_layout);
    final EditText paddingET = (EditText) findViewById(R.id.padding_edit_text);
    paddingET.setText(String.valueOf(10));
    textInputLayout.setVisibility(View.VISIBLE);
    next_button.setVisibility(View.GONE);
    final ToolTip toolTip = new ToolTip().setTitle("Hello!").setDescription(String.format("Current OVERLAY Padding: %s", paddingET.getText().toString()));
    final Overlay overlay = new Overlay().setBackgroundColor(Color.parseColor("#AAFF0000")).disableClick(false).disableClickThroughHole(false).setStyle(Overlay.Style.ROUNDED_RECTANGLE).setHolePadding(Integer.valueOf(paddingET.getText().toString())).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mTutorialHandler.cleanUp();
        }
    });
    // the return handler is used to manipulate the cleanup of all the tutorial elements
    mTutorialHandler = TourGuide.init(this).with(TourGuide.Technique.CLICK).setPointer(null).setToolTip(toolTip).setOverlay(overlay).playOn(button);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mTutorialHandler.cleanUp();
            mTutorialHandler.playOn(button);
        }
    });
    button.setText("   show   ");
    paddingET.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) {
            overlay.setHolePadding((charSequence.length() > 0 && TextUtils.isDigitsOnly(charSequence)) ? Integer.valueOf(charSequence.toString()) : 10);
            toolTip.setDescription(String.format("Current Overlay Padding: %s", charSequence));
            mTutorialHandler.setOverlay(overlay);
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
}
Also used : EditText(android.widget.EditText) ToolTip(tourguide.tourguide.ToolTip) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextInputLayout(android.support.design.widget.TextInputLayout) Overlay(tourguide.tourguide.Overlay) View(android.view.View)

Example 9 with TextInputLayout

use of android.support.design.widget.TextInputLayout in project FirebaseUI-Android by firebase.

the class RegisterEmailActivity method onNewUser.

@Override
public void onNewUser(User user) {
    // New user, direct them to create an account with email/password
    // if account creation is enabled in SignInIntentBuilder
    boolean createAccount = mActivityHelper.getFlowParams().allowNewEmailAccounts;
    TextInputLayout mEmailLayout = (TextInputLayout) findViewById(R.id.email_layout);
    if (createAccount) {
        RegisterEmailFragment fragment = RegisterEmailFragment.getInstance(mActivityHelper.getFlowParams(), user);
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction().replace(R.id.fragment_register_email, fragment, RegisterEmailFragment.TAG);
        if (mEmailLayout != null)
            ft.addSharedElement(mEmailLayout, "email_field");
        ft.disallowAddToBackStack().commit();
    } else {
        mEmailLayout.setError(getString(R.string.error_email_does_not_exist));
    }
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) TextInputLayout(android.support.design.widget.TextInputLayout)

Example 10 with TextInputLayout

use of android.support.design.widget.TextInputLayout in project FirebaseUI-Android by firebase.

the class RegisterEmailFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.register_email_layout, container, false);
    mPasswordFieldValidator = new PasswordFieldValidator((TextInputLayout) v.findViewById(R.id.password_layout), getResources().getInteger(R.integer.min_password_length));
    mNameValidator = new RequiredFieldValidator((TextInputLayout) v.findViewById(R.id.name_layout));
    mEmailFieldValidator = new EmailFieldValidator((TextInputLayout) v.findViewById(R.id.email_layout));
    mEmailEditText = (EditText) v.findViewById(R.id.email);
    mNameEditText = (EditText) v.findViewById(R.id.name);
    mPasswordEditText = (EditText) v.findViewById(R.id.password);
    mAgreementText = (TextView) v.findViewById(R.id.create_account_text);
    mEmailInput = (TextInputLayout) v.findViewById(R.id.email_layout);
    mPasswordInput = (TextInputLayout) v.findViewById(R.id.password_layout);
    mEmailEditText.setOnFocusChangeListener(this);
    mNameEditText.setOnFocusChangeListener(this);
    mPasswordEditText.setOnFocusChangeListener(this);
    v.findViewById(R.id.button_create).setOnClickListener(this);
    if (savedInstanceState != null) {
        return v;
    }
    // If email is passed in, fill in the field and move down to the name field.
    String email = mUser.getEmail();
    if (!TextUtils.isEmpty(email)) {
        mEmailEditText.setText(email);
    }
    // If name is passed in, fill in the field and move down to the password field.
    String name = mUser.getName();
    if (!TextUtils.isEmpty(name)) {
        mNameEditText.setText(name);
    }
    // See http://stackoverflow.com/questions/11082341/android-requestfocus-ineffective#comment51774752_11082523
    if (!TextUtils.isEmpty(mNameEditText.getText())) {
        safeRequestFocus(mPasswordEditText);
    } else if (!TextUtils.isEmpty(mEmailEditText.getText())) {
        safeRequestFocus(mNameEditText);
    } else {
        safeRequestFocus(mEmailEditText);
    }
    return v;
}
Also used : EmailFieldValidator(com.firebase.ui.auth.ui.email.fieldvalidators.EmailFieldValidator) PasswordFieldValidator(com.firebase.ui.auth.ui.email.fieldvalidators.PasswordFieldValidator) TextInputLayout(android.support.design.widget.TextInputLayout) View(android.view.View) TextView(android.widget.TextView) RequiredFieldValidator(com.firebase.ui.auth.ui.email.fieldvalidators.RequiredFieldValidator) 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