Fragment.java revision e0f27d39b0a4f0ef30ef6446e7b675279961cc94
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
19cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.app.Activity;
20cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.ComponentCallbacks;
21cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Context;
22cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Intent;
23cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Configuration;
24cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Resources;
25cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Bundle;
26cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcel;
27cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcelable;
28cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.support.v4.util.DebugUtils;
29cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.AttributeSet;
30be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackbornimport android.util.Log;
31cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.SparseArray;
32cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ContextMenu;
33cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.LayoutInflater;
34cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.Menu;
35cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuInflater;
36cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuItem;
37cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View;
38cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ViewGroup;
39cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ContextMenu.ContextMenuInfo;
40cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View.OnCreateContextMenuListener;
41cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.animation.Animation;
42cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.widget.AdapterView;
43cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
44cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.FileDescriptor;
45cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.PrintWriter;
46cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.util.HashMap;
47cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
48cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornfinal class FragmentState implements Parcelable {
49cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final String mClassName;
50cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final int mIndex;
51cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final boolean mFromLayout;
52cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final int mFragmentId;
53cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final int mContainerId;
54cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final String mTag;
55cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final boolean mRetainInstance;
56e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    final boolean mDetached;
57cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final Bundle mArguments;
58cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
59cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Bundle mSavedFragmentState;
60cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
61cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Fragment mInstance;
62cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
63cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public FragmentState(Fragment frag) {
64cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mClassName = frag.getClass().getName();
65cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mIndex = frag.mIndex;
66cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mFromLayout = frag.mFromLayout;
67cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mFragmentId = frag.mFragmentId;
68cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mContainerId = frag.mContainerId;
69cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mTag = frag.mTag;
70cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mRetainInstance = frag.mRetainInstance;
71e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        mDetached = frag.mDetached;
72cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mArguments = frag.mArguments;
73cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
74cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
75cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public FragmentState(Parcel in) {
76cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mClassName = in.readString();
77cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mIndex = in.readInt();
78cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mFromLayout = in.readInt() != 0;
79cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mFragmentId = in.readInt();
80cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mContainerId = in.readInt();
81cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mTag = in.readString();
82cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mRetainInstance = in.readInt() != 0;
83e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        mDetached = in.readInt() != 0;
84cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mArguments = in.readBundle();
85cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mSavedFragmentState = in.readBundle();
86cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
87cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    public Fragment instantiate(FragmentActivity activity, Fragment parent) {
89cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mInstance != null) {
90cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return mInstance;
91cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
92cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
93cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mArguments != null) {
94cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mArguments.setClassLoader(activity.getClassLoader());
95cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
96cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
97cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance = Fragment.instantiate(activity, mClassName, mArguments);
98cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
99cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mSavedFragmentState != null) {
100cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mSavedFragmentState.setClassLoader(activity.getClassLoader());
101cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mInstance.mSavedFragmentState = mSavedFragmentState;
102cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mInstance.setIndex(mIndex, parent);
104cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.mFromLayout = mFromLayout;
105cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.mRestored = true;
106cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.mFragmentId = mFragmentId;
107cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.mContainerId = mContainerId;
108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.mTag = mTag;
109cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.mRetainInstance = mRetainInstance;
110e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        mInstance.mDetached = mDetached;
111cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.mFragmentManager = activity.mFragments;
112be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn
113be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn        if (FragmentManagerImpl.DEBUG) Log.v(FragmentManagerImpl.TAG,
114be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn                "Instantiated fragment " + mInstance);
115be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn
116cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mInstance;
117cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
118cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
119cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public int describeContents() {
120cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return 0;
121cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
122cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
123cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void writeToParcel(Parcel dest, int flags) {
124cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeString(mClassName);
125cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mIndex);
126cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mFromLayout ? 1 : 0);
127cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mFragmentId);
128cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mContainerId);
129cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeString(mTag);
130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mRetainInstance ? 1 : 0);
131e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        dest.writeInt(mDetached ? 1 : 0);
132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeBundle(mArguments);
133cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeBundle(mSavedFragmentState);
134cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
135cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
136cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public static final Parcelable.Creator<FragmentState> CREATOR
137cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            = new Parcelable.Creator<FragmentState>() {
138cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public FragmentState createFromParcel(Parcel in) {
139cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return new FragmentState(in);
140cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
141cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
142cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public FragmentState[] newArray(int size) {
143cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return new FragmentState[size];
144cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
145cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    };
146cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn}
147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
148cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/**
149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Static library support version of the framework's {@link android.app.Fragment}.
150cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Used to write apps that run on platforms prior to Android 3.0.  When running
151cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on Android 3.0 or above, this implementation is still used; it does not try
1520574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * to switch to the framework's implementation. See the framework SDK
153cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * documentation for a class overview.
154cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */
155cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornpublic class Fragment implements ComponentCallbacks, OnCreateContextMenuListener {
156cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    private static final HashMap<String, Class<?>> sClassMap =
157cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            new HashMap<String, Class<?>>();
158cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
159cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final int INITIALIZING = 0;     // Not yet created.
160cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final int CREATED = 1;          // Created.
161cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final int ACTIVITY_CREATED = 2; // The activity has finished its creation.
162e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    static final int STOPPED = 3;          // Fully created, not started.
163e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    static final int STARTED = 4;          // Created and started, not resumed.
164e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    static final int RESUMED = 5;          // Created started and resumed.
165cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
166cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mState = INITIALIZING;
167cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
168cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Non-null if the fragment's view hierarchy is currently animating away,
169cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // meaning we need to wait a bit on completely destroying it.  This is the
170cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // view that is animating.
171cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    View mAnimatingAway;
172cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If mAnimatingAway != null, this is the state we should move to once the
174cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // animation is done.
175cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mStateAfterAnimating;
176cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
177cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // When instantiated from saved state, this is the saved state.
178cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Bundle mSavedFragmentState;
179cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    SparseArray<Parcelable> mSavedViewState;
180cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
181cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Index into active fragment array.
182cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mIndex = -1;
183cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
184cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Internal unique name for this fragment;
185cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    String mWho;
186cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Construction arguments;
188cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Bundle mArguments;
189cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
190cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Target fragment.
191cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Fragment mTarget;
192cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1932c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn    // For use when retaining a fragment: this is the index of the last mTarget.
1942c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn    int mTargetIndex = -1;
1952c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn
196cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Target request code.
197cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mTargetRequestCode;
198cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // True if the fragment is in the list of added fragments.
200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mAdded;
201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment is being removed from its activity.
203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRemoving;
204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // True if the fragment is in the resumed state.
206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mResumed;
207cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
208cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Set to true if this fragment was instantiated from a layout file.
209cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mFromLayout;
210cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Set to true when the view has actually been inflated in its layout.
212cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mInLayout;
213cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
214cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // True if this fragment has been restored from previously saved state.
215cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRestored;
216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
217cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Number of active back stack entries this fragment is in.
218cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mBackStackNesting;
219cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
220cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The fragment manager we are associated with.  Set as soon as the
221cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // fragment is used in a transaction; cleared after it has been removed
222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // from all transactions.
223abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    FragmentManagerImpl mFragmentManager;
224cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
225cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Activity this fragment is attached to.
226cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    FragmentActivity mActivity;
2270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
2280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    // Private fragment manager for child fragments inside of this one.
2290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    FragmentManagerImpl mChildFragmentManager;
2300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
2310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    // If this Fragment is contained in another Fragment, this is that container.
2320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    Fragment mParentFragment;
2330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
234cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The optional identifier for this fragment -- either the container ID if it
235cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // was dynamically added to the view hierarchy, or the ID supplied in
236cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // layout.
237cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mFragmentId;
238cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
239cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // When a fragment is being dynamically added to the view hierarchy, this
240cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // is the identifier of the parent container it is being added to.
241cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mContainerId;
242cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
243cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The optional named tag for this fragment -- usually used to find
244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // fragments that are not part of the layout.
245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    String mTag;
246cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Set to true when the app has requested that this fragment be hidden
248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // from the user.
249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mHidden;
250cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
251e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    // Set to true when the app has requested that this fragment be deactivated.
252e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    boolean mDetached;
253e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn
254cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment would like its instance retained across
255cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // configuration changes.
256cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRetainInstance;
257cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment is being retained across the current config change.
259cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRetaining;
260cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
261cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment has menu items to contribute.
262cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mHasMenu;
2632a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
2642a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    // Set to true to allow the fragment's menu to be shown.
2652a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    boolean mMenuVisible = true;
2662a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
267cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Used to verify that subclasses call through to super class.
268cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mCalled;
269cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
270cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If app has requested a specific animation, this is the one to use.
271cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mNextAnim;
272cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
273cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The parent container of the fragment after dynamically added to UI.
274cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ViewGroup mContainer;
275cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
276cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The View generated for this fragment.
277cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    View mView;
278cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
279cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The real inner view that will save/restore state.
280cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    View mInnerView;
281abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
282abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    // Whether this fragment should defer starting until after other fragments
283abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    // have been started and their loaders are finished.
284abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    boolean mDeferStart;
28579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell
28679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    // Hint provided by the app that this fragment is currently visible to the user.
28779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    boolean mUserVisibleHint = true;
288abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
289cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    LoaderManagerImpl mLoaderManager;
290cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mLoadersStarted;
291cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mCheckedForLoaderManager;
292cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
293cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
2945c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * State information that has been retrieved from a fragment instance
2955c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * through {@link FragmentManager#saveFragmentInstanceState(Fragment)
2965c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * FragmentManager.saveFragmentInstanceState}.
2975c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     */
2985c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    public static class SavedState implements Parcelable {
2995c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        final Bundle mState;
3005c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3015c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        SavedState(Bundle state) {
3025c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            mState = state;
3035c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
3045c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3055c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        SavedState(Parcel in, ClassLoader loader) {
3065c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            mState = in.readBundle();
3075c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            if (loader != null && mState != null) {
3085c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                mState.setClassLoader(loader);
3095c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            }
3105c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
3115c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3125c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        @Override
3135c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        public int describeContents() {
3145c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            return 0;
3155c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
3165c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3175c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        @Override
3185c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        public void writeToParcel(Parcel dest, int flags) {
3195c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            dest.writeBundle(mState);
3205c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
3215c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3225c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        public static final Parcelable.Creator<SavedState> CREATOR
3235c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                = new Parcelable.Creator<SavedState>() {
3245c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            public SavedState createFromParcel(Parcel in) {
3255c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                return new SavedState(in, null);
3265c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            }
3275c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3285c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            public SavedState[] newArray(int size) {
3295c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                return new SavedState[size];
3305c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            }
3315c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        };
3325c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    }
3335c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3345c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    /**
335cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when
336cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * there is an instantiation failure.
337cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
338cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static public class InstantiationException extends RuntimeException {
339cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public InstantiationException(String msg, Exception cause) {
340cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            super(msg, cause);
341cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
342cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
343cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
344cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
345cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Default constructor.  <strong>Every</strong> fragment must have an
346cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * empty constructor, so it can be instantiated when restoring its
347cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * activity's state.  It is strongly recommended that subclasses do not
348cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * have other constructors with parameters, since these constructors
349cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * will not be called when the fragment is re-instantiated; instead,
350cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * arguments can be supplied by the caller with {@link #setArguments}
351cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * and later retrieved by the Fragment with {@link #getArguments}.
352cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
353cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>Applications should generally not implement a constructor.  The
354cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * first place application code an run where the fragment is ready to
355cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * be used is in {@link #onAttach(Activity)}, the point where the fragment
356cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is actually associated with its activity.  Some applications may also
357cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * want to implement {@link #onInflate} to retrieve attributes from a
358cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * layout resource, though should take care here because this happens for
359cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the fragment is attached to its activity.
360cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
361cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public Fragment() {
362cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
363cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
364cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
365cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Like {@link #instantiate(Context, String, Bundle)} but with a null
366cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * argument Bundle.
367cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
368cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public static Fragment instantiate(Context context, String fname) {
369cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return instantiate(context, fname, null);
370cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
371cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
372cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
373cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Create a new instance of a Fragment with the given class name.  This is
374cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the same as calling its empty constructor.
375cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
376cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param context The calling context being used to instantiate the fragment.
377cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This is currently just used to get its ClassLoader.
378cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param fname The class name of the fragment to instantiate.
379cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param args Bundle of arguments to supply to the fragment, which it
380cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * can retrieve with {@link #getArguments()}.  May be null.
381cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return Returns a new fragment instance.
382cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @throws InstantiationException If there is a failure in instantiating
383cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the given fragment class.  This is a runtime exception; it is not
384cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * normally expected to happen.
385cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
386cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public static Fragment instantiate(Context context, String fname, Bundle args) {
387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        try {
388cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            Class<?> clazz = sClassMap.get(fname);
389cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (clazz == null) {
390cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                // Class not found in the cache, see if it's real, and try to add it
391cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                clazz = context.getClassLoader().loadClass(fname);
392cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                sClassMap.put(fname, clazz);
393cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
394cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            Fragment f = (Fragment)clazz.newInstance();
395cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (args != null) {
396cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                args.setClassLoader(f.getClass().getClassLoader());
397cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                f.mArguments = args;
398cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
399cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return f;
400cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } catch (ClassNotFoundException e) {
401cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new InstantiationException("Unable to instantiate fragment " + fname
402cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + ": make sure class name exists, is public, and has an"
403cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + " empty constructor that is public", e);
404cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } catch (java.lang.InstantiationException e) {
405cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new InstantiationException("Unable to instantiate fragment " + fname
406cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + ": make sure class name exists, is public, and has an"
407cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + " empty constructor that is public", e);
408cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } catch (IllegalAccessException e) {
409cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new InstantiationException("Unable to instantiate fragment " + fname
410cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + ": make sure class name exists, is public, and has an"
411cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + " empty constructor that is public", e);
412cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
413cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
414cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
4150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    final void restoreViewState(Bundle savedInstanceState) {
416cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mSavedViewState != null) {
417cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mInnerView.restoreHierarchyState(mSavedViewState);
418cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mSavedViewState = null;
419cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
4200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
4210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onViewStateRestored(savedInstanceState);
4220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
4230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
4240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onViewStateRestored()");
4250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
426cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
4270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
4280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    final void setIndex(int index, Fragment parent) {
429cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mIndex = index;
4300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (parent != null) {
4310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mWho = parent.mWho + ":" + mIndex;
4320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        } else {
4330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mWho = "android:fragment:" + mIndex;
4340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
435e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    }
4360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
437e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    final boolean isInBackStack() {
438e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        return mBackStackNesting > 0;
439e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    }
440e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn
441cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Subclasses can not override equals().
443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
444cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override final public boolean equals(Object o) {
445cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return super.equals(o);
446cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
447cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
448cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Subclasses can not override hashCode().
450cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
451cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override final public int hashCode() {
452cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return super.hashCode();
453cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
456cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public String toString() {
457cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        StringBuilder sb = new StringBuilder(128);
458cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        DebugUtils.buildShortClassTag(this, sb);
459cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mIndex >= 0) {
460cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(" #");
461cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(mIndex);
462cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
463cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mFragmentId != 0) {
464cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(" id=0x");
465cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(Integer.toHexString(mFragmentId));
466cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
467cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mTag != null) {
468cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(" ");
469cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(mTag);
470cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
471cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append('}');
472cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return sb.toString();
473cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
474cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
475cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
476cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the identifier this fragment is known by.  This is either
477cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the android:id value supplied in a layout or the container view ID
478cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * supplied when adding the fragment.
479cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
480cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public int getId() {
481cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mFragmentId;
482cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
483cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
484cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
485cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Get the tag name of the fragment, if specified.
486cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
487cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public String getTag() {
488cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mTag;
489cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
490cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
491cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
492cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Supply the construction arguments for this fragment.  This can only
493cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * be called before the fragment has been attached to its activity; that
494cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is, you should call it immediately after constructing the fragment.  The
495cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * arguments supplied here will be retained across fragment destroy and
496cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * creation.
497cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
498cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setArguments(Bundle args) {
499cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mIndex >= 0) {
500cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment already active");
501cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
502cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mArguments = args;
503cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
504cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
505cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
506cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the arguments supplied when the fragment was instantiated,
507cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * if any.
508cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
509cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public Bundle getArguments() {
510cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mArguments;
511cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
512cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
513cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
5145c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * Set the initial saved state that this Fragment should restore itself
5155c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * from when first being constructed, as returned by
5165c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * {@link FragmentManager#saveFragmentInstanceState(Fragment)
5175c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * FragmentManager.saveFragmentInstanceState}.
5185c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     *
5195c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * @param state The state the fragment should be restored from.
5205c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     */
5215c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    public void setInitialSavedState(SavedState state) {
5225c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        if (mIndex >= 0) {
5235c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            throw new IllegalStateException("Fragment already active");
5245c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
5255c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        mSavedFragmentState = state != null && state.mState != null
5265c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                ? state.mState : null;
5275c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    }
5285c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
5295c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    /**
530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Optional target for this fragment.  This may be used, for example,
531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * if this fragment is being started by another, and when done wants to
532cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * give a result back to the first.  The target set here is retained
533cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * across instances via {@link FragmentManager#putFragment
534cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * FragmentManager.putFragment()}.
535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param fragment The fragment that is the target of this one.
537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param requestCode Optional request code, for convenience if you
538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * are going to call back with {@link #onActivityResult(int, int, Intent)}.
539cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
540cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setTargetFragment(Fragment fragment, int requestCode) {
541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mTarget = fragment;
542cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mTargetRequestCode = requestCode;
543cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the target fragment set by {@link #setTargetFragment}.
547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public Fragment getTargetFragment() {
549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mTarget;
550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
551cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the target request code set by {@link #setTargetFragment}.
554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public int getTargetRequestCode() {
556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mTargetRequestCode;
557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
558cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the Activity this fragment is currently associated with.
561cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
562cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public FragmentActivity getActivity() {
563cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mActivity;
564cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
565cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
566cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
567cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return <code>getActivity().getResources()</code>.
568cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
569cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public Resources getResources() {
570cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActivity == null) {
571cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
572cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
573cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mActivity.getResources();
574cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
575cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
576cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
577cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return a localized, styled CharSequence from the application's package's
578cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default string table.
579cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
580cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resId Resource id for the CharSequence text
581cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
582cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public final CharSequence getText(int resId) {
583cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return getResources().getText(resId);
584cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
585cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
586cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
587cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return a localized string from the application's package's
588cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default string table.
589cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
590cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resId Resource id for the string
591cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
592cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public final String getString(int resId) {
593cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return getResources().getString(resId);
594cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
595cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
596cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
597cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return a localized formatted string from the application's package's
598cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default string table, substituting the format arguments as defined in
599cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link java.util.Formatter} and {@link java.lang.String#format}.
600cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
601cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resId Resource id for the format string
602cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param formatArgs The format arguments that will be used for substitution.
603cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
604cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
605cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public final String getString(int resId, Object... formatArgs) {
606cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return getResources().getString(resId, formatArgs);
607cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
608cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
609cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
610cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the FragmentManager for interacting with fragments associated
611cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * with this fragment's activity.  Note that this will be non-null slightly
612cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * before {@link #getActivity()}, during the time from when the fragment is
613cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * placed in a {@link FragmentTransaction} until it is committed and
614cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * attached to its activity.
6150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     *
6160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * <p>If this Fragment is a child of another Fragment, the FragmentManager
6170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * returned here will be the parent's {@link #getChildFragmentManager()}.
618cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
619cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public FragmentManager getFragmentManager() {
620cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mFragmentManager;
621cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
622cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
623cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
6240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * Return a private FragmentManager for placing and managing Fragments
6250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * inside of this Fragment.
6260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     */
6270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    final public FragmentManager getChildFragmentManager() {
6280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager == null) {
6290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            instantiateChildFragmentManager();
6300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mState >= RESUMED) {
6310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchResume();
6320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            } else if (mState >= STARTED) {
6330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchStart();
6340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            } else if (mState >= ACTIVITY_CREATED) {
6350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchActivityCreated();
6360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            } else if (mState >= CREATED) {
6370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchCreate();
6380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
6390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
6400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return mChildFragmentManager;
6410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
6420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
6430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    /**
6440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * Returns the parent Fragment containing this Fragment.  If this Fragment
6450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * is attached directly to an Activity, returns null.
6460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     */
6470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    final public Fragment getParentFragment() {
6480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return mParentFragment;
6490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
6500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
6510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    /**
652cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment is currently added to its activity.
653cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
654cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isAdded() {
655cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mActivity != null && mAdded;
656cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
657cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
658cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
6599c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * Return true if the fragment has been explicitly detached from the UI.
6609c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * That is, {@link FragmentTransaction#detach(Fragment)
6619c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * FragmentTransaction.detach(Fragment)} has been used on it.
6629c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     */
6639c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    final public boolean isDetached() {
6649c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        return mDetached;
6659c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
6669c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
6679c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    /**
668cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if this fragment is currently being removed from its
669cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * activity.  This is  <em>not</em> whether its activity is finishing, but
670cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * rather whether it is in the process of being removed from its activity.
671cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
672cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isRemoving() {
673cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mRemoving;
674cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
675cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
676cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
677cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the layout is included as part of an activity view
678cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * hierarchy via the &lt;fragment&gt; tag.  This will always be true when
679cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * fragments are created through the &lt;fragment&gt; tag, <em>except</em>
680cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * in the case where an old fragment is restored from a previous state and
681cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * it does not appear in the layout of the current state.
682cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
683cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isInLayout() {
684cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mInLayout;
685cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
686cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
687cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
688cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment is in the resumed state.  This is true
689cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for the duration of {@link #onResume()} and {@link #onPause()} as well.
690cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
691cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isResumed() {
692cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mResumed;
693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
694cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
695cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
696cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment is currently visible to the user.  This means
697cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * it: (1) has been added, (2) has its view attached to the window, and
698cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * (3) is not hidden.
699cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
700cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isVisible() {
701cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return isAdded() && !isHidden() && mView != null
702cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE;
703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
704cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment has been hidden.  By default fragments
707cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * are shown.  You can find out about changes to this state with
708cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onHiddenChanged}.  Note that the hidden state is orthogonal
709cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to other states -- that is, to be visible to the user, a fragment
710cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * must be both started and not hidden.
711cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
712cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isHidden() {
713cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mHidden;
714cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
715cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
716cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
717cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the hidden state (as returned by {@link #isHidden()} of
718cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the fragment has changed.  Fragments start out not hidden; this will
719cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * be called whenever the fragment changes state from that.
720cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param hidden True if the fragment is now hidden, false if it is not
721cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * visible.
722cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onHiddenChanged(boolean hidden) {
724cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
725cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
726cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
727cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Control whether a fragment instance is retained across Activity
728cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * re-creation (such as from a configuration change).  This can only
729cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * be used with fragments not in the back stack.  If set, the fragment
730cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * lifecycle will be slightly different when an activity is recreated:
731cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <ul>
732cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still
733cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * will be, because the fragment is being detached from its current activity).
734cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <li> {@link #onCreate(Bundle)} will not be called since the fragment
735cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is not being re-created.
736cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b>
737cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * still be called.
738cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * </ul>
739cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
740cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setRetainInstance(boolean retain) {
7410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (retain && mParentFragment != null) {
7420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new IllegalStateException(
7430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    "Can't retain fragements that are nested in other fragments");
7440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
745cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mRetainInstance = retain;
746cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
747cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
748cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean getRetainInstance() {
749cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mRetainInstance;
750cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
751cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
752cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
753cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Report that this fragment would like to participate in populating
754cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the options menu by receiving a call to {@link #onCreateOptionsMenu}
755cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * and related methods.
756cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
757cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param hasMenu If true, the fragment has menu items to contribute.
758cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
759cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setHasOptionsMenu(boolean hasMenu) {
760cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mHasMenu != hasMenu) {
761cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mHasMenu = hasMenu;
762cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (isAdded() && !isHidden()) {
763681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn                mActivity.supportInvalidateOptionsMenu();
764cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
765cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
766cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
7672a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
7682a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    /**
7692a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * Set a hint for whether this fragment's menu should be visible.  This
7702a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * is useful if you know that a fragment has been placed in your view
7712a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * hierarchy so that the user can not currently seen it, so any menu items
7722a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * it has should also not be shown.
7732a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     *
7742a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * @param menuVisible The default is true, meaning the fragment's menu will
7752a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * be shown as usual.  If false, the user will not see the menu.
7762a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     */
7772a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    public void setMenuVisibility(boolean menuVisible) {
7782a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        if (mMenuVisible != menuVisible) {
7792a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            mMenuVisible = menuVisible;
7802a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            if (mHasMenu && isAdded() && !isHidden()) {
7812a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn                mActivity.supportInvalidateOptionsMenu();
7822a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            }
7832a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        }
7842a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    }
7852a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
786cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
78779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * Set a hint to the system about whether this fragment's UI is currently visible
78879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * to the user. This hint defaults to true and is persistent across fragment instance
78979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * state save and restore.
790abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     *
79179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * <p>An app may set this to false to indicate that the fragment's UI is
79279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * scrolled out of visibility or is otherwise not directly visible to the user.
79379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * This may be used by the system to prioritize operations such as fragment lifecycle updates
79479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * or loader ordering behavior.</p>
795abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     *
79679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * @param isVisibleToUser true if this fragment's UI is currently visible to the user (default),
79779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     *                        false if it is not.
798abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     */
79979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    public void setUserVisibleHint(boolean isVisibleToUser) {
80079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        if (!mUserVisibleHint && isVisibleToUser && mState < STARTED) {
801abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell            mFragmentManager.performPendingDeferredStart(this);
802abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell        }
80379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        mUserVisibleHint = isVisibleToUser;
80479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        mDeferStart = !isVisibleToUser;
805abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    }
806abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
807abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    /**
80879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * @return The current value of the user-visible hint on this fragment.
80979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * @see #setUserVisibleHint(boolean)
810abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     */
81179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    public boolean getUserVisibleHint() {
81279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        return mUserVisibleHint;
813abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    }
814abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
815abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    /**
816cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the LoaderManager for this fragment, creating it if needed.
817cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
818cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public LoaderManager getLoaderManager() {
819cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mLoaderManager != null) {
820cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return mLoaderManager;
821cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
822cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActivity == null) {
823cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
824cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
825cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCheckedForLoaderManager = true;
8260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mLoaderManager = mActivity.getLoaderManager(mWho, mLoadersStarted, true);
827cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mLoaderManager;
828cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
829cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
830cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
831cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Call {@link Activity#startActivity(Intent)} on the fragment's
832cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * containing Activity.
833cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
834cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void startActivity(Intent intent) {
835cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActivity == null) {
836cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
837cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
838cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mActivity.startActivityFromFragment(this, intent, -1);
839cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
840cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
841cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
842cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Call {@link Activity#startActivityForResult(Intent, int)} on the fragment's
843cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * containing Activity.
844cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
845cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void startActivityForResult(Intent intent, int requestCode) {
846cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActivity == null) {
847cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
848cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
849cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mActivity.startActivityFromFragment(this, intent, requestCode);
850cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
851cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
852cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
853cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Receive the result from a previous call to
854cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #startActivityForResult(Intent, int)}.  This follows the
855cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * related Activity API as described there in
856cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onActivityResult(int, int, Intent)}.
857cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
858cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param requestCode The integer request code originally supplied to
859cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *                    startActivityForResult(), allowing you to identify who this
860cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *                    result came from.
861cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resultCode The integer result code returned by the child activity
862cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *                   through its setResult().
863cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param data An Intent, which can return result data to the caller
864cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *               (various data can be attached to Intent "extras").
865cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
866cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onActivityResult(int requestCode, int resultCode, Intent data) {
867cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
868cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
869cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
870cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @hide Hack so that DialogFragment can make its Dialog before creating
871cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * its views, and the view construction can use the dialog's context for
872cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * inflation.  Maybe this should become a public API. Note sure.
873cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
874cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public LayoutInflater getLayoutInflater(Bundle savedInstanceState) {
875cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mActivity.getLayoutInflater();
876cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
877cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
878cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
879cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a fragment is being created as part of a view layout
880cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * inflation, typically from setting the content view of an activity.  This
8819277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * may be called immediately after the fragment is created from a <fragment>
882cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tag in a layout file.  Note this is <em>before</em> the fragment's
883cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onAttach(Activity)} has been called; all you should do here is
8849277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * parse the attributes and save them away.
885cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
886cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>This is called every time the fragment is inflated, even if it is
8879277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * being inflated into a new instance with saved state.  It typically makes
8889277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * sense to re-parse the parameters each time, to allow them to change with
8899277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * different configurations.</p>
8909277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
8919277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>Here is a typical implementation of a fragment that can take parameters
8929277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * both through attributes supplied here as well from {@link #getArguments()}:</p>
8939277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
8949277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
8959277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *      fragment}
8969277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
8979277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>Note that parsing the XML attributes uses a "styleable" resource.  The
8989277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * declaration for the styleable used here is:</p>
8999277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
9009277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * {@sample development/samples/ApiDemos/res/values/attrs.xml fragment_arguments}
901cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
9029277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>The fragment can then be declared within its activity's content layout
9039277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * through a tag like this:</p>
9049277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
9059277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * {@sample development/samples/ApiDemos/res/layout/fragment_arguments.xml from_attributes}
9069277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
9079277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>This fragment can also be created dynamically from arguments given
9089277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * at runtime in the arguments Bundle; here is an example of doing so at
9099277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * creation of the containing activity:</p>
9109277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
9119277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
9129277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *      create}
9139277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
9149277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * @param activity The Activity that is inflating this fragment.
915cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param attrs The attributes at the tag where the fragment is
916cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * being created.
917cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
918cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * a previous saved state, this is the state.
919cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
9209277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
921cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
922cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
923cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
924cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
925cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a fragment is first attached to its activity.
926cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreate(Bundle)} will be called after this.
927cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
928cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onAttach(Activity activity) {
929cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
930cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
931cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
932cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
933cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a fragment loads an animation.
934cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
9359277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
936cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return null;
937cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
938cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
939cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
940cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called to do initial creation of a fragment.  This is called after
941cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onAttach(Activity)} and before
942cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
943cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
944cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>Note that this can be called while the fragment's activity is
945cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * still in the process of being created.  As such, you can not rely
946cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * on things like the activity's content view hierarchy being initialized
947cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * at this point.  If you want to do work once the activity itself is
948cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * created, see {@link #onActivityCreated(Bundle)}.
949cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
950cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
951cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * a previous saved state, this is the state.
952cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
953cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onCreate(Bundle savedInstanceState) {
954cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
955cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
9560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
957cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
958cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called to have the fragment instantiate its user interface view.
959cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This is optional, and non-graphical fragments can return null (which
960cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is the default implementation).  This will be called between
961cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}.
962cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
963cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>If you return a View from here, you will later be called in
964cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onDestroyView} when the view is being released.
965cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
966cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param inflater The LayoutInflater object that can be used to inflate
967cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * any views in the fragment,
968cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param container If non-null, this is the parent view that the fragment's
969cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * UI should be attached to.  The fragment should not add the view itself,
970cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * but this can be used to generate the LayoutParams of the view.
971cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If non-null, this fragment is being re-constructed
972cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * from a previous saved state as given here.
973cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
974cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return Return the View for the fragment's UI, or null.
975cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
976cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public View onCreateView(LayoutInflater inflater, ViewGroup container,
977cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            Bundle savedInstanceState) {
978cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return null;
979cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
9800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
981cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
982e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
983e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * has returned, but before any saved state has been restored in to the view.
984e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * This gives subclasses a chance to initialize themselves once
985e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * they know their view hierarchy has been completely created.  The fragment's
986e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * view hierarchy is not however attached to its parent at this point.
987e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
988e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * @param savedInstanceState If non-null, this fragment is being re-constructed
989e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * from a previous saved state as given here.
990e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     */
991e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    public void onViewCreated(View view, Bundle savedInstanceState) {
992e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    }
993e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn
994e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    /**
995cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}),
996cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * if provided.
997cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
998cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return The fragment's root view, or null if it has no layout.
999cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1000cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public View getView() {
1001cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mView;
1002cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1003cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1004cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1005cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment's activity has been created and this
1006cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * fragment's view hierarchy instantiated.  It can be used to do final
1007cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * initialization once these pieces are in place, such as retrieving
1008cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * views or restoring state.  It is also useful for fragments that use
1009cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #setRetainInstance(boolean)} to retain their instance,
1010cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * as this callback tells the fragment when it is fully associated with
1011cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the new activity instance.  This is called after {@link #onCreateView}
10120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * and before {@link #onViewStateRestored(Bundle)}.
10130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     *
1014cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
1015cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * a previous saved state, this is the state.
1016cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1017cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onActivityCreated(Bundle savedInstanceState) {
1018cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1019cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
10200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
10210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    /**
10220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * Called when all saved state has been restored into the view hierarchy
10230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * of the fragment.  This can be used to do initialization based on saved
10240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * state that you are letting the view hierarchy track itself, such as
10250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * whether check box widgets are currently checked.  This is called
10260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * after {@link #onActivityCreated(Bundle)} and before
10270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * {@link #onStart()}.
10280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     *
10290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
10300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     * a previous saved state, this is the state.
10310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn     */
10320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    public void onViewStateRestored(Bundle savedInstanceState) {
10330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = true;
10340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
10350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
1036cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1037cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the Fragment is visible to the user.  This is generally
1038cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onStart() Activity.onStart} of the containing
1039cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
1040cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1041cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onStart() {
1042cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1043cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1044cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (!mLoadersStarted) {
1045cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mLoadersStarted = true;
1046cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (!mCheckedForLoaderManager) {
1047cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mCheckedForLoaderManager = true;
10480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mLoaderManager = mActivity.getLoaderManager(mWho, mLoadersStarted, false);
1049cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1050cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (mLoaderManager != null) {
1051cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mLoaderManager.doStart();
1052cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1053cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1054cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1055cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1056cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1057cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment is visible to the user and actively running.
1058cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This is generally
1059cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onResume() Activity.onResume} of the containing
1060cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
1061cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1062cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onResume() {
1063cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1064cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1065cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1066cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1067cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called to ask the fragment to save its current dynamic state, so it
1068cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * can later be reconstructed in a new instance of its process is
1069cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * restarted.  If a new instance of the fragment later needs to be
1070cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * created, the data you place in the Bundle here will be available
1071cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * in the Bundle given to {@link #onCreate(Bundle)},
1072cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}, and
1073cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onActivityCreated(Bundle)}.
1074cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1075cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>This corresponds to {@link Activity#onSaveInstanceState(Bundle)
1076cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity.onSaveInstanceState(Bundle)} and most of the discussion there
1077cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * applies here as well.  Note however: <em>this method may be called
1078cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * at any time before {@link #onDestroy()}</em>.  There are many situations
1079cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * where a fragment may be mostly torn down (such as when placed on the
1080cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * back stack with no UI showing), but its state will not be saved until
1081cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * its owning activity actually needs to save its state.
1082cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1083cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param outState Bundle in which to place your saved state.
1084cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1085cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onSaveInstanceState(Bundle outState) {
1086cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1087cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1088cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onConfigurationChanged(Configuration newConfig) {
1089cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1090cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1091cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1092cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1093cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the Fragment is no longer resumed.  This is generally
1094cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onPause() Activity.onPause} of the containing
1095cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
1096cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1097cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onPause() {
1098cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1099cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1100cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1101cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1102cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the Fragment is no longer started.  This is generally
1103cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onStop() Activity.onStop} of the containing
1104cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
1105cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1106cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onStop() {
1107cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1109cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1110cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onLowMemory() {
1111cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1112cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1114cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1115cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the view previously created by {@link #onCreateView} has
1116cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * been detached from the fragment.  The next time the fragment needs
1117cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to be displayed, a new view will be created.  This is called
1118cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * after {@link #onStop()} and before {@link #onDestroy()}.  It is called
1119cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <em>regardless</em> of whether {@link #onCreateView} returned a
1120cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * non-null view.  Internally it is called after the view's state has
1121cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * been saved but before it has been removed from its parent.
1122cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1123cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDestroyView() {
1124cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1125cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1126cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1127cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1128cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment is no longer in use.  This is called
1129cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * after {@link #onStop()} and before {@link #onDetach()}.
1130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1131cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDestroy() {
1132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1133cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        //Log.v("foo", "onDestroy: mCheckedForLoaderManager=" + mCheckedForLoaderManager
1134cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        //        + " mLoaderManager=" + mLoaderManager);
1135cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (!mCheckedForLoaderManager) {
1136cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mCheckedForLoaderManager = true;
11370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mLoaderManager = mActivity.getLoaderManager(mWho, mLoadersStarted, false);
1138cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1139cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mLoaderManager != null) {
1140cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mLoaderManager.doDestroy();
1141cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1142cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1143cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1144cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
11459c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * Called by the fragment manager once this fragment has been removed,
11469c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * so that we don't have any left-over state if the application decides
11479c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * to re-use the instance.  This only clears state that the framework
11489c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * internally manages, not things the application sets.
11499c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     */
11509c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    void initState() {
11519c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mIndex = -1;
11529c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mWho = null;
11539c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mAdded = false;
11549c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mRemoving = false;
11559c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mResumed = false;
11569c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mFromLayout = false;
11579c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mInLayout = false;
11589c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mRestored = false;
11599c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mBackStackNesting = 0;
11609c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mFragmentManager = null;
11612a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        mActivity = null;
11629c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mFragmentId = 0;
11639c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mContainerId = 0;
11649c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mTag = null;
11659c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mHidden = false;
11669c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mDetached = false;
11679c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mRetaining = false;
11689c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mLoaderManager = null;
11699c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mLoadersStarted = false;
11709c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mCheckedForLoaderManager = false;
11719c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
11729c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
11739c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    /**
1174cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment is no longer attached to its activity.  This
1175cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is called after {@link #onDestroy()}.
1176cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1177cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDetach() {
1178cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1179cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1180cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1181cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1182cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Initialize the contents of the Activity's standard options menu.  You
1183cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * should place your menu items in to <var>menu</var>.  For this method
1184cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to be called, you must have first called {@link #setHasOptionsMenu}.  See
1185cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu}
1186cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for more information.
1187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1188cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param menu The options menu in which you place your items.
1189cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1190cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #setHasOptionsMenu
1191cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onPrepareOptionsMenu
1192cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onOptionsItemSelected
1193cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1194cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
1195cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1196cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1197cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1198cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Prepare the Screen's standard options menu to be displayed.  This is
1199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * called right before the menu is shown, every time it is shown.  You can
1200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * use this method to efficiently enable/disable items or otherwise
1201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * dynamically modify the contents.  See
1202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu}
1203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for more information.
1204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param menu The options menu as last shown or first initialized by
1206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *             onCreateOptionsMenu().
1207cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1208cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #setHasOptionsMenu
1209cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onCreateOptionsMenu
1210cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onPrepareOptionsMenu(Menu menu) {
1212cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1213cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1214cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1215cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when this fragment's option menu items are no longer being
1216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * included in the overall options menu.  Receiving this call means that
1217cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the menu needed to be rebuilt, but this fragment's items were not
1218cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * included in the newly built menu (its {@link #onCreateOptionsMenu(Menu, MenuInflater)}
1219cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * was not called).
1220cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1221cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDestroyOptionsMenu() {
1222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1223cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1224cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1225cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This hook is called whenever an item in your options menu is selected.
1226cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * The default implementation simply returns false to have the normal
1227cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * processing happen (calling the item's Runnable or sending a message to
1228cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * its Handler as appropriate).  You can use this method for any items
1229cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for which you would like to do processing without those other
1230cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * facilities.
1231cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1232cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>Derived classes should call through to the base class for it to
1233cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * perform the default menu handling.
1234cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1235cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param item The menu item that was selected.
1236cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1237cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return boolean Return false to allow normal menu processing to
1238cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *         proceed, true to consume it here.
1239cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1240cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onCreateOptionsMenu
1241cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1242cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean onOptionsItemSelected(MenuItem item) {
1243cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return false;
1244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1246cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This hook is called whenever the options menu is being closed (either by the user canceling
1248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the menu with the back/menu button, or when an item is selected).
1249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1250cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param menu The options menu as last shown or first initialized by
1251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *             onCreateOptionsMenu().
1252cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1253cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onOptionsMenuClosed(Menu menu) {
1254cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1255cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1256cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1257cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a context menu for the {@code view} is about to be shown.
1258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Unlike {@link #onCreateOptionsMenu}, this will be called every
1259cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * time the context menu is about to be shown and should be populated for
1260cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the view (or item inside the view for {@link AdapterView} subclasses,
1261cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * this can be found in the {@code menuInfo})).
1262cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1263cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an
1264cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * item has been selected.
1265cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1266cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * The default implementation calls up to
1267cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though
1268cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * you can not call this implementation if you don't want that behavior.
1269cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1270cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * It is not safe to hold onto the context menu after this method returns.
1271cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@inheritDoc}
1272cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1273cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
1274cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        getActivity().onCreateContextMenu(menu, v, menuInfo);
1275cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1276cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1277cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1278cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Registers a context menu to be shown for the given view (multiple views
1279cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * can show the context menu). This method will set the
1280cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link OnCreateContextMenuListener} on the view to this fragment, so
1281cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be
1282cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * called when it is time to show the context menu.
1283cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1284cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #unregisterForContextMenu(View)
1285cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param view The view that should show a context menu.
1286cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1287cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void registerForContextMenu(View view) {
1288cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        view.setOnCreateContextMenuListener(this);
1289cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1290cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1291cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1292cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Prevents a context menu to be shown for the given view. This method will
1293cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * remove the {@link OnCreateContextMenuListener} on the view.
1294cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1295cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #registerForContextMenu(View)
1296cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param view The view that should stop showing a context menu.
1297cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1298cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void unregisterForContextMenu(View view) {
1299cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        view.setOnCreateContextMenuListener(null);
1300cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1301cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1302cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1303cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This hook is called whenever an item in a context menu is selected. The
1304cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default implementation simply returns false to have the normal processing
1305cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * happen (calling the item's Runnable or sending a message to its Handler
1306cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * as appropriate). You can use this method for any items for which you
1307cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * would like to do processing without those other facilities.
1308cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1309cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Use {@link MenuItem#getMenuInfo()} to get extra information set by the
1310cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * View that added this menu item.
1311cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1312cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Derived classes should call through to the base class for it to perform
1313cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the default menu handling.
1314cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1315cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param item The context menu item that was selected.
1316cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return boolean Return false to allow normal context menu processing to
1317cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *         proceed, true to consume it here.
1318cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1319cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean onContextItemSelected(MenuItem item) {
1320cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return false;
1321cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1322e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes
1323e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    // SUPPORT MENU
1324e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes
1325e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    /**
1326e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * Initialize the contents of the Activity's standard options menu.  You
1327e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * should place your menu items in to <var>menu</var>.  For this method
1328e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * to be called, you must have first called {@link #setHasOptionsMenu}.  See
1329e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * {@link android.app.Activity#onCreateOptionsMenu(android.view.Menu) Activity.onCreateOptionsMenu}
1330e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * for more information.
1331e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     *
1332e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * @param menu The options menu in which you place your items.
1333e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     *
1334e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * @see #setHasOptionsMenu
1335e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * @see #onPrepareSupportOptionsMenu
1336e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * @see #onSupportOptionsItemSelected
1337e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     */
1338e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    public void onCreateSupportOptionsMenu(android.support.v4.view.Menu menu,
1339e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes            android.support.v4.view.MenuInflater inflater) {
1340e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    }
1341e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes
1342e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    /**
1343e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * Prepare the Screen's standard options menu to be displayed.  This is
1344e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * called right before the menu is shown, every time it is shown.  You can
1345e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * use this method to efficiently enable/disable items or otherwise
1346e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * dynamically modify the contents.  See
1347e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * {@link android.app.Activity#onPrepareOptionsMenu(android.view.Menu) Activity.onPrepareOptionsMenu}
1348e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * for more information.
1349e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     *
1350e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * @param menu The options menu as last shown or first initialized by
1351e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     *             onCreateSupportOptionsMenu().
1352e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     *
1353e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * @see #setHasOptionsMenu
1354e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * @see #onCreateSupportOptionsMenu
1355e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     */
1356e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    public void onPrepareSupportOptionsMenu(android.support.v4.view.Menu menu) {
1357e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    }
1358e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes
1359e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    /**
1360e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * This hook is called whenever an item in your options menu is selected.
1361e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * The default implementation simply returns false to have the normal
1362e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * processing happen (calling the item's Runnable or sending a message to
1363e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * its Handler as appropriate).  You can use this method for any items
1364e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * for which you would like to do processing without those other
1365e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * facilities.
1366e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     *
1367e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * <p>Derived classes should call through to the base class for it to
1368e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * perform the default menu handling.
1369e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     *
1370e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * @param item The menu item that was selected.
1371e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     *
1372e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * @return boolean Return false to allow normal menu processing to
1373e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     *         proceed, true to consume it here.
1374e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     *
1375e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     * @see #onCreateSupportOptionsMenu
1376e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes     */
1377e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    public boolean onSupportOptionsItemSelected(android.support.v4.view.MenuItem item) {
1378e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        return false;
1379e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    }
1380e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes
1381e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    // END SUPPORT MENU
1382cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1383cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1384cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Print the Fragments's state into the given stream.
1385cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1386cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param prefix Text to print at the front of each line.
1387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param fd The raw file descriptor that the dump is being sent to.
1388cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param writer The PrintWriter to which you should dump your state.  This will be
1389cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * closed for you after you return.
1390cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param args additional arguments to the dump request.
1391cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1392cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
1393cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mFragmentId=#");
1394cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(Integer.toHexString(mFragmentId));
13955506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                writer.print(" mContainerId=#");
1396cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(Integer.toHexString(mContainerId));
1397cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mTag="); writer.println(mTag);
1398cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mState="); writer.print(mState);
1399cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mIndex="); writer.print(mIndex);
1400cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mWho="); writer.print(mWho);
1401cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mBackStackNesting="); writer.println(mBackStackNesting);
1402cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mAdded="); writer.print(mAdded);
1403cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mRemoving="); writer.print(mRemoving);
1404cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mResumed="); writer.print(mResumed);
1405cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mFromLayout="); writer.print(mFromLayout);
1406cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mInLayout="); writer.println(mInLayout);
1407cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mHidden="); writer.print(mHidden);
1408e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                writer.print(" mDetached="); writer.print(mDetached);
14092a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn                writer.print(" mMenuVisible="); writer.print(mMenuVisible);
1410cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mHasMenu="); writer.println(mHasMenu);
14112a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        writer.print(prefix); writer.print("mRetainInstance="); writer.print(mRetainInstance);
141279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                writer.print(" mRetaining="); writer.print(mRetaining);
141379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                writer.print(" mUserVisibleHint="); writer.println(mUserVisibleHint);
1414cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mFragmentManager != null) {
1415cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mFragmentManager=");
1416cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mFragmentManager);
1417cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1418cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActivity != null) {
1419cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mActivity=");
1420cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mActivity);
1421cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
14220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mParentFragment != null) {
14230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            writer.print(prefix); writer.print("mParentFragment=");
14240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    writer.println(mParentFragment);
14250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
1426cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mArguments != null) {
1427cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mArguments="); writer.println(mArguments);
1428cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1429cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mSavedFragmentState != null) {
1430cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mSavedFragmentState=");
1431cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mSavedFragmentState);
1432cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1433cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mSavedViewState != null) {
1434cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mSavedViewState=");
1435cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mSavedViewState);
1436cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1437cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mTarget != null) {
1438cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mTarget="); writer.print(mTarget);
1439cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.print(" mTargetRequestCode=");
1440cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mTargetRequestCode);
1441cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mNextAnim != 0) {
1443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mNextAnim="); writer.println(mNextAnim);
1444cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1445cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mContainer != null) {
1446cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mContainer="); writer.println(mContainer);
1447cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1448cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mView != null) {
1449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mView="); writer.println(mView);
1450cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1451cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mInnerView != null) {
1452cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mInnerView="); writer.println(mView);
1453cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mAnimatingAway != null) {
1455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mAnimatingAway="); writer.println(mAnimatingAway);
1456cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mStateAfterAnimating=");
1457cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mStateAfterAnimating);
1458cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1459cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mLoaderManager != null) {
1460cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.println("Loader Manager:");
1461cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mLoaderManager.dump(prefix + "  ", fd, writer, args);
1462cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
14630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
14640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            writer.print(prefix); writer.println("Child " + mChildFragmentManager + ":");
14650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dump(prefix + "  ", fd, writer, args);
14660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
14670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
14680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
14690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    Fragment findFragmentByWho(String who) {
14700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (who.equals(mWho)) {
14710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            return this;
14720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
14730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
14740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            return mChildFragmentManager.findFragmentByWho(who);
14750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
14760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return null;
14770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
14780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
14790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void instantiateChildFragmentManager() {
1480e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        mChildFragmentManager = new FragmentManagerImpl();
14810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mChildFragmentManager.attachActivity(mActivity, new FragmentContainer() {
14820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            @Override
14830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            public View findViewById(int id) {
14840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (mView == null) {
14850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    throw new IllegalStateException("Fragment does not have a view");
14860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                }
14870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                return mView.findViewById(id);
14880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
14890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }, this);
14900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
14910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
14920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performCreate(Bundle savedInstanceState) {
14930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
14940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
14950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
14960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
14970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onCreate(savedInstanceState);
14980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
14990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
15000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onCreate()");
15010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
15020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (savedInstanceState != null) {
15030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            Parcelable p = savedInstanceState.getParcelable(
15040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    FragmentActivity.FRAGMENTS_TAG);
15050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (p != null) {
15060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (mChildFragmentManager == null) {
15070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    instantiateChildFragmentManager();
15080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                }
15090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.restoreAllState(p, null);
15100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchCreate();
15110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
15120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
15130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
15140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
15150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    View performCreateView(LayoutInflater inflater, ViewGroup container,
15160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            Bundle savedInstanceState) {
15170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
15180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
15190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
15200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return onCreateView(inflater, container, savedInstanceState);
15210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
15220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
15230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performActivityCreated(Bundle savedInstanceState) {
15240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
15250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
15260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
15270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
15280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onActivityCreated(savedInstanceState);
15290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
15300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
15310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onActivityCreated()");
15320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
15330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
15340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchActivityCreated();
15350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
1536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
15389c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    void performStart() {
15390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
15400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
15410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.execPendingActions();
15420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
15430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
15449c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        onStart();
15450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
15460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
15470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onStart()");
15480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
15490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
15500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchStart();
15510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
15529c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        if (mLoaderManager != null) {
15539c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn            mLoaderManager.doReportStart();
15549c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        }
15559c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
15569c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
15570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performResume() {
15580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
15590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.noteStateNotSaved();
15600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.execPendingActions();
15610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
15620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
15630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onResume();
15640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
15650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
15660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onResume()");
15670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
15680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
15690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchResume();
15700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.execPendingActions();
15710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
15720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
15730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
15740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performConfigurationChanged(Configuration newConfig) {
15750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onConfigurationChanged(newConfig);
15760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
15770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchConfigurationChanged(newConfig);
15780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
15790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
15800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
15810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performLowMemory() {
15820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onLowMemory();
15830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
15840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchLowMemory();
15850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
15860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
15870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
15880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    /*
15890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performTrimMemory(int level) {
15900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onTrimMemory(level);
15910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
15920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchTrimMemory(level);
15930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
15940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
15950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    */
15960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
15970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    boolean performCreateOptionsMenu(Menu menu, MenuInflater inflater) {
15980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        boolean show = false;
15990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
16000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mHasMenu && mMenuVisible) {
16010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                show = true;
16020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                onCreateOptionsMenu(menu, inflater);
16030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
16040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
16050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                show |= mChildFragmentManager.dispatchCreateOptionsMenu(menu, inflater);
16060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
16070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
16080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return show;
16090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
16100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
16110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    boolean performPrepareOptionsMenu(Menu menu) {
16120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        boolean show = false;
16130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
16140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mHasMenu && mMenuVisible) {
16150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                show = true;
16160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                onPrepareOptionsMenu(menu);
16170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
16180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
16190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                show |= mChildFragmentManager.dispatchPrepareOptionsMenu(menu);
16200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
16210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
16220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return show;
16230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
16240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
16250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    boolean performOptionsItemSelected(MenuItem item) {
16260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
16270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mHasMenu && mMenuVisible) {
16280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (onOptionsItemSelected(item)) {
16290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    return true;
16300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                }
16310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
16320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
16330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (mChildFragmentManager.dispatchOptionsItemSelected(item)) {
16340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    return true;
16350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                }
16360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
16370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
16380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return false;
16390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
16400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
16410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    boolean performContextItemSelected(MenuItem item) {
16420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
16430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (onContextItemSelected(item)) {
16440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                return true;
16450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
16460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
16470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (mChildFragmentManager.dispatchContextItemSelected(item)) {
16480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    return true;
16490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                }
16500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
16510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
16520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        return false;
16530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
16540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
16550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performOptionsMenuClosed(Menu menu) {
16560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mHidden) {
16570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mHasMenu && mMenuVisible) {
16580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                onOptionsMenuClosed(menu);
16590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
16600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (mChildFragmentManager != null) {
16610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mChildFragmentManager.dispatchOptionsMenuClosed(menu);
16620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
16630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
16640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
16650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
1666e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    boolean performCreateSupportOptionsMenu(android.support.v4.view.Menu menu,
1667e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes            android.support.v4.view.MenuInflater inflater) {
1668e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        boolean show = false;
1669e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        if (!mHidden) {
1670e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes            if (mHasMenu && mMenuVisible) {
1671e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes                show = true;
1672e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes                onCreateSupportOptionsMenu(menu, inflater);
1673e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes            }
1674e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes
1675e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes            if (mChildFragmentManager != null) {
1676e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes                show |= mChildFragmentManager.dispatchCreateSupportOptionsMenu(menu, inflater);
1677e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes            }
1678e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        }
1679e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        return show;
1680e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    }
1681e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes
1682e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    boolean performPrepareSupportOptionsMenu(android.support.v4.view.Menu menu) {
1683e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        boolean show = false;
1684e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        if (!mHidden) {
1685e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes            if (mHasMenu && mMenuVisible) {
1686e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes                show = true;
1687e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes                onPrepareSupportOptionsMenu(menu);
1688e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes            }
1689e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes
1690e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes            if (mChildFragmentManager != null) {
1691e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes                show |=  mChildFragmentManager.dispatchPrepareSupportOptionsMenu(menu);
1692e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes            }
1693e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        }
1694e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        return show;
1695e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    }
1696e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes
1697e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    boolean performSupportOptionsItemSelected(android.support.v4.view.MenuItem item) {
1698e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        if (!mHidden) {
1699e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes            if (mHasMenu && mMenuVisible) {
1700e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes                if (onSupportOptionsItemSelected(item)) {
1701e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes                    return true;
1702e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes                }
1703e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes            }
1704e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes
1705e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes            if (mChildFragmentManager != null) {
1706e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes                if (mChildFragmentManager.dispatchSupportOptionsItemSelected(item)) {
1707e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes                    return true;
1708e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes                }
1709e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes            }
1710e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        }
1711e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes        return false;
1712e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes    }
1713e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes
17140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performSaveInstanceState(Bundle outState) {
17150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onSaveInstanceState(outState);
17160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
17170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            Parcelable p = mChildFragmentManager.saveAllState();
17180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            if (p != null) {
17190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                outState.putParcelable(FragmentActivity.FRAGMENTS_TAG, p);
17200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            }
17210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
17220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
17230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
17240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performPause() {
17250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
17260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchPause();
17270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
17280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
17290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onPause();
17300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
17310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
17320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onPause()");
17330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
17340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
17350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
1736cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void performStop() {
17370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
17380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchStop();
17390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
17400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
1741cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        onStop();
17420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
17430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
17440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onStop()");
17450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
1746681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn    }
1747681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn
1748218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn    void performReallyStop() {
17490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
17500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchReallyStop();
17510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
1752cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mLoadersStarted) {
1753cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mLoadersStarted = false;
1754cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (!mCheckedForLoaderManager) {
1755cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mCheckedForLoaderManager = true;
17560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                mLoaderManager = mActivity.getLoaderManager(mWho, mLoadersStarted, false);
1757cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1758cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (mLoaderManager != null) {
1759218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn                if (!mActivity.mRetaining) {
1760cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    mLoaderManager.doStop();
1761cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                } else {
1762cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    mLoaderManager.doRetain();
1763cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1764cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1765cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1766cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
17679c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
17689c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    void performDestroyView() {
17690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
17700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchDestroyView();
17710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
17720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
17739c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        onDestroyView();
17740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
17750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
17760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onDestroyView()");
17770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
17789c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        if (mLoaderManager != null) {
17799c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn            mLoaderManager.doReportNextStart();
17809c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        }
17819c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
17820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
17830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    void performDestroy() {
17840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mChildFragmentManager != null) {
17850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            mChildFragmentManager.dispatchDestroy();
17860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
17870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mCalled = false;
17880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        onDestroy();
17890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (!mCalled) {
17900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            throw new SuperNotCalledException("Fragment " + this
17910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    + " did not call through to super.onDestroy()");
17920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
17930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
1794cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn}
1795