Fragment.java revision 995c3504e6c5b1d20368c36193b44a7e6844709d
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.support.v4.app;
18
19import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP;
20
21import android.app.Activity;
22import android.content.ComponentCallbacks;
23import android.content.Context;
24import android.content.Intent;
25import android.content.IntentSender;
26import android.content.res.Configuration;
27import android.content.res.Resources;
28import android.os.Bundle;
29import android.os.Looper;
30import android.os.Parcel;
31import android.os.Parcelable;
32import android.support.annotation.CallSuper;
33import android.support.annotation.NonNull;
34import android.support.annotation.Nullable;
35import android.support.annotation.RestrictTo;
36import android.support.annotation.StringRes;
37import android.support.v4.util.DebugUtils;
38import android.support.v4.util.SimpleArrayMap;
39import android.support.v4.view.LayoutInflaterCompat;
40import android.util.AttributeSet;
41import android.util.Log;
42import android.util.SparseArray;
43import android.view.ContextMenu;
44import android.view.ContextMenu.ContextMenuInfo;
45import android.view.LayoutInflater;
46import android.view.Menu;
47import android.view.MenuInflater;
48import android.view.MenuItem;
49import android.view.View;
50import android.view.View.OnCreateContextMenuListener;
51import android.view.ViewGroup;
52import android.view.animation.Animation;
53import android.widget.AdapterView;
54
55import java.io.FileDescriptor;
56import java.io.PrintWriter;
57
58final class FragmentState implements Parcelable {
59    final String mClassName;
60    final int mIndex;
61    final boolean mFromLayout;
62    final int mFragmentId;
63    final int mContainerId;
64    final String mTag;
65    final boolean mRetainInstance;
66    final boolean mDetached;
67    final Bundle mArguments;
68    final boolean mHidden;
69
70    Bundle mSavedFragmentState;
71
72    Fragment mInstance;
73
74    public FragmentState(Fragment frag) {
75        mClassName = frag.getClass().getName();
76        mIndex = frag.mIndex;
77        mFromLayout = frag.mFromLayout;
78        mFragmentId = frag.mFragmentId;
79        mContainerId = frag.mContainerId;
80        mTag = frag.mTag;
81        mRetainInstance = frag.mRetainInstance;
82        mDetached = frag.mDetached;
83        mArguments = frag.mArguments;
84        mHidden = frag.mHidden;
85    }
86
87    public FragmentState(Parcel in) {
88        mClassName = in.readString();
89        mIndex = in.readInt();
90        mFromLayout = in.readInt() != 0;
91        mFragmentId = in.readInt();
92        mContainerId = in.readInt();
93        mTag = in.readString();
94        mRetainInstance = in.readInt() != 0;
95        mDetached = in.readInt() != 0;
96        mArguments = in.readBundle();
97        mHidden = in.readInt() != 0;
98        mSavedFragmentState = in.readBundle();
99    }
100
101    public Fragment instantiate(FragmentHostCallback host, FragmentContainer container,
102            Fragment parent, FragmentManagerNonConfig childNonConfig) {
103        if (mInstance == null) {
104            final Context context = host.getContext();
105            if (mArguments != null) {
106                mArguments.setClassLoader(context.getClassLoader());
107            }
108
109            if (container != null) {
110                mInstance = container.instantiate(context, mClassName, mArguments);
111            } else {
112                mInstance = Fragment.instantiate(context, mClassName, mArguments);
113            }
114
115            if (mSavedFragmentState != null) {
116                mSavedFragmentState.setClassLoader(context.getClassLoader());
117                mInstance.mSavedFragmentState = mSavedFragmentState;
118            }
119            mInstance.setIndex(mIndex, parent);
120            mInstance.mFromLayout = mFromLayout;
121            mInstance.mRestored = true;
122            mInstance.mFragmentId = mFragmentId;
123            mInstance.mContainerId = mContainerId;
124            mInstance.mTag = mTag;
125            mInstance.mRetainInstance = mRetainInstance;
126            mInstance.mDetached = mDetached;
127            mInstance.mHidden = mHidden;
128            mInstance.mFragmentManager = host.mFragmentManager;
129
130            if (FragmentManagerImpl.DEBUG) Log.v(FragmentManagerImpl.TAG,
131                    "Instantiated fragment " + mInstance);
132        }
133        mInstance.mChildNonConfig = childNonConfig;
134        return mInstance;
135    }
136
137    @Override
138    public int describeContents() {
139        return 0;
140    }
141
142    @Override
143    public void writeToParcel(Parcel dest, int flags) {
144        dest.writeString(mClassName);
145        dest.writeInt(mIndex);
146        dest.writeInt(mFromLayout ? 1 : 0);
147        dest.writeInt(mFragmentId);
148        dest.writeInt(mContainerId);
149        dest.writeString(mTag);
150        dest.writeInt(mRetainInstance ? 1 : 0);
151        dest.writeInt(mDetached ? 1 : 0);
152        dest.writeBundle(mArguments);
153        dest.writeInt(mHidden? 1 : 0);
154        dest.writeBundle(mSavedFragmentState);
155    }
156
157    public static final Parcelable.Creator<FragmentState> CREATOR
158            = new Parcelable.Creator<FragmentState>() {
159        @Override
160        public FragmentState createFromParcel(Parcel in) {
161            return new FragmentState(in);
162        }
163
164        @Override
165        public FragmentState[] newArray(int size) {
166            return new FragmentState[size];
167        }
168    };
169}
170
171/**
172 * Static library support version of the framework's {@link android.app.Fragment}.
173 * Used to write apps that run on platforms prior to Android 3.0.  When running
174 * on Android 3.0 or above, this implementation is still used; it does not try
175 * to switch to the framework's implementation. See the framework {@link android.app.Fragment}
176 * documentation for a class overview.
177 *
178 * <p>The main differences when using this support version instead of the framework version are:
179 * <ul>
180 *  <li>Your activity must extend {@link FragmentActivity}
181 *  <li>You must call {@link FragmentActivity#getSupportFragmentManager} to get the
182 *  {@link FragmentManager}
183 * </ul>
184 *
185 */
186public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener {
187    private static final SimpleArrayMap<String, Class<?>> sClassMap =
188            new SimpleArrayMap<String, Class<?>>();
189
190    static final Object USE_DEFAULT_TRANSITION = new Object();
191
192    static final int INITIALIZING = 0;     // Not yet created.
193    static final int CREATED = 1;          // Created.
194    static final int ACTIVITY_CREATED = 2; // The activity has finished its creation.
195    static final int STOPPED = 3;          // Fully created, not started.
196    static final int STARTED = 4;          // Created and started, not resumed.
197    static final int RESUMED = 5;          // Created started and resumed.
198
199    int mState = INITIALIZING;
200
201    // When instantiated from saved state, this is the saved state.
202    Bundle mSavedFragmentState;
203    SparseArray<Parcelable> mSavedViewState;
204
205    // Index into active fragment array.
206    int mIndex = -1;
207
208    // Internal unique name for this fragment;
209    String mWho;
210
211    // Construction arguments;
212    Bundle mArguments;
213
214    // Target fragment.
215    Fragment mTarget;
216
217    // For use when retaining a fragment: this is the index of the last mTarget.
218    int mTargetIndex = -1;
219
220    // Target request code.
221    int mTargetRequestCode;
222
223    // True if the fragment is in the list of added fragments.
224    boolean mAdded;
225
226    // If set this fragment is being removed from its activity.
227    boolean mRemoving;
228
229    // Set to true if this fragment was instantiated from a layout file.
230    boolean mFromLayout;
231
232    // Set to true when the view has actually been inflated in its layout.
233    boolean mInLayout;
234
235    // True if this fragment has been restored from previously saved state.
236    boolean mRestored;
237
238    // True if performCreateView has been called and a matching call to performDestroyView
239    // has not yet happened.
240    boolean mPerformedCreateView;
241
242    // Number of active back stack entries this fragment is in.
243    int mBackStackNesting;
244
245    // The fragment manager we are associated with.  Set as soon as the
246    // fragment is used in a transaction; cleared after it has been removed
247    // from all transactions.
248    FragmentManagerImpl mFragmentManager;
249
250    // Host this fragment is attached to.
251    FragmentHostCallback mHost;
252
253    // Private fragment manager for child fragments inside of this one.
254    FragmentManagerImpl mChildFragmentManager;
255
256    // For use when restoring fragment state and descendant fragments are retained.
257    // This state is set by FragmentState.instantiate and cleared in onCreate.
258    FragmentManagerNonConfig mChildNonConfig;
259
260    // If this Fragment is contained in another Fragment, this is that container.
261    Fragment mParentFragment;
262
263    // The optional identifier for this fragment -- either the container ID if it
264    // was dynamically added to the view hierarchy, or the ID supplied in
265    // layout.
266    int mFragmentId;
267
268    // When a fragment is being dynamically added to the view hierarchy, this
269    // is the identifier of the parent container it is being added to.
270    int mContainerId;
271
272    // The optional named tag for this fragment -- usually used to find
273    // fragments that are not part of the layout.
274    String mTag;
275
276    // Set to true when the app has requested that this fragment be hidden
277    // from the user.
278    boolean mHidden;
279
280    // Set to true when the app has requested that this fragment be deactivated.
281    boolean mDetached;
282
283    // If set this fragment would like its instance retained across
284    // configuration changes.
285    boolean mRetainInstance;
286
287    // If set this fragment is being retained across the current config change.
288    boolean mRetaining;
289
290    // If set this fragment has menu items to contribute.
291    boolean mHasMenu;
292
293    // Set to true to allow the fragment's menu to be shown.
294    boolean mMenuVisible = true;
295
296    // Used to verify that subclasses call through to super class.
297    boolean mCalled;
298
299    // The parent container of the fragment after dynamically added to UI.
300    ViewGroup mContainer;
301
302    // The View generated for this fragment.
303    View mView;
304
305    // The real inner view that will save/restore state.
306    View mInnerView;
307
308    // Whether this fragment should defer starting until after other fragments
309    // have been started and their loaders are finished.
310    boolean mDeferStart;
311
312    // Hint provided by the app that this fragment is currently visible to the user.
313    boolean mUserVisibleHint = true;
314
315    LoaderManagerImpl mLoaderManager;
316    boolean mLoadersStarted;
317    boolean mCheckedForLoaderManager;
318
319    // The animation and transition information for the fragment. This will be null
320    // unless the elements are explicitly accessed and should remain null for Fragments
321    // without Views.
322    AnimationInfo mAnimationInfo;
323
324    // True if the View was added, and its animation has yet to be run. This could
325    // also indicate that the fragment view hasn't been made visible, even if there is no
326    // animation for this fragment.
327    boolean mIsNewlyAdded;
328
329    // True if mHidden has been changed and the animation should be scheduled.
330    boolean mHiddenChanged;
331
332    // The alpha of the view when the view was added and then postponed. If the value is less
333    // than zero, this means that the view's add was canceled and should not participate in
334    // removal animations.
335    float mPostponedAlpha;
336
337    /**
338     * State information that has been retrieved from a fragment instance
339     * through {@link FragmentManager#saveFragmentInstanceState(Fragment)
340     * FragmentManager.saveFragmentInstanceState}.
341     */
342    public static class SavedState implements Parcelable {
343        final Bundle mState;
344
345        SavedState(Bundle state) {
346            mState = state;
347        }
348
349        SavedState(Parcel in, ClassLoader loader) {
350            mState = in.readBundle();
351            if (loader != null && mState != null) {
352                mState.setClassLoader(loader);
353            }
354        }
355
356        @Override
357        public int describeContents() {
358            return 0;
359        }
360
361        @Override
362        public void writeToParcel(Parcel dest, int flags) {
363            dest.writeBundle(mState);
364        }
365
366        public static final Parcelable.Creator<SavedState> CREATOR
367                = new Parcelable.Creator<SavedState>() {
368            @Override
369            public SavedState createFromParcel(Parcel in) {
370                return new SavedState(in, null);
371            }
372
373            @Override
374            public SavedState[] newArray(int size) {
375                return new SavedState[size];
376            }
377        };
378    }
379
380    /**
381     * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when
382     * there is an instantiation failure.
383     */
384    static public class InstantiationException extends RuntimeException {
385        public InstantiationException(String msg, Exception cause) {
386            super(msg, cause);
387        }
388    }
389
390    /**
391     * Default constructor.  <strong>Every</strong> fragment must have an
392     * empty constructor, so it can be instantiated when restoring its
393     * activity's state.  It is strongly recommended that subclasses do not
394     * have other constructors with parameters, since these constructors
395     * will not be called when the fragment is re-instantiated; instead,
396     * arguments can be supplied by the caller with {@link #setArguments}
397     * and later retrieved by the Fragment with {@link #getArguments}.
398     *
399     * <p>Applications should generally not implement a constructor. Prefer
400     * {@link #onAttach(Context)} instead. It is the first place application code can run where
401     * the fragment is ready to be used - the point where the fragment is actually associated with
402     * its context. Some applications may also want to implement {@link #onInflate} to retrieve
403     * attributes from a layout resource, although note this happens when the fragment is attached.
404     */
405    public Fragment() {
406    }
407
408    /**
409     * Like {@link #instantiate(Context, String, Bundle)} but with a null
410     * argument Bundle.
411     */
412    public static Fragment instantiate(Context context, String fname) {
413        return instantiate(context, fname, null);
414    }
415
416    /**
417     * Create a new instance of a Fragment with the given class name.  This is
418     * the same as calling its empty constructor.
419     *
420     * @param context The calling context being used to instantiate the fragment.
421     * This is currently just used to get its ClassLoader.
422     * @param fname The class name of the fragment to instantiate.
423     * @param args Bundle of arguments to supply to the fragment, which it
424     * can retrieve with {@link #getArguments()}.  May be null.
425     * @return Returns a new fragment instance.
426     * @throws InstantiationException If there is a failure in instantiating
427     * the given fragment class.  This is a runtime exception; it is not
428     * normally expected to happen.
429     */
430    public static Fragment instantiate(Context context, String fname, @Nullable Bundle args) {
431        try {
432            Class<?> clazz = sClassMap.get(fname);
433            if (clazz == null) {
434                // Class not found in the cache, see if it's real, and try to add it
435                clazz = context.getClassLoader().loadClass(fname);
436                sClassMap.put(fname, clazz);
437            }
438            Fragment f = (Fragment)clazz.newInstance();
439            if (args != null) {
440                args.setClassLoader(f.getClass().getClassLoader());
441                f.setArguments(args);
442            }
443            return f;
444        } catch (ClassNotFoundException e) {
445            throw new InstantiationException("Unable to instantiate fragment " + fname
446                    + ": make sure class name exists, is public, and has an"
447                    + " empty constructor that is public", e);
448        } catch (java.lang.InstantiationException e) {
449            throw new InstantiationException("Unable to instantiate fragment " + fname
450                    + ": make sure class name exists, is public, and has an"
451                    + " empty constructor that is public", e);
452        } catch (IllegalAccessException e) {
453            throw new InstantiationException("Unable to instantiate fragment " + fname
454                    + ": make sure class name exists, is public, and has an"
455                    + " empty constructor that is public", e);
456        }
457    }
458
459    /**
460     * Determine if the given fragment name is a support library fragment class.
461     *
462     * @param context Context used to determine the correct ClassLoader to use
463     * @param fname Class name of the fragment to test
464     * @return true if <code>fname</code> is <code>android.support.v4.app.Fragment</code>
465     *         or a subclass, false otherwise.
466     */
467    static boolean isSupportFragmentClass(Context context, String fname) {
468        try {
469            Class<?> clazz = sClassMap.get(fname);
470            if (clazz == null) {
471                // Class not found in the cache, see if it's real, and try to add it
472                clazz = context.getClassLoader().loadClass(fname);
473                sClassMap.put(fname, clazz);
474            }
475            return Fragment.class.isAssignableFrom(clazz);
476        } catch (ClassNotFoundException e) {
477            return false;
478        }
479    }
480
481    final void restoreViewState(Bundle savedInstanceState) {
482        if (mSavedViewState != null) {
483            mInnerView.restoreHierarchyState(mSavedViewState);
484            mSavedViewState = null;
485        }
486        mCalled = false;
487        onViewStateRestored(savedInstanceState);
488        if (!mCalled) {
489            throw new SuperNotCalledException("Fragment " + this
490                    + " did not call through to super.onViewStateRestored()");
491        }
492    }
493
494    final void setIndex(int index, Fragment parent) {
495        mIndex = index;
496        if (parent != null) {
497            mWho = parent.mWho + ":" + mIndex;
498        } else {
499            mWho = "android:fragment:" + mIndex;
500        }
501    }
502
503    final boolean isInBackStack() {
504        return mBackStackNesting > 0;
505    }
506
507    /**
508     * Subclasses can not override equals().
509     */
510    @Override final public boolean equals(Object o) {
511        return super.equals(o);
512    }
513
514    /**
515     * Subclasses can not override hashCode().
516     */
517    @Override final public int hashCode() {
518        return super.hashCode();
519    }
520
521    @Override
522    public String toString() {
523        StringBuilder sb = new StringBuilder(128);
524        DebugUtils.buildShortClassTag(this, sb);
525        if (mIndex >= 0) {
526            sb.append(" #");
527            sb.append(mIndex);
528        }
529        if (mFragmentId != 0) {
530            sb.append(" id=0x");
531            sb.append(Integer.toHexString(mFragmentId));
532        }
533        if (mTag != null) {
534            sb.append(" ");
535            sb.append(mTag);
536        }
537        sb.append('}');
538        return sb.toString();
539    }
540
541    /**
542     * Return the identifier this fragment is known by.  This is either
543     * the android:id value supplied in a layout or the container view ID
544     * supplied when adding the fragment.
545     */
546    final public int getId() {
547        return mFragmentId;
548    }
549
550    /**
551     * Get the tag name of the fragment, if specified.
552     */
553    final public String getTag() {
554        return mTag;
555    }
556
557    /**
558     * Supply the construction arguments for this fragment.
559     * The arguments supplied here will be retained across fragment destroy and
560     * creation.
561     * <p>This method cannot be called if the fragment is added to a FragmentManager and
562     * if {@link #isStateSaved()} would return true.</p>
563     */
564    public void setArguments(Bundle args) {
565        if (mIndex >= 0 && isStateSaved()) {
566            throw new IllegalStateException("Fragment already active and state has been saved");
567        }
568        mArguments = args;
569    }
570
571    /**
572     * Return the arguments supplied when the fragment was instantiated,
573     * if any.
574     */
575    final public Bundle getArguments() {
576        return mArguments;
577    }
578
579    /**
580     * Returns true if this fragment is added and its state has already been saved
581     * by its host. Any operations that would change saved state should not be performed
582     * if this method returns true, and some operations such as {@link #setArguments(Bundle)}
583     * will fail.
584     *
585     * @return true if this fragment's state has already been saved by its host
586     */
587    public final boolean isStateSaved() {
588        if (mFragmentManager == null) {
589            return false;
590        }
591        return mFragmentManager.isStateSaved();
592    }
593
594    /**
595     * Set the initial saved state that this Fragment should restore itself
596     * from when first being constructed, as returned by
597     * {@link FragmentManager#saveFragmentInstanceState(Fragment)
598     * FragmentManager.saveFragmentInstanceState}.
599     *
600     * @param state The state the fragment should be restored from.
601     */
602    public void setInitialSavedState(SavedState state) {
603        if (mIndex >= 0) {
604            throw new IllegalStateException("Fragment already active");
605        }
606        mSavedFragmentState = state != null && state.mState != null
607                ? state.mState : null;
608    }
609
610    /**
611     * Optional target for this fragment.  This may be used, for example,
612     * if this fragment is being started by another, and when done wants to
613     * give a result back to the first.  The target set here is retained
614     * across instances via {@link FragmentManager#putFragment
615     * FragmentManager.putFragment()}.
616     *
617     * @param fragment The fragment that is the target of this one.
618     * @param requestCode Optional request code, for convenience if you
619     * are going to call back with {@link #onActivityResult(int, int, Intent)}.
620     */
621    public void setTargetFragment(Fragment fragment, int requestCode) {
622        // Don't allow a caller to set a target fragment in another FragmentManager,
623        // but there's a snag: people do set target fragments before fragments get added.
624        // We'll have the FragmentManager check that for validity when we move
625        // the fragments to a valid state.
626        final FragmentManager mine = getFragmentManager();
627        final FragmentManager theirs = fragment != null ? fragment.getFragmentManager() : null;
628        if (mine != null && theirs != null && mine != theirs) {
629            throw new IllegalArgumentException("Fragment " + fragment
630                    + " must share the same FragmentManager to be set as a target fragment");
631        }
632
633        // Don't let someone create a cycle.
634        for (Fragment check = fragment; check != null; check = check.getTargetFragment()) {
635            if (check == this) {
636                throw new IllegalArgumentException("Setting " + fragment + " as the target of "
637                        + this + " would create a target cycle");
638            }
639        }
640        mTarget = fragment;
641        mTargetRequestCode = requestCode;
642    }
643
644    /**
645     * Return the target fragment set by {@link #setTargetFragment}.
646     */
647    final public Fragment getTargetFragment() {
648        return mTarget;
649    }
650
651    /**
652     * Return the target request code set by {@link #setTargetFragment}.
653     */
654    final public int getTargetRequestCode() {
655        return mTargetRequestCode;
656    }
657
658    /**
659     * Return the {@link Context} this fragment is currently associated with.
660     */
661    public Context getContext() {
662        return mHost == null ? null : mHost.getContext();
663    }
664
665    /**
666     * Return the {@link FragmentActivity} this fragment is currently associated with.
667     * May return {@code null} if the fragment is associated with a {@link Context}
668     * instead.
669     */
670    final public FragmentActivity getActivity() {
671        return mHost == null ? null : (FragmentActivity) mHost.getActivity();
672    }
673
674    /**
675     * Return the host object of this fragment. May return {@code null} if the fragment
676     * isn't currently being hosted.
677     */
678    final public Object getHost() {
679        return mHost == null ? null : mHost.onGetHost();
680    }
681
682    /**
683     * Return <code>getActivity().getResources()</code>.
684     */
685    final public Resources getResources() {
686        if (mHost == null) {
687            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
688        }
689        return mHost.getContext().getResources();
690    }
691
692    /**
693     * Return a localized, styled CharSequence from the application's package's
694     * default string table.
695     *
696     * @param resId Resource id for the CharSequence text
697     */
698    public final CharSequence getText(@StringRes int resId) {
699        return getResources().getText(resId);
700    }
701
702    /**
703     * Return a localized string from the application's package's
704     * default string table.
705     *
706     * @param resId Resource id for the string
707     */
708    public final String getString(@StringRes int resId) {
709        return getResources().getString(resId);
710    }
711
712    /**
713     * Return a localized formatted string from the application's package's
714     * default string table, substituting the format arguments as defined in
715     * {@link java.util.Formatter} and {@link java.lang.String#format}.
716     *
717     * @param resId Resource id for the format string
718     * @param formatArgs The format arguments that will be used for substitution.
719     */
720
721    public final String getString(@StringRes int resId, Object... formatArgs) {
722        return getResources().getString(resId, formatArgs);
723    }
724
725    /**
726     * Return the FragmentManager for interacting with fragments associated
727     * with this fragment's activity.  Note that this will be non-null slightly
728     * before {@link #getActivity()}, during the time from when the fragment is
729     * placed in a {@link FragmentTransaction} until it is committed and
730     * attached to its activity.
731     *
732     * <p>If this Fragment is a child of another Fragment, the FragmentManager
733     * returned here will be the parent's {@link #getChildFragmentManager()}.
734     */
735    final public FragmentManager getFragmentManager() {
736        return mFragmentManager;
737    }
738
739    /**
740     * Return a private FragmentManager for placing and managing Fragments
741     * inside of this Fragment.
742     */
743    final public FragmentManager getChildFragmentManager() {
744        if (mChildFragmentManager == null) {
745            instantiateChildFragmentManager();
746            if (mState >= RESUMED) {
747                mChildFragmentManager.dispatchResume();
748            } else if (mState >= STARTED) {
749                mChildFragmentManager.dispatchStart();
750            } else if (mState >= ACTIVITY_CREATED) {
751                mChildFragmentManager.dispatchActivityCreated();
752            } else if (mState >= CREATED) {
753                mChildFragmentManager.dispatchCreate();
754            }
755        }
756        return mChildFragmentManager;
757    }
758
759    /**
760     * Return this fragment's child FragmentManager one has been previously created,
761     * otherwise null.
762     */
763    FragmentManager peekChildFragmentManager() {
764        return mChildFragmentManager;
765    }
766
767    /**
768     * Returns the parent Fragment containing this Fragment.  If this Fragment
769     * is attached directly to an Activity, returns null.
770     */
771    final public Fragment getParentFragment() {
772        return mParentFragment;
773    }
774
775    /**
776     * Return true if the fragment is currently added to its activity.
777     */
778    final public boolean isAdded() {
779        return mHost != null && mAdded;
780    }
781
782    /**
783     * Return true if the fragment has been explicitly detached from the UI.
784     * That is, {@link FragmentTransaction#detach(Fragment)
785     * FragmentTransaction.detach(Fragment)} has been used on it.
786     */
787    final public boolean isDetached() {
788        return mDetached;
789    }
790
791    /**
792     * Return true if this fragment is currently being removed from its
793     * activity.  This is  <em>not</em> whether its activity is finishing, but
794     * rather whether it is in the process of being removed from its activity.
795     */
796    final public boolean isRemoving() {
797        return mRemoving;
798    }
799
800    /**
801     * Return true if the layout is included as part of an activity view
802     * hierarchy via the &lt;fragment&gt; tag.  This will always be true when
803     * fragments are created through the &lt;fragment&gt; tag, <em>except</em>
804     * in the case where an old fragment is restored from a previous state and
805     * it does not appear in the layout of the current state.
806     */
807    final public boolean isInLayout() {
808        return mInLayout;
809    }
810
811    /**
812     * Return true if the fragment is in the resumed state.  This is true
813     * for the duration of {@link #onResume()} and {@link #onPause()} as well.
814     */
815    final public boolean isResumed() {
816        return mState >= RESUMED;
817    }
818
819    /**
820     * Return true if the fragment is currently visible to the user.  This means
821     * it: (1) has been added, (2) has its view attached to the window, and
822     * (3) is not hidden.
823     */
824    final public boolean isVisible() {
825        return isAdded() && !isHidden() && mView != null
826                && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE;
827    }
828
829    /**
830     * Return true if the fragment has been hidden.  By default fragments
831     * are shown.  You can find out about changes to this state with
832     * {@link #onHiddenChanged}.  Note that the hidden state is orthogonal
833     * to other states -- that is, to be visible to the user, a fragment
834     * must be both started and not hidden.
835     */
836    final public boolean isHidden() {
837        return mHidden;
838    }
839
840    /** @hide */
841    @RestrictTo(LIBRARY_GROUP)
842    final public boolean hasOptionsMenu() {
843        return mHasMenu;
844    }
845
846    /** @hide */
847    @RestrictTo(LIBRARY_GROUP)
848    final public boolean isMenuVisible() {
849        return mMenuVisible;
850    }
851
852    /**
853     * Called when the hidden state (as returned by {@link #isHidden()} of
854     * the fragment has changed.  Fragments start out not hidden; this will
855     * be called whenever the fragment changes state from that.
856     * @param hidden True if the fragment is now hidden, false otherwise.
857     */
858    public void onHiddenChanged(boolean hidden) {
859    }
860
861    /**
862     * Control whether a fragment instance is retained across Activity
863     * re-creation (such as from a configuration change).  This can only
864     * be used with fragments not in the back stack.  If set, the fragment
865     * lifecycle will be slightly different when an activity is recreated:
866     * <ul>
867     * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still
868     * will be, because the fragment is being detached from its current activity).
869     * <li> {@link #onCreate(Bundle)} will not be called since the fragment
870     * is not being re-created.
871     * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b>
872     * still be called.
873     * </ul>
874     */
875    public void setRetainInstance(boolean retain) {
876        mRetainInstance = retain;
877    }
878
879    final public boolean getRetainInstance() {
880        return mRetainInstance;
881    }
882
883    /**
884     * Report that this fragment would like to participate in populating
885     * the options menu by receiving a call to {@link #onCreateOptionsMenu}
886     * and related methods.
887     *
888     * @param hasMenu If true, the fragment has menu items to contribute.
889     */
890    public void setHasOptionsMenu(boolean hasMenu) {
891        if (mHasMenu != hasMenu) {
892            mHasMenu = hasMenu;
893            if (isAdded() && !isHidden()) {
894                mHost.onSupportInvalidateOptionsMenu();
895            }
896        }
897    }
898
899    /**
900     * Set a hint for whether this fragment's menu should be visible.  This
901     * is useful if you know that a fragment has been placed in your view
902     * hierarchy so that the user can not currently seen it, so any menu items
903     * it has should also not be shown.
904     *
905     * @param menuVisible The default is true, meaning the fragment's menu will
906     * be shown as usual.  If false, the user will not see the menu.
907     */
908    public void setMenuVisibility(boolean menuVisible) {
909        if (mMenuVisible != menuVisible) {
910            mMenuVisible = menuVisible;
911            if (mHasMenu && isAdded() && !isHidden()) {
912                mHost.onSupportInvalidateOptionsMenu();
913            }
914        }
915    }
916
917    /**
918     * Set a hint to the system about whether this fragment's UI is currently visible
919     * to the user. This hint defaults to true and is persistent across fragment instance
920     * state save and restore.
921     *
922     * <p>An app may set this to false to indicate that the fragment's UI is
923     * scrolled out of visibility or is otherwise not directly visible to the user.
924     * This may be used by the system to prioritize operations such as fragment lifecycle updates
925     * or loader ordering behavior.</p>
926     *
927     * <p><strong>Note:</strong> This method may be called outside of the fragment lifecycle.
928     * and thus has no ordering guarantees with regard to fragment lifecycle method calls.</p>
929     *
930     * @param isVisibleToUser true if this fragment's UI is currently visible to the user (default),
931     *                        false if it is not.
932     */
933    public void setUserVisibleHint(boolean isVisibleToUser) {
934        if (!mUserVisibleHint && isVisibleToUser && mState < STARTED
935                && mFragmentManager != null && isAdded()) {
936            mFragmentManager.performPendingDeferredStart(this);
937        }
938        mUserVisibleHint = isVisibleToUser;
939        mDeferStart = mState < STARTED && !isVisibleToUser;
940    }
941
942    /**
943     * @return The current value of the user-visible hint on this fragment.
944     * @see #setUserVisibleHint(boolean)
945     */
946    public boolean getUserVisibleHint() {
947        return mUserVisibleHint;
948    }
949
950    /**
951     * Return the LoaderManager for this fragment, creating it if needed.
952     */
953    public LoaderManager getLoaderManager() {
954        if (mLoaderManager != null) {
955            return mLoaderManager;
956        }
957        if (mHost == null) {
958            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
959        }
960        mCheckedForLoaderManager = true;
961        mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, true);
962        return mLoaderManager;
963    }
964
965    /**
966     * Call {@link Activity#startActivity(Intent)} from the fragment's
967     * containing Activity.
968     */
969    public void startActivity(Intent intent) {
970        startActivity(intent, null);
971    }
972
973    /**
974     * Call {@link Activity#startActivity(Intent, Bundle)} from the fragment's
975     * containing Activity.
976     */
977    public void startActivity(Intent intent, @Nullable Bundle options) {
978        if (mHost == null) {
979            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
980        }
981        mHost.onStartActivityFromFragment(this /*fragment*/, intent, -1, options);
982    }
983
984    /**
985     * Call {@link Activity#startActivityForResult(Intent, int)} from the fragment's
986     * containing Activity.
987     */
988    public void startActivityForResult(Intent intent, int requestCode) {
989        startActivityForResult(intent, requestCode, null);
990    }
991
992    /**
993     * Call {@link Activity#startActivityForResult(Intent, int, Bundle)} from the fragment's
994     * containing Activity.
995     */
996    public void startActivityForResult(Intent intent, int requestCode, @Nullable Bundle options) {
997        if (mHost == null) {
998            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
999        }
1000        mHost.onStartActivityFromFragment(this /*fragment*/, intent, requestCode, options);
1001    }
1002
1003    /**
1004     * Call {@link Activity#startIntentSenderForResult(IntentSender, int, Intent, int, int, int,
1005     * Bundle)} from the fragment's containing Activity.
1006     */
1007    public void startIntentSenderForResult(IntentSender intent, int requestCode,
1008            @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
1009            Bundle options) throws IntentSender.SendIntentException {
1010        if (mHost == null) {
1011            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
1012        }
1013        mHost.onStartIntentSenderFromFragment(this, intent, requestCode, fillInIntent, flagsMask,
1014                flagsValues, extraFlags, options);
1015    }
1016
1017    /**
1018     * Receive the result from a previous call to
1019     * {@link #startActivityForResult(Intent, int)}.  This follows the
1020     * related Activity API as described there in
1021     * {@link Activity#onActivityResult(int, int, Intent)}.
1022     *
1023     * @param requestCode The integer request code originally supplied to
1024     *                    startActivityForResult(), allowing you to identify who this
1025     *                    result came from.
1026     * @param resultCode The integer result code returned by the child activity
1027     *                   through its setResult().
1028     * @param data An Intent, which can return result data to the caller
1029     *               (various data can be attached to Intent "extras").
1030     */
1031    public void onActivityResult(int requestCode, int resultCode, Intent data) {
1032    }
1033
1034    /**
1035     * Requests permissions to be granted to this application. These permissions
1036     * must be requested in your manifest, they should not be granted to your app,
1037     * and they should have protection level {@link android.content.pm.PermissionInfo
1038     * #PROTECTION_DANGEROUS dangerous}, regardless whether they are declared by
1039     * the platform or a third-party app.
1040     * <p>
1041     * Normal permissions {@link android.content.pm.PermissionInfo#PROTECTION_NORMAL}
1042     * are granted at install time if requested in the manifest. Signature permissions
1043     * {@link android.content.pm.PermissionInfo#PROTECTION_SIGNATURE} are granted at
1044     * install time if requested in the manifest and the signature of your app matches
1045     * the signature of the app declaring the permissions.
1046     * </p>
1047     * <p>
1048     * If your app does not have the requested permissions the user will be presented
1049     * with UI for accepting them. After the user has accepted or rejected the
1050     * requested permissions you will receive a callback on {@link
1051     * #onRequestPermissionsResult(int, String[], int[])} reporting whether the
1052     * permissions were granted or not.
1053     * </p>
1054     * <p>
1055     * Note that requesting a permission does not guarantee it will be granted and
1056     * your app should be able to run without having this permission.
1057     * </p>
1058     * <p>
1059     * This method may start an activity allowing the user to choose which permissions
1060     * to grant and which to reject. Hence, you should be prepared that your activity
1061     * may be paused and resumed. Further, granting some permissions may require
1062     * a restart of you application. In such a case, the system will recreate the
1063     * activity stack before delivering the result to {@link
1064     * #onRequestPermissionsResult(int, String[], int[])}.
1065     * </p>
1066     * <p>
1067     * When checking whether you have a permission you should use {@link
1068     * android.content.Context#checkSelfPermission(String)}.
1069     * </p>
1070     * <p>
1071     * Calling this API for permissions already granted to your app would show UI
1072     * to the user to decided whether the app can still hold these permissions. This
1073     * can be useful if the way your app uses the data guarded by the permissions
1074     * changes significantly.
1075     * </p>
1076     * <p>
1077     * A sample permissions request looks like this:
1078     * </p>
1079     * <code><pre><p>
1080     * private void showContacts() {
1081     *     if (getActivity().checkSelfPermission(Manifest.permission.READ_CONTACTS)
1082     *             != PackageManager.PERMISSION_GRANTED) {
1083     *         requestPermissions(new String[]{Manifest.permission.READ_CONTACTS},
1084     *                 PERMISSIONS_REQUEST_READ_CONTACTS);
1085     *     } else {
1086     *         doShowContacts();
1087     *     }
1088     * }
1089     *
1090     * {@literal @}Override
1091     * public void onRequestPermissionsResult(int requestCode, String[] permissions,
1092     *         int[] grantResults) {
1093     *     if (requestCode == PERMISSIONS_REQUEST_READ_CONTACTS
1094     *             && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
1095     *         doShowContacts();
1096     *     }
1097     * }
1098     * </code></pre></p>
1099     *
1100     * @param permissions The requested permissions.
1101     * @param requestCode Application specific request code to match with a result
1102     *    reported to {@link #onRequestPermissionsResult(int, String[], int[])}.
1103     *
1104     * @see #onRequestPermissionsResult(int, String[], int[])
1105     * @see android.content.Context#checkSelfPermission(String)
1106     */
1107    public final void requestPermissions(@NonNull String[] permissions, int requestCode) {
1108        if (mHost == null) {
1109            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
1110        }
1111        mHost.onRequestPermissionsFromFragment(this, permissions, requestCode);
1112    }
1113
1114    /**
1115     * Callback for the result from requesting permissions. This method
1116     * is invoked for every call on {@link #requestPermissions(String[], int)}.
1117     * <p>
1118     * <strong>Note:</strong> It is possible that the permissions request interaction
1119     * with the user is interrupted. In this case you will receive empty permissions
1120     * and results arrays which should be treated as a cancellation.
1121     * </p>
1122     *
1123     * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}.
1124     * @param permissions The requested permissions. Never null.
1125     * @param grantResults The grant results for the corresponding permissions
1126     *     which is either {@link android.content.pm.PackageManager#PERMISSION_GRANTED}
1127     *     or {@link android.content.pm.PackageManager#PERMISSION_DENIED}. Never null.
1128     *
1129     * @see #requestPermissions(String[], int)
1130     */
1131    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
1132            @NonNull int[] grantResults) {
1133        /* callback - do nothing */
1134    }
1135
1136    /**
1137     * Gets whether you should show UI with rationale for requesting a permission.
1138     * You should do this only if you do not have the permission and the context in
1139     * which the permission is requested does not clearly communicate to the user
1140     * what would be the benefit from granting this permission.
1141     * <p>
1142     * For example, if you write a camera app, requesting the camera permission
1143     * would be expected by the user and no rationale for why it is requested is
1144     * needed. If however, the app needs location for tagging photos then a non-tech
1145     * savvy user may wonder how location is related to taking photos. In this case
1146     * you may choose to show UI with rationale of requesting this permission.
1147     * </p>
1148     *
1149     * @param permission A permission your app wants to request.
1150     * @return Whether you can show permission rationale UI.
1151     *
1152     * @see Context#checkSelfPermission(String)
1153     * @see #requestPermissions(String[], int)
1154     * @see #onRequestPermissionsResult(int, String[], int[])
1155     */
1156    public boolean shouldShowRequestPermissionRationale(@NonNull String permission) {
1157        if (mHost != null) {
1158            return mHost.onShouldShowRequestPermissionRationale(permission);
1159        }
1160        return false;
1161    }
1162
1163    /**
1164     * Returns the LayoutInflater used to inflate Views of this Fragment. The default
1165     * implementation will throw an exception if the Fragment is not attached.
1166     *
1167     * @param savedInstanceState If the fragment is being re-created from
1168     * a previous saved state, this is the state.
1169     * @return The LayoutInflater used to inflate Views of this Fragment.
1170     */
1171    public LayoutInflater getLayoutInflater(Bundle savedInstanceState) {
1172        if (mHost == null) {
1173            throw new IllegalStateException("getLayoutInflater() cannot be executed until the "
1174                    + "Fragment is attached to the FragmentManager.");
1175        }
1176        LayoutInflater result = mHost.onGetLayoutInflater();
1177        getChildFragmentManager(); // Init if needed; use raw implementation below.
1178        LayoutInflaterCompat.setFactory2(result, mChildFragmentManager.getLayoutInflaterFactory());
1179        return result;
1180    }
1181
1182    /**
1183     * Called when a fragment is being created as part of a view layout
1184     * inflation, typically from setting the content view of an activity.  This
1185     * may be called immediately after the fragment is created from a <fragment>
1186     * tag in a layout file.  Note this is <em>before</em> the fragment's
1187     * {@link #onAttach(Activity)} has been called; all you should do here is
1188     * parse the attributes and save them away.
1189     *
1190     * <p>This is called every time the fragment is inflated, even if it is
1191     * being inflated into a new instance with saved state.  It typically makes
1192     * sense to re-parse the parameters each time, to allow them to change with
1193     * different configurations.</p>
1194     *
1195     * <p>Here is a typical implementation of a fragment that can take parameters
1196     * both through attributes supplied here as well from {@link #getArguments()}:</p>
1197     *
1198     * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentArgumentsSupport.java
1199     *      fragment}
1200     *
1201     * <p>Note that parsing the XML attributes uses a "styleable" resource.  The
1202     * declaration for the styleable used here is:</p>
1203     *
1204     * {@sample frameworks/support/samples/Support4Demos/res/values/attrs.xml fragment_arguments}
1205     *
1206     * <p>The fragment can then be declared within its activity's content layout
1207     * through a tag like this:</p>
1208     *
1209     * {@sample frameworks/support/samples/Support4Demos/res/layout/fragment_arguments_support.xml from_attributes}
1210     *
1211     * <p>This fragment can also be created dynamically from arguments given
1212     * at runtime in the arguments Bundle; here is an example of doing so at
1213     * creation of the containing activity:</p>
1214     *
1215     * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentArgumentsSupport.java
1216     *      create}
1217     *
1218     * @param context The Activity that is inflating this fragment.
1219     * @param attrs The attributes at the tag where the fragment is
1220     * being created.
1221     * @param savedInstanceState If the fragment is being re-created from
1222     * a previous saved state, this is the state.
1223     */
1224    @CallSuper
1225    public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) {
1226        mCalled = true;
1227        final Activity hostActivity = mHost == null ? null : mHost.getActivity();
1228        if (hostActivity != null) {
1229            mCalled = false;
1230            onInflate(hostActivity, attrs, savedInstanceState);
1231        }
1232    }
1233
1234    /**
1235     * Called when a fragment is being created as part of a view layout
1236     * inflation, typically from setting the content view of an activity.
1237     *
1238     * @deprecated See {@link #onInflate(Context, AttributeSet, Bundle)}.
1239     */
1240    @Deprecated
1241    @CallSuper
1242    public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
1243        mCalled = true;
1244    }
1245
1246    /**
1247     * Called when a fragment is attached as a child of this fragment.
1248     *
1249     * <p>This is called after the attached fragment's <code>onAttach</code> and before
1250     * the attached fragment's <code>onCreate</code> if the fragment has not yet had a previous
1251     * call to <code>onCreate</code>.</p>
1252     *
1253     * @param childFragment child fragment being attached
1254     */
1255    public void onAttachFragment(Fragment childFragment) {
1256    }
1257
1258    /**
1259     * Called when a fragment is first attached to its context.
1260     * {@link #onCreate(Bundle)} will be called after this.
1261     */
1262    @CallSuper
1263    public void onAttach(Context context) {
1264        mCalled = true;
1265        final Activity hostActivity = mHost == null ? null : mHost.getActivity();
1266        if (hostActivity != null) {
1267            mCalled = false;
1268            onAttach(hostActivity);
1269        }
1270    }
1271
1272    /**
1273     * Called when a fragment is first attached to its activity.
1274     * {@link #onCreate(Bundle)} will be called after this.
1275     *
1276     * @deprecated See {@link #onAttach(Context)}.
1277     */
1278    @Deprecated
1279    @CallSuper
1280    public void onAttach(Activity activity) {
1281        mCalled = true;
1282    }
1283
1284    /**
1285     * Called when a fragment loads an animation.
1286     */
1287    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
1288        return null;
1289    }
1290
1291    /**
1292     * Called to do initial creation of a fragment.  This is called after
1293     * {@link #onAttach(Activity)} and before
1294     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
1295     *
1296     * <p>Note that this can be called while the fragment's activity is
1297     * still in the process of being created.  As such, you can not rely
1298     * on things like the activity's content view hierarchy being initialized
1299     * at this point.  If you want to do work once the activity itself is
1300     * created, see {@link #onActivityCreated(Bundle)}.
1301     *
1302     * <p>Any restored child fragments will be created before the base
1303     * <code>Fragment.onCreate</code> method returns.</p>
1304     *
1305     * @param savedInstanceState If the fragment is being re-created from
1306     * a previous saved state, this is the state.
1307     */
1308    @CallSuper
1309    public void onCreate(@Nullable Bundle savedInstanceState) {
1310        mCalled = true;
1311        restoreChildFragmentState(savedInstanceState);
1312        if (mChildFragmentManager != null
1313                && !mChildFragmentManager.isStateAtLeast(Fragment.CREATED)) {
1314            mChildFragmentManager.dispatchCreate();
1315        }
1316    }
1317
1318    /**
1319     * Restore the state of the child FragmentManager. Called by either
1320     * {@link #onCreate(Bundle)} for non-retained instance fragments or by
1321     * {@link FragmentManagerImpl#moveToState(Fragment, int, int, int, boolean)}
1322     * for retained instance fragments.
1323     *
1324     * <p><strong>Postcondition:</strong> if there were child fragments to restore,
1325     * the child FragmentManager will be instantiated and brought to the {@link #CREATED} state.
1326     * </p>
1327     *
1328     * @param savedInstanceState the savedInstanceState potentially containing fragment info
1329     */
1330    void restoreChildFragmentState(@Nullable Bundle savedInstanceState) {
1331        if (savedInstanceState != null) {
1332            Parcelable p = savedInstanceState.getParcelable(
1333                    FragmentActivity.FRAGMENTS_TAG);
1334            if (p != null) {
1335                if (mChildFragmentManager == null) {
1336                    instantiateChildFragmentManager();
1337                }
1338                mChildFragmentManager.restoreAllState(p, mChildNonConfig);
1339                mChildNonConfig = null;
1340                mChildFragmentManager.dispatchCreate();
1341            }
1342        }
1343    }
1344
1345    /**
1346     * Called to have the fragment instantiate its user interface view.
1347     * This is optional, and non-graphical fragments can return null (which
1348     * is the default implementation).  This will be called between
1349     * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}.
1350     *
1351     * <p>If you return a View from here, you will later be called in
1352     * {@link #onDestroyView} when the view is being released.
1353     *
1354     * @param inflater The LayoutInflater object that can be used to inflate
1355     * any views in the fragment,
1356     * @param container If non-null, this is the parent view that the fragment's
1357     * UI should be attached to.  The fragment should not add the view itself,
1358     * but this can be used to generate the LayoutParams of the view.
1359     * @param savedInstanceState If non-null, this fragment is being re-constructed
1360     * from a previous saved state as given here.
1361     *
1362     * @return Return the View for the fragment's UI, or null.
1363     */
1364    @Nullable
1365    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
1366            @Nullable Bundle savedInstanceState) {
1367        return null;
1368    }
1369
1370    /**
1371     * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
1372     * has returned, but before any saved state has been restored in to the view.
1373     * This gives subclasses a chance to initialize themselves once
1374     * they know their view hierarchy has been completely created.  The fragment's
1375     * view hierarchy is not however attached to its parent at this point.
1376     * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
1377     * @param savedInstanceState If non-null, this fragment is being re-constructed
1378     * from a previous saved state as given here.
1379     */
1380    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
1381    }
1382
1383    /**
1384     * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}),
1385     * if provided.
1386     *
1387     * @return The fragment's root view, or null if it has no layout.
1388     */
1389    @Nullable
1390    public View getView() {
1391        return mView;
1392    }
1393
1394    /**
1395     * Called when the fragment's activity has been created and this
1396     * fragment's view hierarchy instantiated.  It can be used to do final
1397     * initialization once these pieces are in place, such as retrieving
1398     * views or restoring state.  It is also useful for fragments that use
1399     * {@link #setRetainInstance(boolean)} to retain their instance,
1400     * as this callback tells the fragment when it is fully associated with
1401     * the new activity instance.  This is called after {@link #onCreateView}
1402     * and before {@link #onViewStateRestored(Bundle)}.
1403     *
1404     * @param savedInstanceState If the fragment is being re-created from
1405     * a previous saved state, this is the state.
1406     */
1407    @CallSuper
1408    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
1409        mCalled = true;
1410    }
1411
1412    /**
1413     * Called when all saved state has been restored into the view hierarchy
1414     * of the fragment.  This can be used to do initialization based on saved
1415     * state that you are letting the view hierarchy track itself, such as
1416     * whether check box widgets are currently checked.  This is called
1417     * after {@link #onActivityCreated(Bundle)} and before
1418     * {@link #onStart()}.
1419     *
1420     * @param savedInstanceState If the fragment is being re-created from
1421     * a previous saved state, this is the state.
1422     */
1423    @CallSuper
1424    public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
1425        mCalled = true;
1426    }
1427
1428    /**
1429     * Called when the Fragment is visible to the user.  This is generally
1430     * tied to {@link Activity#onStart() Activity.onStart} of the containing
1431     * Activity's lifecycle.
1432     */
1433    @CallSuper
1434    public void onStart() {
1435        mCalled = true;
1436
1437        if (!mLoadersStarted) {
1438            mLoadersStarted = true;
1439            if (!mCheckedForLoaderManager) {
1440                mCheckedForLoaderManager = true;
1441                mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false);
1442            }
1443            if (mLoaderManager != null) {
1444                mLoaderManager.doStart();
1445            }
1446        }
1447    }
1448
1449    /**
1450     * Called when the fragment is visible to the user and actively running.
1451     * This is generally
1452     * tied to {@link Activity#onResume() Activity.onResume} of the containing
1453     * Activity's lifecycle.
1454     */
1455    @CallSuper
1456    public void onResume() {
1457        mCalled = true;
1458    }
1459
1460    /**
1461     * Called to ask the fragment to save its current dynamic state, so it
1462     * can later be reconstructed in a new instance of its process is
1463     * restarted.  If a new instance of the fragment later needs to be
1464     * created, the data you place in the Bundle here will be available
1465     * in the Bundle given to {@link #onCreate(Bundle)},
1466     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}, and
1467     * {@link #onActivityCreated(Bundle)}.
1468     *
1469     * <p>This corresponds to {@link Activity#onSaveInstanceState(Bundle)
1470     * Activity.onSaveInstanceState(Bundle)} and most of the discussion there
1471     * applies here as well.  Note however: <em>this method may be called
1472     * at any time before {@link #onDestroy()}</em>.  There are many situations
1473     * where a fragment may be mostly torn down (such as when placed on the
1474     * back stack with no UI showing), but its state will not be saved until
1475     * its owning activity actually needs to save its state.
1476     *
1477     * @param outState Bundle in which to place your saved state.
1478     */
1479    public void onSaveInstanceState(Bundle outState) {
1480    }
1481
1482    /**
1483     * Called when the Fragment's activity changes from fullscreen mode to multi-window mode and
1484     * visa-versa. This is generally tied to {@link Activity#onMultiWindowModeChanged} of the
1485     * containing Activity.
1486     *
1487     * @param isInMultiWindowMode True if the activity is in multi-window mode.
1488     */
1489    public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
1490    }
1491
1492    /**
1493     * Called by the system when the activity changes to and from picture-in-picture mode. This is
1494     * generally tied to {@link Activity#onPictureInPictureModeChanged} of the containing Activity.
1495     *
1496     * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode.
1497     */
1498    public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
1499    }
1500
1501    @Override
1502    @CallSuper
1503    public void onConfigurationChanged(Configuration newConfig) {
1504        mCalled = true;
1505    }
1506
1507    /**
1508     * Called when the Fragment is no longer resumed.  This is generally
1509     * tied to {@link Activity#onPause() Activity.onPause} of the containing
1510     * Activity's lifecycle.
1511     */
1512    @CallSuper
1513    public void onPause() {
1514        mCalled = true;
1515    }
1516
1517    /**
1518     * Called when the Fragment is no longer started.  This is generally
1519     * tied to {@link Activity#onStop() Activity.onStop} of the containing
1520     * Activity's lifecycle.
1521     */
1522    @CallSuper
1523    public void onStop() {
1524        mCalled = true;
1525    }
1526
1527    @Override
1528    @CallSuper
1529    public void onLowMemory() {
1530        mCalled = true;
1531    }
1532
1533    /**
1534     * Called when the view previously created by {@link #onCreateView} has
1535     * been detached from the fragment.  The next time the fragment needs
1536     * to be displayed, a new view will be created.  This is called
1537     * after {@link #onStop()} and before {@link #onDestroy()}.  It is called
1538     * <em>regardless</em> of whether {@link #onCreateView} returned a
1539     * non-null view.  Internally it is called after the view's state has
1540     * been saved but before it has been removed from its parent.
1541     */
1542    @CallSuper
1543    public void onDestroyView() {
1544        mCalled = true;
1545    }
1546
1547    /**
1548     * Called when the fragment is no longer in use.  This is called
1549     * after {@link #onStop()} and before {@link #onDetach()}.
1550     */
1551    @CallSuper
1552    public void onDestroy() {
1553        mCalled = true;
1554        //Log.v("foo", "onDestroy: mCheckedForLoaderManager=" + mCheckedForLoaderManager
1555        //        + " mLoaderManager=" + mLoaderManager);
1556        if (!mCheckedForLoaderManager) {
1557            mCheckedForLoaderManager = true;
1558            mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false);
1559        }
1560        if (mLoaderManager != null) {
1561            mLoaderManager.doDestroy();
1562        }
1563    }
1564
1565    /**
1566     * Called by the fragment manager once this fragment has been removed,
1567     * so that we don't have any left-over state if the application decides
1568     * to re-use the instance.  This only clears state that the framework
1569     * internally manages, not things the application sets.
1570     */
1571    void initState() {
1572        mIndex = -1;
1573        mWho = null;
1574        mAdded = false;
1575        mRemoving = false;
1576        mFromLayout = false;
1577        mInLayout = false;
1578        mRestored = false;
1579        mBackStackNesting = 0;
1580        mFragmentManager = null;
1581        mChildFragmentManager = null;
1582        mHost = null;
1583        mFragmentId = 0;
1584        mContainerId = 0;
1585        mTag = null;
1586        mHidden = false;
1587        mDetached = false;
1588        mRetaining = false;
1589        mLoaderManager = null;
1590        mLoadersStarted = false;
1591        mCheckedForLoaderManager = false;
1592    }
1593
1594    /**
1595     * Called when the fragment is no longer attached to its activity.  This
1596     * is called after {@link #onDestroy()}.
1597     */
1598    @CallSuper
1599    public void onDetach() {
1600        mCalled = true;
1601    }
1602
1603    /**
1604     * Initialize the contents of the Fragment host's standard options menu.  You
1605     * should place your menu items in to <var>menu</var>.  For this method
1606     * to be called, you must have first called {@link #setHasOptionsMenu}.  See
1607     * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu}
1608     * for more information.
1609     *
1610     * @param menu The options menu in which you place your items.
1611     *
1612     * @see #setHasOptionsMenu
1613     * @see #onPrepareOptionsMenu
1614     * @see #onOptionsItemSelected
1615     */
1616    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
1617    }
1618
1619    /**
1620     * Prepare the Fragment host's standard options menu to be displayed.  This is
1621     * called right before the menu is shown, every time it is shown.  You can
1622     * use this method to efficiently enable/disable items or otherwise
1623     * dynamically modify the contents.  See
1624     * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu}
1625     * for more information.
1626     *
1627     * @param menu The options menu as last shown or first initialized by
1628     *             onCreateOptionsMenu().
1629     *
1630     * @see #setHasOptionsMenu
1631     * @see #onCreateOptionsMenu
1632     */
1633    public void onPrepareOptionsMenu(Menu menu) {
1634    }
1635
1636    /**
1637     * Called when this fragment's option menu items are no longer being
1638     * included in the overall options menu.  Receiving this call means that
1639     * the menu needed to be rebuilt, but this fragment's items were not
1640     * included in the newly built menu (its {@link #onCreateOptionsMenu(Menu, MenuInflater)}
1641     * was not called).
1642     */
1643    public void onDestroyOptionsMenu() {
1644    }
1645
1646    /**
1647     * This hook is called whenever an item in your options menu is selected.
1648     * The default implementation simply returns false to have the normal
1649     * processing happen (calling the item's Runnable or sending a message to
1650     * its Handler as appropriate).  You can use this method for any items
1651     * for which you would like to do processing without those other
1652     * facilities.
1653     *
1654     * <p>Derived classes should call through to the base class for it to
1655     * perform the default menu handling.
1656     *
1657     * @param item The menu item that was selected.
1658     *
1659     * @return boolean Return false to allow normal menu processing to
1660     *         proceed, true to consume it here.
1661     *
1662     * @see #onCreateOptionsMenu
1663     */
1664    public boolean onOptionsItemSelected(MenuItem item) {
1665        return false;
1666    }
1667
1668    /**
1669     * This hook is called whenever the options menu is being closed (either by the user canceling
1670     * the menu with the back/menu button, or when an item is selected).
1671     *
1672     * @param menu The options menu as last shown or first initialized by
1673     *             onCreateOptionsMenu().
1674     */
1675    public void onOptionsMenuClosed(Menu menu) {
1676    }
1677
1678    /**
1679     * Called when a context menu for the {@code view} is about to be shown.
1680     * Unlike {@link #onCreateOptionsMenu}, this will be called every
1681     * time the context menu is about to be shown and should be populated for
1682     * the view (or item inside the view for {@link AdapterView} subclasses,
1683     * this can be found in the {@code menuInfo})).
1684     * <p>
1685     * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an
1686     * item has been selected.
1687     * <p>
1688     * The default implementation calls up to
1689     * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though
1690     * you can not call this implementation if you don't want that behavior.
1691     * <p>
1692     * It is not safe to hold onto the context menu after this method returns.
1693     * {@inheritDoc}
1694     */
1695    @Override
1696    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
1697        getActivity().onCreateContextMenu(menu, v, menuInfo);
1698    }
1699
1700    /**
1701     * Registers a context menu to be shown for the given view (multiple views
1702     * can show the context menu). This method will set the
1703     * {@link OnCreateContextMenuListener} on the view to this fragment, so
1704     * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be
1705     * called when it is time to show the context menu.
1706     *
1707     * @see #unregisterForContextMenu(View)
1708     * @param view The view that should show a context menu.
1709     */
1710    public void registerForContextMenu(View view) {
1711        view.setOnCreateContextMenuListener(this);
1712    }
1713
1714    /**
1715     * Prevents a context menu to be shown for the given view. This method will
1716     * remove the {@link OnCreateContextMenuListener} on the view.
1717     *
1718     * @see #registerForContextMenu(View)
1719     * @param view The view that should stop showing a context menu.
1720     */
1721    public void unregisterForContextMenu(View view) {
1722        view.setOnCreateContextMenuListener(null);
1723    }
1724
1725    /**
1726     * This hook is called whenever an item in a context menu is selected. The
1727     * default implementation simply returns false to have the normal processing
1728     * happen (calling the item's Runnable or sending a message to its Handler
1729     * as appropriate). You can use this method for any items for which you
1730     * would like to do processing without those other facilities.
1731     * <p>
1732     * Use {@link MenuItem#getMenuInfo()} to get extra information set by the
1733     * View that added this menu item.
1734     * <p>
1735     * Derived classes should call through to the base class for it to perform
1736     * the default menu handling.
1737     *
1738     * @param item The context menu item that was selected.
1739     * @return boolean Return false to allow normal context menu processing to
1740     *         proceed, true to consume it here.
1741     */
1742    public boolean onContextItemSelected(MenuItem item) {
1743        return false;
1744    }
1745
1746    /**
1747     * When custom transitions are used with Fragments, the enter transition callback
1748     * is called when this Fragment is attached or detached when not popping the back stack.
1749     *
1750     * @param callback Used to manipulate the shared element transitions on this Fragment
1751     *                 when added not as a pop from the back stack.
1752     */
1753    public void setEnterSharedElementCallback(SharedElementCallback callback) {
1754        ensureAnimationInfo().mEnterTransitionCallback = callback;
1755    }
1756
1757    /**
1758     * When custom transitions are used with Fragments, the exit transition callback
1759     * is called when this Fragment is attached or detached when popping the back stack.
1760     *
1761     * @param callback Used to manipulate the shared element transitions on this Fragment
1762     *                 when added as a pop from the back stack.
1763     */
1764    public void setExitSharedElementCallback(SharedElementCallback callback) {
1765        ensureAnimationInfo().mExitTransitionCallback = callback;
1766    }
1767
1768    /**
1769     * Sets the Transition that will be used to move Views into the initial scene. The entering
1770     * Views will be those that are regular Views or ViewGroups that have
1771     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1772     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1773     * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
1774     * entering Views will remain unaffected.
1775     *
1776     * @param transition The Transition to use to move Views into the initial Scene.
1777     */
1778    public void setEnterTransition(Object transition) {
1779        ensureAnimationInfo().mEnterTransition = transition;
1780    }
1781
1782    /**
1783     * Returns the Transition that will be used to move Views into the initial scene. The entering
1784     * Views will be those that are regular Views or ViewGroups that have
1785     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1786     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1787     * {@link View#INVISIBLE} to {@link View#VISIBLE}.
1788     *
1789     * @return the Transition to use to move Views into the initial Scene.
1790     */
1791    public Object getEnterTransition() {
1792        if (mAnimationInfo == null) {
1793            return null;
1794        }
1795        return mAnimationInfo.mEnterTransition;
1796    }
1797
1798    /**
1799     * Sets the Transition that will be used to move Views out of the scene when the Fragment is
1800     * preparing to be removed, hidden, or detached because of popping the back stack. The exiting
1801     * Views will be those that are regular Views or ViewGroups that have
1802     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1803     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1804     * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
1805     * entering Views will remain unaffected. If nothing is set, the default will be to
1806     * use the same value as set in {@link #setEnterTransition(Object)}.
1807     *
1808     * @param transition The Transition to use to move Views out of the Scene when the Fragment
1809     *                   is preparing to close. <code>transition</code> must be an
1810     *                   android.transition.Transition.
1811     */
1812    public void setReturnTransition(Object transition) {
1813        ensureAnimationInfo().mReturnTransition = transition;
1814    }
1815
1816    /**
1817     * Returns the Transition that will be used to move Views out of the scene when the Fragment is
1818     * preparing to be removed, hidden, or detached because of popping the back stack. The exiting
1819     * Views will be those that are regular Views or ViewGroups that have
1820     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1821     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1822     * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
1823     * entering Views will remain unaffected.
1824     *
1825     * @return the Transition to use to move Views out of the Scene when the Fragment
1826     *         is preparing to close.
1827     */
1828    public Object getReturnTransition() {
1829        if (mAnimationInfo == null) {
1830            return null;
1831        }
1832        return mAnimationInfo.mReturnTransition == USE_DEFAULT_TRANSITION ? getEnterTransition()
1833                : mAnimationInfo.mReturnTransition;
1834    }
1835
1836    /**
1837     * Sets the Transition that will be used to move Views out of the scene when the
1838     * fragment is removed, hidden, or detached when not popping the back stack.
1839     * The exiting Views will be those that are regular Views or ViewGroups that
1840     * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1841     * {@link android.transition.Visibility} as exiting is governed by changing visibility
1842     * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
1843     * remain unaffected.
1844     *
1845     * @param transition The Transition to use to move Views out of the Scene when the Fragment
1846     *                   is being closed not due to popping the back stack. <code>transition</code>
1847     *                   must be an android.transition.Transition.
1848     */
1849    public void setExitTransition(Object transition) {
1850        ensureAnimationInfo().mExitTransition = transition;
1851    }
1852
1853    /**
1854     * Returns the Transition that will be used to move Views out of the scene when the
1855     * fragment is removed, hidden, or detached when not popping the back stack.
1856     * The exiting Views will be those that are regular Views or ViewGroups that
1857     * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1858     * {@link android.transition.Visibility} as exiting is governed by changing visibility
1859     * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
1860     * remain unaffected.
1861     *
1862     * @return the Transition to use to move Views out of the Scene when the Fragment
1863     *         is being closed not due to popping the back stack.
1864     */
1865    public Object getExitTransition() {
1866        if (mAnimationInfo == null) {
1867            return null;
1868        }
1869        return mAnimationInfo.mExitTransition;
1870    }
1871
1872    /**
1873     * Sets the Transition that will be used to move Views in to the scene when returning due
1874     * to popping a back stack. The entering Views will be those that are regular Views
1875     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
1876     * will extend {@link android.transition.Visibility} as exiting is governed by changing
1877     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
1878     * the views will remain unaffected. If nothing is set, the default will be to use the same
1879     * transition as {@link #setExitTransition(Object)}.
1880     *
1881     * @param transition The Transition to use to move Views into the scene when reentering from a
1882     *                   previously-started Activity. <code>transition</code>
1883     *                   must be an android.transition.Transition.
1884     */
1885    public void setReenterTransition(Object transition) {
1886        ensureAnimationInfo().mReenterTransition = transition;
1887    }
1888
1889    /**
1890     * Returns the Transition that will be used to move Views in to the scene when returning due
1891     * to popping a back stack. The entering Views will be those that are regular Views
1892     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
1893     * will extend {@link android.transition.Visibility} as exiting is governed by changing
1894     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
1895     * the views will remain unaffected. If nothing is set, the default will be to use the same
1896     * transition as {@link #setExitTransition(Object)}.
1897     *
1898     * @return the Transition to use to move Views into the scene when reentering from a
1899     *                   previously-started Activity.
1900     */
1901    public Object getReenterTransition() {
1902        if (mAnimationInfo == null) {
1903            return null;
1904        }
1905        return mAnimationInfo.mReenterTransition == USE_DEFAULT_TRANSITION ? getExitTransition()
1906                : mAnimationInfo.mReenterTransition;
1907    }
1908
1909    /**
1910     * Sets the Transition that will be used for shared elements transferred into the content
1911     * Scene. Typical Transitions will affect size and location, such as
1912     * {@link android.transition.ChangeBounds}. A null
1913     * value will cause transferred shared elements to blink to the final position.
1914     *
1915     * @param transition The Transition to use for shared elements transferred into the content
1916     *                   Scene.  <code>transition</code> must be an android.transition.Transition.
1917     */
1918    public void setSharedElementEnterTransition(Object transition) {
1919        ensureAnimationInfo().mSharedElementEnterTransition = transition;
1920    }
1921
1922    /**
1923     * Returns the Transition that will be used for shared elements transferred into the content
1924     * Scene. Typical Transitions will affect size and location, such as
1925     * {@link android.transition.ChangeBounds}. A null
1926     * value will cause transferred shared elements to blink to the final position.
1927     *
1928     * @return The Transition to use for shared elements transferred into the content
1929     *                   Scene.
1930     */
1931    public Object getSharedElementEnterTransition() {
1932        if (mAnimationInfo == null) {
1933            return null;
1934        }
1935        return mAnimationInfo.mSharedElementEnterTransition;
1936    }
1937
1938    /**
1939     * Sets the Transition that will be used for shared elements transferred back during a
1940     * pop of the back stack. This Transition acts in the leaving Fragment.
1941     * Typical Transitions will affect size and location, such as
1942     * {@link android.transition.ChangeBounds}. A null
1943     * value will cause transferred shared elements to blink to the final position.
1944     * If no value is set, the default will be to use the same value as
1945     * {@link #setSharedElementEnterTransition(Object)}.
1946     *
1947     * @param transition The Transition to use for shared elements transferred out of the content
1948     *                   Scene. <code>transition</code> must be an android.transition.Transition.
1949     */
1950    public void setSharedElementReturnTransition(Object transition) {
1951        ensureAnimationInfo().mSharedElementReturnTransition = transition;
1952    }
1953
1954    /**
1955     * Return the Transition that will be used for shared elements transferred back during a
1956     * pop of the back stack. This Transition acts in the leaving Fragment.
1957     * Typical Transitions will affect size and location, such as
1958     * {@link android.transition.ChangeBounds}. A null
1959     * value will cause transferred shared elements to blink to the final position.
1960     * If no value is set, the default will be to use the same value as
1961     * {@link #setSharedElementEnterTransition(Object)}.
1962     *
1963     * @return The Transition to use for shared elements transferred out of the content
1964     *                   Scene.
1965     */
1966    public Object getSharedElementReturnTransition() {
1967        if (mAnimationInfo == null) {
1968            return null;
1969        }
1970        return mAnimationInfo.mSharedElementReturnTransition == USE_DEFAULT_TRANSITION
1971                ? getSharedElementEnterTransition()
1972                : mAnimationInfo.mSharedElementReturnTransition;
1973    }
1974
1975    /**
1976     * Sets whether the the exit transition and enter transition overlap or not.
1977     * When true, the enter transition will start as soon as possible. When false, the
1978     * enter transition will wait until the exit transition completes before starting.
1979     *
1980     * @param allow true to start the enter transition when possible or false to
1981     *              wait until the exiting transition completes.
1982     */
1983    public void setAllowEnterTransitionOverlap(boolean allow) {
1984        ensureAnimationInfo().mAllowEnterTransitionOverlap = allow;
1985    }
1986
1987    /**
1988     * Returns whether the the exit transition and enter transition overlap or not.
1989     * When true, the enter transition will start as soon as possible. When false, the
1990     * enter transition will wait until the exit transition completes before starting.
1991     *
1992     * @return true when the enter transition should start as soon as possible or false to
1993     * when it should wait until the exiting transition completes.
1994     */
1995    public boolean getAllowEnterTransitionOverlap() {
1996        return (mAnimationInfo == null || mAnimationInfo.mAllowEnterTransitionOverlap == null)
1997                ? true : mAnimationInfo.mAllowEnterTransitionOverlap;
1998    }
1999
2000    /**
2001     * Sets whether the the return transition and reenter transition overlap or not.
2002     * When true, the reenter transition will start as soon as possible. When false, the
2003     * reenter transition will wait until the return transition completes before starting.
2004     *
2005     * @param allow true to start the reenter transition when possible or false to wait until the
2006     *              return transition completes.
2007     */
2008    public void setAllowReturnTransitionOverlap(boolean allow) {
2009        ensureAnimationInfo().mAllowReturnTransitionOverlap = allow;
2010    }
2011
2012    /**
2013     * Returns whether the the return transition and reenter transition overlap or not.
2014     * When true, the reenter transition will start as soon as possible. When false, the
2015     * reenter transition will wait until the return transition completes before starting.
2016     *
2017     * @return true to start the reenter transition when possible or false to wait until the
2018     *         return transition completes.
2019     */
2020    public boolean getAllowReturnTransitionOverlap() {
2021        return (mAnimationInfo == null || mAnimationInfo.mAllowReturnTransitionOverlap == null)
2022                ? true : mAnimationInfo.mAllowReturnTransitionOverlap;
2023    }
2024
2025    /**
2026     * Postpone the entering Fragment transition until {@link #startPostponedEnterTransition()}
2027     * or {@link FragmentManager#executePendingTransactions()} has been called.
2028     * <p>
2029     * This method gives the Fragment the ability to delay Fragment animations
2030     * until all data is loaded. Until then, the added, shown, and
2031     * attached Fragments will be INVISIBLE and removed, hidden, and detached Fragments won't
2032     * be have their Views removed. The transaction runs when all postponed added Fragments in the
2033     * transaction have called {@link #startPostponedEnterTransition()}.
2034     * <p>
2035     * This method should be called before being added to the FragmentTransaction or
2036     * in {@link #onCreate(Bundle), {@link #onAttach(Context)}, or
2037     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}}.
2038     * {@link #startPostponedEnterTransition()} must be called to allow the Fragment to
2039     * start the transitions.
2040     * <p>
2041     * When a FragmentTransaction is started that may affect a postponed FragmentTransaction,
2042     * based on which containers are in their operations, the postponed FragmentTransaction
2043     * will have its start triggered. The early triggering may result in faulty or nonexistent
2044     * animations in the postponed transaction. FragmentTransactions that operate only on
2045     * independent containers will not interfere with each other's postponement.
2046     * <p>
2047     * Calling postponeEnterTransition on Fragments with a null View will not postpone the
2048     * transition. Likewise, postponement only works if FragmentTransaction optimizations are
2049     * enabled.
2050     *
2051     * @see Activity#postponeEnterTransition()
2052     * @see FragmentTransaction#setAllowOptimization(boolean)
2053     */
2054    public void postponeEnterTransition() {
2055        ensureAnimationInfo().mEnterTransitionPostponed = true;
2056    }
2057
2058    /**
2059     * Begin postponed transitions after {@link #postponeEnterTransition()} was called.
2060     * If postponeEnterTransition() was called, you must call startPostponedEnterTransition()
2061     * or {@link FragmentManager#executePendingTransactions()} to complete the FragmentTransaction.
2062     * If postponement was interrupted with {@link FragmentManager#executePendingTransactions()},
2063     * before {@code startPostponedEnterTransition()}, animations may not run or may execute
2064     * improperly.
2065     *
2066     * @see Activity#startPostponedEnterTransition()
2067     */
2068    public void startPostponedEnterTransition() {
2069        if (mFragmentManager == null || mFragmentManager.mHost == null) {
2070            ensureAnimationInfo().mEnterTransitionPostponed = false;
2071        } else if (Looper.myLooper() != mFragmentManager.mHost.getHandler().getLooper()) {
2072            mFragmentManager.mHost.getHandler().postAtFrontOfQueue(new Runnable() {
2073                @Override
2074                public void run() {
2075                    callStartTransitionListener();
2076                }
2077            });
2078        } else {
2079            callStartTransitionListener();
2080        }
2081    }
2082
2083    /**
2084     * Calls the start transition listener. This must be called on the UI thread.
2085     */
2086    private void callStartTransitionListener() {
2087        final OnStartEnterTransitionListener listener;
2088        if (mAnimationInfo == null) {
2089            listener = null;
2090        } else {
2091            mAnimationInfo.mEnterTransitionPostponed = false;
2092            listener = mAnimationInfo.mStartEnterTransitionListener;
2093            mAnimationInfo.mStartEnterTransitionListener = null;
2094        }
2095        if (listener != null) {
2096            listener.onStartEnterTransition();
2097        }
2098    }
2099
2100    /**
2101     * Print the Fragments's state into the given stream.
2102     *
2103     * @param prefix Text to print at the front of each line.
2104     * @param fd The raw file descriptor that the dump is being sent to.
2105     * @param writer The PrintWriter to which you should dump your state.  This will be
2106     * closed for you after you return.
2107     * @param args additional arguments to the dump request.
2108     */
2109    public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
2110        writer.print(prefix); writer.print("mFragmentId=#");
2111                writer.print(Integer.toHexString(mFragmentId));
2112                writer.print(" mContainerId=#");
2113                writer.print(Integer.toHexString(mContainerId));
2114                writer.print(" mTag="); writer.println(mTag);
2115        writer.print(prefix); writer.print("mState="); writer.print(mState);
2116                writer.print(" mIndex="); writer.print(mIndex);
2117                writer.print(" mWho="); writer.print(mWho);
2118                writer.print(" mBackStackNesting="); writer.println(mBackStackNesting);
2119        writer.print(prefix); writer.print("mAdded="); writer.print(mAdded);
2120                writer.print(" mRemoving="); writer.print(mRemoving);
2121                writer.print(" mFromLayout="); writer.print(mFromLayout);
2122                writer.print(" mInLayout="); writer.println(mInLayout);
2123        writer.print(prefix); writer.print("mHidden="); writer.print(mHidden);
2124                writer.print(" mDetached="); writer.print(mDetached);
2125                writer.print(" mMenuVisible="); writer.print(mMenuVisible);
2126                writer.print(" mHasMenu="); writer.println(mHasMenu);
2127        writer.print(prefix); writer.print("mRetainInstance="); writer.print(mRetainInstance);
2128                writer.print(" mRetaining="); writer.print(mRetaining);
2129                writer.print(" mUserVisibleHint="); writer.println(mUserVisibleHint);
2130        if (mFragmentManager != null) {
2131            writer.print(prefix); writer.print("mFragmentManager=");
2132                    writer.println(mFragmentManager);
2133        }
2134        if (mHost != null) {
2135            writer.print(prefix); writer.print("mHost=");
2136                    writer.println(mHost);
2137        }
2138        if (mParentFragment != null) {
2139            writer.print(prefix); writer.print("mParentFragment=");
2140                    writer.println(mParentFragment);
2141        }
2142        if (mArguments != null) {
2143            writer.print(prefix); writer.print("mArguments="); writer.println(mArguments);
2144        }
2145        if (mSavedFragmentState != null) {
2146            writer.print(prefix); writer.print("mSavedFragmentState=");
2147                    writer.println(mSavedFragmentState);
2148        }
2149        if (mSavedViewState != null) {
2150            writer.print(prefix); writer.print("mSavedViewState=");
2151                    writer.println(mSavedViewState);
2152        }
2153        if (mTarget != null) {
2154            writer.print(prefix); writer.print("mTarget="); writer.print(mTarget);
2155                    writer.print(" mTargetRequestCode=");
2156                    writer.println(mTargetRequestCode);
2157        }
2158        if (getNextAnim() != 0) {
2159            writer.print(prefix); writer.print("mNextAnim="); writer.println(getNextAnim());
2160        }
2161        if (mContainer != null) {
2162            writer.print(prefix); writer.print("mContainer="); writer.println(mContainer);
2163        }
2164        if (mView != null) {
2165            writer.print(prefix); writer.print("mView="); writer.println(mView);
2166        }
2167        if (mInnerView != null) {
2168            writer.print(prefix); writer.print("mInnerView="); writer.println(mView);
2169        }
2170        if (getAnimatingAway() != null) {
2171            writer.print(prefix);
2172            writer.print("mAnimatingAway=");
2173            writer.println(getAnimatingAway());
2174            writer.print(prefix);
2175            writer.print("mStateAfterAnimating=");
2176            writer.println(getStateAfterAnimating());
2177        }
2178        if (mLoaderManager != null) {
2179            writer.print(prefix); writer.println("Loader Manager:");
2180            mLoaderManager.dump(prefix + "  ", fd, writer, args);
2181        }
2182        if (mChildFragmentManager != null) {
2183            writer.print(prefix); writer.println("Child " + mChildFragmentManager + ":");
2184            mChildFragmentManager.dump(prefix + "  ", fd, writer, args);
2185        }
2186    }
2187
2188    Fragment findFragmentByWho(String who) {
2189        if (who.equals(mWho)) {
2190            return this;
2191        }
2192        if (mChildFragmentManager != null) {
2193            return mChildFragmentManager.findFragmentByWho(who);
2194        }
2195        return null;
2196    }
2197
2198    void instantiateChildFragmentManager() {
2199        if (mHost == null) {
2200            throw new IllegalStateException("Fragment has not been attached yet.");
2201        }
2202        mChildFragmentManager = new FragmentManagerImpl();
2203        mChildFragmentManager.attachController(mHost, new FragmentContainer() {
2204            @Override
2205            @Nullable
2206            public View onFindViewById(int id) {
2207                if (mView == null) {
2208                    throw new IllegalStateException("Fragment does not have a view");
2209                }
2210                return mView.findViewById(id);
2211            }
2212
2213            @Override
2214            public boolean onHasView() {
2215                return (mView != null);
2216            }
2217
2218            @Override
2219            public Fragment instantiate(Context context, String className, Bundle arguments) {
2220                return mHost.instantiate(context, className, arguments);
2221            }
2222        }, this);
2223    }
2224
2225    void performCreate(Bundle savedInstanceState) {
2226        if (mChildFragmentManager != null) {
2227            mChildFragmentManager.noteStateNotSaved();
2228        }
2229        mState = CREATED;
2230        mCalled = false;
2231        onCreate(savedInstanceState);
2232        if (!mCalled) {
2233            throw new SuperNotCalledException("Fragment " + this
2234                    + " did not call through to super.onCreate()");
2235        }
2236    }
2237
2238    View performCreateView(LayoutInflater inflater, ViewGroup container,
2239            Bundle savedInstanceState) {
2240        if (mChildFragmentManager != null) {
2241            mChildFragmentManager.noteStateNotSaved();
2242        }
2243        mPerformedCreateView = true;
2244        return onCreateView(inflater, container, savedInstanceState);
2245    }
2246
2247    void performActivityCreated(Bundle savedInstanceState) {
2248        if (mChildFragmentManager != null) {
2249            mChildFragmentManager.noteStateNotSaved();
2250        }
2251        mState = ACTIVITY_CREATED;
2252        mCalled = false;
2253        onActivityCreated(savedInstanceState);
2254        if (!mCalled) {
2255            throw new SuperNotCalledException("Fragment " + this
2256                    + " did not call through to super.onActivityCreated()");
2257        }
2258        if (mChildFragmentManager != null) {
2259            mChildFragmentManager.dispatchActivityCreated();
2260        }
2261    }
2262
2263    void performStart() {
2264        if (mChildFragmentManager != null) {
2265            mChildFragmentManager.noteStateNotSaved();
2266            mChildFragmentManager.execPendingActions();
2267        }
2268        mState = STARTED;
2269        mCalled = false;
2270        onStart();
2271        if (!mCalled) {
2272            throw new SuperNotCalledException("Fragment " + this
2273                    + " did not call through to super.onStart()");
2274        }
2275        if (mChildFragmentManager != null) {
2276            mChildFragmentManager.dispatchStart();
2277        }
2278        if (mLoaderManager != null) {
2279            mLoaderManager.doReportStart();
2280        }
2281    }
2282
2283    void performResume() {
2284        if (mChildFragmentManager != null) {
2285            mChildFragmentManager.noteStateNotSaved();
2286            mChildFragmentManager.execPendingActions();
2287        }
2288        mState = RESUMED;
2289        mCalled = false;
2290        onResume();
2291        if (!mCalled) {
2292            throw new SuperNotCalledException("Fragment " + this
2293                    + " did not call through to super.onResume()");
2294        }
2295        if (mChildFragmentManager != null) {
2296            mChildFragmentManager.dispatchResume();
2297            mChildFragmentManager.execPendingActions();
2298        }
2299    }
2300
2301    void performMultiWindowModeChanged(boolean isInMultiWindowMode) {
2302        onMultiWindowModeChanged(isInMultiWindowMode);
2303        if (mChildFragmentManager != null) {
2304            mChildFragmentManager.dispatchMultiWindowModeChanged(isInMultiWindowMode);
2305        }
2306    }
2307
2308    void performPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
2309        onPictureInPictureModeChanged(isInPictureInPictureMode);
2310        if (mChildFragmentManager != null) {
2311            mChildFragmentManager.dispatchPictureInPictureModeChanged(isInPictureInPictureMode);
2312        }
2313    }
2314
2315    void performConfigurationChanged(Configuration newConfig) {
2316        onConfigurationChanged(newConfig);
2317        if (mChildFragmentManager != null) {
2318            mChildFragmentManager.dispatchConfigurationChanged(newConfig);
2319        }
2320    }
2321
2322    void performLowMemory() {
2323        onLowMemory();
2324        if (mChildFragmentManager != null) {
2325            mChildFragmentManager.dispatchLowMemory();
2326        }
2327    }
2328
2329    /*
2330    void performTrimMemory(int level) {
2331        onTrimMemory(level);
2332        if (mChildFragmentManager != null) {
2333            mChildFragmentManager.dispatchTrimMemory(level);
2334        }
2335    }
2336    */
2337
2338    boolean performCreateOptionsMenu(Menu menu, MenuInflater inflater) {
2339        boolean show = false;
2340        if (!mHidden) {
2341            if (mHasMenu && mMenuVisible) {
2342                show = true;
2343                onCreateOptionsMenu(menu, inflater);
2344            }
2345            if (mChildFragmentManager != null) {
2346                show |= mChildFragmentManager.dispatchCreateOptionsMenu(menu, inflater);
2347            }
2348        }
2349        return show;
2350    }
2351
2352    boolean performPrepareOptionsMenu(Menu menu) {
2353        boolean show = false;
2354        if (!mHidden) {
2355            if (mHasMenu && mMenuVisible) {
2356                show = true;
2357                onPrepareOptionsMenu(menu);
2358            }
2359            if (mChildFragmentManager != null) {
2360                show |= mChildFragmentManager.dispatchPrepareOptionsMenu(menu);
2361            }
2362        }
2363        return show;
2364    }
2365
2366    boolean performOptionsItemSelected(MenuItem item) {
2367        if (!mHidden) {
2368            if (mHasMenu && mMenuVisible) {
2369                if (onOptionsItemSelected(item)) {
2370                    return true;
2371                }
2372            }
2373            if (mChildFragmentManager != null) {
2374                if (mChildFragmentManager.dispatchOptionsItemSelected(item)) {
2375                    return true;
2376                }
2377            }
2378        }
2379        return false;
2380    }
2381
2382    boolean performContextItemSelected(MenuItem item) {
2383        if (!mHidden) {
2384            if (onContextItemSelected(item)) {
2385                return true;
2386            }
2387            if (mChildFragmentManager != null) {
2388                if (mChildFragmentManager.dispatchContextItemSelected(item)) {
2389                    return true;
2390                }
2391            }
2392        }
2393        return false;
2394    }
2395
2396    void performOptionsMenuClosed(Menu menu) {
2397        if (!mHidden) {
2398            if (mHasMenu && mMenuVisible) {
2399                onOptionsMenuClosed(menu);
2400            }
2401            if (mChildFragmentManager != null) {
2402                mChildFragmentManager.dispatchOptionsMenuClosed(menu);
2403            }
2404        }
2405    }
2406
2407    void performSaveInstanceState(Bundle outState) {
2408        onSaveInstanceState(outState);
2409        if (mChildFragmentManager != null) {
2410            Parcelable p = mChildFragmentManager.saveAllState();
2411            if (p != null) {
2412                outState.putParcelable(FragmentActivity.FRAGMENTS_TAG, p);
2413            }
2414        }
2415    }
2416
2417    void performPause() {
2418        if (mChildFragmentManager != null) {
2419            mChildFragmentManager.dispatchPause();
2420        }
2421        mState = STARTED;
2422        mCalled = false;
2423        onPause();
2424        if (!mCalled) {
2425            throw new SuperNotCalledException("Fragment " + this
2426                    + " did not call through to super.onPause()");
2427        }
2428    }
2429
2430    void performStop() {
2431        if (mChildFragmentManager != null) {
2432            mChildFragmentManager.dispatchStop();
2433        }
2434        mState = STOPPED;
2435        mCalled = false;
2436        onStop();
2437        if (!mCalled) {
2438            throw new SuperNotCalledException("Fragment " + this
2439                    + " did not call through to super.onStop()");
2440        }
2441    }
2442
2443    void performReallyStop() {
2444        if (mChildFragmentManager != null) {
2445            mChildFragmentManager.dispatchReallyStop();
2446        }
2447        mState = ACTIVITY_CREATED;
2448        if (mLoadersStarted) {
2449            mLoadersStarted = false;
2450            if (!mCheckedForLoaderManager) {
2451                mCheckedForLoaderManager = true;
2452                mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false);
2453            }
2454            if (mLoaderManager != null) {
2455                if (mHost.getRetainLoaders()) {
2456                    mLoaderManager.doRetain();
2457                } else {
2458                    mLoaderManager.doStop();
2459                }
2460            }
2461        }
2462    }
2463
2464    void performDestroyView() {
2465        if (mChildFragmentManager != null) {
2466            mChildFragmentManager.dispatchDestroyView();
2467        }
2468        mState = CREATED;
2469        mCalled = false;
2470        onDestroyView();
2471        if (!mCalled) {
2472            throw new SuperNotCalledException("Fragment " + this
2473                    + " did not call through to super.onDestroyView()");
2474        }
2475        if (mLoaderManager != null) {
2476            mLoaderManager.doReportNextStart();
2477        }
2478        mPerformedCreateView = false;
2479    }
2480
2481    void performDestroy() {
2482        if (mChildFragmentManager != null) {
2483            mChildFragmentManager.dispatchDestroy();
2484        }
2485        mState = INITIALIZING;
2486        mCalled = false;
2487        onDestroy();
2488        if (!mCalled) {
2489            throw new SuperNotCalledException("Fragment " + this
2490                    + " did not call through to super.onDestroy()");
2491        }
2492        mChildFragmentManager = null;
2493    }
2494
2495    void performDetach() {
2496        mCalled = false;
2497        onDetach();
2498        if (!mCalled) {
2499            throw new SuperNotCalledException("Fragment " + this
2500                    + " did not call through to super.onDetach()");
2501        }
2502
2503        // Destroy the child FragmentManager if we still have it here.
2504        // We won't unless we're retaining our instance and if we do,
2505        // our child FragmentManager instance state will have already been saved.
2506        if (mChildFragmentManager != null) {
2507            if (!mRetaining) {
2508                throw new IllegalStateException("Child FragmentManager of " + this + " was not "
2509                        + " destroyed and this fragment is not retaining instance");
2510            }
2511            mChildFragmentManager.dispatchDestroy();
2512            mChildFragmentManager = null;
2513        }
2514    }
2515
2516    void setOnStartEnterTransitionListener(OnStartEnterTransitionListener listener) {
2517        ensureAnimationInfo();
2518        if (listener == mAnimationInfo.mStartEnterTransitionListener) {
2519            return;
2520        }
2521        if (listener != null && mAnimationInfo.mStartEnterTransitionListener != null) {
2522            throw new IllegalStateException("Trying to set a replacement "
2523                    + "startPostponedEnterTransition on " + this);
2524        }
2525        if (mAnimationInfo.mEnterTransitionPostponed) {
2526            mAnimationInfo.mStartEnterTransitionListener = listener;
2527        }
2528        if (listener != null) {
2529            listener.startListening();
2530        }
2531    }
2532
2533    private AnimationInfo ensureAnimationInfo() {
2534        if (mAnimationInfo == null) {
2535            mAnimationInfo = new AnimationInfo();
2536        }
2537        return mAnimationInfo;
2538    }
2539
2540    int getNextAnim() {
2541        if (mAnimationInfo == null) {
2542            return 0;
2543        }
2544        return mAnimationInfo.mNextAnim;
2545    }
2546
2547    void setNextAnim(int animResourceId) {
2548        if (mAnimationInfo == null && animResourceId == 0) {
2549            return; // no change!
2550        }
2551        ensureAnimationInfo().mNextAnim = animResourceId;
2552    }
2553
2554    int getNextTransition() {
2555        if (mAnimationInfo == null) {
2556            return 0;
2557        }
2558        return mAnimationInfo.mNextTransition;
2559    }
2560
2561    void setNextTransition(int nextTransition, int nextTransitionStyle) {
2562        if (mAnimationInfo == null && nextTransition == 0 && nextTransitionStyle == 0) {
2563            return; // no change!
2564        }
2565        ensureAnimationInfo();
2566        mAnimationInfo.mNextTransition = nextTransition;
2567        mAnimationInfo.mNextTransitionStyle = nextTransitionStyle;
2568    }
2569
2570    int getNextTransitionStyle() {
2571        if (mAnimationInfo == null) {
2572            return 0;
2573        }
2574        return mAnimationInfo.mNextTransitionStyle;
2575    }
2576
2577    SharedElementCallback getEnterTransitionCallback() {
2578        if (mAnimationInfo == null) {
2579            return null;
2580        }
2581        return mAnimationInfo.mEnterTransitionCallback;
2582    }
2583
2584    SharedElementCallback getExitTransitionCallback() {
2585        if (mAnimationInfo == null) {
2586            return null;
2587        }
2588        return mAnimationInfo.mExitTransitionCallback;
2589    }
2590
2591    View getAnimatingAway() {
2592        if (mAnimationInfo == null) {
2593            return null;
2594        }
2595        return mAnimationInfo.mAnimatingAway;
2596    }
2597
2598    void setAnimatingAway(View view) {
2599        ensureAnimationInfo().mAnimatingAway = view;
2600    }
2601
2602    int getStateAfterAnimating() {
2603        if (mAnimationInfo == null) {
2604            return 0;
2605        }
2606        return mAnimationInfo.mStateAfterAnimating;
2607    }
2608
2609    void setStateAfterAnimating(int state) {
2610        ensureAnimationInfo().mStateAfterAnimating = state;
2611    }
2612
2613    boolean isPostponed() {
2614        if (mAnimationInfo == null) {
2615            return false;
2616        }
2617        return mAnimationInfo.mEnterTransitionPostponed;
2618    }
2619
2620    boolean isHideReplaced() {
2621        if (mAnimationInfo == null) {
2622            return false;
2623        }
2624        return mAnimationInfo.mIsHideReplaced;
2625    }
2626
2627    void setHideReplaced(boolean replaced) {
2628        ensureAnimationInfo().mIsHideReplaced = replaced;
2629    }
2630
2631    /**
2632     * Used internally to be notified when {@link #startPostponedEnterTransition()} has
2633     * been called. This listener will only be called once and then be removed from the
2634     * listeners.
2635     */
2636    interface OnStartEnterTransitionListener {
2637        void onStartEnterTransition();
2638        void startListening();
2639    }
2640
2641    /**
2642     * Contains all the animation and transition information for a fragment. This will only
2643     * be instantiated for Fragments that have Views.
2644     */
2645    static class AnimationInfo {
2646        // Non-null if the fragment's view hierarchy is currently animating away,
2647        // meaning we need to wait a bit on completely destroying it.  This is the
2648        // view that is animating.
2649        View mAnimatingAway;
2650
2651        // If mAnimatingAway != null, this is the state we should move to once the
2652        // animation is done.
2653        int mStateAfterAnimating;
2654
2655        // If app has requested a specific animation, this is the one to use.
2656        int mNextAnim;
2657
2658        // If app has requested a specific transition, this is the one to use.
2659        int mNextTransition;
2660
2661        // If app has requested a specific transition style, this is the one to use.
2662        int mNextTransitionStyle;
2663
2664        private Object mEnterTransition = null;
2665        private Object mReturnTransition = USE_DEFAULT_TRANSITION;
2666        private Object mExitTransition = null;
2667        private Object mReenterTransition = USE_DEFAULT_TRANSITION;
2668        private Object mSharedElementEnterTransition = null;
2669        private Object mSharedElementReturnTransition = USE_DEFAULT_TRANSITION;
2670        private Boolean mAllowReturnTransitionOverlap;
2671        private Boolean mAllowEnterTransitionOverlap;
2672
2673        SharedElementCallback mEnterTransitionCallback = null;
2674        SharedElementCallback mExitTransitionCallback = null;
2675
2676        // True when postponeEnterTransition has been called and startPostponeEnterTransition
2677        // hasn't been called yet.
2678        boolean mEnterTransitionPostponed;
2679
2680        // Listener to wait for startPostponeEnterTransition. After being called, it will
2681        // be set to null
2682        OnStartEnterTransitionListener mStartEnterTransitionListener;
2683
2684        // True if the View was hidden, but the transition is handling the hide
2685        boolean mIsHideReplaced;
2686    }
2687}
2688