351 lines
14 KiB
Java
351 lines
14 KiB
Java
package com.google.android.material.textfield;
|
|
|
|
import android.R;
|
|
import android.content.Context;
|
|
import android.content.res.ColorStateList;
|
|
import android.content.res.TypedArray;
|
|
import android.graphics.Rect;
|
|
import android.graphics.drawable.ColorDrawable;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.graphics.drawable.RippleDrawable;
|
|
import android.os.Build;
|
|
import android.util.AttributeSet;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewParent;
|
|
import android.view.accessibility.AccessibilityManager;
|
|
import android.widget.AdapterView;
|
|
import android.widget.ArrayAdapter;
|
|
import android.widget.Filterable;
|
|
import android.widget.ListAdapter;
|
|
import android.widget.TextView;
|
|
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
|
|
import androidx.core.view.ViewCompat;
|
|
import java.util.Locale;
|
|
import o.C14739fyr;
|
|
import o.C15846jAy;
|
|
import o.C17052tZT;
|
|
import o.Rez;
|
|
import o.Tlu;
|
|
import o.hdZ;
|
|
import o.uqW;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class MaterialAutoCompleteTextView extends AppCompatAutoCompleteTextView {
|
|
ColorStateList a;
|
|
private final AccessibilityManager b;
|
|
final float c;
|
|
final C15846jAy d;
|
|
int e;
|
|
private final int h;
|
|
private final Rect i;
|
|
|
|
public MaterialAutoCompleteTextView(Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
public MaterialAutoCompleteTextView(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, C17052tZT.IeS.autoCompleteTextViewStyle);
|
|
}
|
|
|
|
public MaterialAutoCompleteTextView(Context context, AttributeSet attributeSet, int i) {
|
|
super(hdZ.MQ_(context, attributeSet, i, 0), attributeSet, i);
|
|
this.i = new Rect();
|
|
Context context2 = getContext();
|
|
int[] iArr = C17052tZT.jNh.MaterialAutoCompleteTextView;
|
|
int i2 = C17052tZT.NHB.Widget_AppCompat_AutoCompleteTextView;
|
|
uqW.Kb_(context2, attributeSet, i, i2);
|
|
uqW.Kc_(context2, attributeSet, iArr, i, i2, new int[0]);
|
|
TypedArray obtainStyledAttributes = context2.obtainStyledAttributes(attributeSet, iArr, i, i2);
|
|
if (obtainStyledAttributes.hasValue(C17052tZT.jNh.MaterialAutoCompleteTextView_android_inputType) && obtainStyledAttributes.getInt(C17052tZT.jNh.MaterialAutoCompleteTextView_android_inputType, 0) == 0) {
|
|
setKeyListener(null);
|
|
}
|
|
this.h = obtainStyledAttributes.getResourceId(C17052tZT.jNh.MaterialAutoCompleteTextView_simpleItemLayout, C17052tZT.tOB.mtrl_auto_complete_simple_item);
|
|
this.c = obtainStyledAttributes.getDimensionPixelOffset(C17052tZT.jNh.MaterialAutoCompleteTextView_android_popupElevation, C17052tZT.HBt.mtrl_exposed_dropdown_menu_popup_elevation);
|
|
this.e = obtainStyledAttributes.getColor(C17052tZT.jNh.MaterialAutoCompleteTextView_simpleItemSelectedColor, 0);
|
|
this.a = C14739fyr.Ku_(context2, obtainStyledAttributes, C17052tZT.jNh.MaterialAutoCompleteTextView_simpleItemSelectedRippleColor);
|
|
this.b = (AccessibilityManager) context2.getSystemService("accessibility");
|
|
C15846jAy c15846jAy = new C15846jAy(context2);
|
|
this.d = c15846jAy;
|
|
c15846jAy.c(true);
|
|
c15846jAy.e(this);
|
|
c15846jAy.i(2);
|
|
c15846jAy.iu_(getAdapter());
|
|
c15846jAy.iy_(new AdapterView.OnItemClickListener(this) { // from class: com.google.android.material.textfield.MaterialAutoCompleteTextView.2
|
|
private MaterialAutoCompleteTextView d;
|
|
|
|
{
|
|
this.d = this;
|
|
}
|
|
|
|
@Override // android.widget.AdapterView.OnItemClickListener
|
|
public final void onItemClick(AdapterView<?> adapterView, View view, int i3, long j) {
|
|
MaterialAutoCompleteTextView materialAutoCompleteTextView = this.d;
|
|
MaterialAutoCompleteTextView.e(this.d, i3 < 0 ? materialAutoCompleteTextView.d.o() : materialAutoCompleteTextView.getAdapter().getItem(i3));
|
|
AdapterView.OnItemClickListener onItemClickListener = this.d.getOnItemClickListener();
|
|
if (onItemClickListener != null) {
|
|
if (view == null || i3 < 0) {
|
|
view = this.d.d.k();
|
|
i3 = this.d.d.n();
|
|
j = this.d.d.l();
|
|
}
|
|
onItemClickListener.onItemClick(this.d.d.it_(), view, i3, j);
|
|
}
|
|
this.d.d.b();
|
|
}
|
|
});
|
|
if (obtainStyledAttributes.hasValue(C17052tZT.jNh.MaterialAutoCompleteTextView_simpleItems)) {
|
|
setSimpleItems(obtainStyledAttributes.getResourceId(C17052tZT.jNh.MaterialAutoCompleteTextView_simpleItems, 0));
|
|
}
|
|
obtainStyledAttributes.recycle();
|
|
}
|
|
|
|
@Override // android.widget.AutoCompleteTextView
|
|
public void showDropDown() {
|
|
AccessibilityManager accessibilityManager = this.b;
|
|
if (accessibilityManager != null) {
|
|
try {
|
|
if (((Boolean) Class.forName("android.view.accessibility.AccessibilityManager").getMethod("isTouchExplorationEnabled", null).invoke(accessibilityManager, null)).booleanValue()) {
|
|
this.d.h();
|
|
return;
|
|
}
|
|
} catch (Throwable th) {
|
|
Throwable cause = th.getCause();
|
|
if (cause == null) {
|
|
throw th;
|
|
}
|
|
throw cause;
|
|
}
|
|
}
|
|
super.showDropDown();
|
|
}
|
|
|
|
@Override // android.widget.AutoCompleteTextView
|
|
public void dismissDropDown() {
|
|
AccessibilityManager accessibilityManager = this.b;
|
|
if (accessibilityManager != null) {
|
|
try {
|
|
if (((Boolean) Class.forName("android.view.accessibility.AccessibilityManager").getMethod("isTouchExplorationEnabled", null).invoke(accessibilityManager, null)).booleanValue()) {
|
|
this.d.b();
|
|
return;
|
|
}
|
|
} catch (Throwable th) {
|
|
Throwable cause = th.getCause();
|
|
if (cause == null) {
|
|
throw th;
|
|
}
|
|
throw cause;
|
|
}
|
|
}
|
|
super.dismissDropDown();
|
|
}
|
|
|
|
@Override // android.widget.AutoCompleteTextView, android.widget.TextView, android.view.View
|
|
public void onWindowFocusChanged(boolean z) {
|
|
AccessibilityManager accessibilityManager = this.b;
|
|
if (accessibilityManager != null) {
|
|
try {
|
|
if (((Boolean) Class.forName("android.view.accessibility.AccessibilityManager").getMethod("isTouchExplorationEnabled", null).invoke(accessibilityManager, null)).booleanValue()) {
|
|
return;
|
|
}
|
|
} catch (Throwable th) {
|
|
Throwable cause = th.getCause();
|
|
if (cause == null) {
|
|
throw th;
|
|
}
|
|
throw cause;
|
|
}
|
|
}
|
|
super.onWindowFocusChanged(z);
|
|
}
|
|
|
|
@Override // android.widget.AutoCompleteTextView
|
|
public <T extends ListAdapter & Filterable> void setAdapter(T t) {
|
|
super.setAdapter(t);
|
|
this.d.iu_(getAdapter());
|
|
}
|
|
|
|
@Override // android.widget.TextView
|
|
public void setRawInputType(int i) {
|
|
super.setRawInputType(i);
|
|
TextInputLayout c = c();
|
|
if (c != null) {
|
|
c.b();
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.AutoCompleteTextView
|
|
public void setOnItemSelectedListener(AdapterView.OnItemSelectedListener onItemSelectedListener) {
|
|
super.setOnItemSelectedListener(onItemSelectedListener);
|
|
this.d.iz_(getOnItemSelectedListener());
|
|
}
|
|
|
|
public void setSimpleItems(int i) {
|
|
setSimpleItems(getResources().getStringArray(i));
|
|
}
|
|
|
|
public void setSimpleItems(String[] strArr) {
|
|
setAdapter(new RVV(this, getContext(), this.h, strArr));
|
|
}
|
|
|
|
public void setSimpleItemSelectedColor(int i) {
|
|
this.e = i;
|
|
if (getAdapter() instanceof RVV) {
|
|
RVV rvv = (RVV) getAdapter();
|
|
rvv.b = rvv.Mx_();
|
|
rvv.d = rvv.Mw_();
|
|
}
|
|
}
|
|
|
|
public void setSimpleItemSelectedRippleColor(ColorStateList colorStateList) {
|
|
this.a = colorStateList;
|
|
if (getAdapter() instanceof RVV) {
|
|
RVV rvv = (RVV) getAdapter();
|
|
rvv.b = rvv.Mx_();
|
|
rvv.d = rvv.Mw_();
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.AutoCompleteTextView
|
|
public void setDropDownBackgroundDrawable(Drawable drawable) {
|
|
super.setDropDownBackgroundDrawable(drawable);
|
|
C15846jAy c15846jAy = this.d;
|
|
if (c15846jAy != null) {
|
|
c15846jAy.iv_(drawable);
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.AutoCompleteTextView, android.widget.TextView, android.view.View
|
|
protected void onAttachedToWindow() {
|
|
super.onAttachedToWindow();
|
|
TextInputLayout c = c();
|
|
if (c != null && c.n && super.getHint() == null && Build.MANUFACTURER.toLowerCase(Locale.ENGLISH).equals("meizu")) {
|
|
setHint("");
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.AutoCompleteTextView, android.view.View
|
|
protected void onDetachedFromWindow() {
|
|
super.onDetachedFromWindow();
|
|
this.d.b();
|
|
}
|
|
|
|
@Override // android.widget.TextView
|
|
public CharSequence getHint() {
|
|
TextInputLayout c = c();
|
|
if (c == null || !c.n) {
|
|
return super.getHint();
|
|
}
|
|
if (c.m) {
|
|
return c.j;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override // android.widget.TextView, android.view.View
|
|
protected void onMeasure(int i, int i2) {
|
|
super.onMeasure(i, i2);
|
|
if (View.MeasureSpec.getMode(i) == Integer.MIN_VALUE) {
|
|
int measuredWidth = getMeasuredWidth();
|
|
ListAdapter adapter = getAdapter();
|
|
TextInputLayout c = c();
|
|
int i3 = 0;
|
|
if (adapter != null && c != null) {
|
|
int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(getMeasuredWidth(), 0);
|
|
int makeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(getMeasuredHeight(), 0);
|
|
int min = Math.min(adapter.getCount(), Math.max(0, this.d.n()) + 15);
|
|
View view = null;
|
|
int i4 = 0;
|
|
for (int max = Math.max(0, min - 15); max < min; max++) {
|
|
int itemViewType = adapter.getItemViewType(max);
|
|
if (itemViewType != i4) {
|
|
view = null;
|
|
i4 = itemViewType;
|
|
}
|
|
view = adapter.getView(max, view, c);
|
|
if (view.getLayoutParams() == null) {
|
|
view.setLayoutParams(new ViewGroup.LayoutParams(-2, -2));
|
|
}
|
|
view.measure(makeMeasureSpec, makeMeasureSpec2);
|
|
i3 = Math.max(i3, view.getMeasuredWidth());
|
|
}
|
|
Drawable is_ = this.d.is_();
|
|
if (is_ != null) {
|
|
is_.getPadding(this.i);
|
|
i3 += this.i.left + this.i.right;
|
|
}
|
|
i3 += c.h.f6484o.getMeasuredWidth();
|
|
}
|
|
setMeasuredDimension(Math.min(Math.max(measuredWidth, i3), View.MeasureSpec.getSize(i)), getMeasuredHeight());
|
|
}
|
|
}
|
|
|
|
private TextInputLayout c() {
|
|
for (ViewParent parent = getParent(); parent != null; parent = parent.getParent()) {
|
|
if (parent instanceof TextInputLayout) {
|
|
return (TextInputLayout) parent;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes2.dex */
|
|
public class RVV<T> extends ArrayAdapter<String> {
|
|
ColorStateList b;
|
|
ColorStateList d;
|
|
private MaterialAutoCompleteTextView e;
|
|
|
|
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
|
|
RVV(MaterialAutoCompleteTextView materialAutoCompleteTextView, Context context, int i, String[] strArr) {
|
|
super(context, i, strArr);
|
|
this.e = materialAutoCompleteTextView;
|
|
this.b = Mx_();
|
|
this.d = Mw_();
|
|
}
|
|
|
|
@Override // android.widget.ArrayAdapter, android.widget.Adapter
|
|
public final View getView(int i, View view, ViewGroup viewGroup) {
|
|
View view2 = super.getView(i, view, viewGroup);
|
|
if (view2 instanceof TextView) {
|
|
TextView textView = (TextView) view2;
|
|
Drawable drawable = null;
|
|
if (this.e.getText().toString().contentEquals(textView.getText()) && this.e.e != 0) {
|
|
ColorDrawable colorDrawable = new ColorDrawable(this.e.e);
|
|
if (this.b != null) {
|
|
Tlu.pF_(colorDrawable, this.d);
|
|
drawable = new RippleDrawable(this.b, colorDrawable, null);
|
|
} else {
|
|
drawable = colorDrawable;
|
|
}
|
|
}
|
|
ViewCompat.sn_(textView, drawable);
|
|
}
|
|
return view2;
|
|
}
|
|
|
|
final ColorStateList Mw_() {
|
|
if (this.e.e == 0 || this.e.a == null) {
|
|
return null;
|
|
}
|
|
int[] iArr = {R.attr.state_hovered, -16842919};
|
|
int[] iArr2 = {R.attr.state_selected, -16842919};
|
|
int colorForState = this.e.a.getColorForState(iArr2, 0);
|
|
int colorForState2 = this.e.a.getColorForState(iArr, 0);
|
|
return new ColorStateList(new int[][]{iArr2, iArr, new int[0]}, new int[]{Rez.a(colorForState, this.e.e), Rez.a(colorForState2, this.e.e), this.e.e});
|
|
}
|
|
|
|
final ColorStateList Mx_() {
|
|
if (this.e.a == null) {
|
|
return null;
|
|
}
|
|
int[] iArr = {R.attr.state_pressed};
|
|
return new ColorStateList(new int[][]{iArr, new int[0]}, new int[]{this.e.a.getColorForState(iArr, 0), 0});
|
|
}
|
|
}
|
|
|
|
static /* synthetic */ void e(MaterialAutoCompleteTextView materialAutoCompleteTextView, Object obj) {
|
|
materialAutoCompleteTextView.setText(materialAutoCompleteTextView.convertSelectionToString(obj), false);
|
|
}
|
|
}
|