Skip to content

Commit 8bf3bde

Browse files
Material Design Teamveganafro
authored andcommitted
Automated g4 rollback of changelist 404871534
PiperOrigin-RevId: 404899483
1 parent 2701161 commit 8bf3bde

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

lib/java/com/google/android/material/textfield/TextInputLayout.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,22 +2266,8 @@ private static void updateCounterContentDescription(
22662266
* @see #getPlaceholderText()
22672267
*/
22682268
public void setPlaceholderText(@Nullable final CharSequence placeholderText) {
2269-
if (placeholderTextView == null) {
2270-
placeholderTextView = new AppCompatTextView(getContext());
2271-
placeholderTextView.setId(R.id.textinput_placeholder);
2272-
ViewCompat.setImportantForAccessibility(
2273-
placeholderTextView, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO);
2274-
2275-
placeholderFadeIn = createPlaceholderFadeTransition();
2276-
placeholderFadeIn.setStartDelay(PLACEHOLDER_START_DELAY);
2277-
placeholderFadeOut = createPlaceholderFadeTransition();
2278-
2279-
setPlaceholderTextAppearance(placeholderTextAppearance);
2280-
setPlaceholderTextColor(placeholderTextColor);
2281-
}
2282-
2283-
// If placeholder text is null, disable placeholder.
2284-
if (TextUtils.isEmpty(placeholderText)) {
2269+
// If placeholder text is null, disable placeholder if it's enabled.
2270+
if (placeholderEnabled && TextUtils.isEmpty(placeholderText)) {
22852271
setPlaceholderTextEnabled(false);
22862272
} else {
22872273
if (!placeholderEnabled) {
@@ -2312,6 +2298,19 @@ private void setPlaceholderTextEnabled(boolean placeholderEnabled) {
23122298

23132299
// Otherwise, adjust enabled state.
23142300
if (placeholderEnabled) {
2301+
placeholderTextView = new AppCompatTextView(getContext());
2302+
placeholderTextView.setId(R.id.textinput_placeholder);
2303+
2304+
placeholderFadeIn = createPlaceholderFadeTransition();
2305+
placeholderFadeIn.setStartDelay(PLACEHOLDER_START_DELAY);
2306+
2307+
placeholderFadeOut = createPlaceholderFadeTransition();
2308+
2309+
ViewCompat.setAccessibilityLiveRegion(
2310+
placeholderTextView, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE);
2311+
2312+
setPlaceholderTextAppearance(placeholderTextAppearance);
2313+
setPlaceholderTextColor(placeholderTextColor);
23152314
addPlaceholderTextView();
23162315
} else {
23172316
removePlaceholderTextView();
@@ -2345,9 +2344,6 @@ private void showPlaceholderText() {
23452344
TransitionManager.beginDelayedTransition(inputFrame, placeholderFadeIn);
23462345
placeholderTextView.setVisibility(VISIBLE);
23472346
placeholderTextView.bringToFront();
2348-
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
2349-
announceForAccessibility(placeholderText);
2350-
}
23512347
}
23522348
}
23532349

tests/javatests/com/google/android/material/textfield/TextInputLayoutTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,11 @@ public void testDispatchProvideAutofillStructure() {
361361
final ViewStructureImpl structure = new ViewStructureImpl();
362362
layout.dispatchProvideAutofillStructure(structure, 0);
363363

364-
// 1 x EditText, 2 x TextView (prefix/suffix).
365-
assertEquals(3, structure.getChildCount());
364+
// 1 x EditText, 3 x TextView (prefix/suffix/placeholder).
365+
assertEquals(4, structure.getChildCount());
366366

367367
// Asserts the structure.
368-
ViewStructureImpl childStructure = structure.getChildAt(0);
368+
ViewStructureImpl childStructure = structure.getChildAt(1);
369369
assertEquals(EditText.class.getName(), childStructure.getClassName());
370370
assertEquals("Nested hint", childStructure.getHint().toString());
371371

@@ -751,7 +751,7 @@ public void hintSetOnNestedEditText_propagateInnerHintToAutofillProvider() {
751751

752752
textInputLayout.dispatchProvideAutofillStructure(structure, /* flags= */ 0);
753753

754-
final ViewStructureImpl editText = structure.getChildAt(0);
754+
final ViewStructureImpl editText = structure.getChildAt(1);
755755
assertEquals(EditText.class.getName(), editText.getClassName());
756756
assertEquals(structure.getAutofillId(), textInputLayout.getAutofillId());
757757
assertEquals("Nested hint", editText.getHint().toString());
@@ -767,7 +767,7 @@ public void hintSetOnOuterLayout_propagateOuterHintToAutofillProvider() {
767767

768768
textInputLayout.dispatchProvideAutofillStructure(structure, /* flags= */ 0);
769769

770-
final ViewStructureImpl editText = structure.getChildAt(0);
770+
final ViewStructureImpl editText = structure.getChildAt(1);
771771
assertEquals(EditText.class.getName(), editText.getClassName());
772772
assertEquals(structure.getAutofillId(), textInputLayout.getAutofillId());
773773
assertEquals("Outer hint", editText.getHint().toString());

0 commit comments

Comments
 (0)