Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal] Replace deprecated androidx.core.view.* methods #4180

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.widget.TextViewCompat;
import androidx.customview.view.AbsSavedState;
import com.google.android.material.internal.ThemeEnforcement;
import com.google.android.material.internal.ViewUtils;
Expand Down Expand Up @@ -858,7 +857,7 @@ private void updateIcon(boolean needsIconReset) {
}

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

private void resetIconDrawable() {
if (isIconStart()) {
TextViewCompat.setCompoundDrawablesRelative(this, icon, null, null, null);
setCompoundDrawablesRelative(icon, null, null, null);
} else if (isIconEnd()) {
TextViewCompat.setCompoundDrawablesRelative(this, null, null, icon, null);
setCompoundDrawablesRelative(null, null, icon, null);
} else if (isIconTop()) {
TextViewCompat.setCompoundDrawablesRelative(this, null, icon, null, null);
setCompoundDrawablesRelative(null, icon, null, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public MaterialButtonToggleGroup(
setEnabled(attributes.getBoolean(R.styleable.MaterialButtonToggleGroup_android_enabled, true));
attributes.recycle();

ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void setIcon(@Nullable Drawable icon) {
}
icon = emptyDrawable;
}
TextViewCompat.setCompoundDrawablesRelative(textView, icon, null, null, null);
textView.setCompoundDrawablesRelative(icon, null, null, null);
}

public void setIconSize(@Dimension int iconSize) {
Expand Down
11 changes: 5 additions & 6 deletions lib/java/com/google/android/material/search/SearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.EditText;
import android.widget.ImageButton;
Expand All @@ -63,8 +64,6 @@
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityManagerCompat;
import androidx.core.view.accessibility.AccessibilityManagerCompat.TouchExplorationStateChangeListener;
import androidx.core.widget.TextViewCompat;
import androidx.customview.view.AbsSavedState;
import com.google.android.material.appbar.AppBarLayout;
Expand Down Expand Up @@ -229,14 +228,14 @@ private void setupTouchExplorationStateChangeListener() {
new OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View ignored) {
AccessibilityManagerCompat.addTouchExplorationStateChangeListener(
accessibilityManager, touchExplorationStateChangeListener);
accessibilityManager.addTouchExplorationStateChangeListener(
touchExplorationStateChangeListener);
}

@Override
public void onViewDetachedFromWindow(View ignored) {
AccessibilityManagerCompat.removeTouchExplorationStateChangeListener(
accessibilityManager, touchExplorationStateChangeListener);
accessibilityManager.removeTouchExplorationStateChangeListener(
touchExplorationStateChangeListener);
}
});
}
Expand Down
3 changes: 1 addition & 2 deletions lib/java/com/google/android/material/search/SearchView.java
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ private void updateNavigationIconIfNeeded() {
if (toolbar.getNavigationIconTint() != null) {
DrawableCompat.setTint(navigationIconDrawable, toolbar.getNavigationIconTint());
}
DrawableCompat.setLayoutDirection(
navigationIconDrawable, ViewCompat.getLayoutDirection(this));
DrawableCompat.setLayoutDirection(navigationIconDrawable, getLayoutDirection());
toolbar.setNavigationIcon(
new FadeThroughDrawable(searchBar.getNavigationIcon(), navigationIconDrawable));
updateNavigationIconProgressIfNeeded();
Expand Down
6 changes: 3 additions & 3 deletions lib/java/com/google/android/material/tabs/TabLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -2712,7 +2712,7 @@ public void onMeasure(final int origWidthMeasureSpec, final int origHeightMeasur

final float curTextSize = textView.getTextSize();
final int curLineCount = textView.getLineCount();
final int curMaxLines = TextViewCompat.getMaxLines(textView);
final int curMaxLines = textView.getMaxLines();

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

customTextView = custom.findViewById(android.R.id.text1);
if (customTextView != null) {
defaultMaxLines = TextViewCompat.getMaxLines(customTextView);
defaultMaxLines = customTextView.getMaxLines();
}
customIconView = custom.findViewById(android.R.id.icon);
} else {
Expand All @@ -2801,7 +2801,7 @@ final void updateTab() {
}
if (this.textView == null) {
inflateAndAddDefaultTextView();
defaultMaxLines = TextViewCompat.getMaxLines(this.textView);
defaultMaxLines = this.textView.getMaxLines();
}
TextViewCompat.setTextAppearance(this.textView, defaultTabTextAppearance);
if (isSelected() && selectedTabTextAppearance != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
import android.view.View.OnFocusChangeListener;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.Spinner;
import androidx.annotation.ChecksSdkIntAtLeast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.accessibility.AccessibilityEventCompat;
import androidx.core.view.accessibility.AccessibilityManagerCompat.TouchExplorationStateChangeListener;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import com.google.android.material.animation.AnimationUtils;
import com.google.android.material.motion.MotionUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView.ScaleType;
Expand All @@ -62,8 +63,6 @@
import androidx.annotation.StringRes;
import androidx.annotation.StyleRes;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.view.accessibility.AccessibilityManagerCompat;
import androidx.core.view.accessibility.AccessibilityManagerCompat.TouchExplorationStateChangeListener;
import androidx.core.widget.TextViewCompat;
import com.google.android.material.internal.CheckableImageButton;
import com.google.android.material.internal.TextWatcherAdapter;
Expand Down Expand Up @@ -422,15 +421,15 @@ private void addTouchExplorationStateChangeListenerIfNeeded() {
if (touchExplorationStateChangeListener != null
&& accessibilityManager != null
&& isAttachedToWindow()) {
AccessibilityManagerCompat.addTouchExplorationStateChangeListener(
accessibilityManager, touchExplorationStateChangeListener);
accessibilityManager.addTouchExplorationStateChangeListener(
touchExplorationStateChangeListener);
}
}

private void removeTouchExplorationStateChangeListenerIfNeeded() {
if (touchExplorationStateChangeListener != null && accessibilityManager != null) {
AccessibilityManagerCompat.removeTouchExplorationStateChangeListener(
accessibilityManager, touchExplorationStateChangeListener);
accessibilityManager.removeTouchExplorationStateChangeListener(
touchExplorationStateChangeListener);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
import android.widget.EditText;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.core.view.accessibility.AccessibilityManagerCompat.TouchExplorationStateChangeListener;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import com.google.android.material.internal.CheckableImageButton;
import com.google.android.material.textfield.TextInputLayout.BoxBackgroundMode;
Expand Down
27 changes: 13 additions & 14 deletions lib/java/com/google/android/material/textfield/TextInputLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -4096,17 +4096,16 @@ boolean updateDummyDrawables() {
startDummyDrawableWidth = right;
startDummyDrawable.setBounds(0, 0, startDummyDrawableWidth, 1);
}
final Drawable[] compounds = TextViewCompat.getCompoundDrawablesRelative(editText);
final Drawable[] compounds = editText.getCompoundDrawablesRelative();
if (compounds[0] != startDummyDrawable) {
TextViewCompat.setCompoundDrawablesRelative(
editText, startDummyDrawable, compounds[1], compounds[2], compounds[3]);
editText.setCompoundDrawablesRelative(
startDummyDrawable, compounds[1], compounds[2], compounds[3]);
updatedIcon = true;
}
} else if (startDummyDrawable != null) {
// Remove the dummy start compound drawable if it exists and clear it.
final Drawable[] compounds = TextViewCompat.getCompoundDrawablesRelative(editText);
TextViewCompat.setCompoundDrawablesRelative(
editText, null, compounds[1], compounds[2], compounds[3]);
final Drawable[] compounds = editText.getCompoundDrawablesRelative();
editText.setCompoundDrawablesRelative(null, compounds[1], compounds[2], compounds[3]);
startDummyDrawable = null;
updatedIcon = true;
}
Expand All @@ -4121,14 +4120,14 @@ boolean updateDummyDrawables() {
+ iconView.getMeasuredWidth()
+ ((MarginLayoutParams) iconView.getLayoutParams()).getMarginStart();
}
final Drawable[] compounds = TextViewCompat.getCompoundDrawablesRelative(editText);
final Drawable[] compounds = editText.getCompoundDrawablesRelative();
if (endDummyDrawable != null && endDummyDrawableWidth != right) {
// If endLayout only changed width, update dummy drawable here so that we don't override
// the currently saved originalEditTextEndDrawable.
endDummyDrawableWidth = right;
endDummyDrawable.setBounds(0, 0, endDummyDrawableWidth, 1);
TextViewCompat.setCompoundDrawablesRelative(
editText, compounds[0], compounds[1], endDummyDrawable, compounds[3]);
editText.setCompoundDrawablesRelative(
compounds[0], compounds[1], endDummyDrawable, compounds[3]);
updatedIcon = true;
} else {
if (endDummyDrawable == null) {
Expand All @@ -4139,17 +4138,17 @@ boolean updateDummyDrawables() {
// Store the user defined end compound drawable so that we can restore it later.
if (compounds[2] != endDummyDrawable) {
originalEditTextEndDrawable = compounds[2];
TextViewCompat.setCompoundDrawablesRelative(
editText, compounds[0], compounds[1], endDummyDrawable, compounds[3]);
editText.setCompoundDrawablesRelative(
compounds[0], compounds[1], endDummyDrawable, compounds[3]);
updatedIcon = true;
}
}
} else if (endDummyDrawable != null) {
// Remove the dummy end compound drawable if it exists and clear it.
final Drawable[] compounds = TextViewCompat.getCompoundDrawablesRelative(editText);
final Drawable[] compounds = editText.getCompoundDrawablesRelative();
if (compounds[2] == endDummyDrawable) {
TextViewCompat.setCompoundDrawablesRelative(
editText, compounds[0], compounds[1], originalEditTextEndDrawable, compounds[3]);
editText.setCompoundDrawablesRelative(
compounds[0], compounds[1], originalEditTextEndDrawable, compounds[3]);
updatedIcon = true;
}
endDummyDrawable = null;
Expand Down