ADD week 5
This commit is contained in:
@@ -0,0 +1,356 @@
|
||||
package androidx.fragment.app;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/* loaded from: classes.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_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;
|
||||
}
|
||||
|
||||
static final class Op {
|
||||
int mCmd;
|
||||
Lifecycle.State mCurrentMaxState;
|
||||
int mEnterAnim;
|
||||
int mExitAnim;
|
||||
Fragment mFragment;
|
||||
Lifecycle.State mOldMaxState;
|
||||
int mPopEnterAnim;
|
||||
int mPopExitAnim;
|
||||
|
||||
Op() {
|
||||
}
|
||||
|
||||
Op(int i, Fragment fragment) {
|
||||
this.mCmd = i;
|
||||
this.mFragment = fragment;
|
||||
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.mOldMaxState = fragment.mMaxState;
|
||||
this.mCurrentMaxState = state;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public FragmentTransaction() {
|
||||
this.mOps = new ArrayList<>();
|
||||
this.mAllowAddToBackStack = true;
|
||||
this.mReorderingAllowed = false;
|
||||
this.mFragmentFactory = null;
|
||||
this.mClassLoader = null;
|
||||
}
|
||||
|
||||
FragmentTransaction(FragmentFactory fragmentFactory, ClassLoader classLoader) {
|
||||
this.mOps = new ArrayList<>();
|
||||
this.mAllowAddToBackStack = true;
|
||||
this.mReorderingAllowed = false;
|
||||
this.mFragmentFactory = fragmentFactory;
|
||||
this.mClassLoader = classLoader;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
FragmentTransaction add(ViewGroup viewGroup, Fragment fragment, String str) {
|
||||
fragment.mContainer = viewGroup;
|
||||
return add(viewGroup.getId(), fragment, str);
|
||||
}
|
||||
|
||||
void doAddOp(int i, Fragment fragment, String str, int i2) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user