package com.google.android.material.textfield; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Point; import android.graphics.Rect; import android.text.Editable; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.view.ViewParent; import android.view.accessibility.AccessibilityNodeInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; import androidx.appcompat.widget.AppCompatEditText; import com.google.android.material.R; import com.google.android.material.internal.ManufacturerUtils; import com.google.android.material.internal.ThemeEnforcement; import com.google.android.material.theme.overlay.MaterialThemeOverlay; /* loaded from: classes2.dex */ public class TextInputEditText extends AppCompatEditText { private final Rect parentRect; private boolean textInputLayoutFocusedRectEnabled; private boolean shouldUseTextInputLayoutFocusedRect(TextInputLayout textInputLayout) { return textInputLayout != null && this.textInputLayoutFocusedRectEnabled; } public boolean isTextInputLayoutFocusedRectEnabled() { return this.textInputLayoutFocusedRectEnabled; } public void setTextInputLayoutFocusedRectEnabled(boolean z) { this.textInputLayoutFocusedRectEnabled = z; } public TextInputEditText(Context context) { this(context, null); } public TextInputEditText(Context context, AttributeSet attributeSet) { this(context, attributeSet, R.attr.editTextStyle); } public TextInputEditText(Context context, AttributeSet attributeSet, int i) { super(MaterialThemeOverlay.wrap(context, attributeSet, i, 0), attributeSet, i); this.parentRect = new Rect(); TypedArray obtainStyledAttributes = ThemeEnforcement.obtainStyledAttributes(context, attributeSet, R.styleable.TextInputEditText, i, R.style.Widget_Design_TextInputEditText, new int[0]); setTextInputLayoutFocusedRectEnabled(obtainStyledAttributes.getBoolean(R.styleable.TextInputEditText_textInputLayoutFocusedRectEnabled, false)); obtainStyledAttributes.recycle(); } @Override // android.widget.TextView, android.view.View protected void onAttachedToWindow() { super.onAttachedToWindow(); TextInputLayout textInputLayout = getTextInputLayout(); if (textInputLayout != null && textInputLayout.isProvidingHint() && super.getHint() == null && ManufacturerUtils.isMeizuDevice()) { setHint(""); } } @Override // android.widget.TextView public CharSequence getHint() { TextInputLayout textInputLayout = getTextInputLayout(); if (textInputLayout != null && textInputLayout.isProvidingHint()) { return textInputLayout.getHint(); } return super.getHint(); } @Override // androidx.appcompat.widget.AppCompatEditText, android.widget.TextView, android.view.View public InputConnection onCreateInputConnection(EditorInfo editorInfo) { InputConnection onCreateInputConnection = super.onCreateInputConnection(editorInfo); if (onCreateInputConnection != null && editorInfo.hintText == null) { editorInfo.hintText = getHintFromLayout(); } return onCreateInputConnection; } private TextInputLayout getTextInputLayout() { for (ViewParent parent = getParent(); parent instanceof View; parent = parent.getParent()) { if (parent instanceof TextInputLayout) { return (TextInputLayout) parent; } } return null; } private CharSequence getHintFromLayout() { TextInputLayout textInputLayout = getTextInputLayout(); if (textInputLayout != null) { return textInputLayout.getHint(); } return null; } @Override // android.widget.TextView, android.view.View public void getFocusedRect(Rect rect) { super.getFocusedRect(rect); TextInputLayout textInputLayout = getTextInputLayout(); if (!shouldUseTextInputLayoutFocusedRect(textInputLayout) || rect == null) { return; } textInputLayout.getFocusedRect(this.parentRect); rect.bottom = this.parentRect.bottom; } @Override // android.view.View public boolean getGlobalVisibleRect(Rect rect, Point point) { TextInputLayout textInputLayout = getTextInputLayout(); if (shouldUseTextInputLayoutFocusedRect(textInputLayout)) { boolean globalVisibleRect = textInputLayout.getGlobalVisibleRect(rect, point); if (globalVisibleRect && point != null) { point.offset(-getScrollX(), -getScrollY()); } return globalVisibleRect; } return super.getGlobalVisibleRect(rect, point); } @Override // android.view.View public boolean requestRectangleOnScreen(Rect rect) { TextInputLayout textInputLayout = getTextInputLayout(); if (shouldUseTextInputLayoutFocusedRect(textInputLayout) && rect != null) { this.parentRect.set(rect.left, rect.top, rect.right, rect.bottom + (textInputLayout.getHeight() - getHeight())); return super.requestRectangleOnScreen(this.parentRect); } return super.requestRectangleOnScreen(rect); } @Override // android.view.View public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) { super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo); getTextInputLayout(); } private String getAccessibilityNodeInfoText(TextInputLayout textInputLayout) { Editable text = getText(); CharSequence hint = textInputLayout.getHint(); boolean z = !TextUtils.isEmpty(text); String charSequence = TextUtils.isEmpty(hint) ^ true ? hint.toString() : ""; if (z) { return ((Object) text) + (TextUtils.isEmpty(charSequence) ? "" : ", " + charSequence); } return !TextUtils.isEmpty(charSequence) ? charSequence : ""; } }