Skip to content

Commit 2048110

Browse files
pubiqqhunterstich
authored andcommitted
[Internal] Replace deprecated androidx.core.view.* methods
Resolves #4180 GIT_ORIGIN_REV_ID=8e4ec29abacc33cde748b8f07f0ba5c251cef395 PiperOrigin-RevId: 656004130
1 parent 71ae9f5 commit 2048110

File tree

10 files changed

+36
-41
lines changed

10 files changed

+36
-41
lines changed

lib/java/com/google/android/material/button/MaterialButton.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
import androidx.annotation.RequiresApi;
6262
import androidx.annotation.RestrictTo;
6363
import androidx.core.graphics.drawable.DrawableCompat;
64-
import androidx.core.widget.TextViewCompat;
6564
import androidx.customview.view.AbsSavedState;
6665
import com.google.android.material.internal.ThemeEnforcement;
6766
import com.google.android.material.internal.ViewUtils;
@@ -858,7 +857,7 @@ private void updateIcon(boolean needsIconReset) {
858857
}
859858

860859
// Otherwise only update if the icon or the position has changed
861-
Drawable[] existingDrawables = TextViewCompat.getCompoundDrawablesRelative(this);
860+
Drawable[] existingDrawables = getCompoundDrawablesRelative();
862861
Drawable drawableStart = existingDrawables[0];
863862
Drawable drawableTop = existingDrawables[1];
864863
Drawable drawableEnd = existingDrawables[2];
@@ -874,11 +873,11 @@ private void updateIcon(boolean needsIconReset) {
874873

875874
private void resetIconDrawable() {
876875
if (isIconStart()) {
877-
TextViewCompat.setCompoundDrawablesRelative(this, icon, null, null, null);
876+
setCompoundDrawablesRelative(icon, null, null, null);
878877
} else if (isIconEnd()) {
879-
TextViewCompat.setCompoundDrawablesRelative(this, null, null, icon, null);
878+
setCompoundDrawablesRelative(null, null, icon, null);
880879
} else if (isIconTop()) {
881-
TextViewCompat.setCompoundDrawablesRelative(this, null, icon, null, null);
880+
setCompoundDrawablesRelative(null, icon, null, null);
882881
}
883882
}
884883

lib/java/com/google/android/material/button/MaterialButtonToggleGroup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public MaterialButtonToggleGroup(
221221
setEnabled(attributes.getBoolean(R.styleable.MaterialButtonToggleGroup_android_enabled, true));
222222
attributes.recycle();
223223

224-
ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
224+
setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
225225
}
226226

227227
@Override
@@ -782,7 +782,7 @@ private void dispatchOnButtonChecked(@IdRes int buttonId, boolean checked) {
782782
private void setGeneratedIdIfNeeded(@NonNull MaterialButton materialButton) {
783783
// Generates an ID if none is set, for relative positioning purposes
784784
if (materialButton.getId() == View.NO_ID) {
785-
materialButton.setId(ViewCompat.generateViewId());
785+
materialButton.setId(View.generateViewId());
786786
}
787787
}
788788

lib/java/com/google/android/material/internal/NavigationMenuItemView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void setIcon(@Nullable Drawable icon) {
248248
}
249249
icon = emptyDrawable;
250250
}
251-
TextViewCompat.setCompoundDrawablesRelative(textView, icon, null, null, null);
251+
textView.setCompoundDrawablesRelative(icon, null, null, null);
252252
}
253253

254254
public void setIconSize(@Dimension int iconSize) {

lib/java/com/google/android/material/search/SearchBar.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import android.view.View;
4646
import android.view.ViewGroup;
4747
import android.view.accessibility.AccessibilityManager;
48+
import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
4849
import android.view.accessibility.AccessibilityNodeInfo;
4950
import android.widget.EditText;
5051
import android.widget.ImageButton;
@@ -63,8 +64,6 @@
6364
import androidx.coordinatorlayout.widget.CoordinatorLayout;
6465
import androidx.core.graphics.drawable.DrawableCompat;
6566
import androidx.core.view.ViewCompat;
66-
import androidx.core.view.accessibility.AccessibilityManagerCompat;
67-
import androidx.core.view.accessibility.AccessibilityManagerCompat.TouchExplorationStateChangeListener;
6867
import androidx.core.widget.TextViewCompat;
6968
import androidx.customview.view.AbsSavedState;
7069
import com.google.android.material.appbar.AppBarLayout;
@@ -229,14 +228,14 @@ private void setupTouchExplorationStateChangeListener() {
229228
new OnAttachStateChangeListener() {
230229
@Override
231230
public void onViewAttachedToWindow(View ignored) {
232-
AccessibilityManagerCompat.addTouchExplorationStateChangeListener(
233-
accessibilityManager, touchExplorationStateChangeListener);
231+
accessibilityManager.addTouchExplorationStateChangeListener(
232+
touchExplorationStateChangeListener);
234233
}
235234

236235
@Override
237236
public void onViewDetachedFromWindow(View ignored) {
238-
AccessibilityManagerCompat.removeTouchExplorationStateChangeListener(
239-
accessibilityManager, touchExplorationStateChangeListener);
237+
accessibilityManager.removeTouchExplorationStateChangeListener(
238+
touchExplorationStateChangeListener);
240239
}
241240
});
242241
}

lib/java/com/google/android/material/search/SearchView.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,7 @@ private void updateNavigationIconIfNeeded() {
476476
if (toolbar.getNavigationIconTint() != null) {
477477
DrawableCompat.setTint(navigationIconDrawable, toolbar.getNavigationIconTint());
478478
}
479-
DrawableCompat.setLayoutDirection(
480-
navigationIconDrawable, ViewCompat.getLayoutDirection(this));
479+
DrawableCompat.setLayoutDirection(navigationIconDrawable, getLayoutDirection());
481480
toolbar.setNavigationIcon(
482481
new FadeThroughDrawable(searchBar.getNavigationIcon(), navigationIconDrawable));
483482
updateNavigationIconProgressIfNeeded();

lib/java/com/google/android/material/tabs/TabLayout.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,7 +2712,7 @@ public void onMeasure(final int origWidthMeasureSpec, final int origHeightMeasur
27122712

27132713
final float curTextSize = textView.getTextSize();
27142714
final int curLineCount = textView.getLineCount();
2715-
final int curMaxLines = TextViewCompat.getMaxLines(textView);
2715+
final int curMaxLines = textView.getMaxLines();
27162716

27172717
if (textSize != curTextSize || (curMaxLines >= 0 && maxLines != curMaxLines)) {
27182718
// We've got a new text size and/or max lines...
@@ -2781,7 +2781,7 @@ final void updateTab() {
27812781

27822782
customTextView = custom.findViewById(android.R.id.text1);
27832783
if (customTextView != null) {
2784-
defaultMaxLines = TextViewCompat.getMaxLines(customTextView);
2784+
defaultMaxLines = customTextView.getMaxLines();
27852785
}
27862786
customIconView = custom.findViewById(android.R.id.icon);
27872787
} else {
@@ -2801,7 +2801,7 @@ final void updateTab() {
28012801
}
28022802
if (this.textView == null) {
28032803
inflateAndAddDefaultTextView();
2804-
defaultMaxLines = TextViewCompat.getMaxLines(this.textView);
2804+
defaultMaxLines = this.textView.getMaxLines();
28052805
}
28062806
TextViewCompat.setTextAppearance(this.textView, defaultTabTextAppearance);
28072807
if (isSelected() && selectedTabTextAppearance != -1) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
import android.view.View.OnFocusChangeListener;
3737
import android.view.accessibility.AccessibilityEvent;
3838
import android.view.accessibility.AccessibilityManager;
39+
import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
3940
import android.widget.AutoCompleteTextView;
4041
import android.widget.EditText;
4142
import android.widget.Spinner;
4243
import androidx.annotation.ChecksSdkIntAtLeast;
4344
import androidx.annotation.NonNull;
4445
import androidx.annotation.Nullable;
4546
import androidx.core.view.accessibility.AccessibilityEventCompat;
46-
import androidx.core.view.accessibility.AccessibilityManagerCompat.TouchExplorationStateChangeListener;
4747
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
4848
import com.google.android.material.animation.AnimationUtils;
4949
import com.google.android.material.motion.MotionUtils;

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import android.view.View;
5050
import android.view.ViewGroup;
5151
import android.view.accessibility.AccessibilityManager;
52+
import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
5253
import android.widget.EditText;
5354
import android.widget.FrameLayout;
5455
import android.widget.ImageView.ScaleType;
@@ -62,8 +63,6 @@
6263
import androidx.annotation.StringRes;
6364
import androidx.annotation.StyleRes;
6465
import androidx.core.graphics.drawable.DrawableCompat;
65-
import androidx.core.view.accessibility.AccessibilityManagerCompat;
66-
import androidx.core.view.accessibility.AccessibilityManagerCompat.TouchExplorationStateChangeListener;
6766
import androidx.core.widget.TextViewCompat;
6867
import com.google.android.material.internal.CheckableImageButton;
6968
import com.google.android.material.internal.TextWatcherAdapter;
@@ -422,15 +421,15 @@ private void addTouchExplorationStateChangeListenerIfNeeded() {
422421
if (touchExplorationStateChangeListener != null
423422
&& accessibilityManager != null
424423
&& isAttachedToWindow()) {
425-
AccessibilityManagerCompat.addTouchExplorationStateChangeListener(
426-
accessibilityManager, touchExplorationStateChangeListener);
424+
accessibilityManager.addTouchExplorationStateChangeListener(
425+
touchExplorationStateChangeListener);
427426
}
428427
}
429428

430429
private void removeTouchExplorationStateChangeListenerIfNeeded() {
431430
if (touchExplorationStateChangeListener != null && accessibilityManager != null) {
432-
AccessibilityManagerCompat.removeTouchExplorationStateChangeListener(
433-
accessibilityManager, touchExplorationStateChangeListener);
431+
accessibilityManager.removeTouchExplorationStateChangeListener(
432+
touchExplorationStateChangeListener);
434433
}
435434
}
436435

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import android.view.View.OnClickListener;
2323
import android.view.View.OnFocusChangeListener;
2424
import android.view.accessibility.AccessibilityEvent;
25+
import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
2526
import android.widget.EditText;
2627
import androidx.annotation.DrawableRes;
2728
import androidx.annotation.NonNull;
2829
import androidx.annotation.Nullable;
2930
import androidx.annotation.StringRes;
30-
import androidx.core.view.accessibility.AccessibilityManagerCompat.TouchExplorationStateChangeListener;
3131
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
3232
import com.google.android.material.internal.CheckableImageButton;
3333
import com.google.android.material.textfield.TextInputLayout.BoxBackgroundMode;

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4096,17 +4096,16 @@ boolean updateDummyDrawables() {
40964096
startDummyDrawableWidth = right;
40974097
startDummyDrawable.setBounds(0, 0, startDummyDrawableWidth, 1);
40984098
}
4099-
final Drawable[] compounds = TextViewCompat.getCompoundDrawablesRelative(editText);
4099+
final Drawable[] compounds = editText.getCompoundDrawablesRelative();
41004100
if (compounds[0] != startDummyDrawable) {
4101-
TextViewCompat.setCompoundDrawablesRelative(
4102-
editText, startDummyDrawable, compounds[1], compounds[2], compounds[3]);
4101+
editText.setCompoundDrawablesRelative(
4102+
startDummyDrawable, compounds[1], compounds[2], compounds[3]);
41034103
updatedIcon = true;
41044104
}
41054105
} else if (startDummyDrawable != null) {
41064106
// Remove the dummy start compound drawable if it exists and clear it.
4107-
final Drawable[] compounds = TextViewCompat.getCompoundDrawablesRelative(editText);
4108-
TextViewCompat.setCompoundDrawablesRelative(
4109-
editText, null, compounds[1], compounds[2], compounds[3]);
4107+
final Drawable[] compounds = editText.getCompoundDrawablesRelative();
4108+
editText.setCompoundDrawablesRelative(null, compounds[1], compounds[2], compounds[3]);
41104109
startDummyDrawable = null;
41114110
updatedIcon = true;
41124111
}
@@ -4121,14 +4120,14 @@ boolean updateDummyDrawables() {
41214120
+ iconView.getMeasuredWidth()
41224121
+ ((MarginLayoutParams) iconView.getLayoutParams()).getMarginStart();
41234122
}
4124-
final Drawable[] compounds = TextViewCompat.getCompoundDrawablesRelative(editText);
4123+
final Drawable[] compounds = editText.getCompoundDrawablesRelative();
41254124
if (endDummyDrawable != null && endDummyDrawableWidth != right) {
41264125
// If endLayout only changed width, update dummy drawable here so that we don't override
41274126
// the currently saved originalEditTextEndDrawable.
41284127
endDummyDrawableWidth = right;
41294128
endDummyDrawable.setBounds(0, 0, endDummyDrawableWidth, 1);
4130-
TextViewCompat.setCompoundDrawablesRelative(
4131-
editText, compounds[0], compounds[1], endDummyDrawable, compounds[3]);
4129+
editText.setCompoundDrawablesRelative(
4130+
compounds[0], compounds[1], endDummyDrawable, compounds[3]);
41324131
updatedIcon = true;
41334132
} else {
41344133
if (endDummyDrawable == null) {
@@ -4139,17 +4138,17 @@ boolean updateDummyDrawables() {
41394138
// Store the user defined end compound drawable so that we can restore it later.
41404139
if (compounds[2] != endDummyDrawable) {
41414140
originalEditTextEndDrawable = compounds[2];
4142-
TextViewCompat.setCompoundDrawablesRelative(
4143-
editText, compounds[0], compounds[1], endDummyDrawable, compounds[3]);
4141+
editText.setCompoundDrawablesRelative(
4142+
compounds[0], compounds[1], endDummyDrawable, compounds[3]);
41444143
updatedIcon = true;
41454144
}
41464145
}
41474146
} else if (endDummyDrawable != null) {
41484147
// Remove the dummy end compound drawable if it exists and clear it.
4149-
final Drawable[] compounds = TextViewCompat.getCompoundDrawablesRelative(editText);
4148+
final Drawable[] compounds = editText.getCompoundDrawablesRelative();
41504149
if (compounds[2] == endDummyDrawable) {
4151-
TextViewCompat.setCompoundDrawablesRelative(
4152-
editText, compounds[0], compounds[1], originalEditTextEndDrawable, compounds[3]);
4150+
editText.setCompoundDrawablesRelative(
4151+
compounds[0], compounds[1], originalEditTextEndDrawable, compounds[3]);
41534152
updatedIcon = true;
41544153
}
41554154
endDummyDrawable = null;

0 commit comments

Comments
 (0)