MD5 校验值:d555a6389a0a865314e2706996812829
FragmentManagerImpl.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package fodroidx.fragment.app; import android.R; import android.animation.Animator; import android.animation.AnimatorInflater; import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; import android.animation.PropertyValuesHolder; import android.animation.ValueAnimator; import android.content.Context; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.os.Build; import android.os.Bundle; import android.os.Looper; import android.os.Parcelable; import android.util.AttributeSet; import android.util.Log; import android.util.SparseArray; 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.animation.AccelerateInterpolator; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.AnimationUtils; import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; import android.view.animation.ScaleAnimation; import android.view.animation.Transformation; import fodroidx.collection.ArraySet; import fodroidx.core.os.EnvironmentCompat; import fodroidx.core.util.DebugUtils; import fodroidx.core.util.LogWriter; import fodroidx.core.view.ViewCompat; import fodroidx.fragment.app.Fragment; import fodroidx.fragment.app.FragmentManager; import fodroidx.lifecycle.ViewModelStore; import java.io.FileDescriptor; import java.io.PrintWriter; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; public final class FragmentManagerImpl extends FragmentManager implements LayoutInflater.Factory2 { static final int ANIM_DUR = 220; public static final int ANIM_STYLE_CLOSE_ENTER = 3; public static final int ANIM_STYLE_CLOSE_EXIT = 4; public static final int ANIM_STYLE_FADE_ENTER = 5; public static final int ANIM_STYLE_FADE_EXIT = 6; public static final int ANIM_STYLE_OPEN_ENTER = 1; public static final int ANIM_STYLE_OPEN_EXIT = 2; static boolean DEBUG = false; static final String TAG = "FragmentManager"; static final String TARGET_REQUEST_CODE_STATE_TAG = "android:target_req_state"; static final String TARGET_STATE_TAG = "android:target_state"; static final String USER_VISIBLE_HINT_TAG = "android:user_visible_hint"; static final String VIEW_STATE_TAG = "android:view_state"; static Field sAnimationListenerField; SparseArray<Fragment> mActive; ArrayList<Integer> mAvailBackStackIndices; ArrayList<BackStackRecord> mBackStack; ArrayList<FragmentManager.OnBackStackChangedListener> mBackStackChangeListeners; ArrayList<BackStackRecord> mBackStackIndices; FragmentContainer mContainer; ArrayList<Fragment> mCreatedMenus; boolean mDestroyed; boolean mExecutingActions; boolean mHavePendingDeferredStart; FragmentHostCallback mHost; boolean mNeedMenuInvalidate; String mNoTransactionsBecause; Fragment mParent; ArrayList<OpGenerator> mPendingActions; ArrayList<StartEnterTransitionListener> mPostponedTransactions; Fragment mPrimaryNav; FragmentManagerNonConfig mSavedNonConfig; boolean mStateSaved; boolean mStopped; ArrayList<Fragment> mTmpAddedFragments; ArrayList<Boolean> mTmpIsPop; ArrayList<BackStackRecord> mTmpRecords; static final Interpolator DECELERATE_QUINT = new DecelerateInterpolator(2.5f); static final Interpolator DECELERATE_CUBIC = new DecelerateInterpolator(1.5f); static final Interpolator ACCELERATE_QUINT = new AccelerateInterpolator(2.5f); static final Interpolator ACCELERATE_CUBIC = new AccelerateInterpolator(1.5f); int mNextFragmentIndex = 0; final ArrayList<Fragment> mAdded = new ArrayList<>(); private final CopyOnWriteArrayList<FragmentLifecycleCallbacksHolder> mLifecycleCallbacks = new CopyOnWriteArrayList<>(); int mCurState = 0; Bundle mStateBundle = null; SparseArray<Parcelable> mStateArray = null; Runnable mExecCommit = new Runnable() { @Override public void run() { FragmentManagerImpl.this.execPendingActions(); } }; public interface OpGenerator { boolean generateOps(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2); } public static int reverseTransit(int i) { if (i == 4097) { return 8194; } if (i == 4099) { return FragmentTransaction.TRANSIT_FRAGMENT_FADE; } if (i != 8194) { return 0; } return FragmentTransaction.TRANSIT_FRAGMENT_OPEN; } public static int transitToStyleIndex(int i, boolean z) { if (i == 4097) { return z ? 1 : 2; } if (i == 4099) { return z ? 5 : 6; } if (i != 8194) { return -1; } return z ? 3 : 4; } public LayoutInflater.Factory2 getLayoutInflaterFactory() { return this; } public static final class FragmentLifecycleCallbacksHolder { final FragmentManager.FragmentLifecycleCallbacks mCallback; final boolean mRecursive; FragmentLifecycleCallbacksHolder(FragmentManager.FragmentLifecycleCallbacks fragmentLifecycleCallbacks, boolean z) { this.mCallback = fragmentLifecycleCallbacks; this.mRecursive = z; } } static boolean modifiesAlpha(AnimationOrAnimator animationOrAnimator) { if (animationOrAnimator.animation instanceof AlphaAnimation) { return true; } if (animationOrAnimator.animation instanceof AnimationSet) { List<Animation> animations = ((AnimationSet) animationOrAnimator.animation).getAnimations(); for (int i = 0; i < animations.size(); i++) { if (animations.get(i) instanceof AlphaAnimation) { return true; } } return false; } return modifiesAlpha(animationOrAnimator.animator); } static boolean modifiesAlpha(Animator animator) { if (animator == null) { return false; } if (animator instanceof ValueAnimator) { for (PropertyValuesHolder propertyValuesHolder : ((ValueAnimator) animator).getValues()) { if ("alpha".equals(propertyValuesHolder.getPropertyName())) { return true; } } } else if (animator instanceof AnimatorSet) { ArrayList<Animator> childAnimations = ((AnimatorSet) animator).getChildAnimations(); for (int i = 0; i < childAnimations.size(); i++) { if (modifiesAlpha(childAnimations.get(i))) { return true; } } } return false; } static boolean shouldRunOnHWLayer(View view, AnimationOrAnimator animationOrAnimator) { return view != null && animationOrAnimator != null && Build.VERSION.SDK_INT >= 19 && view.getLayerType() == 0 && ViewCompat.hasOverlappingRendering(view) && modifiesAlpha(animationOrAnimator); } private void throwException(RuntimeException runtimeException) { Log.e(TAG, runtimeException.getMessage()); Log.e(TAG, "Activity state:"); PrintWriter printWriter = new PrintWriter(new LogWriter(TAG)); FragmentHostCallback fragmentHostCallback = this.mHost; if (fragmentHostCallback != null) { try { fragmentHostCallback.onDump(" ", null, printWriter, new String[0]); throw runtimeException; } catch (Exception e) { Log.e(TAG, "Failed dumping state", e); throw runtimeException; } } try { dump(" ", null, printWriter, new String[0]); throw runtimeException; } catch (Exception e2) { Log.e(TAG, "Failed dumping state", e2); throw runtimeException; } } @Override public FragmentTransaction beginTransaction() { return new BackStackRecord(this); } @Override public boolean executePendingTransactions() { boolean execPendingActions = execPendingActions(); forcePostponedTransactions(); return execPendingActions; } @Override public void popBackStack() { enqueueAction(new PopBackStackState(null, -1, 0), false); } @Override public boolean popBackStackImmediate() { checkStateLoss(); return popBackStackImmediate(null, -1, 0); } @Override public void popBackStack(String str, int i) { enqueueAction(new PopBackStackState(str, -1, i), false); } @Override public boolean popBackStackImmediate(String str, int i) { checkStateLoss(); return popBackStackImmediate(str, -1, i); } @Override public void popBackStack(int i, int i2) { if (i < 0) { throw new IllegalArgumentException("Bad id: " + i); } enqueueAction(new PopBackStackState(null, i, i2), false); } @Override public boolean popBackStackImmediate(int i, int i2) { checkStateLoss(); execPendingActions(); if (i < 0) { throw new IllegalArgumentException("Bad id: " + i); } return popBackStackImmediate(null, i, i2); } private boolean popBackStackImmediate(String str, int i, int i2) { FragmentManager peekChildFragmentManager; execPendingActions(); ensureExecReady(true); Fragment fragment = this.mPrimaryNav; if (fragment != null && i < 0 && str == null && (peekChildFragmentManager = fragment.peekChildFragmentManager()) != null && peekChildFragmentManager.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(); } } doPendingDeferredStart(); burpActive(); return popBackStackState; } @Override public int getBackStackEntryCount() { ArrayList<BackStackRecord> arrayList = this.mBackStack; if (arrayList != null) { return arrayList.size(); } return 0; } @Override public FragmentManager.BackStackEntry getBackStackEntryAt(int i) { return this.mBackStack.get(i); } @Override public void addOnBackStackChangedListener(FragmentManager.OnBackStackChangedListener onBackStackChangedListener) { if (this.mBackStackChangeListeners == null) { this.mBackStackChangeListeners = new ArrayList<>(); } this.mBackStackChangeListeners.add(onBackStackChangedListener); } @Override public void removeOnBackStackChangedListener(FragmentManager.OnBackStackChangedListener onBackStackChangedListener) { ArrayList<FragmentManager.OnBackStackChangedListener> arrayList = this.mBackStackChangeListeners; if (arrayList != null) { arrayList.remove(onBackStackChangedListener); } } @Override public void putFragment(Bundle bundle, String str, Fragment fragment) { if (fragment.mIndex < 0) { throwException(new IllegalStateException("Fragment " + fragment + " is not currently in the FragmentManager")); } bundle.putInt(str, fragment.mIndex); } @Override public Fragment getFragment(Bundle bundle, String str) { int i = bundle.getInt(str, -1); if (i == -1) { return null; } Fragment fragment = this.mActive.get(i); if (fragment == null) { throwException(new IllegalStateException("Fragment no longer exists for key " + str + ": index " + i)); } return fragment; } @Override public List<Fragment> getFragments() { List<Fragment> list; if (this.mAdded.isEmpty()) { return Collections.emptyList(); } synchronized (this.mAdded) { list = (List) this.mAdded.clone(); } return list; } public List<Fragment> getActiveFragments() { SparseArray<Fragment> sparseArray = this.mActive; if (sparseArray == null) { return null; } int size = sparseArray.size(); ArrayList arrayList = new ArrayList(size); for (int i = 0; i < size; i++) { arrayList.add(this.mActive.valueAt(i)); } return arrayList; } public int getActiveFragmentCount() { SparseArray<Fragment> sparseArray = this.mActive; if (sparseArray == null) { return 0; } return sparseArray.size(); } @Override public Fragment.SavedState saveFragmentInstanceState(Fragment fragment) { Bundle saveFragmentBasicState; if (fragment.mIndex < 0) { throwException(new IllegalStateException("Fragment " + fragment + " is not currently in the FragmentManager")); } if (fragment.mState <= 0 || (saveFragmentBasicState = saveFragmentBasicState(fragment)) == null) { return null; } return new Fragment.SavedState(saveFragmentBasicState); } @Override public boolean isDestroyed() { return this.mDestroyed; } 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) { DebugUtils.buildShortClassTag(fragment, sb); } else { DebugUtils.buildShortClassTag(this.mHost, sb); } sb.append("}}"); return sb.toString(); } @Override public void dump(String str, FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) { int size; int size2; int size3; int size4; int size5; String str2 = str + " "; SparseArray<Fragment> sparseArray = this.mActive; if (sparseArray != null && (size5 = sparseArray.size()) > 0) { printWriter.print(str); printWriter.print("Active Fragments in "); printWriter.print(Integer.toHexString(System.identityHashCode(this))); printWriter.println(":"); for (int i = 0; i < size5; i++) { Fragment valueAt = this.mActive.valueAt(i); printWriter.print(str); printWriter.print(" #"); printWriter.print(i); printWriter.print(": "); printWriter.println(valueAt); if (valueAt != null) { valueAt.dump(str2, fileDescriptor, printWriter, strArr); } } } int size6 = this.mAdded.size(); if (size6 > 0) { printWriter.print(str); printWriter.println("Added Fragments:"); for (int i2 = 0; i2 < size6; i2++) { Fragment fragment = this.mAdded.get(i2); printWriter.print(str); printWriter.print(" #"); printWriter.print(i2); printWriter.print(": "); printWriter.println(fragment.toString()); } } ArrayList<Fragment> arrayList = this.mCreatedMenus; if (arrayList != null && (size4 = arrayList.size()) > 0) { printWriter.print(str); printWriter.println("Fragments Created Menus:"); for (int i3 = 0; i3 < size4; i3++) { Fragment fragment2 = this.mCreatedMenus.get(i3); printWriter.print(str); printWriter.print(" #"); printWriter.print(i3); printWriter.print(": "); printWriter.println(fragment2.toString()); } } ArrayList<BackStackRecord> arrayList2 = this.mBackStack; if (arrayList2 != null && (size3 = arrayList2.size()) > 0) { printWriter.print(str); printWriter.println("Back Stack:"); for (int i4 = 0; i4 < size3; i4++) { BackStackRecord backStackRecord = this.mBackStack.get(i4); printWriter.print(str); printWriter.print(" #"); printWriter.print(i4); printWriter.print(": "); printWriter.println(backStackRecord.toString()); backStackRecord.dump(str2, fileDescriptor, printWriter, strArr); } } synchronized (this) { if (this.mBackStackIndices != null && (size2 = this.mBackStackIndices.size()) > 0) { printWriter.print(str); printWriter.println("Back Stack Indices:"); for (int i5 = 0; i5 < size2; i5++) { Object obj = (BackStackRecord) this.mBackStackIndices.get(i5); printWriter.print(str); printWriter.print(" #"); printWriter.print(i5); printWriter.print(": "); printWriter.println(obj); } } if (this.mAvailBackStackIndices != null && this.mAvailBackStackIndices.size() > 0) { printWriter.print(str); printWriter.print("mAvailBackStackIndices: "); printWriter.println(Arrays.toString(this.mAvailBackStackIndices.toArray())); } } ArrayList<OpGenerator> arrayList3 = this.mPendingActions; if (arrayList3 != null && (size = arrayList3.size()) > 0) { printWriter.print(str); printWriter.println("Pending Actions:"); for (int i6 = 0; i6 < size; i6++) { Object obj2 = (OpGenerator) this.mPendingActions.get(i6); printWriter.print(str); printWriter.print(" #"); printWriter.print(i6); printWriter.print(": "); printWriter.println(obj2); } } 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); } if (this.mNoTransactionsBecause != null) { printWriter.print(str); printWriter.print(" mNoTransactionsBecause="); printWriter.println(this.mNoTransactionsBecause); } } static AnimationOrAnimator makeOpenCloseAnimation(Context context, float f, float f2, float f3, float f4) { AnimationSet animationSet = new AnimationSet(false); ScaleAnimation scaleAnimation = new ScaleAnimation(f, f2, f, f2, 1, 0.5f, 1, 0.5f); scaleAnimation.setInterpolator(DECELERATE_QUINT); scaleAnimation.setDuration(220L); animationSet.addAnimation(scaleAnimation); AlphaAnimation alphaAnimation = new AlphaAnimation(f3, f4); alphaAnimation.setInterpolator(DECELERATE_CUBIC); alphaAnimation.setDuration(220L); animationSet.addAnimation(alphaAnimation); return new AnimationOrAnimator(animationSet); } static AnimationOrAnimator makeFadeAnimation(Context context, float f, float f2) { AlphaAnimation alphaAnimation = new AlphaAnimation(f, f2); alphaAnimation.setInterpolator(DECELERATE_CUBIC); alphaAnimation.setDuration(220L); return new AnimationOrAnimator(alphaAnimation); } AnimationOrAnimator loadAnimation(Fragment fragment, int i, boolean z, int i2) { int transitToStyleIndex; int nextAnim = fragment.getNextAnim(); Animation onCreateAnimation = fragment.onCreateAnimation(i, z, nextAnim); if (onCreateAnimation != null) { return new AnimationOrAnimator(onCreateAnimation); } Animator onCreateAnimator = fragment.onCreateAnimator(i, z, nextAnim); if (onCreateAnimator != null) { return new AnimationOrAnimator(onCreateAnimator); } if (nextAnim != 0) { boolean equals = "anim".equals(this.mHost.getContext().getResources().getResourceTypeName(nextAnim)); boolean z2 = false; if (equals) { try { Animation loadAnimation = AnimationUtils.loadAnimation(this.mHost.getContext(), nextAnim); if (loadAnimation != null) { return new AnimationOrAnimator(loadAnimation); } z2 = true; } catch (Resources.NotFoundException e) { throw e; } catch (RuntimeException unused) { } } if (!z2) { try { Animator loadAnimator = AnimatorInflater.loadAnimator(this.mHost.getContext(), nextAnim); if (loadAnimator != null) { return new AnimationOrAnimator(loadAnimator); } } catch (RuntimeException e2) { if (equals) { throw e2; } Animation loadAnimation2 = AnimationUtils.loadAnimation(this.mHost.getContext(), nextAnim); if (loadAnimation2 != null) { return new AnimationOrAnimator(loadAnimation2); } } } } if (i == 0 || (transitToStyleIndex = transitToStyleIndex(i, z)) < 0) { return null; } switch (transitToStyleIndex) { case 1: return makeOpenCloseAnimation(this.mHost.getContext(), 1.125f, 1.0f, 0.0f, 1.0f); case 2: return makeOpenCloseAnimation(this.mHost.getContext(), 1.0f, 0.975f, 1.0f, 0.0f); case 3: return makeOpenCloseAnimation(this.mHost.getContext(), 0.975f, 1.0f, 0.0f, 1.0f); case 4: return makeOpenCloseAnimation(this.mHost.getContext(), 1.0f, 1.075f, 1.0f, 0.0f); case 5: return makeFadeAnimation(this.mHost.getContext(), 0.0f, 1.0f); case 6: return makeFadeAnimation(this.mHost.getContext(), 1.0f, 0.0f); default: if (i2 == 0 && this.mHost.onHasWindowAnimations()) { i2 = this.mHost.onGetWindowAnimations(); } if (i2 == 0) { } return null; } } public void performPendingDeferredStart(Fragment fragment) { if (fragment.mDeferStart) { if (this.mExecutingActions) { this.mHavePendingDeferredStart = true; } else { fragment.mDeferStart = false; moveToState(fragment, this.mCurState, 0, 0, false); } } } private static void setHWLayerAnimListenerIfAlpha(View view, AnimationOrAnimator animationOrAnimator) { if (view == null || animationOrAnimator == null || !shouldRunOnHWLayer(view, animationOrAnimator)) { return; } if (animationOrAnimator.animator != null) { animationOrAnimator.animator.addListener(new AnimatorOnHWLayerIfNeededListener(view)); return; } Animation.AnimationListener animationListener = getAnimationListener(animationOrAnimator.animation); view.setLayerType(2, null); animationOrAnimator.animation.setAnimationListener(new AnimateOnHWLayerIfNeededListener(view, animationListener)); } private static Animation.AnimationListener getAnimationListener(Animation animation) { try { if (sAnimationListenerField == null) { sAnimationListenerField = Animation.class.getDeclaredField("mListener"); sAnimationListenerField.setAccessible(true); } return (Animation.AnimationListener) sAnimationListenerField.get(animation); } catch (IllegalAccessException e) { Log.e(TAG, "Cannot access Animation's mListener field", e); return null; } catch (NoSuchFieldException e2) { Log.e(TAG, "No field with the name mListener is found in Animation class", e2); return null; } } public boolean isStateAtLeast(int i) { return this.mCurState >= i; } public void moveToState(Fragment fragment, int i, int i2, int i3, boolean z) { int i4; FragmentManagerImpl fragmentManagerImpl; ViewGroup viewGroup; String str; int i5 = 1; if (!fragment.mAdded || fragment.mDetached) { i4 = i; if (i4 > 1) { i4 = 1; } } else { i4 = i; } if (fragment.mRemoving && i4 > fragment.mState) { i4 = (fragment.mState == 0 && fragment.isInBackStack()) ? 1 : fragment.mState; } int i6 = (!fragment.mDeferStart || fragment.mState >= 3 || i4 <= 2) ? i4 : 2; if (fragment.mState <= i6) { if (fragment.mFromLayout && !fragment.mInLayout) { return; } if (fragment.getAnimatingAway() != null || fragment.getAnimator() != null) { fragment.setAnimatingAway(null); fragment.setAnimator(null); moveToState(fragment, fragment.getStateAfterAnimating(), 0, 0, true); } int i7 = fragment.mState; if (i7 != 0) { if (i7 != 1) { if (i7 != 2) { } if (i6 > 2) { if (DEBUG) { Log.v(TAG, "moveto STARTED: " + fragment); } fragment.performStart(); dispatchOnFragmentStarted(fragment, false); } if (i6 > 3) { if (DEBUG) { Log.v(TAG, "moveto RESUMED: " + fragment); } fragment.performResume(); dispatchOnFragmentResumed(fragment, false); fragment.mSavedFragmentState = null; fragment.mSavedViewState = null; } } } else if (i6 > 0) { if (DEBUG) { Log.v(TAG, "moveto CREATED: " + fragment); } if (fragment.mSavedFragmentState != null) { fragment.mSavedFragmentState.setClassLoader(this.mHost.getContext().getClassLoader()); fragment.mSavedViewState = fragment.mSavedFragmentState.getSparseParcelableArray(VIEW_STATE_TAG); fragment.mTarget = getFragment(fragment.mSavedFragmentState, TARGET_STATE_TAG); if (fragment.mTarget != null) { fragment.mTargetRequestCode = fragment.mSavedFragmentState.getInt(TARGET_REQUEST_CODE_STATE_TAG, 0); } if (fragment.mSavedUserVisibleHint != null) { fragment.mUserVisibleHint = fragment.mSavedUserVisibleHint.booleanValue(); fragment.mSavedUserVisibleHint = null; } else { fragment.mUserVisibleHint = fragment.mSavedFragmentState.getBoolean(USER_VISIBLE_HINT_TAG, true); } if (!fragment.mUserVisibleHint) { fragment.mDeferStart = true; if (i6 > 2) { i6 = 2; } } } FragmentHostCallback fragmentHostCallback = this.mHost; fragment.mHost = fragmentHostCallback; Fragment fragment2 = this.mParent; fragment.mParentFragment = fragment2; if (fragment2 != null) { fragmentManagerImpl = fragment2.mChildFragmentManager; } else { fragmentManagerImpl = fragmentHostCallback.getFragmentManagerImpl(); } fragment.mFragmentManager = fragmentManagerImpl; if (fragment.mTarget != null) { if (this.mActive.get(fragment.mTarget.mIndex) != fragment.mTarget) { throw new IllegalStateException("Fragment " + fragment + " declared target fragment " + fragment.mTarget + " that does not belong to this FragmentManager!"); } if (fragment.mTarget.mState < 1) { moveToState(fragment.mTarget, 1, 0, 0, true); } } dispatchOnFragmentPreAttached(fragment, this.mHost.getContext(), false); fragment.mCalled = false; fragment.onAttach(this.mHost.getContext()); if (!fragment.mCalled) { throw new SuperNotCalledException("Fragment " + fragment + " did not call through to super.onAttach()"); } if (fragment.mParentFragment == null) { this.mHost.onAttachFragment(fragment); } else { fragment.mParentFragment.onAttachFragment(fragment); } dispatchOnFragmentAttached(fragment, this.mHost.getContext(), false); if (!fragment.mIsCreated) { dispatchOnFragmentPreCreated(fragment, fragment.mSavedFragmentState, false); fragment.performCreate(fragment.mSavedFragmentState); dispatchOnFragmentCreated(fragment, fragment.mSavedFragmentState, false); } else { fragment.restoreChildFragmentState(fragment.mSavedFragmentState); fragment.mState = 1; } fragment.mRetaining = false; } ensureInflatedFragmentView(fragment); if (i6 > 1) { if (DEBUG) { Log.v(TAG, "moveto ACTIVITY_CREATED: " + fragment); } if (!fragment.mFromLayout) { if (fragment.mContainerId != 0) { if (fragment.mContainerId == -1) { throwException(new IllegalArgumentException("Cannot create fragment " + fragment + " for a container view with no id")); } viewGroup = (ViewGroup) this.mContainer.onFindViewById(fragment.mContainerId); if (viewGroup == null && !fragment.mRestored) { try { str = fragment.getResources().getResourceName(fragment.mContainerId); } catch (Resources.NotFoundException unused) { str = EnvironmentCompat.MEDIA_UNKNOWN; } throwException(new IllegalArgumentException("No view found for id 0x" + Integer.toHexString(fragment.mContainerId) + " (" + str + ") for fragment " + fragment)); } } else { viewGroup = null; } fragment.mContainer = viewGroup; fragment.performCreateView(fragment.performGetLayoutInflater(fragment.mSavedFragmentState), viewGroup, fragment.mSavedFragmentState); if (fragment.mView != null) { fragment.mInnerView = fragment.mView; fragment.mView.setSaveFromParentEnabled(false); if (viewGroup != null) { viewGroup.addView(fragment.mView); } if (fragment.mHidden) { fragment.mView.setVisibility(8); } fragment.onViewCreated(fragment.mView, fragment.mSavedFragmentState); dispatchOnFragmentViewCreated(fragment, fragment.mView, fragment.mSavedFragmentState, false); fragment.mIsNewlyAdded = fragment.mView.getVisibility() == 0 && fragment.mContainer != null; } else { fragment.mInnerView = null; } } fragment.performActivityCreated(fragment.mSavedFragmentState); dispatchOnFragmentActivityCreated(fragment, fragment.mSavedFragmentState, false); if (fragment.mView != null) { fragment.restoreViewState(fragment.mSavedFragmentState); } fragment.mSavedFragmentState = null; } if (i6 > 2) { } if (i6 > 3) { } } else if (fragment.mState > i6) { int i8 = fragment.mState; if (i8 != 1) { if (i8 != 2) { if (i8 != 3) { if (i8 == 4) { if (i6 < 4) { if (DEBUG) { Log.v(TAG, "movefrom RESUMED: " + fragment); } fragment.performPause(); dispatchOnFragmentPaused(fragment, false); } } } if (i6 < 3) { if (DEBUG) { Log.v(TAG, "movefrom STARTED: " + fragment); } fragment.performStop(); dispatchOnFragmentStopped(fragment, false); } } if (i6 < 2) { if (DEBUG) { Log.v(TAG, "movefrom ACTIVITY_CREATED: " + fragment); } if (fragment.mView != null && this.mHost.onShouldSaveFragmentState(fragment) && fragment.mSavedViewState == null) { saveFragmentViewState(fragment); } fragment.performDestroyView(); dispatchOnFragmentViewDestroyed(fragment, false); if (fragment.mView != null && fragment.mContainer != null) { fragment.mContainer.endViewTransition(fragment.mView); fragment.mView.clearAnimation(); AnimationOrAnimator loadAnimation = (this.mCurState <= 0 || this.mDestroyed || fragment.mView.getVisibility() != 0 || fragment.mPostponedAlpha < 0.0f) ? null : loadAnimation(fragment, i2, false, i3); fragment.mPostponedAlpha = 0.0f; if (loadAnimation != null) { animateRemoveFragment(fragment, loadAnimation, i6); } fragment.mContainer.removeView(fragment.mView); } fragment.mContainer = null; fragment.mView = null; fragment.mViewLifecycleOwner = null; fragment.mViewLifecycleOwnerLiveData.setValue(null); fragment.mInnerView = null; fragment.mInLayout = false; } } if (i6 < 1) { if (this.mDestroyed) { if (fragment.getAnimatingAway() != null) { View animatingAway = fragment.getAnimatingAway(); fragment.setAnimatingAway(null); animatingAway.clearAnimation(); } else if (fragment.getAnimator() != null) { Animator animator = fragment.getAnimator(); fragment.setAnimator(null); animator.cancel(); } } if (fragment.getAnimatingAway() != null || fragment.getAnimator() != null) { fragment.setStateAfterAnimating(i6); if (fragment.mState == i5) { Log.w(TAG, "moveToState: Fragment state for " + fragment + " not updated inline; expected state " + i5 + " found " + fragment.mState); fragment.mState = i5; return; } return; } if (DEBUG) { Log.v(TAG, "movefrom CREATED: " + fragment); } if (!fragment.mRetaining) { fragment.performDestroy(); dispatchOnFragmentDestroyed(fragment, false); } else { fragment.mState = 0; } fragment.performDetach(); dispatchOnFragmentDetached(fragment, false); if (!z) { if (!fragment.mRetaining) { makeInactive(fragment); } else { fragment.mHost = null; fragment.mParentFragment = null; fragment.mFragmentManager = null; } } } } i5 = i6; if (fragment.mState == i5) { } } private void animateRemoveFragment(final Fragment fragment, AnimationOrAnimator animationOrAnimator, int i) { final View view = fragment.mView; final ViewGroup viewGroup = fragment.mContainer; viewGroup.startViewTransition(view); fragment.setStateAfterAnimating(i); if (animationOrAnimator.animation != null) { EndViewTransitionAnimator endViewTransitionAnimator = new EndViewTransitionAnimator(animationOrAnimator.animation, viewGroup, view); fragment.setAnimatingAway(fragment.mView); endViewTransitionAnimator.setAnimationListener(new AnimationListenerWrapper(getAnimationListener(endViewTransitionAnimator)) { @Override public void onAnimationEnd(Animation animation) { super.onAnimationEnd(animation); viewGroup.post(new Runnable() { @Override public void run() { if (fragment.getAnimatingAway() != null) { fragment.setAnimatingAway(null); FragmentManagerImpl.this.moveToState(fragment, fragment.getStateAfterAnimating(), 0, 0, false); } } }); } }); setHWLayerAnimListenerIfAlpha(view, animationOrAnimator); fragment.mView.startAnimation(endViewTransitionAnimator); return; } Animator animator = animationOrAnimator.animator; fragment.setAnimator(animationOrAnimator.animator); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator2) { viewGroup.endViewTransition(view); Animator animator3 = fragment.getAnimator(); fragment.setAnimator(null); if (animator3 == null || viewGroup.indexOfChild(view) >= 0) { return; } FragmentManagerImpl fragmentManagerImpl = FragmentManagerImpl.this; Fragment fragment2 = fragment; fragmentManagerImpl.moveToState(fragment2, fragment2.getStateAfterAnimating(), 0, 0, false); } }); animator.setTarget(fragment.mView); setHWLayerAnimListenerIfAlpha(fragment.mView, animationOrAnimator); animator.start(); } void moveToState(Fragment fragment) { moveToState(fragment, this.mCurState, 0, 0, false); } void ensureInflatedFragmentView(Fragment fragment) { if (!fragment.mFromLayout || fragment.mPerformedCreateView) { return; } fragment.performCreateView(fragment.performGetLayoutInflater(fragment.mSavedFragmentState), null, fragment.mSavedFragmentState); if (fragment.mView != null) { fragment.mInnerView = fragment.mView; fragment.mView.setSaveFromParentEnabled(false); if (fragment.mHidden) { fragment.mView.setVisibility(8); } fragment.onViewCreated(fragment.mView, fragment.mSavedFragmentState); dispatchOnFragmentViewCreated(fragment, fragment.mView, fragment.mSavedFragmentState, false); return; } fragment.mInnerView = null; } void completeShowHideFragment(final Fragment fragment) { if (fragment.mView != null) { AnimationOrAnimator loadAnimation = loadAnimation(fragment, fragment.getNextTransition(), !fragment.mHidden, fragment.getNextTransitionStyle()); if (loadAnimation != null && loadAnimation.animator != null) { loadAnimation.animator.setTarget(fragment.mView); if (fragment.mHidden) { if (fragment.isHideReplaced()) { fragment.setHideReplaced(false); } else { final ViewGroup viewGroup = fragment.mContainer; final View view = fragment.mView; viewGroup.startViewTransition(view); loadAnimation.animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { viewGroup.endViewTransition(view); animator.removeListener(this); if (fragment.mView != null) { fragment.mView.setVisibility(8); } } }); } } else { fragment.mView.setVisibility(0); } setHWLayerAnimListenerIfAlpha(fragment.mView, loadAnimation); loadAnimation.animator.start(); } else { if (loadAnimation != null) { setHWLayerAnimListenerIfAlpha(fragment.mView, loadAnimation); fragment.mView.startAnimation(loadAnimation.animation); loadAnimation.animation.start(); } fragment.mView.setVisibility((!fragment.mHidden || fragment.isHideReplaced()) ? 0 : 8); if (fragment.isHideReplaced()) { fragment.setHideReplaced(false); } } } if (fragment.mAdded && fragment.mHasMenu && fragment.mMenuVisible) { this.mNeedMenuInvalidate = true; } fragment.mHiddenChanged = false; fragment.onHiddenChanged(fragment.mHidden); } public void moveFragmentToExpectedState(Fragment fragment) { if (fragment == null) { return; } int i = this.mCurState; if (fragment.mRemoving) { if (fragment.isInBackStack()) { i = Math.min(i, 1); } else { i = Math.min(i, 0); } } moveToState(fragment, i, fragment.getNextTransition(), fragment.getNextTransitionStyle(), false); if (fragment.mView != null) { Fragment findFragmentUnder = findFragmentUnder(fragment); if (findFragmentUnder != null) { View view = findFragmentUnder.mView; ViewGroup viewGroup = fragment.mContainer; int indexOfChild = viewGroup.indexOfChild(view); int indexOfChild2 = viewGroup.indexOfChild(fragment.mView); if (indexOfChild2 < indexOfChild) { viewGroup.removeViewAt(indexOfChild2); viewGroup.addView(fragment.mView, indexOfChild); } } if (fragment.mIsNewlyAdded && fragment.mContainer != null) { if (fragment.mPostponedAlpha > 0.0f) { fragment.mView.setAlpha(fragment.mPostponedAlpha); } fragment.mPostponedAlpha = 0.0f; fragment.mIsNewlyAdded = false; AnimationOrAnimator loadAnimation = loadAnimation(fragment, fragment.getNextTransition(), true, fragment.getNextTransitionStyle()); if (loadAnimation != null) { setHWLayerAnimListenerIfAlpha(fragment.mView, loadAnimation); if (loadAnimation.animation != null) { fragment.mView.startAnimation(loadAnimation.animation); } else { loadAnimation.animator.setTarget(fragment.mView); loadAnimation.animator.start(); } } } } if (fragment.mHiddenChanged) { completeShowHideFragment(fragment); } } public void moveToState(int i, boolean z) { FragmentHostCallback fragmentHostCallback; if (this.mHost == null && i != 0) { throw new IllegalStateException("No activity"); } if (z || i != this.mCurState) { this.mCurState = i; if (this.mActive != null) { int size = this.mAdded.size(); for (int i2 = 0; i2 < size; i2++) { moveFragmentToExpectedState(this.mAdded.get(i2)); } int size2 = this.mActive.size(); for (int i3 = 0; i3 < size2; i3++) { Fragment valueAt = this.mActive.valueAt(i3); if (valueAt != null && ((valueAt.mRemoving || valueAt.mDetached) && !valueAt.mIsNewlyAdded)) { moveFragmentToExpectedState(valueAt); } } startPendingDeferredFragments(); if (this.mNeedMenuInvalidate && (fragmentHostCallback = this.mHost) != null && this.mCurState == 4) { fragmentHostCallback.onSupportInvalidateOptionsMenu(); this.mNeedMenuInvalidate = false; } } } } void startPendingDeferredFragments() { if (this.mActive == null) { return; } for (int i = 0; i < this.mActive.size(); i++) { Fragment valueAt = this.mActive.valueAt(i); if (valueAt != null) { performPendingDeferredStart(valueAt); } } } public void makeActive(Fragment fragment) { if (fragment.mIndex >= 0) { return; } int i = this.mNextFragmentIndex; this.mNextFragmentIndex = i + 1; fragment.setIndex(i, this.mParent); if (this.mActive == null) { this.mActive = new SparseArray<>(); } this.mActive.put(fragment.mIndex, fragment); if (DEBUG) { Log.v(TAG, "Allocated fragment index " + fragment); } } void makeInactive(Fragment fragment) { if (fragment.mIndex < 0) { return; } if (DEBUG) { Log.v(TAG, "Freeing fragment index " + fragment); } this.mActive.put(fragment.mIndex, null); fragment.initState(); } public void addFragment(Fragment fragment, boolean z) { if (DEBUG) { Log.v(TAG, "add: " + fragment); } makeActive(fragment); if (fragment.mDetached) { return; } if (this.mAdded.contains(fragment)) { throw new IllegalStateException("Fragment already added: " + fragment); } synchronized (this.mAdded) { this.mAdded.add(fragment); } fragment.mAdded = true; fragment.mRemoving = false; if (fragment.mView == null) { fragment.mHiddenChanged = false; } if (fragment.mHasMenu && fragment.mMenuVisible) { this.mNeedMenuInvalidate = true; } if (z) { moveToState(fragment); } } public void removeFragment(Fragment fragment) { if (DEBUG) { Log.v(TAG, "remove: " + fragment + " nesting=" + fragment.mBackStackNesting); } boolean z = !fragment.isInBackStack(); if (!fragment.mDetached || z) { synchronized (this.mAdded) { this.mAdded.remove(fragment); } if (fragment.mHasMenu && fragment.mMenuVisible) { this.mNeedMenuInvalidate = true; } fragment.mAdded = false; fragment.mRemoving = true; } } public void hideFragment(Fragment fragment) { if (DEBUG) { Log.v(TAG, "hide: " + fragment); } if (fragment.mHidden) { return; } fragment.mHidden = true; fragment.mHiddenChanged = true ^ fragment.mHiddenChanged; } public void showFragment(Fragment fragment) { if (DEBUG) { Log.v(TAG, "show: " + fragment); } if (fragment.mHidden) { fragment.mHidden = false; fragment.mHiddenChanged = !fragment.mHiddenChanged; } } public void detachFragment(Fragment fragment) { if (DEBUG) { Log.v(TAG, "detach: " + fragment); } if (fragment.mDetached) { return; } fragment.mDetached = true; if (fragment.mAdded) { if (DEBUG) { Log.v(TAG, "remove from detach: " + fragment); } synchronized (this.mAdded) { this.mAdded.remove(fragment); } if (fragment.mHasMenu && fragment.mMenuVisible) { this.mNeedMenuInvalidate = true; } fragment.mAdded = false; } } public void attachFragment(Fragment fragment) { if (DEBUG) { Log.v(TAG, "attach: " + fragment); } if (fragment.mDetached) { fragment.mDetached = false; if (fragment.mAdded) { return; } if (this.mAdded.contains(fragment)) { throw new IllegalStateException("Fragment already added: " + fragment); } if (DEBUG) { Log.v(TAG, "add from attach: " + fragment); } synchronized (this.mAdded) { this.mAdded.add(fragment); } fragment.mAdded = true; if (fragment.mHasMenu && fragment.mMenuVisible) { this.mNeedMenuInvalidate = true; } } } @Override public Fragment findFragmentById(int i) { for (int size = this.mAdded.size() - 1; size >= 0; size--) { Fragment fragment = this.mAdded.get(size); if (fragment != null && fragment.mFragmentId == i) { return fragment; } } SparseArray<Fragment> sparseArray = this.mActive; if (sparseArray == null) { return null; } for (int size2 = sparseArray.size() - 1; size2 >= 0; size2--) { Fragment valueAt = this.mActive.valueAt(size2); if (valueAt != null && valueAt.mFragmentId == i) { return valueAt; } } return null; } @Override public Fragment findFragmentByTag(String str) { if (str != null) { for (int size = this.mAdded.size() - 1; size >= 0; size--) { Fragment fragment = this.mAdded.get(size); if (fragment != null && str.equals(fragment.mTag)) { return fragment; } } } SparseArray<Fragment> sparseArray = this.mActive; if (sparseArray == null || str == null) { return null; } for (int size2 = sparseArray.size() - 1; size2 >= 0; size2--) { Fragment valueAt = this.mActive.valueAt(size2); if (valueAt != null && str.equals(valueAt.mTag)) { return valueAt; } } return null; } public Fragment findFragmentByWho(String str) { Fragment findFragmentByWho; SparseArray<Fragment> sparseArray = this.mActive; if (sparseArray == null || str == null) { return null; } for (int size = sparseArray.size() - 1; size >= 0; size--) { Fragment valueAt = this.mActive.valueAt(size); if (valueAt != null && (findFragmentByWho = valueAt.findFragmentByWho(str)) != null) { return findFragmentByWho; } } return null; } private void checkStateLoss() { if (isStateSaved()) { throw new IllegalStateException("Can not perform this action after onSaveInstanceState"); } if (this.mNoTransactionsBecause == null) { return; } throw new IllegalStateException("Can not perform this action inside of " + this.mNoTransactionsBecause); } @Override public boolean isStateSaved() { return this.mStateSaved || this.mStopped; } public void enqueueAction(OpGenerator opGenerator, boolean z) { if (!z) { checkStateLoss(); } synchronized (this) { if (!this.mDestroyed && this.mHost != null) { if (this.mPendingActions == null) { this.mPendingActions = new ArrayList<>(); } this.mPendingActions.add(opGenerator); scheduleCommit(); return; } throw new IllegalStateException("Activity has been destroyed"); } } void scheduleCommit() { synchronized (this) { boolean z = false; boolean z2 = (this.mPostponedTransactions == null || this.mPostponedTransactions.isEmpty()) ? false : true; if (this.mPendingActions != null && this.mPendingActions.size() == 1) { z = true; } if (z2 || z) { this.mHost.getHandler().removeCallbacks(this.mExecCommit); this.mHost.getHandler().post(this.mExecCommit); } } } public int allocBackStackIndex(BackStackRecord backStackRecord) { synchronized (this) { if (this.mAvailBackStackIndices != null && this.mAvailBackStackIndices.size() > 0) { int intValue = this.mAvailBackStackIndices.remove(this.mAvailBackStackIndices.size() - 1).intValue(); if (DEBUG) { Log.v(TAG, "Adding back stack index " + intValue + " with " + backStackRecord); } this.mBackStackIndices.set(intValue, backStackRecord); return intValue; } if (this.mBackStackIndices == null) { this.mBackStackIndices = new ArrayList<>(); } int size = this.mBackStackIndices.size(); if (DEBUG) { Log.v(TAG, "Setting back stack index " + size + " to " + backStackRecord); } this.mBackStackIndices.add(backStackRecord); return size; } } public void setBackStackIndex(int i, BackStackRecord backStackRecord) { synchronized (this) { if (this.mBackStackIndices == null) { this.mBackStackIndices = new ArrayList<>(); } int size = this.mBackStackIndices.size(); if (i < size) { if (DEBUG) { Log.v(TAG, "Setting back stack index " + i + " to " + backStackRecord); } this.mBackStackIndices.set(i, backStackRecord); } else { while (size < i) { this.mBackStackIndices.add(null); if (this.mAvailBackStackIndices == null) { this.mAvailBackStackIndices = new ArrayList<>(); } if (DEBUG) { Log.v(TAG, "Adding available back stack index " + size); } this.mAvailBackStackIndices.add(Integer.valueOf(size)); size++; } if (DEBUG) { Log.v(TAG, "Adding back stack index " + i + " with " + backStackRecord); } this.mBackStackIndices.add(backStackRecord); } } } public void freeBackStackIndex(int i) { synchronized (this) { this.mBackStackIndices.set(i, null); if (this.mAvailBackStackIndices == null) { this.mAvailBackStackIndices = new ArrayList<>(); } if (DEBUG) { Log.v(TAG, "Freeing back stack index " + i); } this.mAvailBackStackIndices.add(Integer.valueOf(i)); } } private void ensureExecReady(boolean z) { if (this.mExecutingActions) { throw new IllegalStateException("FragmentManager is already executing transactions"); } if (this.mHost == null) { throw new IllegalStateException("Fragment host has been destroyed"); } if (Looper.myLooper() != this.mHost.getHandler().getLooper()) { throw new IllegalStateException("Must be called from main thread of fragment host"); } if (!z) { checkStateLoss(); } if (this.mTmpRecords == null) { this.mTmpRecords = new ArrayList<>(); this.mTmpIsPop = new ArrayList<>(); } this.mExecutingActions = true; try { executePostponedTransaction(null, null); } finally { this.mExecutingActions = false; } } public void execSingleAction(OpGenerator opGenerator, boolean z) { if (z && (this.mHost == null || this.mDestroyed)) { return; } ensureExecReady(z); if (opGenerator.generateOps(this.mTmpRecords, this.mTmpIsPop)) { this.mExecutingActions = true; try { removeRedundantOperationsAndExecute(this.mTmpRecords, this.mTmpIsPop); } finally { cleanupExec(); } } doPendingDeferredStart(); burpActive(); } private void cleanupExec() { this.mExecutingActions = false; this.mTmpIsPop.clear(); this.mTmpRecords.clear(); } public boolean execPendingActions() { ensureExecReady(true); boolean z = false; while (generateOpsForPendingActions(this.mTmpRecords, this.mTmpIsPop)) { this.mExecutingActions = true; try { removeRedundantOperationsAndExecute(this.mTmpRecords, this.mTmpIsPop); cleanupExec(); z = true; } catch (Throwable th) { cleanupExec(); throw th; } } doPendingDeferredStart(); burpActive(); return z; } private void executePostponedTransaction(ArrayList<BackStackRecord> arrayList, 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.get(indexOf2).booleanValue()) { 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.get(indexOf).booleanValue()) { startEnterTransitionListener.cancelTransaction(); } else { startEnterTransitionListener.completeTransaction(); } } i++; } } private void removeRedundantOperationsAndExecute(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2) { if (arrayList == null || arrayList.isEmpty()) { return; } if (arrayList2 == null || arrayList.size() != arrayList2.size()) { throw new IllegalStateException("Internal error with the back stack records"); } 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); } } private void executeOpsTogether(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2, int i, int i2) { int i3; int i4 = i; boolean z = arrayList.get(i4).mReorderingAllowed; ArrayList<Fragment> arrayList3 = this.mTmpAddedFragments; if (arrayList3 == null) { this.mTmpAddedFragments = new ArrayList<>(); } else { arrayList3.clear(); } this.mTmpAddedFragments.addAll(this.mAdded); Fragment primaryNavigationFragment = getPrimaryNavigationFragment(); boolean z2 = false; for (int i5 = i4; i5 < i2; i5++) { BackStackRecord backStackRecord = arrayList.get(i5); if (!arrayList2.get(i5).booleanValue()) { primaryNavigationFragment = backStackRecord.expandOps(this.mTmpAddedFragments, primaryNavigationFragment); } else { primaryNavigationFragment = backStackRecord.trackAddedFragmentsInPop(this.mTmpAddedFragments, primaryNavigationFragment); } z2 = z2 || backStackRecord.mAddToBackStack; } this.mTmpAddedFragments.clear(); if (!z) { FragmentTransition.startTransitions(this, arrayList, arrayList2, i, i2, false); } executeOps(arrayList, arrayList2, i, i2); if (z) { ArraySet<Fragment> arraySet = new ArraySet<>(); addAddedFragments(arraySet); int postponePostponableTransactions = postponePostponableTransactions(arrayList, arrayList2, i, i2, arraySet); makeRemovedFragmentsInvisible(arraySet); i3 = postponePostponableTransactions; } else { i3 = i2; } if (i3 != i4 && z) { FragmentTransition.startTransitions(this, arrayList, arrayList2, i, i3, true); moveToState(this.mCurState, true); } while (i4 < i2) { BackStackRecord backStackRecord2 = arrayList.get(i4); if (arrayList2.get(i4).booleanValue() && backStackRecord2.mIndex >= 0) { freeBackStackIndex(backStackRecord2.mIndex); backStackRecord2.mIndex = -1; } backStackRecord2.runOnCommitRunnables(); i4++; } if (z2) { reportBackStackChanged(); } } private void makeRemovedFragmentsInvisible(ArraySet<Fragment> arraySet) { int size = arraySet.size(); for (int i = 0; i < size; i++) { Fragment valueAt = arraySet.valueAt(i); if (!valueAt.mAdded) { View view = valueAt.getView(); valueAt.mPostponedAlpha = view.getAlpha(); view.setAlpha(0.0f); } } } private int postponePostponableTransactions(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2, int i, int i2, 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; } void completeExecute(BackStackRecord backStackRecord, boolean z, boolean z2, boolean z3) { if (z) { backStackRecord.executePopOps(z3); } else { backStackRecord.executeOps(); } ArrayList arrayList = new ArrayList(1); ArrayList arrayList2 = new ArrayList(1); arrayList.add(backStackRecord); arrayList2.add(Boolean.valueOf(z)); if (z2) { FragmentTransition.startTransitions(this, arrayList, arrayList2, 0, 1, true); } if (z3) { moveToState(this.mCurState, true); } SparseArray<Fragment> sparseArray = this.mActive; if (sparseArray != null) { int size = sparseArray.size(); for (int i = 0; i < size; i++) { Fragment valueAt = this.mActive.valueAt(i); if (valueAt != null && valueAt.mView != null && valueAt.mIsNewlyAdded && backStackRecord.interactsWith(valueAt.mContainerId)) { if (valueAt.mPostponedAlpha > 0.0f) { valueAt.mView.setAlpha(valueAt.mPostponedAlpha); } if (z3) { valueAt.mPostponedAlpha = 0.0f; } else { valueAt.mPostponedAlpha = -1.0f; valueAt.mIsNewlyAdded = false; } } } } } private Fragment findFragmentUnder(Fragment fragment) { ViewGroup viewGroup = fragment.mContainer; View view = fragment.mView; if (viewGroup != null && view != null) { for (int indexOf = this.mAdded.indexOf(fragment) - 1; indexOf >= 0; indexOf--) { Fragment fragment2 = this.mAdded.get(indexOf); if (fragment2.mContainer == viewGroup && fragment2.mView != null) { return fragment2; } } } return null; } private static void executeOps(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2, int i, int i2) { while (i < i2) { BackStackRecord backStackRecord = arrayList.get(i); if (arrayList2.get(i).booleanValue()) { backStackRecord.bumpBackStackNesting(-1); backStackRecord.executePopOps(i == i2 + (-1)); } else { backStackRecord.bumpBackStackNesting(1); backStackRecord.executeOps(); } i++; } } private void addAddedFragments(ArraySet<Fragment> arraySet) { int i = this.mCurState; if (i < 1) { return; } int min = Math.min(i, 3); int size = this.mAdded.size(); for (int i2 = 0; i2 < size; i2++) { Fragment fragment = this.mAdded.get(i2); if (fragment.mState < min) { moveToState(fragment, min, fragment.getNextAnim(), fragment.getNextTransition(), false); if (fragment.mView != null && !fragment.mHidden && fragment.mIsNewlyAdded) { arraySet.add(fragment); } } } } private void forcePostponedTransactions() { if (this.mPostponedTransactions != null) { while (!this.mPostponedTransactions.isEmpty()) { this.mPostponedTransactions.remove(0).completeTransaction(); } } } private void endAnimatingAwayFragments() { SparseArray<Fragment> sparseArray = this.mActive; int size = sparseArray == null ? 0 : sparseArray.size(); for (int i = 0; i < size; i++) { Fragment valueAt = this.mActive.valueAt(i); if (valueAt != null) { if (valueAt.getAnimatingAway() != null) { int stateAfterAnimating = valueAt.getStateAfterAnimating(); View animatingAway = valueAt.getAnimatingAway(); Animation animation = animatingAway.getAnimation(); if (animation != null) { animation.cancel(); animatingAway.clearAnimation(); } valueAt.setAnimatingAway(null); moveToState(valueAt, stateAfterAnimating, 0, 0, false); } else if (valueAt.getAnimator() != null) { valueAt.getAnimator().end(); } } } } private boolean generateOpsForPendingActions(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2) { synchronized (this) { if (this.mPendingActions != null && this.mPendingActions.size() != 0) { int size = this.mPendingActions.size(); boolean z = false; for (int i = 0; i < size; i++) { z |= this.mPendingActions.get(i).generateOps(arrayList, arrayList2); } this.mPendingActions.clear(); this.mHost.getHandler().removeCallbacks(this.mExecCommit); return z; } return false; } } void doPendingDeferredStart() { if (this.mHavePendingDeferredStart) { this.mHavePendingDeferredStart = false; startPendingDeferredFragments(); } } void reportBackStackChanged() { if (this.mBackStackChangeListeners != null) { for (int i = 0; i < this.mBackStackChangeListeners.size(); i++) { this.mBackStackChangeListeners.get(i).onBackStackChanged(); } } } public void addBackStackState(BackStackRecord backStackRecord) { if (this.mBackStack == null) { this.mBackStack = new ArrayList<>(); } this.mBackStack.add(backStackRecord); } boolean popBackStackState(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2, String str, int i, int i2) { int size; ArrayList<BackStackRecord> arrayList3 = this.mBackStack; if (arrayList3 == null) { return false; } if (str == null && i < 0 && (i2 & 1) == 0) { int size2 = arrayList3.size() - 1; if (size2 < 0) { return false; } arrayList.add(this.mBackStack.remove(size2)); arrayList2.add(true); } else { if (str != null || i >= 0) { size = this.mBackStack.size() - 1; while (size >= 0) { BackStackRecord backStackRecord = this.mBackStack.get(size); if ((str != null && str.equals(backStackRecord.getName())) || (i >= 0 && i == backStackRecord.mIndex)) { break; } size--; } if (size < 0) { return false; } if ((i2 & 1) != 0) { while (true) { size--; if (size < 0) { break; } BackStackRecord backStackRecord2 = this.mBackStack.get(size); if (str == null || !str.equals(backStackRecord2.getName())) { if (i < 0 || i != backStackRecord2.mIndex) { break; } } } } } else { size = -1; } if (size == this.mBackStack.size() - 1) { return false; } for (int size3 = this.mBackStack.size() - 1; size3 > size; size3--) { arrayList.add(this.mBackStack.remove(size3)); arrayList2.add(true); } } return true; } public FragmentManagerNonConfig retainNonConfig() { setRetaining(this.mSavedNonConfig); return this.mSavedNonConfig; } private static void setRetaining(FragmentManagerNonConfig fragmentManagerNonConfig) { if (fragmentManagerNonConfig == null) { return; } List<Fragment> fragments = fragmentManagerNonConfig.getFragments(); if (fragments != null) { Iterator<Fragment> it = fragments.iterator(); while (it.hasNext()) { it.next().mRetaining = true; } } List<FragmentManagerNonConfig> childNonConfigs = fragmentManagerNonConfig.getChildNonConfigs(); if (childNonConfigs != null) { Iterator<FragmentManagerNonConfig> it2 = childNonConfigs.iterator(); while (it2.hasNext()) { setRetaining(it2.next()); } } } void saveNonConfig() { ArrayList arrayList; ArrayList arrayList2; ArrayList arrayList3; FragmentManagerNonConfig fragmentManagerNonConfig; if (this.mActive != null) { arrayList = null; arrayList2 = null; arrayList3 = null; for (int i = 0; i < this.mActive.size(); i++) { Fragment valueAt = this.mActive.valueAt(i); if (valueAt != null) { if (valueAt.mRetainInstance) { if (arrayList == null) { arrayList = new ArrayList(); } arrayList.add(valueAt); valueAt.mTargetIndex = valueAt.mTarget != null ? valueAt.mTarget.mIndex : -1; if (DEBUG) { Log.v(TAG, "retainNonConfig: keeping retained " + valueAt); } } if (valueAt.mChildFragmentManager != null) { valueAt.mChildFragmentManager.saveNonConfig(); fragmentManagerNonConfig = valueAt.mChildFragmentManager.mSavedNonConfig; } else { fragmentManagerNonConfig = valueAt.mChildNonConfig; } if (arrayList2 == null && fragmentManagerNonConfig != null) { arrayList2 = new ArrayList(this.mActive.size()); for (int i2 = 0; i2 < i; i2++) { arrayList2.add(null); } } if (arrayList2 != null) { arrayList2.add(fragmentManagerNonConfig); } if (arrayList3 == null && valueAt.mViewModelStore != null) { arrayList3 = new ArrayList(this.mActive.size()); for (int i3 = 0; i3 < i; i3++) { arrayList3.add(null); } } if (arrayList3 != null) { arrayList3.add(valueAt.mViewModelStore); } } } } else { arrayList = null; arrayList2 = null; arrayList3 = null; } if (arrayList == null && arrayList2 == null && arrayList3 == null) { this.mSavedNonConfig = null; } else { this.mSavedNonConfig = new FragmentManagerNonConfig(arrayList, arrayList2, arrayList3); } } void saveFragmentViewState(Fragment fragment) { if (fragment.mInnerView == null) { return; } SparseArray<Parcelable> sparseArray = this.mStateArray; if (sparseArray == null) { this.mStateArray = new SparseArray<>(); } else { sparseArray.clear(); } fragment.mInnerView.saveHierarchyState(this.mStateArray); if (this.mStateArray.size() > 0) { fragment.mSavedViewState = this.mStateArray; this.mStateArray = null; } } Bundle saveFragmentBasicState(Fragment fragment) { Bundle bundle; if (this.mStateBundle == null) { this.mStateBundle = new Bundle(); } fragment.performSaveInstanceState(this.mStateBundle); dispatchOnFragmentSaveInstanceState(fragment, this.mStateBundle, false); if (this.mStateBundle.isEmpty()) { bundle = null; } else { bundle = this.mStateBundle; this.mStateBundle = null; } if (fragment.mView != null) { saveFragmentViewState(fragment); } if (fragment.mSavedViewState != null) { if (bundle == null) { bundle = new Bundle(); } bundle.putSparseParcelableArray(VIEW_STATE_TAG, fragment.mSavedViewState); } if (!fragment.mUserVisibleHint) { if (bundle == null) { bundle = new Bundle(); } bundle.putBoolean(USER_VISIBLE_HINT_TAG, fragment.mUserVisibleHint); } return bundle; } public Parcelable saveAllState() { int[] iArr; int size; forcePostponedTransactions(); endAnimatingAwayFragments(); execPendingActions(); this.mStateSaved = true; BackStackState[] backStackStateArr = null; this.mSavedNonConfig = null; SparseArray<Fragment> sparseArray = this.mActive; if (sparseArray == null || sparseArray.size() <= 0) { return null; } int size2 = this.mActive.size(); FragmentState[] fragmentStateArr = new FragmentState[size2]; boolean z = false; for (int i = 0; i < size2; i++) { Fragment valueAt = this.mActive.valueAt(i); if (valueAt != null) { if (valueAt.mIndex < 0) { throwException(new IllegalStateException("Failure saving state: active " + valueAt + " has cleared index: " + valueAt.mIndex)); } FragmentState fragmentState = new FragmentState(valueAt); fragmentStateArr[i] = fragmentState; if (valueAt.mState > 0 && fragmentState.mSavedFragmentState == null) { fragmentState.mSavedFragmentState = saveFragmentBasicState(valueAt); if (valueAt.mTarget != null) { if (valueAt.mTarget.mIndex < 0) { throwException(new IllegalStateException("Failure saving state: " + valueAt + " has target not in fragment manager: " + valueAt.mTarget)); } if (fragmentState.mSavedFragmentState == null) { fragmentState.mSavedFragmentState = new Bundle(); } putFragment(fragmentState.mSavedFragmentState, TARGET_STATE_TAG, valueAt.mTarget); if (valueAt.mTargetRequestCode != 0) { fragmentState.mSavedFragmentState.putInt(TARGET_REQUEST_CODE_STATE_TAG, valueAt.mTargetRequestCode); } } } else { fragmentState.mSavedFragmentState = valueAt.mSavedFragmentState; } if (DEBUG) { Log.v(TAG, "Saved state of " + valueAt + ": " + fragmentState.mSavedFragmentState); } z = true; } } if (!z) { if (DEBUG) { Log.v(TAG, "saveAllState: no fragments!"); } return null; } int size3 = this.mAdded.size(); if (size3 > 0) { iArr = new int[size3]; for (int i2 = 0; i2 < size3; i2++) { iArr[i2] = this.mAdded.get(i2).mIndex; if (iArr[i2] < 0) { throwException(new IllegalStateException("Failure saving state: active " + this.mAdded.get(i2) + " has cleared index: " + iArr[i2])); } if (DEBUG) { Log.v(TAG, "saveAllState: adding fragment #" + i2 + ": " + this.mAdded.get(i2)); } } } else { iArr = null; } ArrayList<BackStackRecord> arrayList = this.mBackStack; if (arrayList != null && (size = arrayList.size()) > 0) { backStackStateArr = new BackStackState[size]; for (int i3 = 0; i3 < size; i3++) { backStackStateArr[i3] = new BackStackState(this.mBackStack.get(i3)); if (DEBUG) { Log.v(TAG, "saveAllState: adding back stack #" + i3 + ": " + this.mBackStack.get(i3)); } } } FragmentManagerState fragmentManagerState = new FragmentManagerState(); fragmentManagerState.mActive = fragmentStateArr; fragmentManagerState.mAdded = iArr; fragmentManagerState.mBackStack = backStackStateArr; Fragment fragment = this.mPrimaryNav; if (fragment != null) { fragmentManagerState.mPrimaryNavActiveIndex = fragment.mIndex; } fragmentManagerState.mNextFragmentIndex = this.mNextFragmentIndex; saveNonConfig(); return fragmentManagerState; } public void restoreAllState(Parcelable parcelable, FragmentManagerNonConfig fragmentManagerNonConfig) { List<FragmentManagerNonConfig> list; List<ViewModelStore> list2; if (parcelable == null) { return; } FragmentManagerState fragmentManagerState = (FragmentManagerState) parcelable; if (fragmentManagerState.mActive == null) { return; } if (fragmentManagerNonConfig != null) { List<Fragment> fragments = fragmentManagerNonConfig.getFragments(); list = fragmentManagerNonConfig.getChildNonConfigs(); list2 = fragmentManagerNonConfig.getViewModelStores(); int size = fragments != null ? fragments.size() : 0; for (int i = 0; i < size; i++) { Fragment fragment = fragments.get(i); if (DEBUG) { Log.v(TAG, "restoreAllState: re-attaching retained " + fragment); } int i2 = 0; while (i2 < fragmentManagerState.mActive.length && fragmentManagerState.mActive[i2].mIndex != fragment.mIndex) { i2++; } if (i2 == fragmentManagerState.mActive.length) { throwException(new IllegalStateException("Could not find active fragment with index " + fragment.mIndex)); } FragmentState fragmentState = fragmentManagerState.mActive[i2]; fragmentState.mInstance = fragment; fragment.mSavedViewState = null; fragment.mBackStackNesting = 0; fragment.mInLayout = false; fragment.mAdded = false; fragment.mTarget = null; if (fragmentState.mSavedFragmentState != null) { fragmentState.mSavedFragmentState.setClassLoader(this.mHost.getContext().getClassLoader()); fragment.mSavedViewState = fragmentState.mSavedFragmentState.getSparseParcelableArray(VIEW_STATE_TAG); fragment.mSavedFragmentState = fragmentState.mSavedFragmentState; } } } else { list = null; list2 = null; } this.mActive = new SparseArray<>(fragmentManagerState.mActive.length); int i3 = 0; while (i3 < fragmentManagerState.mActive.length) { FragmentState fragmentState2 = fragmentManagerState.mActive[i3]; if (fragmentState2 != null) { Fragment instantiate = fragmentState2.instantiate(this.mHost, this.mContainer, this.mParent, (list == null || i3 >= list.size()) ? null : list.get(i3), (list2 == null || i3 >= list2.size()) ? null : list2.get(i3)); if (DEBUG) { Log.v(TAG, "restoreAllState: active #" + i3 + ": " + instantiate); } this.mActive.put(instantiate.mIndex, instantiate); fragmentState2.mInstance = null; } i3++; } if (fragmentManagerNonConfig != null) { List<Fragment> fragments2 = fragmentManagerNonConfig.getFragments(); int size2 = fragments2 != null ? fragments2.size() : 0; for (int i4 = 0; i4 < size2; i4++) { Fragment fragment2 = fragments2.get(i4); if (fragment2.mTargetIndex >= 0) { fragment2.mTarget = this.mActive.get(fragment2.mTargetIndex); if (fragment2.mTarget == null) { Log.w(TAG, "Re-attaching retained fragment " + fragment2 + " target no longer exists: " + fragment2.mTargetIndex); } } } } this.mAdded.clear(); if (fragmentManagerState.mAdded != null) { for (int i5 = 0; i5 < fragmentManagerState.mAdded.length; i5++) { Fragment fragment3 = this.mActive.get(fragmentManagerState.mAdded[i5]); if (fragment3 == null) { throwException(new IllegalStateException("No instantiated fragment for index #" + fragmentManagerState.mAdded[i5])); } fragment3.mAdded = true; if (DEBUG) { Log.v(TAG, "restoreAllState: added #" + i5 + ": " + fragment3); } if (this.mAdded.contains(fragment3)) { throw new IllegalStateException("Already added!"); } synchronized (this.mAdded) { this.mAdded.add(fragment3); } } } if (fragmentManagerState.mBackStack != null) { this.mBackStack = new ArrayList<>(fragmentManagerState.mBackStack.length); for (int i6 = 0; i6 < fragmentManagerState.mBackStack.length; i6++) { BackStackRecord instantiate2 = fragmentManagerState.mBackStack[i6].instantiate(this); if (DEBUG) { Log.v(TAG, "restoreAllState: back stack #" + i6 + " (index " + instantiate2.mIndex + "): " + instantiate2); PrintWriter printWriter = new PrintWriter(new LogWriter(TAG)); instantiate2.dump(" ", printWriter, false); printWriter.close(); } this.mBackStack.add(instantiate2); if (instantiate2.mIndex >= 0) { setBackStackIndex(instantiate2.mIndex, instantiate2); } } } else { this.mBackStack = null; } if (fragmentManagerState.mPrimaryNavActiveIndex >= 0) { this.mPrimaryNav = this.mActive.get(fragmentManagerState.mPrimaryNavActiveIndex); } this.mNextFragmentIndex = fragmentManagerState.mNextFragmentIndex; } private void burpActive() { SparseArray<Fragment> sparseArray = this.mActive; if (sparseArray != null) { for (int size = sparseArray.size() - 1; size >= 0; size--) { if (this.mActive.valueAt(size) == null) { SparseArray<Fragment> sparseArray2 = this.mActive; sparseArray2.delete(sparseArray2.keyAt(size)); } } } } public void attachController(FragmentHostCallback fragmentHostCallback, FragmentContainer fragmentContainer, Fragment fragment) { if (this.mHost != null) { throw new IllegalStateException("Already attached"); } this.mHost = fragmentHostCallback; this.mContainer = fragmentContainer; this.mParent = fragment; } public void noteStateNotSaved() { this.mSavedNonConfig = null; this.mStateSaved = false; this.mStopped = false; int size = this.mAdded.size(); for (int i = 0; i < size; i++) { Fragment fragment = this.mAdded.get(i); if (fragment != null) { fragment.noteStateNotSaved(); } } } public void dispatchCreate() { this.mStateSaved = false; this.mStopped = false; dispatchStateChange(1); } public void dispatchActivityCreated() { this.mStateSaved = false; this.mStopped = false; dispatchStateChange(2); } public void dispatchStart() { this.mStateSaved = false; this.mStopped = false; dispatchStateChange(3); } public void dispatchResume() { this.mStateSaved = false; this.mStopped = false; dispatchStateChange(4); } public void dispatchPause() { dispatchStateChange(3); } public void dispatchStop() { this.mStopped = true; dispatchStateChange(2); } public void dispatchDestroyView() { dispatchStateChange(1); } public void dispatchDestroy() { this.mDestroyed = true; execPendingActions(); dispatchStateChange(0); this.mHost = null; this.mContainer = null; this.mParent = null; } private void dispatchStateChange(int i) { try { this.mExecutingActions = true; moveToState(i, false); this.mExecutingActions = false; execPendingActions(); } catch (Throwable th) { this.mExecutingActions = false; throw th; } } public void dispatchMultiWindowModeChanged(boolean z) { for (int size = this.mAdded.size() - 1; size >= 0; size--) { Fragment fragment = this.mAdded.get(size); if (fragment != null) { fragment.performMultiWindowModeChanged(z); } } } public void dispatchPictureInPictureModeChanged(boolean z) { for (int size = this.mAdded.size() - 1; size >= 0; size--) { Fragment fragment = this.mAdded.get(size); if (fragment != null) { fragment.performPictureInPictureModeChanged(z); } } } public void dispatchConfigurationChanged(Configuration configuration) { for (int i = 0; i < this.mAdded.size(); i++) { Fragment fragment = this.mAdded.get(i); if (fragment != null) { fragment.performConfigurationChanged(configuration); } } } public void dispatchLowMemory() { for (int i = 0; i < this.mAdded.size(); i++) { Fragment fragment = this.mAdded.get(i); if (fragment != null) { fragment.performLowMemory(); } } } public boolean dispatchCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { if (this.mCurState < 1) { return false; } ArrayList<Fragment> arrayList = null; boolean z = false; for (int i = 0; i < this.mAdded.size(); i++) { Fragment fragment = this.mAdded.get(i); if (fragment != null && fragment.performCreateOptionsMenu(menu, menuInflater)) { if (arrayList == null) { arrayList = new ArrayList<>(); } arrayList.add(fragment); z = true; } } if (this.mCreatedMenus != null) { for (int i2 = 0; i2 < this.mCreatedMenus.size(); i2++) { Fragment fragment2 = this.mCreatedMenus.get(i2); if (arrayList == null || !arrayList.contains(fragment2)) { fragment2.onDestroyOptionsMenu(); } } } this.mCreatedMenus = arrayList; return z; } public boolean dispatchPrepareOptionsMenu(Menu menu) { if (this.mCurState < 1) { return false; } boolean z = false; for (int i = 0; i < this.mAdded.size(); i++) { Fragment fragment = this.mAdded.get(i); if (fragment != null && fragment.performPrepareOptionsMenu(menu)) { z = true; } } return z; } public boolean dispatchOptionsItemSelected(MenuItem menuItem) { if (this.mCurState < 1) { return false; } for (int i = 0; i < this.mAdded.size(); i++) { Fragment fragment = this.mAdded.get(i); if (fragment != null && fragment.performOptionsItemSelected(menuItem)) { return true; } } return false; } public boolean dispatchContextItemSelected(MenuItem menuItem) { if (this.mCurState < 1) { return false; } for (int i = 0; i < this.mAdded.size(); i++) { Fragment fragment = this.mAdded.get(i); if (fragment != null && fragment.performContextItemSelected(menuItem)) { return true; } } return false; } public void dispatchOptionsMenuClosed(Menu menu) { if (this.mCurState < 1) { return; } for (int i = 0; i < this.mAdded.size(); i++) { Fragment fragment = this.mAdded.get(i); if (fragment != null) { fragment.performOptionsMenuClosed(menu); } } } public void setPrimaryNavigationFragment(Fragment fragment) { if (fragment != null && (this.mActive.get(fragment.mIndex) != fragment || (fragment.mHost != null && fragment.getFragmentManager() != this))) { throw new IllegalArgumentException("Fragment " + fragment + " is not an active fragment of FragmentManager " + this); } this.mPrimaryNav = fragment; } @Override public Fragment getPrimaryNavigationFragment() { return this.mPrimaryNav; } @Override public void registerFragmentLifecycleCallbacks(FragmentManager.FragmentLifecycleCallbacks fragmentLifecycleCallbacks, boolean z) { this.mLifecycleCallbacks.add(new FragmentLifecycleCallbacksHolder(fragmentLifecycleCallbacks, z)); } @Override public void unregisterFragmentLifecycleCallbacks(FragmentManager.FragmentLifecycleCallbacks fragmentLifecycleCallbacks) { synchronized (this.mLifecycleCallbacks) { int i = 0; int size = this.mLifecycleCallbacks.size(); while (true) { if (i >= size) { break; } if (this.mLifecycleCallbacks.get(i).mCallback == fragmentLifecycleCallbacks) { this.mLifecycleCallbacks.remove(i); break; } i++; } } } void dispatchOnFragmentPreAttached(Fragment fragment, Context context, boolean z) { Fragment fragment2 = this.mParent; if (fragment2 != null) { FragmentManager fragmentManager = fragment2.getFragmentManager(); if (fragmentManager instanceof FragmentManagerImpl) { ((FragmentManagerImpl) fragmentManager).dispatchOnFragmentPreAttached(fragment, context, true); } } Iterator<FragmentLifecycleCallbacksHolder> it = this.mLifecycleCallbacks.iterator(); while (it.hasNext()) { FragmentLifecycleCallbacksHolder next = it.next(); if (!z || next.mRecursive) { next.mCallback.onFragmentPreAttached(this, fragment, context); } } } void dispatchOnFragmentAttached(Fragment fragment, Context context, boolean z) { Fragment fragment2 = this.mParent; if (fragment2 != null) { FragmentManager fragmentManager = fragment2.getFragmentManager(); if (fragmentManager instanceof FragmentManagerImpl) { ((FragmentManagerImpl) fragmentManager).dispatchOnFragmentAttached(fragment, context, true); } } Iterator<FragmentLifecycleCallbacksHolder> it = this.mLifecycleCallbacks.iterator(); while (it.hasNext()) { FragmentLifecycleCallbacksHolder next = it.next(); if (!z || next.mRecursive) { next.mCallback.onFragmentAttached(this, fragment, context); } } } void dispatchOnFragmentPreCreated(Fragment fragment, Bundle bundle, boolean z) { Fragment fragment2 = this.mParent; if (fragment2 != null) { FragmentManager fragmentManager = fragment2.getFragmentManager(); if (fragmentManager instanceof FragmentManagerImpl) { ((FragmentManagerImpl) fragmentManager).dispatchOnFragmentPreCreated(fragment, bundle, true); } } Iterator<FragmentLifecycleCallbacksHolder> it = this.mLifecycleCallbacks.iterator(); while (it.hasNext()) { FragmentLifecycleCallbacksHolder next = it.next(); if (!z || next.mRecursive) { next.mCallback.onFragmentPreCreated(this, fragment, bundle); } } } void dispatchOnFragmentCreated(Fragment fragment, Bundle bundle, boolean z) { Fragment fragment2 = this.mParent; if (fragment2 != null) { FragmentManager fragmentManager = fragment2.getFragmentManager(); if (fragmentManager instanceof FragmentManagerImpl) { ((FragmentManagerImpl) fragmentManager).dispatchOnFragmentCreated(fragment, bundle, true); } } Iterator<FragmentLifecycleCallbacksHolder> it = this.mLifecycleCallbacks.iterator(); while (it.hasNext()) { FragmentLifecycleCallbacksHolder next = it.next(); if (!z || next.mRecursive) { next.mCallback.onFragmentCreated(this, fragment, bundle); } } } void dispatchOnFragmentActivityCreated(Fragment fragment, Bundle bundle, boolean z) { Fragment fragment2 = this.mParent; if (fragment2 != null) { FragmentManager fragmentManager = fragment2.getFragmentManager(); if (fragmentManager instanceof FragmentManagerImpl) { ((FragmentManagerImpl) fragmentManager).dispatchOnFragmentActivityCreated(fragment, bundle, true); } } Iterator<FragmentLifecycleCallbacksHolder> it = this.mLifecycleCallbacks.iterator(); while (it.hasNext()) { FragmentLifecycleCallbacksHolder next = it.next(); if (!z || next.mRecursive) { next.mCallback.onFragmentActivityCreated(this, fragment, bundle); } } } void dispatchOnFragmentViewCreated(Fragment fragment, View view, Bundle bundle, boolean z) { Fragment fragment2 = this.mParent; if (fragment2 != null) { FragmentManager fragmentManager = fragment2.getFragmentManager(); if (fragmentManager instanceof FragmentManagerImpl) { ((FragmentManagerImpl) fragmentManager).dispatchOnFragmentViewCreated(fragment, view, bundle, true); } } Iterator<FragmentLifecycleCallbacksHolder> it = this.mLifecycleCallbacks.iterator(); while (it.hasNext()) { FragmentLifecycleCallbacksHolder next = it.next(); if (!z || next.mRecursive) { next.mCallback.onFragmentViewCreated(this, fragment, view, bundle); } } } void dispatchOnFragmentStarted(Fragment fragment, boolean z) { Fragment fragment2 = this.mParent; if (fragment2 != null) { FragmentManager fragmentManager = fragment2.getFragmentManager(); if (fragmentManager instanceof FragmentManagerImpl) { ((FragmentManagerImpl) fragmentManager).dispatchOnFragmentStarted(fragment, true); } } Iterator<FragmentLifecycleCallbacksHolder> it = this.mLifecycleCallbacks.iterator(); while (it.hasNext()) { FragmentLifecycleCallbacksHolder next = it.next(); if (!z || next.mRecursive) { next.mCallback.onFragmentStarted(this, fragment); } } } void dispatchOnFragmentResumed(Fragment fragment, boolean z) { Fragment fragment2 = this.mParent; if (fragment2 != null) { FragmentManager fragmentManager = fragment2.getFragmentManager(); if (fragmentManager instanceof FragmentManagerImpl) { ((FragmentManagerImpl) fragmentManager).dispatchOnFragmentResumed(fragment, true); } } Iterator<FragmentLifecycleCallbacksHolder> it = this.mLifecycleCallbacks.iterator(); while (it.hasNext()) { FragmentLifecycleCallbacksHolder next = it.next(); if (!z || next.mRecursive) { next.mCallback.onFragmentResumed(this, fragment); } } } void dispatchOnFragmentPaused(Fragment fragment, boolean z) { Fragment fragment2 = this.mParent; if (fragment2 != null) { FragmentManager fragmentManager = fragment2.getFragmentManager(); if (fragmentManager instanceof FragmentManagerImpl) { ((FragmentManagerImpl) fragmentManager).dispatchOnFragmentPaused(fragment, true); } } Iterator<FragmentLifecycleCallbacksHolder> it = this.mLifecycleCallbacks.iterator(); while (it.hasNext()) { FragmentLifecycleCallbacksHolder next = it.next(); if (!z || next.mRecursive) { next.mCallback.onFragmentPaused(this, fragment); } } } void dispatchOnFragmentStopped(Fragment fragment, boolean z) { Fragment fragment2 = this.mParent; if (fragment2 != null) { FragmentManager fragmentManager = fragment2.getFragmentManager(); if (fragmentManager instanceof FragmentManagerImpl) { ((FragmentManagerImpl) fragmentManager).dispatchOnFragmentStopped(fragment, true); } } Iterator<FragmentLifecycleCallbacksHolder> it = this.mLifecycleCallbacks.iterator(); while (it.hasNext()) { FragmentLifecycleCallbacksHolder next = it.next(); if (!z || next.mRecursive) { next.mCallback.onFragmentStopped(this, fragment); } } } void dispatchOnFragmentSaveInstanceState(Fragment fragment, Bundle bundle, boolean z) { Fragment fragment2 = this.mParent; if (fragment2 != null) { FragmentManager fragmentManager = fragment2.getFragmentManager(); if (fragmentManager instanceof FragmentManagerImpl) { ((FragmentManagerImpl) fragmentManager).dispatchOnFragmentSaveInstanceState(fragment, bundle, true); } } Iterator<FragmentLifecycleCallbacksHolder> it = this.mLifecycleCallbacks.iterator(); while (it.hasNext()) { FragmentLifecycleCallbacksHolder next = it.next(); if (!z || next.mRecursive) { next.mCallback.onFragmentSaveInstanceState(this, fragment, bundle); } } } void dispatchOnFragmentViewDestroyed(Fragment fragment, boolean z) { Fragment fragment2 = this.mParent; if (fragment2 != null) { FragmentManager fragmentManager = fragment2.getFragmentManager(); if (fragmentManager instanceof FragmentManagerImpl) { ((FragmentManagerImpl) fragmentManager).dispatchOnFragmentViewDestroyed(fragment, true); } } Iterator<FragmentLifecycleCallbacksHolder> it = this.mLifecycleCallbacks.iterator(); while (it.hasNext()) { FragmentLifecycleCallbacksHolder next = it.next(); if (!z || next.mRecursive) { next.mCallback.onFragmentViewDestroyed(this, fragment); } } } void dispatchOnFragmentDestroyed(Fragment fragment, boolean z) { Fragment fragment2 = this.mParent; if (fragment2 != null) { FragmentManager fragmentManager = fragment2.getFragmentManager(); if (fragmentManager instanceof FragmentManagerImpl) { ((FragmentManagerImpl) fragmentManager).dispatchOnFragmentDestroyed(fragment, true); } } Iterator<FragmentLifecycleCallbacksHolder> it = this.mLifecycleCallbacks.iterator(); while (it.hasNext()) { FragmentLifecycleCallbacksHolder next = it.next(); if (!z || next.mRecursive) { next.mCallback.onFragmentDestroyed(this, fragment); } } } void dispatchOnFragmentDetached(Fragment fragment, boolean z) { Fragment fragment2 = this.mParent; if (fragment2 != null) { FragmentManager fragmentManager = fragment2.getFragmentManager(); if (fragmentManager instanceof FragmentManagerImpl) { ((FragmentManagerImpl) fragmentManager).dispatchOnFragmentDetached(fragment, true); } } Iterator<FragmentLifecycleCallbacksHolder> it = this.mLifecycleCallbacks.iterator(); while (it.hasNext()) { FragmentLifecycleCallbacksHolder next = it.next(); if (!z || next.mRecursive) { next.mCallback.onFragmentDetached(this, fragment); } } } @Override public View onCreateView(View view, String str, Context context, AttributeSet attributeSet) { Fragment fragment; if (!"fragment".equals(str)) { return null; } String attributeValue = attributeSet.getAttributeValue(null, "class"); TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, FragmentTag.Fragment); if (attributeValue == null) { attributeValue = obtainStyledAttributes.getString(0); } String str2 = attributeValue; int resourceId = obtainStyledAttributes.getResourceId(1, -1); String string = obtainStyledAttributes.getString(2); obtainStyledAttributes.recycle(); if (!Fragment.isSupportFragmentClass(this.mHost.getContext(), str2)) { return null; } int id = view != null ? view.getId() : 0; if (id == -1 && resourceId == -1 && string == null) { throw new IllegalArgumentException(attributeSet.getPositionDescription() + ": Must specify unique android:id, android:tag, or have a parent with an id for " + str2); } Fragment findFragmentById = resourceId != -1 ? findFragmentById(resourceId) : null; if (findFragmentById == null && string != null) { findFragmentById = findFragmentByTag(string); } if (findFragmentById == null && id != -1) { findFragmentById = findFragmentById(id); } if (DEBUG) { Log.v(TAG, "onCreateView: id=0x" + Integer.toHexString(resourceId) + " fname=" + str2 + " existing=" + findFragmentById); } if (findFragmentById == null) { Fragment instantiate = this.mContainer.instantiate(context, str2, null); instantiate.mFromLayout = true; instantiate.mFragmentId = resourceId != 0 ? resourceId : id; instantiate.mContainerId = id; instantiate.mTag = string; instantiate.mInLayout = true; instantiate.mFragmentManager = this; FragmentHostCallback fragmentHostCallback = this.mHost; instantiate.mHost = fragmentHostCallback; instantiate.onInflate(fragmentHostCallback.getContext(), attributeSet, instantiate.mSavedFragmentState); addFragment(instantiate, true); fragment = instantiate; } else { if (findFragmentById.mInLayout) { throw new IllegalArgumentException(attributeSet.getPositionDescription() + ": Duplicate id 0x" + Integer.toHexString(resourceId) + ", tag " + string + ", or parent id 0x" + Integer.toHexString(id) + " with another fragment for " + str2); } findFragmentById.mInLayout = true; findFragmentById.mHost = this.mHost; if (!findFragmentById.mRetaining) { findFragmentById.onInflate(this.mHost.getContext(), attributeSet, findFragmentById.mSavedFragmentState); } fragment = findFragmentById; } if (this.mCurState < 1 && fragment.mFromLayout) { moveToState(fragment, 1, 0, 0, false); } else { moveToState(fragment); } if (fragment.mView == null) { throw new IllegalStateException("Fragment " + str2 + " did not create a view."); } if (resourceId != 0) { fragment.mView.setId(resourceId); } if (fragment.mView.getTag() == null) { fragment.mView.setTag(string); } return fragment.mView; } @Override public View onCreateView(String str, Context context, AttributeSet attributeSet) { return onCreateView(null, str, context, attributeSet); } public static class FragmentTag { public static final int[] Fragment = {R.attr.name, R.attr.id, R.attr.tag}; public static final int Fragment_id = 1; public static final int Fragment_name = 0; public static final int Fragment_tag = 2; private FragmentTag() { } } private class PopBackStackState implements OpGenerator { final int mFlags; final int mId; final String mName; PopBackStackState(String str, int i, int i2) { this.mName = str; this.mId = i; this.mFlags = i2; } @Override public boolean generateOps(ArrayList<BackStackRecord> arrayList, ArrayList<Boolean> arrayList2) { FragmentManager peekChildFragmentManager; if (FragmentManagerImpl.this.mPrimaryNav == null || this.mId >= 0 || this.mName != null || (peekChildFragmentManager = FragmentManagerImpl.this.mPrimaryNav.peekChildFragmentManager()) == null || !peekChildFragmentManager.popBackStackImmediate()) { return FragmentManagerImpl.this.popBackStackState(arrayList, arrayList2, this.mName, this.mId, this.mFlags); } return false; } } public static class StartEnterTransitionListener implements Fragment.OnStartEnterTransitionListener { final boolean mIsBack; private int mNumPostponed; final BackStackRecord mRecord; StartEnterTransitionListener(BackStackRecord backStackRecord, boolean z) { this.mIsBack = z; this.mRecord = backStackRecord; } @Override public void onStartEnterTransition() { this.mNumPostponed--; if (this.mNumPostponed != 0) { return; } this.mRecord.mManager.scheduleCommit(); } @Override public void startListening() { this.mNumPostponed++; } public boolean isReady() { return this.mNumPostponed == 0; } public void completeTransaction() { boolean z = this.mNumPostponed > 0; FragmentManagerImpl fragmentManagerImpl = this.mRecord.mManager; int size = fragmentManagerImpl.mAdded.size(); for (int i = 0; i < size; i++) { Fragment fragment = fragmentManagerImpl.mAdded.get(i); fragment.setOnStartEnterTransitionListener(null); if (z && fragment.isPostponed()) { fragment.startPostponedEnterTransition(); } } this.mRecord.mManager.completeExecute(this.mRecord, this.mIsBack, !z, true); } public void cancelTransaction() { this.mRecord.mManager.completeExecute(this.mRecord, this.mIsBack, false, false); } } public static class AnimationOrAnimator { public final Animation animation; public final Animator animator; AnimationOrAnimator(Animation animation) { this.animation = animation; this.animator = null; if (animation == null) { throw new IllegalStateException("Animation cannot be null"); } } AnimationOrAnimator(Animator animator) { this.animation = null; this.animator = animator; if (animator == null) { throw new IllegalStateException("Animator cannot be null"); } } } private static class AnimationListenerWrapper implements Animation.AnimationListener { private final Animation.AnimationListener mWrapped; AnimationListenerWrapper(Animation.AnimationListener animationListener) { this.mWrapped = animationListener; } @Override public void onAnimationStart(Animation animation) { Animation.AnimationListener animationListener = this.mWrapped; if (animationListener != null) { animationListener.onAnimationStart(animation); } } @Override public void onAnimationEnd(Animation animation) { Animation.AnimationListener animationListener = this.mWrapped; if (animationListener != null) { animationListener.onAnimationEnd(animation); } } @Override public void onAnimationRepeat(Animation animation) { Animation.AnimationListener animationListener = this.mWrapped; if (animationListener != null) { animationListener.onAnimationRepeat(animation); } } } public static class AnimateOnHWLayerIfNeededListener extends AnimationListenerWrapper { View mView; AnimateOnHWLayerIfNeededListener(View view, Animation.AnimationListener animationListener) { super(animationListener); this.mView = view; } @Override public void onAnimationEnd(Animation animation) { if (ViewCompat.isAttachedToWindow(this.mView) || Build.VERSION.SDK_INT >= 24) { this.mView.post(new Runnable() { @Override public void run() { AnimateOnHWLayerIfNeededListener.this.mView.setLayerType(0, null); } }); } else { this.mView.setLayerType(0, null); } super.onAnimationEnd(animation); } } public static class AnimatorOnHWLayerIfNeededListener extends AnimatorListenerAdapter { View mView; AnimatorOnHWLayerIfNeededListener(View view) { this.mView = view; } @Override public void onAnimationStart(Animator animator) { this.mView.setLayerType(2, null); } @Override public void onAnimationEnd(Animator animator) { this.mView.setLayerType(0, null); animator.removeListener(this); } } public static class EndViewTransitionAnimator extends AnimationSet implements Runnable { private boolean mAnimating; private final View mChild; private boolean mEnded; private final ViewGroup mParent; private boolean mTransitionEnded; EndViewTransitionAnimator(Animation animation, ViewGroup viewGroup, View view) { super(false); this.mAnimating = true; this.mParent = viewGroup; this.mChild = view; addAnimation(animation); this.mParent.post(this); } @Override public boolean getTransformation(long j, Transformation transformation) { this.mAnimating = true; if (this.mEnded) { return !this.mTransitionEnded; } if (!super.getTransformation(j, transformation)) { this.mEnded = true; OneShotPreDrawListener.add(this.mParent, this); } return true; } @Override public boolean getTransformation(long j, Transformation transformation, float f) { this.mAnimating = true; if (this.mEnded) { return !this.mTransitionEnded; } if (!super.getTransformation(j, transformation, f)) { this.mEnded = true; OneShotPreDrawListener.add(this.mParent, this); } return true; } @Override public void run() { if (!this.mEnded && this.mAnimating) { this.mAnimating = false; this.mParent.post(this); } else { this.mParent.endViewTransition(this.mChild); this.mTransitionEnded = true; } } } }