Fragment.java revision 7516316ffdf6fbf7b248c615404831191daa66a4
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; 259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mountimport android.content.res.TypedArray; 269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mountimport android.os.Build; 27cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Bundle; 28cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcel; 29cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcelable; 30a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbyeimport android.support.annotation.Nullable; 31a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbyeimport android.support.annotation.StringRes; 322290993eddf5262a8df7fc9478daed52401e325aDianne Hackbornimport android.support.v4.util.SimpleArrayMap; 33cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.support.v4.util.DebugUtils; 34cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.AttributeSet; 35be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackbornimport android.util.Log; 36cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.SparseArray; 37cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ContextMenu; 38cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.LayoutInflater; 39cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.Menu; 40cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuInflater; 41cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuItem; 42cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View; 43cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ViewGroup; 44cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ContextMenu.ContextMenuInfo; 45cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View.OnCreateContextMenuListener; 46cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.animation.Animation; 47cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.widget.AdapterView; 48cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 49cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.FileDescriptor; 50cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.PrintWriter; 51cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 52cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornfinal class FragmentState implements Parcelable { 53cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final String mClassName; 54cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int mIndex; 55cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final boolean mFromLayout; 56cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int mFragmentId; 57cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int mContainerId; 58cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final String mTag; 59cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final boolean mRetainInstance; 60e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn final boolean mDetached; 61cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final Bundle mArguments; 62cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 63cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Bundle mSavedFragmentState; 64cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 65cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment mInstance; 66cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 67cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentState(Fragment frag) { 68cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mClassName = frag.getClass().getName(); 69cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = frag.mIndex; 70cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mFromLayout = frag.mFromLayout; 71cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mFragmentId = frag.mFragmentId; 72cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mContainerId = frag.mContainerId; 73cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTag = frag.mTag; 74cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mRetainInstance = frag.mRetainInstance; 75e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn mDetached = frag.mDetached; 76cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mArguments = frag.mArguments; 77cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 78cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 79cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentState(Parcel in) { 80cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mClassName = in.readString(); 81cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = in.readInt(); 82cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mFromLayout = in.readInt() != 0; 83cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mFragmentId = in.readInt(); 84cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mContainerId = in.readInt(); 85cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTag = in.readString(); 86cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mRetainInstance = in.readInt() != 0; 87e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn mDetached = in.readInt() != 0; 88cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mArguments = in.readBundle(); 89cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mSavedFragmentState = in.readBundle(); 90cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 91cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn public Fragment instantiate(FragmentActivity activity, Fragment parent) { 93cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mInstance != null) { 94cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mInstance; 95cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 96cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 97cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mArguments != null) { 98cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mArguments.setClassLoader(activity.getClassLoader()); 99cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 100cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 101cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance = Fragment.instantiate(activity, mClassName, mArguments); 102cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 103cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedFragmentState != null) { 104cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mSavedFragmentState.setClassLoader(activity.getClassLoader()); 105cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mSavedFragmentState = mSavedFragmentState; 106cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mInstance.setIndex(mIndex, parent); 108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mFromLayout = mFromLayout; 109cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mRestored = true; 110cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mFragmentId = mFragmentId; 111cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mContainerId = mContainerId; 112cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mTag = mTag; 113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mRetainInstance = mRetainInstance; 114e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn mInstance.mDetached = mDetached; 115cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mFragmentManager = activity.mFragments; 116be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn 117be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn if (FragmentManagerImpl.DEBUG) Log.v(FragmentManagerImpl.TAG, 118be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn "Instantiated fragment " + mInstance); 119be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn 120cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mInstance; 121cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 122cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 123cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public int describeContents() { 124cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return 0; 125cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 126cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 127cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void writeToParcel(Parcel dest, int flags) { 128cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeString(mClassName); 129cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mIndex); 130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mFromLayout ? 1 : 0); 131cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mFragmentId); 132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mContainerId); 133cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeString(mTag); 134cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mRetainInstance ? 1 : 0); 135e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn dest.writeInt(mDetached ? 1 : 0); 136cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeBundle(mArguments); 137cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeBundle(mSavedFragmentState); 138cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 139cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 140cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public static final Parcelable.Creator<FragmentState> CREATOR 141cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn = new Parcelable.Creator<FragmentState>() { 142cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentState createFromParcel(Parcel in) { 143cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return new FragmentState(in); 144cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 145cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 146cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentState[] newArray(int size) { 147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return new FragmentState[size]; 148cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn }; 150cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn} 151cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 152cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/** 153cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Static library support version of the framework's {@link android.app.Fragment}. 154cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Used to write apps that run on platforms prior to Android 3.0. When running 155cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on Android 3.0 or above, this implementation is still used; it does not try 1569dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * to switch to the framework's implementation. See the framework {@link android.app.Fragment} 157cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * documentation for a class overview. 1589dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * 1599dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <p>The main differences when using this support version instead of the framework version are: 1609dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <ul> 1619dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <li>Your activity must extend {@link FragmentActivity} 1629dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <li>You must call {@link FragmentActivity#getSupportFragmentManager} to get the 1639dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * {@link FragmentManager} 1649dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * </ul> 1659dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * 166cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 167cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornpublic class Fragment implements ComponentCallbacks, OnCreateContextMenuListener { 1682290993eddf5262a8df7fc9478daed52401e325aDianne Hackborn private static final SimpleArrayMap<String, Class<?>> sClassMap = 1692290993eddf5262a8df7fc9478daed52401e325aDianne Hackborn new SimpleArrayMap<String, Class<?>>(); 1709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 1719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount static final Object USE_DEFAULT_TRANSITION = new Object(); 1729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int INITIALIZING = 0; // Not yet created. 174cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int CREATED = 1; // Created. 175cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int ACTIVITY_CREATED = 2; // The activity has finished its creation. 176e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn static final int STOPPED = 3; // Fully created, not started. 177e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn static final int STARTED = 4; // Created and started, not resumed. 178e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn static final int RESUMED = 5; // Created started and resumed. 179cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 180cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mState = INITIALIZING; 181cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 182cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Non-null if the fragment's view hierarchy is currently animating away, 183cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // meaning we need to wait a bit on completely destroying it. This is the 184cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // view that is animating. 185cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn View mAnimatingAway; 186cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If mAnimatingAway != null, this is the state we should move to once the 188cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // animation is done. 189cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mStateAfterAnimating; 190cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 191cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // When instantiated from saved state, this is the saved state. 192cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Bundle mSavedFragmentState; 193cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn SparseArray<Parcelable> mSavedViewState; 194cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 195cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Index into active fragment array. 196cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mIndex = -1; 197cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 198cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Internal unique name for this fragment; 199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn String mWho; 200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Construction arguments; 202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Bundle mArguments; 203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Target fragment. 205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment mTarget; 206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 2072c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn // For use when retaining a fragment: this is the index of the last mTarget. 2082c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn int mTargetIndex = -1; 2092c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn 210cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Target request code. 211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mTargetRequestCode; 212cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 213cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // True if the fragment is in the list of added fragments. 214cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mAdded; 215cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment is being removed from its activity. 217cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRemoving; 218cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 219cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // True if the fragment is in the resumed state. 220cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mResumed; 221cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true if this fragment was instantiated from a layout file. 223cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mFromLayout; 224cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 225cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true when the view has actually been inflated in its layout. 226cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mInLayout; 227cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 228cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // True if this fragment has been restored from previously saved state. 229cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRestored; 230cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 231cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Number of active back stack entries this fragment is in. 232cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mBackStackNesting; 233cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 234cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The fragment manager we are associated with. Set as soon as the 235cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // fragment is used in a transaction; cleared after it has been removed 236cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // from all transactions. 237abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell FragmentManagerImpl mFragmentManager; 238cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 239cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Activity this fragment is attached to. 240cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn FragmentActivity mActivity; 2410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 2420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn // Private fragment manager for child fragments inside of this one. 2430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn FragmentManagerImpl mChildFragmentManager; 2440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 2450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn // If this Fragment is contained in another Fragment, this is that container. 2460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Fragment mParentFragment; 2470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The optional identifier for this fragment -- either the container ID if it 249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // was dynamically added to the view hierarchy, or the ID supplied in 250cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // layout. 251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mFragmentId; 252cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 253cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // When a fragment is being dynamically added to the view hierarchy, this 254cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // is the identifier of the parent container it is being added to. 255cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mContainerId; 256cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 257cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The optional named tag for this fragment -- usually used to find 258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // fragments that are not part of the layout. 259cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn String mTag; 260cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 261cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true when the app has requested that this fragment be hidden 262cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // from the user. 263cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mHidden; 264cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 265e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn // Set to true when the app has requested that this fragment be deactivated. 266e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn boolean mDetached; 267e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 268cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment would like its instance retained across 269cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // configuration changes. 270cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRetainInstance; 271cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 272cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment is being retained across the current config change. 273cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRetaining; 274cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 275cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment has menu items to contribute. 276cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mHasMenu; 2772a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 2782a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn // Set to true to allow the fragment's menu to be shown. 2792a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn boolean mMenuVisible = true; 2802a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 281cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Used to verify that subclasses call through to super class. 282cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mCalled; 283cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 284cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If app has requested a specific animation, this is the one to use. 285cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mNextAnim; 286cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 287cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The parent container of the fragment after dynamically added to UI. 288cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn ViewGroup mContainer; 289cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 290cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The View generated for this fragment. 291cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn View mView; 292cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 293cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The real inner view that will save/restore state. 294cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn View mInnerView; 295abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 296abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell // Whether this fragment should defer starting until after other fragments 297abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell // have been started and their loaders are finished. 298abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell boolean mDeferStart; 29979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell 30079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell // Hint provided by the app that this fragment is currently visible to the user. 30179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell boolean mUserVisibleHint = true; 302abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 303cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn LoaderManagerImpl mLoaderManager; 304cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mLoadersStarted; 305cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mCheckedForLoaderManager; 3069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 3079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Object mEnterTransition = null; 3089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Object mReturnTransition = USE_DEFAULT_TRANSITION; 3099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Object mExitTransition = null; 3109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Object mReenterTransition = USE_DEFAULT_TRANSITION; 3119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Object mSharedElementEnterTransition = null; 3129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Object mSharedElementReturnTransition = USE_DEFAULT_TRANSITION; 3139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Boolean mAllowReturnTransitionOverlap; 3149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Boolean mAllowEnterTransitionOverlap; 3159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 3169306f07b1d66f4974a81f781d29739b30124fff0George Mount SharedElementCallback mEnterTransitionCallback = null; 3179306f07b1d66f4974a81f781d29739b30124fff0George Mount SharedElementCallback mExitTransitionCallback = null; 3189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 319cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 3205c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * State information that has been retrieved from a fragment instance 3215c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * through {@link FragmentManager#saveFragmentInstanceState(Fragment) 3225c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * FragmentManager.saveFragmentInstanceState}. 3235c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 3245c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public static class SavedState implements Parcelable { 3255c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn final Bundle mState; 3265c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3275c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn SavedState(Bundle state) { 3285c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState = state; 3295c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3305c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3315c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn SavedState(Parcel in, ClassLoader loader) { 3325c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState = in.readBundle(); 3335c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn if (loader != null && mState != null) { 3345c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState.setClassLoader(loader); 3355c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3365c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3375c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3385c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn @Override 3395c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public int describeContents() { 3405c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return 0; 3415c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3425c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3435c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn @Override 3445c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public void writeToParcel(Parcel dest, int flags) { 3455c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn dest.writeBundle(mState); 3465c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3475c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3485c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public static final Parcelable.Creator<SavedState> CREATOR 3495c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn = new Parcelable.Creator<SavedState>() { 3505c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public SavedState createFromParcel(Parcel in) { 3515c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return new SavedState(in, null); 3525c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3535c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3545c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public SavedState[] newArray(int size) { 3555c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return new SavedState[size]; 3565c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3575c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn }; 3585c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3595c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3605c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 361cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when 362cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * there is an instantiation failure. 363cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 364cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static public class InstantiationException extends RuntimeException { 365cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public InstantiationException(String msg, Exception cause) { 366cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn super(msg, cause); 367cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 368cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 369cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 370cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 371cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Default constructor. <strong>Every</strong> fragment must have an 372cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * empty constructor, so it can be instantiated when restoring its 373cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * activity's state. It is strongly recommended that subclasses do not 374cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * have other constructors with parameters, since these constructors 375cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * will not be called when the fragment is re-instantiated; instead, 376cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * arguments can be supplied by the caller with {@link #setArguments} 377cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * and later retrieved by the Fragment with {@link #getArguments}. 378cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 379cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>Applications should generally not implement a constructor. The 380cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * first place application code an run where the fragment is ready to 381cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * be used is in {@link #onAttach(Activity)}, the point where the fragment 382cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is actually associated with its activity. Some applications may also 383cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * want to implement {@link #onInflate} to retrieve attributes from a 384cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * layout resource, though should take care here because this happens for 385cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the fragment is attached to its activity. 386cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public Fragment() { 388cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 389cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 390cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 391cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Like {@link #instantiate(Context, String, Bundle)} but with a null 392cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * argument Bundle. 393cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 394cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public static Fragment instantiate(Context context, String fname) { 395cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return instantiate(context, fname, null); 396cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 397cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 398cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 399cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Create a new instance of a Fragment with the given class name. This is 400cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the same as calling its empty constructor. 401cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 402cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param context The calling context being used to instantiate the fragment. 403cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is currently just used to get its ClassLoader. 404cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fname The class name of the fragment to instantiate. 405cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param args Bundle of arguments to supply to the fragment, which it 406cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can retrieve with {@link #getArguments()}. May be null. 407cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return Returns a new fragment instance. 408cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @throws InstantiationException If there is a failure in instantiating 409cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the given fragment class. This is a runtime exception; it is not 410cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * normally expected to happen. 411cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 412cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public static Fragment instantiate(Context context, String fname, Bundle args) { 413cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn try { 414cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Class<?> clazz = sClassMap.get(fname); 415cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (clazz == null) { 416cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Class not found in the cache, see if it's real, and try to add it 417cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn clazz = context.getClassLoader().loadClass(fname); 418cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sClassMap.put(fname, clazz); 419cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 420cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment f = (Fragment)clazz.newInstance(); 421cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (args != null) { 422cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn args.setClassLoader(f.getClass().getClassLoader()); 423cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn f.mArguments = args; 424cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 425cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return f; 426cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (ClassNotFoundException e) { 427cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 428cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 429cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 430cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (java.lang.InstantiationException e) { 431cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 432cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 433cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 434cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (IllegalAccessException e) { 435cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 436cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 437cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 438cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 439cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4403fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell 4413fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell /** 4423fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * Determine if the given fragment name is a support library fragment class. 4433fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * 4443fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * @param context Context used to determine the correct ClassLoader to use 4453fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * @param fname Class name of the fragment to test 4463fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * @return true if <code>fname</code> is <code>android.support.v4.app.Fragment</code> 4473fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * or a subclass, false otherwise. 4483fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell */ 4493fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell static boolean isSupportFragmentClass(Context context, String fname) { 4503fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell try { 4513fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell Class<?> clazz = sClassMap.get(fname); 4523fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell if (clazz == null) { 4533fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell // Class not found in the cache, see if it's real, and try to add it 4543fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell clazz = context.getClassLoader().loadClass(fname); 4553fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell sClassMap.put(fname, clazz); 4563fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 4573fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell return Fragment.class.isAssignableFrom(clazz); 4583fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } catch (ClassNotFoundException e) { 4593fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell return false; 4603fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 4613fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 462cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 4630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final void restoreViewState(Bundle savedInstanceState) { 464cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedViewState != null) { 465cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInnerView.restoreHierarchyState(mSavedViewState); 466cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mSavedViewState = null; 467cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 4690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onViewStateRestored(savedInstanceState); 4700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 4710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 4720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onViewStateRestored()"); 4730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 474cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 4760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final void setIndex(int index, Fragment parent) { 477cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = index; 4780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (parent != null) { 4790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mWho = parent.mWho + ":" + mIndex; 4800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else { 4810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mWho = "android:fragment:" + mIndex; 4820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 483e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 4840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 485e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn final boolean isInBackStack() { 486e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn return mBackStackNesting > 0; 487e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 488e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 489cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 490cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Subclasses can not override equals(). 491cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 492cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override final public boolean equals(Object o) { 493cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return super.equals(o); 494cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 495cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 496cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 497cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Subclasses can not override hashCode(). 498cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 499cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override final public int hashCode() { 500cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return super.hashCode(); 501cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 502cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 503cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override 504cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public String toString() { 505cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn StringBuilder sb = new StringBuilder(128); 506cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn DebugUtils.buildShortClassTag(this, sb); 507cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mIndex >= 0) { 508cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" #"); 509cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(mIndex); 510cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 511cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mFragmentId != 0) { 512cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" id=0x"); 513cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(Integer.toHexString(mFragmentId)); 514cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 515cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mTag != null) { 516cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" "); 517cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(mTag); 518cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 519cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append('}'); 520cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return sb.toString(); 521cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 522cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 523cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 524cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the identifier this fragment is known by. This is either 525cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the android:id value supplied in a layout or the container view ID 526cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * supplied when adding the fragment. 527cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 528cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public int getId() { 529cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mFragmentId; 530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 532cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 533cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Get the tag name of the fragment, if specified. 534cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public String getTag() { 536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTag; 537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 539cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 540cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Supply the construction arguments for this fragment. This can only 541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * be called before the fragment has been attached to its activity; that 542cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is, you should call it immediately after constructing the fragment. The 543cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * arguments supplied here will be retained across fragment destroy and 544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * creation. 545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setArguments(Bundle args) { 547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mIndex >= 0) { 548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment already active"); 549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mArguments = args; 551cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the arguments supplied when the fragment was instantiated, 555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if any. 556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public Bundle getArguments() { 558cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mArguments; 559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 561cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 5625c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Set the initial saved state that this Fragment should restore itself 5635c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * from when first being constructed, as returned by 5645c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * {@link FragmentManager#saveFragmentInstanceState(Fragment) 5655c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * FragmentManager.saveFragmentInstanceState}. 5665c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * 5675c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param state The state the fragment should be restored from. 5685c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 5695c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public void setInitialSavedState(SavedState state) { 5705c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn if (mIndex >= 0) { 5715c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn throw new IllegalStateException("Fragment already active"); 5725c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 5735c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mSavedFragmentState = state != null && state.mState != null 5745c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn ? state.mState : null; 5755c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 5765c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 5775c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 578cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Optional target for this fragment. This may be used, for example, 579cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if this fragment is being started by another, and when done wants to 580cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * give a result back to the first. The target set here is retained 581cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * across instances via {@link FragmentManager#putFragment 582cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * FragmentManager.putFragment()}. 583cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 584cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fragment The fragment that is the target of this one. 585cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param requestCode Optional request code, for convenience if you 586cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * are going to call back with {@link #onActivityResult(int, int, Intent)}. 587cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 588cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setTargetFragment(Fragment fragment, int requestCode) { 589cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTarget = fragment; 590cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTargetRequestCode = requestCode; 591cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 592cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 593cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 594cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the target fragment set by {@link #setTargetFragment}. 595cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 596cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public Fragment getTargetFragment() { 597cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTarget; 598cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 599cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 600cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 601cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the target request code set by {@link #setTargetFragment}. 602cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 603cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public int getTargetRequestCode() { 604cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTargetRequestCode; 605cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 606cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 607cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 608cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the Activity this fragment is currently associated with. 609cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 610cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public FragmentActivity getActivity() { 611cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mActivity; 612cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 613cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 614cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 615cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return <code>getActivity().getResources()</code>. 616cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 617cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public Resources getResources() { 618cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mActivity == null) { 619cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 620cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 621cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mActivity.getResources(); 622cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 623cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 624cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 625cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized, styled CharSequence from the application's package's 626cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table. 627cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 628cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the CharSequence text 629cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 630a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final CharSequence getText(@StringRes int resId) { 631cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getText(resId); 632cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 633cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 634cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 635cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized string from the application's package's 636cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table. 637cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 638cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the string 639cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 640a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final String getString(@StringRes int resId) { 641cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getString(resId); 642cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 643cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 644cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 645cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized formatted string from the application's package's 646cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table, substituting the format arguments as defined in 647cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link java.util.Formatter} and {@link java.lang.String#format}. 648cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 649cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the format string 650cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param formatArgs The format arguments that will be used for substitution. 651cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 652cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 653a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final String getString(@StringRes int resId, Object... formatArgs) { 654cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getString(resId, formatArgs); 655cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 656cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 657cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 658cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the FragmentManager for interacting with fragments associated 659cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * with this fragment's activity. Note that this will be non-null slightly 660cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * before {@link #getActivity()}, during the time from when the fragment is 661cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * placed in a {@link FragmentTransaction} until it is committed and 662cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * attached to its activity. 6630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 6640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * <p>If this Fragment is a child of another Fragment, the FragmentManager 6650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * returned here will be the parent's {@link #getChildFragmentManager()}. 666cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 667cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public FragmentManager getFragmentManager() { 668cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mFragmentManager; 669cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 670cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 671cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 6720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Return a private FragmentManager for placing and managing Fragments 6730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * inside of this Fragment. 6740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 6750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final public FragmentManager getChildFragmentManager() { 6760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager == null) { 6770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn instantiateChildFragmentManager(); 6780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mState >= RESUMED) { 6790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchResume(); 6800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= STARTED) { 6810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStart(); 6820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= ACTIVITY_CREATED) { 6830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchActivityCreated(); 6840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= CREATED) { 6850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchCreate(); 6860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 6870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 6880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mChildFragmentManager; 6890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 6900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 6910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 6920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Returns the parent Fragment containing this Fragment. If this Fragment 6930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * is attached directly to an Activity, returns null. 6940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 6950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final public Fragment getParentFragment() { 6960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mParentFragment; 6970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 6980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 6990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 700cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is currently added to its activity. 701cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 702cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isAdded() { 703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mActivity != null && mAdded; 704cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 7079c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * Return true if the fragment has been explicitly detached from the UI. 7089c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * That is, {@link FragmentTransaction#detach(Fragment) 7099c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * FragmentTransaction.detach(Fragment)} has been used on it. 7109c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn */ 7119c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn final public boolean isDetached() { 7129c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn return mDetached; 7139c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 7149c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 7159c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn /** 716cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if this fragment is currently being removed from its 717cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * activity. This is <em>not</em> whether its activity is finishing, but 718cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * rather whether it is in the process of being removed from its activity. 719cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 720cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isRemoving() { 721cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mRemoving; 722cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 724cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 725cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the layout is included as part of an activity view 726cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * hierarchy via the <fragment> tag. This will always be true when 727cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * fragments are created through the <fragment> tag, <em>except</em> 728cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * in the case where an old fragment is restored from a previous state and 729cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * it does not appear in the layout of the current state. 730cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 731cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isInLayout() { 732cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mInLayout; 733cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 734cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 735cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 736cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is in the resumed state. This is true 737cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for the duration of {@link #onResume()} and {@link #onPause()} as well. 738cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 739cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isResumed() { 740cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mResumed; 741cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 742cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 743cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 744cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is currently visible to the user. This means 745cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * it: (1) has been added, (2) has its view attached to the window, and 746cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * (3) is not hidden. 747cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 748cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isVisible() { 749cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return isAdded() && !isHidden() && mView != null 750cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE; 751cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 752cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 753cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 754cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment has been hidden. By default fragments 755cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * are shown. You can find out about changes to this state with 756cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onHiddenChanged}. Note that the hidden state is orthogonal 757cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to other states -- that is, to be visible to the user, a fragment 758cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * must be both started and not hidden. 759cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 760cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isHidden() { 761cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mHidden; 762cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 7633a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 7643a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown /** @hide */ 7653a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown final public boolean hasOptionsMenu() { 7663a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown return mHasMenu; 7673a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown } 7683a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 7693a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown /** @hide */ 7703a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown final public boolean isMenuVisible() { 7713a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown return mMenuVisible; 7723a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown } 7733a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 774cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 775cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the hidden state (as returned by {@link #isHidden()} of 776cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the fragment has changed. Fragments start out not hidden; this will 777cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * be called whenever the fragment changes state from that. 778cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param hidden True if the fragment is now hidden, false if it is not 779cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * visible. 780cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 781cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onHiddenChanged(boolean hidden) { 782cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 783cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 784cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 785cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Control whether a fragment instance is retained across Activity 786cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * re-creation (such as from a configuration change). This can only 787cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * be used with fragments not in the back stack. If set, the fragment 788cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * lifecycle will be slightly different when an activity is recreated: 789cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <ul> 790cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still 791cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * will be, because the fragment is being detached from its current activity). 792cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onCreate(Bundle)} will not be called since the fragment 793cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is not being re-created. 794cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b> 795cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * still be called. 796cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * </ul> 797cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 798cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setRetainInstance(boolean retain) { 7990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (retain && mParentFragment != null) { 8000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new IllegalStateException( 8010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn "Can't retain fragements that are nested in other fragments"); 8020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 803cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mRetainInstance = retain; 804cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 805cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 806cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean getRetainInstance() { 807cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mRetainInstance; 808cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 809cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 810cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 811cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Report that this fragment would like to participate in populating 812cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the options menu by receiving a call to {@link #onCreateOptionsMenu} 813cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * and related methods. 814cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 815cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param hasMenu If true, the fragment has menu items to contribute. 816cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 817cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setHasOptionsMenu(boolean hasMenu) { 818cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mHasMenu != hasMenu) { 819cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mHasMenu = hasMenu; 820cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (isAdded() && !isHidden()) { 821681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn mActivity.supportInvalidateOptionsMenu(); 822cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 823cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 824cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8252a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 8262a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn /** 8272a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * Set a hint for whether this fragment's menu should be visible. This 8282a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * is useful if you know that a fragment has been placed in your view 8292a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * hierarchy so that the user can not currently seen it, so any menu items 8302a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * it has should also not be shown. 8312a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * 8322a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * @param menuVisible The default is true, meaning the fragment's menu will 8332a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * be shown as usual. If false, the user will not see the menu. 8342a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn */ 8352a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn public void setMenuVisibility(boolean menuVisible) { 8362a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn if (mMenuVisible != menuVisible) { 8372a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn mMenuVisible = menuVisible; 8382a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn if (mHasMenu && isAdded() && !isHidden()) { 8392a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn mActivity.supportInvalidateOptionsMenu(); 8402a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 8412a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 8422a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 8432a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 844cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 84579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * Set a hint to the system about whether this fragment's UI is currently visible 84679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * to the user. This hint defaults to true and is persistent across fragment instance 84779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * state save and restore. 848abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell * 84979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * <p>An app may set this to false to indicate that the fragment's UI is 85079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * scrolled out of visibility or is otherwise not directly visible to the user. 85179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * This may be used by the system to prioritize operations such as fragment lifecycle updates 85279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * or loader ordering behavior.</p> 853abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell * 85479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @param isVisibleToUser true if this fragment's UI is currently visible to the user (default), 85579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * false if it is not. 856abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell */ 85779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell public void setUserVisibleHint(boolean isVisibleToUser) { 85879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell if (!mUserVisibleHint && isVisibleToUser && mState < STARTED) { 859abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell mFragmentManager.performPendingDeferredStart(this); 860abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 86179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell mUserVisibleHint = isVisibleToUser; 86279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell mDeferStart = !isVisibleToUser; 863abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 864abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 865abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell /** 86679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @return The current value of the user-visible hint on this fragment. 86779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @see #setUserVisibleHint(boolean) 868abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell */ 86979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell public boolean getUserVisibleHint() { 87079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell return mUserVisibleHint; 871abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 872abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 873abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell /** 874cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the LoaderManager for this fragment, creating it if needed. 875cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 876cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public LoaderManager getLoaderManager() { 877cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoaderManager != null) { 878cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mLoaderManager; 879cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 880cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mActivity == null) { 881cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 882cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 883cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCheckedForLoaderManager = true; 8840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mLoaderManager = mActivity.getLoaderManager(mWho, mLoadersStarted, true); 885cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mLoaderManager; 886cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 887cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 888cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 889cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Call {@link Activity#startActivity(Intent)} on the fragment's 890cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * containing Activity. 891cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 892cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void startActivity(Intent intent) { 893cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mActivity == null) { 894cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 895cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 896cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mActivity.startActivityFromFragment(this, intent, -1); 897cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 898cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 899cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 900cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Call {@link Activity#startActivityForResult(Intent, int)} on the fragment's 901cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * containing Activity. 902cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 903cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void startActivityForResult(Intent intent, int requestCode) { 904cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mActivity == null) { 905cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 906cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 907cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mActivity.startActivityFromFragment(this, intent, requestCode); 908cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 909cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 910cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 911cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Receive the result from a previous call to 912cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #startActivityForResult(Intent, int)}. This follows the 913cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * related Activity API as described there in 914cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onActivityResult(int, int, Intent)}. 915cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 916cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param requestCode The integer request code originally supplied to 917cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * startActivityForResult(), allowing you to identify who this 918cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * result came from. 919cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resultCode The integer result code returned by the child activity 920cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * through its setResult(). 921cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param data An Intent, which can return result data to the caller 922cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * (various data can be attached to Intent "extras"). 923cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 924cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onActivityResult(int requestCode, int resultCode, Intent data) { 925cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 926cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 927cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 928cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @hide Hack so that DialogFragment can make its Dialog before creating 929cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * its views, and the view construction can use the dialog's context for 930cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * inflation. Maybe this should become a public API. Note sure. 931cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 932cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public LayoutInflater getLayoutInflater(Bundle savedInstanceState) { 9330f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell LayoutInflater result = mActivity.getLayoutInflater().cloneInContext(mActivity); 9340f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell getChildFragmentManager(); // Init if needed; use raw implementation below. 9350f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell result.setFactory(mChildFragmentManager.getLayoutInflaterFactory()); 9360f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell return result; 937cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 938cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 939cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 940cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a fragment is being created as part of a view layout 941cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * inflation, typically from setting the content view of an activity. This 9429277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * may be called immediately after the fragment is created from a <fragment> 943cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tag in a layout file. Note this is <em>before</em> the fragment's 944cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onAttach(Activity)} has been called; all you should do here is 9459277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * parse the attributes and save them away. 946cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 947cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>This is called every time the fragment is inflated, even if it is 9489277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * being inflated into a new instance with saved state. It typically makes 9499277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * sense to re-parse the parameters each time, to allow them to change with 9509277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * different configurations.</p> 9519277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 9529277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>Here is a typical implementation of a fragment that can take parameters 9539277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * both through attributes supplied here as well from {@link #getArguments()}:</p> 9549277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 9559277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java 9569277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * fragment} 9579277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 9589277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>Note that parsing the XML attributes uses a "styleable" resource. The 9599277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * declaration for the styleable used here is:</p> 9609277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 9619277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * {@sample development/samples/ApiDemos/res/values/attrs.xml fragment_arguments} 962cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 9639277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>The fragment can then be declared within its activity's content layout 9649277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * through a tag like this:</p> 9659277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 9669277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * {@sample development/samples/ApiDemos/res/layout/fragment_arguments.xml from_attributes} 9679277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 9689277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>This fragment can also be created dynamically from arguments given 9699277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * at runtime in the arguments Bundle; here is an example of doing so at 9709277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * creation of the containing activity:</p> 9719277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 9729277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java 9739277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * create} 9749277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 9759277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * @param activity The Activity that is inflating this fragment. 976cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param attrs The attributes at the tag where the fragment is 977cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * being created. 978cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 979cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 980cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 9819277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { 982cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 983cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 985cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 986cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a fragment is first attached to its activity. 987cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreate(Bundle)} will be called after this. 988cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 989cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onAttach(Activity activity) { 990cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 991cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 992cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 993cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 994cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a fragment loads an animation. 995cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 9969277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { 997cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return null; 998cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 999cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1000cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1001cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to do initial creation of a fragment. This is called after 1002cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onAttach(Activity)} and before 1003cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 1004cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1005cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>Note that this can be called while the fragment's activity is 1006cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * still in the process of being created. As such, you can not rely 1007cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on things like the activity's content view hierarchy being initialized 1008cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * at this point. If you want to do work once the activity itself is 1009cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * created, see {@link #onActivityCreated(Bundle)}. 1010cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1011cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 1012cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 1013cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1014cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onCreate(Bundle savedInstanceState) { 1015cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1016cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 10170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1018cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1019cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to have the fragment instantiate its user interface view. 1020cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is optional, and non-graphical fragments can return null (which 1021cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is the default implementation). This will be called between 1022cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}. 1023cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1024cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>If you return a View from here, you will later be called in 1025cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onDestroyView} when the view is being released. 1026cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1027cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param inflater The LayoutInflater object that can be used to inflate 1028cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * any views in the fragment, 1029cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param container If non-null, this is the parent view that the fragment's 1030cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * UI should be attached to. The fragment should not add the view itself, 1031cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * but this can be used to generate the LayoutParams of the view. 1032cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If non-null, this fragment is being re-constructed 1033cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * from a previous saved state as given here. 1034cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1035cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return Return the View for the fragment's UI, or null. 1036cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1037a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, 1038a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye @Nullable Bundle savedInstanceState) { 1039cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return null; 1040cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 10410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1042cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1043e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} 1044e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * has returned, but before any saved state has been restored in to the view. 1045e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * This gives subclasses a chance to initialize themselves once 1046e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * they know their view hierarchy has been completely created. The fragment's 1047e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * view hierarchy is not however attached to its parent at this point. 1048e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 1049e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * @param savedInstanceState If non-null, this fragment is being re-constructed 1050e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * from a previous saved state as given here. 1051e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn */ 1052a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 1053e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 1054e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 1055e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn /** 1056cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}), 1057cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if provided. 1058cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1059cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return The fragment's root view, or null if it has no layout. 1060cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1061a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye @Nullable 1062cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public View getView() { 1063cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mView; 1064cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1065cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1066cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1067cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment's activity has been created and this 1068cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * fragment's view hierarchy instantiated. It can be used to do final 1069cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * initialization once these pieces are in place, such as retrieving 1070cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * views or restoring state. It is also useful for fragments that use 1071cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #setRetainInstance(boolean)} to retain their instance, 1072cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * as this callback tells the fragment when it is fully associated with 1073cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the new activity instance. This is called after {@link #onCreateView} 10740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * and before {@link #onViewStateRestored(Bundle)}. 10750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 1076cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 1077cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 1078cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1079a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public void onActivityCreated(@Nullable Bundle savedInstanceState) { 1080cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1081cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 10820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 10830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 10840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Called when all saved state has been restored into the view hierarchy 10850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * of the fragment. This can be used to do initialization based on saved 10860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * state that you are letting the view hierarchy track itself, such as 10870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * whether check box widgets are currently checked. This is called 10880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * after {@link #onActivityCreated(Bundle)} and before 10890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * {@link #onStart()}. 10900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 10910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 10920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * a previous saved state, this is the state. 10930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 1094a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public void onViewStateRestored(@Nullable Bundle savedInstanceState) { 10950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = true; 10960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 10970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1098cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1099cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is visible to the user. This is generally 1100cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onStart() Activity.onStart} of the containing 1101cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1102cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1103cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onStart() { 1104cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1105cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1106cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!mLoadersStarted) { 1107cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoadersStarted = true; 1108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!mCheckedForLoaderManager) { 1109cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCheckedForLoaderManager = true; 11100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mLoaderManager = mActivity.getLoaderManager(mWho, mLoadersStarted, false); 1111cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1112cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoaderManager != null) { 1113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoaderManager.doStart(); 1114cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1115cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1116cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1117cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1118cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1119cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is visible to the user and actively running. 1120cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is generally 1121cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onResume() Activity.onResume} of the containing 1122cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1123cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1124cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onResume() { 1125cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1126cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1127cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1128cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1129cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to ask the fragment to save its current dynamic state, so it 1130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can later be reconstructed in a new instance of its process is 1131cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * restarted. If a new instance of the fragment later needs to be 1132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * created, the data you place in the Bundle here will be available 1133cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * in the Bundle given to {@link #onCreate(Bundle)}, 1134cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}, and 1135cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onActivityCreated(Bundle)}. 1136cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1137cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>This corresponds to {@link Activity#onSaveInstanceState(Bundle) 1138cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity.onSaveInstanceState(Bundle)} and most of the discussion there 1139cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * applies here as well. Note however: <em>this method may be called 1140cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * at any time before {@link #onDestroy()}</em>. There are many situations 1141cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * where a fragment may be mostly torn down (such as when placed on the 1142cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * back stack with no UI showing), but its state will not be saved until 1143cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * its owning activity actually needs to save its state. 1144cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1145cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param outState Bundle in which to place your saved state. 1146cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onSaveInstanceState(Bundle outState) { 1148cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1150cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onConfigurationChanged(Configuration newConfig) { 1151cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1152cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1153cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1154cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1155cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is no longer resumed. This is generally 1156cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onPause() Activity.onPause} of the containing 1157cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1158cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1159cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onPause() { 1160cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1161cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1162cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1163cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1164cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is no longer started. This is generally 1165cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onStop() Activity.onStop} of the containing 1166cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1167cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1168cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onStop() { 1169cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1170cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1171cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1172cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onLowMemory() { 1173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1174cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1175cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1176cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1177cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the view previously created by {@link #onCreateView} has 1178cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * been detached from the fragment. The next time the fragment needs 1179cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to be displayed, a new view will be created. This is called 1180cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * after {@link #onStop()} and before {@link #onDestroy()}. It is called 1181cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <em>regardless</em> of whether {@link #onCreateView} returned a 1182cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * non-null view. Internally it is called after the view's state has 1183cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * been saved but before it has been removed from its parent. 1184cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1185cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroyView() { 1186cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1188cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1189cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1190cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is no longer in use. This is called 1191cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * after {@link #onStop()} and before {@link #onDetach()}. 1192cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1193cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroy() { 1194cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1195cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn //Log.v("foo", "onDestroy: mCheckedForLoaderManager=" + mCheckedForLoaderManager 1196cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // + " mLoaderManager=" + mLoaderManager); 1197cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!mCheckedForLoaderManager) { 1198cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCheckedForLoaderManager = true; 11990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mLoaderManager = mActivity.getLoaderManager(mWho, mLoadersStarted, false); 1200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoaderManager != null) { 1202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoaderManager.doDestroy(); 1203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 12079c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * Called by the fragment manager once this fragment has been removed, 12089c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * so that we don't have any left-over state if the application decides 12099c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * to re-use the instance. This only clears state that the framework 12109c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * internally manages, not things the application sets. 12119c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn */ 12129c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void initState() { 12139c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mIndex = -1; 12149c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mWho = null; 12159c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mAdded = false; 12169c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRemoving = false; 12179c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mResumed = false; 12189c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFromLayout = false; 12199c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mInLayout = false; 12209c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRestored = false; 12219c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mBackStackNesting = 0; 12229c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFragmentManager = null; 12236252d78085a07c9d6bb4645a4e8086bf23b0a49aTim Kilbourn mChildFragmentManager = null; 12242a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn mActivity = null; 12259c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFragmentId = 0; 12269c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mContainerId = 0; 12279c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mTag = null; 12289c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mHidden = false; 12299c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mDetached = false; 12309c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRetaining = false; 12319c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mLoaderManager = null; 12329c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mLoadersStarted = false; 12339c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mCheckedForLoaderManager = false; 12349c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 12359c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 12369c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn /** 1237cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is no longer attached to its activity. This 1238cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is called after {@link #onDestroy()}. 1239cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1240cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDetach() { 1241cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1242cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1243cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Initialize the contents of the Activity's standard options menu. You 1246cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * should place your menu items in to <var>menu</var>. For this method 1247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to be called, you must have first called {@link #setHasOptionsMenu}. See 1248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu} 1249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for more information. 1250cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu in which you place your items. 1252cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1253cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #setHasOptionsMenu 1254cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onPrepareOptionsMenu 1255cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onOptionsItemSelected 1256cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1257cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 1258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1259cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1260cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1261cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Prepare the Screen's standard options menu to be displayed. This is 1262cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * called right before the menu is shown, every time it is shown. You can 1263cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * use this method to efficiently enable/disable items or otherwise 1264cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * dynamically modify the contents. See 1265cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu} 1266cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for more information. 1267cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1268cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu as last shown or first initialized by 1269cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * onCreateOptionsMenu(). 1270cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1271cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #setHasOptionsMenu 1272cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onCreateOptionsMenu 1273cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1274cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onPrepareOptionsMenu(Menu menu) { 1275cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1276cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1277cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1278cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when this fragment's option menu items are no longer being 1279cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * included in the overall options menu. Receiving this call means that 1280cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the menu needed to be rebuilt, but this fragment's items were not 1281cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * included in the newly built menu (its {@link #onCreateOptionsMenu(Menu, MenuInflater)} 1282cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * was not called). 1283cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1284cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroyOptionsMenu() { 1285cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1286cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1287cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1288cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever an item in your options menu is selected. 1289cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * The default implementation simply returns false to have the normal 1290cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * processing happen (calling the item's Runnable or sending a message to 1291cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * its Handler as appropriate). You can use this method for any items 1292cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for which you would like to do processing without those other 1293cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * facilities. 1294cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1295cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>Derived classes should call through to the base class for it to 1296cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * perform the default menu handling. 1297cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1298cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param item The menu item that was selected. 1299cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1300cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return boolean Return false to allow normal menu processing to 1301cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * proceed, true to consume it here. 1302cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1303cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onCreateOptionsMenu 1304cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1305cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public boolean onOptionsItemSelected(MenuItem item) { 1306cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return false; 1307cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1308cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1309cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1310cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever the options menu is being closed (either by the user canceling 1311cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the menu with the back/menu button, or when an item is selected). 1312cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1313cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu as last shown or first initialized by 1314cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * onCreateOptionsMenu(). 1315cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1316cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onOptionsMenuClosed(Menu menu) { 1317cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1318cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1319cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1320cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a context menu for the {@code view} is about to be shown. 1321cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Unlike {@link #onCreateOptionsMenu}, this will be called every 1322cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * time the context menu is about to be shown and should be populated for 1323cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the view (or item inside the view for {@link AdapterView} subclasses, 1324cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * this can be found in the {@code menuInfo})). 1325cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1326cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an 1327cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * item has been selected. 1328cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1329cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * The default implementation calls up to 1330cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though 1331cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * you can not call this implementation if you don't want that behavior. 1332cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1333cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * It is not safe to hold onto the context menu after this method returns. 1334cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@inheritDoc} 1335cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1336cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 1337cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn getActivity().onCreateContextMenu(menu, v, menuInfo); 1338cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1339cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1340cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1341cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Registers a context menu to be shown for the given view (multiple views 1342cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can show the context menu). This method will set the 1343cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link OnCreateContextMenuListener} on the view to this fragment, so 1344cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be 1345cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * called when it is time to show the context menu. 1346cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1347cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #unregisterForContextMenu(View) 1348cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param view The view that should show a context menu. 1349cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1350cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void registerForContextMenu(View view) { 1351cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn view.setOnCreateContextMenuListener(this); 1352cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1353cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1354cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1355cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Prevents a context menu to be shown for the given view. This method will 1356cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * remove the {@link OnCreateContextMenuListener} on the view. 1357cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1358cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #registerForContextMenu(View) 1359cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param view The view that should stop showing a context menu. 1360cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1361cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void unregisterForContextMenu(View view) { 1362cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn view.setOnCreateContextMenuListener(null); 1363cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1364cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1365cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1366cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever an item in a context menu is selected. The 1367cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default implementation simply returns false to have the normal processing 1368cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * happen (calling the item's Runnable or sending a message to its Handler 1369cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * as appropriate). You can use this method for any items for which you 1370cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * would like to do processing without those other facilities. 1371cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1372cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Use {@link MenuItem#getMenuInfo()} to get extra information set by the 1373cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * View that added this menu item. 1374cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1375cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Derived classes should call through to the base class for it to perform 1376cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the default menu handling. 1377cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1378cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param item The context menu item that was selected. 1379cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return boolean Return false to allow normal context menu processing to 1380cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * proceed, true to consume it here. 1381cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1382cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public boolean onContextItemSelected(MenuItem item) { 1383cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return false; 1384cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1385e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes 1386cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 13879306f07b1d66f4974a81f781d29739b30124fff0George Mount * When custom transitions are used with Fragments, the enter transition callback 13889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is called when this Fragment is attached or detached when not popping the back stack. 13899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 13909306f07b1d66f4974a81f781d29739b30124fff0George Mount * @param callback Used to manipulate the shared element transitions on this Fragment 13919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when added not as a pop from the back stack. 13929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 1393b1413bc4de16e05ae0455cad93f1edfbcc4eced2George Mount public void setEnterSharedElementCallback(SharedElementCallback callback) { 13949306f07b1d66f4974a81f781d29739b30124fff0George Mount mEnterTransitionCallback = callback; 13959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 13969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 13979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 13989306f07b1d66f4974a81f781d29739b30124fff0George Mount * When custom transitions are used with Fragments, the exit transition callback 13999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is called when this Fragment is attached or detached when popping the back stack. 14009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 14019306f07b1d66f4974a81f781d29739b30124fff0George Mount * @param callback Used to manipulate the shared element transitions on this Fragment 14029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when added as a pop from the back stack. 14039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 1404b1413bc4de16e05ae0455cad93f1edfbcc4eced2George Mount public void setExitSharedElementCallback(SharedElementCallback callback) { 14059306f07b1d66f4974a81f781d29739b30124fff0George Mount mExitTransitionCallback = callback; 14069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 14079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 14089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 14099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views into the initial scene. The entering 14109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 14119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 14129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 14139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null, 14149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. 14159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 14169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views into the initial Scene. 14179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 14189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setEnterTransition(Object transition) { 14199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mEnterTransition = transition; 14209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 14219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 14229f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 14239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views into the initial scene. The entering 14249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 14259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 14269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 14279f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#INVISIBLE} to {@link View#VISIBLE}. 14289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 14299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views into the initial Scene. 14309f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 14319f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getEnterTransition() { 14329f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return mEnterTransition; 14339f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 14349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 14359f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 14369f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views out of the scene when the Fragment is 14379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * preparing to be removed, hidden, or detached because of popping the back stack. The exiting 14389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 14399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 14409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 14419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null, 14429f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. If nothing is set, the default will be to 14439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * use the same value as set in {@link #setEnterTransition(Object)}. 14449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 14459f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views out of the Scene when the Fragment 14469f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is preparing to close. <code>transition</code> must be an 14479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * android.transition.Transition. 14489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 14499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setReturnTransition(Object transition) { 14509f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mReturnTransition = transition; 14519f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 14529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 14539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 14549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views out of the scene when the Fragment is 14559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * preparing to be removed, hidden, or detached because of popping the back stack. The exiting 14569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 14579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 14589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 14599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null, 14609f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. 14619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 14629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views out of the Scene when the Fragment 14639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is preparing to close. 14649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 14659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getReturnTransition() { 14669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return mReturnTransition == USE_DEFAULT_TRANSITION ? getEnterTransition() 14679f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount : mReturnTransition; 14689f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 14699f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 14709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 14719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views out of the scene when the 14729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * fragment is removed, hidden, or detached when not popping the back stack. 14739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * The exiting Views will be those that are regular Views or ViewGroups that 14749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 14759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as exiting is governed by changing visibility 14769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will 14779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * remain unaffected. 14789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 14799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views out of the Scene when the Fragment 14809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is being closed not due to popping the back stack. <code>transition</code> 14819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * must be an android.transition.Transition. 14829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 14839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setExitTransition(Object transition) { 14849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mExitTransition = transition; 14859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 14869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 14879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 14889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views out of the scene when the 14899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * fragment is removed, hidden, or detached when not popping the back stack. 14909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * The exiting Views will be those that are regular Views or ViewGroups that 14919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 14929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as exiting is governed by changing visibility 14939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will 14949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * remain unaffected. 14959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 14969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views out of the Scene when the Fragment 14979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is being closed not due to popping the back stack. 14989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 14999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getExitTransition() { 15009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return mExitTransition; 15019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 15029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 15039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 15049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views in to the scene when returning due 15059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * to popping a back stack. The entering Views will be those that are regular Views 15069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions 15079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * will extend {@link android.transition.Visibility} as exiting is governed by changing 15089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, 15099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * the views will remain unaffected. If nothing is set, the default will be to use the same 15109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * transition as {@link #setExitTransition(Object)}. 15119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 15129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views into the scene when reentering from a 15139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * previously-started Activity. <code>transition</code> 15149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * must be an android.transition.Transition. 15159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 15169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setReenterTransition(Object transition) { 15179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mReenterTransition = transition; 15189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 15199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 15209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 15219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views in to the scene when returning due 15229f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * to popping a back stack. The entering Views will be those that are regular Views 15239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions 15249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * will extend {@link android.transition.Visibility} as exiting is governed by changing 15259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, 15269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * the views will remain unaffected. If nothing is set, the default will be to use the same 15279f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * transition as {@link #setExitTransition(Object)}. 15289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 15299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views into the scene when reentering from a 15309f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * previously-started Activity. 15319f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 15329f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getReenterTransition() { 15339f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return mReenterTransition == USE_DEFAULT_TRANSITION ? getExitTransition() 15349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount : mReenterTransition; 15359f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 15369f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 15379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 15389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used for shared elements transferred into the content 15399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. Typical Transitions will affect size and location, such as 15409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 15419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 15429f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 15439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use for shared elements transferred into the content 15449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. <code>transition</code> must be an android.transition.Transition. 15459f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 15469f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setSharedElementEnterTransition(Object transition) { 15479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mSharedElementEnterTransition = transition; 15489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 15499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 15509f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 15519f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used for shared elements transferred into the content 15529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. Typical Transitions will affect size and location, such as 15539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 15549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 15559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 15569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return The Transition to use for shared elements transferred into the content 15579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. 15589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 15599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getSharedElementEnterTransition() { 15609f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return mSharedElementEnterTransition; 15619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 15629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 15639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 15649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used for shared elements transferred back during a 15659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * pop of the back stack. This Transition acts in the leaving Fragment. 15669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Typical Transitions will affect size and location, such as 15679f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 15689f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 15699f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * If no value is set, the default will be to use the same value as 15709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link #setSharedElementEnterTransition(Object)}. 15719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 15729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use for shared elements transferred out of the content 15739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. <code>transition</code> must be an android.transition.Transition. 15749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 15759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setSharedElementReturnTransition(Object transition) { 15769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mSharedElementReturnTransition = transition; 15779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 15789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 15799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 15809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Return the Transition that will be used for shared elements transferred back during a 15819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * pop of the back stack. This Transition acts in the leaving Fragment. 15829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Typical Transitions will affect size and location, such as 15839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 15849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 15859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * If no value is set, the default will be to use the same value as 15869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link #setSharedElementEnterTransition(Object)}. 15879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 15889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return The Transition to use for shared elements transferred out of the content 15899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. 15909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 15919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getSharedElementReturnTransition() { 15929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return mSharedElementReturnTransition == USE_DEFAULT_TRANSITION ? 15939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount getSharedElementEnterTransition() : mSharedElementReturnTransition; 15949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 15959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 15969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 15979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets whether the the exit transition and enter transition overlap or not. 15989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the enter transition will start as soon as possible. When false, the 15999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * enter transition will wait until the exit transition completes before starting. 16009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 16019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param allow true to start the enter transition when possible or false to 16029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * wait until the exiting transition completes. 16039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 16049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setAllowEnterTransitionOverlap(boolean allow) { 16059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mAllowEnterTransitionOverlap = allow; 16069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 16079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 16089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 16099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns whether the the exit transition and enter transition overlap or not. 16109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the enter transition will start as soon as possible. When false, the 16119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * enter transition will wait until the exit transition completes before starting. 16129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 16139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return true when the enter transition should start as soon as possible or false to 16149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when it should wait until the exiting transition completes. 16159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 16169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public boolean getAllowEnterTransitionOverlap() { 16179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return (mAllowEnterTransitionOverlap == null) ? true : mAllowEnterTransitionOverlap; 16189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 16199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 16209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 16219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets whether the the return transition and reenter transition overlap or not. 16229f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the reenter transition will start as soon as possible. When false, the 16239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * reenter transition will wait until the return transition completes before starting. 16249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 16259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param allow true to start the reenter transition when possible or false to wait until the 16269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * return transition completes. 16279f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 16289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setAllowReturnTransitionOverlap(boolean allow) { 16299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mAllowReturnTransitionOverlap = allow; 16309f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 16319f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 16329f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 16339f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns whether the the return transition and reenter transition overlap or not. 16349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the reenter transition will start as soon as possible. When false, the 16359f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * reenter transition will wait until the return transition completes before starting. 16369f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 16379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return true to start the reenter transition when possible or false to wait until the 16389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * return transition completes. 16399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 16409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public boolean getAllowReturnTransitionOverlap() { 16419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return (mAllowReturnTransitionOverlap == null) ? true : mAllowReturnTransitionOverlap; 16429f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 16439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 16449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 1645cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Print the Fragments's state into the given stream. 1646cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1647cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param prefix Text to print at the front of each line. 1648cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fd The raw file descriptor that the dump is being sent to. 1649cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param writer The PrintWriter to which you should dump your state. This will be 1650cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * closed for you after you return. 1651cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param args additional arguments to the dump request. 1652cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1653cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { 1654cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mFragmentId=#"); 1655cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(Integer.toHexString(mFragmentId)); 16565506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn writer.print(" mContainerId=#"); 1657cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(Integer.toHexString(mContainerId)); 1658cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mTag="); writer.println(mTag); 1659cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mState="); writer.print(mState); 1660cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mIndex="); writer.print(mIndex); 1661cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mWho="); writer.print(mWho); 1662cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mBackStackNesting="); writer.println(mBackStackNesting); 1663cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mAdded="); writer.print(mAdded); 1664cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mRemoving="); writer.print(mRemoving); 1665cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mResumed="); writer.print(mResumed); 1666cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mFromLayout="); writer.print(mFromLayout); 1667cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mInLayout="); writer.println(mInLayout); 1668cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mHidden="); writer.print(mHidden); 1669e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn writer.print(" mDetached="); writer.print(mDetached); 16702a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn writer.print(" mMenuVisible="); writer.print(mMenuVisible); 1671cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mHasMenu="); writer.println(mHasMenu); 16722a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn writer.print(prefix); writer.print("mRetainInstance="); writer.print(mRetainInstance); 167379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell writer.print(" mRetaining="); writer.print(mRetaining); 167479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell writer.print(" mUserVisibleHint="); writer.println(mUserVisibleHint); 1675cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mFragmentManager != null) { 1676cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mFragmentManager="); 1677cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mFragmentManager); 1678cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1679cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mActivity != null) { 1680cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mActivity="); 1681cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mActivity); 1682cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mParentFragment != null) { 16840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.print(prefix); writer.print("mParentFragment="); 16850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.println(mParentFragment); 16860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 1687cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mArguments != null) { 1688cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mArguments="); writer.println(mArguments); 1689cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1690cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedFragmentState != null) { 1691cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mSavedFragmentState="); 1692cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mSavedFragmentState); 1693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1694cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedViewState != null) { 1695cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mSavedViewState="); 1696cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mSavedViewState); 1697cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1698cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mTarget != null) { 1699cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mTarget="); writer.print(mTarget); 1700cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mTargetRequestCode="); 1701cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mTargetRequestCode); 1702cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mNextAnim != 0) { 1704cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mNextAnim="); writer.println(mNextAnim); 1705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mContainer != null) { 1707cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mContainer="); writer.println(mContainer); 1708cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1709cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mView != null) { 1710cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mView="); writer.println(mView); 1711cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1712cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mInnerView != null) { 1713cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mInnerView="); writer.println(mView); 1714cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1715cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mAnimatingAway != null) { 1716cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mAnimatingAway="); writer.println(mAnimatingAway); 1717cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mStateAfterAnimating="); 1718cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mStateAfterAnimating); 1719cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1720cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoaderManager != null) { 1721cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.println("Loader Manager:"); 1722cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoaderManager.dump(prefix + " ", fd, writer, args); 1723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 17240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 17250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.print(prefix); writer.println("Child " + mChildFragmentManager + ":"); 17260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dump(prefix + " ", fd, writer, args); 17270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 17300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Fragment findFragmentByWho(String who) { 17310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (who.equals(mWho)) { 17320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return this; 17330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 17350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mChildFragmentManager.findFragmentByWho(who); 17360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return null; 17380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 17400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void instantiateChildFragmentManager() { 1741e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes mChildFragmentManager = new FragmentManagerImpl(); 17420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.attachActivity(mActivity, new FragmentContainer() { 17430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn @Override 17440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn public View findViewById(int id) { 17450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mView == null) { 17460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new IllegalStateException("Fragment does not have a view"); 17470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mView.findViewById(id); 17490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17507516316ffdf6fbf7b248c615404831191daa66a4George Mount 17517516316ffdf6fbf7b248c615404831191daa66a4George Mount @Override 17527516316ffdf6fbf7b248c615404831191daa66a4George Mount public boolean hasView() { 17537516316ffdf6fbf7b248c615404831191daa66a4George Mount return (mView != null); 17547516316ffdf6fbf7b248c615404831191daa66a4George Mount } 17550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn }, this); 17560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 17580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performCreate(Bundle savedInstanceState) { 17590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 17600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 17610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 17630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onCreate(savedInstanceState); 17640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 17650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 17660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onCreate()"); 17670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (savedInstanceState != null) { 17690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Parcelable p = savedInstanceState.getParcelable( 17700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn FragmentActivity.FRAGMENTS_TAG); 17710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (p != null) { 17720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager == null) { 17730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn instantiateChildFragmentManager(); 17740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.restoreAllState(p, null); 17760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchCreate(); 17770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 17810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn View performCreateView(LayoutInflater inflater, ViewGroup container, 17820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Bundle savedInstanceState) { 17830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 17840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 17850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return onCreateView(inflater, container, savedInstanceState); 17870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 17890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performActivityCreated(Bundle savedInstanceState) { 17900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 17910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 17920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 17940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onActivityCreated(savedInstanceState); 17950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 17960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 17970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onActivityCreated()"); 17980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 17990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 18000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchActivityCreated(); 18010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 1802cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1803cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 18049c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void performStart() { 18050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 18060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 18070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 18080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 18109c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn onStart(); 18110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 18120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 18130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onStart()"); 18140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 18160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStart(); 18170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18189c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn if (mLoaderManager != null) { 18199c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mLoaderManager.doReportStart(); 18209c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 18219c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 18229c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 18230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performResume() { 18240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 18250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 18260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 18270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 18290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onResume(); 18300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 18310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 18320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onResume()"); 18330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 18350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchResume(); 18360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 18370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 18400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performConfigurationChanged(Configuration newConfig) { 18410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onConfigurationChanged(newConfig); 18420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 18430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchConfigurationChanged(newConfig); 18440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 18470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performLowMemory() { 18480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onLowMemory(); 18490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 18500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchLowMemory(); 18510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 18540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /* 18550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performTrimMemory(int level) { 18560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onTrimMemory(level); 18570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 18580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchTrimMemory(level); 18590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 18620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 18630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performCreateOptionsMenu(Menu menu, MenuInflater inflater) { 18640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean show = false; 18650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 18660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 18670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show = true; 18680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onCreateOptionsMenu(menu, inflater); 18690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 18710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show |= mChildFragmentManager.dispatchCreateOptionsMenu(menu, inflater); 18720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return show; 18750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 18770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performPrepareOptionsMenu(Menu menu) { 18780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean show = false; 18790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 18800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 18810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show = true; 18820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onPrepareOptionsMenu(menu); 18830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 18850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show |= mChildFragmentManager.dispatchPrepareOptionsMenu(menu); 18860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return show; 18890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 18910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performOptionsItemSelected(MenuItem item) { 18920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 18930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 18940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (onOptionsItemSelected(item)) { 18950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 18960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 18980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 18990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager.dispatchOptionsItemSelected(item)) { 19000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 19010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return false; 19050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 19070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performContextItemSelected(MenuItem item) { 19080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 19090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (onContextItemSelected(item)) { 19100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 19110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 19130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager.dispatchContextItemSelected(item)) { 19140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 19150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return false; 19190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 19210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performOptionsMenuClosed(Menu menu) { 19220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 19230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 19240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onOptionsMenuClosed(menu); 19250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 19270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchOptionsMenuClosed(menu); 19280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 19320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performSaveInstanceState(Bundle outState) { 19330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onSaveInstanceState(outState); 19340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 19350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Parcelable p = mChildFragmentManager.saveAllState(); 19360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (p != null) { 19370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn outState.putParcelable(FragmentActivity.FRAGMENTS_TAG, p); 19380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 19420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performPause() { 19430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 19440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchPause(); 19450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 19470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onPause(); 19480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 19490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 19500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onPause()"); 19510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1954cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn void performStop() { 19550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 19560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStop(); 19570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 1959cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn onStop(); 19600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 19610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 19620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onStop()"); 19630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 1964681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn } 1965681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn 1966218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn void performReallyStop() { 19670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 19680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchReallyStop(); 19690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 1970cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoadersStarted) { 1971cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoadersStarted = false; 1972cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!mCheckedForLoaderManager) { 1973cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCheckedForLoaderManager = true; 19740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mLoaderManager = mActivity.getLoaderManager(mWho, mLoadersStarted, false); 1975cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1976cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoaderManager != null) { 1977218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn if (!mActivity.mRetaining) { 1978cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoaderManager.doStop(); 1979cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } else { 1980cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoaderManager.doRetain(); 1981cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1982cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1983cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1984cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 19859c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 19869c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void performDestroyView() { 19870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 19880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchDestroyView(); 19890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 19919c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn onDestroyView(); 19920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 19930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 19940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onDestroyView()"); 19950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19969c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn if (mLoaderManager != null) { 19979c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mLoaderManager.doReportNextStart(); 19989c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 19999c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 20000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 20010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performDestroy() { 20020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 20030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchDestroy(); 20040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 20060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onDestroy(); 20070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 20080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 20090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onDestroy()"); 20100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2012cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn} 2013