136 lines
4.2 KiB
Java
136 lines
4.2 KiB
Java
package androidx.appcompat.widget;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.graphics.Canvas;
|
|
import android.util.AttributeSet;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewParent;
|
|
import androidx.appcompat.R$styleable;
|
|
import java.lang.ref.WeakReference;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class ViewStubCompat extends View {
|
|
private int a;
|
|
private int b;
|
|
private WeakReference<View> c;
|
|
private LayoutInflater d;
|
|
private OnInflateListener e;
|
|
|
|
public interface OnInflateListener {
|
|
void a(ViewStubCompat viewStubCompat, View view);
|
|
}
|
|
|
|
public ViewStubCompat(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, 0);
|
|
}
|
|
|
|
public View a() {
|
|
ViewParent parent = getParent();
|
|
if (parent == null || !(parent instanceof ViewGroup)) {
|
|
throw new IllegalStateException("ViewStub must have a non-null ViewGroup viewParent");
|
|
}
|
|
if (this.a == 0) {
|
|
throw new IllegalArgumentException("ViewStub must have a valid layoutResource");
|
|
}
|
|
ViewGroup viewGroup = (ViewGroup) parent;
|
|
LayoutInflater layoutInflater = this.d;
|
|
if (layoutInflater == null) {
|
|
layoutInflater = LayoutInflater.from(getContext());
|
|
}
|
|
View inflate = layoutInflater.inflate(this.a, viewGroup, false);
|
|
int i = this.b;
|
|
if (i != -1) {
|
|
inflate.setId(i);
|
|
}
|
|
int indexOfChild = viewGroup.indexOfChild(this);
|
|
viewGroup.removeViewInLayout(this);
|
|
ViewGroup.LayoutParams layoutParams = getLayoutParams();
|
|
if (layoutParams != null) {
|
|
viewGroup.addView(inflate, indexOfChild, layoutParams);
|
|
} else {
|
|
viewGroup.addView(inflate, indexOfChild);
|
|
}
|
|
this.c = new WeakReference<>(inflate);
|
|
OnInflateListener onInflateListener = this.e;
|
|
if (onInflateListener != null) {
|
|
onInflateListener.a(this, inflate);
|
|
}
|
|
return inflate;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
protected void dispatchDraw(Canvas canvas) {
|
|
}
|
|
|
|
@Override // android.view.View
|
|
@SuppressLint({"MissingSuperCall"})
|
|
public void draw(Canvas canvas) {
|
|
}
|
|
|
|
public int getInflatedId() {
|
|
return this.b;
|
|
}
|
|
|
|
public LayoutInflater getLayoutInflater() {
|
|
return this.d;
|
|
}
|
|
|
|
public int getLayoutResource() {
|
|
return this.a;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
protected void onMeasure(int i, int i2) {
|
|
setMeasuredDimension(0, 0);
|
|
}
|
|
|
|
public void setInflatedId(int i) {
|
|
this.b = i;
|
|
}
|
|
|
|
public void setLayoutInflater(LayoutInflater layoutInflater) {
|
|
this.d = layoutInflater;
|
|
}
|
|
|
|
public void setLayoutResource(int i) {
|
|
this.a = i;
|
|
}
|
|
|
|
public void setOnInflateListener(OnInflateListener onInflateListener) {
|
|
this.e = onInflateListener;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void setVisibility(int i) {
|
|
WeakReference<View> weakReference = this.c;
|
|
if (weakReference != null) {
|
|
View view = weakReference.get();
|
|
if (view == null) {
|
|
throw new IllegalStateException("setVisibility called on un-referenced view");
|
|
}
|
|
view.setVisibility(i);
|
|
return;
|
|
}
|
|
super.setVisibility(i);
|
|
if (i == 0 || i == 4) {
|
|
a();
|
|
}
|
|
}
|
|
|
|
public ViewStubCompat(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
this.a = 0;
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R$styleable.ViewStubCompat, i, 0);
|
|
this.b = obtainStyledAttributes.getResourceId(R$styleable.ViewStubCompat_android_inflatedId, -1);
|
|
this.a = obtainStyledAttributes.getResourceId(R$styleable.ViewStubCompat_android_layout, 0);
|
|
setId(obtainStyledAttributes.getResourceId(R$styleable.ViewStubCompat_android_id, -1));
|
|
obtainStyledAttributes.recycle();
|
|
setVisibility(8);
|
|
setWillNotDraw(true);
|
|
}
|
|
}
|