package androidx.fragment.app; import android.animation.LayoutTransition; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.os.Bundle; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; import android.view.WindowInsets; import android.widget.FrameLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.fragment.R; import c.d.b.a.a; import java.util.ArrayList; public final class FragmentContainerView extends FrameLayout { private ArrayList mDisappearingFragmentChildren; private boolean mDrawDisappearingViewsFirst; private ArrayList mTransitioningFragmentViews; public FragmentContainerView(@NonNull Context context) { super(context); this.mDrawDisappearingViewsFirst = true; } public FragmentContainerView(@NonNull Context context, @Nullable AttributeSet attributeSet) { this(context, attributeSet, 0); } public FragmentContainerView(@NonNull Context context, @Nullable AttributeSet attributeSet, int i) { super(context, attributeSet, i); String str; this.mDrawDisappearingViewsFirst = true; if (attributeSet != null) { String classAttribute = attributeSet.getClassAttribute(); TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.FragmentContainerView); if (classAttribute == null) { classAttribute = obtainStyledAttributes.getString(R.styleable.FragmentContainerView_android_name); str = "android:name"; } else { str = "class"; } obtainStyledAttributes.recycle(); if (classAttribute != null && !isInEditMode()) { throw new UnsupportedOperationException("FragmentContainerView must be within a FragmentActivity to use " + str + "=\"" + classAttribute + "\""); } } } public FragmentContainerView(@NonNull Context context, @NonNull AttributeSet attributeSet, @NonNull FragmentManager fragmentManager) { super(context, attributeSet); this.mDrawDisappearingViewsFirst = true; String classAttribute = attributeSet.getClassAttribute(); TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.FragmentContainerView); classAttribute = classAttribute == null ? obtainStyledAttributes.getString(R.styleable.FragmentContainerView_android_name) : classAttribute; String string = obtainStyledAttributes.getString(R.styleable.FragmentContainerView_android_tag); obtainStyledAttributes.recycle(); int id2 = getId(); Fragment findFragmentById = fragmentManager.findFragmentById(id2); if (classAttribute != null && findFragmentById == null) { if (id2 <= 0) { throw new IllegalStateException(a.u("FragmentContainerView must have an android:id to add Fragment ", classAttribute, string != null ? a.t(" with tag ", string) : "")); } Fragment instantiate = fragmentManager.getFragmentFactory().instantiate(context.getClassLoader(), classAttribute); instantiate.onInflate(context, attributeSet, (Bundle) null); fragmentManager.beginTransaction().setReorderingAllowed(true).add(this, instantiate, string).commitNowAllowingStateLoss(); } } private void addDisappearingFragmentView(@NonNull View view) { ArrayList arrayList = this.mTransitioningFragmentViews; if (arrayList != null && arrayList.contains(view)) { if (this.mDisappearingFragmentChildren == null) { this.mDisappearingFragmentChildren = new ArrayList<>(); } this.mDisappearingFragmentChildren.add(view); } } @Override // android.view.ViewGroup public void addView(@NonNull View view, int i, @Nullable ViewGroup.LayoutParams layoutParams) { if (FragmentManager.getViewFragment(view) != null) { super.addView(view, i, layoutParams); return; } throw new IllegalStateException("Views added to a FragmentContainerView must be associated with a Fragment. View " + view + " is not associated with a Fragment."); } @Override // android.view.ViewGroup public boolean addViewInLayout(@NonNull View view, int i, @Nullable ViewGroup.LayoutParams layoutParams, boolean z2) { if (FragmentManager.getViewFragment(view) != null) { return super.addViewInLayout(view, i, layoutParams, z2); } throw new IllegalStateException("Views added to a FragmentContainerView must be associated with a Fragment. View " + view + " is not associated with a Fragment."); } @Override // android.view.View, android.view.ViewGroup public void dispatchDraw(@NonNull Canvas canvas) { if (this.mDrawDisappearingViewsFirst && this.mDisappearingFragmentChildren != null) { for (int i = 0; i < this.mDisappearingFragmentChildren.size(); i++) { super.drawChild(canvas, this.mDisappearingFragmentChildren.get(i), getDrawingTime()); } } super.dispatchDraw(canvas); } @Override // android.view.ViewGroup public boolean drawChild(@NonNull Canvas canvas, @NonNull View view, long j) { ArrayList arrayList; if (!this.mDrawDisappearingViewsFirst || (arrayList = this.mDisappearingFragmentChildren) == null || arrayList.size() <= 0 || !this.mDisappearingFragmentChildren.contains(view)) { return super.drawChild(canvas, view, j); } return false; } @Override // android.view.ViewGroup public void endViewTransition(@NonNull View view) { ArrayList arrayList = this.mTransitioningFragmentViews; if (arrayList != null) { arrayList.remove(view); ArrayList arrayList2 = this.mDisappearingFragmentChildren; if (arrayList2 != null && arrayList2.remove(view)) { this.mDrawDisappearingViewsFirst = true; } } super.endViewTransition(view); } @Override // android.view.View @NonNull @RequiresApi(20) public WindowInsets onApplyWindowInsets(@NonNull WindowInsets windowInsets) { for (int i = 0; i < getChildCount(); i++) { getChildAt(i).dispatchApplyWindowInsets(new WindowInsets(windowInsets)); } return windowInsets; } @Override // android.view.ViewGroup public void removeAllViewsInLayout() { for (int childCount = getChildCount() - 1; childCount >= 0; childCount--) { addDisappearingFragmentView(getChildAt(childCount)); } super.removeAllViewsInLayout(); } @Override // android.view.ViewGroup public void removeDetachedView(@NonNull View view, boolean z2) { if (z2) { addDisappearingFragmentView(view); } super.removeDetachedView(view, z2); } @Override // android.view.ViewGroup, android.view.ViewManager public void removeView(@NonNull View view) { addDisappearingFragmentView(view); super.removeView(view); } @Override // android.view.ViewGroup public void removeViewAt(int i) { addDisappearingFragmentView(getChildAt(i)); super.removeViewAt(i); } @Override // android.view.ViewGroup public void removeViewInLayout(@NonNull View view) { addDisappearingFragmentView(view); super.removeViewInLayout(view); } @Override // android.view.ViewGroup public void removeViews(int i, int i2) { for (int i3 = i; i3 < i + i2; i3++) { addDisappearingFragmentView(getChildAt(i3)); } super.removeViews(i, i2); } @Override // android.view.ViewGroup public void removeViewsInLayout(int i, int i2) { for (int i3 = i; i3 < i + i2; i3++) { addDisappearingFragmentView(getChildAt(i3)); } super.removeViewsInLayout(i, i2); } public void setDrawDisappearingViewsLast(boolean z2) { this.mDrawDisappearingViewsFirst = z2; } @Override // android.view.ViewGroup public void setLayoutTransition(@Nullable LayoutTransition layoutTransition) { throw new UnsupportedOperationException("FragmentContainerView does not support Layout Transitions or animateLayoutChanges=\"true\"."); } @Override // android.view.ViewGroup public void startViewTransition(@NonNull View view) { if (view.getParent() == this) { if (this.mTransitioningFragmentViews == null) { this.mTransitioningFragmentViews = new ArrayList<>(); } this.mTransitioningFragmentViews.add(view); } super.startViewTransition(view); } }