Rabbit-R1/switch port/java/sources/androidx/fragment/app/FragmentTransaction.java
2024-05-21 17:08:36 -04:00

427 lines
16 KiB
Java

package androidx.fragment.app;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import androidx.core.view.ViewCompat;
import androidx.fragment.app.strictmode.FragmentStrictMode;
import androidx.lifecycle.Lifecycle;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Iterator;
/* loaded from: classes2.dex */
public abstract class FragmentTransaction {
static final int OP_ADD = 1;
static final int OP_ATTACH = 7;
static final int OP_DETACH = 6;
static final int OP_HIDE = 4;
static final int OP_NULL = 0;
static final int OP_REMOVE = 3;
static final int OP_REPLACE = 2;
static final int OP_SET_MAX_LIFECYCLE = 10;
static final int OP_SET_PRIMARY_NAV = 8;
static final int OP_SHOW = 5;
static final int OP_UNSET_PRIMARY_NAV = 9;
public static final int TRANSIT_ENTER_MASK = 4096;
public static final int TRANSIT_EXIT_MASK = 8192;
public static final int TRANSIT_FRAGMENT_CLOSE = 8194;
public static final int TRANSIT_FRAGMENT_FADE = 4099;
public static final int TRANSIT_FRAGMENT_MATCH_ACTIVITY_CLOSE = 8197;
public static final int TRANSIT_FRAGMENT_MATCH_ACTIVITY_OPEN = 4100;
public static final int TRANSIT_FRAGMENT_OPEN = 4097;
public static final int TRANSIT_NONE = 0;
public static final int TRANSIT_UNSET = -1;
boolean mAddToBackStack;
boolean mAllowAddToBackStack;
int mBreadCrumbShortTitleRes;
CharSequence mBreadCrumbShortTitleText;
int mBreadCrumbTitleRes;
CharSequence mBreadCrumbTitleText;
private final ClassLoader mClassLoader;
ArrayList<Runnable> mCommitRunnables;
int mEnterAnim;
int mExitAnim;
private final FragmentFactory mFragmentFactory;
String mName;
ArrayList<Op> mOps;
int mPopEnterAnim;
int mPopExitAnim;
boolean mReorderingAllowed;
ArrayList<String> mSharedElementSourceNames;
ArrayList<String> mSharedElementTargetNames;
int mTransition;
public abstract int commit();
public abstract int commitAllowingStateLoss();
public abstract void commitNow();
public abstract void commitNowAllowingStateLoss();
public boolean isAddToBackStackAllowed() {
return this.mAllowAddToBackStack;
}
@Deprecated
public FragmentTransaction setBreadCrumbShortTitle(int i) {
this.mBreadCrumbShortTitleRes = i;
this.mBreadCrumbShortTitleText = null;
return this;
}
@Deprecated
public FragmentTransaction setBreadCrumbShortTitle(CharSequence charSequence) {
this.mBreadCrumbShortTitleRes = 0;
this.mBreadCrumbShortTitleText = charSequence;
return this;
}
@Deprecated
public FragmentTransaction setBreadCrumbTitle(int i) {
this.mBreadCrumbTitleRes = i;
this.mBreadCrumbTitleText = null;
return this;
}
@Deprecated
public FragmentTransaction setBreadCrumbTitle(CharSequence charSequence) {
this.mBreadCrumbTitleRes = 0;
this.mBreadCrumbTitleText = charSequence;
return this;
}
public FragmentTransaction setCustomAnimations(int i, int i2, int i3, int i4) {
this.mEnterAnim = i;
this.mExitAnim = i2;
this.mPopEnterAnim = i3;
this.mPopExitAnim = i4;
return this;
}
public FragmentTransaction setReorderingAllowed(boolean z) {
this.mReorderingAllowed = z;
return this;
}
public FragmentTransaction setTransition(int i) {
this.mTransition = i;
return this;
}
@Deprecated
public FragmentTransaction setTransitionStyle(int i) {
return this;
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class Op {
int mCmd;
Lifecycle.State mCurrentMaxState;
int mEnterAnim;
int mExitAnim;
Fragment mFragment;
boolean mFromExpandedOp;
Lifecycle.State mOldMaxState;
int mPopEnterAnim;
int mPopExitAnim;
/* JADX INFO: Access modifiers changed from: package-private */
public Op() {
}
/* JADX INFO: Access modifiers changed from: package-private */
public Op(int i, Fragment fragment) {
this.mCmd = i;
this.mFragment = fragment;
this.mFromExpandedOp = false;
this.mOldMaxState = Lifecycle.State.RESUMED;
this.mCurrentMaxState = Lifecycle.State.RESUMED;
}
/* JADX INFO: Access modifiers changed from: package-private */
public Op(int i, Fragment fragment, boolean z) {
this.mCmd = i;
this.mFragment = fragment;
this.mFromExpandedOp = z;
this.mOldMaxState = Lifecycle.State.RESUMED;
this.mCurrentMaxState = Lifecycle.State.RESUMED;
}
Op(int i, Fragment fragment, Lifecycle.State state) {
this.mCmd = i;
this.mFragment = fragment;
this.mFromExpandedOp = false;
this.mOldMaxState = fragment.mMaxState;
this.mCurrentMaxState = state;
}
Op(Op op) {
this.mCmd = op.mCmd;
this.mFragment = op.mFragment;
this.mFromExpandedOp = op.mFromExpandedOp;
this.mEnterAnim = op.mEnterAnim;
this.mExitAnim = op.mExitAnim;
this.mPopEnterAnim = op.mPopEnterAnim;
this.mPopExitAnim = op.mPopExitAnim;
this.mOldMaxState = op.mOldMaxState;
this.mCurrentMaxState = op.mCurrentMaxState;
}
}
@Deprecated
public FragmentTransaction() {
this.mOps = new ArrayList<>();
this.mAllowAddToBackStack = true;
this.mReorderingAllowed = false;
this.mFragmentFactory = null;
this.mClassLoader = null;
}
/* JADX INFO: Access modifiers changed from: package-private */
public FragmentTransaction(FragmentFactory fragmentFactory, ClassLoader classLoader) {
this.mOps = new ArrayList<>();
this.mAllowAddToBackStack = true;
this.mReorderingAllowed = false;
this.mFragmentFactory = fragmentFactory;
this.mClassLoader = classLoader;
}
/* JADX INFO: Access modifiers changed from: package-private */
public FragmentTransaction(FragmentFactory fragmentFactory, ClassLoader classLoader, FragmentTransaction fragmentTransaction) {
this(fragmentFactory, classLoader);
Iterator<Op> it = fragmentTransaction.mOps.iterator();
while (it.hasNext()) {
this.mOps.add(new Op(it.next()));
}
this.mEnterAnim = fragmentTransaction.mEnterAnim;
this.mExitAnim = fragmentTransaction.mExitAnim;
this.mPopEnterAnim = fragmentTransaction.mPopEnterAnim;
this.mPopExitAnim = fragmentTransaction.mPopExitAnim;
this.mTransition = fragmentTransaction.mTransition;
this.mAddToBackStack = fragmentTransaction.mAddToBackStack;
this.mAllowAddToBackStack = fragmentTransaction.mAllowAddToBackStack;
this.mName = fragmentTransaction.mName;
this.mBreadCrumbShortTitleRes = fragmentTransaction.mBreadCrumbShortTitleRes;
this.mBreadCrumbShortTitleText = fragmentTransaction.mBreadCrumbShortTitleText;
this.mBreadCrumbTitleRes = fragmentTransaction.mBreadCrumbTitleRes;
this.mBreadCrumbTitleText = fragmentTransaction.mBreadCrumbTitleText;
if (fragmentTransaction.mSharedElementSourceNames != null) {
ArrayList<String> arrayList = new ArrayList<>();
this.mSharedElementSourceNames = arrayList;
arrayList.addAll(fragmentTransaction.mSharedElementSourceNames);
}
if (fragmentTransaction.mSharedElementTargetNames != null) {
ArrayList<String> arrayList2 = new ArrayList<>();
this.mSharedElementTargetNames = arrayList2;
arrayList2.addAll(fragmentTransaction.mSharedElementTargetNames);
}
this.mReorderingAllowed = fragmentTransaction.mReorderingAllowed;
}
/* JADX INFO: Access modifiers changed from: package-private */
public void addOp(Op op) {
this.mOps.add(op);
op.mEnterAnim = this.mEnterAnim;
op.mExitAnim = this.mExitAnim;
op.mPopEnterAnim = this.mPopEnterAnim;
op.mPopExitAnim = this.mPopExitAnim;
}
private Fragment createFragment(Class<? extends Fragment> cls, Bundle bundle) {
FragmentFactory fragmentFactory = this.mFragmentFactory;
if (fragmentFactory == null) {
throw new IllegalStateException("Creating a Fragment requires that this FragmentTransaction was built with FragmentManager.beginTransaction()");
}
ClassLoader classLoader = this.mClassLoader;
if (classLoader == null) {
throw new IllegalStateException("The FragmentManager must be attached to itshost to create a Fragment");
}
Fragment instantiate = fragmentFactory.instantiate(classLoader, cls.getName());
if (bundle != null) {
instantiate.setArguments(bundle);
}
return instantiate;
}
public final FragmentTransaction add(Class<? extends Fragment> cls, Bundle bundle, String str) {
return add(createFragment(cls, bundle), str);
}
public FragmentTransaction add(Fragment fragment, String str) {
doAddOp(0, fragment, str, 1);
return this;
}
public final FragmentTransaction add(int i, Class<? extends Fragment> cls, Bundle bundle) {
return add(i, createFragment(cls, bundle));
}
public FragmentTransaction add(int i, Fragment fragment) {
doAddOp(i, fragment, null, 1);
return this;
}
public final FragmentTransaction add(int i, Class<? extends Fragment> cls, Bundle bundle, String str) {
return add(i, createFragment(cls, bundle), str);
}
public FragmentTransaction add(int i, Fragment fragment, String str) {
doAddOp(i, fragment, str, 1);
return this;
}
/* JADX INFO: Access modifiers changed from: package-private */
public FragmentTransaction add(ViewGroup viewGroup, Fragment fragment, String str) {
fragment.mContainer = viewGroup;
return add(viewGroup.getId(), fragment, str);
}
/* JADX INFO: Access modifiers changed from: package-private */
public void doAddOp(int i, Fragment fragment, String str, int i2) {
if (fragment.mPreviousWho != null) {
FragmentStrictMode.onFragmentReuse(fragment, fragment.mPreviousWho);
}
Class<?> cls = fragment.getClass();
int modifiers = cls.getModifiers();
if (cls.isAnonymousClass() || !Modifier.isPublic(modifiers) || (cls.isMemberClass() && !Modifier.isStatic(modifiers))) {
throw new IllegalStateException("Fragment " + cls.getCanonicalName() + " must be a public static class to be properly recreated from instance state.");
}
if (str != null) {
if (fragment.mTag != null && !str.equals(fragment.mTag)) {
throw new IllegalStateException("Can't change tag of fragment " + fragment + ": was " + fragment.mTag + " now " + str);
}
fragment.mTag = str;
}
if (i != 0) {
if (i == -1) {
throw new IllegalArgumentException("Can't add fragment " + fragment + " with tag " + str + " to container view with no id");
}
if (fragment.mFragmentId != 0 && fragment.mFragmentId != i) {
throw new IllegalStateException("Can't change container ID of fragment " + fragment + ": was " + fragment.mFragmentId + " now " + i);
}
fragment.mFragmentId = i;
fragment.mContainerId = i;
}
addOp(new Op(i2, fragment));
}
public final FragmentTransaction replace(int i, Class<? extends Fragment> cls, Bundle bundle) {
return replace(i, cls, bundle, null);
}
public FragmentTransaction replace(int i, Fragment fragment) {
return replace(i, fragment, (String) null);
}
public final FragmentTransaction replace(int i, Class<? extends Fragment> cls, Bundle bundle, String str) {
return replace(i, createFragment(cls, bundle), str);
}
public FragmentTransaction replace(int i, Fragment fragment, String str) {
if (i == 0) {
throw new IllegalArgumentException("Must use non-zero containerViewId");
}
doAddOp(i, fragment, str, 2);
return this;
}
public FragmentTransaction remove(Fragment fragment) {
addOp(new Op(3, fragment));
return this;
}
public FragmentTransaction hide(Fragment fragment) {
addOp(new Op(4, fragment));
return this;
}
public FragmentTransaction show(Fragment fragment) {
addOp(new Op(5, fragment));
return this;
}
public FragmentTransaction detach(Fragment fragment) {
addOp(new Op(6, fragment));
return this;
}
public FragmentTransaction attach(Fragment fragment) {
addOp(new Op(7, fragment));
return this;
}
public FragmentTransaction setPrimaryNavigationFragment(Fragment fragment) {
addOp(new Op(8, fragment));
return this;
}
public FragmentTransaction setMaxLifecycle(Fragment fragment, Lifecycle.State state) {
addOp(new Op(10, fragment, state));
return this;
}
public boolean isEmpty() {
return this.mOps.isEmpty();
}
public FragmentTransaction setCustomAnimations(int i, int i2) {
return setCustomAnimations(i, i2, 0, 0);
}
public FragmentTransaction addSharedElement(View view, String str) {
if (FragmentTransition.supportsTransition()) {
String transitionName = ViewCompat.getTransitionName(view);
if (transitionName == null) {
throw new IllegalArgumentException("Unique transitionNames are required for all sharedElements");
}
if (this.mSharedElementSourceNames == null) {
this.mSharedElementSourceNames = new ArrayList<>();
this.mSharedElementTargetNames = new ArrayList<>();
} else {
if (this.mSharedElementTargetNames.contains(str)) {
throw new IllegalArgumentException("A shared element with the target name '" + str + "' has already been added to the transaction.");
}
if (this.mSharedElementSourceNames.contains(transitionName)) {
throw new IllegalArgumentException("A shared element with the source name '" + transitionName + "' has already been added to the transaction.");
}
}
this.mSharedElementSourceNames.add(transitionName);
this.mSharedElementTargetNames.add(str);
}
return this;
}
public FragmentTransaction addToBackStack(String str) {
if (!this.mAllowAddToBackStack) {
throw new IllegalStateException("This FragmentTransaction is not allowed to be added to the back stack.");
}
this.mAddToBackStack = true;
this.mName = str;
return this;
}
public FragmentTransaction disallowAddToBackStack() {
if (this.mAddToBackStack) {
throw new IllegalStateException("This transaction is already being added to the back stack");
}
this.mAllowAddToBackStack = false;
return this;
}
@Deprecated
public FragmentTransaction setAllowOptimization(boolean z) {
return setReorderingAllowed(z);
}
public FragmentTransaction runOnCommit(Runnable runnable) {
disallowAddToBackStack();
if (this.mCommitRunnables == null) {
this.mCommitRunnables = new ArrayList<>();
}
this.mCommitRunnables.add(runnable);
return this;
}
}