Java Code Examples for com.google.android.material.textfield.TextInputLayout

The following examples show how to use com.google.android.material.textfield.TextInputLayout. These examples are extracted from open source projects. 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 Project: candybar   Source File: ReportBugsHelper.java    License: Apache License 2.0 6 votes vote down vote up
public static void prepareReportBugs(@NonNull Context context) {
    MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
    builder.customView(R.layout.dialog_report_bugs, true);
    builder.typeface(
            TypefaceHelper.getMedium(context),
            TypefaceHelper.getRegular(context));
    builder.positiveText(R.string.report_bugs_send);
    builder.negativeText(R.string.close);

    MaterialDialog dialog = builder.build();

    EditText editText = (EditText) dialog.findViewById(R.id.input_desc);
    TextInputLayout inputLayout = (TextInputLayout) dialog.findViewById(R.id.input_layout);

    dialog.getActionButton(DialogAction.POSITIVE).setOnClickListener(view -> {
        if (editText.getText().length() > 0) {
            inputLayout.setErrorEnabled(false);
            ReportBugsTask.start(context, editText.getText().toString(), AsyncTask.THREAD_POOL_EXECUTOR);
            dialog.dismiss();
            return;
        }

        inputLayout.setError(context.getResources().getString(R.string.report_bugs_desc_empty));
    });
    dialog.show();
}
 
Example 2
Source Project: arcusandroid   Source File: PasswordValidator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *
 * Create a password validator that checks for passwords matching requirements.
 * This will also post the appropriate Error Messages to {@link #firstPass}
 *
 * @param context Context used to get resources.
 * @param firstPass First Password box (Where errors are appended)
 * @param secondPass Second Password box
 * @param emailAddress Input email address
 */
public PasswordValidator(
        Context context,
        @Nullable TextInputLayout firstPassLayout,
        EditText firstPass,
        @Nullable TextInputLayout secondPassLayout,
        EditText secondPass,
        String emailAddress
) {
   this.context = context;
   this.firstPassLayout = firstPassLayout;
   this.firstPass = firstPass;
   this.secondPassLayout = secondPassLayout;
   this.secondPass = secondPass;
   this.emailAddress = emailAddress;
}
 
Example 3
public static ViewAction setStartIconOnLongClickListener(
    final OnLongClickListener onLongClickListener) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Set a long click listener for the start icon";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setStartIconOnLongClickListener(onLongClickListener);
    }
  };
}
 
Example 4
Source Project: MHViewer   Source File: HostsActivity.java    License: 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 5
public static ViewAction setErrorIconOnClickListener(final OnClickListener onClickListener) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Set error icon OnClickListener";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setErrorIconOnClickListener(onClickListener);
    }
  };
}
 
Example 6
public static ViewAction setHelperText(final CharSequence helperText) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

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

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setHelperText(helperText);
    }
  };
}
 
Example 7
public static ViewAction setBoxBackgroundColor(@ColorInt final int backgroundColor) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Sets the box's background color";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setBoxBackgroundColor(backgroundColor);
    }
  };
}
 
Example 8
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    final InputConnection ic = super.onCreateInputConnection(outAttrs);
    if (ic != null) {
        if (outAttrs.hintText == null) {
            // If we don't have a hint and our parent is a TextInputLayout, use it's hint for the
            // EditorInfo. This allows us to display a hint in 'extract mode'.
            final ViewParent parent = getParent();
            if (parent instanceof TextInputLayout) {
                outAttrs.hintText = ((TextInputLayout) parent).getHint();
            }
        }
        outAttrs.imeOptions = outAttrs.imeOptions | EditorInfo.IME_FLAG_NO_FULLSCREEN;
    }
    return ic;
}
 
Example 9
/** Long clicks end or start icon. */
public static ViewAction longClickIcon(final boolean isEndIcon) {
  return new ViewAction() {

    @Override
    public Matcher<View> getConstraints() {
      return ViewMatchers.isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Long clicks the end or start icon";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout item = (TextInputLayout) view;
      // Reach in and find the icon view since we don't have a public API to get a reference to it
      CheckableImageButton iconView =
          item.findViewById(isEndIcon ? R.id.text_input_end_icon : R.id.text_input_start_icon);
      iconView.performLongClick();
    }
  };
}
 
Example 10
Source Project: Aria2App   Source File: EditProfileActivity.java    License: 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 11
public static ViewAction setHint(final String hint) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Sets the hint/label text";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setHint(hint);
    }
  };
}
 
Example 12
Source Project: dynamic-support   Source File: DynamicInputUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tint the {@link TextInputLayout} by changing its label and focus colors according to the
 * supplied color.
 *
 * @param textInputLayout The text input layout to be colorized.
 * @param color The color to be used.
 */
public static void setColor(@NonNull TextInputLayout textInputLayout, @ColorInt int color) {
    try {
        Field fFocusedTextColor = TextInputLayout.class.getDeclaredField("focusedTextColor");
        fFocusedTextColor.setAccessible(true);
        fFocusedTextColor.set(textInputLayout, ColorStateList.valueOf(color));
        Method mUpdateLabelState = TextInputLayout.class.getDeclaredMethod(
                "updateLabelState", boolean.class, boolean.class);
        mUpdateLabelState.setAccessible(true);
        mUpdateLabelState.invoke(textInputLayout, false, true);
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (textInputLayout.getEditText() != null) {
        setColor(textInputLayout.getEditText(), textInputLayout.getBoxBackgroundColor(), color);
        textInputLayout.setHintTextColor(textInputLayout.getEditText().getHintTextColors());
    }
}
 
Example 13
Source Project: dynamic-support   Source File: DynamicTextInputEditText.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setColor() {
    if (mColor != WidgetDefaults.ADS_COLOR_UNKNOWN) {
        if (isBackgroundAware() && mContrastWithColor != WidgetDefaults.ADS_COLOR_UNKNOWN) {
            mColor = DynamicColorUtils.getContrastColor(mColor, mContrastWithColor);
        }

        post(new Runnable() {
            @Override
            public void run() {
                TextInputLayout parent = getParentTextInputLayout();

                if (parent != null) {
                    DynamicInputUtils.setColor(DynamicTextInputEditText.this,
                            parent.getBoxBackgroundColor(), mColor);
                }
            }
        });
    }
}
 
Example 14
public static ViewAction setStartIconOnClickListener(final OnClickListener onClickListener) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Set a click listener for the start icon";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setStartIconOnClickListener(onClickListener);
    }
  };
}
 
Example 15
public static ViewAction setEndIconMode(final int endIconMode) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Set end icon mode";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setEndIconMode(endIconMode);
    }
  };
}
 
Example 16
public static ViewAction setCounterEnabled(final boolean enabled) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

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

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setCounterEnabled(enabled);
    }
  };
}
 
Example 17
public static ViewAction setTypeface(final Typeface typeface) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

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

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setTypeface(typeface);
    }
  };
}
 
Example 18
public static ViewAction setStartIconContentDescription(final CharSequence contentDesc) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Set a content description for the start icon";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setStartIconContentDescription(contentDesc);
    }
  };
}
 
Example 19
public static ViewAction setHelperTextTextAppearance(final int resId) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Sets the helper text appearance";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setHelperTextTextAppearance(resId);
    }
  };
}
 
Example 20
Source Project: science-journal   Source File: TextLabelDetailsFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(
    LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
  setHasOptionsMenu(true);
  noteTextLayout =
      (TextInputLayout) inflater.inflate(R.layout.text_label_details_fragment, container, false);
  noteText = noteTextLayout.findViewById(R.id.note_text);
  noteText.setText(originalLabel.getTextLabelValue().getText());
  noteText.post(() -> noteText.setSelection(noteText.getText().toString().length()));

  RxTextView.afterTextChangeEvents(noteText)
      .subscribe(
          events -> {
            verifyInput(noteText.getText().toString());
          });

  // TODO: Transition

  return noteTextLayout;
}
 
Example 21
public static ViewAction setCustomEndIconContent() {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Set custom end icon content";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setEndIconDrawable(new ColorDrawable(Color.BLUE));
      layout.setEndIconContentDescription(R.string.textinput_custom_end_icon);
    }
  };
}
 
Example 22
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 23
@Test
public void textInputFormatError() {
  View root =
      rangeDateSelector.onCreateTextInputView(
          LayoutInflater.from(context),
          null,
          null,
          new CalendarConstraints.Builder().build(),
          new OnSelectionChangedListener<Pair<Long, Long>>() {
            @Override
            public void onSelectionChanged(Pair<Long, Long> selection) {}
          });
  TextInputLayout startTextInput = root.findViewById(R.id.mtrl_picker_text_input_range_start);
  TextInputLayout endTextInput = root.findViewById(R.id.mtrl_picker_text_input_range_end);

  startTextInput.getEditText().setText("22/22/2010", BufferType.EDITABLE);
  endTextInput.getEditText().setText("555-555-5555", BufferType.EDITABLE);

  assertThat(startTextInput.getError(), notNullValue());
  assertThat(endTextInput.getError(), notNullValue());
}
 
Example 24
/** Clicks end or start icon. */
public static ViewAction clickIcon(final boolean isEndIcon) {
  return new ViewAction() {

    @Override
    public Matcher<View> getConstraints() {
      return ViewMatchers.isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Clicks the end or start icon";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout item = (TextInputLayout) view;
      // Reach in and find the icon view since we don't have a public API to get a reference to it
      CheckableImageButton iconView =
          item.findViewById(isEndIcon ? R.id.text_input_end_icon : R.id.text_input_start_icon);
      iconView.performClick();
    }
  };
}
 
Example 25
public static ViewAction setEndIconOnClickListener(final OnClickListener onClickListener) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Set end icon OnClickListener";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setEndIconOnClickListener(onClickListener);
    }
  };
}
 
Example 26
/**
 * Sets the text field's stroke width.
 *
 * @param strokeWidth the value to use for the text field box's stroke
 * @return the action of setting the box stroke width on a {@link TextInputLayout}
 */
public static ViewAction setBoxStrokeWidth(final int strokeWidth) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Sets the box's stroke width.";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setBoxStrokeWidth(strokeWidth);
    }
  };
}
 
Example 27
/**
 * Returns a matcher that matches TextInputLayouts with non-empty content descriptions for the
 * end icon.
 */
public static Matcher<View> endIconHasContentDescription() {
  return new TypeSafeMatcher<View>(TextInputLayout.class) {
    @Override
    public void describeTo(Description description) {
      description.appendText(
          "TextInputLayout has non-empty content description" + "for end icon.");
    }

    @Override
    protected boolean matchesSafely(View view) {
      TextInputLayout item = (TextInputLayout) view;
      // Reach in and find the end icon since we don't have a public API to get a reference to it
      View endIcon = item.findViewById(R.id.text_input_end_icon);
      return !TextUtils.isEmpty(item.getEndIconContentDescription())
          && !TextUtils.isEmpty(endIcon.getContentDescription());
    }
  };
}
 
Example 28
/** Returns a matcher that matches TextInputLayouts with non-displayed end icons. */
public static Matcher<View> doesNotShowEndIcon() {
  return new TypeSafeMatcher<View>(TextInputLayout.class) {
    @Override
    public void describeTo(Description description) {
      description.appendText("TextInputLayout doesn't show end icon.");
    }

    @Override
    protected boolean matchesSafely(View item) {
      // Reach in and find the end icon since we don't have a public API
      // to get a reference to it
      View endIcon = item.findViewById(R.id.text_input_end_icon);
      return endIcon.getVisibility() != View.VISIBLE;
    }
  };
}
 
Example 29
/** Sets the transformation method. */
public static ViewAction setTransformationMethod(
    final TransformationMethod transformationMethod) {
  return new ViewAction() {

    @Override
    public Matcher<View> getConstraints() {
      return ViewMatchers.isAssignableFrom(TextInputLayout.class);
    }

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

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout item = (TextInputLayout) view;
      item.getEditText().setTransformationMethod(transformationMethod);
    }
  };
}
 
Example 30
/** Returns a matcher that matches TextInputLayouts with checked end icons. */
public static Matcher<View> endIconIsChecked() {
  return new TypeSafeMatcher<View>(TextInputLayout.class) {
    @Override
    public void describeTo(Description description) {
      description.appendText("TextInputLayout's end icon is checked.");
    }

    @Override
    protected boolean matchesSafely(View item) {
      // Reach in and find the start icon since we don't have a public API
      // to get a reference to it
      CheckableImageButton endIcon = item.findViewById(R.id.text_input_end_icon);
      return endIcon.isChecked();
    }
  };
}