package androidx.appcompat.widget; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.os.Build; import android.text.Editable; import android.util.AttributeSet; import android.view.ActionMode; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; import android.view.textclassifier.TextClassifier; import android.widget.EditText; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.RestrictTo; import androidx.appcompat.R; import androidx.core.view.TintableBackgroundView; import androidx.core.widget.TextViewCompat; public class AppCompatEditText extends EditText implements TintableBackgroundView { private final AppCompatBackgroundHelper mBackgroundTintHelper; private final AppCompatTextClassifierHelper mTextClassifierHelper; private final AppCompatTextHelper mTextHelper; public AppCompatEditText(@NonNull Context context) { this(context, null); } public AppCompatEditText(@NonNull Context context, @Nullable AttributeSet attributeSet) { this(context, attributeSet, R.attr.editTextStyle); } public AppCompatEditText(@NonNull Context context, @Nullable AttributeSet attributeSet, int i) { super(TintContextWrapper.wrap(context), attributeSet, i); ThemeUtils.checkAppCompatTheme(this, getContext()); AppCompatBackgroundHelper appCompatBackgroundHelper = new AppCompatBackgroundHelper(this); this.mBackgroundTintHelper = appCompatBackgroundHelper; appCompatBackgroundHelper.loadFromAttributes(attributeSet, i); AppCompatTextHelper appCompatTextHelper = new AppCompatTextHelper(this); this.mTextHelper = appCompatTextHelper; appCompatTextHelper.loadFromAttributes(attributeSet, i); appCompatTextHelper.applyCompoundDrawablesTints(); this.mTextClassifierHelper = new AppCompatTextClassifierHelper(this); } @Override // android.widget.TextView, android.view.View public void drawableStateChanged() { super.drawableStateChanged(); AppCompatBackgroundHelper appCompatBackgroundHelper = this.mBackgroundTintHelper; if (appCompatBackgroundHelper != null) { appCompatBackgroundHelper.applySupportBackgroundTint(); } AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null) { appCompatTextHelper.applyCompoundDrawablesTints(); } } @Override // androidx.core.view.TintableBackgroundView @Nullable @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public ColorStateList getSupportBackgroundTintList() { AppCompatBackgroundHelper appCompatBackgroundHelper = this.mBackgroundTintHelper; if (appCompatBackgroundHelper != null) { return appCompatBackgroundHelper.getSupportBackgroundTintList(); } return null; } @Override // androidx.core.view.TintableBackgroundView @Nullable @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public PorterDuff.Mode getSupportBackgroundTintMode() { AppCompatBackgroundHelper appCompatBackgroundHelper = this.mBackgroundTintHelper; if (appCompatBackgroundHelper != null) { return appCompatBackgroundHelper.getSupportBackgroundTintMode(); } return null; } @Override // android.widget.EditText, android.widget.TextView @Nullable public Editable getText() { return Build.VERSION.SDK_INT >= 28 ? super.getText() : super.getEditableText(); } @Override // android.widget.TextView @NonNull @RequiresApi(api = 26) public TextClassifier getTextClassifier() { AppCompatTextClassifierHelper appCompatTextClassifierHelper; return (Build.VERSION.SDK_INT >= 28 || (appCompatTextClassifierHelper = this.mTextClassifierHelper) == null) ? super.getTextClassifier() : appCompatTextClassifierHelper.getTextClassifier(); } @Override // android.widget.TextView, android.view.View public InputConnection onCreateInputConnection(EditorInfo editorInfo) { return AppCompatHintHelper.onCreateInputConnection(super.onCreateInputConnection(editorInfo), editorInfo, this); } @Override // android.view.View public void setBackgroundDrawable(Drawable drawable) { super.setBackgroundDrawable(drawable); AppCompatBackgroundHelper appCompatBackgroundHelper = this.mBackgroundTintHelper; if (appCompatBackgroundHelper != null) { appCompatBackgroundHelper.onSetBackgroundDrawable(drawable); } } @Override // android.view.View public void setBackgroundResource(@DrawableRes int i) { super.setBackgroundResource(i); AppCompatBackgroundHelper appCompatBackgroundHelper = this.mBackgroundTintHelper; if (appCompatBackgroundHelper != null) { appCompatBackgroundHelper.onSetBackgroundResource(i); } } @Override // android.widget.TextView public void setCustomSelectionActionModeCallback(ActionMode.Callback callback) { super.setCustomSelectionActionModeCallback(TextViewCompat.wrapCustomSelectionActionModeCallback(this, callback)); } @Override // androidx.core.view.TintableBackgroundView @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void setSupportBackgroundTintList(@Nullable ColorStateList colorStateList) { AppCompatBackgroundHelper appCompatBackgroundHelper = this.mBackgroundTintHelper; if (appCompatBackgroundHelper != null) { appCompatBackgroundHelper.setSupportBackgroundTintList(colorStateList); } } @Override // androidx.core.view.TintableBackgroundView @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void setSupportBackgroundTintMode(@Nullable PorterDuff.Mode mode) { AppCompatBackgroundHelper appCompatBackgroundHelper = this.mBackgroundTintHelper; if (appCompatBackgroundHelper != null) { appCompatBackgroundHelper.setSupportBackgroundTintMode(mode); } } @Override // android.widget.TextView public void setTextAppearance(Context context, int i) { super.setTextAppearance(context, i); AppCompatTextHelper appCompatTextHelper = this.mTextHelper; if (appCompatTextHelper != null) { appCompatTextHelper.onSetTextAppearance(context, i); } } @Override // android.widget.TextView @RequiresApi(api = 26) public void setTextClassifier(@Nullable TextClassifier textClassifier) { AppCompatTextClassifierHelper appCompatTextClassifierHelper; if (Build.VERSION.SDK_INT >= 28 || (appCompatTextClassifierHelper = this.mTextClassifierHelper) == null) { super.setTextClassifier(textClassifier); } else { appCompatTextClassifierHelper.setTextClassifier(textClassifier); } } }