2652 lines
110 KiB
Java
2652 lines
110 KiB
Java
package androidx.fragment.app;
|
|
|
|
import android.animation.Animator;
|
|
import android.animation.AnimatorListenerAdapter;
|
|
import android.annotation.SuppressLint;
|
|
import android.content.Context;
|
|
import android.content.ContextWrapper;
|
|
import android.content.Intent;
|
|
import android.content.IntentSender;
|
|
import android.content.res.Configuration;
|
|
import android.os.Bundle;
|
|
import android.os.Looper;
|
|
import android.os.Parcel;
|
|
import android.os.Parcelable;
|
|
import android.util.Log;
|
|
import android.view.LayoutInflater;
|
|
import android.view.Menu;
|
|
import android.view.MenuInflater;
|
|
import android.view.MenuItem;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewParent;
|
|
import android.view.animation.Animation;
|
|
import androidx.activity.OnBackPressedCallback;
|
|
import androidx.activity.OnBackPressedDispatcher;
|
|
import androidx.activity.OnBackPressedDispatcherOwner;
|
|
import androidx.activity.result.ActivityResult;
|
|
import androidx.activity.result.ActivityResultCallback;
|
|
import androidx.activity.result.ActivityResultLauncher;
|
|
import androidx.activity.result.ActivityResultRegistry;
|
|
import androidx.activity.result.ActivityResultRegistryOwner;
|
|
import androidx.activity.result.IntentSenderRequest;
|
|
import androidx.activity.result.contract.ActivityResultContract;
|
|
import androidx.activity.result.contract.ActivityResultContracts;
|
|
import androidx.annotation.IdRes;
|
|
import androidx.annotation.MainThread;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.annotation.StringRes;
|
|
import androidx.collection.ArraySet;
|
|
import androidx.core.os.CancellationSignal;
|
|
import androidx.fragment.R;
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.fragment.app.FragmentAnim;
|
|
import androidx.fragment.app.FragmentTransaction;
|
|
import androidx.fragment.app.FragmentTransition;
|
|
import androidx.lifecycle.Lifecycle;
|
|
import androidx.lifecycle.LifecycleEventObserver;
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
import androidx.lifecycle.ViewModelStore;
|
|
import androidx.lifecycle.ViewModelStoreOwner;
|
|
import c.d.b.a.a;
|
|
import java.io.FileDescriptor;
|
|
import java.io.PrintWriter;
|
|
import java.util.ArrayDeque;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
public abstract class FragmentManager implements FragmentResultOwner {
|
|
private static boolean DEBUG = false;
|
|
private static final String EXTRA_CREATED_FILLIN_INTENT = "androidx.fragment.extra.ACTIVITY_OPTIONS_BUNDLE";
|
|
public static final int POP_BACK_STACK_INCLUSIVE = 1;
|
|
public static final String TAG = "FragmentManager";
|
|
public static boolean USE_STATE_MANAGER = true;
|
|
public ArrayList<BackStackRecord> mBackStack;
|
|
private ArrayList<OnBackStackChangedListener> mBackStackChangeListeners;
|
|
private final AtomicInteger mBackStackIndex = new AtomicInteger();
|
|
private FragmentContainer mContainer;
|
|
private ArrayList<Fragment> mCreatedMenus;
|
|
public int mCurState = -1;
|
|
private SpecialEffectsControllerFactory mDefaultSpecialEffectsControllerFactory = new AnonymousClass4();
|
|
private boolean mDestroyed;
|
|
private Runnable mExecCommit = new AnonymousClass5();
|
|
private boolean mExecutingActions;
|
|
private Map<Fragment, HashSet<CancellationSignal>> mExitAnimationCancellationSignals = Collections.synchronizedMap(new HashMap());
|
|
private FragmentFactory mFragmentFactory = null;
|
|
private final FragmentStore mFragmentStore = new FragmentStore();
|
|
private final FragmentTransition.Callback mFragmentTransitionCallback = new AnonymousClass2();
|
|
private boolean mHavePendingDeferredStart;
|
|
private FragmentHostCallback<?> mHost;
|
|
private FragmentFactory mHostFragmentFactory = new AnonymousClass3();
|
|
public ArrayDeque<LaunchedFragmentInfo> mLaunchedFragments = new ArrayDeque<>();
|
|
private final FragmentLayoutInflaterFactory mLayoutInflaterFactory = new FragmentLayoutInflaterFactory(this);
|
|
private final FragmentLifecycleCallbacksDispatcher mLifecycleCallbacksDispatcher = new FragmentLifecycleCallbacksDispatcher(this);
|
|
private boolean mNeedMenuInvalidate;
|
|
private FragmentManagerViewModel mNonConfig;
|
|
private final CopyOnWriteArrayList<FragmentOnAttachListener> mOnAttachListeners = new CopyOnWriteArrayList<>();
|
|
private final OnBackPressedCallback mOnBackPressedCallback = new AnonymousClass1(false);
|
|
private OnBackPressedDispatcher mOnBackPressedDispatcher;
|
|
private Fragment mParent;
|
|
private final ArrayList<OpGenerator> mPendingActions = new ArrayList<>();
|
|
private ArrayList<StartEnterTransitionListener> mPostponedTransactions;
|
|
@Nullable
|
|
public Fragment mPrimaryNav;
|
|
private ActivityResultLauncher<String[]> mRequestPermissions;
|
|
private final Map<String, LifecycleAwareResultListener> mResultListeners = Collections.synchronizedMap(new HashMap());
|
|
private final Map<String, Bundle> mResults = Collections.synchronizedMap(new HashMap());
|
|
private SpecialEffectsControllerFactory mSpecialEffectsControllerFactory = null;
|
|
private ActivityResultLauncher<Intent> mStartActivityForResult;
|
|
private ActivityResultLauncher<IntentSenderRequest> mStartIntentSenderForResult;
|
|
private boolean mStateSaved;
|
|
private boolean mStopped;
|
|
private ArrayList<Fragment> mTmpAddedFragments;
|
|
private ArrayList<Boolean> mTmpIsPop;
|
|
private ArrayList<BackStackRecord> mTmpRecords;
|
|
|
|
/* renamed from: androidx.fragment.app.FragmentManager$1 reason: invalid class name */
|
|
public class AnonymousClass1 extends OnBackPressedCallback {
|
|
public AnonymousClass1(boolean z2) {
|
|
super(z2);
|
|
}
|
|
|
|
@Override // androidx.activity.OnBackPressedCallback
|
|
public void handleOnBackPressed() {
|
|
FragmentManager.this.handleOnBackPressed();
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.FragmentManager$10 reason: invalid class name */
|
|
public class AnonymousClass10 implements ActivityResultCallback<ActivityResult> {
|
|
public AnonymousClass10() {
|
|
}
|
|
|
|
public void onActivityResult(ActivityResult activityResult) {
|
|
LaunchedFragmentInfo pollFirst = FragmentManager.this.mLaunchedFragments.pollFirst();
|
|
if (pollFirst == null) {
|
|
Log.w("FragmentManager", "No IntentSenders were started for " + this);
|
|
return;
|
|
}
|
|
String str = pollFirst.mWho;
|
|
int i = pollFirst.mRequestCode;
|
|
Fragment findFragmentByWho = FragmentManager.access$200(FragmentManager.this).findFragmentByWho(str);
|
|
if (findFragmentByWho == null) {
|
|
a.h0("Intent Sender result delivered for unknown Fragment ", str, "FragmentManager");
|
|
} else {
|
|
findFragmentByWho.onActivityResult(i, activityResult.getResultCode(), activityResult.getData());
|
|
}
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.FragmentManager$11 reason: invalid class name */
|
|
public class AnonymousClass11 implements ActivityResultCallback<Map<String, Boolean>> {
|
|
public AnonymousClass11() {
|
|
}
|
|
|
|
@SuppressLint({"SyntheticAccessor"})
|
|
public void onActivityResult(Map<String, Boolean> map) {
|
|
String[] strArr = (String[]) map.keySet().toArray(new String[0]);
|
|
ArrayList arrayList = new ArrayList(map.values());
|
|
int[] iArr = new int[arrayList.size()];
|
|
for (int i = 0; i < arrayList.size(); i++) {
|
|
iArr[i] = ((Boolean) arrayList.get(i)).booleanValue() ? 0 : -1;
|
|
}
|
|
LaunchedFragmentInfo pollFirst = FragmentManager.this.mLaunchedFragments.pollFirst();
|
|
if (pollFirst == null) {
|
|
Log.w("FragmentManager", "No permissions were requested for " + this);
|
|
return;
|
|
}
|
|
String str = pollFirst.mWho;
|
|
int i2 = pollFirst.mRequestCode;
|
|
Fragment findFragmentByWho = FragmentManager.access$200(FragmentManager.this).findFragmentByWho(str);
|
|
if (findFragmentByWho == null) {
|
|
a.h0("Permission request result delivered for unknown Fragment ", str, "FragmentManager");
|
|
} else {
|
|
findFragmentByWho.onRequestPermissionsResult(i2, strArr, iArr);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.FragmentManager$2 reason: invalid class name */
|
|
public class AnonymousClass2 implements FragmentTransition.Callback {
|
|
public AnonymousClass2() {
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentTransition.Callback
|
|
public void onComplete(@NonNull Fragment fragment, @NonNull CancellationSignal cancellationSignal) {
|
|
if (!cancellationSignal.isCanceled()) {
|
|
FragmentManager.this.removeCancellationSignal(fragment, cancellationSignal);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentTransition.Callback
|
|
public void onStart(@NonNull Fragment fragment, @NonNull CancellationSignal cancellationSignal) {
|
|
FragmentManager.this.addCancellationSignal(fragment, cancellationSignal);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.FragmentManager$3 reason: invalid class name */
|
|
public class AnonymousClass3 extends FragmentFactory {
|
|
public AnonymousClass3() {
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentFactory
|
|
@NonNull
|
|
public Fragment instantiate(@NonNull ClassLoader classLoader, @NonNull String str) {
|
|
return FragmentManager.this.getHost().instantiate(FragmentManager.this.getHost().getContext(), str, null);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.FragmentManager$4 reason: invalid class name */
|
|
public class AnonymousClass4 implements SpecialEffectsControllerFactory {
|
|
public AnonymousClass4() {
|
|
}
|
|
|
|
@Override // androidx.fragment.app.SpecialEffectsControllerFactory
|
|
@NonNull
|
|
public SpecialEffectsController createController(@NonNull ViewGroup viewGroup) {
|
|
return new DefaultSpecialEffectsController(viewGroup);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.FragmentManager$5 reason: invalid class name */
|
|
public class AnonymousClass5 implements Runnable {
|
|
public AnonymousClass5() {
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
FragmentManager.this.execPendingActions(true);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.FragmentManager$6 reason: invalid class name */
|
|
public class AnonymousClass6 implements LifecycleEventObserver {
|
|
public final /* synthetic */ Lifecycle val$lifecycle;
|
|
public final /* synthetic */ FragmentResultListener val$listener;
|
|
public final /* synthetic */ String val$requestKey;
|
|
|
|
public AnonymousClass6(String str, FragmentResultListener fragmentResultListener, Lifecycle lifecycle) {
|
|
this.val$requestKey = str;
|
|
this.val$listener = fragmentResultListener;
|
|
this.val$lifecycle = lifecycle;
|
|
}
|
|
|
|
@Override // androidx.lifecycle.LifecycleEventObserver
|
|
public void onStateChanged(@NonNull LifecycleOwner lifecycleOwner, @NonNull Lifecycle.Event event) {
|
|
Bundle bundle;
|
|
if (event == Lifecycle.Event.ON_START && (bundle = (Bundle) FragmentManager.access$000(FragmentManager.this).get(this.val$requestKey)) != null) {
|
|
this.val$listener.onFragmentResult(this.val$requestKey, bundle);
|
|
FragmentManager.this.clearFragmentResult(this.val$requestKey);
|
|
}
|
|
if (event == Lifecycle.Event.ON_DESTROY) {
|
|
this.val$lifecycle.removeObserver(this);
|
|
FragmentManager.access$100(FragmentManager.this).remove(this.val$requestKey);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.FragmentManager$7 reason: invalid class name */
|
|
public class AnonymousClass7 extends AnimatorListenerAdapter {
|
|
public final /* synthetic */ View val$animatingView;
|
|
public final /* synthetic */ ViewGroup val$container;
|
|
public final /* synthetic */ Fragment val$fragment;
|
|
|
|
public AnonymousClass7(ViewGroup viewGroup, View view, Fragment fragment) {
|
|
this.val$container = viewGroup;
|
|
this.val$animatingView = view;
|
|
this.val$fragment = fragment;
|
|
}
|
|
|
|
@Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
|
|
public void onAnimationEnd(Animator animator) {
|
|
this.val$container.endViewTransition(this.val$animatingView);
|
|
animator.removeListener(this);
|
|
Fragment fragment = this.val$fragment;
|
|
View view = fragment.mView;
|
|
if (view != null && fragment.mHidden) {
|
|
view.setVisibility(8);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.FragmentManager$8 reason: invalid class name */
|
|
public class AnonymousClass8 implements FragmentOnAttachListener {
|
|
public final /* synthetic */ Fragment val$parent;
|
|
|
|
public AnonymousClass8(Fragment fragment) {
|
|
this.val$parent = fragment;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentOnAttachListener
|
|
public void onAttachFragment(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment) {
|
|
this.val$parent.onAttachFragment(fragment);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.FragmentManager$9 reason: invalid class name */
|
|
public class AnonymousClass9 implements ActivityResultCallback<ActivityResult> {
|
|
public AnonymousClass9() {
|
|
}
|
|
|
|
public void onActivityResult(ActivityResult activityResult) {
|
|
LaunchedFragmentInfo pollFirst = FragmentManager.this.mLaunchedFragments.pollFirst();
|
|
if (pollFirst == null) {
|
|
Log.w("FragmentManager", "No Activities were started for result for " + this);
|
|
return;
|
|
}
|
|
String str = pollFirst.mWho;
|
|
int i = pollFirst.mRequestCode;
|
|
Fragment findFragmentByWho = FragmentManager.access$200(FragmentManager.this).findFragmentByWho(str);
|
|
if (findFragmentByWho == null) {
|
|
a.h0("Activity result delivered for unknown Fragment ", str, "FragmentManager");
|
|
} else {
|
|
findFragmentByWho.onActivityResult(i, activityResult.getResultCode(), activityResult.getData());
|
|
}
|
|
}
|
|
}
|
|
|
|
public interface BackStackEntry {
|
|
@Nullable
|
|
@Deprecated
|
|
CharSequence getBreadCrumbShortTitle();
|
|
|
|
@StringRes
|
|
@Deprecated
|
|
int getBreadCrumbShortTitleRes();
|
|
|
|
@Nullable
|
|
@Deprecated
|
|
CharSequence getBreadCrumbTitle();
|
|
|
|
@StringRes
|
|
@Deprecated
|
|
int getBreadCrumbTitleRes();
|
|
|
|
int getId();
|
|
|
|
@Nullable
|
|
String getName();
|
|
}
|
|
|
|
public static class FragmentIntentSenderContract extends ActivityResultContract<IntentSenderRequest, ActivityResult> {
|
|
@NonNull
|
|
public Intent createIntent(@NonNull Context context, IntentSenderRequest intentSenderRequest) {
|
|
Bundle bundleExtra;
|
|
Intent intent = new Intent("androidx.activity.result.contract.action.INTENT_SENDER_REQUEST");
|
|
Intent fillInIntent = intentSenderRequest.getFillInIntent();
|
|
if (!(fillInIntent == null || (bundleExtra = fillInIntent.getBundleExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE")) == null)) {
|
|
intent.putExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE", bundleExtra);
|
|
fillInIntent.removeExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE");
|
|
if (fillInIntent.getBooleanExtra("androidx.fragment.extra.ACTIVITY_OPTIONS_BUNDLE", false)) {
|
|
intentSenderRequest = new IntentSenderRequest.Builder(intentSenderRequest.getIntentSender()).setFillInIntent(null).setFlags(intentSenderRequest.getFlagsValues(), intentSenderRequest.getFlagsMask()).build();
|
|
}
|
|
}
|
|
intent.putExtra("androidx.activity.result.contract.extra.INTENT_SENDER_REQUEST", intentSenderRequest);
|
|
if (FragmentManager.isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "CreateIntent created the following intent: " + intent);
|
|
}
|
|
return intent;
|
|
}
|
|
|
|
@Override // androidx.activity.result.contract.ActivityResultContract
|
|
@NonNull
|
|
public ActivityResult parseResult(int i, @Nullable Intent intent) {
|
|
return new ActivityResult(i, intent);
|
|
}
|
|
}
|
|
|
|
public static abstract class FragmentLifecycleCallbacks {
|
|
@Deprecated
|
|
public void onFragmentActivityCreated(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, @Nullable Bundle bundle) {
|
|
}
|
|
|
|
public void onFragmentAttached(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, @NonNull Context context) {
|
|
}
|
|
|
|
public void onFragmentCreated(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, @Nullable Bundle bundle) {
|
|
}
|
|
|
|
public void onFragmentDestroyed(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment) {
|
|
}
|
|
|
|
public void onFragmentDetached(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment) {
|
|
}
|
|
|
|
public void onFragmentPaused(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment) {
|
|
}
|
|
|
|
public void onFragmentPreAttached(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, @NonNull Context context) {
|
|
}
|
|
|
|
public void onFragmentPreCreated(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, @Nullable Bundle bundle) {
|
|
}
|
|
|
|
public void onFragmentResumed(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment) {
|
|
}
|
|
|
|
public void onFragmentSaveInstanceState(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, @NonNull Bundle bundle) {
|
|
}
|
|
|
|
public void onFragmentStarted(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment) {
|
|
}
|
|
|
|
public void onFragmentStopped(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment) {
|
|
}
|
|
|
|
public void onFragmentViewCreated(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, @NonNull View view, @Nullable Bundle bundle) {
|
|
}
|
|
|
|
public void onFragmentViewDestroyed(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment) {
|
|
}
|
|
}
|
|
|
|
@SuppressLint({"BanParcelableUsage"})
|
|
public static class LaunchedFragmentInfo implements Parcelable {
|
|
public static final Parcelable.Creator<LaunchedFragmentInfo> CREATOR = new AnonymousClass1();
|
|
public int mRequestCode;
|
|
public String mWho;
|
|
|
|
/* renamed from: androidx.fragment.app.FragmentManager$LaunchedFragmentInfo$1 reason: invalid class name */
|
|
public class AnonymousClass1 implements Parcelable.Creator<LaunchedFragmentInfo> {
|
|
@Override // android.os.Parcelable.Creator
|
|
public LaunchedFragmentInfo createFromParcel(Parcel parcel) {
|
|
return new LaunchedFragmentInfo(parcel);
|
|
}
|
|
|
|
@Override // android.os.Parcelable.Creator
|
|
public LaunchedFragmentInfo[] newArray(int i) {
|
|
return new LaunchedFragmentInfo[i];
|
|
}
|
|
}
|
|
|
|
public LaunchedFragmentInfo(@NonNull Parcel parcel) {
|
|
this.mWho = parcel.readString();
|
|
this.mRequestCode = parcel.readInt();
|
|
}
|
|
|
|
public LaunchedFragmentInfo(@NonNull String str, int i) {
|
|
this.mWho = str;
|
|
this.mRequestCode = i;
|
|
}
|
|
|
|
@Override // android.os.Parcelable
|
|
public int describeContents() {
|
|
return 0;
|
|
}
|
|
|
|
@Override // android.os.Parcelable
|
|
public void writeToParcel(Parcel parcel, int i) {
|
|
parcel.writeString(this.mWho);
|
|
parcel.writeInt(this.mRequestCode);
|
|
}
|
|
}
|
|
|
|
public static class LifecycleAwareResultListener implements FragmentResultListener {
|
|
private final Lifecycle mLifecycle;
|
|
private final FragmentResultListener mListener;
|
|
private final LifecycleEventObserver mObserver;
|
|
|
|
public LifecycleAwareResultListener(@NonNull Lifecycle lifecycle, @NonNull FragmentResultListener fragmentResultListener, @NonNull LifecycleEventObserver lifecycleEventObserver) {
|
|
this.mLifecycle = lifecycle;
|
|
this.mListener = fragmentResultListener;
|
|
this.mObserver = lifecycleEventObserver;
|
|
}
|
|
|
|
public boolean isAtLeast(Lifecycle.State state) {
|
|
return this.mLifecycle.getCurrentState().isAtLeast(state);
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentResultListener
|
|
public void onFragmentResult(@NonNull String str, @NonNull Bundle bundle) {
|
|
this.mListener.onFragmentResult(str, bundle);
|
|
}
|
|
|
|
public void removeObserver() {
|
|
this.mLifecycle.removeObserver(this.mObserver);
|
|
}
|
|
}
|
|
|
|
public interface OnBackStackChangedListener {
|
|
@MainThread
|
|
void onBackStackChanged();
|
|
}
|
|
|
|
public interface OpGenerator {
|
|
boolean generateOps(@NonNull ArrayList<BackStackRecord> arrayList, @NonNull ArrayList<Boolean> arrayList2);
|
|
}
|
|
|
|
public class PopBackStackState implements OpGenerator {
|
|
public final int mFlags;
|
|
public final int mId;
|
|
public final String mName;
|
|
|
|
public PopBackStackState(@Nullable String str, int i, int i2) {
|
|
this.mName = str;
|
|
this.mId = i;
|
|
this.mFlags = i2;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentManager.OpGenerator
|
|
public boolean generateOps(@NonNull ArrayList<BackStackRecord> arrayList, @NonNull ArrayList<Boolean> arrayList2) {
|
|
Fragment fragment = FragmentManager.this.mPrimaryNav;
|
|
if (fragment == null || this.mId >= 0 || this.mName != null || !fragment.getChildFragmentManager().popBackStackImmediate()) {
|
|
return FragmentManager.this.popBackStackState(arrayList, arrayList2, this.mName, this.mId, this.mFlags);
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static class StartEnterTransitionListener implements Fragment.OnStartEnterTransitionListener {
|
|
public final boolean mIsBack;
|
|
private int mNumPostponed;
|
|
public final BackStackRecord mRecord;
|
|
|
|
public StartEnterTransitionListener(@NonNull BackStackRecord backStackRecord, boolean z2) {
|
|
this.mIsBack = z2;
|
|
this.mRecord = backStackRecord;
|
|
}
|
|
|
|
public void cancelTransaction() {
|
|
BackStackRecord backStackRecord = this.mRecord;
|
|
backStackRecord.mManager.completeExecute(backStackRecord, this.mIsBack, false, false);
|
|
}
|
|
|
|
public void completeTransaction() {
|
|
boolean z2 = this.mNumPostponed > 0;
|
|
for (Fragment fragment : this.mRecord.mManager.getFragments()) {
|
|
fragment.setOnStartEnterTransitionListener(null);
|
|
if (z2 && fragment.isPostponed()) {
|
|
fragment.startPostponedEnterTransition();
|
|
}
|
|
}
|
|
BackStackRecord backStackRecord = this.mRecord;
|
|
backStackRecord.mManager.completeExecute(backStackRecord, this.mIsBack, !z2, true);
|
|
}
|
|
|
|
public boolean isReady() {
|
|
return this.mNumPostponed == 0;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment.OnStartEnterTransitionListener
|
|
public void onStartEnterTransition() {
|
|
int i = this.mNumPostponed - 1;
|
|
this.mNumPostponed = i;
|
|
if (i == 0) {
|
|
this.mRecord.mManager.scheduleCommit();
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment.OnStartEnterTransitionListener
|
|
public void startListening() {
|
|
this.mNumPostponed++;
|
|
}
|
|
}
|
|
|
|
public static /* synthetic */ Map access$000(FragmentManager fragmentManager) {
|
|
return fragmentManager.mResults;
|
|
}
|
|
|
|
public static /* synthetic */ Map access$100(FragmentManager fragmentManager) {
|
|
return fragmentManager.mResultListeners;
|
|
}
|
|
|
|
public static /* synthetic */ FragmentStore access$200(FragmentManager fragmentManager) {
|
|
return fragmentManager.mFragmentStore;
|
|
}
|
|
|
|
private void addAddedFragments(@NonNull ArraySet<Fragment> arraySet) {
|
|
int i = this.mCurState;
|
|
if (i >= 1) {
|
|
int min = Math.min(i, 5);
|
|
for (Fragment fragment : this.mFragmentStore.getFragments()) {
|
|
if (fragment.mState < min) {
|
|
moveToState(fragment, min);
|
|
if (fragment.mView != null && !fragment.mHidden && fragment.mIsNewlyAdded) {
|
|
arraySet.add(fragment);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void cancelExitAnimation(@NonNull Fragment fragment) {
|
|
HashSet<CancellationSignal> hashSet = this.mExitAnimationCancellationSignals.get(fragment);
|
|
if (hashSet != null) {
|
|
Iterator<CancellationSignal> it = hashSet.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().cancel();
|
|
}
|
|
hashSet.clear();
|
|
destroyFragmentView(fragment);
|
|
this.mExitAnimationCancellationSignals.remove(fragment);
|
|
}
|
|
}
|
|
|
|
private void checkStateLoss() {
|
|
if (isStateSaved()) {
|
|
throw new IllegalStateException("Can not perform this action after onSaveInstanceState");
|
|
}
|
|
}
|
|
|
|
private void cleanupExec() {
|
|
this.mExecutingActions = false;
|
|
this.mTmpIsPop.clear();
|
|
this.mTmpRecords.clear();
|
|
}
|
|
|
|
private Set<SpecialEffectsController> collectAllSpecialEffectsController() {
|
|
HashSet hashSet = new HashSet();
|
|
for (FragmentStateManager fragmentStateManager : this.mFragmentStore.getActiveFragmentStateManagers()) {
|
|
ViewGroup viewGroup = fragmentStateManager.getFragment().mContainer;
|
|
if (viewGroup != null) {
|
|
hashSet.add(SpecialEffectsController.getOrCreateController(viewGroup, getSpecialEffectsControllerFactory()));
|
|
}
|
|
}
|
|
return hashSet;
|
|
}
|
|
|
|
private Set<SpecialEffectsController> collectChangedControllers(@NonNull ArrayList<BackStackRecord> arrayList, int i, int i2) {
|
|
ViewGroup viewGroup;
|
|
HashSet hashSet = new HashSet();
|
|
while (i < i2) {
|
|
Iterator<FragmentTransaction.Op> it = arrayList.get(i).mOps.iterator();
|
|
while (it.hasNext()) {
|
|
Fragment fragment = it.next().mFragment;
|
|
if (!(fragment == null || (viewGroup = fragment.mContainer) == null)) {
|
|
hashSet.add(SpecialEffectsController.getOrCreateController(viewGroup, this));
|
|
}
|
|
}
|
|
i++;
|
|
}
|
|
return hashSet;
|
|
}
|
|
|
|
private void completeShowHideFragment(@NonNull Fragment fragment) {
|
|
Animator animator;
|
|
if (fragment.mView != null) {
|
|
FragmentAnim.AnimationOrAnimator loadAnimation = FragmentAnim.loadAnimation(this.mHost.getContext(), fragment, !fragment.mHidden);
|
|
if (loadAnimation == null || (animator = loadAnimation.animator) == null) {
|
|
if (loadAnimation != null) {
|
|
fragment.mView.startAnimation(loadAnimation.animation);
|
|
loadAnimation.animation.start();
|
|
}
|
|
fragment.mView.setVisibility((!fragment.mHidden || fragment.isHideReplaced()) ? 0 : 8);
|
|
if (fragment.isHideReplaced()) {
|
|
fragment.setHideReplaced(false);
|
|
}
|
|
} else {
|
|
animator.setTarget(fragment.mView);
|
|
if (!fragment.mHidden) {
|
|
fragment.mView.setVisibility(0);
|
|
} else if (fragment.isHideReplaced()) {
|
|
fragment.setHideReplaced(false);
|
|
} else {
|
|
ViewGroup viewGroup = fragment.mContainer;
|
|
View view = fragment.mView;
|
|
viewGroup.startViewTransition(view);
|
|
loadAnimation.animator.addListener(new AnonymousClass7(viewGroup, view, fragment));
|
|
}
|
|
loadAnimation.animator.start();
|
|
}
|
|
}
|
|
if (fragment.mAdded && isMenuAvailable(fragment)) {
|
|
this.mNeedMenuInvalidate = true;
|
|
}
|
|
fragment.mHiddenChanged = false;
|
|
fragment.onHiddenChanged(fragment.mHidden);
|
|
}
|
|
|
|
private void destroyFragmentView(@NonNull Fragment fragment) {
|
|
fragment.performDestroyView();
|
|
this.mLifecycleCallbacksDispatcher.dispatchOnFragmentViewDestroyed(fragment, false);
|
|
fragment.mContainer = null;
|
|
fragment.mView = null;
|
|
fragment.mViewLifecycleOwner = null;
|
|
fragment.mViewLifecycleOwnerLiveData.setValue(null);
|
|
fragment.mInLayout = false;
|
|
}
|
|
|
|
private void dispatchParentPrimaryNavigationFragmentChanged(@Nullable Fragment fragment) {
|
|
if (fragment != null && fragment.equals(findActiveFragment(fragment.mWho))) {
|
|
fragment.performPrimaryNavigationFragmentChanged();
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: finally extract failed */
|
|
private void dispatchStateChange(int i) {
|
|
try {
|
|
this.mExecutingActions = true;
|
|
this.mFragmentStore.dispatchStateChange(i);
|
|
moveToState(i, false);
|
|
if (USE_STATE_MANAGER) {
|
|
for (SpecialEffectsController specialEffectsController : collectAllSpecialEffectsController()) {
|
|
specialEffectsController.forceCompleteAllOperations();
|
|
}
|
|
}
|
|
this.mExecutingActions = false;
|
|
execPendingActions(true);
|
|
} catch (Throwable th) {
|
|
this.mExecutingActions = false;
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
private void doPendingDeferredStart() {
|
|
if (this.mHavePendingDeferredStart) {
|
|
this.mHavePendingDeferredStart = false;
|
|
startPendingDeferredFragments();
|
|
}
|
|
}
|
|
|
|
@Deprecated
|
|
public static void enableDebugLogging(boolean z2) {
|
|
DEBUG = z2;
|
|
}
|
|
|
|
@FragmentStateManagerControl
|
|
public static void enableNewStateManager(boolean z2) {
|
|
USE_STATE_MANAGER = z2;
|
|
}
|
|
|
|
private void endAnimatingAwayFragments() {
|
|
if (USE_STATE_MANAGER) {
|
|
for (SpecialEffectsController specialEffectsController : collectAllSpecialEffectsController()) {
|
|
specialEffectsController.forceCompleteAllOperations();
|
|
}
|
|
} else if (!this.mExitAnimationCancellationSignals.isEmpty()) {
|
|
for (Fragment fragment : this.mExitAnimationCancellationSignals.keySet()) {
|
|
cancelExitAnimation(fragment);
|
|
moveToState(fragment);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ensureExecReady(boolean z2) {
|
|
if (this.mExecutingActions) {
|
|
throw new IllegalStateException("FragmentManager is already executing transactions");
|
|
} else if (this.mHost == null) {
|
|
if (this.mDestroyed) {
|
|
throw new IllegalStateException("FragmentManager has been destroyed");
|
|
}
|
|
throw new IllegalStateException("FragmentManager has not been attached to a host.");
|
|
} else if (Looper.myLooper() == this.mHost.getHandler().getLooper()) {
|
|
if (!z2) {
|
|
checkStateLoss();
|
|
}
|
|
if (this.mTmpRecords == null) {
|
|
this.mTmpRecords = new ArrayList<>();
|
|
this.mTmpIsPop = new ArrayList<>();
|
|
}
|
|
this.mExecutingActions = true;
|
|
boolean z3 = false;
|
|
try {
|
|
executePostponedTransaction(null, null);
|
|
} finally {
|
|
this.mExecutingActions = z3;
|
|
}
|
|
} else {
|
|
throw new IllegalStateException("Must be called from main thread of fragment host");
|
|
}
|
|
}
|
|
|
|
private static void executeOps(@NonNull ArrayList<BackStackRecord> arrayList, @NonNull ArrayList<Boolean> arrayList2, int i, int i2) {
|
|
while (i < i2) {
|
|
BackStackRecord backStackRecord = arrayList.get(i);
|
|
boolean z2 = true;
|
|
if (arrayList2.get(i).booleanValue()) {
|
|
backStackRecord.bumpBackStackNesting(-1);
|
|
if (i != i2 - 1) {
|
|
z2 = false;
|
|
}
|
|
backStackRecord.executePopOps(z2);
|
|
} else {
|
|
backStackRecord.bumpBackStackNesting(1);
|
|
backStackRecord.executeOps();
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:107:? A[RETURN, SYNTHETIC] */
|
|
/* JADX WARNING: Removed duplicated region for block: B:38:0x00c5 */
|
|
/* JADX WARNING: Removed duplicated region for block: B:60:0x0143 */
|
|
/* JADX WARNING: Removed duplicated region for block: B:73:0x019d */
|
|
/* JADX WARNING: Removed duplicated region for block: B:80:0x01be */
|
|
private void executeOpsTogether(@NonNull ArrayList<BackStackRecord> arrayList, @NonNull ArrayList<Boolean> arrayList2, int i, int i2) {
|
|
boolean z2;
|
|
ArrayList<Boolean> arrayList3;
|
|
int i3;
|
|
int i4;
|
|
int i5;
|
|
int i6;
|
|
int i7;
|
|
ArrayList<Boolean> arrayList4;
|
|
boolean z3;
|
|
int i8;
|
|
boolean z4;
|
|
boolean z5 = arrayList.get(i).mReorderingAllowed;
|
|
ArrayList<Fragment> arrayList5 = this.mTmpAddedFragments;
|
|
if (arrayList5 == null) {
|
|
this.mTmpAddedFragments = new ArrayList<>();
|
|
} else {
|
|
arrayList5.clear();
|
|
}
|
|
this.mTmpAddedFragments.addAll(this.mFragmentStore.getFragments());
|
|
Fragment primaryNavigationFragment = getPrimaryNavigationFragment();
|
|
boolean z6 = false;
|
|
for (int i9 = i; i9 < i2; i9++) {
|
|
BackStackRecord backStackRecord = arrayList.get(i9);
|
|
primaryNavigationFragment = !arrayList2.get(i9).booleanValue() ? backStackRecord.expandOps(this.mTmpAddedFragments, primaryNavigationFragment) : backStackRecord.trackAddedFragmentsInPop(this.mTmpAddedFragments, primaryNavigationFragment);
|
|
z6 = z6 || backStackRecord.mAddToBackStack;
|
|
}
|
|
this.mTmpAddedFragments.clear();
|
|
if (!z5 && this.mCurState >= 1) {
|
|
if (USE_STATE_MANAGER) {
|
|
for (int i10 = i; i10 < i2; i10++) {
|
|
Iterator<FragmentTransaction.Op> it = arrayList.get(i10).mOps.iterator();
|
|
while (it.hasNext()) {
|
|
Fragment fragment = it.next().mFragment;
|
|
if (!(fragment == null || fragment.mFragmentManager == null)) {
|
|
this.mFragmentStore.makeActive(createOrGetFragmentStateManager(fragment));
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
z2 = true;
|
|
FragmentTransition.startTransitions(this.mHost.getContext(), this.mContainer, arrayList, arrayList2, i, i2, false, this.mFragmentTransitionCallback);
|
|
executeOps(arrayList, arrayList2, i, i2);
|
|
if (!USE_STATE_MANAGER) {
|
|
boolean booleanValue = arrayList2.get(i2 - 1).booleanValue();
|
|
for (int i11 = i; i11 < i2; i11++) {
|
|
BackStackRecord backStackRecord2 = arrayList.get(i11);
|
|
if (booleanValue) {
|
|
int size = backStackRecord2.mOps.size();
|
|
int i12 = z2 ? 1 : 0;
|
|
int i13 = z2 ? 1 : 0;
|
|
int i14 = z2 ? 1 : 0;
|
|
for (int i15 = size - i12; i15 >= 0; i15--) {
|
|
Fragment fragment2 = backStackRecord2.mOps.get(i15).mFragment;
|
|
if (fragment2 != null) {
|
|
createOrGetFragmentStateManager(fragment2).moveToExpectedState();
|
|
}
|
|
}
|
|
} else {
|
|
Iterator<FragmentTransaction.Op> it2 = backStackRecord2.mOps.iterator();
|
|
while (it2.hasNext()) {
|
|
Fragment fragment3 = it2.next().mFragment;
|
|
if (fragment3 != null) {
|
|
createOrGetFragmentStateManager(fragment3).moveToExpectedState();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
moveToState(this.mCurState, z2);
|
|
for (SpecialEffectsController specialEffectsController : collectChangedControllers(arrayList, i, i2)) {
|
|
specialEffectsController.updateOperationDirection(booleanValue);
|
|
specialEffectsController.markPostponedState();
|
|
specialEffectsController.executePendingOperations();
|
|
}
|
|
i3 = i2;
|
|
arrayList3 = arrayList2;
|
|
} else {
|
|
if (z5) {
|
|
ArraySet<Fragment> arraySet = new ArraySet<>();
|
|
addAddedFragments(arraySet);
|
|
i5 = 1;
|
|
z3 = z5;
|
|
i6 = i2;
|
|
i7 = i;
|
|
arrayList4 = arrayList2;
|
|
i8 = postponePostponableTransactions(arrayList, arrayList2, i, i2, arraySet);
|
|
makeRemovedFragmentsInvisible(arraySet);
|
|
} else {
|
|
z3 = z5;
|
|
i6 = i2;
|
|
i7 = i;
|
|
arrayList4 = arrayList2;
|
|
i5 = 1;
|
|
i8 = i6;
|
|
}
|
|
if (i8 == i7 || !z3) {
|
|
arrayList3 = arrayList4;
|
|
i3 = i6;
|
|
} else {
|
|
if (this.mCurState >= i5) {
|
|
arrayList3 = arrayList4;
|
|
i3 = i6;
|
|
z4 = true;
|
|
FragmentTransition.startTransitions(this.mHost.getContext(), this.mContainer, arrayList, arrayList2, i, i8, true, this.mFragmentTransitionCallback);
|
|
} else {
|
|
arrayList3 = arrayList4;
|
|
i3 = i6;
|
|
z4 = true;
|
|
}
|
|
moveToState(this.mCurState, z4);
|
|
}
|
|
}
|
|
for (i4 = i; i4 < i3; i4++) {
|
|
BackStackRecord backStackRecord3 = arrayList.get(i4);
|
|
if (arrayList3.get(i4).booleanValue() && backStackRecord3.mIndex >= 0) {
|
|
backStackRecord3.mIndex = -1;
|
|
}
|
|
backStackRecord3.runOnCommitRunnables();
|
|
}
|
|
if (!z6) {
|
|
reportBackStackChanged();
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
z2 = true;
|
|
executeOps(arrayList, arrayList2, i, i2);
|
|
if (!USE_STATE_MANAGER) {
|
|
}
|
|
while (i4 < i3) {
|
|
}
|
|
if (!z6) {
|
|
}
|
|
}
|
|
|
|
private void executePostponedTransaction(@Nullable ArrayList<BackStackRecord> arrayList, @Nullable ArrayList<Boolean> arrayList2) {
|
|
int indexOf;
|
|
int indexOf2;
|
|
ArrayList<StartEnterTransitionListener> arrayList3 = this.mPostponedTransactions;
|
|
int size = arrayList3 == null ? 0 : arrayList3.size();
|
|
int i = 0;
|
|
while (i < size) {
|
|
StartEnterTransitionListener startEnterTransitionListener = this.mPostponedTransactions.get(i);
|
|
if (arrayList != null && !startEnterTransitionListener.mIsBack && (indexOf2 = arrayList.indexOf(startEnterTransitionListener.mRecord)) != -1 && arrayList2 != null && arrayList2.get(indexOf2).booleanValue()) {
|
|
this.mPostponedTransactions.remove(i);
|
|
i--;
|
|
size--;
|
|
startEnterTransitionListener.cancelTransaction();
|
|
} else if (startEnterTransitionListener.isReady() || (arrayList != null && startEnterTransitionListener.mRecord.interactsWith(arrayList, 0, arrayList.size()))) {
|
|
this.mPostponedTransactions.remove(i);
|
|
i--;
|
|
size--;
|
|
if (arrayList == null || startEnterTransitionListener.mIsBack || (indexOf = arrayList.indexOf(startEnterTransitionListener.mRecord)) == -1 || arrayList2 == null || !arrayList2.get(indexOf).booleanValue()) {
|
|
startEnterTransitionListener.completeTransaction();
|
|
} else {
|
|
startEnterTransitionListener.cancelTransaction();
|
|
}
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
public static <F extends Fragment> F findFragment(@NonNull View view) {
|
|
F f = (F) findViewFragment(view);
|
|
if (f != null) {
|
|
return f;
|
|
}
|
|
throw new IllegalStateException("View " + view + " does not have a Fragment set");
|
|
}
|
|
|
|
@NonNull
|
|
public static FragmentManager findFragmentManager(@NonNull View view) {
|
|
Fragment findViewFragment = findViewFragment(view);
|
|
if (findViewFragment == null) {
|
|
Context context = view.getContext();
|
|
FragmentActivity fragmentActivity = null;
|
|
while (true) {
|
|
if (!(context instanceof ContextWrapper)) {
|
|
break;
|
|
} else if (context instanceof FragmentActivity) {
|
|
fragmentActivity = (FragmentActivity) context;
|
|
break;
|
|
} else {
|
|
context = ((ContextWrapper) context).getBaseContext();
|
|
}
|
|
}
|
|
if (fragmentActivity != null) {
|
|
return fragmentActivity.getSupportFragmentManager();
|
|
}
|
|
throw new IllegalStateException("View " + view + " is not within a subclass of FragmentActivity.");
|
|
} else if (findViewFragment.isAdded()) {
|
|
return findViewFragment.getChildFragmentManager();
|
|
} else {
|
|
throw new IllegalStateException("The Fragment " + findViewFragment + " that owns View " + view + " has already been destroyed. Nested fragments should always use the child FragmentManager.");
|
|
}
|
|
}
|
|
|
|
@Nullable
|
|
private static Fragment findViewFragment(@NonNull View view) {
|
|
while (view != null) {
|
|
Fragment viewFragment = getViewFragment(view);
|
|
if (viewFragment != null) {
|
|
return viewFragment;
|
|
}
|
|
ViewParent parent = view.getParent();
|
|
view = parent instanceof View ? (View) parent : null;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private void forcePostponedTransactions() {
|
|
if (USE_STATE_MANAGER) {
|
|
for (SpecialEffectsController specialEffectsController : collectAllSpecialEffectsController()) {
|
|
specialEffectsController.forcePostponedExecutePendingOperations();
|
|
}
|
|
} else if (this.mPostponedTransactions != null) {
|
|
while (!this.mPostponedTransactions.isEmpty()) {
|
|
this.mPostponedTransactions.remove(0).completeTransaction();
|
|
}
|
|
}
|
|
}
|
|
|
|
private boolean generateOpsForPendingActions(@NonNull ArrayList<BackStackRecord> arrayList, @NonNull ArrayList<Boolean> arrayList2) {
|
|
synchronized (this.mPendingActions) {
|
|
if (this.mPendingActions.isEmpty()) {
|
|
return false;
|
|
}
|
|
int size = this.mPendingActions.size();
|
|
boolean z2 = false;
|
|
for (int i = 0; i < size; i++) {
|
|
z2 |= this.mPendingActions.get(i).generateOps(arrayList, arrayList2);
|
|
}
|
|
this.mPendingActions.clear();
|
|
this.mHost.getHandler().removeCallbacks(this.mExecCommit);
|
|
return z2;
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
private FragmentManagerViewModel getChildNonConfig(@NonNull Fragment fragment) {
|
|
return this.mNonConfig.getChildNonConfig(fragment);
|
|
}
|
|
|
|
private ViewGroup getFragmentContainer(@NonNull Fragment fragment) {
|
|
ViewGroup viewGroup = fragment.mContainer;
|
|
if (viewGroup != null) {
|
|
return viewGroup;
|
|
}
|
|
if (fragment.mContainerId > 0 && this.mContainer.onHasView()) {
|
|
View onFindViewById = this.mContainer.onFindViewById(fragment.mContainerId);
|
|
if (onFindViewById instanceof ViewGroup) {
|
|
return (ViewGroup) onFindViewById;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Nullable
|
|
public static Fragment getViewFragment(@NonNull View view) {
|
|
Object tag = view.getTag(R.id.fragment_container_view_tag);
|
|
if (tag instanceof Fragment) {
|
|
return (Fragment) tag;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static boolean isLoggingEnabled(int i) {
|
|
return DEBUG || Log.isLoggable("FragmentManager", i);
|
|
}
|
|
|
|
private boolean isMenuAvailable(@NonNull Fragment fragment) {
|
|
return (fragment.mHasMenu && fragment.mMenuVisible) || fragment.mChildFragmentManager.checkForMenus();
|
|
}
|
|
|
|
private void makeRemovedFragmentsInvisible(@NonNull ArraySet<Fragment> arraySet) {
|
|
int size = arraySet.size();
|
|
for (int i = 0; i < size; i++) {
|
|
Fragment valueAt = arraySet.valueAt(i);
|
|
if (!valueAt.mAdded) {
|
|
View requireView = valueAt.requireView();
|
|
valueAt.mPostponedAlpha = requireView.getAlpha();
|
|
requireView.setAlpha(0.0f);
|
|
}
|
|
}
|
|
}
|
|
|
|
private boolean popBackStackImmediate(@Nullable String str, int i, int i2) {
|
|
execPendingActions(false);
|
|
ensureExecReady(true);
|
|
Fragment fragment = this.mPrimaryNav;
|
|
if (fragment != null && i < 0 && str == null && fragment.getChildFragmentManager().popBackStackImmediate()) {
|
|
return true;
|
|
}
|
|
boolean popBackStackState = popBackStackState(this.mTmpRecords, this.mTmpIsPop, str, i, i2);
|
|
if (popBackStackState) {
|
|
this.mExecutingActions = true;
|
|
try {
|
|
removeRedundantOperationsAndExecute(this.mTmpRecords, this.mTmpIsPop);
|
|
} finally {
|
|
cleanupExec();
|
|
}
|
|
}
|
|
updateOnBackPressedCallbackEnabled();
|
|
doPendingDeferredStart();
|
|
this.mFragmentStore.burpActive();
|
|
return popBackStackState;
|
|
}
|
|
|
|
private int postponePostponableTransactions(@NonNull ArrayList<BackStackRecord> arrayList, @NonNull ArrayList<Boolean> arrayList2, int i, int i2, @NonNull ArraySet<Fragment> arraySet) {
|
|
int i3 = i2;
|
|
for (int i4 = i2 - 1; i4 >= i; i4--) {
|
|
BackStackRecord backStackRecord = arrayList.get(i4);
|
|
boolean booleanValue = arrayList2.get(i4).booleanValue();
|
|
if (backStackRecord.isPostponed() && !backStackRecord.interactsWith(arrayList, i4 + 1, i2)) {
|
|
if (this.mPostponedTransactions == null) {
|
|
this.mPostponedTransactions = new ArrayList<>();
|
|
}
|
|
StartEnterTransitionListener startEnterTransitionListener = new StartEnterTransitionListener(backStackRecord, booleanValue);
|
|
this.mPostponedTransactions.add(startEnterTransitionListener);
|
|
backStackRecord.setOnStartPostponedListener(startEnterTransitionListener);
|
|
if (booleanValue) {
|
|
backStackRecord.executeOps();
|
|
} else {
|
|
backStackRecord.executePopOps(false);
|
|
}
|
|
i3--;
|
|
if (i4 != i3) {
|
|
arrayList.remove(i4);
|
|
arrayList.add(i3, backStackRecord);
|
|
}
|
|
addAddedFragments(arraySet);
|
|
}
|
|
}
|
|
return i3;
|
|
}
|
|
|
|
private void removeRedundantOperationsAndExecute(@NonNull ArrayList<BackStackRecord> arrayList, @NonNull ArrayList<Boolean> arrayList2) {
|
|
if (!arrayList.isEmpty()) {
|
|
if (arrayList.size() == arrayList2.size()) {
|
|
executePostponedTransaction(arrayList, arrayList2);
|
|
int size = arrayList.size();
|
|
int i = 0;
|
|
int i2 = 0;
|
|
while (i < size) {
|
|
if (!arrayList.get(i).mReorderingAllowed) {
|
|
if (i2 != i) {
|
|
executeOpsTogether(arrayList, arrayList2, i2, i);
|
|
}
|
|
i2 = i + 1;
|
|
if (arrayList2.get(i).booleanValue()) {
|
|
while (i2 < size && arrayList2.get(i2).booleanValue() && !arrayList.get(i2).mReorderingAllowed) {
|
|
i2++;
|
|
}
|
|
}
|
|
executeOpsTogether(arrayList, arrayList2, i, i2);
|
|
i = i2 - 1;
|
|
}
|
|
i++;
|
|
}
|
|
if (i2 != size) {
|
|
executeOpsTogether(arrayList, arrayList2, i2, size);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
throw new IllegalStateException("Internal error with the back stack records");
|
|
}
|
|
}
|
|
|
|
private void reportBackStackChanged() {
|
|
if (this.mBackStackChangeListeners != null) {
|
|
for (int i = 0; i < this.mBackStackChangeListeners.size(); i++) {
|
|
this.mBackStackChangeListeners.get(i).onBackStackChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static int reverseTransit(int i) {
|
|
if (i == 4097) {
|
|
return 8194;
|
|
}
|
|
if (i != 4099) {
|
|
return i != 8194 ? 0 : 4097;
|
|
}
|
|
return 4099;
|
|
}
|
|
|
|
private void setVisibleRemovingFragment(@NonNull Fragment fragment) {
|
|
ViewGroup fragmentContainer = getFragmentContainer(fragment);
|
|
if (fragmentContainer != null && fragment.getNextAnim() > 0) {
|
|
int i = R.id.visible_removing_fragment_view_tag;
|
|
if (fragmentContainer.getTag(i) == null) {
|
|
fragmentContainer.setTag(i, fragment);
|
|
}
|
|
((Fragment) fragmentContainer.getTag(i)).setNextAnim(fragment.getNextAnim());
|
|
}
|
|
}
|
|
|
|
private void startPendingDeferredFragments() {
|
|
for (FragmentStateManager fragmentStateManager : this.mFragmentStore.getActiveFragmentStateManagers()) {
|
|
performPendingDeferredStart(fragmentStateManager);
|
|
}
|
|
}
|
|
|
|
private void throwException(RuntimeException runtimeException) {
|
|
Log.e("FragmentManager", runtimeException.getMessage());
|
|
Log.e("FragmentManager", "Activity state:");
|
|
PrintWriter printWriter = new PrintWriter(new LogWriter("FragmentManager"));
|
|
FragmentHostCallback<?> fragmentHostCallback = this.mHost;
|
|
if (fragmentHostCallback != null) {
|
|
try {
|
|
fragmentHostCallback.onDump(" ", null, printWriter, new String[0]);
|
|
} catch (Exception e) {
|
|
Log.e("FragmentManager", "Failed dumping state", e);
|
|
}
|
|
} else {
|
|
try {
|
|
dump(" ", null, printWriter, new String[0]);
|
|
} catch (Exception e2) {
|
|
Log.e("FragmentManager", "Failed dumping state", e2);
|
|
}
|
|
}
|
|
throw runtimeException;
|
|
}
|
|
|
|
private void updateOnBackPressedCallbackEnabled() {
|
|
boolean z2;
|
|
synchronized (this.mPendingActions) {
|
|
z2 = true;
|
|
if (!this.mPendingActions.isEmpty()) {
|
|
this.mOnBackPressedCallback.setEnabled(true);
|
|
return;
|
|
}
|
|
}
|
|
OnBackPressedCallback onBackPressedCallback = this.mOnBackPressedCallback;
|
|
if (getBackStackEntryCount() <= 0 || !isPrimaryNavigation(this.mParent)) {
|
|
z2 = false;
|
|
}
|
|
onBackPressedCallback.setEnabled(z2);
|
|
}
|
|
|
|
public void addBackStackState(BackStackRecord backStackRecord) {
|
|
if (this.mBackStack == null) {
|
|
this.mBackStack = new ArrayList<>();
|
|
}
|
|
this.mBackStack.add(backStackRecord);
|
|
}
|
|
|
|
public void addCancellationSignal(@NonNull Fragment fragment, @NonNull CancellationSignal cancellationSignal) {
|
|
if (this.mExitAnimationCancellationSignals.get(fragment) == null) {
|
|
this.mExitAnimationCancellationSignals.put(fragment, new HashSet<>());
|
|
}
|
|
this.mExitAnimationCancellationSignals.get(fragment).add(cancellationSignal);
|
|
}
|
|
|
|
public void addFragment(@NonNull Fragment fragment) {
|
|
if (isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "add: " + fragment);
|
|
}
|
|
FragmentStateManager createOrGetFragmentStateManager = createOrGetFragmentStateManager(fragment);
|
|
fragment.mFragmentManager = this;
|
|
this.mFragmentStore.makeActive(createOrGetFragmentStateManager);
|
|
if (!fragment.mDetached) {
|
|
this.mFragmentStore.addFragment(fragment);
|
|
fragment.mRemoving = false;
|
|
if (fragment.mView == null) {
|
|
fragment.mHiddenChanged = false;
|
|
}
|
|
if (isMenuAvailable(fragment)) {
|
|
this.mNeedMenuInvalidate = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void addFragmentOnAttachListener(@NonNull FragmentOnAttachListener fragmentOnAttachListener) {
|
|
this.mOnAttachListeners.add(fragmentOnAttachListener);
|
|
}
|
|
|
|
public void addOnBackStackChangedListener(@NonNull OnBackStackChangedListener onBackStackChangedListener) {
|
|
if (this.mBackStackChangeListeners == null) {
|
|
this.mBackStackChangeListeners = new ArrayList<>();
|
|
}
|
|
this.mBackStackChangeListeners.add(onBackStackChangedListener);
|
|
}
|
|
|
|
public void addRetainedFragment(@NonNull Fragment fragment) {
|
|
this.mNonConfig.addRetainedFragment(fragment);
|
|
}
|
|
|
|
public int allocBackStackIndex() {
|
|
return this.mBackStackIndex.getAndIncrement();
|
|
}
|
|
|
|
@SuppressLint({"SyntheticAccessor"})
|
|
public void attachController(@NonNull FragmentHostCallback<?> fragmentHostCallback, @NonNull FragmentContainer fragmentContainer, @Nullable Fragment fragment) {
|
|
if (this.mHost == null) {
|
|
this.mHost = fragmentHostCallback;
|
|
this.mContainer = fragmentContainer;
|
|
this.mParent = fragment;
|
|
if (fragment != null) {
|
|
addFragmentOnAttachListener(new AnonymousClass8(fragment));
|
|
} else if (fragmentHostCallback instanceof FragmentOnAttachListener) {
|
|
addFragmentOnAttachListener((FragmentOnAttachListener) fragmentHostCallback);
|
|
}
|
|
if (this.mParent != null) {
|
|
updateOnBackPressedCallbackEnabled();
|
|
}
|
|
if (fragmentHostCallback instanceof OnBackPressedDispatcherOwner) {
|
|
OnBackPressedDispatcherOwner onBackPressedDispatcherOwner = (OnBackPressedDispatcherOwner) fragmentHostCallback;
|
|
OnBackPressedDispatcher onBackPressedDispatcher = onBackPressedDispatcherOwner.getOnBackPressedDispatcher();
|
|
this.mOnBackPressedDispatcher = onBackPressedDispatcher;
|
|
LifecycleOwner lifecycleOwner = onBackPressedDispatcherOwner;
|
|
if (fragment != null) {
|
|
lifecycleOwner = fragment;
|
|
}
|
|
onBackPressedDispatcher.addCallback(lifecycleOwner, this.mOnBackPressedCallback);
|
|
}
|
|
if (fragment != null) {
|
|
this.mNonConfig = fragment.mFragmentManager.getChildNonConfig(fragment);
|
|
} else if (fragmentHostCallback instanceof ViewModelStoreOwner) {
|
|
this.mNonConfig = FragmentManagerViewModel.getInstance(((ViewModelStoreOwner) fragmentHostCallback).getViewModelStore());
|
|
} else {
|
|
this.mNonConfig = new FragmentManagerViewModel(false);
|
|
}
|
|
this.mNonConfig.setIsStateSaved(isStateSaved());
|
|
this.mFragmentStore.setNonConfig(this.mNonConfig);
|
|
FragmentHostCallback<?> fragmentHostCallback2 = this.mHost;
|
|
if (fragmentHostCallback2 instanceof ActivityResultRegistryOwner) {
|
|
ActivityResultRegistry activityResultRegistry = ((ActivityResultRegistryOwner) fragmentHostCallback2).getActivityResultRegistry();
|
|
String u = a.u("FragmentManager:", fragment != null ? a.D(new StringBuilder(), fragment.mWho, ":") : "");
|
|
this.mStartActivityForResult = activityResultRegistry.register(a.u(u, "StartActivityForResult"), new ActivityResultContracts.StartActivityForResult(), new AnonymousClass9());
|
|
this.mStartIntentSenderForResult = activityResultRegistry.register(a.u(u, "StartIntentSenderForResult"), new FragmentIntentSenderContract(), new AnonymousClass10());
|
|
this.mRequestPermissions = activityResultRegistry.register(a.u(u, "RequestPermissions"), new ActivityResultContracts.RequestMultiplePermissions(), new AnonymousClass11());
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
throw new IllegalStateException("Already attached");
|
|
}
|
|
|
|
public void attachFragment(@NonNull Fragment fragment) {
|
|
if (isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "attach: " + fragment);
|
|
}
|
|
if (fragment.mDetached) {
|
|
fragment.mDetached = false;
|
|
if (!fragment.mAdded) {
|
|
this.mFragmentStore.addFragment(fragment);
|
|
if (isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "add from attach: " + fragment);
|
|
}
|
|
if (isMenuAvailable(fragment)) {
|
|
this.mNeedMenuInvalidate = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
public FragmentTransaction beginTransaction() {
|
|
return new BackStackRecord(this);
|
|
}
|
|
|
|
public boolean checkForMenus() {
|
|
boolean z2 = false;
|
|
for (Fragment fragment : this.mFragmentStore.getActiveFragments()) {
|
|
if (fragment != null) {
|
|
z2 = isMenuAvailable(fragment);
|
|
continue;
|
|
}
|
|
if (z2) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentResultOwner
|
|
public final void clearFragmentResult(@NonNull String str) {
|
|
this.mResults.remove(str);
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentResultOwner
|
|
public final void clearFragmentResultListener(@NonNull String str) {
|
|
LifecycleAwareResultListener remove = this.mResultListeners.remove(str);
|
|
if (remove != null) {
|
|
remove.removeObserver();
|
|
}
|
|
}
|
|
|
|
public void completeExecute(@NonNull BackStackRecord backStackRecord, boolean z2, boolean z3, boolean z4) {
|
|
if (z2) {
|
|
backStackRecord.executePopOps(z4);
|
|
} else {
|
|
backStackRecord.executeOps();
|
|
}
|
|
ArrayList arrayList = new ArrayList(1);
|
|
ArrayList arrayList2 = new ArrayList(1);
|
|
arrayList.add(backStackRecord);
|
|
arrayList2.add(Boolean.valueOf(z2));
|
|
if (z3 && this.mCurState >= 1) {
|
|
FragmentTransition.startTransitions(this.mHost.getContext(), this.mContainer, arrayList, arrayList2, 0, 1, true, this.mFragmentTransitionCallback);
|
|
}
|
|
if (z4) {
|
|
moveToState(this.mCurState, true);
|
|
}
|
|
for (Fragment fragment : this.mFragmentStore.getActiveFragments()) {
|
|
if (fragment != null && fragment.mView != null && fragment.mIsNewlyAdded && backStackRecord.interactsWith(fragment.mContainerId)) {
|
|
float f = fragment.mPostponedAlpha;
|
|
if (f > 0.0f) {
|
|
fragment.mView.setAlpha(f);
|
|
}
|
|
if (z4) {
|
|
fragment.mPostponedAlpha = 0.0f;
|
|
} else {
|
|
fragment.mPostponedAlpha = -1.0f;
|
|
fragment.mIsNewlyAdded = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
public FragmentStateManager createOrGetFragmentStateManager(@NonNull Fragment fragment) {
|
|
FragmentStateManager fragmentStateManager = this.mFragmentStore.getFragmentStateManager(fragment.mWho);
|
|
if (fragmentStateManager != null) {
|
|
return fragmentStateManager;
|
|
}
|
|
FragmentStateManager fragmentStateManager2 = new FragmentStateManager(this.mLifecycleCallbacksDispatcher, this.mFragmentStore, fragment);
|
|
fragmentStateManager2.restoreState(this.mHost.getContext().getClassLoader());
|
|
fragmentStateManager2.setFragmentManagerState(this.mCurState);
|
|
return fragmentStateManager2;
|
|
}
|
|
|
|
public void detachFragment(@NonNull Fragment fragment) {
|
|
if (isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "detach: " + fragment);
|
|
}
|
|
if (!fragment.mDetached) {
|
|
fragment.mDetached = true;
|
|
if (fragment.mAdded) {
|
|
if (isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "remove from detach: " + fragment);
|
|
}
|
|
this.mFragmentStore.removeFragment(fragment);
|
|
if (isMenuAvailable(fragment)) {
|
|
this.mNeedMenuInvalidate = true;
|
|
}
|
|
setVisibleRemovingFragment(fragment);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void dispatchActivityCreated() {
|
|
this.mStateSaved = false;
|
|
this.mStopped = false;
|
|
this.mNonConfig.setIsStateSaved(false);
|
|
dispatchStateChange(4);
|
|
}
|
|
|
|
public void dispatchAttach() {
|
|
this.mStateSaved = false;
|
|
this.mStopped = false;
|
|
this.mNonConfig.setIsStateSaved(false);
|
|
dispatchStateChange(0);
|
|
}
|
|
|
|
public void dispatchConfigurationChanged(@NonNull Configuration configuration) {
|
|
for (Fragment fragment : this.mFragmentStore.getFragments()) {
|
|
if (fragment != null) {
|
|
fragment.performConfigurationChanged(configuration);
|
|
}
|
|
}
|
|
}
|
|
|
|
public boolean dispatchContextItemSelected(@NonNull MenuItem menuItem) {
|
|
if (this.mCurState < 1) {
|
|
return false;
|
|
}
|
|
for (Fragment fragment : this.mFragmentStore.getFragments()) {
|
|
if (fragment != null && fragment.performContextItemSelected(menuItem)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void dispatchCreate() {
|
|
this.mStateSaved = false;
|
|
this.mStopped = false;
|
|
this.mNonConfig.setIsStateSaved(false);
|
|
dispatchStateChange(1);
|
|
}
|
|
|
|
public boolean dispatchCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) {
|
|
if (this.mCurState < 1) {
|
|
return false;
|
|
}
|
|
ArrayList<Fragment> arrayList = null;
|
|
boolean z2 = false;
|
|
for (Fragment fragment : this.mFragmentStore.getFragments()) {
|
|
if (fragment != null && isParentMenuVisible(fragment) && fragment.performCreateOptionsMenu(menu, menuInflater)) {
|
|
if (arrayList == null) {
|
|
arrayList = new ArrayList<>();
|
|
}
|
|
arrayList.add(fragment);
|
|
z2 = true;
|
|
}
|
|
}
|
|
if (this.mCreatedMenus != null) {
|
|
for (int i = 0; i < this.mCreatedMenus.size(); i++) {
|
|
Fragment fragment2 = this.mCreatedMenus.get(i);
|
|
if (arrayList == null || !arrayList.contains(fragment2)) {
|
|
fragment2.onDestroyOptionsMenu();
|
|
}
|
|
}
|
|
}
|
|
this.mCreatedMenus = arrayList;
|
|
return z2;
|
|
}
|
|
|
|
public void dispatchDestroy() {
|
|
this.mDestroyed = true;
|
|
execPendingActions(true);
|
|
endAnimatingAwayFragments();
|
|
dispatchStateChange(-1);
|
|
this.mHost = null;
|
|
this.mContainer = null;
|
|
this.mParent = null;
|
|
if (this.mOnBackPressedDispatcher != null) {
|
|
this.mOnBackPressedCallback.remove();
|
|
this.mOnBackPressedDispatcher = null;
|
|
}
|
|
ActivityResultLauncher<Intent> activityResultLauncher = this.mStartActivityForResult;
|
|
if (activityResultLauncher != null) {
|
|
activityResultLauncher.unregister();
|
|
this.mStartIntentSenderForResult.unregister();
|
|
this.mRequestPermissions.unregister();
|
|
}
|
|
}
|
|
|
|
public void dispatchDestroyView() {
|
|
dispatchStateChange(1);
|
|
}
|
|
|
|
public void dispatchLowMemory() {
|
|
for (Fragment fragment : this.mFragmentStore.getFragments()) {
|
|
if (fragment != null) {
|
|
fragment.performLowMemory();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void dispatchMultiWindowModeChanged(boolean z2) {
|
|
for (Fragment fragment : this.mFragmentStore.getFragments()) {
|
|
if (fragment != null) {
|
|
fragment.performMultiWindowModeChanged(z2);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void dispatchOnAttachFragment(@NonNull Fragment fragment) {
|
|
Iterator<FragmentOnAttachListener> it = this.mOnAttachListeners.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().onAttachFragment(this, fragment);
|
|
}
|
|
}
|
|
|
|
public boolean dispatchOptionsItemSelected(@NonNull MenuItem menuItem) {
|
|
if (this.mCurState < 1) {
|
|
return false;
|
|
}
|
|
for (Fragment fragment : this.mFragmentStore.getFragments()) {
|
|
if (fragment != null && fragment.performOptionsItemSelected(menuItem)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void dispatchOptionsMenuClosed(@NonNull Menu menu) {
|
|
if (this.mCurState >= 1) {
|
|
for (Fragment fragment : this.mFragmentStore.getFragments()) {
|
|
if (fragment != null) {
|
|
fragment.performOptionsMenuClosed(menu);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void dispatchPause() {
|
|
dispatchStateChange(5);
|
|
}
|
|
|
|
public void dispatchPictureInPictureModeChanged(boolean z2) {
|
|
for (Fragment fragment : this.mFragmentStore.getFragments()) {
|
|
if (fragment != null) {
|
|
fragment.performPictureInPictureModeChanged(z2);
|
|
}
|
|
}
|
|
}
|
|
|
|
public boolean dispatchPrepareOptionsMenu(@NonNull Menu menu) {
|
|
boolean z2 = false;
|
|
if (this.mCurState < 1) {
|
|
return false;
|
|
}
|
|
for (Fragment fragment : this.mFragmentStore.getFragments()) {
|
|
if (fragment != null && isParentMenuVisible(fragment) && fragment.performPrepareOptionsMenu(menu)) {
|
|
z2 = true;
|
|
}
|
|
}
|
|
return z2;
|
|
}
|
|
|
|
public void dispatchPrimaryNavigationFragmentChanged() {
|
|
updateOnBackPressedCallbackEnabled();
|
|
dispatchParentPrimaryNavigationFragmentChanged(this.mPrimaryNav);
|
|
}
|
|
|
|
public void dispatchResume() {
|
|
this.mStateSaved = false;
|
|
this.mStopped = false;
|
|
this.mNonConfig.setIsStateSaved(false);
|
|
dispatchStateChange(7);
|
|
}
|
|
|
|
public void dispatchStart() {
|
|
this.mStateSaved = false;
|
|
this.mStopped = false;
|
|
this.mNonConfig.setIsStateSaved(false);
|
|
dispatchStateChange(5);
|
|
}
|
|
|
|
public void dispatchStop() {
|
|
this.mStopped = true;
|
|
this.mNonConfig.setIsStateSaved(true);
|
|
dispatchStateChange(4);
|
|
}
|
|
|
|
public void dispatchViewCreated() {
|
|
dispatchStateChange(2);
|
|
}
|
|
|
|
public void dump(@NonNull String str, @Nullable FileDescriptor fileDescriptor, @NonNull PrintWriter printWriter, @Nullable String[] strArr) {
|
|
int size;
|
|
int size2;
|
|
String u = a.u(str, " ");
|
|
this.mFragmentStore.dump(str, fileDescriptor, printWriter, strArr);
|
|
ArrayList<Fragment> arrayList = this.mCreatedMenus;
|
|
if (arrayList != null && (size2 = arrayList.size()) > 0) {
|
|
printWriter.print(str);
|
|
printWriter.println("Fragments Created Menus:");
|
|
for (int i = 0; i < size2; i++) {
|
|
printWriter.print(str);
|
|
printWriter.print(" #");
|
|
printWriter.print(i);
|
|
printWriter.print(": ");
|
|
printWriter.println(this.mCreatedMenus.get(i).toString());
|
|
}
|
|
}
|
|
ArrayList<BackStackRecord> arrayList2 = this.mBackStack;
|
|
if (arrayList2 != null && (size = arrayList2.size()) > 0) {
|
|
printWriter.print(str);
|
|
printWriter.println("Back Stack:");
|
|
for (int i2 = 0; i2 < size; i2++) {
|
|
BackStackRecord backStackRecord = this.mBackStack.get(i2);
|
|
printWriter.print(str);
|
|
printWriter.print(" #");
|
|
printWriter.print(i2);
|
|
printWriter.print(": ");
|
|
printWriter.println(backStackRecord.toString());
|
|
backStackRecord.dump(u, printWriter);
|
|
}
|
|
}
|
|
printWriter.print(str);
|
|
printWriter.println("Back Stack Index: " + this.mBackStackIndex.get());
|
|
synchronized (this.mPendingActions) {
|
|
int size3 = this.mPendingActions.size();
|
|
if (size3 > 0) {
|
|
printWriter.print(str);
|
|
printWriter.println("Pending Actions:");
|
|
for (int i3 = 0; i3 < size3; i3++) {
|
|
printWriter.print(str);
|
|
printWriter.print(" #");
|
|
printWriter.print(i3);
|
|
printWriter.print(": ");
|
|
printWriter.println(this.mPendingActions.get(i3));
|
|
}
|
|
}
|
|
}
|
|
printWriter.print(str);
|
|
printWriter.println("FragmentManager misc state:");
|
|
printWriter.print(str);
|
|
printWriter.print(" mHost=");
|
|
printWriter.println(this.mHost);
|
|
printWriter.print(str);
|
|
printWriter.print(" mContainer=");
|
|
printWriter.println(this.mContainer);
|
|
if (this.mParent != null) {
|
|
printWriter.print(str);
|
|
printWriter.print(" mParent=");
|
|
printWriter.println(this.mParent);
|
|
}
|
|
printWriter.print(str);
|
|
printWriter.print(" mCurState=");
|
|
printWriter.print(this.mCurState);
|
|
printWriter.print(" mStateSaved=");
|
|
printWriter.print(this.mStateSaved);
|
|
printWriter.print(" mStopped=");
|
|
printWriter.print(this.mStopped);
|
|
printWriter.print(" mDestroyed=");
|
|
printWriter.println(this.mDestroyed);
|
|
if (this.mNeedMenuInvalidate) {
|
|
printWriter.print(str);
|
|
printWriter.print(" mNeedMenuInvalidate=");
|
|
printWriter.println(this.mNeedMenuInvalidate);
|
|
}
|
|
}
|
|
|
|
public void enqueueAction(@NonNull OpGenerator opGenerator, boolean z2) {
|
|
if (!z2) {
|
|
if (this.mHost != null) {
|
|
checkStateLoss();
|
|
} else if (this.mDestroyed) {
|
|
throw new IllegalStateException("FragmentManager has been destroyed");
|
|
} else {
|
|
throw new IllegalStateException("FragmentManager has not been attached to a host.");
|
|
}
|
|
}
|
|
synchronized (this.mPendingActions) {
|
|
if (this.mHost != null) {
|
|
this.mPendingActions.add(opGenerator);
|
|
scheduleCommit();
|
|
} else if (!z2) {
|
|
throw new IllegalStateException("Activity has been destroyed");
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: finally extract failed */
|
|
public boolean execPendingActions(boolean z2) {
|
|
ensureExecReady(z2);
|
|
boolean z3 = false;
|
|
while (generateOpsForPendingActions(this.mTmpRecords, this.mTmpIsPop)) {
|
|
this.mExecutingActions = true;
|
|
try {
|
|
removeRedundantOperationsAndExecute(this.mTmpRecords, this.mTmpIsPop);
|
|
cleanupExec();
|
|
z3 = true;
|
|
} catch (Throwable th) {
|
|
cleanupExec();
|
|
throw th;
|
|
}
|
|
}
|
|
updateOnBackPressedCallbackEnabled();
|
|
doPendingDeferredStart();
|
|
this.mFragmentStore.burpActive();
|
|
return z3;
|
|
}
|
|
|
|
public void execSingleAction(@NonNull OpGenerator opGenerator, boolean z2) {
|
|
if (!z2 || (this.mHost != null && !this.mDestroyed)) {
|
|
ensureExecReady(z2);
|
|
if (opGenerator.generateOps(this.mTmpRecords, this.mTmpIsPop)) {
|
|
this.mExecutingActions = true;
|
|
try {
|
|
removeRedundantOperationsAndExecute(this.mTmpRecords, this.mTmpIsPop);
|
|
} finally {
|
|
cleanupExec();
|
|
}
|
|
}
|
|
updateOnBackPressedCallbackEnabled();
|
|
doPendingDeferredStart();
|
|
this.mFragmentStore.burpActive();
|
|
}
|
|
}
|
|
|
|
public boolean executePendingTransactions() {
|
|
boolean execPendingActions = execPendingActions(true);
|
|
forcePostponedTransactions();
|
|
return execPendingActions;
|
|
}
|
|
|
|
@Nullable
|
|
public Fragment findActiveFragment(@NonNull String str) {
|
|
return this.mFragmentStore.findActiveFragment(str);
|
|
}
|
|
|
|
@Nullable
|
|
public Fragment findFragmentById(@IdRes int i) {
|
|
return this.mFragmentStore.findFragmentById(i);
|
|
}
|
|
|
|
@Nullable
|
|
public Fragment findFragmentByTag(@Nullable String str) {
|
|
return this.mFragmentStore.findFragmentByTag(str);
|
|
}
|
|
|
|
public Fragment findFragmentByWho(@NonNull String str) {
|
|
return this.mFragmentStore.findFragmentByWho(str);
|
|
}
|
|
|
|
public int getActiveFragmentCount() {
|
|
return this.mFragmentStore.getActiveFragmentCount();
|
|
}
|
|
|
|
@NonNull
|
|
public List<Fragment> getActiveFragments() {
|
|
return this.mFragmentStore.getActiveFragments();
|
|
}
|
|
|
|
@NonNull
|
|
public BackStackEntry getBackStackEntryAt(int i) {
|
|
return this.mBackStack.get(i);
|
|
}
|
|
|
|
public int getBackStackEntryCount() {
|
|
ArrayList<BackStackRecord> arrayList = this.mBackStack;
|
|
if (arrayList != null) {
|
|
return arrayList.size();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
@NonNull
|
|
public FragmentContainer getContainer() {
|
|
return this.mContainer;
|
|
}
|
|
|
|
@Nullable
|
|
public Fragment getFragment(@NonNull Bundle bundle, @NonNull String str) {
|
|
String string = bundle.getString(str);
|
|
if (string == null) {
|
|
return null;
|
|
}
|
|
Fragment findActiveFragment = findActiveFragment(string);
|
|
if (findActiveFragment == null) {
|
|
throwException(new IllegalStateException("Fragment no longer exists for key " + str + ": unique id " + string));
|
|
}
|
|
return findActiveFragment;
|
|
}
|
|
|
|
@NonNull
|
|
public FragmentFactory getFragmentFactory() {
|
|
FragmentFactory fragmentFactory = this.mFragmentFactory;
|
|
if (fragmentFactory != null) {
|
|
return fragmentFactory;
|
|
}
|
|
Fragment fragment = this.mParent;
|
|
return fragment != null ? fragment.mFragmentManager.getFragmentFactory() : this.mHostFragmentFactory;
|
|
}
|
|
|
|
@NonNull
|
|
public FragmentStore getFragmentStore() {
|
|
return this.mFragmentStore;
|
|
}
|
|
|
|
@NonNull
|
|
public List<Fragment> getFragments() {
|
|
return this.mFragmentStore.getFragments();
|
|
}
|
|
|
|
@NonNull
|
|
public FragmentHostCallback<?> getHost() {
|
|
return this.mHost;
|
|
}
|
|
|
|
@NonNull
|
|
public LayoutInflater.Factory2 getLayoutInflaterFactory() {
|
|
return this.mLayoutInflaterFactory;
|
|
}
|
|
|
|
@NonNull
|
|
public FragmentLifecycleCallbacksDispatcher getLifecycleCallbacksDispatcher() {
|
|
return this.mLifecycleCallbacksDispatcher;
|
|
}
|
|
|
|
@Nullable
|
|
public Fragment getParent() {
|
|
return this.mParent;
|
|
}
|
|
|
|
@Nullable
|
|
public Fragment getPrimaryNavigationFragment() {
|
|
return this.mPrimaryNav;
|
|
}
|
|
|
|
@NonNull
|
|
public SpecialEffectsControllerFactory getSpecialEffectsControllerFactory() {
|
|
SpecialEffectsControllerFactory specialEffectsControllerFactory = this.mSpecialEffectsControllerFactory;
|
|
if (specialEffectsControllerFactory != null) {
|
|
return specialEffectsControllerFactory;
|
|
}
|
|
Fragment fragment = this.mParent;
|
|
return fragment != null ? fragment.mFragmentManager.getSpecialEffectsControllerFactory() : this.mDefaultSpecialEffectsControllerFactory;
|
|
}
|
|
|
|
@NonNull
|
|
public ViewModelStore getViewModelStore(@NonNull Fragment fragment) {
|
|
return this.mNonConfig.getViewModelStore(fragment);
|
|
}
|
|
|
|
public void handleOnBackPressed() {
|
|
execPendingActions(true);
|
|
if (this.mOnBackPressedCallback.isEnabled()) {
|
|
popBackStackImmediate();
|
|
} else {
|
|
this.mOnBackPressedDispatcher.onBackPressed();
|
|
}
|
|
}
|
|
|
|
public void hideFragment(@NonNull Fragment fragment) {
|
|
if (isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "hide: " + fragment);
|
|
}
|
|
if (!fragment.mHidden) {
|
|
fragment.mHidden = true;
|
|
fragment.mHiddenChanged = true ^ fragment.mHiddenChanged;
|
|
setVisibleRemovingFragment(fragment);
|
|
}
|
|
}
|
|
|
|
public boolean isDestroyed() {
|
|
return this.mDestroyed;
|
|
}
|
|
|
|
public boolean isParentMenuVisible(@Nullable Fragment fragment) {
|
|
if (fragment == null) {
|
|
return true;
|
|
}
|
|
return fragment.isMenuVisible();
|
|
}
|
|
|
|
public boolean isPrimaryNavigation(@Nullable Fragment fragment) {
|
|
if (fragment == null) {
|
|
return true;
|
|
}
|
|
FragmentManager fragmentManager = fragment.mFragmentManager;
|
|
return fragment.equals(fragmentManager.getPrimaryNavigationFragment()) && isPrimaryNavigation(fragmentManager.mParent);
|
|
}
|
|
|
|
public boolean isStateAtLeast(int i) {
|
|
return this.mCurState >= i;
|
|
}
|
|
|
|
public boolean isStateSaved() {
|
|
return this.mStateSaved || this.mStopped;
|
|
}
|
|
|
|
public void launchRequestPermissions(@NonNull Fragment fragment, @NonNull String[] strArr, int i) {
|
|
if (this.mRequestPermissions != null) {
|
|
this.mLaunchedFragments.addLast(new LaunchedFragmentInfo(fragment.mWho, i));
|
|
this.mRequestPermissions.launch(strArr);
|
|
return;
|
|
}
|
|
this.mHost.onRequestPermissionsFromFragment(fragment, strArr, i);
|
|
}
|
|
|
|
public void launchStartActivityForResult(@NonNull Fragment fragment, @SuppressLint({"UnknownNullness"}) Intent intent, int i, @Nullable Bundle bundle) {
|
|
if (this.mStartActivityForResult != null) {
|
|
this.mLaunchedFragments.addLast(new LaunchedFragmentInfo(fragment.mWho, i));
|
|
if (!(intent == null || bundle == null)) {
|
|
intent.putExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE", bundle);
|
|
}
|
|
this.mStartActivityForResult.launch(intent);
|
|
return;
|
|
}
|
|
this.mHost.onStartActivityFromFragment(fragment, intent, i, bundle);
|
|
}
|
|
|
|
public void launchStartIntentSenderForResult(@NonNull Fragment fragment, @SuppressLint({"UnknownNullness"}) IntentSender intentSender, int i, @Nullable Intent intent, int i2, int i3, int i4, @Nullable Bundle bundle) throws IntentSender.SendIntentException {
|
|
Intent intent2;
|
|
if (this.mStartIntentSenderForResult != null) {
|
|
if (bundle != null) {
|
|
if (intent == null) {
|
|
intent2 = new Intent();
|
|
intent2.putExtra("androidx.fragment.extra.ACTIVITY_OPTIONS_BUNDLE", true);
|
|
} else {
|
|
intent2 = intent;
|
|
}
|
|
if (isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "ActivityOptions " + bundle + " were added to fillInIntent " + intent2 + " for fragment " + fragment);
|
|
}
|
|
intent2.putExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE", bundle);
|
|
} else {
|
|
intent2 = intent;
|
|
}
|
|
IntentSenderRequest build = new IntentSenderRequest.Builder(intentSender).setFillInIntent(intent2).setFlags(i3, i2).build();
|
|
this.mLaunchedFragments.addLast(new LaunchedFragmentInfo(fragment.mWho, i));
|
|
if (isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "Fragment " + fragment + "is launching an IntentSender for result ");
|
|
}
|
|
this.mStartIntentSenderForResult.launch(build);
|
|
return;
|
|
}
|
|
this.mHost.onStartIntentSenderFromFragment(fragment, intentSender, i, intent, i2, i3, i4, bundle);
|
|
}
|
|
|
|
public void moveFragmentToExpectedState(@NonNull Fragment fragment) {
|
|
if (this.mFragmentStore.containsActiveFragment(fragment.mWho)) {
|
|
moveToState(fragment);
|
|
View view = fragment.mView;
|
|
if (!(view == null || !fragment.mIsNewlyAdded || fragment.mContainer == null)) {
|
|
float f = fragment.mPostponedAlpha;
|
|
if (f > 0.0f) {
|
|
view.setAlpha(f);
|
|
}
|
|
fragment.mPostponedAlpha = 0.0f;
|
|
fragment.mIsNewlyAdded = false;
|
|
FragmentAnim.AnimationOrAnimator loadAnimation = FragmentAnim.loadAnimation(this.mHost.getContext(), fragment, true);
|
|
if (loadAnimation != null) {
|
|
Animation animation = loadAnimation.animation;
|
|
if (animation != null) {
|
|
fragment.mView.startAnimation(animation);
|
|
} else {
|
|
loadAnimation.animator.setTarget(fragment.mView);
|
|
loadAnimation.animator.start();
|
|
}
|
|
}
|
|
}
|
|
if (fragment.mHiddenChanged) {
|
|
completeShowHideFragment(fragment);
|
|
}
|
|
} else if (isLoggingEnabled(3)) {
|
|
Log.d("FragmentManager", "Ignoring moving " + fragment + " to state " + this.mCurState + "since it is not added to " + this);
|
|
}
|
|
}
|
|
|
|
public void moveToState(int i, boolean z2) {
|
|
FragmentHostCallback<?> fragmentHostCallback;
|
|
if (this.mHost == null && i != -1) {
|
|
throw new IllegalStateException("No activity");
|
|
} else if (z2 || i != this.mCurState) {
|
|
this.mCurState = i;
|
|
if (USE_STATE_MANAGER) {
|
|
this.mFragmentStore.moveToExpectedState();
|
|
} else {
|
|
for (Fragment fragment : this.mFragmentStore.getFragments()) {
|
|
moveFragmentToExpectedState(fragment);
|
|
}
|
|
for (FragmentStateManager fragmentStateManager : this.mFragmentStore.getActiveFragmentStateManagers()) {
|
|
Fragment fragment2 = fragmentStateManager.getFragment();
|
|
if (!fragment2.mIsNewlyAdded) {
|
|
moveFragmentToExpectedState(fragment2);
|
|
}
|
|
if (fragment2.mRemoving && !fragment2.isInBackStack()) {
|
|
this.mFragmentStore.makeInactive(fragmentStateManager);
|
|
}
|
|
}
|
|
}
|
|
startPendingDeferredFragments();
|
|
if (this.mNeedMenuInvalidate && (fragmentHostCallback = this.mHost) != null && this.mCurState == 7) {
|
|
fragmentHostCallback.onSupportInvalidateOptionsMenu();
|
|
this.mNeedMenuInvalidate = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void moveToState(@NonNull Fragment fragment) {
|
|
moveToState(fragment, this.mCurState);
|
|
}
|
|
|
|
/* JADX WARNING: Code restructure failed: missing block: B:22:0x0053, code lost:
|
|
if (r2 != 5) goto L_0x0161;
|
|
*/
|
|
/* JADX WARNING: Removed duplicated region for block: B:28:0x0063 */
|
|
/* JADX WARNING: Removed duplicated region for block: B:30:0x0068 */
|
|
/* JADX WARNING: Removed duplicated region for block: B:32:0x006d */
|
|
/* JADX WARNING: Removed duplicated region for block: B:34:0x0072 */
|
|
/* JADX WARNING: Removed duplicated region for block: B:36:0x0077 */
|
|
/* JADX WARNING: Removed duplicated region for block: B:94:0x015d */
|
|
public void moveToState(@NonNull Fragment fragment, int i) {
|
|
ViewGroup viewGroup;
|
|
FragmentStateManager fragmentStateManager = this.mFragmentStore.getFragmentStateManager(fragment.mWho);
|
|
int i2 = 1;
|
|
if (fragmentStateManager == null) {
|
|
fragmentStateManager = new FragmentStateManager(this.mLifecycleCallbacksDispatcher, this.mFragmentStore, fragment);
|
|
fragmentStateManager.setFragmentManagerState(1);
|
|
}
|
|
if (fragment.mFromLayout && fragment.mInLayout && fragment.mState == 2) {
|
|
i = Math.max(i, 2);
|
|
}
|
|
int min = Math.min(i, fragmentStateManager.computeExpectedState());
|
|
int i3 = fragment.mState;
|
|
if (i3 <= min) {
|
|
if (i3 < min && !this.mExitAnimationCancellationSignals.isEmpty()) {
|
|
cancelExitAnimation(fragment);
|
|
}
|
|
int i4 = fragment.mState;
|
|
if (i4 != -1) {
|
|
if (i4 != 0) {
|
|
if (i4 != 1) {
|
|
if (i4 != 2) {
|
|
if (i4 != 4) {
|
|
}
|
|
if (min > 4) {
|
|
fragmentStateManager.start();
|
|
}
|
|
if (min > 5) {
|
|
fragmentStateManager.resume();
|
|
}
|
|
}
|
|
if (min > 2) {
|
|
fragmentStateManager.activityCreated();
|
|
}
|
|
if (min > 4) {
|
|
}
|
|
if (min > 5) {
|
|
}
|
|
}
|
|
if (min > -1) {
|
|
fragmentStateManager.ensureInflatedView();
|
|
}
|
|
if (min > 1) {
|
|
fragmentStateManager.createView();
|
|
}
|
|
if (min > 2) {
|
|
}
|
|
if (min > 4) {
|
|
}
|
|
if (min > 5) {
|
|
}
|
|
}
|
|
} else if (min > -1) {
|
|
fragmentStateManager.attach();
|
|
}
|
|
if (min > 0) {
|
|
fragmentStateManager.create();
|
|
}
|
|
if (min > -1) {
|
|
}
|
|
if (min > 1) {
|
|
}
|
|
if (min > 2) {
|
|
}
|
|
if (min > 4) {
|
|
}
|
|
if (min > 5) {
|
|
}
|
|
} else if (i3 > min) {
|
|
if (i3 != 0) {
|
|
if (i3 != 1) {
|
|
if (i3 != 2) {
|
|
if (i3 != 4) {
|
|
if (i3 != 5) {
|
|
if (i3 == 7) {
|
|
if (min < 7) {
|
|
fragmentStateManager.pause();
|
|
}
|
|
}
|
|
}
|
|
if (min < 5) {
|
|
fragmentStateManager.stop();
|
|
}
|
|
}
|
|
if (min < 4) {
|
|
if (isLoggingEnabled(3)) {
|
|
Log.d("FragmentManager", "movefrom ACTIVITY_CREATED: " + fragment);
|
|
}
|
|
if (fragment.mView != null && this.mHost.onShouldSaveFragmentState(fragment) && fragment.mSavedViewState == null) {
|
|
fragmentStateManager.saveViewState();
|
|
}
|
|
}
|
|
}
|
|
if (min < 2) {
|
|
FragmentAnim.AnimationOrAnimator animationOrAnimator = null;
|
|
View view = fragment.mView;
|
|
if (!(view == null || (viewGroup = fragment.mContainer) == null)) {
|
|
viewGroup.endViewTransition(view);
|
|
fragment.mView.clearAnimation();
|
|
if (!fragment.isRemovingParent()) {
|
|
if (this.mCurState > -1 && !this.mDestroyed && fragment.mView.getVisibility() == 0 && fragment.mPostponedAlpha >= 0.0f) {
|
|
animationOrAnimator = FragmentAnim.loadAnimation(this.mHost.getContext(), fragment, false);
|
|
}
|
|
fragment.mPostponedAlpha = 0.0f;
|
|
ViewGroup viewGroup2 = fragment.mContainer;
|
|
View view2 = fragment.mView;
|
|
if (animationOrAnimator != null) {
|
|
FragmentAnim.animateRemoveFragment(fragment, animationOrAnimator, this.mFragmentTransitionCallback);
|
|
}
|
|
viewGroup2.removeView(view2);
|
|
if (isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "Removing view " + view2 + " for fragment " + fragment + " from container " + viewGroup2);
|
|
}
|
|
if (viewGroup2 != fragment.mContainer) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if (this.mExitAnimationCancellationSignals.get(fragment) == null) {
|
|
fragmentStateManager.destroyFragmentView();
|
|
}
|
|
}
|
|
}
|
|
if (min < 1) {
|
|
if (this.mExitAnimationCancellationSignals.get(fragment) == null) {
|
|
fragmentStateManager.destroy();
|
|
}
|
|
if (i2 < 0) {
|
|
fragmentStateManager.detach();
|
|
}
|
|
min = i2;
|
|
}
|
|
}
|
|
i2 = min;
|
|
if (i2 < 0) {
|
|
}
|
|
min = i2;
|
|
}
|
|
if (fragment.mState != min) {
|
|
if (isLoggingEnabled(3)) {
|
|
Log.d("FragmentManager", "moveToState: Fragment state for " + fragment + " not updated inline; expected state " + min + " found " + fragment.mState);
|
|
}
|
|
fragment.mState = min;
|
|
}
|
|
}
|
|
|
|
public void noteStateNotSaved() {
|
|
if (this.mHost != null) {
|
|
this.mStateSaved = false;
|
|
this.mStopped = false;
|
|
this.mNonConfig.setIsStateSaved(false);
|
|
for (Fragment fragment : this.mFragmentStore.getFragments()) {
|
|
if (fragment != null) {
|
|
fragment.noteStateNotSaved();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
@Deprecated
|
|
public FragmentTransaction openTransaction() {
|
|
return beginTransaction();
|
|
}
|
|
|
|
public void performPendingDeferredStart(@NonNull FragmentStateManager fragmentStateManager) {
|
|
Fragment fragment = fragmentStateManager.getFragment();
|
|
if (!fragment.mDeferStart) {
|
|
return;
|
|
}
|
|
if (this.mExecutingActions) {
|
|
this.mHavePendingDeferredStart = true;
|
|
return;
|
|
}
|
|
fragment.mDeferStart = false;
|
|
if (USE_STATE_MANAGER) {
|
|
fragmentStateManager.moveToExpectedState();
|
|
} else {
|
|
moveToState(fragment);
|
|
}
|
|
}
|
|
|
|
public void popBackStack() {
|
|
enqueueAction(new PopBackStackState(null, -1, 0), false);
|
|
}
|
|
|
|
public void popBackStack(int i, int i2) {
|
|
if (i >= 0) {
|
|
enqueueAction(new PopBackStackState(null, i, i2), false);
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException(a.l("Bad id: ", i));
|
|
}
|
|
|
|
public void popBackStack(@Nullable String str, int i) {
|
|
enqueueAction(new PopBackStackState(str, -1, i), false);
|
|
}
|
|
|
|
public boolean popBackStackImmediate() {
|
|
return popBackStackImmediate(null, -1, 0);
|
|
}
|
|
|
|
public boolean popBackStackImmediate(int i, int i2) {
|
|
if (i >= 0) {
|
|
return popBackStackImmediate(null, i, i2);
|
|
}
|
|
throw new IllegalArgumentException(a.l("Bad id: ", i));
|
|
}
|
|
|
|
public boolean popBackStackImmediate(@Nullable String str, int i) {
|
|
return popBackStackImmediate(str, -1, i);
|
|
}
|
|
|
|
public boolean popBackStackState(@NonNull ArrayList<BackStackRecord> arrayList, @NonNull ArrayList<Boolean> arrayList2, @Nullable String str, int i, int i2) {
|
|
int i3;
|
|
ArrayList<BackStackRecord> arrayList3 = this.mBackStack;
|
|
if (arrayList3 == null) {
|
|
return false;
|
|
}
|
|
if (str == null && i < 0 && (i2 & 1) == 0) {
|
|
int size = arrayList3.size() - 1;
|
|
if (size < 0) {
|
|
return false;
|
|
}
|
|
arrayList.add(this.mBackStack.remove(size));
|
|
arrayList2.add(Boolean.TRUE);
|
|
} else {
|
|
if (str != null || i >= 0) {
|
|
int size2 = arrayList3.size() - 1;
|
|
while (size2 >= 0) {
|
|
BackStackRecord backStackRecord = this.mBackStack.get(size2);
|
|
if ((str != null && str.equals(backStackRecord.getName())) || (i >= 0 && i == backStackRecord.mIndex)) {
|
|
break;
|
|
}
|
|
size2--;
|
|
}
|
|
if (size2 < 0) {
|
|
return false;
|
|
}
|
|
if ((i2 & 1) != 0) {
|
|
while (true) {
|
|
size2--;
|
|
if (size2 < 0) {
|
|
break;
|
|
}
|
|
BackStackRecord backStackRecord2 = this.mBackStack.get(size2);
|
|
if (str == null || !str.equals(backStackRecord2.getName())) {
|
|
if (i < 0 || i != backStackRecord2.mIndex) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
i3 = size2;
|
|
} else {
|
|
i3 = -1;
|
|
}
|
|
if (i3 == this.mBackStack.size() - 1) {
|
|
return false;
|
|
}
|
|
for (int size3 = this.mBackStack.size() - 1; size3 > i3; size3--) {
|
|
arrayList.add(this.mBackStack.remove(size3));
|
|
arrayList2.add(Boolean.TRUE);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public void putFragment(@NonNull Bundle bundle, @NonNull String str, @NonNull Fragment fragment) {
|
|
if (fragment.mFragmentManager != this) {
|
|
throwException(new IllegalStateException(a.s("Fragment ", fragment, " is not currently in the FragmentManager")));
|
|
}
|
|
bundle.putString(str, fragment.mWho);
|
|
}
|
|
|
|
public void registerFragmentLifecycleCallbacks(@NonNull FragmentLifecycleCallbacks fragmentLifecycleCallbacks, boolean z2) {
|
|
this.mLifecycleCallbacksDispatcher.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, z2);
|
|
}
|
|
|
|
public void removeCancellationSignal(@NonNull Fragment fragment, @NonNull CancellationSignal cancellationSignal) {
|
|
HashSet<CancellationSignal> hashSet = this.mExitAnimationCancellationSignals.get(fragment);
|
|
if (hashSet != null && hashSet.remove(cancellationSignal) && hashSet.isEmpty()) {
|
|
this.mExitAnimationCancellationSignals.remove(fragment);
|
|
if (fragment.mState < 5) {
|
|
destroyFragmentView(fragment);
|
|
moveToState(fragment);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void removeFragment(@NonNull Fragment fragment) {
|
|
if (isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "remove: " + fragment + " nesting=" + fragment.mBackStackNesting);
|
|
}
|
|
boolean z2 = !fragment.isInBackStack();
|
|
if (!fragment.mDetached || z2) {
|
|
this.mFragmentStore.removeFragment(fragment);
|
|
if (isMenuAvailable(fragment)) {
|
|
this.mNeedMenuInvalidate = true;
|
|
}
|
|
fragment.mRemoving = true;
|
|
setVisibleRemovingFragment(fragment);
|
|
}
|
|
}
|
|
|
|
public void removeFragmentOnAttachListener(@NonNull FragmentOnAttachListener fragmentOnAttachListener) {
|
|
this.mOnAttachListeners.remove(fragmentOnAttachListener);
|
|
}
|
|
|
|
public void removeOnBackStackChangedListener(@NonNull OnBackStackChangedListener onBackStackChangedListener) {
|
|
ArrayList<OnBackStackChangedListener> arrayList = this.mBackStackChangeListeners;
|
|
if (arrayList != null) {
|
|
arrayList.remove(onBackStackChangedListener);
|
|
}
|
|
}
|
|
|
|
public void removeRetainedFragment(@NonNull Fragment fragment) {
|
|
this.mNonConfig.removeRetainedFragment(fragment);
|
|
}
|
|
|
|
public void restoreAllState(@Nullable Parcelable parcelable, @Nullable FragmentManagerNonConfig fragmentManagerNonConfig) {
|
|
if (this.mHost instanceof ViewModelStoreOwner) {
|
|
throwException(new IllegalStateException("You must use restoreSaveState when your FragmentHostCallback implements ViewModelStoreOwner"));
|
|
}
|
|
this.mNonConfig.restoreFromSnapshot(fragmentManagerNonConfig);
|
|
restoreSaveState(parcelable);
|
|
}
|
|
|
|
public void restoreSaveState(@Nullable Parcelable parcelable) {
|
|
FragmentStateManager fragmentStateManager;
|
|
if (parcelable != null) {
|
|
FragmentManagerState fragmentManagerState = (FragmentManagerState) parcelable;
|
|
if (fragmentManagerState.mActive != null) {
|
|
this.mFragmentStore.resetActiveFragments();
|
|
Iterator<FragmentState> it = fragmentManagerState.mActive.iterator();
|
|
while (it.hasNext()) {
|
|
FragmentState next = it.next();
|
|
if (next != null) {
|
|
Fragment findRetainedFragmentByWho = this.mNonConfig.findRetainedFragmentByWho(next.mWho);
|
|
if (findRetainedFragmentByWho != null) {
|
|
if (isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "restoreSaveState: re-attaching retained " + findRetainedFragmentByWho);
|
|
}
|
|
fragmentStateManager = new FragmentStateManager(this.mLifecycleCallbacksDispatcher, this.mFragmentStore, findRetainedFragmentByWho, next);
|
|
} else {
|
|
fragmentStateManager = new FragmentStateManager(this.mLifecycleCallbacksDispatcher, this.mFragmentStore, this.mHost.getContext().getClassLoader(), getFragmentFactory(), next);
|
|
}
|
|
Fragment fragment = fragmentStateManager.getFragment();
|
|
fragment.mFragmentManager = this;
|
|
if (isLoggingEnabled(2)) {
|
|
StringBuilder L = a.L("restoreSaveState: active (");
|
|
L.append(fragment.mWho);
|
|
L.append("): ");
|
|
L.append(fragment);
|
|
Log.v("FragmentManager", L.toString());
|
|
}
|
|
fragmentStateManager.restoreState(this.mHost.getContext().getClassLoader());
|
|
this.mFragmentStore.makeActive(fragmentStateManager);
|
|
fragmentStateManager.setFragmentManagerState(this.mCurState);
|
|
}
|
|
}
|
|
for (Fragment fragment2 : this.mNonConfig.getRetainedFragments()) {
|
|
if (!this.mFragmentStore.containsActiveFragment(fragment2.mWho)) {
|
|
if (isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "Discarding retained Fragment " + fragment2 + " that was not found in the set of active Fragments " + fragmentManagerState.mActive);
|
|
}
|
|
this.mNonConfig.removeRetainedFragment(fragment2);
|
|
fragment2.mFragmentManager = this;
|
|
FragmentStateManager fragmentStateManager2 = new FragmentStateManager(this.mLifecycleCallbacksDispatcher, this.mFragmentStore, fragment2);
|
|
fragmentStateManager2.setFragmentManagerState(1);
|
|
fragmentStateManager2.moveToExpectedState();
|
|
fragment2.mRemoving = true;
|
|
fragmentStateManager2.moveToExpectedState();
|
|
}
|
|
}
|
|
this.mFragmentStore.restoreAddedFragments(fragmentManagerState.mAdded);
|
|
if (fragmentManagerState.mBackStack != null) {
|
|
this.mBackStack = new ArrayList<>(fragmentManagerState.mBackStack.length);
|
|
int i = 0;
|
|
while (true) {
|
|
BackStackState[] backStackStateArr = fragmentManagerState.mBackStack;
|
|
if (i >= backStackStateArr.length) {
|
|
break;
|
|
}
|
|
BackStackRecord instantiate = backStackStateArr[i].instantiate(this);
|
|
if (isLoggingEnabled(2)) {
|
|
StringBuilder M = a.M("restoreAllState: back stack #", i, " (index ");
|
|
M.append(instantiate.mIndex);
|
|
M.append("): ");
|
|
M.append(instantiate);
|
|
Log.v("FragmentManager", M.toString());
|
|
PrintWriter printWriter = new PrintWriter(new LogWriter("FragmentManager"));
|
|
instantiate.dump(" ", printWriter, false);
|
|
printWriter.close();
|
|
}
|
|
this.mBackStack.add(instantiate);
|
|
i++;
|
|
}
|
|
} else {
|
|
this.mBackStack = null;
|
|
}
|
|
this.mBackStackIndex.set(fragmentManagerState.mBackStackIndex);
|
|
String str = fragmentManagerState.mPrimaryNavActiveWho;
|
|
if (str != null) {
|
|
Fragment findActiveFragment = findActiveFragment(str);
|
|
this.mPrimaryNav = findActiveFragment;
|
|
dispatchParentPrimaryNavigationFragmentChanged(findActiveFragment);
|
|
}
|
|
ArrayList<String> arrayList = fragmentManagerState.mResultKeys;
|
|
if (arrayList != null) {
|
|
for (int i2 = 0; i2 < arrayList.size(); i2++) {
|
|
this.mResults.put(arrayList.get(i2), fragmentManagerState.mResults.get(i2));
|
|
}
|
|
}
|
|
this.mLaunchedFragments = new ArrayDeque<>(fragmentManagerState.mLaunchedFragments);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Deprecated
|
|
public FragmentManagerNonConfig retainNonConfig() {
|
|
if (this.mHost instanceof ViewModelStoreOwner) {
|
|
throwException(new IllegalStateException("You cannot use retainNonConfig when your FragmentHostCallback implements ViewModelStoreOwner."));
|
|
}
|
|
return this.mNonConfig.getSnapshot();
|
|
}
|
|
|
|
public Parcelable saveAllState() {
|
|
int size;
|
|
forcePostponedTransactions();
|
|
endAnimatingAwayFragments();
|
|
execPendingActions(true);
|
|
this.mStateSaved = true;
|
|
this.mNonConfig.setIsStateSaved(true);
|
|
ArrayList<FragmentState> saveActiveFragments = this.mFragmentStore.saveActiveFragments();
|
|
BackStackState[] backStackStateArr = null;
|
|
if (saveActiveFragments.isEmpty()) {
|
|
if (isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "saveAllState: no fragments!");
|
|
}
|
|
return null;
|
|
}
|
|
ArrayList<String> saveAddedFragments = this.mFragmentStore.saveAddedFragments();
|
|
ArrayList<BackStackRecord> arrayList = this.mBackStack;
|
|
if (arrayList != null && (size = arrayList.size()) > 0) {
|
|
backStackStateArr = new BackStackState[size];
|
|
for (int i = 0; i < size; i++) {
|
|
backStackStateArr[i] = new BackStackState(this.mBackStack.get(i));
|
|
if (isLoggingEnabled(2)) {
|
|
StringBuilder M = a.M("saveAllState: adding back stack #", i, ": ");
|
|
M.append(this.mBackStack.get(i));
|
|
Log.v("FragmentManager", M.toString());
|
|
}
|
|
}
|
|
}
|
|
FragmentManagerState fragmentManagerState = new FragmentManagerState();
|
|
fragmentManagerState.mActive = saveActiveFragments;
|
|
fragmentManagerState.mAdded = saveAddedFragments;
|
|
fragmentManagerState.mBackStack = backStackStateArr;
|
|
fragmentManagerState.mBackStackIndex = this.mBackStackIndex.get();
|
|
Fragment fragment = this.mPrimaryNav;
|
|
if (fragment != null) {
|
|
fragmentManagerState.mPrimaryNavActiveWho = fragment.mWho;
|
|
}
|
|
fragmentManagerState.mResultKeys.addAll(this.mResults.keySet());
|
|
fragmentManagerState.mResults.addAll(this.mResults.values());
|
|
fragmentManagerState.mLaunchedFragments = new ArrayList<>(this.mLaunchedFragments);
|
|
return fragmentManagerState;
|
|
}
|
|
|
|
@Nullable
|
|
public Fragment.SavedState saveFragmentInstanceState(@NonNull Fragment fragment) {
|
|
FragmentStateManager fragmentStateManager = this.mFragmentStore.getFragmentStateManager(fragment.mWho);
|
|
if (fragmentStateManager == null || !fragmentStateManager.getFragment().equals(fragment)) {
|
|
throwException(new IllegalStateException(a.s("Fragment ", fragment, " is not currently in the FragmentManager")));
|
|
}
|
|
return fragmentStateManager.saveInstanceState();
|
|
}
|
|
|
|
public void scheduleCommit() {
|
|
synchronized (this.mPendingActions) {
|
|
ArrayList<StartEnterTransitionListener> arrayList = this.mPostponedTransactions;
|
|
boolean z2 = false;
|
|
boolean z3 = arrayList != null && !arrayList.isEmpty();
|
|
if (this.mPendingActions.size() == 1) {
|
|
z2 = true;
|
|
}
|
|
if (z3 || z2) {
|
|
this.mHost.getHandler().removeCallbacks(this.mExecCommit);
|
|
this.mHost.getHandler().post(this.mExecCommit);
|
|
updateOnBackPressedCallbackEnabled();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void setExitAnimationOrder(@NonNull Fragment fragment, boolean z2) {
|
|
ViewGroup fragmentContainer = getFragmentContainer(fragment);
|
|
if (fragmentContainer != null && (fragmentContainer instanceof FragmentContainerView)) {
|
|
((FragmentContainerView) fragmentContainer).setDrawDisappearingViewsLast(!z2);
|
|
}
|
|
}
|
|
|
|
public void setFragmentFactory(@NonNull FragmentFactory fragmentFactory) {
|
|
this.mFragmentFactory = fragmentFactory;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentResultOwner
|
|
public final void setFragmentResult(@NonNull String str, @NonNull Bundle bundle) {
|
|
LifecycleAwareResultListener lifecycleAwareResultListener = this.mResultListeners.get(str);
|
|
if (lifecycleAwareResultListener == null || !lifecycleAwareResultListener.isAtLeast(Lifecycle.State.STARTED)) {
|
|
this.mResults.put(str, bundle);
|
|
} else {
|
|
lifecycleAwareResultListener.onFragmentResult(str, bundle);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentResultOwner
|
|
@SuppressLint({"SyntheticAccessor"})
|
|
public final void setFragmentResultListener(@NonNull String str, @NonNull LifecycleOwner lifecycleOwner, @NonNull FragmentResultListener fragmentResultListener) {
|
|
Lifecycle lifecycle = lifecycleOwner.getLifecycle();
|
|
if (lifecycle.getCurrentState() != Lifecycle.State.DESTROYED) {
|
|
AnonymousClass6 r0 = new AnonymousClass6(str, fragmentResultListener, lifecycle);
|
|
lifecycle.addObserver(r0);
|
|
LifecycleAwareResultListener put = this.mResultListeners.put(str, new LifecycleAwareResultListener(lifecycle, fragmentResultListener, r0));
|
|
if (put != null) {
|
|
put.removeObserver();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void setMaxLifecycle(@NonNull Fragment fragment, @NonNull Lifecycle.State state) {
|
|
if (!fragment.equals(findActiveFragment(fragment.mWho)) || !(fragment.mHost == null || fragment.mFragmentManager == this)) {
|
|
throw new IllegalArgumentException("Fragment " + fragment + " is not an active fragment of FragmentManager " + this);
|
|
}
|
|
fragment.mMaxState = state;
|
|
}
|
|
|
|
public void setPrimaryNavigationFragment(@Nullable Fragment fragment) {
|
|
if (fragment == null || (fragment.equals(findActiveFragment(fragment.mWho)) && (fragment.mHost == null || fragment.mFragmentManager == this))) {
|
|
Fragment fragment2 = this.mPrimaryNav;
|
|
this.mPrimaryNav = fragment;
|
|
dispatchParentPrimaryNavigationFragmentChanged(fragment2);
|
|
dispatchParentPrimaryNavigationFragmentChanged(this.mPrimaryNav);
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("Fragment " + fragment + " is not an active fragment of FragmentManager " + this);
|
|
}
|
|
|
|
public void setSpecialEffectsControllerFactory(@NonNull SpecialEffectsControllerFactory specialEffectsControllerFactory) {
|
|
this.mSpecialEffectsControllerFactory = specialEffectsControllerFactory;
|
|
}
|
|
|
|
public void showFragment(@NonNull Fragment fragment) {
|
|
if (isLoggingEnabled(2)) {
|
|
Log.v("FragmentManager", "show: " + fragment);
|
|
}
|
|
if (fragment.mHidden) {
|
|
fragment.mHidden = false;
|
|
fragment.mHiddenChanged = !fragment.mHiddenChanged;
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
public String toString() {
|
|
StringBuilder sb = new StringBuilder(128);
|
|
sb.append("FragmentManager{");
|
|
sb.append(Integer.toHexString(System.identityHashCode(this)));
|
|
sb.append(" in ");
|
|
Fragment fragment = this.mParent;
|
|
if (fragment != null) {
|
|
sb.append(fragment.getClass().getSimpleName());
|
|
sb.append("{");
|
|
sb.append(Integer.toHexString(System.identityHashCode(this.mParent)));
|
|
sb.append("}");
|
|
} else {
|
|
FragmentHostCallback<?> fragmentHostCallback = this.mHost;
|
|
if (fragmentHostCallback != null) {
|
|
sb.append(fragmentHostCallback.getClass().getSimpleName());
|
|
sb.append("{");
|
|
sb.append(Integer.toHexString(System.identityHashCode(this.mHost)));
|
|
sb.append("}");
|
|
} else {
|
|
sb.append("null");
|
|
}
|
|
}
|
|
sb.append("}}");
|
|
return sb.toString();
|
|
}
|
|
|
|
public void unregisterFragmentLifecycleCallbacks(@NonNull FragmentLifecycleCallbacks fragmentLifecycleCallbacks) {
|
|
this.mLifecycleCallbacksDispatcher.unregisterFragmentLifecycleCallbacks(fragmentLifecycleCallbacks);
|
|
}
|
|
}
|