303 lines
13 KiB
Java
303 lines
13 KiB
Java
package androidx.appcompat.app;
|
|
|
|
import android.R;
|
|
import android.content.Context;
|
|
import android.content.ContextWrapper;
|
|
import android.content.res.TypedArray;
|
|
import android.os.Build;
|
|
import android.util.AttributeSet;
|
|
import android.util.Log;
|
|
import android.view.InflateException;
|
|
import android.view.View;
|
|
import androidx.appcompat.R$styleable;
|
|
import androidx.appcompat.view.ContextThemeWrapper;
|
|
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
|
|
import androidx.appcompat.widget.AppCompatButton;
|
|
import androidx.appcompat.widget.AppCompatCheckBox;
|
|
import androidx.appcompat.widget.AppCompatCheckedTextView;
|
|
import androidx.appcompat.widget.AppCompatEditText;
|
|
import androidx.appcompat.widget.AppCompatImageButton;
|
|
import androidx.appcompat.widget.AppCompatImageView;
|
|
import androidx.appcompat.widget.AppCompatMultiAutoCompleteTextView;
|
|
import androidx.appcompat.widget.AppCompatRadioButton;
|
|
import androidx.appcompat.widget.AppCompatRatingBar;
|
|
import androidx.appcompat.widget.AppCompatSeekBar;
|
|
import androidx.appcompat.widget.AppCompatSpinner;
|
|
import androidx.appcompat.widget.AppCompatTextView;
|
|
import androidx.appcompat.widget.TintContextWrapper;
|
|
import androidx.collection.ArrayMap;
|
|
import androidx.core.view.ViewCompat;
|
|
import java.lang.reflect.Constructor;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class AppCompatViewInflater {
|
|
private static final String LOG_TAG = "AppCompatViewInflater";
|
|
private final Object[] mConstructorArgs = new Object[2];
|
|
private static final Class<?>[] sConstructorSignature = {Context.class, AttributeSet.class};
|
|
private static final int[] sOnClickAttrs = {R.attr.onClick};
|
|
private static final String[] sClassPrefixList = {"android.widget.", "android.view.", "android.webkit."};
|
|
private static final Map<String, Constructor<? extends View>> sConstructorMap = new ArrayMap();
|
|
|
|
private static class DeclaredOnClickListener implements View.OnClickListener {
|
|
private final View a;
|
|
private final String b;
|
|
private Method c;
|
|
private Context d;
|
|
|
|
public DeclaredOnClickListener(View view, String str) {
|
|
this.a = view;
|
|
this.b = str;
|
|
}
|
|
|
|
private void a(Context context, String str) {
|
|
String str2;
|
|
Method method;
|
|
while (context != null) {
|
|
try {
|
|
if (!context.isRestricted() && (method = context.getClass().getMethod(this.b, View.class)) != null) {
|
|
this.c = method;
|
|
this.d = context;
|
|
return;
|
|
}
|
|
} catch (NoSuchMethodException unused) {
|
|
}
|
|
context = context instanceof ContextWrapper ? ((ContextWrapper) context).getBaseContext() : null;
|
|
}
|
|
int id = this.a.getId();
|
|
if (id == -1) {
|
|
str2 = "";
|
|
} else {
|
|
str2 = " with id '" + this.a.getContext().getResources().getResourceEntryName(id) + "'";
|
|
}
|
|
throw new IllegalStateException("Could not find method " + this.b + "(View) in a parent or ancestor Context for android:onClick attribute defined on view " + this.a.getClass() + str2);
|
|
}
|
|
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
if (this.c == null) {
|
|
a(this.a.getContext(), this.b);
|
|
}
|
|
try {
|
|
this.c.invoke(this.d, view);
|
|
} catch (IllegalAccessException e) {
|
|
throw new IllegalStateException("Could not execute non-public method for android:onClick", e);
|
|
} catch (InvocationTargetException e2) {
|
|
throw new IllegalStateException("Could not execute method for android:onClick", e2);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void checkOnClickListener(View view, AttributeSet attributeSet) {
|
|
Context context = view.getContext();
|
|
if (context instanceof ContextWrapper) {
|
|
if (Build.VERSION.SDK_INT < 15 || ViewCompat.t(view)) {
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, sOnClickAttrs);
|
|
String string = obtainStyledAttributes.getString(0);
|
|
if (string != null) {
|
|
view.setOnClickListener(new DeclaredOnClickListener(view, string));
|
|
}
|
|
obtainStyledAttributes.recycle();
|
|
}
|
|
}
|
|
}
|
|
|
|
private View createViewByPrefix(Context context, String str, String str2) throws ClassNotFoundException, InflateException {
|
|
String str3;
|
|
Constructor<? extends View> constructor = sConstructorMap.get(str);
|
|
if (constructor == null) {
|
|
try {
|
|
ClassLoader classLoader = context.getClassLoader();
|
|
if (str2 != null) {
|
|
str3 = str2 + str;
|
|
} else {
|
|
str3 = str;
|
|
}
|
|
constructor = classLoader.loadClass(str3).asSubclass(View.class).getConstructor(sConstructorSignature);
|
|
sConstructorMap.put(str, constructor);
|
|
} catch (Exception unused) {
|
|
return null;
|
|
}
|
|
}
|
|
constructor.setAccessible(true);
|
|
return constructor.newInstance(this.mConstructorArgs);
|
|
}
|
|
|
|
private View createViewFromTag(Context context, String str, AttributeSet attributeSet) {
|
|
if (str.equals("view")) {
|
|
str = attributeSet.getAttributeValue(null, "class");
|
|
}
|
|
try {
|
|
this.mConstructorArgs[0] = context;
|
|
this.mConstructorArgs[1] = attributeSet;
|
|
if (-1 != str.indexOf(46)) {
|
|
return createViewByPrefix(context, str, null);
|
|
}
|
|
for (int i = 0; i < sClassPrefixList.length; i++) {
|
|
View createViewByPrefix = createViewByPrefix(context, str, sClassPrefixList[i]);
|
|
if (createViewByPrefix != null) {
|
|
return createViewByPrefix;
|
|
}
|
|
}
|
|
return null;
|
|
} catch (Exception unused) {
|
|
return null;
|
|
} finally {
|
|
Object[] objArr = this.mConstructorArgs;
|
|
objArr[0] = null;
|
|
objArr[1] = null;
|
|
}
|
|
}
|
|
|
|
private static Context themifyContext(Context context, AttributeSet attributeSet, boolean z, boolean z2) {
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R$styleable.View, 0, 0);
|
|
int resourceId = z ? obtainStyledAttributes.getResourceId(R$styleable.View_android_theme, 0) : 0;
|
|
if (z2 && resourceId == 0 && (resourceId = obtainStyledAttributes.getResourceId(R$styleable.View_theme, 0)) != 0) {
|
|
Log.i(LOG_TAG, "app:theme is now deprecated. Please move to using android:theme instead.");
|
|
}
|
|
obtainStyledAttributes.recycle();
|
|
return resourceId != 0 ? ((context instanceof ContextThemeWrapper) && ((ContextThemeWrapper) context).a() == resourceId) ? context : new ContextThemeWrapper(context, resourceId) : context;
|
|
}
|
|
|
|
private void verifyNotNull(View view, String str) {
|
|
if (view != null) {
|
|
return;
|
|
}
|
|
throw new IllegalStateException(getClass().getName() + " asked to inflate view for <" + str + ">, but returned null");
|
|
}
|
|
|
|
protected AppCompatAutoCompleteTextView createAutoCompleteTextView(Context context, AttributeSet attributeSet) {
|
|
return new AppCompatAutoCompleteTextView(context, attributeSet);
|
|
}
|
|
|
|
protected AppCompatButton createButton(Context context, AttributeSet attributeSet) {
|
|
return new AppCompatButton(context, attributeSet);
|
|
}
|
|
|
|
protected AppCompatCheckBox createCheckBox(Context context, AttributeSet attributeSet) {
|
|
return new AppCompatCheckBox(context, attributeSet);
|
|
}
|
|
|
|
protected AppCompatCheckedTextView createCheckedTextView(Context context, AttributeSet attributeSet) {
|
|
return new AppCompatCheckedTextView(context, attributeSet);
|
|
}
|
|
|
|
protected AppCompatEditText createEditText(Context context, AttributeSet attributeSet) {
|
|
return new AppCompatEditText(context, attributeSet);
|
|
}
|
|
|
|
protected AppCompatImageButton createImageButton(Context context, AttributeSet attributeSet) {
|
|
return new AppCompatImageButton(context, attributeSet);
|
|
}
|
|
|
|
protected AppCompatImageView createImageView(Context context, AttributeSet attributeSet) {
|
|
return new AppCompatImageView(context, attributeSet);
|
|
}
|
|
|
|
protected AppCompatMultiAutoCompleteTextView createMultiAutoCompleteTextView(Context context, AttributeSet attributeSet) {
|
|
return new AppCompatMultiAutoCompleteTextView(context, attributeSet);
|
|
}
|
|
|
|
protected AppCompatRadioButton createRadioButton(Context context, AttributeSet attributeSet) {
|
|
return new AppCompatRadioButton(context, attributeSet);
|
|
}
|
|
|
|
protected AppCompatRatingBar createRatingBar(Context context, AttributeSet attributeSet) {
|
|
return new AppCompatRatingBar(context, attributeSet);
|
|
}
|
|
|
|
protected AppCompatSeekBar createSeekBar(Context context, AttributeSet attributeSet) {
|
|
return new AppCompatSeekBar(context, attributeSet);
|
|
}
|
|
|
|
protected AppCompatSpinner createSpinner(Context context, AttributeSet attributeSet) {
|
|
return new AppCompatSpinner(context, attributeSet);
|
|
}
|
|
|
|
protected AppCompatTextView createTextView(Context context, AttributeSet attributeSet) {
|
|
return new AppCompatTextView(context, attributeSet);
|
|
}
|
|
|
|
protected View createView(Context context, String str, AttributeSet attributeSet) {
|
|
return null;
|
|
}
|
|
|
|
final View createView(View view, String str, Context context, AttributeSet attributeSet, boolean z, boolean z2, boolean z3, boolean z4) {
|
|
Context context2;
|
|
View createTextView;
|
|
context2 = (!z || view == null) ? context : view.getContext();
|
|
if (z2 || z3) {
|
|
context2 = themifyContext(context2, attributeSet, z2, z3);
|
|
}
|
|
if (z4) {
|
|
context2 = TintContextWrapper.b(context2);
|
|
}
|
|
switch (str) {
|
|
case "TextView":
|
|
createTextView = createTextView(context2, attributeSet);
|
|
verifyNotNull(createTextView, str);
|
|
break;
|
|
case "ImageView":
|
|
createTextView = createImageView(context2, attributeSet);
|
|
verifyNotNull(createTextView, str);
|
|
break;
|
|
case "Button":
|
|
createTextView = createButton(context2, attributeSet);
|
|
verifyNotNull(createTextView, str);
|
|
break;
|
|
case "EditText":
|
|
createTextView = createEditText(context2, attributeSet);
|
|
verifyNotNull(createTextView, str);
|
|
break;
|
|
case "Spinner":
|
|
createTextView = createSpinner(context2, attributeSet);
|
|
verifyNotNull(createTextView, str);
|
|
break;
|
|
case "ImageButton":
|
|
createTextView = createImageButton(context2, attributeSet);
|
|
verifyNotNull(createTextView, str);
|
|
break;
|
|
case "CheckBox":
|
|
createTextView = createCheckBox(context2, attributeSet);
|
|
verifyNotNull(createTextView, str);
|
|
break;
|
|
case "RadioButton":
|
|
createTextView = createRadioButton(context2, attributeSet);
|
|
verifyNotNull(createTextView, str);
|
|
break;
|
|
case "CheckedTextView":
|
|
createTextView = createCheckedTextView(context2, attributeSet);
|
|
verifyNotNull(createTextView, str);
|
|
break;
|
|
case "AutoCompleteTextView":
|
|
createTextView = createAutoCompleteTextView(context2, attributeSet);
|
|
verifyNotNull(createTextView, str);
|
|
break;
|
|
case "MultiAutoCompleteTextView":
|
|
createTextView = createMultiAutoCompleteTextView(context2, attributeSet);
|
|
verifyNotNull(createTextView, str);
|
|
break;
|
|
case "RatingBar":
|
|
createTextView = createRatingBar(context2, attributeSet);
|
|
verifyNotNull(createTextView, str);
|
|
break;
|
|
case "SeekBar":
|
|
createTextView = createSeekBar(context2, attributeSet);
|
|
verifyNotNull(createTextView, str);
|
|
break;
|
|
default:
|
|
createTextView = createView(context2, str, attributeSet);
|
|
break;
|
|
}
|
|
if (createTextView == null && context != context2) {
|
|
createTextView = createViewFromTag(context2, str, attributeSet);
|
|
}
|
|
if (createTextView != null) {
|
|
checkOnClickListener(createTextView, attributeSet);
|
|
}
|
|
return createTextView;
|
|
}
|
|
}
|