Fragment.java revision 995c3504e6c5b1d20368c36193b44a7e6844709d
1cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/*
2cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Copyright (C) 2011 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
17cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornpackage android.support.v4.app;
18cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
198e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikasimport static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP;
20990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
21cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.app.Activity;
22cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.ComponentCallbacks;
23cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Context;
24cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Intent;
25fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarriimport android.content.IntentSender;
26cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Configuration;
27cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Resources;
28cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Bundle;
29990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mountimport android.os.Looper;
30cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcel;
31cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcelable;
32916455675ddb34d0eb848b2355550268d82c3ce7Adam Powellimport android.support.annotation.CallSuper;
33e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslavimport android.support.annotation.NonNull;
34a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbyeimport android.support.annotation.Nullable;
35c39d9c75590eca86a5e7e32a8824ba04a0d42e9bAlan Viveretteimport android.support.annotation.RestrictTo;
36a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbyeimport android.support.annotation.StringRes;
37cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.support.v4.util.DebugUtils;
389562a3b639225d406d736b64a12e2d75459259e3Alan Viveretteimport android.support.v4.util.SimpleArrayMap;
39bf0947be2ead9b3d8e5865bcd3d3652d02a2aa5aChris Banesimport android.support.v4.view.LayoutInflaterCompat;
40cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.AttributeSet;
41be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackbornimport android.util.Log;
42cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.SparseArray;
43cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ContextMenu;
449562a3b639225d406d736b64a12e2d75459259e3Alan Viveretteimport android.view.ContextMenu.ContextMenuInfo;
45cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.LayoutInflater;
46cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.Menu;
47cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuInflater;
48cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuItem;
49cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View;
50cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View.OnCreateContextMenuListener;
519562a3b639225d406d736b64a12e2d75459259e3Alan Viveretteimport android.view.ViewGroup;
52cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.animation.Animation;
53cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.widget.AdapterView;
54cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
55cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.FileDescriptor;
56cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.PrintWriter;
57cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
58cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornfinal class FragmentState implements Parcelable {
59cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final String mClassName;
60cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final int mIndex;
61cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final boolean mFromLayout;
62cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final int mFragmentId;
63cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final int mContainerId;
64cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final String mTag;
65cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final boolean mRetainInstance;
66e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    final boolean mDetached;
67cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final Bundle mArguments;
68340a183c3293d98842e4a2671b500e8e80258818Todd Kennedy    final boolean mHidden;
694bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
70cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Bundle mSavedFragmentState;
714bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
72cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Fragment mInstance;
73c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell
74cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public FragmentState(Fragment frag) {
75cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mClassName = frag.getClass().getName();
76cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mIndex = frag.mIndex;
77cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mFromLayout = frag.mFromLayout;
78cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mFragmentId = frag.mFragmentId;
79cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mContainerId = frag.mContainerId;
80cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mTag = frag.mTag;
81cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mRetainInstance = frag.mRetainInstance;
82e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        mDetached = frag.mDetached;
83cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mArguments = frag.mArguments;
84340a183c3293d98842e4a2671b500e8e80258818Todd Kennedy        mHidden = frag.mHidden;
85cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
864bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
87cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public FragmentState(Parcel in) {
88cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mClassName = in.readString();
89cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mIndex = in.readInt();
90cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mFromLayout = in.readInt() != 0;
91cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mFragmentId = in.readInt();
92cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mContainerId = in.readInt();
93cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mTag = in.readString();
94cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mRetainInstance = in.readInt() != 0;
95e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        mDetached = in.readInt() != 0;
96cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mArguments = in.readBundle();
97340a183c3293d98842e4a2671b500e8e80258818Todd Kennedy        mHidden = in.readInt() != 0;
98cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mSavedFragmentState = in.readBundle();
99cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
100d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1014aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell    public Fragment instantiate(FragmentHostCallback host, FragmentContainer container,
1024aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell            Fragment parent, FragmentManagerNonConfig childNonConfig) {
103c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell        if (mInstance == null) {
104c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            final Context context = host.getContext();
105c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            if (mArguments != null) {
106c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell                mArguments.setClassLoader(context.getClassLoader());
107c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            }
108d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1094aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell            if (container != null) {
1104aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell                mInstance = container.instantiate(context, mClassName, mArguments);
1114aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell            } else {
1124aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell                mInstance = Fragment.instantiate(context, mClassName, mArguments);
1134aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell            }
114d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
115c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            if (mSavedFragmentState != null) {
116c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell                mSavedFragmentState.setClassLoader(context.getClassLoader());
117c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell                mInstance.mSavedFragmentState = mSavedFragmentState;
118c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            }
119c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            mInstance.setIndex(mIndex, parent);
120c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            mInstance.mFromLayout = mFromLayout;
121c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            mInstance.mRestored = true;
122c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            mInstance.mFragmentId = mFragmentId;
123c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            mInstance.mContainerId = mContainerId;
124c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            mInstance.mTag = mTag;
125c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            mInstance.mRetainInstance = mRetainInstance;
126c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            mInstance.mDetached = mDetached;
127c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            mInstance.mHidden = mHidden;
128c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            mInstance.mFragmentManager = host.mFragmentManager;
129c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell
130c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell            if (FragmentManagerImpl.DEBUG) Log.v(FragmentManagerImpl.TAG,
131c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell                    "Instantiated fragment " + mInstance);
132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
133c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell        mInstance.mChildNonConfig = childNonConfig;
134cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mInstance;
135cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
136d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
13790ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas    @Override
138cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public int describeContents() {
139cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return 0;
140cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
141cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
14290ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas    @Override
143cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void writeToParcel(Parcel dest, int flags) {
144cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeString(mClassName);
145cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mIndex);
146cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mFromLayout ? 1 : 0);
147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mFragmentId);
148cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mContainerId);
149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeString(mTag);
150cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mRetainInstance ? 1 : 0);
151e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        dest.writeInt(mDetached ? 1 : 0);
152cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeBundle(mArguments);
153340a183c3293d98842e4a2671b500e8e80258818Todd Kennedy        dest.writeInt(mHidden? 1 : 0);
154cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeBundle(mSavedFragmentState);
155cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1564bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
157cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public static final Parcelable.Creator<FragmentState> CREATOR
158cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            = new Parcelable.Creator<FragmentState>() {
15990ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas        @Override
160cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public FragmentState createFromParcel(Parcel in) {
161cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return new FragmentState(in);
162cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
16390ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas
16490ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas        @Override
165cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public FragmentState[] newArray(int size) {
166cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return new FragmentState[size];
167cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
168cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    };
169cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn}
170cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
171cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/**
172cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Static library support version of the framework's {@link android.app.Fragment}.
173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Used to write apps that run on platforms prior to Android 3.0.  When running
174cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on Android 3.0 or above, this implementation is still used; it does not try
1759dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * to switch to the framework's implementation. See the framework {@link android.app.Fragment}
176cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * documentation for a class overview.
1779dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main *
1789dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <p>The main differences when using this support version instead of the framework version are:
1799dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <ul>
1809dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main *  <li>Your activity must extend {@link FragmentActivity}
1819dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main *  <li>You must call {@link FragmentActivity#getSupportFragmentManager} to get the
1829dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main *  {@link FragmentManager}
1839dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * </ul>
1849dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main *
185cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */
186cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornpublic class Fragment implements ComponentCallbacks, OnCreateContextMenuListener {
1872290993eddf5262a8df7fc9478daed52401e325aDianne Hackborn    private static final SimpleArrayMap<String, Class<?>> sClassMap =
1882290993eddf5262a8df7fc9478daed52401e325aDianne Hackborn            new SimpleArrayMap<String, Class<?>>();
1899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
1909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    static final Object USE_DEFAULT_TRANSITION = new Object();
1919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
192cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final int INITIALIZING = 0;     // Not yet created.
193cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final int CREATED = 1;          // Created.
194cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final int ACTIVITY_CREATED = 2; // The activity has finished its creation.
195e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    static final int STOPPED = 3;          // Fully created, not started.
196e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    static final int STARTED = 4;          // Created and started, not resumed.
197e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    static final int RESUMED = 5;          // Created started and resumed.
1984bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mState = INITIALIZING;
2004bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // When instantiated from saved state, this is the saved state.
202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Bundle mSavedFragmentState;
203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    SparseArray<Parcelable> mSavedViewState;
2044bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Index into active fragment array.
206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mIndex = -1;
2074bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
208cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Internal unique name for this fragment;
209cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    String mWho;
2104bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Construction arguments;
212cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Bundle mArguments;
213cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
214cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Target fragment.
215cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Fragment mTarget;
216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
2172c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn    // For use when retaining a fragment: this is the index of the last mTarget.
2182c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn    int mTargetIndex = -1;
2192c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn
220cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Target request code.
221cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mTargetRequestCode;
222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
223cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // True if the fragment is in the list of added fragments.
224cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mAdded;
2254bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
226cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment is being removed from its activity.
227cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRemoving;
2284bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
229cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Set to true if this fragment was instantiated from a layout file.
230cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mFromLayout;
2314bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
232cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Set to true when the view has actually been inflated in its layout.
233cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mInLayout;
234cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
235cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // True if this fragment has been restored from previously saved state.
236cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRestored;
237d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
23837149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell    // True if performCreateView has been called and a matching call to performDestroyView
23937149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell    // has not yet happened.
24037149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell    boolean mPerformedCreateView;
24137149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell
242cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Number of active back stack entries this fragment is in.
243cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mBackStackNesting;
244d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The fragment manager we are associated with.  Set as soon as the
246cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // fragment is used in a transaction; cleared after it has been removed
247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // from all transactions.
248abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    FragmentManagerImpl mFragmentManager;
249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
250d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    // Host this fragment is attached to.
2518491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy    FragmentHostCallback mHost;
2520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
2530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    // Private fragment manager for child fragments inside of this one.
2540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    FragmentManagerImpl mChildFragmentManager;
2550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
256c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell    // For use when restoring fragment state and descendant fragments are retained.
257c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell    // This state is set by FragmentState.instantiate and cleared in onCreate.
258c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell    FragmentManagerNonConfig mChildNonConfig;
259c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell
2600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    // If this Fragment is contained in another Fragment, this is that container.
2610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    Fragment mParentFragment;
2620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
263cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The optional identifier for this fragment -- either the container ID if it
264cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // was dynamically added to the view hierarchy, or the ID supplied in
265cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // layout.
266cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mFragmentId;
2674bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
268cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // When a fragment is being dynamically added to the view hierarchy, this
269cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // is the identifier of the parent container it is being added to.
270cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mContainerId;
2714bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
272cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The optional named tag for this fragment -- usually used to find
273cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // fragments that are not part of the layout.
274cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    String mTag;
2754bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
276cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Set to true when the app has requested that this fragment be hidden
277cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // from the user.
278cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mHidden;
2794bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
280e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    // Set to true when the app has requested that this fragment be deactivated.
281e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    boolean mDetached;
282e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn
283cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment would like its instance retained across
284cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // configuration changes.
285cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRetainInstance;
2862bdd09a243b422960168170e2344274cc9cfd788Todd Kennedy
287cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment is being retained across the current config change.
288cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRetaining;
2894bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
290cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment has menu items to contribute.
291cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mHasMenu;
2922a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
2932a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    // Set to true to allow the fragment's menu to be shown.
2942a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    boolean mMenuVisible = true;
2952a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
296cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Used to verify that subclasses call through to super class.
297cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mCalled;
2984bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
299cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The parent container of the fragment after dynamically added to UI.
300cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ViewGroup mContainer;
3014bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
302cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The View generated for this fragment.
303cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    View mView;
3044bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
305cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The real inner view that will save/restore state.
306cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    View mInnerView;
307abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
308abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    // Whether this fragment should defer starting until after other fragments
309abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    // have been started and their loaders are finished.
310abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    boolean mDeferStart;
3114bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
31279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    // Hint provided by the app that this fragment is currently visible to the user.
31379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    boolean mUserVisibleHint = true;
314abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
315cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    LoaderManagerImpl mLoaderManager;
316cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mLoadersStarted;
317cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mCheckedForLoaderManager;
3189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
319990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    // The animation and transition information for the fragment. This will be null
320990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    // unless the elements are explicitly accessed and should remain null for Fragments
321990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    // without Views.
322990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    AnimationInfo mAnimationInfo;
3239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
324990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    // True if the View was added, and its animation has yet to be run. This could
325990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    // also indicate that the fragment view hasn't been made visible, even if there is no
326990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    // animation for this fragment.
327990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    boolean mIsNewlyAdded;
328990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
329990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    // True if mHidden has been changed and the animation should be scheduled.
330990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    boolean mHiddenChanged;
3319f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
3320bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount    // The alpha of the view when the view was added and then postponed. If the value is less
3330bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount    // than zero, this means that the view's add was canceled and should not participate in
3340bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount    // removal animations.
3350bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount    float mPostponedAlpha;
3360bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount
337cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
3385c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * State information that has been retrieved from a fragment instance
3395c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * through {@link FragmentManager#saveFragmentInstanceState(Fragment)
3405c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * FragmentManager.saveFragmentInstanceState}.
3415c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     */
3425c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    public static class SavedState implements Parcelable {
3435c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        final Bundle mState;
3445c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3455c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        SavedState(Bundle state) {
3465c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            mState = state;
3475c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
3485c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3495c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        SavedState(Parcel in, ClassLoader loader) {
3505c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            mState = in.readBundle();
3515c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            if (loader != null && mState != null) {
3525c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                mState.setClassLoader(loader);
3535c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            }
3545c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
3555c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3565c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        @Override
3575c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        public int describeContents() {
3585c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            return 0;
3595c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
3605c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3615c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        @Override
3625c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        public void writeToParcel(Parcel dest, int flags) {
3635c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            dest.writeBundle(mState);
3645c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
3655c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3665c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        public static final Parcelable.Creator<SavedState> CREATOR
3675c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                = new Parcelable.Creator<SavedState>() {
368d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            @Override
3695c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            public SavedState createFromParcel(Parcel in) {
3705c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                return new SavedState(in, null);
3715c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            }
3725c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
373d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            @Override
3745c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            public SavedState[] newArray(int size) {
3755c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                return new SavedState[size];
3765c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            }
3775c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        };
3785c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    }
3795c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3805c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    /**
381cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when
382cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * there is an instantiation failure.
383cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
384cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static public class InstantiationException extends RuntimeException {
385cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public InstantiationException(String msg, Exception cause) {
386cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            super(msg, cause);
387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
388cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
389cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
390cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
391cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Default constructor.  <strong>Every</strong> fragment must have an
392cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * empty constructor, so it can be instantiated when restoring its
393cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * activity's state.  It is strongly recommended that subclasses do not
394cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * have other constructors with parameters, since these constructors
395cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * will not be called when the fragment is re-instantiated; instead,
396cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * arguments can be supplied by the caller with {@link #setArguments}
397cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * and later retrieved by the Fragment with {@link #getArguments}.
3984bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
39904f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas     * <p>Applications should generally not implement a constructor. Prefer
40004f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas     * {@link #onAttach(Context)} instead. It is the first place application code can run where
40104f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas     * the fragment is ready to be used - the point where the fragment is actually associated with
40204f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas     * its context. Some applications may also want to implement {@link #onInflate} to retrieve
40304f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas     * attributes from a layout resource, although note this happens when the fragment is attached.
404cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
405cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public Fragment() {
406cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
407cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
408cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
409cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Like {@link #instantiate(Context, String, Bundle)} but with a null
410cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * argument Bundle.
411cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
412cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public static Fragment instantiate(Context context, String fname) {
413cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return instantiate(context, fname, null);
414cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
415cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
416cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
417cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Create a new instance of a Fragment with the given class name.  This is
418cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the same as calling its empty constructor.
419cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
420cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param context The calling context being used to instantiate the fragment.
421cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This is currently just used to get its ClassLoader.
422cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param fname The class name of the fragment to instantiate.
423cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param args Bundle of arguments to supply to the fragment, which it
424cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * can retrieve with {@link #getArguments()}.  May be null.
425cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return Returns a new fragment instance.
426cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @throws InstantiationException If there is a failure in instantiating
427cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the given fragment class.  This is a runtime exception; it is not
428cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * normally expected to happen.
429cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
430c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy    public static Fragment instantiate(Context context, String fname, @Nullable Bundle args) {
431cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        try {
432cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            Class<?> clazz = sClassMap.get(fname);
433cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (clazz == null) {
434cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                // Class not found in the cache, see if it's real, and try to add it
435cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                clazz = context.getClassLoader().loadClass(fname);
436cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                sClassMap.put(fname, clazz);
437cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
438cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            Fragment f = (Fragment)clazz.newInstance();
439cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (args != null) {
440cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                args.setClassLoader(f.getClass().getClassLoader());
44137149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell                f.setArguments(args);
442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return f;
444cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } catch (ClassNotFoundException e) {
445cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new InstantiationException("Unable to instantiate fragment " + fname
446cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + ": make sure class name exists, is public, and has an"
447cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + " empty constructor that is public", e);
448cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } catch (java.lang.InstantiationException e) {
449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new InstantiationException("Unable to instantiate fragment " + fname
450cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + ": make sure class name exists, is public, and has an"
451cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + " empty constructor that is public", e);
452cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } catch (IllegalAccessException e) {
453cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new InstantiationException("Unable to instantiate fragment " + fname
454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + ": make sure class name exists, is public, and has an"
455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + " empty constructor that is public", e);
456cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
457cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
4583fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell
4593fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell    /**
4603fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell     * Determine if the given fragment name is a support library fragment class.
4613fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell     *
4623fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell     * @param context Context used to determine the correct ClassLoader to use
4633fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell     * @param fname Class name of the fragment to test
4643fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell     * @return true if <code>fname</code> is <code>android.support.v4.app.Fragment</code>
4653fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell     *         or a subclass, false otherwise.
4663fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell     */
4673fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell    static boolean isSupportFragmentClass(Context context, String fname) {
4683fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell        try {
4693fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell            Class<?> clazz = sClassMap.get(fname);
4703fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell            if (clazz == null) {
4713fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell                // Class not found in the cache, see if it's real, and try to add it
4723fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell                clazz = context.getClassLoader().loadClass(fname);
4733fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell                sClassMap.put(fname, clazz);
4743fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell            }
4753fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell            return Fragment.class.isAssignableFrom(clazz);
4763fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell        } catch (ClassNotFoundException e) {
4773fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell            return false;
4783fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell        }
4793fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell    }
4804bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
4810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    final void restoreViewState(Bundle savedInstanceState) {
482cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mSavedViewState != null) {
483cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mInnerView.restoreHierarchyState(mSavedViewState);
484cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mSavedViewState = null;
485cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
4860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
4870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onViewStateRestored(savedInstanceState);
4880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
4890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
4900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onViewStateRestored()");
4910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
492cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
4930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
4940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    final void setIndex(int index, Fragment parent) {
495cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mIndex = index;
4960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (parent != null) {
4970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mWho = parent.mWho + ":" + mIndex;
4980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        } else {
4990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mWho = "android:fragment:" + mIndex;
5000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
501e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    }
5020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
503e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    final boolean isInBackStack() {
504e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        return mBackStackNesting > 0;
505e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    }
506e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn
507cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
508cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Subclasses can not override equals().
509cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
510cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override final public boolean equals(Object o) {
511cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return super.equals(o);
512cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
513cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
514cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
515cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Subclasses can not override hashCode().
516cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
517cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override final public int hashCode() {
518cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return super.hashCode();
519cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
5204bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
521cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
522cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public String toString() {
523cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        StringBuilder sb = new StringBuilder(128);
524cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        DebugUtils.buildShortClassTag(this, sb);
525cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mIndex >= 0) {
526cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(" #");
527cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(mIndex);
528cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
529cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mFragmentId != 0) {
530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(" id=0x");
531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(Integer.toHexString(mFragmentId));
532cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
533cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mTag != null) {
534cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(" ");
535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(mTag);
536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append('}');
538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return sb.toString();
539cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
5404bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
542cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the identifier this fragment is known by.  This is either
543cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the android:id value supplied in a layout or the container view ID
544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * supplied when adding the fragment.
545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public int getId() {
547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mFragmentId;
548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
5494bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
551cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Get the tag name of the fragment, if specified.
552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public String getTag() {
554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mTag;
555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
5564bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
5585e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * Supply the construction arguments for this fragment.
5595e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * The arguments supplied here will be retained across fragment destroy and
560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * creation.
5615e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * <p>This method cannot be called if the fragment is added to a FragmentManager and
5625e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * if {@link #isStateSaved()} would return true.</p>
563cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
564cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setArguments(Bundle args) {
5655e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell        if (mIndex >= 0 && isStateSaved()) {
5665e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell            throw new IllegalStateException("Fragment already active and state has been saved");
567cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
568cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mArguments = args;
569cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
570cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
571cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
572cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the arguments supplied when the fragment was instantiated,
573cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * if any.
574cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
575cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public Bundle getArguments() {
576cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mArguments;
577cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
578cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
579cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
5805e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * Returns true if this fragment is added and its state has already been saved
5815e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * by its host. Any operations that would change saved state should not be performed
5825e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * if this method returns true, and some operations such as {@link #setArguments(Bundle)}
5835e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * will fail.
5845e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     *
5855e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     * @return true if this fragment's state has already been saved by its host
5865e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell     */
5875e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell    public final boolean isStateSaved() {
5885e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell        if (mFragmentManager == null) {
5895e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell            return false;
5905e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell        }
5915e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell        return mFragmentManager.isStateSaved();
5925e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell    }
5935e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell
5945e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell    /**
5955c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * Set the initial saved state that this Fragment should restore itself
5965c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * from when first being constructed, as returned by
5975c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * {@link FragmentManager#saveFragmentInstanceState(Fragment)
5985c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * FragmentManager.saveFragmentInstanceState}.
5995c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     *
6005c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * @param state The state the fragment should be restored from.
6015c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     */
6025c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    public void setInitialSavedState(SavedState state) {
6035c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        if (mIndex >= 0) {
6045c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            throw new IllegalStateException("Fragment already active");
6055c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
6065c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        mSavedFragmentState = state != null && state.mState != null
6075c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                ? state.mState : null;
6085c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    }
6095c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
6105c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    /**
611cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Optional target for this fragment.  This may be used, for example,
612cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * if this fragment is being started by another, and when done wants to
613cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * give a result back to the first.  The target set here is retained
614cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * across instances via {@link FragmentManager#putFragment
615cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * FragmentManager.putFragment()}.
616cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
617cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param fragment The fragment that is the target of this one.
618cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param requestCode Optional request code, for convenience if you
619cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * are going to call back with {@link #onActivityResult(int, int, Intent)}.
620cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
621cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setTargetFragment(Fragment fragment, int requestCode) {
622a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        // Don't allow a caller to set a target fragment in another FragmentManager,
623a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        // but there's a snag: people do set target fragments before fragments get added.
624a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        // We'll have the FragmentManager check that for validity when we move
625a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        // the fragments to a valid state.
626a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        final FragmentManager mine = getFragmentManager();
6272ab15df66963610bc02cb30e9a459f2b49c2ccfaAdam Powell        final FragmentManager theirs = fragment != null ? fragment.getFragmentManager() : null;
628a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        if (mine != null && theirs != null && mine != theirs) {
629a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell            throw new IllegalArgumentException("Fragment " + fragment
630a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell                    + " must share the same FragmentManager to be set as a target fragment");
631a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        }
632a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell
633a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        // Don't let someone create a cycle.
634a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        for (Fragment check = fragment; check != null; check = check.getTargetFragment()) {
635a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell            if (check == this) {
636a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell                throw new IllegalArgumentException("Setting " + fragment + " as the target of "
637a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell                        + this + " would create a target cycle");
638a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell            }
639a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell        }
640cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mTarget = fragment;
641cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mTargetRequestCode = requestCode;
642cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
643cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
644cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
645cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the target fragment set by {@link #setTargetFragment}.
646cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
647cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public Fragment getTargetFragment() {
648cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mTarget;
649cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
650cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
651cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
652cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the target request code set by {@link #setTargetFragment}.
653cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
654cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public int getTargetRequestCode() {
655cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mTargetRequestCode;
656cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
657cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
658cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
659d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * Return the {@link Context} this fragment is currently associated with.
660d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     */
661edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy    public Context getContext() {
662d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        return mHost == null ? null : mHost.getContext();
663d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    }
664d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
665d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    /**
666d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * Return the {@link FragmentActivity} this fragment is currently associated with.
667d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * May return {@code null} if the fragment is associated with a {@link Context}
668d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * instead.
669cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
670cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public FragmentActivity getActivity() {
671d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        return mHost == null ? null : (FragmentActivity) mHost.getActivity();
672cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
673d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
674cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
675edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy     * Return the host object of this fragment. May return {@code null} if the fragment
676edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy     * isn't currently being hosted.
677edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy     */
678edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy    final public Object getHost() {
6798491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy        return mHost == null ? null : mHost.onGetHost();
680edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy    }
681edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy
682edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy    /**
683cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return <code>getActivity().getResources()</code>.
684cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
685cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public Resources getResources() {
686d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        if (mHost == null) {
687cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
688cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
689d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        return mHost.getContext().getResources();
690cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
691d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
692cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return a localized, styled CharSequence from the application's package's
694cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default string table.
695cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
696cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resId Resource id for the CharSequence text
697cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
698a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye    public final CharSequence getText(@StringRes int resId) {
699cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return getResources().getText(resId);
700cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
701cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
702cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return a localized string from the application's package's
704cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default string table.
705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resId Resource id for the string
707cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
708a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye    public final String getString(@StringRes int resId) {
709cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return getResources().getString(resId);
710cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
711cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
712cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
713cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return a localized formatted string from the application's package's
714cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default string table, substituting the format arguments as defined in
715cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link java.util.Formatter} and {@link java.lang.String#format}.
716cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
717cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resId Resource id for the format string
718cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param formatArgs The format arguments that will be used for substitution.
719cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
720cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
721a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye    public final String getString(@StringRes int resId, Object... formatArgs) {
722cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return getResources().getString(resId, formatArgs);
723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
724cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
725cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
726cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the FragmentManager for interacting with fragments associated
727cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * with this fragment's activity.  Note that this will be non-null slightly
728cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * before {@link #getActivity()}, during the time from when the fragment is
729cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * placed in a {@link FragmentTransaction} until it is committed and
730cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * attached to its activity.
7310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     *
7320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * <p>If this Fragment is a child of another Fragment, the FragmentManager
7330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * returned here will be the parent's {@link #getChildFragmentManager()}.
734cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
735cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public FragmentManager getFragmentManager() {
736cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mFragmentManager;
737cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
738cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
739cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
7400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * Return a private FragmentManager for placing and managing Fragments
7410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * inside of this Fragment.
7420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     */
7430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    final public FragmentManager getChildFragmentManager() {
7440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager == null) {
7450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            instantiateChildFragmentManager();
7460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mState >= RESUMED) {
7470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchResume();
7480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            } else if (mState >= STARTED) {
7490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchStart();
7500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            } else if (mState >= ACTIVITY_CREATED) {
7510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchActivityCreated();
7520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            } else if (mState >= CREATED) {
7530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchCreate();
7540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
7550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
7560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return mChildFragmentManager;
7570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
7580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
7590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    /**
760267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell     * Return this fragment's child FragmentManager one has been previously created,
761267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell     * otherwise null.
762267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell     */
763267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell    FragmentManager peekChildFragmentManager() {
764267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell        return mChildFragmentManager;
765267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell    }
766267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell
767267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell    /**
7680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * Returns the parent Fragment containing this Fragment.  If this Fragment
7690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * is attached directly to an Activity, returns null.
7700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     */
7710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    final public Fragment getParentFragment() {
7720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return mParentFragment;
7730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
7740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
7750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    /**
776cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment is currently added to its activity.
777cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
778cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isAdded() {
779d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        return mHost != null && mAdded;
780cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
781cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
782cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
7839c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * Return true if the fragment has been explicitly detached from the UI.
7849c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * That is, {@link FragmentTransaction#detach(Fragment)
7859c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * FragmentTransaction.detach(Fragment)} has been used on it.
7869c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     */
7879c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    final public boolean isDetached() {
7889c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        return mDetached;
7899c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
7909c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
7919c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    /**
792cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if this fragment is currently being removed from its
793cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * activity.  This is  <em>not</em> whether its activity is finishing, but
794cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * rather whether it is in the process of being removed from its activity.
795cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
796cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isRemoving() {
797cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mRemoving;
798cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
7994bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
800cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
801cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the layout is included as part of an activity view
802cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * hierarchy via the &lt;fragment&gt; tag.  This will always be true when
803cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * fragments are created through the &lt;fragment&gt; tag, <em>except</em>
804cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * in the case where an old fragment is restored from a previous state and
805cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * it does not appear in the layout of the current state.
806cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
807cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isInLayout() {
808cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mInLayout;
809cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
810cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
811cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
812cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment is in the resumed state.  This is true
813cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for the duration of {@link #onResume()} and {@link #onPause()} as well.
814cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
815cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isResumed() {
81620735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        return mState >= RESUMED;
817cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
8184bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
819cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
820cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment is currently visible to the user.  This means
8214bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     * it: (1) has been added, (2) has its view attached to the window, and
822cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * (3) is not hidden.
823cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
824cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isVisible() {
825cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return isAdded() && !isHidden() && mView != null
826cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE;
827cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
8284bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
829cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
830cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment has been hidden.  By default fragments
831cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * are shown.  You can find out about changes to this state with
832cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onHiddenChanged}.  Note that the hidden state is orthogonal
833cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to other states -- that is, to be visible to the user, a fragment
834cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * must be both started and not hidden.
835cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
836cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isHidden() {
837cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mHidden;
838cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
8393a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown
8403a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    /** @hide */
8418e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas    @RestrictTo(LIBRARY_GROUP)
8423a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    final public boolean hasOptionsMenu() {
8433a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown        return mHasMenu;
8443a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    }
8453a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown
8463a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    /** @hide */
8478e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas    @RestrictTo(LIBRARY_GROUP)
8483a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    final public boolean isMenuVisible() {
8493a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown        return mMenuVisible;
8503a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    }
8513a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown
852cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
853cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the hidden state (as returned by {@link #isHidden()} of
854cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the fragment has changed.  Fragments start out not hidden; this will
855cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * be called whenever the fragment changes state from that.
856527415d706bf580ff2bb7b492e5202b985cfa2c7Aurimas Liutikas     * @param hidden True if the fragment is now hidden, false otherwise.
857cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
858cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onHiddenChanged(boolean hidden) {
859cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
8604bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
861cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
862cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Control whether a fragment instance is retained across Activity
863cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * re-creation (such as from a configuration change).  This can only
864cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * be used with fragments not in the back stack.  If set, the fragment
865cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * lifecycle will be slightly different when an activity is recreated:
866cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <ul>
867cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still
868cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * will be, because the fragment is being detached from its current activity).
869cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <li> {@link #onCreate(Bundle)} will not be called since the fragment
870cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is not being re-created.
871cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b>
872cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * still be called.
873cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * </ul>
874cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
875cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setRetainInstance(boolean retain) {
876cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mRetainInstance = retain;
877cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
8784bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
879cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean getRetainInstance() {
880cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mRetainInstance;
881cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
8824bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
883cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
884cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Report that this fragment would like to participate in populating
885cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the options menu by receiving a call to {@link #onCreateOptionsMenu}
886cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * and related methods.
887d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     *
888cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param hasMenu If true, the fragment has menu items to contribute.
889cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
890cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setHasOptionsMenu(boolean hasMenu) {
891cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mHasMenu != hasMenu) {
892cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mHasMenu = hasMenu;
893cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (isAdded() && !isHidden()) {
8948491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy                mHost.onSupportInvalidateOptionsMenu();
895cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
896cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
897cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
8982a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
8992a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    /**
9002a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * Set a hint for whether this fragment's menu should be visible.  This
9012a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * is useful if you know that a fragment has been placed in your view
9022a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * hierarchy so that the user can not currently seen it, so any menu items
9032a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * it has should also not be shown.
9042a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     *
9052a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * @param menuVisible The default is true, meaning the fragment's menu will
9062a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * be shown as usual.  If false, the user will not see the menu.
9072a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     */
9082a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    public void setMenuVisibility(boolean menuVisible) {
9092a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        if (mMenuVisible != menuVisible) {
9102a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            mMenuVisible = menuVisible;
9112a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            if (mHasMenu && isAdded() && !isHidden()) {
9128491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy                mHost.onSupportInvalidateOptionsMenu();
9132a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            }
9142a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        }
9152a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    }
9162a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
917cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
91879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * Set a hint to the system about whether this fragment's UI is currently visible
91979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * to the user. This hint defaults to true and is persistent across fragment instance
92079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * state save and restore.
921abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     *
92279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * <p>An app may set this to false to indicate that the fragment's UI is
92379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * scrolled out of visibility or is otherwise not directly visible to the user.
92479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * This may be used by the system to prioritize operations such as fragment lifecycle updates
92579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * or loader ordering behavior.</p>
926abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     *
9270244762c99db7b1fb6c4905bc1224fefac927014Adam Powell     * <p><strong>Note:</strong> This method may be called outside of the fragment lifecycle.
9280244762c99db7b1fb6c4905bc1224fefac927014Adam Powell     * and thus has no ordering guarantees with regard to fragment lifecycle method calls.</p>
9290244762c99db7b1fb6c4905bc1224fefac927014Adam Powell     *
93079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * @param isVisibleToUser true if this fragment's UI is currently visible to the user (default),
93179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     *                        false if it is not.
932abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     */
93379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    public void setUserVisibleHint(boolean isVisibleToUser) {
9343ab5a96f51cbd0498a62f1e91f1ef99e95cb1b1cAdam Powell        if (!mUserVisibleHint && isVisibleToUser && mState < STARTED
9353ab5a96f51cbd0498a62f1e91f1ef99e95cb1b1cAdam Powell                && mFragmentManager != null && isAdded()) {
936abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell            mFragmentManager.performPendingDeferredStart(this);
937abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell        }
93879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        mUserVisibleHint = isVisibleToUser;
939c83dccecb0ec4bf9f4befdb18caccb8f373ed7bcAdam Powell        mDeferStart = mState < STARTED && !isVisibleToUser;
940abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    }
941abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
942abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    /**
94379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * @return The current value of the user-visible hint on this fragment.
94479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * @see #setUserVisibleHint(boolean)
945abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     */
94679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    public boolean getUserVisibleHint() {
94779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        return mUserVisibleHint;
948abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    }
949abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
950abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    /**
951cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the LoaderManager for this fragment, creating it if needed.
952cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
953cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public LoaderManager getLoaderManager() {
954cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mLoaderManager != null) {
955cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return mLoaderManager;
956cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
957d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        if (mHost == null) {
958cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
959cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
960cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCheckedForLoaderManager = true;
961d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, true);
962cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mLoaderManager;
963cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
964d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
965cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
9668491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy     * Call {@link Activity#startActivity(Intent)} from the fragment's
967cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * containing Activity.
968cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
969cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void startActivity(Intent intent) {
9700e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick        startActivity(intent, null);
9710e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick    }
9720e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick
9730e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick    /**
9740e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick     * Call {@link Activity#startActivity(Intent, Bundle)} from the fragment's
9750e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick     * containing Activity.
9760e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick     */
9770e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick    public void startActivity(Intent intent, @Nullable Bundle options) {
978d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        if (mHost == null) {
979cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
980cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
9810e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick        mHost.onStartActivityFromFragment(this /*fragment*/, intent, -1, options);
982cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
983d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
984cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
9858491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy     * Call {@link Activity#startActivityForResult(Intent, int)} from the fragment's
986cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * containing Activity.
987cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
988cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void startActivityForResult(Intent intent, int requestCode) {
9890e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick        startActivityForResult(intent, requestCode, null);
9900e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick    }
9910e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick
9920e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick    /**
9930e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick     * Call {@link Activity#startActivityForResult(Intent, int, Bundle)} from the fragment's
9940e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick     * containing Activity.
9950e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick     */
9960e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick    public void startActivityForResult(Intent intent, int requestCode, @Nullable Bundle options) {
997d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        if (mHost == null) {
998cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
999cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
10000e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick        mHost.onStartActivityFromFragment(this /*fragment*/, intent, requestCode, options);
1001fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri    }
1002fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri
1003fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri    /**
1004fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri     * Call {@link Activity#startIntentSenderForResult(IntentSender, int, Intent, int, int, int,
1005fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri     * Bundle)} from the fragment's containing Activity.
1006fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri     */
1007fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri    public void startIntentSenderForResult(IntentSender intent, int requestCode,
1008fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri            @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
1009fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri            Bundle options) throws IntentSender.SendIntentException {
1010fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri        if (mHost == null) {
1011fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
1012fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri        }
1013fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri        mHost.onStartIntentSenderFromFragment(this, intent, requestCode, fillInIntent, flagsMask,
1014fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri                flagsValues, extraFlags, options);
1015cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1016d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1017cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1018cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Receive the result from a previous call to
1019cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #startActivityForResult(Intent, int)}.  This follows the
1020cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * related Activity API as described there in
1021cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onActivityResult(int, int, Intent)}.
1022d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     *
1023cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param requestCode The integer request code originally supplied to
1024cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *                    startActivityForResult(), allowing you to identify who this
1025cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *                    result came from.
1026cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resultCode The integer result code returned by the child activity
1027cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *                   through its setResult().
1028cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param data An Intent, which can return result data to the caller
1029cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *               (various data can be attached to Intent "extras").
1030cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1031cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onActivityResult(int requestCode, int resultCode, Intent data) {
1032cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1033d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1034cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1035e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * Requests permissions to be granted to this application. These permissions
1036e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * must be requested in your manifest, they should not be granted to your app,
1037e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * and they should have protection level {@link android.content.pm.PermissionInfo
1038e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * #PROTECTION_DANGEROUS dangerous}, regardless whether they are declared by
1039e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * the platform or a third-party app.
1040e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <p>
1041e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * Normal permissions {@link android.content.pm.PermissionInfo#PROTECTION_NORMAL}
1042e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * are granted at install time if requested in the manifest. Signature permissions
1043e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * {@link android.content.pm.PermissionInfo#PROTECTION_SIGNATURE} are granted at
1044e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * install time if requested in the manifest and the signature of your app matches
1045e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * the signature of the app declaring the permissions.
1046e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </p>
1047e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <p>
1048e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * If your app does not have the requested permissions the user will be presented
1049e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * with UI for accepting them. After the user has accepted or rejected the
1050e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * requested permissions you will receive a callback on {@link
1051e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * #onRequestPermissionsResult(int, String[], int[])} reporting whether the
1052e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * permissions were granted or not.
1053e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </p>
1054e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <p>
1055e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * Note that requesting a permission does not guarantee it will be granted and
1056e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * your app should be able to run without having this permission.
1057e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </p>
1058e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <p>
1059e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * This method may start an activity allowing the user to choose which permissions
1060e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * to grant and which to reject. Hence, you should be prepared that your activity
1061e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * may be paused and resumed. Further, granting some permissions may require
1062e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * a restart of you application. In such a case, the system will recreate the
1063e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * activity stack before delivering the result to {@link
1064e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * #onRequestPermissionsResult(int, String[], int[])}.
1065e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </p>
1066e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <p>
1067e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * When checking whether you have a permission you should use {@link
1068e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * android.content.Context#checkSelfPermission(String)}.
1069e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </p>
1070e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <p>
10712750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov     * Calling this API for permissions already granted to your app would show UI
10722750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov     * to the user to decided whether the app can still hold these permissions. This
10732750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov     * can be useful if the way your app uses the data guarded by the permissions
10742750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov     * changes significantly.
10752750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov     * </p>
10762750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov     * <p>
1077e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * A sample permissions request looks like this:
1078e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </p>
1079e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <code><pre><p>
1080e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * private void showContacts() {
1081e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *     if (getActivity().checkSelfPermission(Manifest.permission.READ_CONTACTS)
1082e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *             != PackageManager.PERMISSION_GRANTED) {
1083e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *         requestPermissions(new String[]{Manifest.permission.READ_CONTACTS},
1084e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *                 PERMISSIONS_REQUEST_READ_CONTACTS);
1085e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *     } else {
1086e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *         doShowContacts();
1087e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *     }
1088e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * }
1089e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *
1090e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * {@literal @}Override
1091e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * public void onRequestPermissionsResult(int requestCode, String[] permissions,
1092e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *         int[] grantResults) {
1093e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *     if (requestCode == PERMISSIONS_REQUEST_READ_CONTACTS
1094e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *             && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
1095e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *         doShowContacts();
1096e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *     }
1097e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * }
1098e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </code></pre></p>
1099e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *
1100e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @param permissions The requested permissions.
1101e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @param requestCode Application specific request code to match with a result
1102e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *    reported to {@link #onRequestPermissionsResult(int, String[], int[])}.
1103e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *
1104e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @see #onRequestPermissionsResult(int, String[], int[])
1105e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @see android.content.Context#checkSelfPermission(String)
1106e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     */
1107e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    public final void requestPermissions(@NonNull String[] permissions, int requestCode) {
1108e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav        if (mHost == null) {
1109e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
1110e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav        }
11115fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian        mHost.onRequestPermissionsFromFragment(this, permissions, requestCode);
1112e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    }
1113e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav
1114e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    /**
1115e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * Callback for the result from requesting permissions. This method
1116e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * is invoked for every call on {@link #requestPermissions(String[], int)}.
1117dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov     * <p>
1118dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov     * <strong>Note:</strong> It is possible that the permissions request interaction
1119dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov     * with the user is interrupted. In this case you will receive empty permissions
1120dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov     * and results arrays which should be treated as a cancellation.
1121dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov     * </p>
1122e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *
1123e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}.
1124e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @param permissions The requested permissions. Never null.
1125e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @param grantResults The grant results for the corresponding permissions
1126e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *     which is either {@link android.content.pm.PackageManager#PERMISSION_GRANTED}
1127e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *     or {@link android.content.pm.PackageManager#PERMISSION_DENIED}. Never null.
1128e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *
1129e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @see #requestPermissions(String[], int)
1130e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     */
1131e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
1132e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav            @NonNull int[] grantResults) {
1133e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav        /* callback - do nothing */
1134e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    }
1135e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav
1136e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    /**
1137e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * Gets whether you should show UI with rationale for requesting a permission.
1138e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * You should do this only if you do not have the permission and the context in
1139e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * which the permission is requested does not clearly communicate to the user
1140e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * what would be the benefit from granting this permission.
1141e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * <p>
1142e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * For example, if you write a camera app, requesting the camera permission
1143e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * would be expected by the user and no rationale for why it is requested is
1144e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * needed. If however, the app needs location for tagging photos then a non-tech
1145e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * savvy user may wonder how location is related to taking photos. In this case
1146e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * you may choose to show UI with rationale of requesting this permission.
1147e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * </p>
1148e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *
1149e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @param permission A permission your app wants to request.
1150e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @return Whether you can show permission rationale UI.
1151e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     *
1152e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @see Context#checkSelfPermission(String)
1153e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @see #requestPermissions(String[], int)
1154e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     * @see #onRequestPermissionsResult(int, String[], int[])
1155e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav     */
1156e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    public boolean shouldShowRequestPermissionRationale(@NonNull String permission) {
1157e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav        if (mHost != null) {
1158e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav            return mHost.onShouldShowRequestPermissionRationale(permission);
1159e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav        }
1160e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav        return false;
1161e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    }
1162e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav
1163e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav    /**
116496221034e4a23a2abb83f772a0281bb197ac5ac0George Mount     * Returns the LayoutInflater used to inflate Views of this Fragment. The default
116596221034e4a23a2abb83f772a0281bb197ac5ac0George Mount     * implementation will throw an exception if the Fragment is not attached.
116696221034e4a23a2abb83f772a0281bb197ac5ac0George Mount     *
1167995c3504e6c5b1d20368c36193b44a7e6844709dGeorge Mount     * @param savedInstanceState If the fragment is being re-created from
1168995c3504e6c5b1d20368c36193b44a7e6844709dGeorge Mount     * a previous saved state, this is the state.
116996221034e4a23a2abb83f772a0281bb197ac5ac0George Mount     * @return The LayoutInflater used to inflate Views of this Fragment.
1170cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1171cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public LayoutInflater getLayoutInflater(Bundle savedInstanceState) {
117296221034e4a23a2abb83f772a0281bb197ac5ac0George Mount        if (mHost == null) {
117396221034e4a23a2abb83f772a0281bb197ac5ac0George Mount            throw new IllegalStateException("getLayoutInflater() cannot be executed until the "
117496221034e4a23a2abb83f772a0281bb197ac5ac0George Mount                    + "Fragment is attached to the FragmentManager.");
117596221034e4a23a2abb83f772a0281bb197ac5ac0George Mount        }
11768491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy        LayoutInflater result = mHost.onGetLayoutInflater();
11770f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell        getChildFragmentManager(); // Init if needed; use raw implementation below.
11784bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas        LayoutInflaterCompat.setFactory2(result, mChildFragmentManager.getLayoutInflaterFactory());
11790f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell        return result;
1180cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1181d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1182cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1183cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a fragment is being created as part of a view layout
1184cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * inflation, typically from setting the content view of an activity.  This
11859277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * may be called immediately after the fragment is created from a <fragment>
1186cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tag in a layout file.  Note this is <em>before</em> the fragment's
1187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onAttach(Activity)} has been called; all you should do here is
11889277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * parse the attributes and save them away.
11894bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1190cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>This is called every time the fragment is inflated, even if it is
11919277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * being inflated into a new instance with saved state.  It typically makes
11929277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * sense to re-parse the parameters each time, to allow them to change with
11939277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * different configurations.</p>
11949277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
11959277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>Here is a typical implementation of a fragment that can take parameters
11969277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * both through attributes supplied here as well from {@link #getArguments()}:</p>
11979277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
11989562a3b639225d406d736b64a12e2d75459259e3Alan Viverette     * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentArgumentsSupport.java
11999277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *      fragment}
12009277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
12019277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>Note that parsing the XML attributes uses a "styleable" resource.  The
12029277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * declaration for the styleable used here is:</p>
12039277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
12049562a3b639225d406d736b64a12e2d75459259e3Alan Viverette     * {@sample frameworks/support/samples/Support4Demos/res/values/attrs.xml fragment_arguments}
12054bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
12069277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>The fragment can then be declared within its activity's content layout
12079277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * through a tag like this:</p>
12089277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
12099562a3b639225d406d736b64a12e2d75459259e3Alan Viverette     * {@sample frameworks/support/samples/Support4Demos/res/layout/fragment_arguments_support.xml from_attributes}
12109277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
12119277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>This fragment can also be created dynamically from arguments given
12129277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * at runtime in the arguments Bundle; here is an example of doing so at
12139277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * creation of the containing activity:</p>
12149277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
12159562a3b639225d406d736b64a12e2d75459259e3Alan Viverette     * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentArgumentsSupport.java
12169277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *      create}
12179277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
1218d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * @param context The Activity that is inflating this fragment.
1219cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param attrs The attributes at the tag where the fragment is
1220cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * being created.
1221cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
1222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * a previous saved state, this is the state.
1223cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1224916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1225d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) {
1226d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        mCalled = true;
1227d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        final Activity hostActivity = mHost == null ? null : mHost.getActivity();
1228d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        if (hostActivity != null) {
1229d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            mCalled = false;
1230d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            onInflate(hostActivity, attrs, savedInstanceState);
1231d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        }
1232d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    }
1233d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1234d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    /**
1235d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * Called when a fragment is being created as part of a view layout
1236d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * inflation, typically from setting the content view of an activity.
1237d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette     *
1238d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette     * @deprecated See {@link #onInflate(Context, AttributeSet, Bundle)}.
1239d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     */
1240d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    @Deprecated
1241916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
12429277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
1243cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
12459f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
1246cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1247cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     * Called when a fragment is attached as a child of this fragment.
1248cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     *
1249cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     * <p>This is called after the attached fragment's <code>onAttach</code> and before
1250cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     * the attached fragment's <code>onCreate</code> if the fragment has not yet had a previous
1251cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     * call to <code>onCreate</code>.</p>
1252cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     *
1253cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     * @param childFragment child fragment being attached
1254cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell     */
1255cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell    public void onAttachFragment(Fragment childFragment) {
1256cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell    }
1257cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell
1258cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell    /**
1259d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * Called when a fragment is first attached to its context.
1260d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     * {@link #onCreate(Bundle)} will be called after this.
1261d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy     */
1262916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1263d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    public void onAttach(Context context) {
1264d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        mCalled = true;
1265d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        final Activity hostActivity = mHost == null ? null : mHost.getActivity();
1266d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        if (hostActivity != null) {
1267d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            mCalled = false;
1268d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            onAttach(hostActivity);
1269d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        }
1270d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    }
1271d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1272d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    /**
1273cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a fragment is first attached to its activity.
1274cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreate(Bundle)} will be called after this.
1275d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette     *
1276d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette     * @deprecated See {@link #onAttach(Context)}.
1277cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1278d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    @Deprecated
1279916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1280cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onAttach(Activity activity) {
1281cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1282cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1283d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1284cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1285cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a fragment loads an animation.
1286cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
12879277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
1288cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return null;
1289cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1290d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1291cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1292cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called to do initial creation of a fragment.  This is called after
1293cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onAttach(Activity)} and before
1294cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
12954bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1296cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>Note that this can be called while the fragment's activity is
1297cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * still in the process of being created.  As such, you can not rely
1298cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * on things like the activity's content view hierarchy being initialized
1299cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * at this point.  If you want to do work once the activity itself is
1300cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * created, see {@link #onActivityCreated(Bundle)}.
1301277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell     *
1302277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell     * <p>Any restored child fragments will be created before the base
1303277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell     * <code>Fragment.onCreate</code> method returns.</p>
13044bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1305cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
1306cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * a previous saved state, this is the state.
1307cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1308916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1309c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy    public void onCreate(@Nullable Bundle savedInstanceState) {
1310cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
13119375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell        restoreChildFragmentState(savedInstanceState);
1312fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell        if (mChildFragmentManager != null
1313fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell                && !mChildFragmentManager.isStateAtLeast(Fragment.CREATED)) {
1314fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell            mChildFragmentManager.dispatchCreate();
1315fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell        }
13169375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell    }
13179375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell
13189375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell    /**
13199375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * Restore the state of the child FragmentManager. Called by either
13209375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * {@link #onCreate(Bundle)} for non-retained instance fragments or by
13219375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * {@link FragmentManagerImpl#moveToState(Fragment, int, int, int, boolean)}
13229375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * for retained instance fragments.
13239375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     *
13249375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * <p><strong>Postcondition:</strong> if there were child fragments to restore,
13259375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * the child FragmentManager will be instantiated and brought to the {@link #CREATED} state.
13269375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * </p>
13279375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     *
13289375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * @param savedInstanceState the savedInstanceState potentially containing fragment info
13299375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     */
13309375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell    void restoreChildFragmentState(@Nullable Bundle savedInstanceState) {
1331277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell        if (savedInstanceState != null) {
1332277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell            Parcelable p = savedInstanceState.getParcelable(
1333277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell                    FragmentActivity.FRAGMENTS_TAG);
1334277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell            if (p != null) {
1335277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell                if (mChildFragmentManager == null) {
1336277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell                    instantiateChildFragmentManager();
1337277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell                }
1338c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell                mChildFragmentManager.restoreAllState(p, mChildNonConfig);
1339c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell                mChildNonConfig = null;
1340277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell                mChildFragmentManager.dispatchCreate();
1341277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell            }
1342277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell        }
1343cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
13440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
1345cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1346cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called to have the fragment instantiate its user interface view.
1347cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This is optional, and non-graphical fragments can return null (which
1348cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is the default implementation).  This will be called between
1349cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}.
13504bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1351cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>If you return a View from here, you will later be called in
1352cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onDestroyView} when the view is being released.
13534bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1354cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param inflater The LayoutInflater object that can be used to inflate
1355cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * any views in the fragment,
1356cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param container If non-null, this is the parent view that the fragment's
1357cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * UI should be attached to.  The fragment should not add the view itself,
1358cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * but this can be used to generate the LayoutParams of the view.
1359cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If non-null, this fragment is being re-constructed
1360cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * from a previous saved state as given here.
13614bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1362cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return Return the View for the fragment's UI, or null.
1363cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1364c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy    @Nullable
1365a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
1366a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye            @Nullable Bundle savedInstanceState) {
1367cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return null;
1368cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
13690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
1370cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1371e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
1372e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * has returned, but before any saved state has been restored in to the view.
1373e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * This gives subclasses a chance to initialize themselves once
1374e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * they know their view hierarchy has been completely created.  The fragment's
1375e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * view hierarchy is not however attached to its parent at this point.
1376e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
1377e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * @param savedInstanceState If non-null, this fragment is being re-constructed
1378e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * from a previous saved state as given here.
1379e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     */
1380a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
1381e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    }
1382e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn
1383e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    /**
1384cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}),
1385cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * if provided.
13864bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return The fragment's root view, or null if it has no layout.
1388cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1389a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye    @Nullable
1390cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public View getView() {
1391cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mView;
1392cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
13934bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1394cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1395cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment's activity has been created and this
1396cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * fragment's view hierarchy instantiated.  It can be used to do final
1397cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * initialization once these pieces are in place, such as retrieving
1398cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * views or restoring state.  It is also useful for fragments that use
1399cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #setRetainInstance(boolean)} to retain their instance,
1400cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * as this callback tells the fragment when it is fully associated with
1401cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the new activity instance.  This is called after {@link #onCreateView}
14020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * and before {@link #onViewStateRestored(Bundle)}.
14030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     *
1404cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
1405cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * a previous saved state, this is the state.
1406cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1407916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1408a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
1409cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1410cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
14110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
14120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    /**
14130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * Called when all saved state has been restored into the view hierarchy
14140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * of the fragment.  This can be used to do initialization based on saved
14150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * state that you are letting the view hierarchy track itself, such as
14160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * whether check box widgets are currently checked.  This is called
14170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * after {@link #onActivityCreated(Bundle)} and before
14180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * {@link #onStart()}.
14190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     *
14200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
14210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * a previous saved state, this is the state.
14220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     */
1423916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1424a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye    public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
14250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = true;
14260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
14270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
1428cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1429cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the Fragment is visible to the user.  This is generally
1430cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onStart() Activity.onStart} of the containing
1431cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
1432cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1433916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1434cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onStart() {
1435cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1436d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1437cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (!mLoadersStarted) {
1438cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mLoadersStarted = true;
1439cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (!mCheckedForLoaderManager) {
1440cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mCheckedForLoaderManager = true;
1441d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy                mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false);
1442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (mLoaderManager != null) {
1444cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mLoaderManager.doStart();
1445cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1446cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1447cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1448d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy
1449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1450cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment is visible to the user and actively running.
1451cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This is generally
1452cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onResume() Activity.onResume} of the containing
1453cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
1454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1455916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1456cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onResume() {
1457cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1458cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
14594bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1460cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1461cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called to ask the fragment to save its current dynamic state, so it
1462cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * can later be reconstructed in a new instance of its process is
1463cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * restarted.  If a new instance of the fragment later needs to be
1464cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * created, the data you place in the Bundle here will be available
1465cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * in the Bundle given to {@link #onCreate(Bundle)},
1466cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}, and
1467cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onActivityCreated(Bundle)}.
1468cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1469cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>This corresponds to {@link Activity#onSaveInstanceState(Bundle)
1470cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity.onSaveInstanceState(Bundle)} and most of the discussion there
1471cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * applies here as well.  Note however: <em>this method may be called
1472cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * at any time before {@link #onDestroy()}</em>.  There are many situations
1473cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * where a fragment may be mostly torn down (such as when placed on the
1474cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * back stack with no UI showing), but its state will not be saved until
1475cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * its owning activity actually needs to save its state.
1476cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1477cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param outState Bundle in which to place your saved state.
1478cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1479cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onSaveInstanceState(Bundle outState) {
1480cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
14815fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian
14825fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    /**
14835fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     * Called when the Fragment's activity changes from fullscreen mode to multi-window mode and
14845fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     * visa-versa. This is generally tied to {@link Activity#onMultiWindowModeChanged} of the
14855fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     * containing Activity.
14865fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     *
14875fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     * @param isInMultiWindowMode True if the activity is in multi-window mode.
14885fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     */
14895fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
14905fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    }
14915fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian
14925fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    /**
14935fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     * Called by the system when the activity changes to and from picture-in-picture mode. This is
14945fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     * generally tied to {@link Activity#onPictureInPictureModeChanged} of the containing Activity.
14955fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     *
14965fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode.
14975fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian     */
14985fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
14995fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    }
15005fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian
150190ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas    @Override
1502916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1503cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onConfigurationChanged(Configuration newConfig) {
1504cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1505cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
15065fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian
1507cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1508cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the Fragment is no longer resumed.  This is generally
1509cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onPause() Activity.onPause} of the containing
1510cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
1511cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1512916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1513cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onPause() {
1514cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1515cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
15164bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1517cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1518cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the Fragment is no longer started.  This is generally
1519cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onStop() Activity.onStop} of the containing
1520cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
1521cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1522916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1523cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onStop() {
1524cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1525cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1526916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell
152790ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas    @Override
1528916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1529cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onLowMemory() {
1530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
15324bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1533cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1534cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the view previously created by {@link #onCreateView} has
1535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * been detached from the fragment.  The next time the fragment needs
1536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to be displayed, a new view will be created.  This is called
1537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * after {@link #onStop()} and before {@link #onDestroy()}.  It is called
1538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <em>regardless</em> of whether {@link #onCreateView} returned a
1539cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * non-null view.  Internally it is called after the view's state has
1540cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * been saved but before it has been removed from its parent.
1541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1542916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1543cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDestroyView() {
1544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
15464bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment is no longer in use.  This is called
1549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * after {@link #onStop()} and before {@link #onDetach()}.
1550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1551916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDestroy() {
1553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        //Log.v("foo", "onDestroy: mCheckedForLoaderManager=" + mCheckedForLoaderManager
1555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        //        + " mLoaderManager=" + mLoaderManager);
1556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (!mCheckedForLoaderManager) {
1557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mCheckedForLoaderManager = true;
1558d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false);
1559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mLoaderManager != null) {
1561cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mLoaderManager.doDestroy();
1562cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1563cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1564cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1565cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
15669c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * Called by the fragment manager once this fragment has been removed,
15679c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * so that we don't have any left-over state if the application decides
15689c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * to re-use the instance.  This only clears state that the framework
15699c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * internally manages, not things the application sets.
15709c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     */
15719c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    void initState() {
15729c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mIndex = -1;
15739c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mWho = null;
15749c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mAdded = false;
15759c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mRemoving = false;
15769c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mFromLayout = false;
15779c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mInLayout = false;
15789c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mRestored = false;
15799c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mBackStackNesting = 0;
15809c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mFragmentManager = null;
15816252d78085a07c9d6bb4645a4e8086bf23b0a49aTim Kilbourn        mChildFragmentManager = null;
1582d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        mHost = null;
15839c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mFragmentId = 0;
15849c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mContainerId = 0;
15859c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mTag = null;
15869c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mHidden = false;
15879c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mDetached = false;
15889c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mRetaining = false;
15899c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mLoaderManager = null;
15909c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mLoadersStarted = false;
15919c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mCheckedForLoaderManager = false;
15929c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
15939c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
15949c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    /**
1595cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment is no longer attached to its activity.  This
1596cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is called after {@link #onDestroy()}.
1597cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1598916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    @CallSuper
1599cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDetach() {
1600cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1601cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
16024bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1603cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
16049375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * Initialize the contents of the Fragment host's standard options menu.  You
1605cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * should place your menu items in to <var>menu</var>.  For this method
1606cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to be called, you must have first called {@link #setHasOptionsMenu}.  See
1607cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu}
1608cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for more information.
16094bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1610cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param menu The options menu in which you place your items.
16114bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1612cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #setHasOptionsMenu
1613cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onPrepareOptionsMenu
1614cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onOptionsItemSelected
1615cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1616cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
1617cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1618cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1619cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
16209375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell     * Prepare the Fragment host's standard options menu to be displayed.  This is
1621cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * called right before the menu is shown, every time it is shown.  You can
1622cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * use this method to efficiently enable/disable items or otherwise
1623cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * dynamically modify the contents.  See
1624cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu}
1625cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for more information.
16264bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1627cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param menu The options menu as last shown or first initialized by
1628cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *             onCreateOptionsMenu().
16294bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1630cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #setHasOptionsMenu
1631cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onCreateOptionsMenu
1632cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1633cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onPrepareOptionsMenu(Menu menu) {
1634cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1635cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1636cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1637cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when this fragment's option menu items are no longer being
1638cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * included in the overall options menu.  Receiving this call means that
1639cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the menu needed to be rebuilt, but this fragment's items were not
1640cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * included in the newly built menu (its {@link #onCreateOptionsMenu(Menu, MenuInflater)}
1641cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * was not called).
1642cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1643cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDestroyOptionsMenu() {
1644cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
16454bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1646cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1647cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This hook is called whenever an item in your options menu is selected.
1648cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * The default implementation simply returns false to have the normal
1649cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * processing happen (calling the item's Runnable or sending a message to
1650cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * its Handler as appropriate).  You can use this method for any items
1651cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for which you would like to do processing without those other
1652cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * facilities.
16534bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1654cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>Derived classes should call through to the base class for it to
1655cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * perform the default menu handling.
16564bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1657cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param item The menu item that was selected.
16584bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1659cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return boolean Return false to allow normal menu processing to
1660cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *         proceed, true to consume it here.
16614bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1662cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onCreateOptionsMenu
1663cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1664cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean onOptionsItemSelected(MenuItem item) {
1665cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return false;
1666cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1667cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1668cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1669cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This hook is called whenever the options menu is being closed (either by the user canceling
1670cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the menu with the back/menu button, or when an item is selected).
16714bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1672cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param menu The options menu as last shown or first initialized by
1673cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *             onCreateOptionsMenu().
1674cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1675cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onOptionsMenuClosed(Menu menu) {
1676cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
16774bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1678cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1679cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a context menu for the {@code view} is about to be shown.
1680cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Unlike {@link #onCreateOptionsMenu}, this will be called every
1681cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * time the context menu is about to be shown and should be populated for
1682cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the view (or item inside the view for {@link AdapterView} subclasses,
1683cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * this can be found in the {@code menuInfo})).
1684cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1685cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an
1686cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * item has been selected.
1687cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1688cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * The default implementation calls up to
1689cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though
1690cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * you can not call this implementation if you don't want that behavior.
1691cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1692cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * It is not safe to hold onto the context menu after this method returns.
1693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@inheritDoc}
1694cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1695d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy    @Override
1696cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
1697cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        getActivity().onCreateContextMenu(menu, v, menuInfo);
1698cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1699cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1700cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1701cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Registers a context menu to be shown for the given view (multiple views
1702cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * can show the context menu). This method will set the
1703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link OnCreateContextMenuListener} on the view to this fragment, so
1704cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be
1705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * called when it is time to show the context menu.
17064bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1707cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #unregisterForContextMenu(View)
1708cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param view The view that should show a context menu.
1709cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1710cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void registerForContextMenu(View view) {
1711cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        view.setOnCreateContextMenuListener(this);
1712cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
17134bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1714cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1715cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Prevents a context menu to be shown for the given view. This method will
1716cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * remove the {@link OnCreateContextMenuListener} on the view.
17174bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1718cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #registerForContextMenu(View)
1719cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param view The view that should stop showing a context menu.
1720cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1721cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void unregisterForContextMenu(View view) {
1722cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        view.setOnCreateContextMenuListener(null);
1723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
17244bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas
1725cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1726cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This hook is called whenever an item in a context menu is selected. The
1727cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default implementation simply returns false to have the normal processing
1728cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * happen (calling the item's Runnable or sending a message to its Handler
1729cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * as appropriate). You can use this method for any items for which you
1730cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * would like to do processing without those other facilities.
1731cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1732cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Use {@link MenuItem#getMenuInfo()} to get extra information set by the
1733cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * View that added this menu item.
1734cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1735cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Derived classes should call through to the base class for it to perform
1736cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the default menu handling.
17374bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas     *
1738cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param item The context menu item that was selected.
1739cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return boolean Return false to allow normal context menu processing to
1740cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *         proceed, true to consume it here.
1741cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1742cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean onContextItemSelected(MenuItem item) {
1743cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return false;
1744cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1745e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes
1746cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
17479306f07b1d66f4974a81f781d29739b30124fff0George Mount     * When custom transitions are used with Fragments, the enter transition callback
17489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * is called when this Fragment is attached or detached when not popping the back stack.
17499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
17509306f07b1d66f4974a81f781d29739b30124fff0George Mount     * @param callback Used to manipulate the shared element transitions on this Fragment
17519f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                 when added not as a pop from the back stack.
17529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
1753b1413bc4de16e05ae0455cad93f1edfbcc4eced2George Mount    public void setEnterSharedElementCallback(SharedElementCallback callback) {
1754990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mEnterTransitionCallback = callback;
17559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
17569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
17579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
17589306f07b1d66f4974a81f781d29739b30124fff0George Mount     * When custom transitions are used with Fragments, the exit transition callback
17599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * is called when this Fragment is attached or detached when popping the back stack.
17609f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
17619306f07b1d66f4974a81f781d29739b30124fff0George Mount     * @param callback Used to manipulate the shared element transitions on this Fragment
17629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                 when added as a pop from the back stack.
17639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
1764b1413bc4de16e05ae0455cad93f1edfbcc4eced2George Mount    public void setExitSharedElementCallback(SharedElementCallback callback) {
1765990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mExitTransitionCallback = callback;
17669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
17679f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
17689f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
17699f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets the Transition that will be used to move Views into the initial scene. The entering
17709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Views will be those that are regular Views or ViewGroups that have
17719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
17729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.Visibility} as entering is governed by changing visibility from
17739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
17749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * entering Views will remain unaffected.
17759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
17769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param transition The Transition to use to move Views into the initial Scene.
17779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
17789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public void setEnterTransition(Object transition) {
1779990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mEnterTransition = transition;
17809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
17819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
17829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
17839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Returns the Transition that will be used to move Views into the initial scene. The entering
17849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Views will be those that are regular Views or ViewGroups that have
17859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
17869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.Visibility} as entering is governed by changing visibility from
17879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link View#INVISIBLE} to {@link View#VISIBLE}.
17889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
17899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return the Transition to use to move Views into the initial Scene.
17909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
17919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public Object getEnterTransition() {
1792990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
1793990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
1794990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
1795990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mEnterTransition;
17969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
17979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
17989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
17999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets the Transition that will be used to move Views out of the scene when the Fragment is
18009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * preparing to be removed, hidden, or detached because of popping the back stack. The exiting
18019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Views will be those that are regular Views or ViewGroups that have
18029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
18039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.Visibility} as entering is governed by changing visibility from
18049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
18059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * entering Views will remain unaffected. If nothing is set, the default will be to
18069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * use the same value as set in {@link #setEnterTransition(Object)}.
18079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
18089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param transition The Transition to use to move Views out of the Scene when the Fragment
18099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                   is preparing to close. <code>transition</code> must be an
18109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                   android.transition.Transition.
18119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
18129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public void setReturnTransition(Object transition) {
1813990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mReturnTransition = transition;
18149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
18159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
18169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
18179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Returns the Transition that will be used to move Views out of the scene when the Fragment is
18189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * preparing to be removed, hidden, or detached because of popping the back stack. The exiting
18199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Views will be those that are regular Views or ViewGroups that have
18209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
18219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.Visibility} as entering is governed by changing visibility from
18229f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
18239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * entering Views will remain unaffected.
18249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
18259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return the Transition to use to move Views out of the Scene when the Fragment
18269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *         is preparing to close.
18279f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
18289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public Object getReturnTransition() {
1829990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
1830990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
1831990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
1832990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mReturnTransition == USE_DEFAULT_TRANSITION ? getEnterTransition()
1833990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                : mAnimationInfo.mReturnTransition;
18349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
18359f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
18369f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
18379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets the Transition that will be used to move Views out of the scene when the
18389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * fragment is removed, hidden, or detached when not popping the back stack.
18399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * The exiting Views will be those that are regular Views or ViewGroups that
18409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
18419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.Visibility} as exiting is governed by changing visibility
18429f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
18439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * remain unaffected.
18449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
18459f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param transition The Transition to use to move Views out of the Scene when the Fragment
18469f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                   is being closed not due to popping the back stack. <code>transition</code>
18479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                   must be an android.transition.Transition.
18489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
18499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public void setExitTransition(Object transition) {
1850990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mExitTransition = transition;
18519f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
18529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
18539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
18549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Returns the Transition that will be used to move Views out of the scene when the
18559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * fragment is removed, hidden, or detached when not popping the back stack.
18569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * The exiting Views will be those that are regular Views or ViewGroups that
18579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
18589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.Visibility} as exiting is governed by changing visibility
18599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
18609f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * remain unaffected.
18619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
18629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return the Transition to use to move Views out of the Scene when the Fragment
18639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *         is being closed not due to popping the back stack.
18649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
18659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public Object getExitTransition() {
1866990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
1867990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
1868990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
1869990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mExitTransition;
18709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
18719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
18729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
18739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets the Transition that will be used to move Views in to the scene when returning due
18749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * to popping a back stack. The entering Views will be those that are regular Views
18759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
18769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * will extend {@link android.transition.Visibility} as exiting is governed by changing
18779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
18789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * the views will remain unaffected. If nothing is set, the default will be to use the same
18799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * transition as {@link #setExitTransition(Object)}.
18809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
18819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param transition The Transition to use to move Views into the scene when reentering from a
18829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                   previously-started Activity. <code>transition</code>
18839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                   must be an android.transition.Transition.
18849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
18859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public void setReenterTransition(Object transition) {
1886990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mReenterTransition = transition;
18879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
18889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
18899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
18909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Returns the Transition that will be used to move Views in to the scene when returning due
18919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * to popping a back stack. The entering Views will be those that are regular Views
18929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
18939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * will extend {@link android.transition.Visibility} as exiting is governed by changing
18949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
18959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * the views will remain unaffected. If nothing is set, the default will be to use the same
18969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * transition as {@link #setExitTransition(Object)}.
18979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
18989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return the Transition to use to move Views into the scene when reentering from a
18999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                   previously-started Activity.
19009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
19019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public Object getReenterTransition() {
1902990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
1903990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
1904990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
1905990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mReenterTransition == USE_DEFAULT_TRANSITION ? getExitTransition()
1906990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                : mAnimationInfo.mReenterTransition;
19079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
19089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
19099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
19109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets the Transition that will be used for shared elements transferred into the content
19119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Scene. Typical Transitions will affect size and location, such as
19129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.ChangeBounds}. A null
19139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * value will cause transferred shared elements to blink to the final position.
19149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
19159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param transition The Transition to use for shared elements transferred into the content
19169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                   Scene.  <code>transition</code> must be an android.transition.Transition.
19179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
19189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public void setSharedElementEnterTransition(Object transition) {
1919990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mSharedElementEnterTransition = transition;
19209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
19219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
19229f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
19239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Returns the Transition that will be used for shared elements transferred into the content
19249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Scene. Typical Transitions will affect size and location, such as
19259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.ChangeBounds}. A null
19269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * value will cause transferred shared elements to blink to the final position.
19279f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
19289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return The Transition to use for shared elements transferred into the content
19299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                   Scene.
19309f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
19319f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public Object getSharedElementEnterTransition() {
1932990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
1933990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
1934990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
1935990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mSharedElementEnterTransition;
19369f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
19379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
19389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
19399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets the Transition that will be used for shared elements transferred back during a
19409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * pop of the back stack. This Transition acts in the leaving Fragment.
19419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Typical Transitions will affect size and location, such as
19429f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.ChangeBounds}. A null
19439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * value will cause transferred shared elements to blink to the final position.
19449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * If no value is set, the default will be to use the same value as
19459f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link #setSharedElementEnterTransition(Object)}.
19469f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
19479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param transition The Transition to use for shared elements transferred out of the content
19489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                   Scene. <code>transition</code> must be an android.transition.Transition.
19499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
19509f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public void setSharedElementReturnTransition(Object transition) {
1951990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mSharedElementReturnTransition = transition;
19529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
19539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
19549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
19559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Return the Transition that will be used for shared elements transferred back during a
19569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * pop of the back stack. This Transition acts in the leaving Fragment.
19579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Typical Transitions will affect size and location, such as
19589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link android.transition.ChangeBounds}. A null
19599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * value will cause transferred shared elements to blink to the final position.
19609f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * If no value is set, the default will be to use the same value as
19619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * {@link #setSharedElementEnterTransition(Object)}.
19629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
19639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return The Transition to use for shared elements transferred out of the content
19649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *                   Scene.
19659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
19669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public Object getSharedElementReturnTransition() {
1967990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
1968990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
1969990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
1970990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mSharedElementReturnTransition == USE_DEFAULT_TRANSITION
1971990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                ? getSharedElementEnterTransition()
1972990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                : mAnimationInfo.mSharedElementReturnTransition;
19739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
19749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
19759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
19769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets whether the the exit transition and enter transition overlap or not.
19779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * When true, the enter transition will start as soon as possible. When false, the
19789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * enter transition will wait until the exit transition completes before starting.
19799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
19809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param allow true to start the enter transition when possible or false to
19819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *              wait until the exiting transition completes.
19829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
19839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public void setAllowEnterTransitionOverlap(boolean allow) {
1984990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mAllowEnterTransitionOverlap = allow;
19859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
19869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
19879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
19889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Returns whether the the exit transition and enter transition overlap or not.
19899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * When true, the enter transition will start as soon as possible. When false, the
19909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * enter transition will wait until the exit transition completes before starting.
19919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
19929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return true when the enter transition should start as soon as possible or false to
19939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * when it should wait until the exiting transition completes.
19949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
19959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public boolean getAllowEnterTransitionOverlap() {
1996990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return (mAnimationInfo == null || mAnimationInfo.mAllowEnterTransitionOverlap == null)
1997990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                ? true : mAnimationInfo.mAllowEnterTransitionOverlap;
19989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
19999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
20009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
20019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Sets whether the the return transition and reenter transition overlap or not.
20029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * When true, the reenter transition will start as soon as possible. When false, the
20039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * reenter transition will wait until the return transition completes before starting.
20049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
20059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @param allow true to start the reenter transition when possible or false to wait until the
20069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *              return transition completes.
20079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
20089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public void setAllowReturnTransitionOverlap(boolean allow) {
2009990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mAllowReturnTransitionOverlap = allow;
20109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
20119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
20129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
20139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * Returns whether the the return transition and reenter transition overlap or not.
20149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * When true, the reenter transition will start as soon as possible. When false, the
20159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * reenter transition will wait until the return transition completes before starting.
20169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *
20179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     * @return true to start the reenter transition when possible or false to wait until the
20189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     *         return transition completes.
20199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount     */
20209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    public boolean getAllowReturnTransitionOverlap() {
2021990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return (mAnimationInfo == null || mAnimationInfo.mAllowReturnTransitionOverlap == null)
2022990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                ? true : mAnimationInfo.mAllowReturnTransitionOverlap;
2023990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2024990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2025990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    /**
2026990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * Postpone the entering Fragment transition until {@link #startPostponedEnterTransition()}
2027990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * or {@link FragmentManager#executePendingTransactions()} has been called.
2028990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * <p>
2029990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * This method gives the Fragment the ability to delay Fragment animations
2030990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * until all data is loaded. Until then, the added, shown, and
2031990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * attached Fragments will be INVISIBLE and removed, hidden, and detached Fragments won't
2032990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * be have their Views removed. The transaction runs when all postponed added Fragments in the
2033990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * transaction have called {@link #startPostponedEnterTransition()}.
2034990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * <p>
2035990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * This method should be called before being added to the FragmentTransaction or
2036990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * in {@link #onCreate(Bundle), {@link #onAttach(Context)}, or
2037990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}}.
2038990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * {@link #startPostponedEnterTransition()} must be called to allow the Fragment to
2039990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * start the transitions.
2040990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * <p>
2041990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * When a FragmentTransaction is started that may affect a postponed FragmentTransaction,
2042990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * based on which containers are in their operations, the postponed FragmentTransaction
2043990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * will have its start triggered. The early triggering may result in faulty or nonexistent
2044990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * animations in the postponed transaction. FragmentTransactions that operate only on
2045990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * independent containers will not interfere with each other's postponement.
2046990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * <p>
2047990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * Calling postponeEnterTransition on Fragments with a null View will not postpone the
2048990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * transition. Likewise, postponement only works if FragmentTransaction optimizations are
2049990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * enabled.
2050990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     *
2051990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * @see Activity#postponeEnterTransition()
2052990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * @see FragmentTransaction#setAllowOptimization(boolean)
2053990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     */
2054990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    public void postponeEnterTransition() {
2055990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mEnterTransitionPostponed = true;
2056990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2057990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2058990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    /**
2059990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * Begin postponed transitions after {@link #postponeEnterTransition()} was called.
2060990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * If postponeEnterTransition() was called, you must call startPostponedEnterTransition()
2061990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * or {@link FragmentManager#executePendingTransactions()} to complete the FragmentTransaction.
2062990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * If postponement was interrupted with {@link FragmentManager#executePendingTransactions()},
2063990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * before {@code startPostponedEnterTransition()}, animations may not run or may execute
2064990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * improperly.
2065990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     *
2066990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * @see Activity#startPostponedEnterTransition()
2067990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     */
2068990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    public void startPostponedEnterTransition() {
2069990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mFragmentManager == null || mFragmentManager.mHost == null) {
2070990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            ensureAnimationInfo().mEnterTransitionPostponed = false;
2071990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        } else if (Looper.myLooper() != mFragmentManager.mHost.getHandler().getLooper()) {
2072990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            mFragmentManager.mHost.getHandler().postAtFrontOfQueue(new Runnable() {
2073990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                @Override
2074990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                public void run() {
2075990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                    callStartTransitionListener();
2076990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                }
2077990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            });
2078990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        } else {
2079990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            callStartTransitionListener();
2080990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2081990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2082990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2083990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    /**
2084990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * Calls the start transition listener. This must be called on the UI thread.
2085990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     */
2086990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    private void callStartTransitionListener() {
2087990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        final OnStartEnterTransitionListener listener;
2088990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2089990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            listener = null;
2090990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        } else {
2091990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            mAnimationInfo.mEnterTransitionPostponed = false;
2092990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            listener = mAnimationInfo.mStartEnterTransitionListener;
2093990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            mAnimationInfo.mStartEnterTransitionListener = null;
2094990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2095990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (listener != null) {
2096990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            listener.onStartEnterTransition();
2097990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
20989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    }
20999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount
21009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount    /**
2101cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Print the Fragments's state into the given stream.
2102cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
2103cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param prefix Text to print at the front of each line.
2104cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param fd The raw file descriptor that the dump is being sent to.
2105cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param writer The PrintWriter to which you should dump your state.  This will be
2106cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * closed for you after you return.
2107cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param args additional arguments to the dump request.
2108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
2109cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
2110cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mFragmentId=#");
2111cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(Integer.toHexString(mFragmentId));
21125506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                writer.print(" mContainerId=#");
2113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(Integer.toHexString(mContainerId));
2114cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mTag="); writer.println(mTag);
2115cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mState="); writer.print(mState);
2116cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mIndex="); writer.print(mIndex);
2117cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mWho="); writer.print(mWho);
2118cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mBackStackNesting="); writer.println(mBackStackNesting);
2119cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mAdded="); writer.print(mAdded);
2120cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mRemoving="); writer.print(mRemoving);
2121cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mFromLayout="); writer.print(mFromLayout);
2122cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mInLayout="); writer.println(mInLayout);
2123cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mHidden="); writer.print(mHidden);
2124e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                writer.print(" mDetached="); writer.print(mDetached);
21252a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn                writer.print(" mMenuVisible="); writer.print(mMenuVisible);
2126cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mHasMenu="); writer.println(mHasMenu);
21272a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        writer.print(prefix); writer.print("mRetainInstance="); writer.print(mRetainInstance);
212879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                writer.print(" mRetaining="); writer.print(mRetaining);
212979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                writer.print(" mUserVisibleHint="); writer.println(mUserVisibleHint);
2130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mFragmentManager != null) {
2131cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mFragmentManager=");
2132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mFragmentManager);
2133cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2134d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        if (mHost != null) {
2135d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy            writer.print(prefix); writer.print("mHost=");
2136d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy                    writer.println(mHost);
2137cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
21380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mParentFragment != null) {
21390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            writer.print(prefix); writer.print("mParentFragment=");
21400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    writer.println(mParentFragment);
21410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
2142cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mArguments != null) {
2143cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mArguments="); writer.println(mArguments);
2144cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2145cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mSavedFragmentState != null) {
2146cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mSavedFragmentState=");
2147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mSavedFragmentState);
2148cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mSavedViewState != null) {
2150cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mSavedViewState=");
2151cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mSavedViewState);
2152cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2153cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mTarget != null) {
2154cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mTarget="); writer.print(mTarget);
2155cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.print(" mTargetRequestCode=");
2156cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mTargetRequestCode);
2157cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2158990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (getNextAnim() != 0) {
2159990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            writer.print(prefix); writer.print("mNextAnim="); writer.println(getNextAnim());
2160cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2161cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mContainer != null) {
2162cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mContainer="); writer.println(mContainer);
2163cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2164cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mView != null) {
2165cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mView="); writer.println(mView);
2166cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2167cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mInnerView != null) {
2168cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mInnerView="); writer.println(mView);
2169cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2170990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (getAnimatingAway() != null) {
2171990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            writer.print(prefix);
2172990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            writer.print("mAnimatingAway=");
2173990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            writer.println(getAnimatingAway());
2174990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            writer.print(prefix);
2175990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            writer.print("mStateAfterAnimating=");
2176990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            writer.println(getStateAfterAnimating());
2177cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2178cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mLoaderManager != null) {
2179cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.println("Loader Manager:");
2180cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mLoaderManager.dump(prefix + "  ", fd, writer, args);
2181cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
21820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
21830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            writer.print(prefix); writer.println("Child " + mChildFragmentManager + ":");
21840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dump(prefix + "  ", fd, writer, args);
21850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
21860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
21870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
21880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    Fragment findFragmentByWho(String who) {
21890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (who.equals(mWho)) {
21900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            return this;
21910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
21920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
21930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            return mChildFragmentManager.findFragmentByWho(who);
21940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
21950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return null;
21960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
21970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
21980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void instantiateChildFragmentManager() {
21991c7e1f738e202226b365c81715b221d2e864fdd5George Mount        if (mHost == null) {
22001c7e1f738e202226b365c81715b221d2e864fdd5George Mount            throw new IllegalStateException("Fragment has not been attached yet.");
22011c7e1f738e202226b365c81715b221d2e864fdd5George Mount        }
2202e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        mChildFragmentManager = new FragmentManagerImpl();
2203d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy        mChildFragmentManager.attachController(mHost, new FragmentContainer() {
22040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            @Override
22050fb3ec354da6c1f3ed1777bca5270710cc537e92Scott Kennedy            @Nullable
22068491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy            public View onFindViewById(int id) {
22070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (mView == null) {
22080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    throw new IllegalStateException("Fragment does not have a view");
22090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                }
22100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                return mView.findViewById(id);
22110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
22127516316ffdf6fbf7b248c615404831191daa66a4George Mount
22137516316ffdf6fbf7b248c615404831191daa66a4George Mount            @Override
22148491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy            public boolean onHasView() {
22157516316ffdf6fbf7b248c615404831191daa66a4George Mount                return (mView != null);
22167516316ffdf6fbf7b248c615404831191daa66a4George Mount            }
22174aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell
22184aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell            @Override
22194aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell            public Fragment instantiate(Context context, String className, Bundle arguments) {
22204aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell                return mHost.instantiate(context, className, arguments);
22214aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell            }
22220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }, this);
22230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
22240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
22250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performCreate(Bundle savedInstanceState) {
22260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
22270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
22280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
222920735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = CREATED;
22300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
22310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onCreate(savedInstanceState);
22320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
22330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
22340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onCreate()");
22350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
22360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
22370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
22380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    View performCreateView(LayoutInflater inflater, ViewGroup container,
22390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            Bundle savedInstanceState) {
22400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
22410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
22420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
224337149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell        mPerformedCreateView = true;
22440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return onCreateView(inflater, container, savedInstanceState);
22450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
22460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
22470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performActivityCreated(Bundle savedInstanceState) {
22480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
22490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
22500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
225120735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = ACTIVITY_CREATED;
22520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
22530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onActivityCreated(savedInstanceState);
22540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
22550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
22560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onActivityCreated()");
22570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
22580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
22590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchActivityCreated();
22600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
2261cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
2262cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
22639c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    void performStart() {
22640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
22650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
22660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.execPendingActions();
22670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
226820735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = STARTED;
22690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
22709c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        onStart();
22710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
22720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
22730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onStart()");
22740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
22750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
22760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchStart();
22770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
22789c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        if (mLoaderManager != null) {
22799c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn            mLoaderManager.doReportStart();
22809c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        }
22819c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
22829c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
22830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performResume() {
22840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
22850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
22860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.execPendingActions();
22870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
228820735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = RESUMED;
22890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
22900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onResume();
22910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
22920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
22930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onResume()");
22940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
22950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
22960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchResume();
22970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.execPendingActions();
22980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
22990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
23000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
23015fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    void performMultiWindowModeChanged(boolean isInMultiWindowMode) {
23025fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian        onMultiWindowModeChanged(isInMultiWindowMode);
23035fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian        if (mChildFragmentManager != null) {
23045fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian            mChildFragmentManager.dispatchMultiWindowModeChanged(isInMultiWindowMode);
23055fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian        }
23065fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    }
23075fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian
23085fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    void performPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
23095fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian        onPictureInPictureModeChanged(isInPictureInPictureMode);
23105fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian        if (mChildFragmentManager != null) {
23115fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian            mChildFragmentManager.dispatchPictureInPictureModeChanged(isInPictureInPictureMode);
23125fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian        }
23135fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian    }
23145fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian
23150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performConfigurationChanged(Configuration newConfig) {
23160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onConfigurationChanged(newConfig);
23170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
23180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchConfigurationChanged(newConfig);
23190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
23200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
23210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
23220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performLowMemory() {
23230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onLowMemory();
23240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
23250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchLowMemory();
23260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
23270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
23280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
23290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    /*
23300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performTrimMemory(int level) {
23310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onTrimMemory(level);
23320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
23330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchTrimMemory(level);
23340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
23350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
23360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    */
23370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
23380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    boolean performCreateOptionsMenu(Menu menu, MenuInflater inflater) {
23390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        boolean show = false;
23400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
23410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mHasMenu && mMenuVisible) {
23420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                show = true;
23430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                onCreateOptionsMenu(menu, inflater);
23440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
23450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
23460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                show |= mChildFragmentManager.dispatchCreateOptionsMenu(menu, inflater);
23470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
23480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
23490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return show;
23500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
23510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
23520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    boolean performPrepareOptionsMenu(Menu menu) {
23530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        boolean show = false;
23540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
23550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mHasMenu && mMenuVisible) {
23560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                show = true;
23570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                onPrepareOptionsMenu(menu);
23580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
23590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
23600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                show |= mChildFragmentManager.dispatchPrepareOptionsMenu(menu);
23610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
23620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
23630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return show;
23640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
23650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
23660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    boolean performOptionsItemSelected(MenuItem item) {
23670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
23680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mHasMenu && mMenuVisible) {
23690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (onOptionsItemSelected(item)) {
23700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    return true;
23710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                }
23720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
23730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
23740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (mChildFragmentManager.dispatchOptionsItemSelected(item)) {
23750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    return true;
23760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                }
23770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
23780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
23790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return false;
23800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
23810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
23820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    boolean performContextItemSelected(MenuItem item) {
23830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
23840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (onContextItemSelected(item)) {
23850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                return true;
23860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
23870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
23880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (mChildFragmentManager.dispatchContextItemSelected(item)) {
23890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    return true;
23900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                }
23910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
23920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
23930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return false;
23940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
23950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
23960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performOptionsMenuClosed(Menu menu) {
23970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
23980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mHasMenu && mMenuVisible) {
23990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                onOptionsMenuClosed(menu);
24000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
24010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
24020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchOptionsMenuClosed(menu);
24030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
24040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
24050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
24060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
24070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performSaveInstanceState(Bundle outState) {
24080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onSaveInstanceState(outState);
24090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
24100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            Parcelable p = mChildFragmentManager.saveAllState();
24110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (p != null) {
24120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                outState.putParcelable(FragmentActivity.FRAGMENTS_TAG, p);
24130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
24140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
24150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
24160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
24170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performPause() {
24180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
24190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchPause();
24200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
242120735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = STARTED;
24220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
24230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onPause();
24240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
24250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
24260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onPause()");
24270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
24280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
24290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
2430cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void performStop() {
24310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
24320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchStop();
24330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
243420735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = STOPPED;
24350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
2436cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        onStop();
24370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
24380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
24390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onStop()");
24400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
2441681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn    }
2442681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn
2443218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn    void performReallyStop() {
24440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
24450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchReallyStop();
24460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
244720735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = ACTIVITY_CREATED;
2448cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mLoadersStarted) {
2449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mLoadersStarted = false;
2450cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (!mCheckedForLoaderManager) {
2451cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mCheckedForLoaderManager = true;
2452d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy                mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false);
2453cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
2454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (mLoaderManager != null) {
245564ece2df3d6d789f7a642692acbe85fa1b998d6bTodd Kennedy                if (mHost.getRetainLoaders()) {
2456cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    mLoaderManager.doRetain();
24572bdd09a243b422960168170e2344274cc9cfd788Todd Kennedy                } else {
24582bdd09a243b422960168170e2344274cc9cfd788Todd Kennedy                    mLoaderManager.doStop();
2459cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
2460cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
2461cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2462cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
24639c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
24649c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    void performDestroyView() {
24650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
24660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchDestroyView();
24670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
246820735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = CREATED;
24690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
24709c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        onDestroyView();
24710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
24720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
24730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onDestroyView()");
24740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
24759c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        if (mLoaderManager != null) {
24769c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn            mLoaderManager.doReportNextStart();
24779c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        }
247837149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell        mPerformedCreateView = false;
24799c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
24800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
24810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performDestroy() {
24820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
24830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchDestroy();
24840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
248520735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell        mState = INITIALIZING;
24860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
24870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onDestroy();
24880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
24890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
24900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onDestroy()");
24910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
24924706c089880423ee5929d4635c6dfc5c3151b20fGeorge Mount        mChildFragmentManager = null;
24930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
24949375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell
2495916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    void performDetach() {
2496916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        mCalled = false;
2497916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        onDetach();
2498916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        if (!mCalled) {
2499916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell            throw new SuperNotCalledException("Fragment " + this
2500916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell                    + " did not call through to super.onDetach()");
2501916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        }
2502916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell
2503916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        // Destroy the child FragmentManager if we still have it here.
2504916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        // We won't unless we're retaining our instance and if we do,
2505916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        // our child FragmentManager instance state will have already been saved.
2506916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        if (mChildFragmentManager != null) {
2507916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell            if (!mRetaining) {
2508916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell                throw new IllegalStateException("Child FragmentManager of " + this + " was not "
2509916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell                        + " destroyed and this fragment is not retaining instance");
2510916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell            }
2511916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell            mChildFragmentManager.dispatchDestroy();
2512916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell            mChildFragmentManager = null;
2513916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell        }
2514916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell    }
2515916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell
2516990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    void setOnStartEnterTransitionListener(OnStartEnterTransitionListener listener) {
2517990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo();
2518990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (listener == mAnimationInfo.mStartEnterTransitionListener) {
2519990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return;
2520990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2521990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (listener != null && mAnimationInfo.mStartEnterTransitionListener != null) {
2522990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            throw new IllegalStateException("Trying to set a replacement "
2523990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount                    + "startPostponedEnterTransition on " + this);
2524990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2525990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo.mEnterTransitionPostponed) {
2526990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            mAnimationInfo.mStartEnterTransitionListener = listener;
2527990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2528990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (listener != null) {
2529990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            listener.startListening();
2530990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2531990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2532990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2533990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    private AnimationInfo ensureAnimationInfo() {
2534990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2535990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            mAnimationInfo = new AnimationInfo();
2536990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2537990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo;
2538990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2539990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2540990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    int getNextAnim() {
2541990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2542990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return 0;
2543990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2544990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mNextAnim;
2545990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2546990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2547990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    void setNextAnim(int animResourceId) {
2548990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null && animResourceId == 0) {
2549990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return; // no change!
2550990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2551990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mNextAnim = animResourceId;
2552990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2553990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2554990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    int getNextTransition() {
2555990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2556990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return 0;
2557990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2558990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mNextTransition;
2559990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2560990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2561990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    void setNextTransition(int nextTransition, int nextTransitionStyle) {
2562990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null && nextTransition == 0 && nextTransitionStyle == 0) {
2563990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return; // no change!
2564990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2565990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo();
2566990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        mAnimationInfo.mNextTransition = nextTransition;
2567990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        mAnimationInfo.mNextTransitionStyle = nextTransitionStyle;
2568990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2569990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2570990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    int getNextTransitionStyle() {
2571990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2572990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return 0;
2573990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2574990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mNextTransitionStyle;
2575990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2576990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2577990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    SharedElementCallback getEnterTransitionCallback() {
2578990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2579990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
2580990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2581990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mEnterTransitionCallback;
2582990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2583990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2584990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    SharedElementCallback getExitTransitionCallback() {
2585990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2586990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
2587990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2588990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mExitTransitionCallback;
2589990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2590990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2591990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    View getAnimatingAway() {
2592990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2593990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return null;
2594990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2595990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mAnimatingAway;
2596990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2597990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2598990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    void setAnimatingAway(View view) {
2599990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mAnimatingAway = view;
2600990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2601990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2602990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    int getStateAfterAnimating() {
2603990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2604990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return 0;
2605990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2606990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mStateAfterAnimating;
2607990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2608990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2609990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    void setStateAfterAnimating(int state) {
2610990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        ensureAnimationInfo().mStateAfterAnimating = state;
2611990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2612990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2613990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    boolean isPostponed() {
2614990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        if (mAnimationInfo == null) {
2615990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount            return false;
2616990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        }
2617990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        return mAnimationInfo.mEnterTransitionPostponed;
2618990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2619990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2620667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount    boolean isHideReplaced() {
2621667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount        if (mAnimationInfo == null) {
2622667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount            return false;
2623667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount        }
2624667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount        return mAnimationInfo.mIsHideReplaced;
2625667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount    }
2626667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount
2627667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount    void setHideReplaced(boolean replaced) {
2628667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount        ensureAnimationInfo().mIsHideReplaced = replaced;
2629667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount    }
2630667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount
2631990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    /**
2632990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * Used internally to be notified when {@link #startPostponedEnterTransition()} has
2633990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * been called. This listener will only be called once and then be removed from the
2634990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * listeners.
2635990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     */
2636990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    interface OnStartEnterTransitionListener {
2637990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        void onStartEnterTransition();
2638990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        void startListening();
2639990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2640990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2641990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    /**
2642990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * Contains all the animation and transition information for a fragment. This will only
2643990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     * be instantiated for Fragments that have Views.
2644990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount     */
2645990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    static class AnimationInfo {
2646990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // Non-null if the fragment's view hierarchy is currently animating away,
2647990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // meaning we need to wait a bit on completely destroying it.  This is the
2648990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // view that is animating.
2649990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        View mAnimatingAway;
2650990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2651990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // If mAnimatingAway != null, this is the state we should move to once the
2652990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // animation is done.
2653990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        int mStateAfterAnimating;
2654990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2655990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // If app has requested a specific animation, this is the one to use.
2656990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        int mNextAnim;
2657990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2658990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // If app has requested a specific transition, this is the one to use.
2659990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        int mNextTransition;
2660990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2661990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // If app has requested a specific transition style, this is the one to use.
2662990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        int mNextTransitionStyle;
2663990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2664990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Object mEnterTransition = null;
2665990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Object mReturnTransition = USE_DEFAULT_TRANSITION;
2666990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Object mExitTransition = null;
2667990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Object mReenterTransition = USE_DEFAULT_TRANSITION;
2668990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Object mSharedElementEnterTransition = null;
2669990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Object mSharedElementReturnTransition = USE_DEFAULT_TRANSITION;
2670990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Boolean mAllowReturnTransitionOverlap;
2671990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        private Boolean mAllowEnterTransitionOverlap;
2672990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2673990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        SharedElementCallback mEnterTransitionCallback = null;
2674990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        SharedElementCallback mExitTransitionCallback = null;
2675990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2676990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // True when postponeEnterTransition has been called and startPostponeEnterTransition
2677990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // hasn't been called yet.
2678990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        boolean mEnterTransitionPostponed;
2679990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2680990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // Listener to wait for startPostponeEnterTransition. After being called, it will
2681990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        // be set to null
2682990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount        OnStartEnterTransitionListener mStartEnterTransitionListener;
2683990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount
2684667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount        // True if the View was hidden, but the transition is handling the hide
2685667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount        boolean mIsHideReplaced;
2686990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount    }
2687cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn}
2688