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

The following examples show how to use com.google.android.material.textfield.TextInputLayout#setError() . 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: HostsActivity.java    From MHViewer with Apache License 2.0 7 votes vote down vote up
protected void put(AlertDialog dialog) {
  TextView host = dialog.findViewById(R.id.host);
  TextView ip = dialog.findViewById(R.id.ip);
  String hostString = host.getText().toString().trim().toLowerCase(Locale.US);
  String ipString = ip.getText().toString().trim();

  if (!Hosts.isValidHost(hostString)) {
    TextInputLayout hostInputLayout = dialog.findViewById(R.id.host_input_layout);
    hostInputLayout.setError(getContext().getString(R.string.invalid_host));
    return;
  }

  if (!Hosts.isValidIp(ipString)) {
    TextInputLayout ipInputLayout = dialog.findViewById(R.id.ip_input_layout);
    ipInputLayout.setError(getContext().getString(R.string.invalid_ip));
    return;
  }

  HostsActivity activity = (HostsActivity) dialog.getOwnerActivity();
  activity.hosts.put(hostString, ipString);
  activity.notifyHostsChanges();

  dialog.dismiss();
}
 
Example 2
Source File: TextInputLayoutActions.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
public static ViewAction setError(final CharSequence errorText) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Sets the error";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setError(errorText);
    }
  };
}
 
Example 3
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 4
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 5
Source File: HostsActivity.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
protected void put(AlertDialog dialog) {
  TextView host = dialog.findViewById(R.id.host);
  TextView ip = dialog.findViewById(R.id.ip);
  String hostString = host.getText().toString().trim().toLowerCase(Locale.US);
  String ipString = ip.getText().toString().trim();

  if (!Hosts.isValidHost(hostString)) {
    TextInputLayout hostInputLayout = dialog.findViewById(R.id.host_input_layout);
    hostInputLayout.setError(getContext().getString(R.string.invalid_host));
    return;
  }

  if (!Hosts.isValidIp(ipString)) {
    TextInputLayout ipInputLayout = dialog.findViewById(R.id.ip_input_layout);
    ipInputLayout.setError(getContext().getString(R.string.invalid_ip));
    return;
  }

  HostsActivity activity = (HostsActivity) dialog.getOwnerActivity();
  activity.hosts.put(hostString, ipString);
  activity.notifyHostsChanges();

  dialog.dismiss();
}
 
Example 6
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 7
Source File: RangeDateSelector.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void clearInvalidRange(@NonNull TextInputLayout start, @NonNull TextInputLayout end) {
  if (start.getError() != null && invalidRangeStartError.contentEquals(start.getError())) {
    start.setError(null);
  }
  if (end.getError() != null && invalidRangeEndError.contentEquals(end.getError())) {
    end.setError(null);
  }
}
 
Example 8
Source File: TextFieldControllableDemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private boolean checkTextInputIsNull(TextInputLayout textInputLayout) {
  if (textInputLayout.getEditText().getText() == null
      || textInputLayout.getEditText().length() == 0) {
    textInputLayout.setError(
        getResources().getString(R.string.cat_textfield_null_input_error_text));
    return true;
  }
  textInputLayout.setError(null);
  return false;
}
 
Example 9
Source File: TextFieldControllableDemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void setAllTextFieldsError(String error) {
  ViewGroup parent = (ViewGroup) textfields.get(0).getParent();
  boolean textfieldWithErrorHasFocus = false;
  for (TextInputLayout textfield : textfields) {
    setErrorIconClickListeners(textfield);
    textfield.setError(error);
    textfieldWithErrorHasFocus |= textfield.hasFocus();
  }
  if (!textfieldWithErrorHasFocus) {
    // Request accessibility focus on the first text field to show an error.
    parent.getChildAt(0).requestFocus();
  }
}
 
Example 10
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 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: 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 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);
    }
}
 
Example 14
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 15
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 16
Source File: PasswordValidator.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
private void setError(
        @Nullable TextInputLayout textInputLayout,
        @NonNull EditText editText,
        String error
) {
   if (textInputLayout != null) {
      textInputLayout.setError(error);
   } else {
      editText.setError(error);
   }
}
 
Example 17
Source File: BugReportActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
private void removeError(TextInputLayout editTextLayout) {
    editTextLayout.setError(null);
}
 
Example 18
Source File: ContainerTransformConfigurationHelper.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private static void setTextInputLayoutError(TextInputLayout layout) {
  layout.setError(" ");
}
 
Example 19
Source File: RangeDateSelector.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private void setInvalidRange(@NonNull TextInputLayout start, @NonNull TextInputLayout end) {
  start.setError(invalidRangeStartError);
  end.setError(invalidRangeEndError);
}
 
Example 20
Source File: BugReportActivity.java    From Phonograph with GNU General Public License v3.0 4 votes vote down vote up
private void removeError(TextInputLayout editTextLayout) {
    editTextLayout.setError(null);
}