1cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/* 2cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Copyright (C) 2011 The Android Open Source Project 3cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 4cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License"); 5cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * you may not use this file except in compliance with the License. 6cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * You may obtain a copy of the License at 7cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 8cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * http://www.apache.org/licenses/LICENSE-2.0 9cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 10cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Unless required by applicable law or agreed to in writing, software 11cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS, 12cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * See the License for the specific language governing permissions and 14cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * limitations under the License. 15cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 16cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 17cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornpackage android.support.v4.app; 18cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 198e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikasimport static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP; 20990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2115e593ea3575512d7072240d1db9d74fad8749a3George Mountimport android.animation.Animator; 22cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.app.Activity; 23cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.ComponentCallbacks; 24cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Context; 25cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Intent; 26fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarriimport android.content.IntentSender; 27cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Configuration; 28cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Resources; 29cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Bundle; 30990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mountimport android.os.Looper; 31cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcel; 32cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcelable; 33916455675ddb34d0eb848b2355550268d82c3ce7Adam Powellimport android.support.annotation.CallSuper; 34e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslavimport android.support.annotation.NonNull; 35a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbyeimport android.support.annotation.Nullable; 36c39d9c75590eca86a5e7e32a8824ba04a0d42e9bAlan Viveretteimport android.support.annotation.RestrictTo; 37a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbyeimport android.support.annotation.StringRes; 38cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.support.v4.util.DebugUtils; 399562a3b639225d406d736b64a12e2d75459259e3Alan Viveretteimport android.support.v4.util.SimpleArrayMap; 40bf0947be2ead9b3d8e5865bcd3d3652d02a2aa5aChris Banesimport android.support.v4.view.LayoutInflaterCompat; 41cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.AttributeSet; 42be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackbornimport android.util.Log; 43cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.SparseArray; 44cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ContextMenu; 459562a3b639225d406d736b64a12e2d75459259e3Alan Viveretteimport android.view.ContextMenu.ContextMenuInfo; 46cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.LayoutInflater; 47cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.Menu; 48cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuInflater; 49cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuItem; 50cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View; 51cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View.OnCreateContextMenuListener; 529562a3b639225d406d736b64a12e2d75459259e3Alan Viveretteimport android.view.ViewGroup; 53cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.animation.Animation; 54cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.widget.AdapterView; 55cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 56cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.FileDescriptor; 57cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.PrintWriter; 58b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikasimport java.lang.reflect.InvocationTargetException; 59cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 60cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornfinal class FragmentState implements Parcelable { 61cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final String mClassName; 62cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int mIndex; 63cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final boolean mFromLayout; 64cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int mFragmentId; 65cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int mContainerId; 66cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final String mTag; 67cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final boolean mRetainInstance; 68e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn final boolean mDetached; 69cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final Bundle mArguments; 70340a183c3293d98842e4a2671b500e8e80258818Todd Kennedy final boolean mHidden; 714bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 72cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Bundle mSavedFragmentState; 734bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 74cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment mInstance; 75c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell 76cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentState(Fragment frag) { 77cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mClassName = frag.getClass().getName(); 78cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = frag.mIndex; 79cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mFromLayout = frag.mFromLayout; 80cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mFragmentId = frag.mFragmentId; 81cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mContainerId = frag.mContainerId; 82cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTag = frag.mTag; 83cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mRetainInstance = frag.mRetainInstance; 84e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn mDetached = frag.mDetached; 85cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mArguments = frag.mArguments; 86340a183c3293d98842e4a2671b500e8e80258818Todd Kennedy mHidden = frag.mHidden; 87cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 884bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 89cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentState(Parcel in) { 90cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mClassName = in.readString(); 91cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = in.readInt(); 92cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mFromLayout = in.readInt() != 0; 93cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mFragmentId = in.readInt(); 94cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mContainerId = in.readInt(); 95cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTag = in.readString(); 96cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mRetainInstance = in.readInt() != 0; 97e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn mDetached = in.readInt() != 0; 98cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mArguments = in.readBundle(); 99340a183c3293d98842e4a2671b500e8e80258818Todd Kennedy mHidden = in.readInt() != 0; 100cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mSavedFragmentState = in.readBundle(); 101cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 102d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1034aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell public Fragment instantiate(FragmentHostCallback host, FragmentContainer container, 1044aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell Fragment parent, FragmentManagerNonConfig childNonConfig) { 105c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell if (mInstance == null) { 106c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell final Context context = host.getContext(); 107c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell if (mArguments != null) { 108c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mArguments.setClassLoader(context.getClassLoader()); 109c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell } 110d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1114aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell if (container != null) { 1124aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell mInstance = container.instantiate(context, mClassName, mArguments); 1134aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell } else { 1144aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell mInstance = Fragment.instantiate(context, mClassName, mArguments); 1154aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell } 116d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 117c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell if (mSavedFragmentState != null) { 118c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mSavedFragmentState.setClassLoader(context.getClassLoader()); 119c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mInstance.mSavedFragmentState = mSavedFragmentState; 120c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell } 121c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mInstance.setIndex(mIndex, parent); 122c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mInstance.mFromLayout = mFromLayout; 123c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mInstance.mRestored = true; 124c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mInstance.mFragmentId = mFragmentId; 125c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mInstance.mContainerId = mContainerId; 126c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mInstance.mTag = mTag; 127c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mInstance.mRetainInstance = mRetainInstance; 128c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mInstance.mDetached = mDetached; 129c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mInstance.mHidden = mHidden; 130c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mInstance.mFragmentManager = host.mFragmentManager; 131c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell 132c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell if (FragmentManagerImpl.DEBUG) Log.v(FragmentManagerImpl.TAG, 133c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell "Instantiated fragment " + mInstance); 134cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 135c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mInstance.mChildNonConfig = childNonConfig; 136cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mInstance; 137cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 138d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 13990ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas @Override 140cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public int describeContents() { 141cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return 0; 142cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 143cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 14490ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas @Override 145cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void writeToParcel(Parcel dest, int flags) { 146cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeString(mClassName); 147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mIndex); 148cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mFromLayout ? 1 : 0); 149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mFragmentId); 150cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mContainerId); 151cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeString(mTag); 152cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mRetainInstance ? 1 : 0); 153e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn dest.writeInt(mDetached ? 1 : 0); 154cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeBundle(mArguments); 155340a183c3293d98842e4a2671b500e8e80258818Todd Kennedy dest.writeInt(mHidden? 1 : 0); 156cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeBundle(mSavedFragmentState); 157cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1584bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 159cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public static final Parcelable.Creator<FragmentState> CREATOR 160cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn = new Parcelable.Creator<FragmentState>() { 16190ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas @Override 162cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentState createFromParcel(Parcel in) { 163cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return new FragmentState(in); 164cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16590ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas 16690ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas @Override 167cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentState[] newArray(int size) { 168cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return new FragmentState[size]; 169cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 170cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn }; 171cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn} 172cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/** 174cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Static library support version of the framework's {@link android.app.Fragment}. 175cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Used to write apps that run on platforms prior to Android 3.0. When running 176cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on Android 3.0 or above, this implementation is still used; it does not try 1779dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * to switch to the framework's implementation. See the framework {@link android.app.Fragment} 178cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * documentation for a class overview. 1799dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * 1809dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <p>The main differences when using this support version instead of the framework version are: 1819dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <ul> 1829dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <li>Your activity must extend {@link FragmentActivity} 1839dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <li>You must call {@link FragmentActivity#getSupportFragmentManager} to get the 1849dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * {@link FragmentManager} 1859dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * </ul> 1869dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * 187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 188cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornpublic class Fragment implements ComponentCallbacks, OnCreateContextMenuListener { 1892290993eddf5262a8df7fc9478daed52401e325aDianne Hackborn private static final SimpleArrayMap<String, Class<?>> sClassMap = 1902290993eddf5262a8df7fc9478daed52401e325aDianne Hackborn new SimpleArrayMap<String, Class<?>>(); 1919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 1929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount static final Object USE_DEFAULT_TRANSITION = new Object(); 1939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 194cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int INITIALIZING = 0; // Not yet created. 195cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int CREATED = 1; // Created. 196cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int ACTIVITY_CREATED = 2; // The activity has finished its creation. 197e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn static final int STOPPED = 3; // Fully created, not started. 198e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn static final int STARTED = 4; // Created and started, not resumed. 199e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn static final int RESUMED = 5; // Created started and resumed. 2004bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mState = INITIALIZING; 2024bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // When instantiated from saved state, this is the saved state. 204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Bundle mSavedFragmentState; 205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn SparseArray<Parcelable> mSavedViewState; 2064bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 207cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Index into active fragment array. 208cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mIndex = -1; 2094bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 210cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Internal unique name for this fragment; 211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn String mWho; 2124bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 213cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Construction arguments; 214cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Bundle mArguments; 215cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Target fragment. 217cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment mTarget; 218cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 2192c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn // For use when retaining a fragment: this is the index of the last mTarget. 2202c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn int mTargetIndex = -1; 2212c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn 222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Target request code. 223cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mTargetRequestCode; 224cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 225cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // True if the fragment is in the list of added fragments. 226cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mAdded; 2274bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 228cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment is being removed from its activity. 229cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRemoving; 2304bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 231cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true if this fragment was instantiated from a layout file. 232cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mFromLayout; 2334bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 234cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true when the view has actually been inflated in its layout. 235cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mInLayout; 236cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 237cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // True if this fragment has been restored from previously saved state. 238cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRestored; 239d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 24037149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell // True if performCreateView has been called and a matching call to performDestroyView 24137149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell // has not yet happened. 24237149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell boolean mPerformedCreateView; 24337149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell 244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Number of active back stack entries this fragment is in. 245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mBackStackNesting; 246d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The fragment manager we are associated with. Set as soon as the 248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // fragment is used in a transaction; cleared after it has been removed 249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // from all transactions. 250abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell FragmentManagerImpl mFragmentManager; 251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 252d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy // Host this fragment is attached to. 2538491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy FragmentHostCallback mHost; 2540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 2550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn // Private fragment manager for child fragments inside of this one. 2560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn FragmentManagerImpl mChildFragmentManager; 2570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 258c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell // For use when restoring fragment state and descendant fragments are retained. 259c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell // This state is set by FragmentState.instantiate and cleared in onCreate. 260c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell FragmentManagerNonConfig mChildNonConfig; 261c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell 2620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn // If this Fragment is contained in another Fragment, this is that container. 2630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Fragment mParentFragment; 2640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 265cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The optional identifier for this fragment -- either the container ID if it 266cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // was dynamically added to the view hierarchy, or the ID supplied in 267cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // layout. 268cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mFragmentId; 2694bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 270cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // When a fragment is being dynamically added to the view hierarchy, this 271cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // is the identifier of the parent container it is being added to. 272cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mContainerId; 2734bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 274cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The optional named tag for this fragment -- usually used to find 275cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // fragments that are not part of the layout. 276cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn String mTag; 2774bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 278cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true when the app has requested that this fragment be hidden 279cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // from the user. 280cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mHidden; 2814bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 282e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn // Set to true when the app has requested that this fragment be deactivated. 283e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn boolean mDetached; 284e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 285cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment would like its instance retained across 286cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // configuration changes. 287cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRetainInstance; 2882bdd09a243b422960168170e2344274cc9cfd788Todd Kennedy 289cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment is being retained across the current config change. 290cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRetaining; 2914bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 292cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment has menu items to contribute. 293cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mHasMenu; 2942a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 2952a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn // Set to true to allow the fragment's menu to be shown. 2962a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn boolean mMenuVisible = true; 2972a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 298cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Used to verify that subclasses call through to super class. 299cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mCalled; 3004bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 301cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The parent container of the fragment after dynamically added to UI. 302cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn ViewGroup mContainer; 3034bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 304cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The View generated for this fragment. 305cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn View mView; 3064bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 307cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The real inner view that will save/restore state. 308cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn View mInnerView; 309abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 310abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell // Whether this fragment should defer starting until after other fragments 311abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell // have been started and their loaders are finished. 312abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell boolean mDeferStart; 3134bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 31479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell // Hint provided by the app that this fragment is currently visible to the user. 31579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell boolean mUserVisibleHint = true; 316abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 317cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn LoaderManagerImpl mLoaderManager; 318cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mLoadersStarted; 319cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mCheckedForLoaderManager; 3209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 321990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // The animation and transition information for the fragment. This will be null 322990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // unless the elements are explicitly accessed and should remain null for Fragments 323990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // without Views. 324990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount AnimationInfo mAnimationInfo; 3259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 326990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // True if the View was added, and its animation has yet to be run. This could 327990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // also indicate that the fragment view hasn't been made visible, even if there is no 328990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // animation for this fragment. 329990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount boolean mIsNewlyAdded; 330990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 331990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // True if mHidden has been changed and the animation should be scheduled. 332990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount boolean mHiddenChanged; 3339f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 3340bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount // The alpha of the view when the view was added and then postponed. If the value is less 3350bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount // than zero, this means that the view's add was canceled and should not participate in 3360bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount // removal animations. 3370bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount float mPostponedAlpha; 3380bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount 3398b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount // The cached value from onGetLayoutInflater(Bundle) that will be returned from 3408b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount // getLayoutInflater() 3418b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount LayoutInflater mLayoutInflater; 3428b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount 343cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 3445c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * State information that has been retrieved from a fragment instance 3455c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * through {@link FragmentManager#saveFragmentInstanceState(Fragment) 3465c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * FragmentManager.saveFragmentInstanceState}. 3475c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 3485c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public static class SavedState implements Parcelable { 3495c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn final Bundle mState; 3505c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3515c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn SavedState(Bundle state) { 3525c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState = state; 3535c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3545c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3555c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn SavedState(Parcel in, ClassLoader loader) { 3565c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState = in.readBundle(); 3575c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn if (loader != null && mState != null) { 3585c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState.setClassLoader(loader); 3595c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3605c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3615c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3625c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn @Override 3635c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public int describeContents() { 3645c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return 0; 3655c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3665c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3675c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn @Override 3685c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public void writeToParcel(Parcel dest, int flags) { 3695c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn dest.writeBundle(mState); 3705c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3715c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3725c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public static final Parcelable.Creator<SavedState> CREATOR 3735c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn = new Parcelable.Creator<SavedState>() { 374d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Override 3755c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public SavedState createFromParcel(Parcel in) { 3765c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return new SavedState(in, null); 3775c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3785c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 379d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Override 3805c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public SavedState[] newArray(int size) { 3815c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return new SavedState[size]; 3825c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3835c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn }; 3845c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3855c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3865c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when 388cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * there is an instantiation failure. 389cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 390cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static public class InstantiationException extends RuntimeException { 391cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public InstantiationException(String msg, Exception cause) { 392cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn super(msg, cause); 393cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 394cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 395cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 396cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 397cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Default constructor. <strong>Every</strong> fragment must have an 398cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * empty constructor, so it can be instantiated when restoring its 399cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * activity's state. It is strongly recommended that subclasses do not 400cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * have other constructors with parameters, since these constructors 401cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * will not be called when the fragment is re-instantiated; instead, 402cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * arguments can be supplied by the caller with {@link #setArguments} 403cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * and later retrieved by the Fragment with {@link #getArguments}. 4044bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 40504f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * <p>Applications should generally not implement a constructor. Prefer 40604f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * {@link #onAttach(Context)} instead. It is the first place application code can run where 40704f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * the fragment is ready to be used - the point where the fragment is actually associated with 40804f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * its context. Some applications may also want to implement {@link #onInflate} to retrieve 40904f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * attributes from a layout resource, although note this happens when the fragment is attached. 410cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 411cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public Fragment() { 412cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 413cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 414cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 415cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Like {@link #instantiate(Context, String, Bundle)} but with a null 416cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * argument Bundle. 417cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 418cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public static Fragment instantiate(Context context, String fname) { 419cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return instantiate(context, fname, null); 420cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 421cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 422cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 423cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Create a new instance of a Fragment with the given class name. This is 424cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the same as calling its empty constructor. 425cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 426cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param context The calling context being used to instantiate the fragment. 427cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is currently just used to get its ClassLoader. 428cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fname The class name of the fragment to instantiate. 429cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param args Bundle of arguments to supply to the fragment, which it 430cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can retrieve with {@link #getArguments()}. May be null. 431cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return Returns a new fragment instance. 432cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @throws InstantiationException If there is a failure in instantiating 433cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the given fragment class. This is a runtime exception; it is not 434cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * normally expected to happen. 435cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 436c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy public static Fragment instantiate(Context context, String fname, @Nullable Bundle args) { 437cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn try { 438cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Class<?> clazz = sClassMap.get(fname); 439cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (clazz == null) { 440cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Class not found in the cache, see if it's real, and try to add it 441cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn clazz = context.getClassLoader().loadClass(fname); 442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sClassMap.put(fname, clazz); 443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 444b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas Fragment f = (Fragment) clazz.getConstructor().newInstance(); 445cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (args != null) { 446cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn args.setClassLoader(f.getClass().getClassLoader()); 44737149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell f.setArguments(args); 448cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return f; 450cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (ClassNotFoundException e) { 451cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 452cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 453cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (java.lang.InstantiationException e) { 455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 456cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 457cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 458cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (IllegalAccessException e) { 459cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 460cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 461cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 462b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas } catch (NoSuchMethodException e) { 463b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas throw new InstantiationException("Unable to instantiate fragment " + fname 464b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas + ": could not find Fragment constructor", e); 465b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas } catch (InvocationTargetException e) { 466b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas throw new InstantiationException("Unable to instantiate fragment " + fname 467b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas + ": calling Fragment constructor caused an exception", e); 468cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 469cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4703fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell 4713fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell /** 4723fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * Determine if the given fragment name is a support library fragment class. 4733fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * 4743fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * @param context Context used to determine the correct ClassLoader to use 4753fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * @param fname Class name of the fragment to test 4763fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * @return true if <code>fname</code> is <code>android.support.v4.app.Fragment</code> 4773fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * or a subclass, false otherwise. 4783fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell */ 4793fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell static boolean isSupportFragmentClass(Context context, String fname) { 4803fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell try { 4813fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell Class<?> clazz = sClassMap.get(fname); 4823fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell if (clazz == null) { 4833fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell // Class not found in the cache, see if it's real, and try to add it 4843fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell clazz = context.getClassLoader().loadClass(fname); 4853fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell sClassMap.put(fname, clazz); 4863fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 4873fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell return Fragment.class.isAssignableFrom(clazz); 4883fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } catch (ClassNotFoundException e) { 4893fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell return false; 4903fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 4913fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 4924bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 4930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final void restoreViewState(Bundle savedInstanceState) { 494cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedViewState != null) { 495cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInnerView.restoreHierarchyState(mSavedViewState); 496cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mSavedViewState = null; 497cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 4990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onViewStateRestored(savedInstanceState); 5000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 5010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 5020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onViewStateRestored()"); 5030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 504cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 5050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 5060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final void setIndex(int index, Fragment parent) { 507cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = index; 5080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (parent != null) { 5090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mWho = parent.mWho + ":" + mIndex; 5100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else { 5110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mWho = "android:fragment:" + mIndex; 5120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 513e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 5140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 515e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn final boolean isInBackStack() { 516e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn return mBackStackNesting > 0; 517e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 518e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 519cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 520cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Subclasses can not override equals(). 521cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 522cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override final public boolean equals(Object o) { 523cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return super.equals(o); 524cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 525cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 526cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 527cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Subclasses can not override hashCode(). 528cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 529cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override final public int hashCode() { 530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return super.hashCode(); 531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 5324bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 533cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override 534cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public String toString() { 535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn StringBuilder sb = new StringBuilder(128); 536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn DebugUtils.buildShortClassTag(this, sb); 537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mIndex >= 0) { 538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" #"); 539cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(mIndex); 540cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mFragmentId != 0) { 542cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" id=0x"); 543cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(Integer.toHexString(mFragmentId)); 544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mTag != null) { 546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" "); 547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(mTag); 548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append('}'); 550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return sb.toString(); 551cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 5524bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the identifier this fragment is known by. This is either 555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the android:id value supplied in a layout or the container view ID 556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * supplied when adding the fragment. 557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 558cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public int getId() { 559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mFragmentId; 560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 5614bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 562cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 563cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Get the tag name of the fragment, if specified. 564cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 565cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public String getTag() { 566cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTag; 567cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 5684bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 569cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 5705e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * Supply the construction arguments for this fragment. 5715e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * The arguments supplied here will be retained across fragment destroy and 572cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * creation. 5735e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * <p>This method cannot be called if the fragment is added to a FragmentManager and 5745e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * if {@link #isStateSaved()} would return true.</p> 575cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 576cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setArguments(Bundle args) { 5775e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell if (mIndex >= 0 && isStateSaved()) { 5785e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell throw new IllegalStateException("Fragment already active and state has been saved"); 579cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 580cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mArguments = args; 581cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 582cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 583cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 584cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the arguments supplied when the fragment was instantiated, 585cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if any. 586cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 587cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public Bundle getArguments() { 588cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mArguments; 589cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 590cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 591cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 5925e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * Returns true if this fragment is added and its state has already been saved 5935e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * by its host. Any operations that would change saved state should not be performed 5945e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * if this method returns true, and some operations such as {@link #setArguments(Bundle)} 5955e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * will fail. 5965e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * 5975e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * @return true if this fragment's state has already been saved by its host 5985e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell */ 5995e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell public final boolean isStateSaved() { 6005e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell if (mFragmentManager == null) { 6015e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell return false; 6025e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell } 6035e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell return mFragmentManager.isStateSaved(); 6045e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell } 6055e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell 6065e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell /** 6075c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Set the initial saved state that this Fragment should restore itself 6085c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * from when first being constructed, as returned by 6095c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * {@link FragmentManager#saveFragmentInstanceState(Fragment) 6105c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * FragmentManager.saveFragmentInstanceState}. 6115c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * 6125c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param state The state the fragment should be restored from. 6135c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 6145c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public void setInitialSavedState(SavedState state) { 6155c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn if (mIndex >= 0) { 6165c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn throw new IllegalStateException("Fragment already active"); 6175c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 6185c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mSavedFragmentState = state != null && state.mState != null 6195c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn ? state.mState : null; 6205c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 6215c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 6225c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 623cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Optional target for this fragment. This may be used, for example, 624cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if this fragment is being started by another, and when done wants to 625cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * give a result back to the first. The target set here is retained 626cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * across instances via {@link FragmentManager#putFragment 627cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * FragmentManager.putFragment()}. 628cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 629cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fragment The fragment that is the target of this one. 630cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param requestCode Optional request code, for convenience if you 631cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * are going to call back with {@link #onActivityResult(int, int, Intent)}. 632cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 633b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas @SuppressWarnings("ReferenceEquality") 634cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setTargetFragment(Fragment fragment, int requestCode) { 635a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // Don't allow a caller to set a target fragment in another FragmentManager, 636a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // but there's a snag: people do set target fragments before fragments get added. 637a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // We'll have the FragmentManager check that for validity when we move 638a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // the fragments to a valid state. 639a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell final FragmentManager mine = getFragmentManager(); 6402ab15df66963610bc02cb30e9a459f2b49c2ccfaAdam Powell final FragmentManager theirs = fragment != null ? fragment.getFragmentManager() : null; 641a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell if (mine != null && theirs != null && mine != theirs) { 642a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell throw new IllegalArgumentException("Fragment " + fragment 643a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell + " must share the same FragmentManager to be set as a target fragment"); 644a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell } 645a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell 646a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // Don't let someone create a cycle. 647a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell for (Fragment check = fragment; check != null; check = check.getTargetFragment()) { 648a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell if (check == this) { 649a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell throw new IllegalArgumentException("Setting " + fragment + " as the target of " 650a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell + this + " would create a target cycle"); 651a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell } 652a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell } 653cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTarget = fragment; 654cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTargetRequestCode = requestCode; 655cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 656cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 657cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 658cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the target fragment set by {@link #setTargetFragment}. 659cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 660cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public Fragment getTargetFragment() { 661cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTarget; 662cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 663cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 664cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 665cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the target request code set by {@link #setTargetFragment}. 666cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 667cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public int getTargetRequestCode() { 668cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTargetRequestCode; 669cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 670cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 671cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 672d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Return the {@link Context} this fragment is currently associated with. 673d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy */ 674edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy public Context getContext() { 675d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy return mHost == null ? null : mHost.getContext(); 676d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 677d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 678d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy /** 679d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Return the {@link FragmentActivity} this fragment is currently associated with. 680d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * May return {@code null} if the fragment is associated with a {@link Context} 681d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * instead. 682cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 683cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public FragmentActivity getActivity() { 684d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy return mHost == null ? null : (FragmentActivity) mHost.getActivity(); 685cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 686d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 687cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 688edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy * Return the host object of this fragment. May return {@code null} if the fragment 689edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy * isn't currently being hosted. 690edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy */ 691edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy final public Object getHost() { 6928491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy return mHost == null ? null : mHost.onGetHost(); 693edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy } 694edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy 695edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy /** 696cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return <code>getActivity().getResources()</code>. 697cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 698cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public Resources getResources() { 699d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost == null) { 700cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 701cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 702d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy return mHost.getContext().getResources(); 703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 704d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized, styled CharSequence from the application's package's 707cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table. 708cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 709cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the CharSequence text 710cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 711a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final CharSequence getText(@StringRes int resId) { 712cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getText(resId); 713cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 714cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 715cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 716cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized string from the application's package's 717cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table. 718cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 719cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the string 720cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 721a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final String getString(@StringRes int resId) { 722cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getString(resId); 723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 724cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 725cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 726cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized formatted string from the application's package's 727cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table, substituting the format arguments as defined in 728cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link java.util.Formatter} and {@link java.lang.String#format}. 729cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 730cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the format string 731cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param formatArgs The format arguments that will be used for substitution. 732cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 733cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 734a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final String getString(@StringRes int resId, Object... formatArgs) { 735cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getString(resId, formatArgs); 736cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 737cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 738cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 739cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the FragmentManager for interacting with fragments associated 740cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * with this fragment's activity. Note that this will be non-null slightly 741cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * before {@link #getActivity()}, during the time from when the fragment is 742cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * placed in a {@link FragmentTransaction} until it is committed and 743cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * attached to its activity. 7440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 7450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * <p>If this Fragment is a child of another Fragment, the FragmentManager 7460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * returned here will be the parent's {@link #getChildFragmentManager()}. 747cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 748cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public FragmentManager getFragmentManager() { 749cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mFragmentManager; 750cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 751cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 752cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 7530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Return a private FragmentManager for placing and managing Fragments 7540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * inside of this Fragment. 7550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 7560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final public FragmentManager getChildFragmentManager() { 7570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager == null) { 7580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn instantiateChildFragmentManager(); 7590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mState >= RESUMED) { 7600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchResume(); 7610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= STARTED) { 7620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStart(); 7630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= ACTIVITY_CREATED) { 7640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchActivityCreated(); 7650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= CREATED) { 7660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchCreate(); 7670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 7680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 7690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mChildFragmentManager; 7700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 7710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 7720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 773267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell * Return this fragment's child FragmentManager one has been previously created, 774267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell * otherwise null. 775267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell */ 776267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell FragmentManager peekChildFragmentManager() { 777267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell return mChildFragmentManager; 778267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell } 779267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell 780267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell /** 7810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Returns the parent Fragment containing this Fragment. If this Fragment 7820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * is attached directly to an Activity, returns null. 7830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 7840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final public Fragment getParentFragment() { 7850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mParentFragment; 7860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 7870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 7880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 789cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is currently added to its activity. 790cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 791cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isAdded() { 792d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy return mHost != null && mAdded; 793cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 794cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 795cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 7969c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * Return true if the fragment has been explicitly detached from the UI. 7979c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * That is, {@link FragmentTransaction#detach(Fragment) 7989c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * FragmentTransaction.detach(Fragment)} has been used on it. 7999c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn */ 8009c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn final public boolean isDetached() { 8019c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn return mDetached; 8029c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 8039c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 8049c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn /** 805cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if this fragment is currently being removed from its 806cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * activity. This is <em>not</em> whether its activity is finishing, but 807cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * rather whether it is in the process of being removed from its activity. 808cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 809cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isRemoving() { 810cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mRemoving; 811cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8124bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 813cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 814cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the layout is included as part of an activity view 815cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * hierarchy via the <fragment> tag. This will always be true when 816cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * fragments are created through the <fragment> tag, <em>except</em> 817cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * in the case where an old fragment is restored from a previous state and 818cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * it does not appear in the layout of the current state. 819cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 820cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isInLayout() { 821cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mInLayout; 822cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 823cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 824cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 825cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is in the resumed state. This is true 826cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for the duration of {@link #onResume()} and {@link #onPause()} as well. 827cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 828cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isResumed() { 82920735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell return mState >= RESUMED; 830cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8314bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 832cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 833cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is currently visible to the user. This means 8344bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * it: (1) has been added, (2) has its view attached to the window, and 835cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * (3) is not hidden. 836cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 837cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isVisible() { 838cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return isAdded() && !isHidden() && mView != null 839cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE; 840cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8414bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 842cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 843cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment has been hidden. By default fragments 844cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * are shown. You can find out about changes to this state with 845cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onHiddenChanged}. Note that the hidden state is orthogonal 846cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to other states -- that is, to be visible to the user, a fragment 847cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * must be both started and not hidden. 848cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 849cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isHidden() { 850cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mHidden; 851cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8523a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 8533a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown /** @hide */ 8548e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas @RestrictTo(LIBRARY_GROUP) 8553a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown final public boolean hasOptionsMenu() { 8563a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown return mHasMenu; 8573a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown } 8583a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 8593a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown /** @hide */ 8608e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas @RestrictTo(LIBRARY_GROUP) 8613a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown final public boolean isMenuVisible() { 8623a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown return mMenuVisible; 8633a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown } 8643a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 865cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 866cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the hidden state (as returned by {@link #isHidden()} of 867cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the fragment has changed. Fragments start out not hidden; this will 868cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * be called whenever the fragment changes state from that. 869527415d706bf580ff2bb7b492e5202b985cfa2c7Aurimas Liutikas * @param hidden True if the fragment is now hidden, false otherwise. 870cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 871cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onHiddenChanged(boolean hidden) { 872cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8734bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 874cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 875cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Control whether a fragment instance is retained across Activity 876cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * re-creation (such as from a configuration change). This can only 877cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * be used with fragments not in the back stack. If set, the fragment 878cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * lifecycle will be slightly different when an activity is recreated: 879cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <ul> 880cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still 881cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * will be, because the fragment is being detached from its current activity). 882cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onCreate(Bundle)} will not be called since the fragment 883cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is not being re-created. 884cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b> 885cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * still be called. 886cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * </ul> 887cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 888cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setRetainInstance(boolean retain) { 889cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mRetainInstance = retain; 890cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8914bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 892cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean getRetainInstance() { 893cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mRetainInstance; 894cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8954bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 896cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 897cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Report that this fragment would like to participate in populating 898cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the options menu by receiving a call to {@link #onCreateOptionsMenu} 899cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * and related methods. 900d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * 901cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param hasMenu If true, the fragment has menu items to contribute. 902cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 903cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setHasOptionsMenu(boolean hasMenu) { 904cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mHasMenu != hasMenu) { 905cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mHasMenu = hasMenu; 906cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (isAdded() && !isHidden()) { 9078491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy mHost.onSupportInvalidateOptionsMenu(); 908cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 909cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 910cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9112a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 9122a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn /** 9132a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * Set a hint for whether this fragment's menu should be visible. This 9142a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * is useful if you know that a fragment has been placed in your view 9152a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * hierarchy so that the user can not currently seen it, so any menu items 9162a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * it has should also not be shown. 9172a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * 9182a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * @param menuVisible The default is true, meaning the fragment's menu will 9192a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * be shown as usual. If false, the user will not see the menu. 9202a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn */ 9212a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn public void setMenuVisibility(boolean menuVisible) { 9222a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn if (mMenuVisible != menuVisible) { 9232a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn mMenuVisible = menuVisible; 9242a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn if (mHasMenu && isAdded() && !isHidden()) { 9258491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy mHost.onSupportInvalidateOptionsMenu(); 9262a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 9272a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 9282a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 9292a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 930cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 93179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * Set a hint to the system about whether this fragment's UI is currently visible 93279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * to the user. This hint defaults to true and is persistent across fragment instance 93379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * state save and restore. 934abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell * 93579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * <p>An app may set this to false to indicate that the fragment's UI is 93679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * scrolled out of visibility or is otherwise not directly visible to the user. 93779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * This may be used by the system to prioritize operations such as fragment lifecycle updates 93879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * or loader ordering behavior.</p> 939abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell * 9400244762c99db7b1fb6c4905bc1224fefac927014Adam Powell * <p><strong>Note:</strong> This method may be called outside of the fragment lifecycle. 9410244762c99db7b1fb6c4905bc1224fefac927014Adam Powell * and thus has no ordering guarantees with regard to fragment lifecycle method calls.</p> 9420244762c99db7b1fb6c4905bc1224fefac927014Adam Powell * 94379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @param isVisibleToUser true if this fragment's UI is currently visible to the user (default), 94479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * false if it is not. 945abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell */ 94679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell public void setUserVisibleHint(boolean isVisibleToUser) { 9473ab5a96f51cbd0498a62f1e91f1ef99e95cb1b1cAdam Powell if (!mUserVisibleHint && isVisibleToUser && mState < STARTED 9483ab5a96f51cbd0498a62f1e91f1ef99e95cb1b1cAdam Powell && mFragmentManager != null && isAdded()) { 949abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell mFragmentManager.performPendingDeferredStart(this); 950abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 95179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell mUserVisibleHint = isVisibleToUser; 952c83dccecb0ec4bf9f4befdb18caccb8f373ed7bcAdam Powell mDeferStart = mState < STARTED && !isVisibleToUser; 953abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 954abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 955abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell /** 95679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @return The current value of the user-visible hint on this fragment. 95779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @see #setUserVisibleHint(boolean) 958abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell */ 95979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell public boolean getUserVisibleHint() { 96079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell return mUserVisibleHint; 961abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 962abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 963abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell /** 964cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the LoaderManager for this fragment, creating it if needed. 965cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 966cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public LoaderManager getLoaderManager() { 967cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoaderManager != null) { 968cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mLoaderManager; 969cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 970d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost == null) { 971cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 972cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 973cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCheckedForLoaderManager = true; 974d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, true); 975cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mLoaderManager; 976cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 977d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 978cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 9798491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy * Call {@link Activity#startActivity(Intent)} from the fragment's 980cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * containing Activity. 981cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 982cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void startActivity(Intent intent) { 9830e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick startActivity(intent, null); 9840e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick } 9850e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick 9860e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick /** 9870e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick * Call {@link Activity#startActivity(Intent, Bundle)} from the fragment's 9880e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick * containing Activity. 9890e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick */ 9900e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick public void startActivity(Intent intent, @Nullable Bundle options) { 991d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost == null) { 992cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 993cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9940e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick mHost.onStartActivityFromFragment(this /*fragment*/, intent, -1, options); 995cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 996d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 997cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 9988491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy * Call {@link Activity#startActivityForResult(Intent, int)} from the fragment's 999cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * containing Activity. 1000cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1001cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void startActivityForResult(Intent intent, int requestCode) { 10020e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick startActivityForResult(intent, requestCode, null); 10030e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick } 10040e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick 10050e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick /** 10060e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick * Call {@link Activity#startActivityForResult(Intent, int, Bundle)} from the fragment's 10070e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick * containing Activity. 10080e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick */ 10090e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick public void startActivityForResult(Intent intent, int requestCode, @Nullable Bundle options) { 1010d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost == null) { 1011cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 1012cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 10130e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick mHost.onStartActivityFromFragment(this /*fragment*/, intent, requestCode, options); 1014fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri } 1015fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri 1016fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri /** 1017fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri * Call {@link Activity#startIntentSenderForResult(IntentSender, int, Intent, int, int, int, 1018fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri * Bundle)} from the fragment's containing Activity. 1019fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri */ 1020fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri public void startIntentSenderForResult(IntentSender intent, int requestCode, 1021fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, 1022fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri Bundle options) throws IntentSender.SendIntentException { 1023fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri if (mHost == null) { 1024fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 1025fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri } 1026fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri mHost.onStartIntentSenderFromFragment(this, intent, requestCode, fillInIntent, flagsMask, 1027fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri flagsValues, extraFlags, options); 1028cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1029d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1030cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1031cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Receive the result from a previous call to 1032cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #startActivityForResult(Intent, int)}. This follows the 1033cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * related Activity API as described there in 1034cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onActivityResult(int, int, Intent)}. 1035d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * 1036cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param requestCode The integer request code originally supplied to 1037cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * startActivityForResult(), allowing you to identify who this 1038cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * result came from. 1039cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resultCode The integer result code returned by the child activity 1040cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * through its setResult(). 1041cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param data An Intent, which can return result data to the caller 1042cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * (various data can be attached to Intent "extras"). 1043cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1044cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onActivityResult(int requestCode, int resultCode, Intent data) { 1045cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1046d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1047cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1048e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Requests permissions to be granted to this application. These permissions 1049e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * must be requested in your manifest, they should not be granted to your app, 1050e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * and they should have protection level {@link android.content.pm.PermissionInfo 1051e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * #PROTECTION_DANGEROUS dangerous}, regardless whether they are declared by 1052e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * the platform or a third-party app. 1053e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1054e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Normal permissions {@link android.content.pm.PermissionInfo#PROTECTION_NORMAL} 1055e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * are granted at install time if requested in the manifest. Signature permissions 1056e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * {@link android.content.pm.PermissionInfo#PROTECTION_SIGNATURE} are granted at 1057e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * install time if requested in the manifest and the signature of your app matches 1058e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * the signature of the app declaring the permissions. 1059e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1060e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1061e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * If your app does not have the requested permissions the user will be presented 1062e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * with UI for accepting them. After the user has accepted or rejected the 1063e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * requested permissions you will receive a callback on {@link 1064e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * #onRequestPermissionsResult(int, String[], int[])} reporting whether the 1065e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * permissions were granted or not. 1066e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1067e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1068e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Note that requesting a permission does not guarantee it will be granted and 1069e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * your app should be able to run without having this permission. 1070e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1071e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1072e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * This method may start an activity allowing the user to choose which permissions 1073e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * to grant and which to reject. Hence, you should be prepared that your activity 1074e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * may be paused and resumed. Further, granting some permissions may require 1075e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * a restart of you application. In such a case, the system will recreate the 1076e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * activity stack before delivering the result to {@link 1077e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * #onRequestPermissionsResult(int, String[], int[])}. 1078e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1079e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1080e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * When checking whether you have a permission you should use {@link 1081e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * android.content.Context#checkSelfPermission(String)}. 1082e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1083e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 10842750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * Calling this API for permissions already granted to your app would show UI 10852750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * to the user to decided whether the app can still hold these permissions. This 10862750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * can be useful if the way your app uses the data guarded by the permissions 10872750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * changes significantly. 10882750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * </p> 10892750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * <p> 1090e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * A sample permissions request looks like this: 1091e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1092e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <code><pre><p> 1093e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * private void showContacts() { 1094e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * if (getActivity().checkSelfPermission(Manifest.permission.READ_CONTACTS) 1095e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * != PackageManager.PERMISSION_GRANTED) { 1096e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, 1097e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * PERMISSIONS_REQUEST_READ_CONTACTS); 1098e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } else { 1099e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * doShowContacts(); 1100e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1101e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1102e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1103e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * {@literal @}Override 1104e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * public void onRequestPermissionsResult(int requestCode, String[] permissions, 1105e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * int[] grantResults) { 1106e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * if (requestCode == PERMISSIONS_REQUEST_READ_CONTACTS 1107e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 1108e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * doShowContacts(); 1109e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1110e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1111e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </code></pre></p> 1112e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1113e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param permissions The requested permissions. 1114e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param requestCode Application specific request code to match with a result 1115e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * reported to {@link #onRequestPermissionsResult(int, String[], int[])}. 1116e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1117e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #onRequestPermissionsResult(int, String[], int[]) 1118e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see android.content.Context#checkSelfPermission(String) 1119e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav */ 1120e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav public final void requestPermissions(@NonNull String[] permissions, int requestCode) { 1121e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav if (mHost == null) { 1122e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 1123e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 11245fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian mHost.onRequestPermissionsFromFragment(this, permissions, requestCode); 1125e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1126e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav 1127e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /** 1128e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Callback for the result from requesting permissions. This method 1129e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * is invoked for every call on {@link #requestPermissions(String[], int)}. 1130dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * <p> 1131dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * <strong>Note:</strong> It is possible that the permissions request interaction 1132dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * with the user is interrupted. In this case you will receive empty permissions 1133dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * and results arrays which should be treated as a cancellation. 1134dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * </p> 1135e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1136e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}. 1137e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param permissions The requested permissions. Never null. 1138e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param grantResults The grant results for the corresponding permissions 1139e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * which is either {@link android.content.pm.PackageManager#PERMISSION_GRANTED} 1140e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * or {@link android.content.pm.PackageManager#PERMISSION_DENIED}. Never null. 1141e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1142e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #requestPermissions(String[], int) 1143e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav */ 1144e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, 1145e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav @NonNull int[] grantResults) { 1146e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /* callback - do nothing */ 1147e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1148e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav 1149e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /** 1150e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Gets whether you should show UI with rationale for requesting a permission. 1151e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * You should do this only if you do not have the permission and the context in 1152e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * which the permission is requested does not clearly communicate to the user 1153e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * what would be the benefit from granting this permission. 1154e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1155e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * For example, if you write a camera app, requesting the camera permission 1156e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * would be expected by the user and no rationale for why it is requested is 1157e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * needed. If however, the app needs location for tagging photos then a non-tech 1158e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * savvy user may wonder how location is related to taking photos. In this case 1159e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * you may choose to show UI with rationale of requesting this permission. 1160e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1161e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1162e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param permission A permission your app wants to request. 1163e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @return Whether you can show permission rationale UI. 1164e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1165e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see Context#checkSelfPermission(String) 1166e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #requestPermissions(String[], int) 1167e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #onRequestPermissionsResult(int, String[], int[]) 1168e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav */ 1169e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav public boolean shouldShowRequestPermissionRationale(@NonNull String permission) { 1170e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav if (mHost != null) { 1171e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav return mHost.onShouldShowRequestPermissionRationale(permission); 1172e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1173e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav return false; 1174e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1175e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav 1176e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /** 117796221034e4a23a2abb83f772a0281bb197ac5ac0George Mount * Returns the LayoutInflater used to inflate Views of this Fragment. The default 117896221034e4a23a2abb83f772a0281bb197ac5ac0George Mount * implementation will throw an exception if the Fragment is not attached. 117996221034e4a23a2abb83f772a0281bb197ac5ac0George Mount * 1180995c3504e6c5b1d20368c36193b44a7e6844709dGeorge Mount * @param savedInstanceState If the fragment is being re-created from 1181995c3504e6c5b1d20368c36193b44a7e6844709dGeorge Mount * a previous saved state, this is the state. 118296221034e4a23a2abb83f772a0281bb197ac5ac0George Mount * @return The LayoutInflater used to inflate Views of this Fragment. 1183cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 11840abeed582ee0a105edb41181d76e8ee034750f22George Mount public LayoutInflater onGetLayoutInflater(Bundle savedInstanceState) { 11850abeed582ee0a105edb41181d76e8ee034750f22George Mount // TODO: move the implementation in getLayoutInflater to here 11860abeed582ee0a105edb41181d76e8ee034750f22George Mount return getLayoutInflater(savedInstanceState); 11870abeed582ee0a105edb41181d76e8ee034750f22George Mount } 11880abeed582ee0a105edb41181d76e8ee034750f22George Mount 11890abeed582ee0a105edb41181d76e8ee034750f22George Mount /** 11908b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * Returns the cached LayoutInflater used to inflate Views of this Fragment. If 11918b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #onGetLayoutInflater(Bundle)} has not been called {@link #onGetLayoutInflater(Bundle)} 11928b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * will be called with a {@code null} argument and that value will be cached. 11938b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * <p> 11948b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * The cached LayoutInflater will be replaced immediately prior to 11958b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} and cleared immediately after 11968b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #onDetach()}. 11978b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * 11988b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * @return The LayoutInflater used to inflate Views of this Fragment. 11998b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount */ 12008b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount public final LayoutInflater getLayoutInflater() { 12018b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount if (mLayoutInflater == null) { 12028b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount return performGetLayoutInflater(null); 12038b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount } 12048b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount return mLayoutInflater; 12058b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount } 12068b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount 12078b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount /** 12088b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * Calls {@link #onGetLayoutInflater(Bundle)} and caches the result for use by 12098b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #getLayoutInflater()}. 12108b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * 12118b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * @param savedInstanceState If the fragment is being re-created from 12128b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * a previous saved state, this is the state. 12138b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * @return The LayoutInflater used to inflate Views of this Fragment. 12148b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount */ 12158b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount LayoutInflater performGetLayoutInflater(Bundle savedInstanceState) { 12168b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount LayoutInflater layoutInflater = onGetLayoutInflater(savedInstanceState); 12178b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount mLayoutInflater = layoutInflater; 12188b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount return mLayoutInflater; 12198b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount } 12208b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount 12218b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount /** 12228b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * Override {@link #onGetLayoutInflater(Bundle)} when you need to change the 12238b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * LayoutInflater or call {@link #getLayoutInflater()} when you want to 12248b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * retrieve the current LayoutInflater. 12258b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * 12260abeed582ee0a105edb41181d76e8ee034750f22George Mount * @hide 12278b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * @deprecated Override {@link #onGetLayoutInflater(Bundle)} or call 12288b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #getLayoutInflater()} instead of this method. 12290abeed582ee0a105edb41181d76e8ee034750f22George Mount */ 12300abeed582ee0a105edb41181d76e8ee034750f22George Mount @Deprecated 12310abeed582ee0a105edb41181d76e8ee034750f22George Mount @RestrictTo(LIBRARY_GROUP) 12320abeed582ee0a105edb41181d76e8ee034750f22George Mount public LayoutInflater getLayoutInflater(Bundle savedFragmentState) { 123396221034e4a23a2abb83f772a0281bb197ac5ac0George Mount if (mHost == null) { 12340abeed582ee0a105edb41181d76e8ee034750f22George Mount throw new IllegalStateException("onGetLayoutInflater() cannot be executed until the " 123596221034e4a23a2abb83f772a0281bb197ac5ac0George Mount + "Fragment is attached to the FragmentManager."); 123696221034e4a23a2abb83f772a0281bb197ac5ac0George Mount } 12378491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy LayoutInflater result = mHost.onGetLayoutInflater(); 12380f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell getChildFragmentManager(); // Init if needed; use raw implementation below. 12394bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas LayoutInflaterCompat.setFactory2(result, mChildFragmentManager.getLayoutInflaterFactory()); 12400f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell return result; 1241cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1242d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1243cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a fragment is being created as part of a view layout 1245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * inflation, typically from setting the content view of an activity. This 12469277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * may be called immediately after the fragment is created from a <fragment> 1247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tag in a layout file. Note this is <em>before</em> the fragment's 1248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onAttach(Activity)} has been called; all you should do here is 12499277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * parse the attributes and save them away. 12504bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>This is called every time the fragment is inflated, even if it is 12529277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * being inflated into a new instance with saved state. It typically makes 12539277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * sense to re-parse the parameters each time, to allow them to change with 12549277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * different configurations.</p> 12559277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 12569277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>Here is a typical implementation of a fragment that can take parameters 12579277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * both through attributes supplied here as well from {@link #getArguments()}:</p> 12589277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 12599562a3b639225d406d736b64a12e2d75459259e3Alan Viverette * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentArgumentsSupport.java 12609277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * fragment} 12619277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 12629277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>Note that parsing the XML attributes uses a "styleable" resource. The 12639277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * declaration for the styleable used here is:</p> 12649277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 12659562a3b639225d406d736b64a12e2d75459259e3Alan Viverette * {@sample frameworks/support/samples/Support4Demos/res/values/attrs.xml fragment_arguments} 12664bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 12679277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>The fragment can then be declared within its activity's content layout 12689277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * through a tag like this:</p> 12699277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 12709562a3b639225d406d736b64a12e2d75459259e3Alan Viverette * {@sample frameworks/support/samples/Support4Demos/res/layout/fragment_arguments_support.xml from_attributes} 12719277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 12729277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>This fragment can also be created dynamically from arguments given 12739277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * at runtime in the arguments Bundle; here is an example of doing so at 12749277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * creation of the containing activity:</p> 12759277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 12769562a3b639225d406d736b64a12e2d75459259e3Alan Viverette * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentArgumentsSupport.java 12779277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * create} 12789277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 1279d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * @param context The Activity that is inflating this fragment. 1280cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param attrs The attributes at the tag where the fragment is 1281cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * being created. 1282cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 1283cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 1284cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1285916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1286d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) { 1287d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = true; 1288d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy final Activity hostActivity = mHost == null ? null : mHost.getActivity(); 1289d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (hostActivity != null) { 1290d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = false; 1291d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy onInflate(hostActivity, attrs, savedInstanceState); 1292d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1293d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1294d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1295d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy /** 1296d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Called when a fragment is being created as part of a view layout 1297d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * inflation, typically from setting the content view of an activity. 1298d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * 1299d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * @deprecated See {@link #onInflate(Context, AttributeSet, Bundle)}. 1300d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy */ 1301d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Deprecated 1302916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 13039277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { 1304cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1305cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 13069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 1307cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1308cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * Called when a fragment is attached as a child of this fragment. 1309cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * 1310cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * <p>This is called after the attached fragment's <code>onAttach</code> and before 1311cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * the attached fragment's <code>onCreate</code> if the fragment has not yet had a previous 1312cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * call to <code>onCreate</code>.</p> 1313cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * 1314cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * @param childFragment child fragment being attached 1315cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell */ 1316cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell public void onAttachFragment(Fragment childFragment) { 1317cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell } 1318cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell 1319cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell /** 1320d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Called when a fragment is first attached to its context. 1321d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * {@link #onCreate(Bundle)} will be called after this. 1322d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy */ 1323916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1324d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy public void onAttach(Context context) { 1325d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = true; 1326d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy final Activity hostActivity = mHost == null ? null : mHost.getActivity(); 1327d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (hostActivity != null) { 1328d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = false; 1329d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy onAttach(hostActivity); 1330d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1331d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1332d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1333d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy /** 1334cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a fragment is first attached to its activity. 1335cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreate(Bundle)} will be called after this. 1336d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * 1337d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * @deprecated See {@link #onAttach(Context)}. 1338cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1339d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Deprecated 1340916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1341cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onAttach(Activity activity) { 1342cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1343cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1344d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1345cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 134615e593ea3575512d7072240d1db9d74fad8749a3George Mount * Called when a fragment loads an animation. Note that if 134715e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int)} was called with 134815e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link Animator} resources instead of {@link Animation} resources, {@code nextAnim} 134915e593ea3575512d7072240d1db9d74fad8749a3George Mount * will be an animator resource. 135015e593ea3575512d7072240d1db9d74fad8749a3George Mount * 135115e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param transit The value set in {@link FragmentTransaction#setTransition(int)} or 0 if not 135215e593ea3575512d7072240d1db9d74fad8749a3George Mount * set. 135315e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param enter {@code true} when the fragment is added/attached/shown or {@code false} when 135415e593ea3575512d7072240d1db9d74fad8749a3George Mount * the fragment is removed/detached/hidden. 135515e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param nextAnim The resource set in 135615e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int)}, 135715e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int, int, int)}, or 135815e593ea3575512d7072240d1db9d74fad8749a3George Mount * 0 if neither was called. The value will depend on the current operation. 1359cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 13609277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { 1361cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return null; 1362cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1363d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1364cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 136515e593ea3575512d7072240d1db9d74fad8749a3George Mount * Called when a fragment loads an animator. This will be called when 136615e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link #onCreateAnimation(int, boolean, int)} returns null. Note that if 136715e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int)} was called with 136815e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link Animation} resources instead of {@link Animator} resources, {@code nextAnim} 136915e593ea3575512d7072240d1db9d74fad8749a3George Mount * will be an animation resource. 137015e593ea3575512d7072240d1db9d74fad8749a3George Mount * 137115e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param transit The value set in {@link FragmentTransaction#setTransition(int)} or 0 if not 137215e593ea3575512d7072240d1db9d74fad8749a3George Mount * set. 137315e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param enter {@code true} when the fragment is added/attached/shown or {@code false} when 137415e593ea3575512d7072240d1db9d74fad8749a3George Mount * the fragment is removed/detached/hidden. 137515e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param nextAnim The resource set in 137615e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int)}, 137715e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int, int, int)}, or 137815e593ea3575512d7072240d1db9d74fad8749a3George Mount * 0 if neither was called. The value will depend on the current operation. 137915e593ea3575512d7072240d1db9d74fad8749a3George Mount */ 138015e593ea3575512d7072240d1db9d74fad8749a3George Mount public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) { 138115e593ea3575512d7072240d1db9d74fad8749a3George Mount return null; 138215e593ea3575512d7072240d1db9d74fad8749a3George Mount } 138315e593ea3575512d7072240d1db9d74fad8749a3George Mount 138415e593ea3575512d7072240d1db9d74fad8749a3George Mount /** 1385cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to do initial creation of a fragment. This is called after 1386cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onAttach(Activity)} and before 1387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 13884bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1389cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>Note that this can be called while the fragment's activity is 1390cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * still in the process of being created. As such, you can not rely 1391cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on things like the activity's content view hierarchy being initialized 1392cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * at this point. If you want to do work once the activity itself is 1393cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * created, see {@link #onActivityCreated(Bundle)}. 1394277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell * 1395277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell * <p>Any restored child fragments will be created before the base 1396277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell * <code>Fragment.onCreate</code> method returns.</p> 13974bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1398cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 1399cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 1400cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1401916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1402c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy public void onCreate(@Nullable Bundle savedInstanceState) { 1403cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 14049375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell restoreChildFragmentState(savedInstanceState); 1405fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell if (mChildFragmentManager != null 1406fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell && !mChildFragmentManager.isStateAtLeast(Fragment.CREATED)) { 1407fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell mChildFragmentManager.dispatchCreate(); 1408fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell } 14099375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell } 14109375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell 14119375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell /** 14129375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * Restore the state of the child FragmentManager. Called by either 14139375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * {@link #onCreate(Bundle)} for non-retained instance fragments or by 14149375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * {@link FragmentManagerImpl#moveToState(Fragment, int, int, int, boolean)} 14159375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * for retained instance fragments. 14169375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * 14179375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * <p><strong>Postcondition:</strong> if there were child fragments to restore, 14189375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * the child FragmentManager will be instantiated and brought to the {@link #CREATED} state. 14199375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * </p> 14209375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * 14219375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * @param savedInstanceState the savedInstanceState potentially containing fragment info 14229375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell */ 14239375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell void restoreChildFragmentState(@Nullable Bundle savedInstanceState) { 1424277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell if (savedInstanceState != null) { 1425277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell Parcelable p = savedInstanceState.getParcelable( 1426277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell FragmentActivity.FRAGMENTS_TAG); 1427277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell if (p != null) { 1428277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell if (mChildFragmentManager == null) { 1429277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell instantiateChildFragmentManager(); 1430277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell } 1431c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mChildFragmentManager.restoreAllState(p, mChildNonConfig); 1432c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mChildNonConfig = null; 1433277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell mChildFragmentManager.dispatchCreate(); 1434277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell } 1435277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell } 1436cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 14370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1438cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1439cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to have the fragment instantiate its user interface view. 1440cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is optional, and non-graphical fragments can return null (which 1441cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is the default implementation). This will be called between 1442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}. 14434bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1444cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>If you return a View from here, you will later be called in 1445cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onDestroyView} when the view is being released. 14464bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1447cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param inflater The LayoutInflater object that can be used to inflate 1448cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * any views in the fragment, 1449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param container If non-null, this is the parent view that the fragment's 1450cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * UI should be attached to. The fragment should not add the view itself, 1451cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * but this can be used to generate the LayoutParams of the view. 1452cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If non-null, this fragment is being re-constructed 1453cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * from a previous saved state as given here. 14544bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return Return the View for the fragment's UI, or null. 1456cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1457c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy @Nullable 1458a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, 1459a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye @Nullable Bundle savedInstanceState) { 1460cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return null; 1461cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 14620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1463cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1464e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} 1465e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * has returned, but before any saved state has been restored in to the view. 1466e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * This gives subclasses a chance to initialize themselves once 1467e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * they know their view hierarchy has been completely created. The fragment's 1468e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * view hierarchy is not however attached to its parent at this point. 1469e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 1470e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * @param savedInstanceState If non-null, this fragment is being re-constructed 1471e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * from a previous saved state as given here. 1472e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn */ 1473a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 1474e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 1475e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 1476e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn /** 1477cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}), 1478cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if provided. 14794bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1480cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return The fragment's root view, or null if it has no layout. 1481cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1482a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye @Nullable 1483cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public View getView() { 1484cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mView; 1485cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 14864bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1487cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1488cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment's activity has been created and this 1489cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * fragment's view hierarchy instantiated. It can be used to do final 1490cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * initialization once these pieces are in place, such as retrieving 1491cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * views or restoring state. It is also useful for fragments that use 1492cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #setRetainInstance(boolean)} to retain their instance, 1493cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * as this callback tells the fragment when it is fully associated with 1494cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the new activity instance. This is called after {@link #onCreateView} 14950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * and before {@link #onViewStateRestored(Bundle)}. 14960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 1497cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 1498cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 1499cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1500916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1501a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public void onActivityCreated(@Nullable Bundle savedInstanceState) { 1502cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1503cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 15040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 15050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 15060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Called when all saved state has been restored into the view hierarchy 15070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * of the fragment. This can be used to do initialization based on saved 15080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * state that you are letting the view hierarchy track itself, such as 15090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * whether check box widgets are currently checked. This is called 15100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * after {@link #onActivityCreated(Bundle)} and before 15110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * {@link #onStart()}. 15120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 15130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 15140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * a previous saved state, this is the state. 15150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 1516916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1517a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public void onViewStateRestored(@Nullable Bundle savedInstanceState) { 15180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = true; 15190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 15200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1521cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1522cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is visible to the user. This is generally 1523cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onStart() Activity.onStart} of the containing 1524cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1525cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1526916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1527cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onStart() { 1528cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1529d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!mLoadersStarted) { 1531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoadersStarted = true; 1532cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!mCheckedForLoaderManager) { 1533cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCheckedForLoaderManager = true; 1534d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false); 1535b51206c625a09945a96ad091e35a4a9e5f72802cGeorge Mount } else if (mLoaderManager != null) { 1536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoaderManager.doStart(); 1537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1539cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1540d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1542cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is visible to the user and actively running. 1543cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is generally 1544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onResume() Activity.onResume} of the containing 1545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1547916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onResume() { 1549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 15514bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to ask the fragment to save its current dynamic state, so it 1554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can later be reconstructed in a new instance of its process is 1555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * restarted. If a new instance of the fragment later needs to be 1556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * created, the data you place in the Bundle here will be available 1557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * in the Bundle given to {@link #onCreate(Bundle)}, 1558cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}, and 1559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onActivityCreated(Bundle)}. 1560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1561cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>This corresponds to {@link Activity#onSaveInstanceState(Bundle) 1562cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity.onSaveInstanceState(Bundle)} and most of the discussion there 1563cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * applies here as well. Note however: <em>this method may be called 1564cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * at any time before {@link #onDestroy()}</em>. There are many situations 1565cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * where a fragment may be mostly torn down (such as when placed on the 1566cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * back stack with no UI showing), but its state will not be saved until 1567cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * its owning activity actually needs to save its state. 1568cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1569cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param outState Bundle in which to place your saved state. 1570cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1571cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onSaveInstanceState(Bundle outState) { 1572cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 15735fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 15745fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian /** 15755fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * Called when the Fragment's activity changes from fullscreen mode to multi-window mode and 15765fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * visa-versa. This is generally tied to {@link Activity#onMultiWindowModeChanged} of the 15775fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * containing Activity. 15785fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * 15795fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * @param isInMultiWindowMode True if the activity is in multi-window mode. 15805fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian */ 15815fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { 15825fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 15835fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 15845fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian /** 15855fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * Called by the system when the activity changes to and from picture-in-picture mode. This is 15865fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * generally tied to {@link Activity#onPictureInPictureModeChanged} of the containing Activity. 15875fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * 15885fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode. 15895fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian */ 15905fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { 15915fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 15925fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 159390ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas @Override 1594916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1595cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onConfigurationChanged(Configuration newConfig) { 1596cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1597cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 15985fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 1599cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1600cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is no longer resumed. This is generally 1601cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onPause() Activity.onPause} of the containing 1602cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1603cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1604916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1605cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onPause() { 1606cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1607cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16084bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1609cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1610cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is no longer started. This is generally 1611cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onStop() Activity.onStop} of the containing 1612cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1613cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1614916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1615cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onStop() { 1616cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1617cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1618916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell 161990ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas @Override 1620916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1621cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onLowMemory() { 1622cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1623cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16244bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1625cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1626cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the view previously created by {@link #onCreateView} has 1627cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * been detached from the fragment. The next time the fragment needs 1628cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to be displayed, a new view will be created. This is called 1629cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * after {@link #onStop()} and before {@link #onDestroy()}. It is called 1630cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <em>regardless</em> of whether {@link #onCreateView} returned a 1631cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * non-null view. Internally it is called after the view's state has 1632cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * been saved but before it has been removed from its parent. 1633cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1634916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1635cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroyView() { 1636cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1637cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16384bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1639cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1640cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is no longer in use. This is called 1641cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * after {@link #onStop()} and before {@link #onDetach()}. 1642cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1643916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1644cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroy() { 1645cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1646cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn //Log.v("foo", "onDestroy: mCheckedForLoaderManager=" + mCheckedForLoaderManager 1647cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // + " mLoaderManager=" + mLoaderManager); 1648cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!mCheckedForLoaderManager) { 1649cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCheckedForLoaderManager = true; 1650d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false); 1651cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1652cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoaderManager != null) { 1653cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoaderManager.doDestroy(); 1654cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1655cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1656cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1657cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 16589c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * Called by the fragment manager once this fragment has been removed, 16599c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * so that we don't have any left-over state if the application decides 16609c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * to re-use the instance. This only clears state that the framework 16619c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * internally manages, not things the application sets. 16629c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn */ 16639c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void initState() { 16649c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mIndex = -1; 16659c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mWho = null; 16669c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mAdded = false; 16679c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRemoving = false; 16689c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFromLayout = false; 16699c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mInLayout = false; 16709c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRestored = false; 16719c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mBackStackNesting = 0; 16729c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFragmentManager = null; 16736252d78085a07c9d6bb4645a4e8086bf23b0a49aTim Kilbourn mChildFragmentManager = null; 1674d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mHost = null; 16759c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFragmentId = 0; 16769c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mContainerId = 0; 16779c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mTag = null; 16789c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mHidden = false; 16799c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mDetached = false; 16809c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRetaining = false; 16819c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mLoaderManager = null; 16829c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mLoadersStarted = false; 16839c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mCheckedForLoaderManager = false; 16849c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 16859c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 16869c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn /** 1687cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is no longer attached to its activity. This 1688cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is called after {@link #onDestroy()}. 1689cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1690916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1691cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDetach() { 1692cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16944bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1695cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 16969375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * Initialize the contents of the Fragment host's standard options menu. You 1697cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * should place your menu items in to <var>menu</var>. For this method 1698cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to be called, you must have first called {@link #setHasOptionsMenu}. See 1699cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu} 1700cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for more information. 17014bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1702cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu in which you place your items. 17034bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1704cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #setHasOptionsMenu 1705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onPrepareOptionsMenu 1706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onOptionsItemSelected 1707cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1708cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 1709cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1710cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1711cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 17129375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * Prepare the Fragment host's standard options menu to be displayed. This is 1713cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * called right before the menu is shown, every time it is shown. You can 1714cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * use this method to efficiently enable/disable items or otherwise 1715cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * dynamically modify the contents. See 1716cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu} 1717cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for more information. 17184bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1719cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu as last shown or first initialized by 1720cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * onCreateOptionsMenu(). 17214bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1722cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #setHasOptionsMenu 1723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onCreateOptionsMenu 1724cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1725cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onPrepareOptionsMenu(Menu menu) { 1726cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1727cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1728cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1729cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when this fragment's option menu items are no longer being 1730cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * included in the overall options menu. Receiving this call means that 1731cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the menu needed to be rebuilt, but this fragment's items were not 1732cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * included in the newly built menu (its {@link #onCreateOptionsMenu(Menu, MenuInflater)} 1733cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * was not called). 1734cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1735cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroyOptionsMenu() { 1736cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 17374bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1738cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1739cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever an item in your options menu is selected. 1740cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * The default implementation simply returns false to have the normal 1741cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * processing happen (calling the item's Runnable or sending a message to 1742cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * its Handler as appropriate). You can use this method for any items 1743cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for which you would like to do processing without those other 1744cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * facilities. 17454bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1746cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>Derived classes should call through to the base class for it to 1747cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * perform the default menu handling. 17484bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1749cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param item The menu item that was selected. 17504bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1751cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return boolean Return false to allow normal menu processing to 1752cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * proceed, true to consume it here. 17534bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1754cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onCreateOptionsMenu 1755cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1756cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public boolean onOptionsItemSelected(MenuItem item) { 1757cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return false; 1758cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1759cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1760cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1761cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever the options menu is being closed (either by the user canceling 1762cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the menu with the back/menu button, or when an item is selected). 17634bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1764cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu as last shown or first initialized by 1765cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * onCreateOptionsMenu(). 1766cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1767cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onOptionsMenuClosed(Menu menu) { 1768cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 17694bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1770cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1771cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a context menu for the {@code view} is about to be shown. 1772cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Unlike {@link #onCreateOptionsMenu}, this will be called every 1773cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * time the context menu is about to be shown and should be populated for 1774cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the view (or item inside the view for {@link AdapterView} subclasses, 1775cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * this can be found in the {@code menuInfo})). 1776cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1777cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an 1778cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * item has been selected. 1779cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1780cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * The default implementation calls up to 1781cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though 1782cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * you can not call this implementation if you don't want that behavior. 1783cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1784cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * It is not safe to hold onto the context menu after this method returns. 1785cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@inheritDoc} 1786cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1787d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Override 1788cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 1789cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn getActivity().onCreateContextMenu(menu, v, menuInfo); 1790cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1791cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1792cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1793cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Registers a context menu to be shown for the given view (multiple views 1794cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can show the context menu). This method will set the 1795cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link OnCreateContextMenuListener} on the view to this fragment, so 1796cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be 1797cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * called when it is time to show the context menu. 17984bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1799cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #unregisterForContextMenu(View) 1800cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param view The view that should show a context menu. 1801cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1802cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void registerForContextMenu(View view) { 1803cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn view.setOnCreateContextMenuListener(this); 1804cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 18054bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1806cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1807cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Prevents a context menu to be shown for the given view. This method will 1808cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * remove the {@link OnCreateContextMenuListener} on the view. 18094bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1810cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #registerForContextMenu(View) 1811cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param view The view that should stop showing a context menu. 1812cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1813cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void unregisterForContextMenu(View view) { 1814cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn view.setOnCreateContextMenuListener(null); 1815cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 18164bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1817cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1818cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever an item in a context menu is selected. The 1819cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default implementation simply returns false to have the normal processing 1820cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * happen (calling the item's Runnable or sending a message to its Handler 1821cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * as appropriate). You can use this method for any items for which you 1822cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * would like to do processing without those other facilities. 1823cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1824cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Use {@link MenuItem#getMenuInfo()} to get extra information set by the 1825cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * View that added this menu item. 1826cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1827cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Derived classes should call through to the base class for it to perform 1828cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the default menu handling. 18294bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1830cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param item The context menu item that was selected. 1831cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return boolean Return false to allow normal context menu processing to 1832cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * proceed, true to consume it here. 1833cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1834cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public boolean onContextItemSelected(MenuItem item) { 1835cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return false; 1836cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1837e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes 1838cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 18399306f07b1d66f4974a81f781d29739b30124fff0George Mount * When custom transitions are used with Fragments, the enter transition callback 18409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is called when this Fragment is attached or detached when not popping the back stack. 18419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 18429306f07b1d66f4974a81f781d29739b30124fff0George Mount * @param callback Used to manipulate the shared element transitions on this Fragment 18439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when added not as a pop from the back stack. 18449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 1845b1413bc4de16e05ae0455cad93f1edfbcc4eced2George Mount public void setEnterSharedElementCallback(SharedElementCallback callback) { 1846990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mEnterTransitionCallback = callback; 18479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 18489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 18499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 18509306f07b1d66f4974a81f781d29739b30124fff0George Mount * When custom transitions are used with Fragments, the exit transition callback 18519f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is called when this Fragment is attached or detached when popping the back stack. 18529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 18539306f07b1d66f4974a81f781d29739b30124fff0George Mount * @param callback Used to manipulate the shared element transitions on this Fragment 18549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when added as a pop from the back stack. 18559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 1856b1413bc4de16e05ae0455cad93f1edfbcc4eced2George Mount public void setExitSharedElementCallback(SharedElementCallback callback) { 1857990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mExitTransitionCallback = callback; 18589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 18599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 18609f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 18619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views into the initial scene. The entering 18629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 18639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 18649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 18659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null, 18669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. 18679f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 18689f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views into the initial Scene. 18699f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 18709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setEnterTransition(Object transition) { 1871990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mEnterTransition = transition; 18729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 18739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 18749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 18759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views into the initial scene. The entering 18769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 18779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 18789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 18799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#INVISIBLE} to {@link View#VISIBLE}. 18809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 18819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views into the initial Scene. 18829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 18839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getEnterTransition() { 1884990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 1885990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 1886990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 1887990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mEnterTransition; 18889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 18899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 18909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 18919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views out of the scene when the Fragment is 18929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * preparing to be removed, hidden, or detached because of popping the back stack. The exiting 18939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 18949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 18959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 18969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null, 18979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. If nothing is set, the default will be to 18989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * use the same value as set in {@link #setEnterTransition(Object)}. 18999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views out of the Scene when the Fragment 19019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is preparing to close. <code>transition</code> must be an 19029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * android.transition.Transition. 19039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setReturnTransition(Object transition) { 1905990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mReturnTransition = transition; 19069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views out of the scene when the Fragment is 19109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * preparing to be removed, hidden, or detached because of popping the back stack. The exiting 19119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 19129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 19139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 19149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null, 19159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. 19169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views out of the Scene when the Fragment 19189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is preparing to close. 19199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getReturnTransition() { 1921990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 1922990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 1923990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 1924990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mReturnTransition == USE_DEFAULT_TRANSITION ? getEnterTransition() 1925990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount : mAnimationInfo.mReturnTransition; 19269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19279f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views out of the scene when the 19309f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * fragment is removed, hidden, or detached when not popping the back stack. 19319f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * The exiting Views will be those that are regular Views or ViewGroups that 19329f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 19339f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as exiting is governed by changing visibility 19349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will 19359f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * remain unaffected. 19369f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views out of the Scene when the Fragment 19389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is being closed not due to popping the back stack. <code>transition</code> 19399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * must be an android.transition.Transition. 19409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setExitTransition(Object transition) { 1942990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mExitTransition = transition; 19439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19459f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19469f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views out of the scene when the 19479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * fragment is removed, hidden, or detached when not popping the back stack. 19489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * The exiting Views will be those that are regular Views or ViewGroups that 19499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 19509f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as exiting is governed by changing visibility 19519f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will 19529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * remain unaffected. 19539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views out of the Scene when the Fragment 19559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is being closed not due to popping the back stack. 19569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getExitTransition() { 1958990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 1959990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 1960990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 1961990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mExitTransition; 19629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views in to the scene when returning due 19669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * to popping a back stack. The entering Views will be those that are regular Views 19679f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions 19689f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * will extend {@link android.transition.Visibility} as exiting is governed by changing 19699f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, 19709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * the views will remain unaffected. If nothing is set, the default will be to use the same 19719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * transition as {@link #setExitTransition(Object)}. 19729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views into the scene when reentering from a 19749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * previously-started Activity. <code>transition</code> 19759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * must be an android.transition.Transition. 19769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setReenterTransition(Object transition) { 1978990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mReenterTransition = transition; 19799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views in to the scene when returning due 19839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * to popping a back stack. The entering Views will be those that are regular Views 19849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions 19859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * will extend {@link android.transition.Visibility} as exiting is governed by changing 19869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, 19879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * the views will remain unaffected. If nothing is set, the default will be to use the same 19889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * transition as {@link #setExitTransition(Object)}. 19899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views into the scene when reentering from a 19919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * previously-started Activity. 19929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getReenterTransition() { 1994990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 1995990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 1996990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 1997990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mReenterTransition == USE_DEFAULT_TRANSITION ? getExitTransition() 1998990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount : mAnimationInfo.mReenterTransition; 19999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used for shared elements transferred into the content 20039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. Typical Transitions will affect size and location, such as 20049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 20059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 20069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use for shared elements transferred into the content 20089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. <code>transition</code> must be an android.transition.Transition. 20099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setSharedElementEnterTransition(Object transition) { 2011990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mSharedElementEnterTransition = transition; 20129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used for shared elements transferred into the content 20169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. Typical Transitions will affect size and location, such as 20179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 20189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 20199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return The Transition to use for shared elements transferred into the content 20219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. 20229f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getSharedElementEnterTransition() { 2024990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2025990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2026990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2027990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mSharedElementEnterTransition; 20289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20309f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20319f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used for shared elements transferred back during a 20329f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * pop of the back stack. This Transition acts in the leaving Fragment. 20339f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Typical Transitions will affect size and location, such as 20349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 20359f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 20369f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * If no value is set, the default will be to use the same value as 20379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link #setSharedElementEnterTransition(Object)}. 20389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use for shared elements transferred out of the content 20409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. <code>transition</code> must be an android.transition.Transition. 20419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20429f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setSharedElementReturnTransition(Object transition) { 2043990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mSharedElementReturnTransition = transition; 20449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20459f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20469f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Return the Transition that will be used for shared elements transferred back during a 20489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * pop of the back stack. This Transition acts in the leaving Fragment. 20499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Typical Transitions will affect size and location, such as 20509f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 20519f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 20529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * If no value is set, the default will be to use the same value as 20539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link #setSharedElementEnterTransition(Object)}. 20549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return The Transition to use for shared elements transferred out of the content 20569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. 20579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getSharedElementReturnTransition() { 2059990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2060990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2061990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2062990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mSharedElementReturnTransition == USE_DEFAULT_TRANSITION 2063990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ? getSharedElementEnterTransition() 2064990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount : mAnimationInfo.mSharedElementReturnTransition; 20659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20679f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20689f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets whether the the exit transition and enter transition overlap or not. 20699f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the enter transition will start as soon as possible. When false, the 20709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * enter transition will wait until the exit transition completes before starting. 20719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param allow true to start the enter transition when possible or false to 20739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * wait until the exiting transition completes. 20749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setAllowEnterTransitionOverlap(boolean allow) { 2076990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mAllowEnterTransitionOverlap = allow; 20779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns whether the the exit transition and enter transition overlap or not. 20819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the enter transition will start as soon as possible. When false, the 20829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * enter transition will wait until the exit transition completes before starting. 20839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return true when the enter transition should start as soon as possible or false to 20859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when it should wait until the exiting transition completes. 20869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public boolean getAllowEnterTransitionOverlap() { 2088990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return (mAnimationInfo == null || mAnimationInfo.mAllowEnterTransitionOverlap == null) 2089990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ? true : mAnimationInfo.mAllowEnterTransitionOverlap; 20909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets whether the the return transition and reenter transition overlap or not. 20949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the reenter transition will start as soon as possible. When false, the 20959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * reenter transition will wait until the return transition completes before starting. 20969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param allow true to start the reenter transition when possible or false to wait until the 20989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * return transition completes. 20999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 21009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setAllowReturnTransitionOverlap(boolean allow) { 2101990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mAllowReturnTransitionOverlap = allow; 21029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 21039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 21049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 21059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns whether the the return transition and reenter transition overlap or not. 21069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the reenter transition will start as soon as possible. When false, the 21079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * reenter transition will wait until the return transition completes before starting. 21089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 21099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return true to start the reenter transition when possible or false to wait until the 21109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * return transition completes. 21119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 21129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public boolean getAllowReturnTransitionOverlap() { 2113990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return (mAnimationInfo == null || mAnimationInfo.mAllowReturnTransitionOverlap == null) 2114990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ? true : mAnimationInfo.mAllowReturnTransitionOverlap; 2115990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2116990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2117990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2118990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Postpone the entering Fragment transition until {@link #startPostponedEnterTransition()} 2119990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * or {@link FragmentManager#executePendingTransactions()} has been called. 2120990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * <p> 2121990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * This method gives the Fragment the ability to delay Fragment animations 2122990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * until all data is loaded. Until then, the added, shown, and 2123990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * attached Fragments will be INVISIBLE and removed, hidden, and detached Fragments won't 2124990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * be have their Views removed. The transaction runs when all postponed added Fragments in the 2125990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * transaction have called {@link #startPostponedEnterTransition()}. 2126990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * <p> 2127990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * This method should be called before being added to the FragmentTransaction or 2128990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * in {@link #onCreate(Bundle), {@link #onAttach(Context)}, or 2129990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}}. 2130990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * {@link #startPostponedEnterTransition()} must be called to allow the Fragment to 2131990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * start the transitions. 2132990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * <p> 2133990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * When a FragmentTransaction is started that may affect a postponed FragmentTransaction, 2134990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * based on which containers are in their operations, the postponed FragmentTransaction 2135990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * will have its start triggered. The early triggering may result in faulty or nonexistent 2136990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * animations in the postponed transaction. FragmentTransactions that operate only on 2137990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * independent containers will not interfere with each other's postponement. 2138990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * <p> 2139990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Calling postponeEnterTransition on Fragments with a null View will not postpone the 2140fda5be2466024a656152015c45a7681361d399bbGeorge Mount * transition. Likewise, postponement only works if 2141fda5be2466024a656152015c45a7681361d399bbGeorge Mount * {@link FragmentTransaction#setReorderingAllowed(boolean) FragmentTransaction reordering} is 2142990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * enabled. 2143990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * 2144990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * @see Activity#postponeEnterTransition() 2145fda5be2466024a656152015c45a7681361d399bbGeorge Mount * @see FragmentTransaction#setReorderingAllowed(boolean) 2146990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2147990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount public void postponeEnterTransition() { 2148990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mEnterTransitionPostponed = true; 2149990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2150990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2151990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2152990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Begin postponed transitions after {@link #postponeEnterTransition()} was called. 2153990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * If postponeEnterTransition() was called, you must call startPostponedEnterTransition() 2154990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * or {@link FragmentManager#executePendingTransactions()} to complete the FragmentTransaction. 2155990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * If postponement was interrupted with {@link FragmentManager#executePendingTransactions()}, 2156990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * before {@code startPostponedEnterTransition()}, animations may not run or may execute 2157990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * improperly. 2158990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * 2159990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * @see Activity#startPostponedEnterTransition() 2160990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2161990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount public void startPostponedEnterTransition() { 2162990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mFragmentManager == null || mFragmentManager.mHost == null) { 2163990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mEnterTransitionPostponed = false; 2164990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } else if (Looper.myLooper() != mFragmentManager.mHost.getHandler().getLooper()) { 2165990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mFragmentManager.mHost.getHandler().postAtFrontOfQueue(new Runnable() { 2166990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount @Override 2167990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount public void run() { 2168990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount callStartTransitionListener(); 2169990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2170990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount }); 2171990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } else { 2172990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount callStartTransitionListener(); 2173990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2174990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2175990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2176990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2177990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Calls the start transition listener. This must be called on the UI thread. 2178990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2179990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private void callStartTransitionListener() { 2180990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount final OnStartEnterTransitionListener listener; 2181990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2182990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount listener = null; 2183990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } else { 2184990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mEnterTransitionPostponed = false; 2185990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount listener = mAnimationInfo.mStartEnterTransitionListener; 2186990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mStartEnterTransitionListener = null; 2187990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2188990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (listener != null) { 2189990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount listener.onStartEnterTransition(); 2190990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 21919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 21929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 21939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 2194cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Print the Fragments's state into the given stream. 2195cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 2196cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param prefix Text to print at the front of each line. 2197cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fd The raw file descriptor that the dump is being sent to. 2198cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param writer The PrintWriter to which you should dump your state. This will be 2199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * closed for you after you return. 2200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param args additional arguments to the dump request. 2201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 2202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { 2203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mFragmentId=#"); 2204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(Integer.toHexString(mFragmentId)); 22055506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn writer.print(" mContainerId=#"); 2206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(Integer.toHexString(mContainerId)); 2207cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mTag="); writer.println(mTag); 2208cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mState="); writer.print(mState); 2209cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mIndex="); writer.print(mIndex); 2210cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mWho="); writer.print(mWho); 2211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mBackStackNesting="); writer.println(mBackStackNesting); 2212cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mAdded="); writer.print(mAdded); 2213cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mRemoving="); writer.print(mRemoving); 2214cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mFromLayout="); writer.print(mFromLayout); 2215cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mInLayout="); writer.println(mInLayout); 2216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mHidden="); writer.print(mHidden); 2217e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn writer.print(" mDetached="); writer.print(mDetached); 22182a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn writer.print(" mMenuVisible="); writer.print(mMenuVisible); 2219cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mHasMenu="); writer.println(mHasMenu); 22202a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn writer.print(prefix); writer.print("mRetainInstance="); writer.print(mRetainInstance); 222179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell writer.print(" mRetaining="); writer.print(mRetaining); 222279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell writer.print(" mUserVisibleHint="); writer.println(mUserVisibleHint); 2223cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mFragmentManager != null) { 2224cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mFragmentManager="); 2225cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mFragmentManager); 2226cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2227d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost != null) { 2228d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy writer.print(prefix); writer.print("mHost="); 2229d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy writer.println(mHost); 2230cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 22310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mParentFragment != null) { 22320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.print(prefix); writer.print("mParentFragment="); 22330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.println(mParentFragment); 22340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2235cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mArguments != null) { 2236cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mArguments="); writer.println(mArguments); 2237cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2238cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedFragmentState != null) { 2239cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mSavedFragmentState="); 2240cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mSavedFragmentState); 2241cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2242cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedViewState != null) { 2243cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mSavedViewState="); 2244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mSavedViewState); 2245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2246cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mTarget != null) { 2247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mTarget="); writer.print(mTarget); 2248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mTargetRequestCode="); 2249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mTargetRequestCode); 2250cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2251990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (getNextAnim() != 0) { 2252990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print(prefix); writer.print("mNextAnim="); writer.println(getNextAnim()); 2253cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2254cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mContainer != null) { 2255cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mContainer="); writer.println(mContainer); 2256cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2257cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mView != null) { 2258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mView="); writer.println(mView); 2259cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2260cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mInnerView != null) { 2261cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mInnerView="); writer.println(mView); 2262cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2263990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (getAnimatingAway() != null) { 2264990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print(prefix); 2265990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print("mAnimatingAway="); 2266990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.println(getAnimatingAway()); 2267990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print(prefix); 2268990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print("mStateAfterAnimating="); 2269990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.println(getStateAfterAnimating()); 2270cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2271cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoaderManager != null) { 2272cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.println("Loader Manager:"); 2273cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoaderManager.dump(prefix + " ", fd, writer, args); 2274cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 22750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 22760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.print(prefix); writer.println("Child " + mChildFragmentManager + ":"); 22770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dump(prefix + " ", fd, writer, args); 22780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 22790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 22800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 22810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Fragment findFragmentByWho(String who) { 22820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (who.equals(mWho)) { 22830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return this; 22840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 22850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 22860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mChildFragmentManager.findFragmentByWho(who); 22870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 22880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return null; 22890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 22900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 22910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void instantiateChildFragmentManager() { 22921c7e1f738e202226b365c81715b221d2e864fdd5George Mount if (mHost == null) { 22931c7e1f738e202226b365c81715b221d2e864fdd5George Mount throw new IllegalStateException("Fragment has not been attached yet."); 22941c7e1f738e202226b365c81715b221d2e864fdd5George Mount } 2295e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes mChildFragmentManager = new FragmentManagerImpl(); 2296d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mChildFragmentManager.attachController(mHost, new FragmentContainer() { 22970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn @Override 22980fb3ec354da6c1f3ed1777bca5270710cc537e92Scott Kennedy @Nullable 22998491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy public View onFindViewById(int id) { 23000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mView == null) { 23010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new IllegalStateException("Fragment does not have a view"); 23020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mView.findViewById(id); 23040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23057516316ffdf6fbf7b248c615404831191daa66a4George Mount 23067516316ffdf6fbf7b248c615404831191daa66a4George Mount @Override 23078491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy public boolean onHasView() { 23087516316ffdf6fbf7b248c615404831191daa66a4George Mount return (mView != null); 23097516316ffdf6fbf7b248c615404831191daa66a4George Mount } 23104aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell 23114aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell @Override 23124aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell public Fragment instantiate(Context context, String className, Bundle arguments) { 23134aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell return mHost.instantiate(context, className, arguments); 23144aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell } 23150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn }, this); 23160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 23180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performCreate(Bundle savedInstanceState) { 23190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 23210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 232220735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = CREATED; 23230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 23240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onCreate(savedInstanceState); 23250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 23260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 23270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onCreate()"); 23280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 23310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn View performCreateView(LayoutInflater inflater, ViewGroup container, 23320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Bundle savedInstanceState) { 23330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 23350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 233637149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell mPerformedCreateView = true; 23370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return onCreateView(inflater, container, savedInstanceState); 23380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 23400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performActivityCreated(Bundle savedInstanceState) { 23410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 23430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 234420735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = ACTIVITY_CREATED; 23450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 23460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onActivityCreated(savedInstanceState); 23470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 23480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 23490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onActivityCreated()"); 23500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchActivityCreated(); 23530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2354cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2355cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 23569c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void performStart() { 23570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 23590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 23600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 236120735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = STARTED; 23620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 23639c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn onStart(); 23640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 23650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 23660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onStart()"); 23670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStart(); 23700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23719c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn if (mLoaderManager != null) { 23729c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mLoaderManager.doReportStart(); 23739c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 23749c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 23759c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 23760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performResume() { 23770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 23790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 23800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 238120735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = RESUMED; 23820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 23830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onResume(); 23840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 23850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 23860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onResume()"); 23870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchResume(); 23900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 23910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 23940765353c002bfdf681c982565810aa4be3499dd0George Mount void noteStateNotSaved() { 23950765353c002bfdf681c982565810aa4be3499dd0George Mount if (mChildFragmentManager != null) { 23960765353c002bfdf681c982565810aa4be3499dd0George Mount mChildFragmentManager.noteStateNotSaved(); 23970765353c002bfdf681c982565810aa4be3499dd0George Mount } 23980765353c002bfdf681c982565810aa4be3499dd0George Mount } 23990765353c002bfdf681c982565810aa4be3499dd0George Mount 24005fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian void performMultiWindowModeChanged(boolean isInMultiWindowMode) { 24015fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian onMultiWindowModeChanged(isInMultiWindowMode); 24025fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian if (mChildFragmentManager != null) { 24035fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian mChildFragmentManager.dispatchMultiWindowModeChanged(isInMultiWindowMode); 24045fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 24055fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 24065fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 24075fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian void performPictureInPictureModeChanged(boolean isInPictureInPictureMode) { 24085fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian onPictureInPictureModeChanged(isInPictureInPictureMode); 24095fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian if (mChildFragmentManager != null) { 24105fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian mChildFragmentManager.dispatchPictureInPictureModeChanged(isInPictureInPictureMode); 24115fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 24125fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 24135fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 24140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performConfigurationChanged(Configuration newConfig) { 24150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onConfigurationChanged(newConfig); 24160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchConfigurationChanged(newConfig); 24180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performLowMemory() { 24220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onLowMemory(); 24230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchLowMemory(); 24250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /* 24290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performTrimMemory(int level) { 24300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onTrimMemory(level); 24310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchTrimMemory(level); 24330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 24360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performCreateOptionsMenu(Menu menu, MenuInflater inflater) { 24380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean show = false; 24390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 24400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 24410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show = true; 24420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onCreateOptionsMenu(menu, inflater); 24430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show |= mChildFragmentManager.dispatchCreateOptionsMenu(menu, inflater); 24460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return show; 24490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performPrepareOptionsMenu(Menu menu) { 24520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean show = false; 24530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 24540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 24550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show = true; 24560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onPrepareOptionsMenu(menu); 24570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show |= mChildFragmentManager.dispatchPrepareOptionsMenu(menu); 24600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return show; 24630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performOptionsItemSelected(MenuItem item) { 24660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 24670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 24680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (onOptionsItemSelected(item)) { 24690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 24700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager.dispatchOptionsItemSelected(item)) { 24740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 24750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return false; 24790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performContextItemSelected(MenuItem item) { 24820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 24830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (onContextItemSelected(item)) { 24840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 24850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager.dispatchContextItemSelected(item)) { 24880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 24890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return false; 24930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performOptionsMenuClosed(Menu menu) { 24960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 24970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 24980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onOptionsMenuClosed(menu); 24990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchOptionsMenuClosed(menu); 25020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 25060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performSaveInstanceState(Bundle outState) { 25070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onSaveInstanceState(outState); 25080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Parcelable p = mChildFragmentManager.saveAllState(); 25100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (p != null) { 25110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn outState.putParcelable(FragmentActivity.FRAGMENTS_TAG, p); 25120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 25160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performPause() { 25170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchPause(); 25190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 252020735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = STARTED; 25210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 25220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onPause(); 25230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 25240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 25250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onPause()"); 25260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 2529cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn void performStop() { 25300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStop(); 25320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 253320735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = STOPPED; 25340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 2535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn onStop(); 25360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 25370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 25380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onStop()"); 25390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2540681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn } 2541681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn 2542218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn void performReallyStop() { 25430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchReallyStop(); 25450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 254620735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = ACTIVITY_CREATED; 2547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoadersStarted) { 2548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoadersStarted = false; 2549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!mCheckedForLoaderManager) { 2550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCheckedForLoaderManager = true; 2551d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false); 2552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoaderManager != null) { 255464ece2df3d6d789f7a642692acbe85fa1b998d6bTodd Kennedy if (mHost.getRetainLoaders()) { 2555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoaderManager.doRetain(); 25562bdd09a243b422960168170e2344274cc9cfd788Todd Kennedy } else { 25572bdd09a243b422960168170e2344274cc9cfd788Todd Kennedy mLoaderManager.doStop(); 2558cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2561cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 25629c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 25639c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void performDestroyView() { 25640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchDestroyView(); 25660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 256720735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = CREATED; 25680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 25699c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn onDestroyView(); 25700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 25710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 25720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onDestroyView()"); 25730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25749c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn if (mLoaderManager != null) { 25759c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mLoaderManager.doReportNextStart(); 25769c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 257737149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell mPerformedCreateView = false; 25789c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 25790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 25800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performDestroy() { 25810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchDestroy(); 25830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 258420735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = INITIALIZING; 25850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 25860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onDestroy(); 25870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 25880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 25890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onDestroy()"); 25900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25914706c089880423ee5929d4635c6dfc5c3151b20fGeorge Mount mChildFragmentManager = null; 25920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25939375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell 2594916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell void performDetach() { 2595916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell mCalled = false; 2596916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell onDetach(); 25978b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount mLayoutInflater = null; 2598916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell if (!mCalled) { 2599916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell throw new SuperNotCalledException("Fragment " + this 2600916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell + " did not call through to super.onDetach()"); 2601916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell } 2602916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell 2603916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell // Destroy the child FragmentManager if we still have it here. 2604916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell // We won't unless we're retaining our instance and if we do, 2605916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell // our child FragmentManager instance state will have already been saved. 2606916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell if (mChildFragmentManager != null) { 2607916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell if (!mRetaining) { 2608916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell throw new IllegalStateException("Child FragmentManager of " + this + " was not " 2609916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell + " destroyed and this fragment is not retaining instance"); 2610916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell } 2611916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell mChildFragmentManager.dispatchDestroy(); 2612916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell mChildFragmentManager = null; 2613916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell } 2614916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell } 2615916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell 2616990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setOnStartEnterTransitionListener(OnStartEnterTransitionListener listener) { 2617990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo(); 2618990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (listener == mAnimationInfo.mStartEnterTransitionListener) { 2619990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return; 2620990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2621990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (listener != null && mAnimationInfo.mStartEnterTransitionListener != null) { 2622990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount throw new IllegalStateException("Trying to set a replacement " 2623990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount + "startPostponedEnterTransition on " + this); 2624990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2625990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo.mEnterTransitionPostponed) { 2626990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mStartEnterTransitionListener = listener; 2627990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2628990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (listener != null) { 2629990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount listener.startListening(); 2630990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2631990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2632990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2633990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private AnimationInfo ensureAnimationInfo() { 2634990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2635990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo = new AnimationInfo(); 2636990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2637990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo; 2638990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2639990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2640990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int getNextAnim() { 2641990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2642990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return 0; 2643990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2644990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mNextAnim; 2645990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2646990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2647990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setNextAnim(int animResourceId) { 2648990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null && animResourceId == 0) { 2649990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return; // no change! 2650990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2651990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mNextAnim = animResourceId; 2652990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2653990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2654990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int getNextTransition() { 2655990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2656990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return 0; 2657990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2658990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mNextTransition; 2659990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2660990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2661990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setNextTransition(int nextTransition, int nextTransitionStyle) { 2662990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null && nextTransition == 0 && nextTransitionStyle == 0) { 2663990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return; // no change! 2664990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2665990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo(); 2666990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mNextTransition = nextTransition; 2667990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mNextTransitionStyle = nextTransitionStyle; 2668990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2669990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2670990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int getNextTransitionStyle() { 2671990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2672990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return 0; 2673990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2674990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mNextTransitionStyle; 2675990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2676990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2677990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount SharedElementCallback getEnterTransitionCallback() { 2678990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2679990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2680990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2681990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mEnterTransitionCallback; 2682990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2683990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2684990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount SharedElementCallback getExitTransitionCallback() { 2685990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2686990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2687990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2688990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mExitTransitionCallback; 2689990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2690990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2691990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount View getAnimatingAway() { 2692990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2693990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2694990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2695990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mAnimatingAway; 2696990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2697990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2698990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setAnimatingAway(View view) { 2699990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mAnimatingAway = view; 2700990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2701990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 270215e593ea3575512d7072240d1db9d74fad8749a3George Mount void setAnimator(Animator animator) { 270315e593ea3575512d7072240d1db9d74fad8749a3George Mount ensureAnimationInfo().mAnimator = animator; 270415e593ea3575512d7072240d1db9d74fad8749a3George Mount } 270515e593ea3575512d7072240d1db9d74fad8749a3George Mount 270615e593ea3575512d7072240d1db9d74fad8749a3George Mount Animator getAnimator() { 270715e593ea3575512d7072240d1db9d74fad8749a3George Mount if (mAnimationInfo == null) { 270815e593ea3575512d7072240d1db9d74fad8749a3George Mount return null; 270915e593ea3575512d7072240d1db9d74fad8749a3George Mount } 271015e593ea3575512d7072240d1db9d74fad8749a3George Mount return mAnimationInfo.mAnimator; 271115e593ea3575512d7072240d1db9d74fad8749a3George Mount } 271215e593ea3575512d7072240d1db9d74fad8749a3George Mount 2713990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int getStateAfterAnimating() { 2714990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2715990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return 0; 2716990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2717990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mStateAfterAnimating; 2718990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2719990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2720990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setStateAfterAnimating(int state) { 2721990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mStateAfterAnimating = state; 2722990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2723990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2724990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount boolean isPostponed() { 2725990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2726990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return false; 2727990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2728990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mEnterTransitionPostponed; 2729990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2730990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2731667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount boolean isHideReplaced() { 2732667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount if (mAnimationInfo == null) { 2733667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount return false; 2734667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount } 2735667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount return mAnimationInfo.mIsHideReplaced; 2736667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount } 2737667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount 2738667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount void setHideReplaced(boolean replaced) { 2739667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount ensureAnimationInfo().mIsHideReplaced = replaced; 2740667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount } 2741667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount 2742990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2743990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Used internally to be notified when {@link #startPostponedEnterTransition()} has 2744990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * been called. This listener will only be called once and then be removed from the 2745990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * listeners. 2746990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2747990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount interface OnStartEnterTransitionListener { 2748990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void onStartEnterTransition(); 2749990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void startListening(); 2750990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2751990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2752990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2753990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Contains all the animation and transition information for a fragment. This will only 2754990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * be instantiated for Fragments that have Views. 2755990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2756990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount static class AnimationInfo { 2757990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // Non-null if the fragment's view hierarchy is currently animating away, 2758990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // meaning we need to wait a bit on completely destroying it. This is the 2759990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // view that is animating. 2760990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount View mAnimatingAway; 2761990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 276215e593ea3575512d7072240d1db9d74fad8749a3George Mount // Non-null if the fragment's view hierarchy is currently animating away with an 276315e593ea3575512d7072240d1db9d74fad8749a3George Mount // animator instead of an animation. 276415e593ea3575512d7072240d1db9d74fad8749a3George Mount Animator mAnimator; 276515e593ea3575512d7072240d1db9d74fad8749a3George Mount 2766990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // If mAnimatingAway != null, this is the state we should move to once the 2767990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // animation is done. 2768990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int mStateAfterAnimating; 2769990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2770990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // If app has requested a specific animation, this is the one to use. 2771990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int mNextAnim; 2772990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2773990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // If app has requested a specific transition, this is the one to use. 2774990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int mNextTransition; 2775990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2776990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // If app has requested a specific transition style, this is the one to use. 2777990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int mNextTransitionStyle; 2778990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2779990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mEnterTransition = null; 2780990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mReturnTransition = USE_DEFAULT_TRANSITION; 2781990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mExitTransition = null; 2782990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mReenterTransition = USE_DEFAULT_TRANSITION; 2783990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mSharedElementEnterTransition = null; 2784990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mSharedElementReturnTransition = USE_DEFAULT_TRANSITION; 2785990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Boolean mAllowReturnTransitionOverlap; 2786990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Boolean mAllowEnterTransitionOverlap; 2787990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2788990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount SharedElementCallback mEnterTransitionCallback = null; 2789990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount SharedElementCallback mExitTransitionCallback = null; 2790990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2791990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // True when postponeEnterTransition has been called and startPostponeEnterTransition 2792990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // hasn't been called yet. 2793990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount boolean mEnterTransitionPostponed; 2794990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2795990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // Listener to wait for startPostponeEnterTransition. After being called, it will 2796990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // be set to null 2797990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount OnStartEnterTransitionListener mStartEnterTransitionListener; 2798990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2799667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount // True if the View was hidden, but the transition is handling the hide 2800667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount boolean mIsHideReplaced; 2801990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2802cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn} 2803