Skip to content

Commit

Permalink
[TextInputLayout] Fix IndexOutOfBoundsException when trying to change…
Browse files Browse the repository at this point in the history
… end icon

Resolves #1788
Resolves #1724
Resolves #1748

PiperOrigin-RevId: 345541684
(cherry picked from commit dd0e697)
  • Loading branch information
amrkhalil22 authored and dsn5ft committed Dec 15, 2020
1 parent 291486c commit 963ad14
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ public void onEditTextAttached(@NonNull TextInputLayout textInputLayout) {
new OnEndIconChangedListener() {
@Override
public void onEndIconChanged(@NonNull TextInputLayout textInputLayout, int previousIcon) {
EditText editText = textInputLayout.getEditText();
final EditText editText = textInputLayout.getEditText();
if (editText != null && previousIcon == TextInputLayout.END_ICON_CLEAR_TEXT) {
// Remove any listeners set on the edit text.
editText.removeTextChangedListener(clearTextEndIconTextWatcher);
editText.post(
new Runnable() {
@Override
public void run() {
editText.removeTextChangedListener(clearTextEndIconTextWatcher);
}
});
if (editText.getOnFocusChangeListener() == onFocusChangeListener) {
editText.setOnFocusChangeListener(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,24 @@ public void onEditTextAttached(@NonNull TextInputLayout textInputLayout) {
textInputLayout.setEndIconVisible(true);
}
};

@SuppressLint("ClickableViewAccessibility") // There's an accessibility delegate that handles
// interactions with the dropdown menu.
private final OnEndIconChangedListener endIconChangedListener =
new OnEndIconChangedListener() {
@Override
public void onEndIconChanged(@NonNull TextInputLayout textInputLayout, int previousIcon) {
AutoCompleteTextView editText = (AutoCompleteTextView) textInputLayout.getEditText();
final AutoCompleteTextView editText =
(AutoCompleteTextView) textInputLayout.getEditText();
if (editText != null && previousIcon == TextInputLayout.END_ICON_DROPDOWN_MENU) {
// Remove any listeners set on the edit text.
editText.removeTextChangedListener(exposedDropdownEndIconTextWatcher);
editText.post(
new Runnable() {
@Override
public void run() {
editText.removeTextChangedListener(exposedDropdownEndIconTextWatcher);
}
});
if (editText.getOnFocusChangeListener() == onFocusChangeListener) {
editText.setOnFocusChangeListener(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,19 @@ public void onEditTextAttached(@NonNull TextInputLayout textInputLayout) {
new OnEndIconChangedListener() {
@Override
public void onEndIconChanged(@NonNull TextInputLayout textInputLayout, int previousIcon) {
EditText editText = textInputLayout.getEditText();
final EditText editText = textInputLayout.getEditText();
if (editText != null && previousIcon == TextInputLayout.END_ICON_PASSWORD_TOGGLE) {
// If the end icon was the password toggle add it back the PasswordTransformation
// in case it might have been removed to make the password visible.
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
// Remove any listeners set on the edit text.
editText.removeTextChangedListener(textWatcher);
editText.post(
new Runnable() {
@Override
public void run() {
editText.removeTextChangedListener(textWatcher);
}
});
}
}
};
Expand Down

0 comments on commit 963ad14

Please sign in to comment.