Fragment.java revision 320113721c2e14bbc2403809046fa2959a665c11
1cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/*
2ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * Copyright 2018 The Android Open Source Project
3cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn *
4cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License");
5cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * you may not use this file except in compliance with the License.
6cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * You may obtain a copy of the License at
7cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn *
8cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn *      http://www.apache.org/licenses/LICENSE-2.0
9cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn *
10cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Unless required by applicable law or agreed to in writing, software
11cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS,
12cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * See the License for the specific language governing permissions and
14cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * limitations under the License.
15cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */
16cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
17ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikaspackage androidx.fragment.app;
18cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
19ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
20990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2115e593ea3575512d7072240d1db9d74fad8749a3George Mountimport android.animation.Animator;
22cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.app.Activity;
23c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinetsimport android.arch.lifecycle.Lifecycle;
24c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinetsimport android.arch.lifecycle.LifecycleOwner;
25c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinetsimport android.arch.lifecycle.LifecycleRegistry;
2641516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lakeimport android.arch.lifecycle.ViewModelStore;
2741516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lakeimport android.arch.lifecycle.ViewModelStoreOwner;
28cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.ComponentCallbacks;
29cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Context;
30cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Intent;
31fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarriimport android.content.IntentSender;
32cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Configuration;
33cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Resources;
34cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Bundle;
35990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mountimport android.os.Looper;
36cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcel;
37cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcelable;
38cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.AttributeSet;
39cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.SparseArray;
40cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ContextMenu;
419562a3b639225d406d736b64a12e2d75459259e3Alan Viveretteimport android.view.ContextMenu.ContextMenuInfo;
42cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.LayoutInflater;
43cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.Menu;
44cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuInflater;
45cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuItem;
46cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View;
47cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View.OnCreateContextMenuListener;
489562a3b639225d406d736b64a12e2d75459259e3Alan Viveretteimport android.view.ViewGroup;
49cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.animation.Animation;
50cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.widget.AdapterView;
51cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
52320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.annotation.CallSuper;
53320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.annotation.NonNull;
54320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.annotation.Nullable;
55320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.annotation.RestrictTo;
56320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.annotation.StringRes;
57320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.collection.SimpleArrayMap;
58320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.core.app.SharedElementCallback;
59320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.core.util.DebugUtils;
60320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.core.view.LayoutInflaterCompat;
61320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.loader.app.LoaderManager;
62320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikas
63cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.FileDescriptor;
64cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.PrintWriter;
65b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikasimport java.lang.reflect.InvocationTargetException;
66cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
67cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/**
68cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Static library support version of the framework's {@link android.app.Fragment}.
69cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Used to write apps that run on platforms prior to Android 3.0.  When running
70cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on Android 3.0 or above, this implementation is still used; it does not try
719dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * to switch to the framework's implementation. See the framework {@link android.app.Fragment}
72cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * documentation for a class overview.
739dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main *
749dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <p>The main differences when using this support version instead of the framework version are:
759dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <ul>
769dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main *  <li>Your activity must extend {@link FragmentActivity}
779dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main *  <li>You must call {@link FragmentActivity#getSupportFragmentManager} to get the
789dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main *  {@link FragmentManager}
799dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * </ul>
809dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main *
81cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */
8241516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lakepublic class Fragment implements ComponentCallbacks, OnCreateContextMenuListener, LifecycleOwner,
8341516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake        ViewModelStoreOwner {
842290993eddf5262a8df7fc9478daed52401e325aDianne Hackborn    private static final SimpleArrayMap<String, Class<?>> sClassMap =
852290993eddf5262a8df7fc9478daed52401e325aDianne Hackborn            new SimpleArrayMap<String, Class<?>>();
869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    static final Object USE_DEFAULT_TRANSITION = new Object();
889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
89cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final int INITIALIZING = 0;     // Not yet created.
90cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final int CREATED = 1;          // Created.
91cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final int ACTIVITY_CREATED = 2; // The activity has finished its creation.
92e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    static final int STOPPED = 3;          // Fully created, not started.
93e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    static final int STARTED = 4;          // Created and started, not resumed.
94e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    static final int RESUMED = 5;          // Created started and resumed.
954bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
96cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mState = INITIALIZING;
974bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
98cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // When instantiated from saved state, this is the saved state.
99cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Bundle mSavedFragmentState;
100cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    SparseArray<Parcelable> mSavedViewState;
1014bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
102cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Index into active fragment array.
103cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mIndex = -1;
1044bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
105cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Internal unique name for this fragment;
106cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    String mWho;
1074bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Construction arguments;
109cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Bundle mArguments;
110cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
111cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Target fragment.
112cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Fragment mTarget;
113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1142c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn    // For use when retaining a fragment: this is the index of the last mTarget.
1152c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn    int mTargetIndex = -1;
1162c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn
117cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Target request code.
118cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mTargetRequestCode;
119cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
120cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // True if the fragment is in the list of added fragments.
121cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mAdded;
1224bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
123cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment is being removed from its activity.
124cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRemoving;
1254bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
126cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Set to true if this fragment was instantiated from a layout file.
127cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mFromLayout;
1284bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
129cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Set to true when the view has actually been inflated in its layout.
130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mInLayout;
131cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // True if this fragment has been restored from previously saved state.
133cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRestored;
134d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
13537149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell    // True if performCreateView has been called and a matching call to performDestroyView
13637149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell    // has not yet happened.
13737149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell    boolean mPerformedCreateView;
13837149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell
139cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Number of active back stack entries this fragment is in.
140cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mBackStackNesting;
141d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
142cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The fragment manager we are associated with.  Set as soon as the
143cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // fragment is used in a transaction; cleared after it has been removed
144cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // from all transactions.
145abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    FragmentManagerImpl mFragmentManager;
146cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
147d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    // Host this fragment is attached to.
1488491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy    FragmentHostCallback mHost;
1490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
1500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    // Private fragment manager for child fragments inside of this one.
1510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    FragmentManagerImpl mChildFragmentManager;
1520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
153c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell    // For use when restoring fragment state and descendant fragments are retained.
154c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell    // This state is set by FragmentState.instantiate and cleared in onCreate.
155c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell    FragmentManagerNonConfig mChildNonConfig;
156c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell
15741516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake    // ViewModelStore for storing ViewModels associated with this Fragment
15841516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake    ViewModelStore mViewModelStore;
15941516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake
1600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    // If this Fragment is contained in another Fragment, this is that container.
1610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    Fragment mParentFragment;
1620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
163cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The optional identifier for this fragment -- either the container ID if it
164cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // was dynamically added to the view hierarchy, or the ID supplied in
165cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // layout.
166cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mFragmentId;
1674bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
168cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // When a fragment is being dynamically added to the view hierarchy, this
169cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // is the identifier of the parent container it is being added to.
170cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mContainerId;
1714bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
172cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The optional named tag for this fragment -- usually used to find
173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // fragments that are not part of the layout.
174cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    String mTag;
1754bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
176cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Set to true when the app has requested that this fragment be hidden
177cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // from the user.
178cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mHidden;
1794bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
180e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    // Set to true when the app has requested that this fragment be deactivated.
181e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    boolean mDetached;
182e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn
183cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment would like its instance retained across
184cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // configuration changes.
185cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRetainInstance;
1862bdd09a243b422960168170e2344274cc9cfd788Todd Kennedy
187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment is being retained across the current config change.
188cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRetaining;
1894bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
190cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment has menu items to contribute.
191cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mHasMenu;
1922a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
1932a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    // Set to true to allow the fragment's menu to be shown.
1942a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    boolean mMenuVisible = true;
1952a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
196cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Used to verify that subclasses call through to super class.
197cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mCalled;
1984bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The parent container of the fragment after dynamically added to UI.
200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ViewGroup mContainer;
2014bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The View generated for this fragment.
203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    View mView;
2044bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The real inner view that will save/restore state.
206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    View mInnerView;
207abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
208abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    // Whether this fragment should defer starting until after other fragments
209abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    // have been started and their loaders are finished.
210abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    boolean mDeferStart;
2114bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
21279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    // Hint provided by the app that this fragment is currently visible to the user.
21379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    boolean mUserVisibleHint = true;
214abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
215990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    // The animation and transition information for the fragment. This will be null
216990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    // unless the elements are explicitly accessed and should remain null for Fragments
217990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    // without Views.
218990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    AnimationInfo mAnimationInfo;
2199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
220990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    // True if the View was added, and its animation has yet to be run. This could
221990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    // also indicate that the fragment view hasn't been made visible, even if there is no
222990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    // animation for this fragment.
223990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    boolean mIsNewlyAdded;
224990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
225990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    // True if mHidden has been changed and the animation should be scheduled.
226990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    boolean mHiddenChanged;
2279f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
2280bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount    // The alpha of the view when the view was added and then postponed. If the value is less
2290bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount    // than zero, this means that the view's add was canceled and should not participate in
2300bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount    // removal animations.
2310bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount    float mPostponedAlpha;
2320bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount
2338b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount    // The cached value from onGetLayoutInflater(Bundle) that will be returned from
2348b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount    // getLayoutInflater()
2358b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount    LayoutInflater mLayoutInflater;
2368b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount
237e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount    // Keep track of whether or not this Fragment has run performCreate(). Retained instance
238e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount    // fragments can have mRetaining set to true without going through creation, so we must
239e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount    // track it separately.
240e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount    boolean mIsCreated;
241e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount
242c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets    LifecycleRegistry mLifecycleRegistry = new LifecycleRegistry(this);
243c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets
244c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets    @Override
245c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets    public Lifecycle getLifecycle() {
246c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets        return mLifecycleRegistry;
247c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets    }
248c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets
24941516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake    @NonNull
25041516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake    @Override
25141516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake    public ViewModelStore getViewModelStore() {
25241516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake        if (getContext() == null) {
25341516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake            throw new IllegalStateException("Can't access ViewModels from detached fragment");
25441516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake        }
25541516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake        if (mViewModelStore == null) {
25641516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake            mViewModelStore = new ViewModelStore();
25741516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake        }
25841516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake        return mViewModelStore;
25941516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake    }
26041516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake
261cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
2625c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * State information that has been retrieved from a fragment instance
2635c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * through {@link FragmentManager#saveFragmentInstanceState(Fragment)
2645c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * FragmentManager.saveFragmentInstanceState}.
2655c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     */
2665c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    public static class SavedState implements Parcelable {
2675c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        final Bundle mState;
2685c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
2695c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        SavedState(Bundle state) {
2705c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            mState = state;
2715c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
2725c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
2735c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        SavedState(Parcel in, ClassLoader loader) {
2745c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            mState = in.readBundle();
2755c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            if (loader != null && mState != null) {
2765c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                mState.setClassLoader(loader);
2775c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            }
2785c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
2795c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
2805c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        @Override
2815c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        public int describeContents() {
2825c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            return 0;
2835c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
2845c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
2855c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        @Override
2865c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        public void writeToParcel(Parcel dest, int flags) {
2875c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            dest.writeBundle(mState);
2885c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
2895c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
2905c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        public static final Parcelable.Creator<SavedState> CREATOR
2915c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                = new Parcelable.Creator<SavedState>() {
292d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            @Override
2935c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            public SavedState createFromParcel(Parcel in) {
2945c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                return new SavedState(in, null);
2955c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            }
2965c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
297d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            @Override
2985c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            public SavedState[] newArray(int size) {
2995c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                return new SavedState[size];
3005c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            }
3015c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        };
3025c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    }
3035c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3045c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    /**
305cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when
306cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * there is an instantiation failure.
307cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
308960e687174a4c2daca556d52bfd48e2fd8f4f317Jake Wharton    @SuppressWarnings("JavaLangClash")
309960e687174a4c2daca556d52bfd48e2fd8f4f317Jake Wharton    public static class InstantiationException extends RuntimeException {
310cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public InstantiationException(String msg, Exception cause) {
311cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            super(msg, cause);
312cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
313cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
314cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
315cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
316cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Default constructor.  <strong>Every</strong> fragment must have an
317cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * empty constructor, so it can be instantiated when restoring its
318cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * activity's state.  It is strongly recommended that subclasses do not
319cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * have other constructors with parameters, since these constructors
320cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * will not be called when the fragment is re-instantiated; instead,
321cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * arguments can be supplied by the caller with {@link #setArguments}
322cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * and later retrieved by the Fragment with {@link #getArguments}.
3234bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
32404f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas     * <p>Applications should generally not implement a constructor. Prefer
32504f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas     * {@link #onAttach(Context)} instead. It is the first place application code can run where
32604f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas     * the fragment is ready to be used - the point where the fragment is actually associated with
32704f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas     * its context. Some applications may also want to implement {@link #onInflate} to retrieve
32804f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas     * attributes from a layout resource, although note this happens when the fragment is attached.
329cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
330cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public Fragment() {
331cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
332cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
333cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
334cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Like {@link #instantiate(Context, String, Bundle)} but with a null
335cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * argument Bundle.
336cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
337cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public static Fragment instantiate(Context context, String fname) {
338cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return instantiate(context, fname, null);
339cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
340cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
341cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
342cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Create a new instance of a Fragment with the given class name.  This is
343cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the same as calling its empty constructor.
344cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
345cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param context The calling context being used to instantiate the fragment.
346cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This is currently just used to get its ClassLoader.
347cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param fname The class name of the fragment to instantiate.
348cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param args Bundle of arguments to supply to the fragment, which it
349cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * can retrieve with {@link #getArguments()}.  May be null.
350cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return Returns a new fragment instance.
351cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @throws InstantiationException If there is a failure in instantiating
352cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the given fragment class.  This is a runtime exception; it is not
353cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * normally expected to happen.
354cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
355c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy    public static Fragment instantiate(Context context, String fname, @Nullable Bundle args) {
356cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        try {
357cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            Class<?> clazz = sClassMap.get(fname);
358cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (clazz == null) {
359cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                // Class not found in the cache, see if it's real, and try to add it
360cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                clazz = context.getClassLoader().loadClass(fname);
361cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                sClassMap.put(fname, clazz);
362cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
363b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas            Fragment f = (Fragment) clazz.getConstructor().newInstance();
364cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (args != null) {
365cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                args.setClassLoader(f.getClass().getClassLoader());
36637149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell                f.setArguments(args);
367cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
368cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return f;
369cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } catch (ClassNotFoundException e) {
370cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new InstantiationException("Unable to instantiate fragment " + fname
371cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + ": make sure class name exists, is public, and has an"
372cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + " empty constructor that is public", e);
373cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } catch (java.lang.InstantiationException e) {
374cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new InstantiationException("Unable to instantiate fragment " + fname
375cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + ": make sure class name exists, is public, and has an"
376cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + " empty constructor that is public", e);
377cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } catch (IllegalAccessException e) {
378cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new InstantiationException("Unable to instantiate fragment " + fname
379cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + ": make sure class name exists, is public, and has an"
380cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + " empty constructor that is public", e);
381b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas        } catch (NoSuchMethodException e) {
382b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas            throw new InstantiationException("Unable to instantiate fragment " + fname
383b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas                    + ": could not find Fragment constructor", e);
384b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas        } catch (InvocationTargetException e) {
385b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas            throw new InstantiationException("Unable to instantiate fragment " + fname
386b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas                    + ": calling Fragment constructor caused an exception", e);
387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
388cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
3893fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell
3903fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell    /**
3913fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell     * Determine if the given fragment name is a support library fragment class.
3923fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell     *
3933fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell     * @param context Context used to determine the correct ClassLoader to use
3943fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell     * @param fname Class name of the fragment to test
395ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas     * @return true if <code>fname</code> is <code>androidx.fragment.app.Fragment</code>
3963fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell     *         or a subclass, false otherwise.
3973fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell     */
3983fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell    static boolean isSupportFragmentClass(Context context, String fname) {
3993fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell        try {
4003fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell            Class<?> clazz = sClassMap.get(fname);
4013fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell            if (clazz == null) {
4023fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell                // Class not found in the cache, see if it's real, and try to add it
4033fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell                clazz = context.getClassLoader().loadClass(fname);
4043fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell                sClassMap.put(fname, clazz);
4053fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell            }
4063fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell            return Fragment.class.isAssignableFrom(clazz);
4073fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell        } catch (ClassNotFoundException e) {
4083fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell            return false;
4093fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell        }
4103fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell    }
4114bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
4120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    final void restoreViewState(Bundle savedInstanceState) {
413cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mSavedViewState != null) {
414cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mInnerView.restoreHierarchyState(mSavedViewState);
415cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mSavedViewState = null;
416cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
4170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
4180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onViewStateRestored(savedInstanceState);
4190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
4200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
4210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onViewStateRestored()");
4220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
423cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
4240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
4250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    final void setIndex(int index, Fragment parent) {
426cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mIndex = index;
4270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (parent != null) {
4280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mWho = parent.mWho + ":" + mIndex;
4290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        } else {
4300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mWho = "android:fragment:" + mIndex;
4310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
432e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    }
4330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
434e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    final boolean isInBackStack() {
435e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        return mBackStackNesting > 0;
436e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    }
437e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn
438cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
439cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Subclasses can not override equals().
440cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
441cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override final public boolean equals(Object o) {
442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return super.equals(o);
443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
444cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
445cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
446cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Subclasses can not override hashCode().
447cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
448cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override final public int hashCode() {
449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return super.hashCode();
450cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
4514bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
452cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
453cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public String toString() {
454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        StringBuilder sb = new StringBuilder(128);
455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        DebugUtils.buildShortClassTag(this, sb);
456cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mIndex >= 0) {
457cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(" #");
458cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(mIndex);
459cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
460cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mFragmentId != 0) {
461cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(" id=0x");
462cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(Integer.toHexString(mFragmentId));
463cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
464cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mTag != null) {
465cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(" ");
466cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(mTag);
467cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
468cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append('}');
469cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return sb.toString();
470cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
4714bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
472cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
473cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the identifier this fragment is known by.  This is either
474cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the android:id value supplied in a layout or the container view ID
475cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * supplied when adding the fragment.
476cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
477cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public int getId() {
478cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mFragmentId;
479cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
4804bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
481cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
482cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Get the tag name of the fragment, if specified.
483cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
4842a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @Nullable
485cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public String getTag() {
486cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mTag;
487cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
4884bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
489cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
4905e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * Supply the construction arguments for this fragment.
4915e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * The arguments supplied here will be retained across fragment destroy and
492cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * creation.
4935e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * <p>This method cannot be called if the fragment is added to a FragmentManager and
4945e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * if {@link #isStateSaved()} would return true.</p>
495cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
4962a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    public void setArguments(@Nullable Bundle args) {
4975e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell        if (mIndex >= 0 && isStateSaved()) {
4985e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell            throw new IllegalStateException("Fragment already active and state has been saved");
499cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
500cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mArguments = args;
501cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
502cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
503cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
504cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the arguments supplied when the fragment was instantiated,
505cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * if any.
506cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
5072a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @Nullable
508cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public Bundle getArguments() {
509cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mArguments;
510cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
511cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
512cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
5135e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * Returns true if this fragment is added and its state has already been saved
5145e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * by its host. Any operations that would change saved state should not be performed
5155e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * if this method returns true, and some operations such as {@link #setArguments(Bundle)}
5165e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * will fail.
5175e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     *
5185e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * @return true if this fragment's state has already been saved by its host
5195e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     */
5205e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell    public final boolean isStateSaved() {
5215e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell        if (mFragmentManager == null) {
5225e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell            return false;
5235e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell        }
5245e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell        return mFragmentManager.isStateSaved();
5255e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell    }
5265e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell
5275e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell    /**
5285c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * Set the initial saved state that this Fragment should restore itself
5295c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * from when first being constructed, as returned by
5305c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * {@link FragmentManager#saveFragmentInstanceState(Fragment)
5315c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * FragmentManager.saveFragmentInstanceState}.
5325c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     *
5335c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * @param state The state the fragment should be restored from.
5345c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     */
5352a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    public void setInitialSavedState(@Nullable SavedState state) {
5365c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        if (mIndex >= 0) {
5375c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            throw new IllegalStateException("Fragment already active");
5385c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
5395c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        mSavedFragmentState = state != null && state.mState != null
5405c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                ? state.mState : null;
5415c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    }
5425c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
5435c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    /**
544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Optional target for this fragment.  This may be used, for example,
545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * if this fragment is being started by another, and when done wants to
546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * give a result back to the first.  The target set here is retained
547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * across instances via {@link FragmentManager#putFragment
548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * FragmentManager.putFragment()}.
549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param fragment The fragment that is the target of this one.
551cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param requestCode Optional request code, for convenience if you
552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * are going to call back with {@link #onActivityResult(int, int, Intent)}.
553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
554b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas    @SuppressWarnings("ReferenceEquality")
5552a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    public void setTargetFragment(@Nullable Fragment fragment, int requestCode) {
556a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        // Don't allow a caller to set a target fragment in another FragmentManager,
557a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        // but there's a snag: people do set target fragments before fragments get added.
558a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        // We'll have the FragmentManager check that for validity when we move
559a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        // the fragments to a valid state.
560a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        final FragmentManager mine = getFragmentManager();
5612ab15df66963610bc02cb30e9a459f2b49c2ccfaAdam Powell        final FragmentManager theirs = fragment != null ? fragment.getFragmentManager() : null;
562a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        if (mine != null && theirs != null && mine != theirs) {
563a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell            throw new IllegalArgumentException("Fragment " + fragment
564a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell                    + " must share the same FragmentManager to be set as a target fragment");
565a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        }
566a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell
567a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        // Don't let someone create a cycle.
568a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        for (Fragment check = fragment; check != null; check = check.getTargetFragment()) {
569a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell            if (check == this) {
570a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell                throw new IllegalArgumentException("Setting " + fragment + " as the target of "
571a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell                        + this + " would create a target cycle");
572a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell            }
573a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        }
574cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mTarget = fragment;
575cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mTargetRequestCode = requestCode;
576cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
577cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
578cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
579cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the target fragment set by {@link #setTargetFragment}.
580cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
5812a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @Nullable
582cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public Fragment getTargetFragment() {
583cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mTarget;
584cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
585cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
586cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
587cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the target request code set by {@link #setTargetFragment}.
588cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
589cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public int getTargetRequestCode() {
590cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mTargetRequestCode;
591cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
592cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
593cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
594d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * Return the {@link Context} this fragment is currently associated with.
595c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     *
596c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * @see #requireContext()
597d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     */
598b38fded102ffe4de21f2d048262f52d5bcefbfd5Jake Wharton    @Nullable
599edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy    public Context getContext() {
600d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        return mHost == null ? null : mHost.getContext();
601d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    }
602d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
603d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    /**
604c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * Return the {@link Context} this fragment is currently associated with.
605c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     *
606c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * @throws IllegalStateException if not currently associated with a context.
607c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * @see #getContext()
608c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     */
609c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    @NonNull
610c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    public final Context requireContext() {
611c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        Context context = getContext();
612c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        if (context == null) {
613c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton            throw new IllegalStateException("Fragment " + this + " not attached to a context.");
614c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        }
615c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        return context;
616c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    }
617c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton
618c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    /**
619d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * Return the {@link FragmentActivity} this fragment is currently associated with.
620d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * May return {@code null} if the fragment is associated with a {@link Context}
621d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * instead.
622c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     *
623c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * @see #requireActivity()
624cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
625b38fded102ffe4de21f2d048262f52d5bcefbfd5Jake Wharton    @Nullable
626cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public FragmentActivity getActivity() {
627d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        return mHost == null ? null : (FragmentActivity) mHost.getActivity();
628cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
629d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
630cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
631c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * Return the {@link FragmentActivity} this fragment is currently associated with.
632c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     *
633c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * @throws IllegalStateException if not currently associated with an activity or if associated
634c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * only with a context.
635c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * @see #getActivity()
636c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     */
637c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    @NonNull
638c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    public final FragmentActivity requireActivity() {
639c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        FragmentActivity activity = getActivity();
640c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        if (activity == null) {
641c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton            throw new IllegalStateException("Fragment " + this + " not attached to an activity.");
642c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        }
643c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        return activity;
644c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    }
645c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton
646c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    /**
647edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy     * Return the host object of this fragment. May return {@code null} if the fragment
648edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy     * isn't currently being hosted.
649c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     *
650c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * @see #requireHost()
651edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy     */
652b38fded102ffe4de21f2d048262f52d5bcefbfd5Jake Wharton    @Nullable
653edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy    final public Object getHost() {
6548491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy        return mHost == null ? null : mHost.onGetHost();
655edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy    }
656edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy
657edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy    /**
658c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * Return the host object of this fragment.
659c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     *
660c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * @throws IllegalStateException if not currently associated with a host.
661c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * @see #getHost()
662cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
6632a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @NonNull
664c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    public final Object requireHost() {
665c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        Object host = getHost();
666c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        if (host == null) {
667c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton            throw new IllegalStateException("Fragment " + this + " not attached to a host.");
668cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
669c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        return host;
670c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    }
671c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton
672c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    /**
673c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * Return <code>requireActivity().getResources()</code>.
674c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     */
675c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    @NonNull
676c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    final public Resources getResources() {
677c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        return requireContext().getResources();
678cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
679d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
680cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
681cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return a localized, styled CharSequence from the application's package's
682cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default string table.
683cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
684cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resId Resource id for the CharSequence text
685cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
6862a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @NonNull
687a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye    public final CharSequence getText(@StringRes int resId) {
688cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return getResources().getText(resId);
689cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
690cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
691cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
692cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return a localized string from the application's package's
693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default string table.
694cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
695cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resId Resource id for the string
696cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
6972a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @NonNull
698a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye    public final String getString(@StringRes int resId) {
699cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return getResources().getString(resId);
700cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
701cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
702cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return a localized formatted string from the application's package's
704cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default string table, substituting the format arguments as defined in
705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link java.util.Formatter} and {@link java.lang.String#format}.
706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
707cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resId Resource id for the format string
708cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param formatArgs The format arguments that will be used for substitution.
709cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
7102a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @NonNull
711a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye    public final String getString(@StringRes int resId, Object... formatArgs) {
712cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return getResources().getString(resId, formatArgs);
713cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
714cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
715cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
716cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the FragmentManager for interacting with fragments associated
717cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * with this fragment's activity.  Note that this will be non-null slightly
718cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * before {@link #getActivity()}, during the time from when the fragment is
719cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * placed in a {@link FragmentTransaction} until it is committed and
720cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * attached to its activity.
7210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     *
7220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * <p>If this Fragment is a child of another Fragment, the FragmentManager
7230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * returned here will be the parent's {@link #getChildFragmentManager()}.
724c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     *
725c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * @see #requireFragmentManager()
726cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
727b38fded102ffe4de21f2d048262f52d5bcefbfd5Jake Wharton    @Nullable
728cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public FragmentManager getFragmentManager() {
729cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mFragmentManager;
730cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
731cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
732cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
733c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * Return the FragmentManager for interacting with fragments associated
734c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * with this fragment's activity.  Note that this will available slightly
735c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * before {@link #getActivity()}, during the time from when the fragment is
736c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * placed in a {@link FragmentTransaction} until it is committed and
737c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * attached to its activity.
738c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     *
739c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * <p>If this Fragment is a child of another Fragment, the FragmentManager
740c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * returned here will be the parent's {@link #getChildFragmentManager()}.
741c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     *
742c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * @throws IllegalStateException if not associated with a transaction or host.
743c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     * @see #getFragmentManager()
744c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton     */
745c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    @NonNull
746c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    public final FragmentManager requireFragmentManager() {
747c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        FragmentManager fragmentManager = getFragmentManager();
748c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        if (fragmentManager == null) {
749c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton            throw new IllegalStateException(
750c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton                    "Fragment " + this + " not associated with a fragment manager.");
751c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        }
752c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton        return fragmentManager;
753c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    }
754c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton
755c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton    /**
7560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * Return a private FragmentManager for placing and managing Fragments
7570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * inside of this Fragment.
7580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     */
7592a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @NonNull
7600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    final public FragmentManager getChildFragmentManager() {
7610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager == null) {
7620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            instantiateChildFragmentManager();
7630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mState >= RESUMED) {
7640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchResume();
7650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            } else if (mState >= STARTED) {
7660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchStart();
7670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            } else if (mState >= ACTIVITY_CREATED) {
7680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchActivityCreated();
7690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            } else if (mState >= CREATED) {
7700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchCreate();
7710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
7720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
7730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return mChildFragmentManager;
7740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
7750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
7760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    /**
777267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell     * Return this fragment's child FragmentManager one has been previously created,
778267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell     * otherwise null.
779267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell     */
7802a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @Nullable
781267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell    FragmentManager peekChildFragmentManager() {
782267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell        return mChildFragmentManager;
783267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell    }
784267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell
785267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell    /**
7860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * Returns the parent Fragment containing this Fragment.  If this Fragment
7870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * is attached directly to an Activity, returns null.
7880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     */
7892a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @Nullable
7900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    final public Fragment getParentFragment() {
7910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return mParentFragment;
7920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
7930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
7940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    /**
795cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment is currently added to its activity.
796cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
797cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isAdded() {
798d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        return mHost != null && mAdded;
799cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
800cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
801cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
8029c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * Return true if the fragment has been explicitly detached from the UI.
8039c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * That is, {@link FragmentTransaction#detach(Fragment)
8049c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * FragmentTransaction.detach(Fragment)} has been used on it.
8059c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     */
8069c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    final public boolean isDetached() {
8079c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        return mDetached;
8089c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
8099c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
8109c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    /**
811cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if this fragment is currently being removed from its
812cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * activity.  This is  <em>not</em> whether its activity is finishing, but
813cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * rather whether it is in the process of being removed from its activity.
814cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
815cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isRemoving() {
816cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mRemoving;
817cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
8184bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
819cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
820cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the layout is included as part of an activity view
821cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * hierarchy via the &lt;fragment&gt; tag.  This will always be true when
822cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * fragments are created through the &lt;fragment&gt; tag, <em>except</em>
823cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * in the case where an old fragment is restored from a previous state and
824cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * it does not appear in the layout of the current state.
825cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
826cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isInLayout() {
827cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mInLayout;
828cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
829cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
830cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
831cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment is in the resumed state.  This is true
832cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for the duration of {@link #onResume()} and {@link #onPause()} as well.
833cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
834cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isResumed() {
83520735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        return mState >= RESUMED;
836cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
8374bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
838cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
839cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment is currently visible to the user.  This means
8404bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     * it: (1) has been added, (2) has its view attached to the window, and
841cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * (3) is not hidden.
842cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
843cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isVisible() {
844cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return isAdded() && !isHidden() && mView != null
845cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE;
846cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
8474bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
848cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
849cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment has been hidden.  By default fragments
850cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * are shown.  You can find out about changes to this state with
851cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onHiddenChanged}.  Note that the hidden state is orthogonal
852cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to other states -- that is, to be visible to the user, a fragment
853cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * must be both started and not hidden.
854cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
855cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isHidden() {
856cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mHidden;
857cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
8583a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown
8593a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    /** @hide */
8608e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas    @RestrictTo(LIBRARY_GROUP)
8613a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    final public boolean hasOptionsMenu() {
8623a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown        return mHasMenu;
8633a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    }
8643a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown
8653a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    /** @hide */
8668e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas    @RestrictTo(LIBRARY_GROUP)
8673a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    final public boolean isMenuVisible() {
8683a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown        return mMenuVisible;
8693a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    }
8703a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown
871cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
872cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the hidden state (as returned by {@link #isHidden()} of
873cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the fragment has changed.  Fragments start out not hidden; this will
874cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * be called whenever the fragment changes state from that.
875527415d706bf580ff2bb7b492e5202b985cfa2c7Aurimas Liutikas     * @param hidden True if the fragment is now hidden, false otherwise.
876cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
877cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onHiddenChanged(boolean hidden) {
878cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
8794bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
880cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
881cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Control whether a fragment instance is retained across Activity
882cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * re-creation (such as from a configuration change).  This can only
883cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * be used with fragments not in the back stack.  If set, the fragment
884cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * lifecycle will be slightly different when an activity is recreated:
885cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <ul>
886cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still
887cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * will be, because the fragment is being detached from its current activity).
888cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <li> {@link #onCreate(Bundle)} will not be called since the fragment
889cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is not being re-created.
890cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b>
891cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * still be called.
892cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * </ul>
893cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
894cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setRetainInstance(boolean retain) {
895cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mRetainInstance = retain;
896cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
8974bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
898cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean getRetainInstance() {
899cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mRetainInstance;
900cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
9014bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
902cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
903cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Report that this fragment would like to participate in populating
904cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the options menu by receiving a call to {@link #onCreateOptionsMenu}
905cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * and related methods.
906d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     *
907cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param hasMenu If true, the fragment has menu items to contribute.
908cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
909cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setHasOptionsMenu(boolean hasMenu) {
910cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mHasMenu != hasMenu) {
911cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mHasMenu = hasMenu;
912cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (isAdded() && !isHidden()) {
9138491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy                mHost.onSupportInvalidateOptionsMenu();
914cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
915cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
916cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
9172a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
9182a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    /**
9192a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * Set a hint for whether this fragment's menu should be visible.  This
9202a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * is useful if you know that a fragment has been placed in your view
9212a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * hierarchy so that the user can not currently seen it, so any menu items
9222a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * it has should also not be shown.
9232a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     *
9242a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * @param menuVisible The default is true, meaning the fragment's menu will
9252a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * be shown as usual.  If false, the user will not see the menu.
9262a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     */
9272a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    public void setMenuVisibility(boolean menuVisible) {
9282a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        if (mMenuVisible != menuVisible) {
9292a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            mMenuVisible = menuVisible;
9302a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            if (mHasMenu && isAdded() && !isHidden()) {
9318491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy                mHost.onSupportInvalidateOptionsMenu();
9322a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            }
9332a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        }
9342a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    }
9352a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
936cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
93779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * Set a hint to the system about whether this fragment's UI is currently visible
93879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * to the user. This hint defaults to true and is persistent across fragment instance
93979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * state save and restore.
940abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     *
94179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * <p>An app may set this to false to indicate that the fragment's UI is
94279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * scrolled out of visibility or is otherwise not directly visible to the user.
94379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * This may be used by the system to prioritize operations such as fragment lifecycle updates
94479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * or loader ordering behavior.</p>
945abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     *
9460244762c99db7b1fb6c4905bc1224fefac927014Adam Powell     * <p><strong>Note:</strong> This method may be called outside of the fragment lifecycle.
9470244762c99db7b1fb6c4905bc1224fefac927014Adam Powell     * and thus has no ordering guarantees with regard to fragment lifecycle method calls.</p>
9480244762c99db7b1fb6c4905bc1224fefac927014Adam Powell     *
94979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * @param isVisibleToUser true if this fragment's UI is currently visible to the user (default),
95079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     *                        false if it is not.
951abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     */
95279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    public void setUserVisibleHint(boolean isVisibleToUser) {
9533ab5a96f51cbd0498a62f1e91f1ef99e95cb1b1cAdam Powell        if (!mUserVisibleHint && isVisibleToUser && mState < STARTED
9543ab5a96f51cbd0498a62f1e91f1ef99e95cb1b1cAdam Powell                && mFragmentManager != null && isAdded()) {
955abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell            mFragmentManager.performPendingDeferredStart(this);
956abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell        }
95779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        mUserVisibleHint = isVisibleToUser;
958c83dccecb0ec4bf9f4befdb18caccb8f373ed7bcAdam Powell        mDeferStart = mState < STARTED && !isVisibleToUser;
9590d29663c8688de94a3260584037c21dfd9e4cbfaIan Lake        if (mSavedFragmentState != null) {
9600d29663c8688de94a3260584037c21dfd9e4cbfaIan Lake            // Ensure that if the user visible hint is set before the Fragment has
9610d29663c8688de94a3260584037c21dfd9e4cbfaIan Lake            // restored its state that we don't lose the new value
9620d29663c8688de94a3260584037c21dfd9e4cbfaIan Lake            mSavedFragmentState.putBoolean(FragmentManagerImpl.USER_VISIBLE_HINT_TAG,
9630d29663c8688de94a3260584037c21dfd9e4cbfaIan Lake                    mUserVisibleHint);
9640d29663c8688de94a3260584037c21dfd9e4cbfaIan Lake        }
965abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    }
966abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
967abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    /**
96879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * @return The current value of the user-visible hint on this fragment.
96979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * @see #setUserVisibleHint(boolean)
970abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     */
97179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    public boolean getUserVisibleHint() {
97279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        return mUserVisibleHint;
973abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    }
974abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
975abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    /**
976afe28d91550483f9b7a82076a507151b4defd9baIan Lake     * Return the LoaderManager for this fragment.
977cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
978cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public LoaderManager getLoaderManager() {
979afe28d91550483f9b7a82076a507151b4defd9baIan Lake        return LoaderManager.getInstance(this);
980cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
981d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
982cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
9838491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy     * Call {@link Activity#startActivity(Intent)} from the fragment's
984cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * containing Activity.
985cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
986cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void startActivity(Intent intent) {
9870e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick        startActivity(intent, null);
9880e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick    }
9890e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick
9900e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick    /**
9910e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick     * Call {@link Activity#startActivity(Intent, Bundle)} from the fragment's
9920e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick     * containing Activity.
9930e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick     */
9940e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick    public void startActivity(Intent intent, @Nullable Bundle options) {
995d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        if (mHost == null) {
996cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
997cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
9980e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick        mHost.onStartActivityFromFragment(this /*fragment*/, intent, -1, options);
999cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1000d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1001cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
10028491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy     * Call {@link Activity#startActivityForResult(Intent, int)} from the fragment's
1003cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * containing Activity.
1004cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1005cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void startActivityForResult(Intent intent, int requestCode) {
10060e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick        startActivityForResult(intent, requestCode, null);
10070e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick    }
10080e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick
10090e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick    /**
10100e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick     * Call {@link Activity#startActivityForResult(Intent, int, Bundle)} from the fragment's
10110e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick     * containing Activity.
10120e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick     */
10130e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick    public void startActivityForResult(Intent intent, int requestCode, @Nullable Bundle options) {
1014d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        if (mHost == null) {
1015cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
1016cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
10170e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick        mHost.onStartActivityFromFragment(this /*fragment*/, intent, requestCode, options);
1018fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri    }
1019fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri
1020fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri    /**
1021fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri     * Call {@link Activity#startIntentSenderForResult(IntentSender, int, Intent, int, int, int,
1022fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri     * Bundle)} from the fragment's containing Activity.
1023fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri     */
1024fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri    public void startIntentSenderForResult(IntentSender intent, int requestCode,
1025fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri            @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
1026fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri            Bundle options) throws IntentSender.SendIntentException {
1027fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri        if (mHost == null) {
1028fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
1029fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri        }
1030fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri        mHost.onStartIntentSenderFromFragment(this, intent, requestCode, fillInIntent, flagsMask,
1031fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri                flagsValues, extraFlags, options);
1032cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1033d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1034cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1035cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Receive the result from a previous call to
1036cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #startActivityForResult(Intent, int)}.  This follows the
1037cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * related Activity API as described there in
1038cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onActivityResult(int, int, Intent)}.
1039d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     *
1040cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param requestCode The integer request code originally supplied to
1041cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *                    startActivityForResult(), allowing you to identify who this
1042cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *                    result came from.
1043cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resultCode The integer result code returned by the child activity
1044cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *                   through its setResult().
1045cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param data An Intent, which can return result data to the caller
1046cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *               (various data can be attached to Intent "extras").
1047cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1048cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onActivityResult(int requestCode, int resultCode, Intent data) {
1049cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1050d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1051cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1052e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * Requests permissions to be granted to this application. These permissions
1053e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * must be requested in your manifest, they should not be granted to your app,
1054e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * and they should have protection level {@link android.content.pm.PermissionInfo
1055e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * #PROTECTION_DANGEROUS dangerous}, regardless whether they are declared by
1056e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * the platform or a third-party app.
1057e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <p>
1058e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * Normal permissions {@link android.content.pm.PermissionInfo#PROTECTION_NORMAL}
1059e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * are granted at install time if requested in the manifest. Signature permissions
1060e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * {@link android.content.pm.PermissionInfo#PROTECTION_SIGNATURE} are granted at
1061e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * install time if requested in the manifest and the signature of your app matches
1062e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * the signature of the app declaring the permissions.
1063e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </p>
1064e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <p>
1065e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * If your app does not have the requested permissions the user will be presented
1066e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * with UI for accepting them. After the user has accepted or rejected the
1067e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * requested permissions you will receive a callback on {@link
1068e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * #onRequestPermissionsResult(int, String[], int[])} reporting whether the
1069e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * permissions were granted or not.
1070e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </p>
1071e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <p>
1072e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * Note that requesting a permission does not guarantee it will be granted and
1073e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * your app should be able to run without having this permission.
1074e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </p>
1075e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <p>
1076e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * This method may start an activity allowing the user to choose which permissions
1077e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * to grant and which to reject. Hence, you should be prepared that your activity
1078e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * may be paused and resumed. Further, granting some permissions may require
1079e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * a restart of you application. In such a case, the system will recreate the
1080e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * activity stack before delivering the result to {@link
1081e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * #onRequestPermissionsResult(int, String[], int[])}.
1082e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </p>
1083e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <p>
1084e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * When checking whether you have a permission you should use {@link
1085e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * android.content.Context#checkSelfPermission(String)}.
1086e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </p>
1087e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <p>
10882750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov     * Calling this API for permissions already granted to your app would show UI
10892750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov     * to the user to decided whether the app can still hold these permissions. This
10902750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov     * can be useful if the way your app uses the data guarded by the permissions
10912750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov     * changes significantly.
10922750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov     * </p>
10932750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov     * <p>
1094e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * A sample permissions request looks like this:
1095e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </p>
1096e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <code><pre><p>
1097e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * private void showContacts() {
1098e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *     if (getActivity().checkSelfPermission(Manifest.permission.READ_CONTACTS)
1099e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *             != PackageManager.PERMISSION_GRANTED) {
1100e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *         requestPermissions(new String[]{Manifest.permission.READ_CONTACTS},
1101e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *                 PERMISSIONS_REQUEST_READ_CONTACTS);
1102e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *     } else {
1103e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *         doShowContacts();
1104e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *     }
1105e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * }
1106e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *
1107e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * {@literal @}Override
1108e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * public void onRequestPermissionsResult(int requestCode, String[] permissions,
1109e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *         int[] grantResults) {
1110e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *     if (requestCode == PERMISSIONS_REQUEST_READ_CONTACTS
1111e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *             && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
1112e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *         doShowContacts();
1113e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *     }
1114e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * }
1115e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </code></pre></p>
1116e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *
1117e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @param permissions The requested permissions.
1118e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @param requestCode Application specific request code to match with a result
1119e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *    reported to {@link #onRequestPermissionsResult(int, String[], int[])}.
1120e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *
1121e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @see #onRequestPermissionsResult(int, String[], int[])
1122e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @see android.content.Context#checkSelfPermission(String)
1123e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     */
1124e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    public final void requestPermissions(@NonNull String[] permissions, int requestCode) {
1125e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav        if (mHost == null) {
1126e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
1127e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav        }
11285fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian        mHost.onRequestPermissionsFromFragment(this, permissions, requestCode);
1129e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    }
1130e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav
1131e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    /**
1132e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * Callback for the result from requesting permissions. This method
1133e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * is invoked for every call on {@link #requestPermissions(String[], int)}.
1134dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov     * <p>
1135dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov     * <strong>Note:</strong> It is possible that the permissions request interaction
1136dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov     * with the user is interrupted. In this case you will receive empty permissions
1137dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov     * and results arrays which should be treated as a cancellation.
1138dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov     * </p>
1139e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *
1140e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}.
1141e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @param permissions The requested permissions. Never null.
1142e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @param grantResults The grant results for the corresponding permissions
1143e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *     which is either {@link android.content.pm.PackageManager#PERMISSION_GRANTED}
1144e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *     or {@link android.content.pm.PackageManager#PERMISSION_DENIED}. Never null.
1145e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *
1146e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @see #requestPermissions(String[], int)
1147e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     */
1148e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
1149e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav            @NonNull int[] grantResults) {
1150e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav        /* callback - do nothing */
1151e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    }
1152e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav
1153e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    /**
1154e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * Gets whether you should show UI with rationale for requesting a permission.
1155e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * You should do this only if you do not have the permission and the context in
1156e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * which the permission is requested does not clearly communicate to the user
1157e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * what would be the benefit from granting this permission.
1158e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <p>
1159e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * For example, if you write a camera app, requesting the camera permission
1160e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * would be expected by the user and no rationale for why it is requested is
1161e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * needed. If however, the app needs location for tagging photos then a non-tech
1162e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * savvy user may wonder how location is related to taking photos. In this case
1163e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * you may choose to show UI with rationale of requesting this permission.
1164e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </p>
1165e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *
1166e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @param permission A permission your app wants to request.
1167e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @return Whether you can show permission rationale UI.
1168e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *
1169e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @see Context#checkSelfPermission(String)
1170e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @see #requestPermissions(String[], int)
1171e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @see #onRequestPermissionsResult(int, String[], int[])
1172e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     */
1173e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    public boolean shouldShowRequestPermissionRationale(@NonNull String permission) {
1174e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav        if (mHost != null) {
1175e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav            return mHost.onShouldShowRequestPermissionRationale(permission);
1176e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav        }
1177e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav        return false;
1178e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    }
1179e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav
1180e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    /**
118196221034e4a23a2abb83f772a0281bb197ac5ac0George Mount     * Returns the LayoutInflater used to inflate Views of this Fragment. The default
118296221034e4a23a2abb83f772a0281bb197ac5ac0George Mount     * implementation will throw an exception if the Fragment is not attached.
118396221034e4a23a2abb83f772a0281bb197ac5ac0George Mount     *
1184995c3504e6c5b1d20368c36193b44a7e6844709dGeorge Mount     * @param savedInstanceState If the fragment is being re-created from
1185995c3504e6c5b1d20368c36193b44a7e6844709dGeorge Mount     * a previous saved state, this is the state.
118696221034e4a23a2abb83f772a0281bb197ac5ac0George Mount     * @return The LayoutInflater used to inflate Views of this Fragment.
1187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1188b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton    @NonNull
1189b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton    public LayoutInflater onGetLayoutInflater(@Nullable Bundle savedInstanceState) {
11900abeed582ee0a105edb41181d76e8ee034750f22George Mount        // TODO: move the implementation in getLayoutInflater to here
11910abeed582ee0a105edb41181d76e8ee034750f22George Mount        return getLayoutInflater(savedInstanceState);
11920abeed582ee0a105edb41181d76e8ee034750f22George Mount    }
11930abeed582ee0a105edb41181d76e8ee034750f22George Mount
11940abeed582ee0a105edb41181d76e8ee034750f22George Mount    /**
11958b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * Returns the cached LayoutInflater used to inflate Views of this Fragment. If
11968b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * {@link #onGetLayoutInflater(Bundle)} has not been called {@link #onGetLayoutInflater(Bundle)}
11978b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * will be called with a {@code null} argument and that value will be cached.
11988b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * <p>
11998b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * The cached LayoutInflater will be replaced immediately prior to
12008b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} and cleared immediately after
12018b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * {@link #onDetach()}.
12028b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     *
12038b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * @return The LayoutInflater used to inflate Views of this Fragment.
12048b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     */
12058b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount    public final LayoutInflater getLayoutInflater() {
12068b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount        if (mLayoutInflater == null) {
12078b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount            return performGetLayoutInflater(null);
12088b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount        }
12098b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount        return mLayoutInflater;
12108b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount    }
12118b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount
12128b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount    /**
12138b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * Calls {@link #onGetLayoutInflater(Bundle)} and caches the result for use by
12148b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * {@link #getLayoutInflater()}.
12158b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     *
12168b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * @param savedInstanceState If the fragment is being re-created from
12178b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * a previous saved state, this is the state.
12188b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * @return The LayoutInflater used to inflate Views of this Fragment.
12198b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     */
1220b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton    @NonNull
1221b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton    LayoutInflater performGetLayoutInflater(@Nullable Bundle savedInstanceState) {
12228b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount        LayoutInflater layoutInflater = onGetLayoutInflater(savedInstanceState);
12238b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount        mLayoutInflater = layoutInflater;
12248b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount        return mLayoutInflater;
12258b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount    }
12268b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount
12278b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount    /**
12288b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * Override {@link #onGetLayoutInflater(Bundle)} when you need to change the
12298b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * LayoutInflater or call {@link #getLayoutInflater()} when you want to
12308b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * retrieve the current LayoutInflater.
12318b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     *
12320abeed582ee0a105edb41181d76e8ee034750f22George Mount     * @hide
12338b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * @deprecated Override {@link #onGetLayoutInflater(Bundle)} or call
12348b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount     * {@link #getLayoutInflater()} instead of this method.
12350abeed582ee0a105edb41181d76e8ee034750f22George Mount     */
12360abeed582ee0a105edb41181d76e8ee034750f22George Mount    @Deprecated
1237b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton    @NonNull
12380abeed582ee0a105edb41181d76e8ee034750f22George Mount    @RestrictTo(LIBRARY_GROUP)
1239b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton    public LayoutInflater getLayoutInflater(@Nullable Bundle savedFragmentState) {
124096221034e4a23a2abb83f772a0281bb197ac5ac0George Mount        if (mHost == null) {
12410abeed582ee0a105edb41181d76e8ee034750f22George Mount            throw new IllegalStateException("onGetLayoutInflater() cannot be executed until the "
124296221034e4a23a2abb83f772a0281bb197ac5ac0George Mount                    + "Fragment is attached to the FragmentManager.");
124396221034e4a23a2abb83f772a0281bb197ac5ac0George Mount        }
12448491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy        LayoutInflater result = mHost.onGetLayoutInflater();
12450f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell        getChildFragmentManager(); // Init if needed; use raw implementation below.
12464bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas        LayoutInflaterCompat.setFactory2(result, mChildFragmentManager.getLayoutInflaterFactory());
12470f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell        return result;
1248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1249d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1250cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a fragment is being created as part of a view layout
1252cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * inflation, typically from setting the content view of an activity.  This
12539277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * may be called immediately after the fragment is created from a <fragment>
1254cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tag in a layout file.  Note this is <em>before</em> the fragment's
1255cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onAttach(Activity)} has been called; all you should do here is
12569277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * parse the attributes and save them away.
12574bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>This is called every time the fragment is inflated, even if it is
12599277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * being inflated into a new instance with saved state.  It typically makes
12609277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * sense to re-parse the parameters each time, to allow them to change with
12619277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * different configurations.</p>
12629277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
12639277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>Here is a typical implementation of a fragment that can take parameters
12649277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * both through attributes supplied here as well from {@link #getArguments()}:</p>
12659277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
1266f266a0a76eb23a0a00ae16f823df2af73bff480fAurimas Liutikas     * {@sample frameworks/support/samples/Support4Demos/src/main/java/com/example/android/supportv4/app/FragmentArgumentsSupport.java
12679277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *      fragment}
12689277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
12699277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>Note that parsing the XML attributes uses a "styleable" resource.  The
12709277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * declaration for the styleable used here is:</p>
12719277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
1272f266a0a76eb23a0a00ae16f823df2af73bff480fAurimas Liutikas     * {@sample frameworks/support/samples/Support4Demos/src/main/res/values/attrs.xml fragment_arguments}
12734bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
12749277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>The fragment can then be declared within its activity's content layout
12759277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * through a tag like this:</p>
12769277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
1277f266a0a76eb23a0a00ae16f823df2af73bff480fAurimas Liutikas     * {@sample frameworks/support/samples/Support4Demos/src/main/res/layout/fragment_arguments_support.xml from_attributes}
12789277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
12799277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>This fragment can also be created dynamically from arguments given
12809277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * at runtime in the arguments Bundle; here is an example of doing so at
12819277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * creation of the containing activity:</p>
12829277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
1283f266a0a76eb23a0a00ae16f823df2af73bff480fAurimas Liutikas     * {@sample frameworks/support/samples/Support4Demos/src/main/java/com/example/android/supportv4/app/FragmentArgumentsSupport.java
12849277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *      create}
12859277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
1286d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * @param context The Activity that is inflating this fragment.
1287cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param attrs The attributes at the tag where the fragment is
1288cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * being created.
1289cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
1290cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * a previous saved state, this is the state.
1291cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1292916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1293d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) {
1294d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        mCalled = true;
1295d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        final Activity hostActivity = mHost == null ? null : mHost.getActivity();
1296d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        if (hostActivity != null) {
1297d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            mCalled = false;
1298d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            onInflate(hostActivity, attrs, savedInstanceState);
1299d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        }
1300d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    }
1301d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1302d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    /**
1303d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * Called when a fragment is being created as part of a view layout
1304d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * inflation, typically from setting the content view of an activity.
1305d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette     *
1306d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette     * @deprecated See {@link #onInflate(Context, AttributeSet, Bundle)}.
1307d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     */
1308d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    @Deprecated
1309916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
13109277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
1311cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1312cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
13139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
1314cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1315cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     * Called when a fragment is attached as a child of this fragment.
1316cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     *
1317cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     * <p>This is called after the attached fragment's <code>onAttach</code> and before
1318cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     * the attached fragment's <code>onCreate</code> if the fragment has not yet had a previous
1319cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     * call to <code>onCreate</code>.</p>
1320cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     *
1321cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     * @param childFragment child fragment being attached
1322cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     */
1323cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell    public void onAttachFragment(Fragment childFragment) {
1324cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell    }
1325cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell
1326cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell    /**
1327d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * Called when a fragment is first attached to its context.
1328d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * {@link #onCreate(Bundle)} will be called after this.
1329d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     */
1330916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1331d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    public void onAttach(Context context) {
1332d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        mCalled = true;
1333d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        final Activity hostActivity = mHost == null ? null : mHost.getActivity();
1334d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        if (hostActivity != null) {
1335d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            mCalled = false;
1336d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            onAttach(hostActivity);
1337d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        }
1338d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    }
1339d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1340d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    /**
1341cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a fragment is first attached to its activity.
1342cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreate(Bundle)} will be called after this.
1343d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette     *
1344d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette     * @deprecated See {@link #onAttach(Context)}.
1345cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1346d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    @Deprecated
1347916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1348cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onAttach(Activity activity) {
1349cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1350cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1351d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1352cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
135315e593ea3575512d7072240d1db9d74fad8749a3George Mount     * Called when a fragment loads an animation. Note that if
135415e593ea3575512d7072240d1db9d74fad8749a3George Mount     * {@link FragmentTransaction#setCustomAnimations(int, int)} was called with
135515e593ea3575512d7072240d1db9d74fad8749a3George Mount     * {@link Animator} resources instead of {@link Animation} resources, {@code nextAnim}
135615e593ea3575512d7072240d1db9d74fad8749a3George Mount     * will be an animator resource.
135715e593ea3575512d7072240d1db9d74fad8749a3George Mount     *
135815e593ea3575512d7072240d1db9d74fad8749a3George Mount     * @param transit The value set in {@link FragmentTransaction#setTransition(int)} or 0 if not
135915e593ea3575512d7072240d1db9d74fad8749a3George Mount     *                set.
136015e593ea3575512d7072240d1db9d74fad8749a3George Mount     * @param enter {@code true} when the fragment is added/attached/shown or {@code false} when
136115e593ea3575512d7072240d1db9d74fad8749a3George Mount     *              the fragment is removed/detached/hidden.
136215e593ea3575512d7072240d1db9d74fad8749a3George Mount     * @param nextAnim The resource set in
136315e593ea3575512d7072240d1db9d74fad8749a3George Mount     *                 {@link FragmentTransaction#setCustomAnimations(int, int)},
136415e593ea3575512d7072240d1db9d74fad8749a3George Mount     *                 {@link FragmentTransaction#setCustomAnimations(int, int, int, int)}, or
136515e593ea3575512d7072240d1db9d74fad8749a3George Mount     *                 0 if neither was called. The value will depend on the current operation.
1366cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
13679277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
1368cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return null;
1369cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1370d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1371cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
137215e593ea3575512d7072240d1db9d74fad8749a3George Mount     * Called when a fragment loads an animator. This will be called when
137315e593ea3575512d7072240d1db9d74fad8749a3George Mount     * {@link #onCreateAnimation(int, boolean, int)} returns null. Note that if
137415e593ea3575512d7072240d1db9d74fad8749a3George Mount     * {@link FragmentTransaction#setCustomAnimations(int, int)} was called with
137515e593ea3575512d7072240d1db9d74fad8749a3George Mount     * {@link Animation} resources instead of {@link Animator} resources, {@code nextAnim}
137615e593ea3575512d7072240d1db9d74fad8749a3George Mount     * will be an animation resource.
137715e593ea3575512d7072240d1db9d74fad8749a3George Mount     *
137815e593ea3575512d7072240d1db9d74fad8749a3George Mount     * @param transit The value set in {@link FragmentTransaction#setTransition(int)} or 0 if not
137915e593ea3575512d7072240d1db9d74fad8749a3George Mount     *                set.
138015e593ea3575512d7072240d1db9d74fad8749a3George Mount     * @param enter {@code true} when the fragment is added/attached/shown or {@code false} when
138115e593ea3575512d7072240d1db9d74fad8749a3George Mount     *              the fragment is removed/detached/hidden.
138215e593ea3575512d7072240d1db9d74fad8749a3George Mount     * @param nextAnim The resource set in
138315e593ea3575512d7072240d1db9d74fad8749a3George Mount     *                 {@link FragmentTransaction#setCustomAnimations(int, int)},
138415e593ea3575512d7072240d1db9d74fad8749a3George Mount     *                 {@link FragmentTransaction#setCustomAnimations(int, int, int, int)}, or
138515e593ea3575512d7072240d1db9d74fad8749a3George Mount     *                 0 if neither was called. The value will depend on the current operation.
138615e593ea3575512d7072240d1db9d74fad8749a3George Mount     */
138715e593ea3575512d7072240d1db9d74fad8749a3George Mount    public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
138815e593ea3575512d7072240d1db9d74fad8749a3George Mount        return null;
138915e593ea3575512d7072240d1db9d74fad8749a3George Mount    }
139015e593ea3575512d7072240d1db9d74fad8749a3George Mount
139115e593ea3575512d7072240d1db9d74fad8749a3George Mount    /**
1392cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called to do initial creation of a fragment.  This is called after
1393cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onAttach(Activity)} and before
1394cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
13954bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1396cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>Note that this can be called while the fragment's activity is
1397cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * still in the process of being created.  As such, you can not rely
1398cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * on things like the activity's content view hierarchy being initialized
1399cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * at this point.  If you want to do work once the activity itself is
1400cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * created, see {@link #onActivityCreated(Bundle)}.
1401277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell     *
1402277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell     * <p>Any restored child fragments will be created before the base
1403277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell     * <code>Fragment.onCreate</code> method returns.</p>
14044bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1405cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
1406cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * a previous saved state, this is the state.
1407cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1408916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1409c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy    public void onCreate(@Nullable Bundle savedInstanceState) {
1410cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
14119375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell        restoreChildFragmentState(savedInstanceState);
1412fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell        if (mChildFragmentManager != null
1413fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell                && !mChildFragmentManager.isStateAtLeast(Fragment.CREATED)) {
1414fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell            mChildFragmentManager.dispatchCreate();
1415fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell        }
14169375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell    }
14179375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell
14189375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell    /**
14199375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * Restore the state of the child FragmentManager. Called by either
14209375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * {@link #onCreate(Bundle)} for non-retained instance fragments or by
14219375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * {@link FragmentManagerImpl#moveToState(Fragment, int, int, int, boolean)}
14229375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * for retained instance fragments.
14239375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     *
14249375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * <p><strong>Postcondition:</strong> if there were child fragments to restore,
14259375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * the child FragmentManager will be instantiated and brought to the {@link #CREATED} state.
14269375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * </p>
14279375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     *
14289375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * @param savedInstanceState the savedInstanceState potentially containing fragment info
14299375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     */
14309375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell    void restoreChildFragmentState(@Nullable Bundle savedInstanceState) {
1431277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell        if (savedInstanceState != null) {
1432277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell            Parcelable p = savedInstanceState.getParcelable(
1433277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell                    FragmentActivity.FRAGMENTS_TAG);
1434277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell            if (p != null) {
1435277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell                if (mChildFragmentManager == null) {
1436277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell                    instantiateChildFragmentManager();
1437277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell                }
1438c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell                mChildFragmentManager.restoreAllState(p, mChildNonConfig);
1439c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell                mChildNonConfig = null;
1440277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell                mChildFragmentManager.dispatchCreate();
1441277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell            }
1442277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell        }
1443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
14440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
1445cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1446cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called to have the fragment instantiate its user interface view.
1447cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This is optional, and non-graphical fragments can return null (which
1448cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is the default implementation).  This will be called between
1449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}.
14504bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1451cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>If you return a View from here, you will later be called in
1452cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onDestroyView} when the view is being released.
14534bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param inflater The LayoutInflater object that can be used to inflate
1455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * any views in the fragment,
1456cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param container If non-null, this is the parent view that the fragment's
1457cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * UI should be attached to.  The fragment should not add the view itself,
1458cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * but this can be used to generate the LayoutParams of the view.
1459cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If non-null, this fragment is being re-constructed
1460cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * from a previous saved state as given here.
14614bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1462cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return Return the View for the fragment's UI, or null.
1463cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1464c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy    @Nullable
1465b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
1466a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye            @Nullable Bundle savedInstanceState) {
1467cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return null;
1468cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
14690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
1470cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1471e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
1472e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * has returned, but before any saved state has been restored in to the view.
1473e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * This gives subclasses a chance to initialize themselves once
1474e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * they know their view hierarchy has been completely created.  The fragment's
1475e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * view hierarchy is not however attached to its parent at this point.
1476e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
1477e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * @param savedInstanceState If non-null, this fragment is being re-constructed
1478e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * from a previous saved state as given here.
1479e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     */
1480cb3829a5ee01e3c0783019c04d083bde4d0082e8Jake Wharton    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
1481e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    }
1482e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn
1483e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    /**
1484cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}),
1485cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * if provided.
14864bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1487cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return The fragment's root view, or null if it has no layout.
1488cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1489a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye    @Nullable
1490cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public View getView() {
1491cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mView;
1492cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
14934bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1494cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1495cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment's activity has been created and this
1496cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * fragment's view hierarchy instantiated.  It can be used to do final
1497cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * initialization once these pieces are in place, such as retrieving
1498cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * views or restoring state.  It is also useful for fragments that use
1499cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #setRetainInstance(boolean)} to retain their instance,
1500cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * as this callback tells the fragment when it is fully associated with
1501cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the new activity instance.  This is called after {@link #onCreateView}
15020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * and before {@link #onViewStateRestored(Bundle)}.
15030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     *
1504cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
1505cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * a previous saved state, this is the state.
1506cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1507916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1508a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
1509cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1510cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
15110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
15120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    /**
15130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * Called when all saved state has been restored into the view hierarchy
15140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * of the fragment.  This can be used to do initialization based on saved
15150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * state that you are letting the view hierarchy track itself, such as
15160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * whether check box widgets are currently checked.  This is called
15170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * after {@link #onActivityCreated(Bundle)} and before
15180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * {@link #onStart()}.
15190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     *
15200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
15210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * a previous saved state, this is the state.
15220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     */
1523916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1524a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye    public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
15250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = true;
15260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
15270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
1528cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1529cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the Fragment is visible to the user.  This is generally
1530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onStart() Activity.onStart} of the containing
1531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
1532cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1533916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1534cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onStart() {
1535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1537d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1539cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment is visible to the user and actively running.
1540cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This is generally
1541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onResume() Activity.onResume} of the containing
1542cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
1543cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1544916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onResume() {
1546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
15484bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called to ask the fragment to save its current dynamic state, so it
1551cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * can later be reconstructed in a new instance of its process is
1552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * restarted.  If a new instance of the fragment later needs to be
1553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * created, the data you place in the Bundle here will be available
1554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * in the Bundle given to {@link #onCreate(Bundle)},
1555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}, and
1556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onActivityCreated(Bundle)}.
1557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1558cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>This corresponds to {@link Activity#onSaveInstanceState(Bundle)
1559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity.onSaveInstanceState(Bundle)} and most of the discussion there
1560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * applies here as well.  Note however: <em>this method may be called
1561cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * at any time before {@link #onDestroy()}</em>.  There are many situations
1562cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * where a fragment may be mostly torn down (such as when placed on the
1563cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * back stack with no UI showing), but its state will not be saved until
1564cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * its owning activity actually needs to save its state.
1565cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1566cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param outState Bundle in which to place your saved state.
1567cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1568abdae2e27083efa81020e1619250fb2864f3bbc4Jake Wharton    public void onSaveInstanceState(@NonNull Bundle outState) {
1569cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
15705fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian
15715fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    /**
15725fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     * Called when the Fragment's activity changes from fullscreen mode to multi-window mode and
15735fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     * visa-versa. This is generally tied to {@link Activity#onMultiWindowModeChanged} of the
15745fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     * containing Activity.
15755fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     *
15765fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     * @param isInMultiWindowMode True if the activity is in multi-window mode.
15775fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     */
15785fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
15795fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    }
15805fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian
15815fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    /**
15825fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     * Called by the system when the activity changes to and from picture-in-picture mode. This is
15835fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     * generally tied to {@link Activity#onPictureInPictureModeChanged} of the containing Activity.
15845fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     *
15855fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode.
15865fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     */
15875fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
15885fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    }
15895fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian
159090ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas    @Override
1591916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1592cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onConfigurationChanged(Configuration newConfig) {
1593cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1594cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
15955fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian
1596cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1597cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the Fragment is no longer resumed.  This is generally
1598cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onPause() Activity.onPause} of the containing
1599cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
1600cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1601916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1602cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onPause() {
1603cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1604cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
16054bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1606cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1607cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the Fragment is no longer started.  This is generally
1608cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onStop() Activity.onStop} of the containing
1609cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
1610cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1611916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1612cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onStop() {
1613cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1614cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1615916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell
161690ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas    @Override
1617916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1618cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onLowMemory() {
1619cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1620cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
16214bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1622cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1623cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the view previously created by {@link #onCreateView} has
1624cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * been detached from the fragment.  The next time the fragment needs
1625cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to be displayed, a new view will be created.  This is called
1626cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * after {@link #onStop()} and before {@link #onDestroy()}.  It is called
1627cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <em>regardless</em> of whether {@link #onCreateView} returned a
1628cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * non-null view.  Internally it is called after the view's state has
1629cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * been saved but before it has been removed from its parent.
1630cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1631916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1632cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDestroyView() {
1633cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1634cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
16354bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1636cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1637cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment is no longer in use.  This is called
1638cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * after {@link #onStop()} and before {@link #onDetach()}.
1639cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1640916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1641cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDestroy() {
1642cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
16430d429d5f5bb0d6197d5c7a24b5c0bb5bcd5db8cdIan Lake        // Use mStateSaved instead of isStateSaved() since we're past onStop()
16440d429d5f5bb0d6197d5c7a24b5c0bb5bcd5db8cdIan Lake        if (mViewModelStore != null && !mHost.mFragmentManager.mStateSaved) {
164541516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake            mViewModelStore.clear();
164641516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake        }
1647cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1648cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1649cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
16509c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * Called by the fragment manager once this fragment has been removed,
16519c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * so that we don't have any left-over state if the application decides
16529c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * to re-use the instance.  This only clears state that the framework
16539c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * internally manages, not things the application sets.
16549c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     */
16559c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    void initState() {
16569c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mIndex = -1;
16579c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mWho = null;
16589c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mAdded = false;
16599c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mRemoving = false;
16609c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mFromLayout = false;
16619c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mInLayout = false;
16629c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mRestored = false;
16639c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mBackStackNesting = 0;
16649c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mFragmentManager = null;
16656252d78085a07c9d6bb4645a4e8086bf23b0a49aTim Kilbourn        mChildFragmentManager = null;
1666d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        mHost = null;
16679c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mFragmentId = 0;
16689c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mContainerId = 0;
16699c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mTag = null;
16709c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mHidden = false;
16719c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mDetached = false;
16729c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mRetaining = false;
16739c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
16749c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
16759c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    /**
1676cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment is no longer attached to its activity.  This
1677cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is called after {@link #onDestroy()}.
1678cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1679916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1680cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDetach() {
1681cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1682cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
16834bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1684cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
16859375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * Initialize the contents of the Fragment host's standard options menu.  You
1686cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * should place your menu items in to <var>menu</var>.  For this method
1687cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to be called, you must have first called {@link #setHasOptionsMenu}.  See
1688cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu}
1689cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for more information.
16904bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1691cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param menu The options menu in which you place your items.
16924bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #setHasOptionsMenu
1694cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onPrepareOptionsMenu
1695cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onOptionsItemSelected
1696cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1697cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
1698cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1699cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1700cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
17019375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * Prepare the Fragment host's standard options menu to be displayed.  This is
1702cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * called right before the menu is shown, every time it is shown.  You can
1703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * use this method to efficiently enable/disable items or otherwise
1704cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * dynamically modify the contents.  See
1705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu}
1706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for more information.
17074bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1708cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param menu The options menu as last shown or first initialized by
1709cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *             onCreateOptionsMenu().
17104bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1711cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #setHasOptionsMenu
1712cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onCreateOptionsMenu
1713cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1714cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onPrepareOptionsMenu(Menu menu) {
1715cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1716cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1717cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1718cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when this fragment's option menu items are no longer being
1719cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * included in the overall options menu.  Receiving this call means that
1720cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the menu needed to be rebuilt, but this fragment's items were not
1721cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * included in the newly built menu (its {@link #onCreateOptionsMenu(Menu, MenuInflater)}
1722cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * was not called).
1723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1724cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDestroyOptionsMenu() {
1725cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
17264bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1727cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1728cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This hook is called whenever an item in your options menu is selected.
1729cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * The default implementation simply returns false to have the normal
1730cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * processing happen (calling the item's Runnable or sending a message to
1731cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * its Handler as appropriate).  You can use this method for any items
1732cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for which you would like to do processing without those other
1733cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * facilities.
17344bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1735cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>Derived classes should call through to the base class for it to
1736cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * perform the default menu handling.
17374bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1738cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param item The menu item that was selected.
17394bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1740cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return boolean Return false to allow normal menu processing to
1741cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *         proceed, true to consume it here.
17424bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1743cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onCreateOptionsMenu
1744cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1745cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean onOptionsItemSelected(MenuItem item) {
1746cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return false;
1747cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1748cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1749cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1750cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This hook is called whenever the options menu is being closed (either by the user canceling
1751cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the menu with the back/menu button, or when an item is selected).
17524bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1753cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param menu The options menu as last shown or first initialized by
1754cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *             onCreateOptionsMenu().
1755cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1756cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onOptionsMenuClosed(Menu menu) {
1757cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
17584bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1759cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1760cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a context menu for the {@code view} is about to be shown.
1761cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Unlike {@link #onCreateOptionsMenu}, this will be called every
1762cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * time the context menu is about to be shown and should be populated for
1763cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the view (or item inside the view for {@link AdapterView} subclasses,
1764cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * this can be found in the {@code menuInfo})).
1765cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1766cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an
1767cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * item has been selected.
1768cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1769cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * The default implementation calls up to
1770cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though
1771cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * you can not call this implementation if you don't want that behavior.
1772cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1773cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * It is not safe to hold onto the context menu after this method returns.
1774cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@inheritDoc}
1775cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1776d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    @Override
1777cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
1778cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        getActivity().onCreateContextMenu(menu, v, menuInfo);
1779cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1780cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1781cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1782cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Registers a context menu to be shown for the given view (multiple views
1783cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * can show the context menu). This method will set the
1784cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link OnCreateContextMenuListener} on the view to this fragment, so
1785cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be
1786cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * called when it is time to show the context menu.
17874bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1788cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #unregisterForContextMenu(View)
1789cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param view The view that should show a context menu.
1790cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1791cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void registerForContextMenu(View view) {
1792cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        view.setOnCreateContextMenuListener(this);
1793cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
17944bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1795cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1796cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Prevents a context menu to be shown for the given view. This method will
1797cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * remove the {@link OnCreateContextMenuListener} on the view.
17984bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1799cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #registerForContextMenu(View)
1800cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param view The view that should stop showing a context menu.
1801cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1802cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void unregisterForContextMenu(View view) {
1803cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        view.setOnCreateContextMenuListener(null);
1804cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
18054bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1806cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1807cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This hook is called whenever an item in a context menu is selected. The
1808cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default implementation simply returns false to have the normal processing
1809cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * happen (calling the item's Runnable or sending a message to its Handler
1810cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * as appropriate). You can use this method for any items for which you
1811cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * would like to do processing without those other facilities.
1812cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1813cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Use {@link MenuItem#getMenuInfo()} to get extra information set by the
1814cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * View that added this menu item.
1815cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1816cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Derived classes should call through to the base class for it to perform
1817cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the default menu handling.
18184bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1819cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param item The context menu item that was selected.
1820cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return boolean Return false to allow normal context menu processing to
1821cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *         proceed, true to consume it here.
1822cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1823cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean onContextItemSelected(MenuItem item) {
1824cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return false;
1825cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1826e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes
1827cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
18289306f07b1d66f4974a81f781d29739b30124fff0George Mount     * When custom transitions are used with Fragments, the enter transition callback
18299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * is called when this Fragment is attached or detached when not popping the back stack.
18309f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
18319306f07b1d66f4974a81f781d29739b30124fff0George Mount     * @param callback Used to manipulate the shared element transitions on this Fragment
18329f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                 when added not as a pop from the back stack.
18339f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
1834b1413bc4de16e05ae0455cad93f1edfbcc4eced2George Mount    public void setEnterSharedElementCallback(SharedElementCallback callback) {
1835990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mEnterTransitionCallback = callback;
18369f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
18379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
18389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
18399306f07b1d66f4974a81f781d29739b30124fff0George Mount     * When custom transitions are used with Fragments, the exit transition callback
18409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * is called when this Fragment is attached or detached when popping the back stack.
18419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
18429306f07b1d66f4974a81f781d29739b30124fff0George Mount     * @param callback Used to manipulate the shared element transitions on this Fragment
18439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                 when added as a pop from the back stack.
18449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
1845b1413bc4de16e05ae0455cad93f1edfbcc4eced2George Mount    public void setExitSharedElementCallback(SharedElementCallback callback) {
1846990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mExitTransitionCallback = callback;
18479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
18489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
18499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
18509f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets the Transition that will be used to move Views into the initial scene. The entering
18519f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Views will be those that are regular Views or ViewGroups that have
18529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
18539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.Visibility} as entering is governed by changing visibility from
18549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
18559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * entering Views will remain unaffected.
18569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
18579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param transition The Transition to use to move Views into the initial Scene.
18589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
18592a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    public void setEnterTransition(@Nullable Object transition) {
1860990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mEnterTransition = transition;
18619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
18629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
18639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
18649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Returns the Transition that will be used to move Views into the initial scene. The entering
18659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Views will be those that are regular Views or ViewGroups that have
18669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
18679f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.Visibility} as entering is governed by changing visibility from
18689f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link View#INVISIBLE} to {@link View#VISIBLE}.
18699f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
18709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return the Transition to use to move Views into the initial Scene.
18719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
18722a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @Nullable
18739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public Object getEnterTransition() {
1874990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
1875990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
1876990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
1877990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mEnterTransition;
18789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
18799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
18809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
18819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets the Transition that will be used to move Views out of the scene when the Fragment is
18829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * preparing to be removed, hidden, or detached because of popping the back stack. The exiting
18839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Views will be those that are regular Views or ViewGroups that have
18849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
18859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.Visibility} as entering is governed by changing visibility from
18869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
18879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * entering Views will remain unaffected. If nothing is set, the default will be to
18889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * use the same value as set in {@link #setEnterTransition(Object)}.
18899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
18909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param transition The Transition to use to move Views out of the Scene when the Fragment
1891a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay     *         is preparing to close. <code>transition</code> must be an
1892a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay     *         {@link android.transition.Transition android.transition.Transition} or
1893ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas     *         {@link androidx.transition.Transition androidx.transition.Transition}.
18949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
18952a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    public void setReturnTransition(@Nullable Object transition) {
1896990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mReturnTransition = transition;
18979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
18989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
18999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
19009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Returns the Transition that will be used to move Views out of the scene when the Fragment is
19019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * preparing to be removed, hidden, or detached because of popping the back stack. The exiting
19029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Views will be those that are regular Views or ViewGroups that have
19039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
19049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.Visibility} as entering is governed by changing visibility from
19059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
19069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * entering Views will remain unaffected.
19079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
19089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return the Transition to use to move Views out of the Scene when the Fragment
19099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *         is preparing to close.
19109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
19112a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @Nullable
19129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public Object getReturnTransition() {
1913990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
1914990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
1915990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
1916990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mReturnTransition == USE_DEFAULT_TRANSITION ? getEnterTransition()
1917990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                : mAnimationInfo.mReturnTransition;
19189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
19199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
19209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
19219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets the Transition that will be used to move Views out of the scene when the
19229f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * fragment is removed, hidden, or detached when not popping the back stack.
19239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * The exiting Views will be those that are regular Views or ViewGroups that
19249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
19259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.Visibility} as exiting is governed by changing visibility
19269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
19279f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * remain unaffected.
19289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
19299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param transition The Transition to use to move Views out of the Scene when the Fragment
1930a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay     *          is being closed not due to popping the back stack. <code>transition</code>
1931a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay     *          must be an
1932a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay     *          {@link android.transition.Transition android.transition.Transition} or
1933ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas     *          {@link androidx.transition.Transition androidx.transition.Transition}.
19349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
19352a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    public void setExitTransition(@Nullable Object transition) {
1936990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mExitTransition = transition;
19379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
19389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
19399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
19409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Returns the Transition that will be used to move Views out of the scene when the
19419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * fragment is removed, hidden, or detached when not popping the back stack.
19429f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * The exiting Views will be those that are regular Views or ViewGroups that
19439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
19449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.Visibility} as exiting is governed by changing visibility
19459f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
19469f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * remain unaffected.
19479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
19489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return the Transition to use to move Views out of the Scene when the Fragment
19499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *         is being closed not due to popping the back stack.
19509f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
19512a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @Nullable
19529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public Object getExitTransition() {
1953990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
1954990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
1955990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
1956990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mExitTransition;
19579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
19589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
19599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
19609f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets the Transition that will be used to move Views in to the scene when returning due
19619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * to popping a back stack. The entering Views will be those that are regular Views
19629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
19639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * will extend {@link android.transition.Visibility} as exiting is governed by changing
19649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
19659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * the views will remain unaffected. If nothing is set, the default will be to use the same
19669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * transition as {@link #setExitTransition(Object)}.
19679f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
19689f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param transition The Transition to use to move Views into the scene when reentering from a
1969a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay     *          previously-started Activity. <code>transition</code>
1970a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay     *          must be an
1971a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay     *          {@link android.transition.Transition android.transition.Transition} or
1972ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas     *          {@link androidx.transition.Transition androidx.transition.Transition}.
19739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
19742a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    public void setReenterTransition(@Nullable Object transition) {
1975990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mReenterTransition = transition;
19769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
19779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
19789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
19799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Returns the Transition that will be used to move Views in to the scene when returning due
19809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * to popping a back stack. The entering Views will be those that are regular Views
19819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
19829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * will extend {@link android.transition.Visibility} as exiting is governed by changing
19839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
19849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * the views will remain unaffected. If nothing is set, the default will be to use the same
19859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * transition as {@link #setExitTransition(Object)}.
19869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
19879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return the Transition to use to move Views into the scene when reentering from a
19889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                   previously-started Activity.
19899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
19909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public Object getReenterTransition() {
1991990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
1992990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
1993990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
1994990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mReenterTransition == USE_DEFAULT_TRANSITION ? getExitTransition()
1995990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                : mAnimationInfo.mReenterTransition;
19969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
19979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
19989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
19999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets the Transition that will be used for shared elements transferred into the content
20009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Scene. Typical Transitions will affect size and location, such as
20019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.ChangeBounds}. A null
20029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * value will cause transferred shared elements to blink to the final position.
20039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
20049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param transition The Transition to use for shared elements transferred into the content
2005a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay     *          Scene.  <code>transition</code> must be an
2006a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay     *          {@link android.transition.Transition android.transition.Transition} or
2007ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas     *          {@link androidx.transition.Transition androidx.transition.Transition}.
20089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
20092a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    public void setSharedElementEnterTransition(@Nullable Object transition) {
2010990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mSharedElementEnterTransition = transition;
20119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
20129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
20139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
20149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Returns the Transition that will be used for shared elements transferred into the content
20159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Scene. Typical Transitions will affect size and location, such as
20169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.ChangeBounds}. A null
20179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * value will cause transferred shared elements to blink to the final position.
20189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
20199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return The Transition to use for shared elements transferred into the content
20209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                   Scene.
20219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
20222a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @Nullable
20239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public Object getSharedElementEnterTransition() {
2024990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2025990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
2026990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2027990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mSharedElementEnterTransition;
20289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
20299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
20309f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
20319f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets the Transition that will be used for shared elements transferred back during a
20329f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * pop of the back stack. This Transition acts in the leaving Fragment.
20339f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Typical Transitions will affect size and location, such as
20349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.ChangeBounds}. A null
20359f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * value will cause transferred shared elements to blink to the final position.
20369f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * If no value is set, the default will be to use the same value as
20379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link #setSharedElementEnterTransition(Object)}.
20389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
20399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param transition The Transition to use for shared elements transferred out of the content
2040a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay     *          Scene. <code>transition</code> must be an
2041a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay     *          {@link android.transition.Transition android.transition.Transition} or
2042ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas     *          {@link androidx.transition.Transition androidx.transition.Transition}.
20439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
20442a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    public void setSharedElementReturnTransition(@Nullable Object transition) {
2045990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mSharedElementReturnTransition = transition;
20469f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
20479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
20489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
20499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Return the Transition that will be used for shared elements transferred back during a
20509f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * pop of the back stack. This Transition acts in the leaving Fragment.
20519f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Typical Transitions will affect size and location, such as
20529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.ChangeBounds}. A null
20539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * value will cause transferred shared elements to blink to the final position.
20549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * If no value is set, the default will be to use the same value as
20559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link #setSharedElementEnterTransition(Object)}.
20569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
20579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return The Transition to use for shared elements transferred out of the content
20589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                   Scene.
20599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
20602a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton    @Nullable
20619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public Object getSharedElementReturnTransition() {
2062990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2063990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
2064990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2065990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mSharedElementReturnTransition == USE_DEFAULT_TRANSITION
2066990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                ? getSharedElementEnterTransition()
2067990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                : mAnimationInfo.mSharedElementReturnTransition;
20689f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
20699f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
20709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
20719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets whether the the exit transition and enter transition overlap or not.
20729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * When true, the enter transition will start as soon as possible. When false, the
20739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * enter transition will wait until the exit transition completes before starting.
20749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
20759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param allow true to start the enter transition when possible or false to
20769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *              wait until the exiting transition completes.
20779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
20789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public void setAllowEnterTransitionOverlap(boolean allow) {
2079990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mAllowEnterTransitionOverlap = allow;
20809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
20819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
20829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
20839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Returns whether the the exit transition and enter transition overlap or not.
20849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * When true, the enter transition will start as soon as possible. When false, the
20859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * enter transition will wait until the exit transition completes before starting.
20869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
20879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return true when the enter transition should start as soon as possible or false to
20889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * when it should wait until the exiting transition completes.
20899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
20909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public boolean getAllowEnterTransitionOverlap() {
2091990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return (mAnimationInfo == null || mAnimationInfo.mAllowEnterTransitionOverlap == null)
2092990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                ? true : mAnimationInfo.mAllowEnterTransitionOverlap;
20939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
20949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
20959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
20969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets whether the the return transition and reenter transition overlap or not.
20979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * When true, the reenter transition will start as soon as possible. When false, the
20989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * reenter transition will wait until the return transition completes before starting.
20999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
21009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param allow true to start the reenter transition when possible or false to wait until the
21019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *              return transition completes.
21029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
21039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public void setAllowReturnTransitionOverlap(boolean allow) {
2104990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mAllowReturnTransitionOverlap = allow;
21059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
21069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
21079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
21089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Returns whether the the return transition and reenter transition overlap or not.
21099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * When true, the reenter transition will start as soon as possible. When false, the
21109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * reenter transition will wait until the return transition completes before starting.
21119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
21129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return true to start the reenter transition when possible or false to wait until the
21139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *         return transition completes.
21149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
21159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public boolean getAllowReturnTransitionOverlap() {
2116990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return (mAnimationInfo == null || mAnimationInfo.mAllowReturnTransitionOverlap == null)
2117990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                ? true : mAnimationInfo.mAllowReturnTransitionOverlap;
2118990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2119990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2120990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    /**
2121990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * Postpone the entering Fragment transition until {@link #startPostponedEnterTransition()}
2122990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * or {@link FragmentManager#executePendingTransactions()} has been called.
2123990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * <p>
2124990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * This method gives the Fragment the ability to delay Fragment animations
2125990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * until all data is loaded. Until then, the added, shown, and
2126990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * attached Fragments will be INVISIBLE and removed, hidden, and detached Fragments won't
2127990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * be have their Views removed. The transaction runs when all postponed added Fragments in the
2128990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * transaction have called {@link #startPostponedEnterTransition()}.
2129990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * <p>
2130990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * This method should be called before being added to the FragmentTransaction or
2131990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * in {@link #onCreate(Bundle), {@link #onAttach(Context)}, or
2132990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}}.
2133990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * {@link #startPostponedEnterTransition()} must be called to allow the Fragment to
2134990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * start the transitions.
2135990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * <p>
2136990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * When a FragmentTransaction is started that may affect a postponed FragmentTransaction,
2137990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * based on which containers are in their operations, the postponed FragmentTransaction
2138990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * will have its start triggered. The early triggering may result in faulty or nonexistent
2139990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * animations in the postponed transaction. FragmentTransactions that operate only on
2140990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * independent containers will not interfere with each other's postponement.
2141990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * <p>
2142990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * Calling postponeEnterTransition on Fragments with a null View will not postpone the
2143fda5be2466024a656152015c45a7681361d399bbGeorge Mount     * transition. Likewise, postponement only works if
2144fda5be2466024a656152015c45a7681361d399bbGeorge Mount     * {@link FragmentTransaction#setReorderingAllowed(boolean) FragmentTransaction reordering} is
2145990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * enabled.
2146990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     *
2147990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * @see Activity#postponeEnterTransition()
2148fda5be2466024a656152015c45a7681361d399bbGeorge Mount     * @see FragmentTransaction#setReorderingAllowed(boolean)
2149990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     */
2150990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    public void postponeEnterTransition() {
2151990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mEnterTransitionPostponed = true;
2152990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2153990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2154990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    /**
2155990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * Begin postponed transitions after {@link #postponeEnterTransition()} was called.
2156990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * If postponeEnterTransition() was called, you must call startPostponedEnterTransition()
2157990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * or {@link FragmentManager#executePendingTransactions()} to complete the FragmentTransaction.
2158990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * If postponement was interrupted with {@link FragmentManager#executePendingTransactions()},
2159990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * before {@code startPostponedEnterTransition()}, animations may not run or may execute
2160990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * improperly.
2161990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     *
2162990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * @see Activity#startPostponedEnterTransition()
2163990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     */
2164990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    public void startPostponedEnterTransition() {
2165990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mFragmentManager == null || mFragmentManager.mHost == null) {
2166990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            ensureAnimationInfo().mEnterTransitionPostponed = false;
2167990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        } else if (Looper.myLooper() != mFragmentManager.mHost.getHandler().getLooper()) {
2168990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            mFragmentManager.mHost.getHandler().postAtFrontOfQueue(new Runnable() {
2169990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                @Override
2170990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                public void run() {
2171990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                    callStartTransitionListener();
2172990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                }
2173990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            });
2174990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        } else {
2175990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            callStartTransitionListener();
2176990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2177990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2178990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2179990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    /**
2180990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * Calls the start transition listener. This must be called on the UI thread.
2181990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     */
2182990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    private void callStartTransitionListener() {
2183990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        final OnStartEnterTransitionListener listener;
2184990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2185990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            listener = null;
2186990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        } else {
2187990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            mAnimationInfo.mEnterTransitionPostponed = false;
2188990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            listener = mAnimationInfo.mStartEnterTransitionListener;
2189990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            mAnimationInfo.mStartEnterTransitionListener = null;
2190990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2191990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (listener != null) {
2192990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            listener.onStartEnterTransition();
2193990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
21949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
21959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
21969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
2197cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Print the Fragments's state into the given stream.
2198cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
2199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param prefix Text to print at the front of each line.
2200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param fd The raw file descriptor that the dump is being sent to.
2201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param writer The PrintWriter to which you should dump your state.  This will be
2202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * closed for you after you return.
2203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param args additional arguments to the dump request.
2204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
2205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
2206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mFragmentId=#");
2207cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(Integer.toHexString(mFragmentId));
22085506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                writer.print(" mContainerId=#");
2209cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(Integer.toHexString(mContainerId));
2210cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mTag="); writer.println(mTag);
2211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mState="); writer.print(mState);
2212cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mIndex="); writer.print(mIndex);
2213cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mWho="); writer.print(mWho);
2214cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mBackStackNesting="); writer.println(mBackStackNesting);
2215cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mAdded="); writer.print(mAdded);
2216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mRemoving="); writer.print(mRemoving);
2217cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mFromLayout="); writer.print(mFromLayout);
2218cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mInLayout="); writer.println(mInLayout);
2219cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mHidden="); writer.print(mHidden);
2220e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                writer.print(" mDetached="); writer.print(mDetached);
22212a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn                writer.print(" mMenuVisible="); writer.print(mMenuVisible);
2222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mHasMenu="); writer.println(mHasMenu);
22232a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        writer.print(prefix); writer.print("mRetainInstance="); writer.print(mRetainInstance);
222479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                writer.print(" mRetaining="); writer.print(mRetaining);
222579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                writer.print(" mUserVisibleHint="); writer.println(mUserVisibleHint);
2226cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mFragmentManager != null) {
2227cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mFragmentManager=");
2228cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mFragmentManager);
2229cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2230d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        if (mHost != null) {
2231d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            writer.print(prefix); writer.print("mHost=");
2232d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy                    writer.println(mHost);
2233cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
22340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mParentFragment != null) {
22350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            writer.print(prefix); writer.print("mParentFragment=");
22360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    writer.println(mParentFragment);
22370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
2238cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mArguments != null) {
2239cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mArguments="); writer.println(mArguments);
2240cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2241cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mSavedFragmentState != null) {
2242cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mSavedFragmentState=");
2243cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mSavedFragmentState);
2244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mSavedViewState != null) {
2246cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mSavedViewState=");
2247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mSavedViewState);
2248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mTarget != null) {
2250cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mTarget="); writer.print(mTarget);
2251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.print(" mTargetRequestCode=");
2252cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mTargetRequestCode);
2253cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2254990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (getNextAnim() != 0) {
2255990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            writer.print(prefix); writer.print("mNextAnim="); writer.println(getNextAnim());
2256cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2257cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mContainer != null) {
2258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mContainer="); writer.println(mContainer);
2259cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2260cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mView != null) {
2261cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mView="); writer.println(mView);
2262cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2263cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mInnerView != null) {
2264cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mInnerView="); writer.println(mView);
2265cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2266990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (getAnimatingAway() != null) {
2267990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            writer.print(prefix);
2268990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            writer.print("mAnimatingAway=");
2269990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            writer.println(getAnimatingAway());
2270990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            writer.print(prefix);
2271990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            writer.print("mStateAfterAnimating=");
2272990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            writer.println(getStateAfterAnimating());
2273cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2274afe28d91550483f9b7a82076a507151b4defd9baIan Lake        LoaderManager.getInstance(this).dump(prefix, fd, writer, args);
22750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
22760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            writer.print(prefix); writer.println("Child " + mChildFragmentManager + ":");
22770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dump(prefix + "  ", fd, writer, args);
22780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
22790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
22800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
22810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    Fragment findFragmentByWho(String who) {
22820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (who.equals(mWho)) {
22830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            return this;
22840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
22850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
22860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            return mChildFragmentManager.findFragmentByWho(who);
22870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
22880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return null;
22890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
22900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
22910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void instantiateChildFragmentManager() {
22921c7e1f738e202226b365c81715b221d2e864fdd5George Mount        if (mHost == null) {
22931c7e1f738e202226b365c81715b221d2e864fdd5George Mount            throw new IllegalStateException("Fragment has not been attached yet.");
22941c7e1f738e202226b365c81715b221d2e864fdd5George Mount        }
2295e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        mChildFragmentManager = new FragmentManagerImpl();
2296d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        mChildFragmentManager.attachController(mHost, new FragmentContainer() {
22970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            @Override
22980fb3ec354da6c1f3ed1777bca5270710cc537e92Scott Kennedy            @Nullable
22998491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy            public View onFindViewById(int id) {
23000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (mView == null) {
23010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    throw new IllegalStateException("Fragment does not have a view");
23020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                }
23030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                return mView.findViewById(id);
23040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
23057516316ffdf6fbf7b248c615404831191daa66a4George Mount
23067516316ffdf6fbf7b248c615404831191daa66a4George Mount            @Override
23078491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy            public boolean onHasView() {
23087516316ffdf6fbf7b248c615404831191daa66a4George Mount                return (mView != null);
23097516316ffdf6fbf7b248c615404831191daa66a4George Mount            }
23104aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell
23114aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell            @Override
23124aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell            public Fragment instantiate(Context context, String className, Bundle arguments) {
23134aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell                return mHost.instantiate(context, className, arguments);
23144aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell            }
23150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }, this);
23160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
23170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
23180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performCreate(Bundle savedInstanceState) {
23190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
23200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
23210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
232220735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = CREATED;
23230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
23240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onCreate(savedInstanceState);
2325e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount        mIsCreated = true;
23260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
23270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
23280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onCreate()");
23290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
2330c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets        mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
23310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
23320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
2333b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton    View performCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
2334b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton            @Nullable Bundle savedInstanceState) {
23350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
23360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
23370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
233837149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell        mPerformedCreateView = true;
23390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return onCreateView(inflater, container, savedInstanceState);
23400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
23410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
23420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performActivityCreated(Bundle savedInstanceState) {
23430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
23440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
23450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
234620735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = ACTIVITY_CREATED;
23470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
23480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onActivityCreated(savedInstanceState);
23490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
23500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
23510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onActivityCreated()");
23520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
23530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
23540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchActivityCreated();
23550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
2356cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
2357cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
23589c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    void performStart() {
23590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
23600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
23610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.execPendingActions();
23620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
236320735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = STARTED;
23640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
23659c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        onStart();
23660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
23670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
23680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onStart()");
23690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
23700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
23710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchStart();
23720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
2373c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets        mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
23749c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
23759c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
23760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performResume() {
23770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
23780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
23790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.execPendingActions();
23800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
238120735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = RESUMED;
23820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
23830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onResume();
23840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
23850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
23860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onResume()");
23870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
23880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
23890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchResume();
23900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.execPendingActions();
23910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
2392c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets        mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME);
23930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
23940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
23950765353c002bfdf681c982565810aa4be3499dd0George Mount    void noteStateNotSaved() {
23960765353c002bfdf681c982565810aa4be3499dd0George Mount        if (mChildFragmentManager != null) {
23970765353c002bfdf681c982565810aa4be3499dd0George Mount            mChildFragmentManager.noteStateNotSaved();
23980765353c002bfdf681c982565810aa4be3499dd0George Mount        }
23990765353c002bfdf681c982565810aa4be3499dd0George Mount    }
24000765353c002bfdf681c982565810aa4be3499dd0George Mount
24015fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    void performMultiWindowModeChanged(boolean isInMultiWindowMode) {
24025fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian        onMultiWindowModeChanged(isInMultiWindowMode);
24035fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian        if (mChildFragmentManager != null) {
24045fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian            mChildFragmentManager.dispatchMultiWindowModeChanged(isInMultiWindowMode);
24055fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian        }
24065fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    }
24075fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian
24085fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    void performPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
24095fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian        onPictureInPictureModeChanged(isInPictureInPictureMode);
24105fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian        if (mChildFragmentManager != null) {
24115fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian            mChildFragmentManager.dispatchPictureInPictureModeChanged(isInPictureInPictureMode);
24125fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian        }
24135fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    }
24145fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian
24150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performConfigurationChanged(Configuration newConfig) {
24160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onConfigurationChanged(newConfig);
24170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
24180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchConfigurationChanged(newConfig);
24190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
24200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
24210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
24220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performLowMemory() {
24230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onLowMemory();
24240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
24250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchLowMemory();
24260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
24270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
24280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
24290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    /*
24300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performTrimMemory(int level) {
24310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onTrimMemory(level);
24320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
24330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchTrimMemory(level);
24340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
24350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
24360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    */
24370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
24380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    boolean performCreateOptionsMenu(Menu menu, MenuInflater inflater) {
24390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        boolean show = false;
24400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
24410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mHasMenu && mMenuVisible) {
24420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                show = true;
24430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                onCreateOptionsMenu(menu, inflater);
24440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
24450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
24460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                show |= mChildFragmentManager.dispatchCreateOptionsMenu(menu, inflater);
24470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
24480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
24490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return show;
24500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
24510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
24520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    boolean performPrepareOptionsMenu(Menu menu) {
24530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        boolean show = false;
24540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
24550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mHasMenu && mMenuVisible) {
24560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                show = true;
24570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                onPrepareOptionsMenu(menu);
24580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
24590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
24600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                show |= mChildFragmentManager.dispatchPrepareOptionsMenu(menu);
24610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
24620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
24630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return show;
24640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
24650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
24660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    boolean performOptionsItemSelected(MenuItem item) {
24670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
24680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mHasMenu && mMenuVisible) {
24690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (onOptionsItemSelected(item)) {
24700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    return true;
24710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                }
24720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
24730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
24740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (mChildFragmentManager.dispatchOptionsItemSelected(item)) {
24750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    return true;
24760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                }
24770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
24780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
24790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return false;
24800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
24810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
24820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    boolean performContextItemSelected(MenuItem item) {
24830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
24840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (onContextItemSelected(item)) {
24850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                return true;
24860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
24870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
24880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (mChildFragmentManager.dispatchContextItemSelected(item)) {
24890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    return true;
24900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                }
24910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
24920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
24930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return false;
24940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
24950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
24960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performOptionsMenuClosed(Menu menu) {
24970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
24980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mHasMenu && mMenuVisible) {
24990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                onOptionsMenuClosed(menu);
25000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
25010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
25020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchOptionsMenuClosed(menu);
25030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
25040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
25050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
25060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
25070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performSaveInstanceState(Bundle outState) {
25080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onSaveInstanceState(outState);
25090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
25100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            Parcelable p = mChildFragmentManager.saveAllState();
25110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (p != null) {
25120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                outState.putParcelable(FragmentActivity.FRAGMENTS_TAG, p);
25130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
25140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
25150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
25160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
25170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performPause() {
2518c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets        mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE);
25190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
25200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchPause();
25210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
252220735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = STARTED;
25230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
25240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onPause();
25250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
25260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
25270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onPause()");
25280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
25290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
25300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
2531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void performStop() {
2532c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets        mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
25330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
25340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchStop();
25350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
253620735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = STOPPED;
25370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
2538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        onStop();
25390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
25400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
25410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onStop()");
25420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
2543681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn    }
2544681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn
2545218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn    void performReallyStop() {
25460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
25470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchReallyStop();
25480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
254920735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = ACTIVITY_CREATED;
2550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
25519c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
25529c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    void performDestroyView() {
25530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
25540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchDestroyView();
25550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
255620735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = CREATED;
25570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
25589c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        onDestroyView();
25590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
25600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
25610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onDestroyView()");
25620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
2563afe28d91550483f9b7a82076a507151b4defd9baIan Lake        // Handles the detach/reattach case where the view hierarchy
2564afe28d91550483f9b7a82076a507151b4defd9baIan Lake        // is destroyed and recreated and an additional call to
2565afe28d91550483f9b7a82076a507151b4defd9baIan Lake        // onLoadFinished may be needed to ensure the new view
2566afe28d91550483f9b7a82076a507151b4defd9baIan Lake        // hierarchy is populated from data from the Loaders
2567afe28d91550483f9b7a82076a507151b4defd9baIan Lake        LoaderManager.getInstance(this).markForRedelivery();
256837149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell        mPerformedCreateView = false;
25699c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
25700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
25710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performDestroy() {
2572c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets        mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY);
25730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
25740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchDestroy();
25750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
257620735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = INITIALIZING;
25770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
2578e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount        mIsCreated = false;
25790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onDestroy();
25800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
25810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
25820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onDestroy()");
25830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
25844706c089880423ee5929d4635c6dfc5c3151b20fGeorge Mount        mChildFragmentManager = null;
25850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
25869375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell
2587916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    void performDetach() {
2588916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        mCalled = false;
2589916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        onDetach();
25908b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount        mLayoutInflater = null;
2591916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        if (!mCalled) {
2592916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell            throw new SuperNotCalledException("Fragment " + this
2593916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell                    + " did not call through to super.onDetach()");
2594916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        }
2595916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell
2596916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        // Destroy the child FragmentManager if we still have it here.
2597916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        // We won't unless we're retaining our instance and if we do,
2598916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        // our child FragmentManager instance state will have already been saved.
2599916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        if (mChildFragmentManager != null) {
2600916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell            if (!mRetaining) {
2601916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell                throw new IllegalStateException("Child FragmentManager of " + this + " was not "
2602916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell                        + " destroyed and this fragment is not retaining instance");
2603916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell            }
2604916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell            mChildFragmentManager.dispatchDestroy();
2605916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell            mChildFragmentManager = null;
2606916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        }
2607916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    }
2608916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell
2609990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    void setOnStartEnterTransitionListener(OnStartEnterTransitionListener listener) {
2610990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo();
2611990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (listener == mAnimationInfo.mStartEnterTransitionListener) {
2612990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return;
2613990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2614990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (listener != null && mAnimationInfo.mStartEnterTransitionListener != null) {
2615990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            throw new IllegalStateException("Trying to set a replacement "
2616990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                    + "startPostponedEnterTransition on " + this);
2617990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2618990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo.mEnterTransitionPostponed) {
2619990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            mAnimationInfo.mStartEnterTransitionListener = listener;
2620990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2621990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (listener != null) {
2622990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            listener.startListening();
2623990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2624990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2625990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2626990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    private AnimationInfo ensureAnimationInfo() {
2627990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2628990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            mAnimationInfo = new AnimationInfo();
2629990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2630990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo;
2631990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2632990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2633990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    int getNextAnim() {
2634990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2635990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return 0;
2636990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2637990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mNextAnim;
2638990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2639990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2640990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    void setNextAnim(int animResourceId) {
2641990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null && animResourceId == 0) {
2642990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return; // no change!
2643990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2644990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mNextAnim = animResourceId;
2645990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2646990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2647990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    int getNextTransition() {
2648990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2649990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return 0;
2650990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2651990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mNextTransition;
2652990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2653990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2654990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    void setNextTransition(int nextTransition, int nextTransitionStyle) {
2655990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null && nextTransition == 0 && nextTransitionStyle == 0) {
2656990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return; // no change!
2657990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2658990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo();
2659990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        mAnimationInfo.mNextTransition = nextTransition;
2660990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        mAnimationInfo.mNextTransitionStyle = nextTransitionStyle;
2661990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2662990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2663990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    int getNextTransitionStyle() {
2664990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2665990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return 0;
2666990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2667990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mNextTransitionStyle;
2668990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2669990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2670990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    SharedElementCallback getEnterTransitionCallback() {
2671990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2672990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
2673990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2674990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mEnterTransitionCallback;
2675990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2676990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2677990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    SharedElementCallback getExitTransitionCallback() {
2678990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2679990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
2680990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2681990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mExitTransitionCallback;
2682990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2683990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2684990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    View getAnimatingAway() {
2685990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2686990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
2687990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2688990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mAnimatingAway;
2689990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2690990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2691990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    void setAnimatingAway(View view) {
2692990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mAnimatingAway = view;
2693990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2694990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
269515e593ea3575512d7072240d1db9d74fad8749a3George Mount    void setAnimator(Animator animator) {
269615e593ea3575512d7072240d1db9d74fad8749a3George Mount        ensureAnimationInfo().mAnimator = animator;
269715e593ea3575512d7072240d1db9d74fad8749a3George Mount    }
269815e593ea3575512d7072240d1db9d74fad8749a3George Mount
269915e593ea3575512d7072240d1db9d74fad8749a3George Mount    Animator getAnimator() {
270015e593ea3575512d7072240d1db9d74fad8749a3George Mount        if (mAnimationInfo == null) {
270115e593ea3575512d7072240d1db9d74fad8749a3George Mount            return null;
270215e593ea3575512d7072240d1db9d74fad8749a3George Mount        }
270315e593ea3575512d7072240d1db9d74fad8749a3George Mount        return mAnimationInfo.mAnimator;
270415e593ea3575512d7072240d1db9d74fad8749a3George Mount    }
270515e593ea3575512d7072240d1db9d74fad8749a3George Mount
2706990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    int getStateAfterAnimating() {
2707990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2708990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return 0;
2709990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2710990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mStateAfterAnimating;
2711990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2712990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2713990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    void setStateAfterAnimating(int state) {
2714990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mStateAfterAnimating = state;
2715990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2716990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2717990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    boolean isPostponed() {
2718990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2719990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return false;
2720990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2721990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mEnterTransitionPostponed;
2722990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2723990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2724667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount    boolean isHideReplaced() {
2725667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount        if (mAnimationInfo == null) {
2726667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount            return false;
2727667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount        }
2728667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount        return mAnimationInfo.mIsHideReplaced;
2729667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount    }
2730667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount
2731667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount    void setHideReplaced(boolean replaced) {
2732667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount        ensureAnimationInfo().mIsHideReplaced = replaced;
2733667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount    }
2734667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount
2735990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    /**
2736990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * Used internally to be notified when {@link #startPostponedEnterTransition()} has
2737990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * been called. This listener will only be called once and then be removed from the
2738990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * listeners.
2739990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     */
2740990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    interface OnStartEnterTransitionListener {
2741990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        void onStartEnterTransition();
2742990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        void startListening();
2743990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2744990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2745990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    /**
2746990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * Contains all the animation and transition information for a fragment. This will only
2747990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * be instantiated for Fragments that have Views.
2748990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     */
2749990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    static class AnimationInfo {
2750990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // Non-null if the fragment's view hierarchy is currently animating away,
2751990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // meaning we need to wait a bit on completely destroying it.  This is the
2752990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // view that is animating.
2753990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        View mAnimatingAway;
2754990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
275515e593ea3575512d7072240d1db9d74fad8749a3George Mount        // Non-null if the fragment's view hierarchy is currently animating away with an
275615e593ea3575512d7072240d1db9d74fad8749a3George Mount        // animator instead of an animation.
275715e593ea3575512d7072240d1db9d74fad8749a3George Mount        Animator mAnimator;
275815e593ea3575512d7072240d1db9d74fad8749a3George Mount
2759990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // If mAnimatingAway != null, this is the state we should move to once the
2760990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // animation is done.
2761990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        int mStateAfterAnimating;
2762990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2763990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // If app has requested a specific animation, this is the one to use.
2764990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        int mNextAnim;
2765990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2766990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // If app has requested a specific transition, this is the one to use.
2767990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        int mNextTransition;
2768990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2769990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // If app has requested a specific transition style, this is the one to use.
2770990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        int mNextTransitionStyle;
2771990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2772990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Object mEnterTransition = null;
2773990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Object mReturnTransition = USE_DEFAULT_TRANSITION;
2774990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Object mExitTransition = null;
2775990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Object mReenterTransition = USE_DEFAULT_TRANSITION;
2776990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Object mSharedElementEnterTransition = null;
2777990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Object mSharedElementReturnTransition = USE_DEFAULT_TRANSITION;
2778990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Boolean mAllowReturnTransitionOverlap;
2779990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Boolean mAllowEnterTransitionOverlap;
2780990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2781990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        SharedElementCallback mEnterTransitionCallback = null;
2782990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        SharedElementCallback mExitTransitionCallback = null;
2783990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2784990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // True when postponeEnterTransition has been called and startPostponeEnterTransition
2785990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // hasn't been called yet.
2786990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        boolean mEnterTransitionPostponed;
2787990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2788990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // Listener to wait for startPostponeEnterTransition. After being called, it will
2789990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // be set to null
2790990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        OnStartEnterTransitionListener mStartEnterTransitionListener;
2791990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2792667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount        // True if the View was hidden, but the transition is handling the hide
2793667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount        boolean mIsHideReplaced;
2794990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2795cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn}
2796