Java Code Examples for com.google.android.material.textfield.TextInputLayout#setErrorEnabled()

The following examples show how to use com.google.android.material.textfield.TextInputLayout#setErrorEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditProfileActivity.java    From Aria2App with GNU General Public License v3.0 6 votes vote down vote up
private void handleInvalidFieldException(@NonNull InvalidFieldException ex) {
    if (ex.where == Where.ACTIVITY) {
        TextInputLayout field = findViewById(ex.fieldId);
        field.clearFocus();
        field.setErrorEnabled(true);
        field.setError(getString(ex.reasonRes));
        return;
    }

    if (ex.pos == -1) return;
    showConditionAt(ex.pos);

    FieldErrorFragmentWithState fragment = (FieldErrorFragmentWithState) pagerAdapter.get(ex.where);
    pager.setCurrentItem(ex.where.pagerPos(), true);
    fragment.onFieldError(ex.fieldId, getString(ex.reasonRes));
}
 
Example 2
Source File: TextInputLayoutActions.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
public static ViewAction setErrorEnabled(final boolean enabled) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Enables/disables the error";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setErrorEnabled(enabled);
    }
  };
}
 
Example 3
Source File: AddCameraActivity.java    From evercam-android with GNU Affero General Public License v3.0 6 votes vote down vote up
private void populateDefaultAuth() {
    if (mSelectedModel != null) {
        String defaultUsername = mSelectedModel.getDefaultUsername();
        String defaultPassword = mSelectedModel.getDefaultPassword();

        TextInputLayout usernameInputLayout = (TextInputLayout) findViewById(R.id.input_layout_cam_username);
        TextInputLayout passwordInputLayout = (TextInputLayout) findViewById(R.id.input_layout_cam_password);
        usernameInputLayout.setErrorEnabled(true);
        passwordInputLayout.setErrorEnabled(true);

        if (!defaultUsername.isEmpty()) {
            usernameInputLayout.setError(getString(R.string.default_colon) + defaultUsername);
        } else {
            usernameInputLayout.setErrorEnabled(false);
        }
        if (!defaultPassword.isEmpty()) {
            passwordInputLayout.setError(getString(R.string.default_colon) + defaultPassword);
        } else {
            passwordInputLayout.setErrorEnabled(false);
        }
    }
}
 
Example 4
Source File: AuthenticationFragment.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onFieldError(@IdRes int fieldId, String reason) {
    TextInputLayout inputLayout = layout.findViewById(fieldId);
    if (inputLayout != null) {
        inputLayout.setErrorEnabled(true);
        inputLayout.setError(reason);
    }
}
 
Example 5
Source File: DirectDownloadFragment.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onFieldError(@IdRes int fieldId, String reason) {
    TextInputLayout inputLayout = layout.findViewById(fieldId);
    if (inputLayout != null) {
        inputLayout.setErrorEnabled(true);
        inputLayout.setError(reason);
    }
}
 
Example 6
Source File: ConnectionFragment.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onFieldError(@IdRes int fieldId, String reason) {
    if (layout == null) return;

    TextInputLayout inputLayout = layout.findViewById(fieldId);
    if (inputLayout != null) {
        inputLayout.setErrorEnabled(true);
        inputLayout.setError(reason);
    }
}
 
Example 7
Source File: EditTexts.java    From convalida with Apache License 2.0 5 votes vote down vote up
public static void setError(EditText editText, @NonNull String errorMessage) {
    TextInputLayout layout = getTextInputLayout(editText);

    if (layout != null) {
        CharSequence error = layout.getError();

        if(error == null || !error.toString().equals(errorMessage)) {
            layout.setErrorEnabled(true);
            layout.setError(errorMessage);
        }
    } else {
        editText.setError(errorMessage);
    }
}
 
Example 8
Source File: EditTexts.java    From convalida with Apache License 2.0 5 votes vote down vote up
public static void removeError(EditText editText) {
    TextInputLayout layout = getTextInputLayout(editText);

    if (layout != null) {
        layout.setErrorEnabled(false);
        layout.setError(null);
    } else {
        editText.setError(null);
    }
}
 
Example 9
Source File: EditTextHandler.java    From data-binding-validator with Apache License 2.0 5 votes vote down vote up
public static void setError(TextView textView, String errorMessage) {
    TextInputLayout textInputLayout = getTextInputLayout(textView);
    if (textInputLayout != null) {
        textInputLayout.setErrorEnabled(!TextUtils.isEmpty(errorMessage));
        textInputLayout.setError(errorMessage);
    } else {
        textView.setError(errorMessage);
    }
}
 
Example 10
Source File: ValidationHelper.java    From MagicForm with Apache License 2.0 5 votes vote down vote up
private static void cleanError(EditText editText)
{
	TextInputLayout textInputLayout = getTextInputLayout(editText);

	if (textInputLayout != null)
	{
		textInputLayout.setError(null);
		textInputLayout.setErrorEnabled(false);
	}
	else
	{
		editText.setError(null);
	}
}
 
Example 11
Source File: ValidationHelper.java    From MagicForm with Apache License 2.0 5 votes vote down vote up
private static void setError(EditText editText, String error)
{
	TextInputLayout textInputLayout = getTextInputLayout(editText);

	if (textInputLayout != null)
	{
		textInputLayout.setErrorEnabled(true);
		textInputLayout.setError(error);
	}
	else
	{
		editText.setError(error);
	}
}
 
Example 12
Source File: CreatePlaylistDialogFragment.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private void onCreateDialogLayout(@Nullable String restoredName) {
    mInputLayout = new TextInputLayout(getContext());
    mEditText = new AppCompatEditText(getContext());

    mEditText.setInputType(InputType.TYPE_CLASS_TEXT);
    mEditText.setHint(R.string.hint_playlist_name);
    mEditText.setText(restoredName);

    mInputLayout.addView(mEditText);
    mInputLayout.setErrorEnabled(true);

    mEditText.addTextChangedListener(this);
}
 
Example 13
Source File: ErrorEditText.java    From android-card-form with MIT License 5 votes vote down vote up
/**
 * Controls the error state of this {@link ErrorEditText} and sets a visual indication that the
 * {@link ErrorEditText} contains an error.
 *
 * @param errorMessage the error message to display to the user. {@code null} will remove any error message displayed.
 */
public void setError(@Nullable String errorMessage) {
    mError = !TextUtils.isEmpty(errorMessage);

    TextInputLayout textInputLayout = getTextInputLayoutParent();
    if (textInputLayout != null) {
        textInputLayout.setErrorEnabled(!TextUtils.isEmpty(errorMessage));
        textInputLayout.setError(errorMessage);
    }

    if (mErrorAnimator != null && mError) {
        startAnimation(mErrorAnimator);
        VibrationHelper.vibrate(getContext(), 10);
    }
}