Fragment.java revision 20735a45289fdad3d5d31228992e0dccd3d5dd4f
1cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/* 2cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Copyright (C) 2011 The Android Open Source Project 3cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 4cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License"); 5cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * you may not use this file except in compliance with the License. 6cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * You may obtain a copy of the License at 7cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 8cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * http://www.apache.org/licenses/LICENSE-2.0 9cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 10cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Unless required by applicable law or agreed to in writing, software 11cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS, 12cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * See the License for the specific language governing permissions and 14cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * limitations under the License. 15cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 16cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 17cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornpackage android.support.v4.app; 18cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 19cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.app.Activity; 20cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.ComponentCallbacks; 21cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Context; 22cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Intent; 23cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Configuration; 24cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Resources; 25cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Bundle; 26cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcel; 27cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcelable; 28e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslavimport android.support.annotation.NonNull; 29a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbyeimport android.support.annotation.Nullable; 30a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbyeimport android.support.annotation.StringRes; 312290993eddf5262a8df7fc9478daed52401e325aDianne Hackbornimport android.support.v4.util.SimpleArrayMap; 32cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.support.v4.util.DebugUtils; 33bf0947be2ead9b3d8e5865bcd3d3652d02a2aa5aChris Banesimport android.support.v4.view.LayoutInflaterCompat; 34cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.AttributeSet; 35be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackbornimport android.util.Log; 36cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.SparseArray; 37cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ContextMenu; 38cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.LayoutInflater; 39cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.Menu; 40cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuInflater; 41cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuItem; 42cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View; 43cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ViewGroup; 44cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ContextMenu.ContextMenuInfo; 45cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View.OnCreateContextMenuListener; 46cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.animation.Animation; 47cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.widget.AdapterView; 48cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 49cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.FileDescriptor; 50cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.PrintWriter; 51cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 52cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornfinal class FragmentState implements Parcelable { 53cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final String mClassName; 54cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int mIndex; 55cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final boolean mFromLayout; 56cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int mFragmentId; 57cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int mContainerId; 58cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final String mTag; 59cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final boolean mRetainInstance; 60e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn final boolean mDetached; 61cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final Bundle mArguments; 62340a183c3293d98842e4a2671b500e8e80258818Todd Kennedy final boolean mHidden; 63cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 64cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Bundle mSavedFragmentState; 65cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 66cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment mInstance; 67cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 68cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentState(Fragment frag) { 69cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mClassName = frag.getClass().getName(); 70cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = frag.mIndex; 71cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mFromLayout = frag.mFromLayout; 72cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mFragmentId = frag.mFragmentId; 73cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mContainerId = frag.mContainerId; 74cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTag = frag.mTag; 75cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mRetainInstance = frag.mRetainInstance; 76e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn mDetached = frag.mDetached; 77cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mArguments = frag.mArguments; 78340a183c3293d98842e4a2671b500e8e80258818Todd Kennedy mHidden = frag.mHidden; 79cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 80cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 81cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentState(Parcel in) { 82cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mClassName = in.readString(); 83cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = in.readInt(); 84cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mFromLayout = in.readInt() != 0; 85cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mFragmentId = in.readInt(); 86cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mContainerId = in.readInt(); 87cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTag = in.readString(); 88cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mRetainInstance = in.readInt() != 0; 89e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn mDetached = in.readInt() != 0; 90cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mArguments = in.readBundle(); 91340a183c3293d98842e4a2671b500e8e80258818Todd Kennedy mHidden = in.readInt() != 0; 92cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mSavedFragmentState = in.readBundle(); 93cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 94d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 958491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy public Fragment instantiate(FragmentHostCallback host, Fragment parent) { 96cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mInstance != null) { 97cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mInstance; 98cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 99d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 100d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy final Context context = host.getContext(); 101cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mArguments != null) { 102d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mArguments.setClassLoader(context.getClassLoader()); 103cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 104d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 105d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mInstance = Fragment.instantiate(context, mClassName, mArguments); 106d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 107cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedFragmentState != null) { 108d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mSavedFragmentState.setClassLoader(context.getClassLoader()); 109cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mSavedFragmentState = mSavedFragmentState; 110cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mInstance.setIndex(mIndex, parent); 112cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mFromLayout = mFromLayout; 113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mRestored = true; 114cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mFragmentId = mFragmentId; 115cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mContainerId = mContainerId; 116cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mTag = mTag; 117cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInstance.mRetainInstance = mRetainInstance; 118e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn mInstance.mDetached = mDetached; 119340a183c3293d98842e4a2671b500e8e80258818Todd Kennedy mInstance.mHidden = mHidden; 120d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mInstance.mFragmentManager = host.mFragmentManager; 121be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn 122be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn if (FragmentManagerImpl.DEBUG) Log.v(FragmentManagerImpl.TAG, 123be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn "Instantiated fragment " + mInstance); 124be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn 125cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mInstance; 126cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 127d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 128cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public int describeContents() { 129cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return 0; 130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 131cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void writeToParcel(Parcel dest, int flags) { 133cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeString(mClassName); 134cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mIndex); 135cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mFromLayout ? 1 : 0); 136cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mFragmentId); 137cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mContainerId); 138cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeString(mTag); 139cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mRetainInstance ? 1 : 0); 140e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn dest.writeInt(mDetached ? 1 : 0); 141cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeBundle(mArguments); 142340a183c3293d98842e4a2671b500e8e80258818Todd Kennedy dest.writeInt(mHidden? 1 : 0); 143cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeBundle(mSavedFragmentState); 144cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 145cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 146cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public static final Parcelable.Creator<FragmentState> CREATOR 147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn = new Parcelable.Creator<FragmentState>() { 148cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentState createFromParcel(Parcel in) { 149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return new FragmentState(in); 150cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 151cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 152cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentState[] newArray(int size) { 153cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return new FragmentState[size]; 154cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 155cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn }; 156cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn} 157cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 158cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/** 159cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Static library support version of the framework's {@link android.app.Fragment}. 160cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Used to write apps that run on platforms prior to Android 3.0. When running 161cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on Android 3.0 or above, this implementation is still used; it does not try 1629dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * to switch to the framework's implementation. See the framework {@link android.app.Fragment} 163cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * documentation for a class overview. 1649dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * 1659dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <p>The main differences when using this support version instead of the framework version are: 1669dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <ul> 1679dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <li>Your activity must extend {@link FragmentActivity} 1689dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <li>You must call {@link FragmentActivity#getSupportFragmentManager} to get the 1699dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * {@link FragmentManager} 1709dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * </ul> 1719dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * 172cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornpublic class Fragment implements ComponentCallbacks, OnCreateContextMenuListener { 1742290993eddf5262a8df7fc9478daed52401e325aDianne Hackborn private static final SimpleArrayMap<String, Class<?>> sClassMap = 1752290993eddf5262a8df7fc9478daed52401e325aDianne Hackborn new SimpleArrayMap<String, Class<?>>(); 1769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 1779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount static final Object USE_DEFAULT_TRANSITION = new Object(); 1789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 179cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int INITIALIZING = 0; // Not yet created. 180cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int CREATED = 1; // Created. 181cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int ACTIVITY_CREATED = 2; // The activity has finished its creation. 182e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn static final int STOPPED = 3; // Fully created, not started. 183e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn static final int STARTED = 4; // Created and started, not resumed. 184e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn static final int RESUMED = 5; // Created started and resumed. 185cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 186cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mState = INITIALIZING; 187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 188cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Non-null if the fragment's view hierarchy is currently animating away, 189cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // meaning we need to wait a bit on completely destroying it. This is the 190cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // view that is animating. 191cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn View mAnimatingAway; 192cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 193cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If mAnimatingAway != null, this is the state we should move to once the 194cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // animation is done. 195cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mStateAfterAnimating; 196cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 197cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // When instantiated from saved state, this is the saved state. 198cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Bundle mSavedFragmentState; 199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn SparseArray<Parcelable> mSavedViewState; 200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Index into active fragment array. 202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mIndex = -1; 203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Internal unique name for this fragment; 205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn String mWho; 206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 207cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Construction arguments; 208cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Bundle mArguments; 209cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 210cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Target fragment. 211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment mTarget; 212cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 2132c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn // For use when retaining a fragment: this is the index of the last mTarget. 2142c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn int mTargetIndex = -1; 2152c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn 216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Target request code. 217cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mTargetRequestCode; 218cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 219cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // True if the fragment is in the list of added fragments. 220cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mAdded; 221cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment is being removed from its activity. 223cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRemoving; 224cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 225cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true if this fragment was instantiated from a layout file. 226cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mFromLayout; 227cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 228cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true when the view has actually been inflated in its layout. 229cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mInLayout; 230cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 231cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // True if this fragment has been restored from previously saved state. 232cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRestored; 233d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 234cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Number of active back stack entries this fragment is in. 235cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mBackStackNesting; 236d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 237cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The fragment manager we are associated with. Set as soon as the 238cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // fragment is used in a transaction; cleared after it has been removed 239cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // from all transactions. 240abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell FragmentManagerImpl mFragmentManager; 241cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 242d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy // Host this fragment is attached to. 2438491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy FragmentHostCallback mHost; 2440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 2450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn // Private fragment manager for child fragments inside of this one. 2460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn FragmentManagerImpl mChildFragmentManager; 2470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 2480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn // If this Fragment is contained in another Fragment, this is that container. 2490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Fragment mParentFragment; 2500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The optional identifier for this fragment -- either the container ID if it 252cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // was dynamically added to the view hierarchy, or the ID supplied in 253cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // layout. 254cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mFragmentId; 255cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 256cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // When a fragment is being dynamically added to the view hierarchy, this 257cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // is the identifier of the parent container it is being added to. 258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mContainerId; 259cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 260cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The optional named tag for this fragment -- usually used to find 261cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // fragments that are not part of the layout. 262cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn String mTag; 263cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 264cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true when the app has requested that this fragment be hidden 265cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // from the user. 266cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mHidden; 267cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 268e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn // Set to true when the app has requested that this fragment be deactivated. 269e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn boolean mDetached; 270e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 271cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment would like its instance retained across 272cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // configuration changes. 273cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRetainInstance; 2742bdd09a243b422960168170e2344274cc9cfd788Todd Kennedy 275cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment is being retained across the current config change. 276cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRetaining; 277cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 278cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment has menu items to contribute. 279cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mHasMenu; 2802a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 2812a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn // Set to true to allow the fragment's menu to be shown. 2822a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn boolean mMenuVisible = true; 2832a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 284cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Used to verify that subclasses call through to super class. 285cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mCalled; 286cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 287cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If app has requested a specific animation, this is the one to use. 288cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mNextAnim; 289cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 290cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The parent container of the fragment after dynamically added to UI. 291cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn ViewGroup mContainer; 292cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 293cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The View generated for this fragment. 294cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn View mView; 295cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 296cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The real inner view that will save/restore state. 297cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn View mInnerView; 298abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 299abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell // Whether this fragment should defer starting until after other fragments 300abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell // have been started and their loaders are finished. 301abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell boolean mDeferStart; 30279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell 30379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell // Hint provided by the app that this fragment is currently visible to the user. 30479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell boolean mUserVisibleHint = true; 305abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 306cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn LoaderManagerImpl mLoaderManager; 307cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mLoadersStarted; 308cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mCheckedForLoaderManager; 3099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 3109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Object mEnterTransition = null; 3119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Object mReturnTransition = USE_DEFAULT_TRANSITION; 3129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Object mExitTransition = null; 3139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Object mReenterTransition = USE_DEFAULT_TRANSITION; 3149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Object mSharedElementEnterTransition = null; 3159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Object mSharedElementReturnTransition = USE_DEFAULT_TRANSITION; 3169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Boolean mAllowReturnTransitionOverlap; 3179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount Boolean mAllowEnterTransitionOverlap; 3189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 3199306f07b1d66f4974a81f781d29739b30124fff0George Mount SharedElementCallback mEnterTransitionCallback = null; 3209306f07b1d66f4974a81f781d29739b30124fff0George Mount SharedElementCallback mExitTransitionCallback = null; 3219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 322cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 3235c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * State information that has been retrieved from a fragment instance 3245c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * through {@link FragmentManager#saveFragmentInstanceState(Fragment) 3255c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * FragmentManager.saveFragmentInstanceState}. 3265c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 3275c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public static class SavedState implements Parcelable { 3285c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn final Bundle mState; 3295c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3305c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn SavedState(Bundle state) { 3315c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState = state; 3325c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3335c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3345c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn SavedState(Parcel in, ClassLoader loader) { 3355c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState = in.readBundle(); 3365c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn if (loader != null && mState != null) { 3375c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState.setClassLoader(loader); 3385c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3395c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3405c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3415c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn @Override 3425c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public int describeContents() { 3435c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return 0; 3445c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3455c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3465c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn @Override 3475c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public void writeToParcel(Parcel dest, int flags) { 3485c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn dest.writeBundle(mState); 3495c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3505c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3515c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public static final Parcelable.Creator<SavedState> CREATOR 3525c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn = new Parcelable.Creator<SavedState>() { 353d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Override 3545c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public SavedState createFromParcel(Parcel in) { 3555c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return new SavedState(in, null); 3565c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3575c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 358d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Override 3595c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public SavedState[] newArray(int size) { 3605c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return new SavedState[size]; 3615c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3625c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn }; 3635c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3645c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3655c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 366cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when 367cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * there is an instantiation failure. 368cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 369cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static public class InstantiationException extends RuntimeException { 370cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public InstantiationException(String msg, Exception cause) { 371cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn super(msg, cause); 372cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 373cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 374cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 375cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 376cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Default constructor. <strong>Every</strong> fragment must have an 377cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * empty constructor, so it can be instantiated when restoring its 378cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * activity's state. It is strongly recommended that subclasses do not 379cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * have other constructors with parameters, since these constructors 380cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * will not be called when the fragment is re-instantiated; instead, 381cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * arguments can be supplied by the caller with {@link #setArguments} 382cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * and later retrieved by the Fragment with {@link #getArguments}. 383cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 384cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>Applications should generally not implement a constructor. The 385cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * first place application code an run where the fragment is ready to 386cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * be used is in {@link #onAttach(Activity)}, the point where the fragment 387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is actually associated with its activity. Some applications may also 388cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * want to implement {@link #onInflate} to retrieve attributes from a 389cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * layout resource, though should take care here because this happens for 390cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the fragment is attached to its activity. 391cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 392cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public Fragment() { 393cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 394cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 395cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 396cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Like {@link #instantiate(Context, String, Bundle)} but with a null 397cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * argument Bundle. 398cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 399cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public static Fragment instantiate(Context context, String fname) { 400cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return instantiate(context, fname, null); 401cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 402cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 403cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 404cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Create a new instance of a Fragment with the given class name. This is 405cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the same as calling its empty constructor. 406cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 407cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param context The calling context being used to instantiate the fragment. 408cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is currently just used to get its ClassLoader. 409cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fname The class name of the fragment to instantiate. 410cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param args Bundle of arguments to supply to the fragment, which it 411cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can retrieve with {@link #getArguments()}. May be null. 412cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return Returns a new fragment instance. 413cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @throws InstantiationException If there is a failure in instantiating 414cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the given fragment class. This is a runtime exception; it is not 415cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * normally expected to happen. 416cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 417c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy public static Fragment instantiate(Context context, String fname, @Nullable Bundle args) { 418cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn try { 419cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Class<?> clazz = sClassMap.get(fname); 420cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (clazz == null) { 421cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Class not found in the cache, see if it's real, and try to add it 422cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn clazz = context.getClassLoader().loadClass(fname); 423cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sClassMap.put(fname, clazz); 424cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 425cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment f = (Fragment)clazz.newInstance(); 426cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (args != null) { 427cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn args.setClassLoader(f.getClass().getClassLoader()); 428cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn f.mArguments = args; 429cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 430cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return f; 431cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (ClassNotFoundException e) { 432cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 433cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 434cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 435cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (java.lang.InstantiationException e) { 436cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 437cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 438cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 439cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (IllegalAccessException e) { 440cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 441cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 444cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4453fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell 4463fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell /** 4473fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * Determine if the given fragment name is a support library fragment class. 4483fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * 4493fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * @param context Context used to determine the correct ClassLoader to use 4503fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * @param fname Class name of the fragment to test 4513fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * @return true if <code>fname</code> is <code>android.support.v4.app.Fragment</code> 4523fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * or a subclass, false otherwise. 4533fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell */ 4543fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell static boolean isSupportFragmentClass(Context context, String fname) { 4553fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell try { 4563fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell Class<?> clazz = sClassMap.get(fname); 4573fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell if (clazz == null) { 4583fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell // Class not found in the cache, see if it's real, and try to add it 4593fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell clazz = context.getClassLoader().loadClass(fname); 4603fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell sClassMap.put(fname, clazz); 4613fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 4623fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell return Fragment.class.isAssignableFrom(clazz); 4633fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } catch (ClassNotFoundException e) { 4643fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell return false; 4653fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 4663fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 467cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 4680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final void restoreViewState(Bundle savedInstanceState) { 469cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedViewState != null) { 470cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInnerView.restoreHierarchyState(mSavedViewState); 471cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mSavedViewState = null; 472cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 4740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onViewStateRestored(savedInstanceState); 4750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 4760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 4770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onViewStateRestored()"); 4780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 479cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 4810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final void setIndex(int index, Fragment parent) { 482cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = index; 4830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (parent != null) { 4840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mWho = parent.mWho + ":" + mIndex; 4850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else { 4860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mWho = "android:fragment:" + mIndex; 4870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 488e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 4890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 490e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn final boolean isInBackStack() { 491e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn return mBackStackNesting > 0; 492e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 493e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 494cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 495cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Subclasses can not override equals(). 496cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 497cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override final public boolean equals(Object o) { 498cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return super.equals(o); 499cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 500cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 501cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 502cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Subclasses can not override hashCode(). 503cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 504cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override final public int hashCode() { 505cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return super.hashCode(); 506cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 507cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 508cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override 509cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public String toString() { 510cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn StringBuilder sb = new StringBuilder(128); 511cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn DebugUtils.buildShortClassTag(this, sb); 512cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mIndex >= 0) { 513cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" #"); 514cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(mIndex); 515cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 516cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mFragmentId != 0) { 517cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" id=0x"); 518cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(Integer.toHexString(mFragmentId)); 519cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 520cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mTag != null) { 521cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" "); 522cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(mTag); 523cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 524cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append('}'); 525cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return sb.toString(); 526cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 527cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 528cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 529cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the identifier this fragment is known by. This is either 530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the android:id value supplied in a layout or the container view ID 531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * supplied when adding the fragment. 532cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 533cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public int getId() { 534cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mFragmentId; 535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Get the tag name of the fragment, if specified. 539cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 540cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public String getTag() { 541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTag; 542cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 543cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Supply the construction arguments for this fragment. This can only 546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * be called before the fragment has been attached to its activity; that 547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is, you should call it immediately after constructing the fragment. The 548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * arguments supplied here will be retained across fragment destroy and 549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * creation. 550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 551cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setArguments(Bundle args) { 552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mIndex >= 0) { 553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment already active"); 554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mArguments = args; 556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 558cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the arguments supplied when the fragment was instantiated, 560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if any. 561cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 562cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public Bundle getArguments() { 563cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mArguments; 564cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 565cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 566cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 5675c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Set the initial saved state that this Fragment should restore itself 5685c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * from when first being constructed, as returned by 5695c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * {@link FragmentManager#saveFragmentInstanceState(Fragment) 5705c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * FragmentManager.saveFragmentInstanceState}. 5715c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * 5725c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param state The state the fragment should be restored from. 5735c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 5745c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public void setInitialSavedState(SavedState state) { 5755c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn if (mIndex >= 0) { 5765c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn throw new IllegalStateException("Fragment already active"); 5775c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 5785c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mSavedFragmentState = state != null && state.mState != null 5795c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn ? state.mState : null; 5805c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 5815c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 5825c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 583cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Optional target for this fragment. This may be used, for example, 584cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if this fragment is being started by another, and when done wants to 585cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * give a result back to the first. The target set here is retained 586cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * across instances via {@link FragmentManager#putFragment 587cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * FragmentManager.putFragment()}. 588cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 589cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fragment The fragment that is the target of this one. 590cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param requestCode Optional request code, for convenience if you 591cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * are going to call back with {@link #onActivityResult(int, int, Intent)}. 592cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 593cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setTargetFragment(Fragment fragment, int requestCode) { 594cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTarget = fragment; 595cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTargetRequestCode = requestCode; 596cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 597cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 598cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 599cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the target fragment set by {@link #setTargetFragment}. 600cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 601cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public Fragment getTargetFragment() { 602cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTarget; 603cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 604cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 605cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 606cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the target request code set by {@link #setTargetFragment}. 607cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 608cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public int getTargetRequestCode() { 609cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTargetRequestCode; 610cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 611cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 612cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 613d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Return the {@link Context} this fragment is currently associated with. 614d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy */ 615edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy public Context getContext() { 616d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy return mHost == null ? null : mHost.getContext(); 617d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 618d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 619d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy /** 620d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Return the {@link FragmentActivity} this fragment is currently associated with. 621d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * May return {@code null} if the fragment is associated with a {@link Context} 622d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * instead. 623cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 624cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public FragmentActivity getActivity() { 625d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy return mHost == null ? null : (FragmentActivity) mHost.getActivity(); 626cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 627d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 628cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 629edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy * Return the host object of this fragment. May return {@code null} if the fragment 630edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy * isn't currently being hosted. 631edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy */ 632edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy final public Object getHost() { 6338491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy return mHost == null ? null : mHost.onGetHost(); 634edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy } 635edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy 636edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy /** 637cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return <code>getActivity().getResources()</code>. 638cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 639cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public Resources getResources() { 640d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost == null) { 641cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 642cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 643d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy return mHost.getContext().getResources(); 644cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 645d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 646cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 647cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized, styled CharSequence from the application's package's 648cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table. 649cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 650cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the CharSequence text 651cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 652a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final CharSequence getText(@StringRes int resId) { 653cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getText(resId); 654cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 655cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 656cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 657cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized string from the application's package's 658cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table. 659cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 660cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the string 661cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 662a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final String getString(@StringRes int resId) { 663cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getString(resId); 664cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 665cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 666cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 667cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized formatted string from the application's package's 668cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table, substituting the format arguments as defined in 669cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link java.util.Formatter} and {@link java.lang.String#format}. 670cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 671cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the format string 672cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param formatArgs The format arguments that will be used for substitution. 673cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 674cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 675a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final String getString(@StringRes int resId, Object... formatArgs) { 676cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getString(resId, formatArgs); 677cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 678cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 679cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 680cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the FragmentManager for interacting with fragments associated 681cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * with this fragment's activity. Note that this will be non-null slightly 682cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * before {@link #getActivity()}, during the time from when the fragment is 683cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * placed in a {@link FragmentTransaction} until it is committed and 684cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * attached to its activity. 6850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 6860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * <p>If this Fragment is a child of another Fragment, the FragmentManager 6870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * returned here will be the parent's {@link #getChildFragmentManager()}. 688cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 689cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public FragmentManager getFragmentManager() { 690cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mFragmentManager; 691cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 692cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 6940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Return a private FragmentManager for placing and managing Fragments 6950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * inside of this Fragment. 6960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 6970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final public FragmentManager getChildFragmentManager() { 6980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager == null) { 6990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn instantiateChildFragmentManager(); 7000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mState >= RESUMED) { 7010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchResume(); 7020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= STARTED) { 7030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStart(); 7040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= ACTIVITY_CREATED) { 7050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchActivityCreated(); 7060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= CREATED) { 7070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchCreate(); 7080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 7090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 7100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mChildFragmentManager; 7110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 7120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 7130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 7140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Returns the parent Fragment containing this Fragment. If this Fragment 7150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * is attached directly to an Activity, returns null. 7160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 7170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final public Fragment getParentFragment() { 7180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mParentFragment; 7190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 7200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 7210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 722cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is currently added to its activity. 723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 724cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isAdded() { 725d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy return mHost != null && mAdded; 726cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 727cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 728cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 7299c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * Return true if the fragment has been explicitly detached from the UI. 7309c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * That is, {@link FragmentTransaction#detach(Fragment) 7319c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * FragmentTransaction.detach(Fragment)} has been used on it. 7329c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn */ 7339c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn final public boolean isDetached() { 7349c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn return mDetached; 7359c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 7369c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 7379c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn /** 738cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if this fragment is currently being removed from its 739cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * activity. This is <em>not</em> whether its activity is finishing, but 740cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * rather whether it is in the process of being removed from its activity. 741cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 742cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isRemoving() { 743cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mRemoving; 744cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 745cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 746cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 747cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the layout is included as part of an activity view 748cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * hierarchy via the <fragment> tag. This will always be true when 749cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * fragments are created through the <fragment> tag, <em>except</em> 750cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * in the case where an old fragment is restored from a previous state and 751cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * it does not appear in the layout of the current state. 752cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 753cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isInLayout() { 754cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mInLayout; 755cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 756cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 757cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 758cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is in the resumed state. This is true 759cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for the duration of {@link #onResume()} and {@link #onPause()} as well. 760cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 761cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isResumed() { 76220735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell return mState >= RESUMED; 763cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 764cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 765cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 766cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is currently visible to the user. This means 767cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * it: (1) has been added, (2) has its view attached to the window, and 768cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * (3) is not hidden. 769cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 770cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isVisible() { 771cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return isAdded() && !isHidden() && mView != null 772cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE; 773cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 774cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 775cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 776cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment has been hidden. By default fragments 777cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * are shown. You can find out about changes to this state with 778cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onHiddenChanged}. Note that the hidden state is orthogonal 779cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to other states -- that is, to be visible to the user, a fragment 780cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * must be both started and not hidden. 781cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 782cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isHidden() { 783cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mHidden; 784cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 7853a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 7863a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown /** @hide */ 7873a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown final public boolean hasOptionsMenu() { 7883a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown return mHasMenu; 7893a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown } 7903a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 7913a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown /** @hide */ 7923a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown final public boolean isMenuVisible() { 7933a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown return mMenuVisible; 7943a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown } 7953a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 796cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 797cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the hidden state (as returned by {@link #isHidden()} of 798cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the fragment has changed. Fragments start out not hidden; this will 799cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * be called whenever the fragment changes state from that. 800cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param hidden True if the fragment is now hidden, false if it is not 801cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * visible. 802cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 803cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onHiddenChanged(boolean hidden) { 804cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 805cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 806cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 807cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Control whether a fragment instance is retained across Activity 808cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * re-creation (such as from a configuration change). This can only 809cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * be used with fragments not in the back stack. If set, the fragment 810cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * lifecycle will be slightly different when an activity is recreated: 811cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <ul> 812cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still 813cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * will be, because the fragment is being detached from its current activity). 814cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onCreate(Bundle)} will not be called since the fragment 815cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is not being re-created. 816cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b> 817cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * still be called. 818cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * </ul> 819cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 820cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setRetainInstance(boolean retain) { 8210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (retain && mParentFragment != null) { 8220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new IllegalStateException( 8230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn "Can't retain fragements that are nested in other fragments"); 8240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 825cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mRetainInstance = retain; 826cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 827cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 828cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean getRetainInstance() { 829cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mRetainInstance; 830cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 831cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 832cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 833cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Report that this fragment would like to participate in populating 834cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the options menu by receiving a call to {@link #onCreateOptionsMenu} 835cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * and related methods. 836d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * 837cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param hasMenu If true, the fragment has menu items to contribute. 838cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 839cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setHasOptionsMenu(boolean hasMenu) { 840cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mHasMenu != hasMenu) { 841cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mHasMenu = hasMenu; 842cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (isAdded() && !isHidden()) { 8438491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy mHost.onSupportInvalidateOptionsMenu(); 844cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 845cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 846cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8472a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 8482a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn /** 8492a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * Set a hint for whether this fragment's menu should be visible. This 8502a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * is useful if you know that a fragment has been placed in your view 8512a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * hierarchy so that the user can not currently seen it, so any menu items 8522a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * it has should also not be shown. 8532a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * 8542a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * @param menuVisible The default is true, meaning the fragment's menu will 8552a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * be shown as usual. If false, the user will not see the menu. 8562a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn */ 8572a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn public void setMenuVisibility(boolean menuVisible) { 8582a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn if (mMenuVisible != menuVisible) { 8592a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn mMenuVisible = menuVisible; 8602a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn if (mHasMenu && isAdded() && !isHidden()) { 8618491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy mHost.onSupportInvalidateOptionsMenu(); 8622a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 8632a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 8642a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 8652a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 866cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 86779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * Set a hint to the system about whether this fragment's UI is currently visible 86879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * to the user. This hint defaults to true and is persistent across fragment instance 86979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * state save and restore. 870abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell * 87179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * <p>An app may set this to false to indicate that the fragment's UI is 87279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * scrolled out of visibility or is otherwise not directly visible to the user. 87379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * This may be used by the system to prioritize operations such as fragment lifecycle updates 87479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * or loader ordering behavior.</p> 875abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell * 87679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @param isVisibleToUser true if this fragment's UI is currently visible to the user (default), 87779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * false if it is not. 878abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell */ 87979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell public void setUserVisibleHint(boolean isVisibleToUser) { 88079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell if (!mUserVisibleHint && isVisibleToUser && mState < STARTED) { 881abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell mFragmentManager.performPendingDeferredStart(this); 882abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 88379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell mUserVisibleHint = isVisibleToUser; 88479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell mDeferStart = !isVisibleToUser; 885abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 886abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 887abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell /** 88879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @return The current value of the user-visible hint on this fragment. 88979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @see #setUserVisibleHint(boolean) 890abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell */ 89179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell public boolean getUserVisibleHint() { 89279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell return mUserVisibleHint; 893abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 894abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 895abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell /** 896cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the LoaderManager for this fragment, creating it if needed. 897cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 898cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public LoaderManager getLoaderManager() { 899cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoaderManager != null) { 900cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mLoaderManager; 901cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 902d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost == null) { 903cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 904cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 905cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCheckedForLoaderManager = true; 906d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, true); 907cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mLoaderManager; 908cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 909d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 910cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 9118491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy * Call {@link Activity#startActivity(Intent)} from the fragment's 912cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * containing Activity. 913cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 914cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void startActivity(Intent intent) { 915d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost == null) { 916cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 917cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9188491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy mHost.onStartActivityFromFragment(this /*fragment*/, intent, -1); 919cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 920d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 921cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 9228491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy * Call {@link Activity#startActivityForResult(Intent, int)} from the fragment's 923cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * containing Activity. 924cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 925cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void startActivityForResult(Intent intent, int requestCode) { 926d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost == null) { 927cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 928cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9298491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy mHost.onStartActivityFromFragment(this /*fragment*/, intent, requestCode); 930cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 931d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 932cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 933cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Receive the result from a previous call to 934cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #startActivityForResult(Intent, int)}. This follows the 935cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * related Activity API as described there in 936cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onActivityResult(int, int, Intent)}. 937d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * 938cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param requestCode The integer request code originally supplied to 939cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * startActivityForResult(), allowing you to identify who this 940cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * result came from. 941cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resultCode The integer result code returned by the child activity 942cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * through its setResult(). 943cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param data An Intent, which can return result data to the caller 944cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * (various data can be attached to Intent "extras"). 945cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 946cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onActivityResult(int requestCode, int resultCode, Intent data) { 947cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 948d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 949cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 950e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Requests permissions to be granted to this application. These permissions 951e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * must be requested in your manifest, they should not be granted to your app, 952e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * and they should have protection level {@link android.content.pm.PermissionInfo 953e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * #PROTECTION_DANGEROUS dangerous}, regardless whether they are declared by 954e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * the platform or a third-party app. 955e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 956e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Normal permissions {@link android.content.pm.PermissionInfo#PROTECTION_NORMAL} 957e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * are granted at install time if requested in the manifest. Signature permissions 958e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * {@link android.content.pm.PermissionInfo#PROTECTION_SIGNATURE} are granted at 959e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * install time if requested in the manifest and the signature of your app matches 960e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * the signature of the app declaring the permissions. 961e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 962e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 963e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * If your app does not have the requested permissions the user will be presented 964e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * with UI for accepting them. After the user has accepted or rejected the 965e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * requested permissions you will receive a callback on {@link 966e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * #onRequestPermissionsResult(int, String[], int[])} reporting whether the 967e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * permissions were granted or not. 968e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 969e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 970e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Note that requesting a permission does not guarantee it will be granted and 971e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * your app should be able to run without having this permission. 972e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 973e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 974e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * This method may start an activity allowing the user to choose which permissions 975e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * to grant and which to reject. Hence, you should be prepared that your activity 976e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * may be paused and resumed. Further, granting some permissions may require 977e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * a restart of you application. In such a case, the system will recreate the 978e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * activity stack before delivering the result to {@link 979e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * #onRequestPermissionsResult(int, String[], int[])}. 980e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 981e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 982e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * When checking whether you have a permission you should use {@link 983e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * android.content.Context#checkSelfPermission(String)}. 984e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 985e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 9862750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * Calling this API for permissions already granted to your app would show UI 9872750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * to the user to decided whether the app can still hold these permissions. This 9882750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * can be useful if the way your app uses the data guarded by the permissions 9892750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * changes significantly. 9902750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * </p> 9912750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * <p> 992e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * A sample permissions request looks like this: 993e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 994e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <code><pre><p> 995e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * private void showContacts() { 996e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * if (getActivity().checkSelfPermission(Manifest.permission.READ_CONTACTS) 997e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * != PackageManager.PERMISSION_GRANTED) { 998e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, 999e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * PERMISSIONS_REQUEST_READ_CONTACTS); 1000e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } else { 1001e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * doShowContacts(); 1002e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1003e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1004e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1005e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * {@literal @}Override 1006e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * public void onRequestPermissionsResult(int requestCode, String[] permissions, 1007e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * int[] grantResults) { 1008e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * if (requestCode == PERMISSIONS_REQUEST_READ_CONTACTS 1009e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 1010e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * doShowContacts(); 1011e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1012e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1013e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </code></pre></p> 1014e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1015e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param permissions The requested permissions. 1016e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param requestCode Application specific request code to match with a result 1017e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * reported to {@link #onRequestPermissionsResult(int, String[], int[])}. 1018e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1019e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #onRequestPermissionsResult(int, String[], int[]) 1020e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see android.content.Context#checkSelfPermission(String) 1021e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav */ 1022e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav public final void requestPermissions(@NonNull String[] permissions, int requestCode) { 1023e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav if (mHost == null) { 1024e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 1025e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1026e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav mHost.onRequestPermissionsFromFragment(this, permissions,requestCode); 1027e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1028e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav 1029e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /** 1030e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Callback for the result from requesting permissions. This method 1031e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * is invoked for every call on {@link #requestPermissions(String[], int)}. 1032dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * <p> 1033dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * <strong>Note:</strong> It is possible that the permissions request interaction 1034dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * with the user is interrupted. In this case you will receive empty permissions 1035dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * and results arrays which should be treated as a cancellation. 1036dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * </p> 1037e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1038e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}. 1039e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param permissions The requested permissions. Never null. 1040e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param grantResults The grant results for the corresponding permissions 1041e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * which is either {@link android.content.pm.PackageManager#PERMISSION_GRANTED} 1042e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * or {@link android.content.pm.PackageManager#PERMISSION_DENIED}. Never null. 1043e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1044e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #requestPermissions(String[], int) 1045e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav */ 1046e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, 1047e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav @NonNull int[] grantResults) { 1048e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /* callback - do nothing */ 1049e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1050e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav 1051e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /** 1052e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Gets whether you should show UI with rationale for requesting a permission. 1053e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * You should do this only if you do not have the permission and the context in 1054e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * which the permission is requested does not clearly communicate to the user 1055e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * what would be the benefit from granting this permission. 1056e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1057e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * For example, if you write a camera app, requesting the camera permission 1058e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * would be expected by the user and no rationale for why it is requested is 1059e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * needed. If however, the app needs location for tagging photos then a non-tech 1060e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * savvy user may wonder how location is related to taking photos. In this case 1061e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * you may choose to show UI with rationale of requesting this permission. 1062e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1063e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1064e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param permission A permission your app wants to request. 1065e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @return Whether you can show permission rationale UI. 1066e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1067e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see Context#checkSelfPermission(String) 1068e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #requestPermissions(String[], int) 1069e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #onRequestPermissionsResult(int, String[], int[]) 1070e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav */ 1071e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav public boolean shouldShowRequestPermissionRationale(@NonNull String permission) { 1072e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav if (mHost != null) { 1073e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav return mHost.onShouldShowRequestPermissionRationale(permission); 1074e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1075e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav return false; 1076e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1077e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav 1078e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /** 1079cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @hide Hack so that DialogFragment can make its Dialog before creating 1080cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * its views, and the view construction can use the dialog's context for 1081cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * inflation. Maybe this should become a public API. Note sure. 1082cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1083cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public LayoutInflater getLayoutInflater(Bundle savedInstanceState) { 10848491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy LayoutInflater result = mHost.onGetLayoutInflater(); 10850f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell getChildFragmentManager(); // Init if needed; use raw implementation below. 1086bf0947be2ead9b3d8e5865bcd3d3652d02a2aa5aChris Banes LayoutInflaterCompat.setFactory(result, mChildFragmentManager.getLayoutInflaterFactory()); 10870f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell return result; 1088cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1089d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1090cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1091cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a fragment is being created as part of a view layout 1092cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * inflation, typically from setting the content view of an activity. This 10939277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * may be called immediately after the fragment is created from a <fragment> 1094cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tag in a layout file. Note this is <em>before</em> the fragment's 1095cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onAttach(Activity)} has been called; all you should do here is 10969277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * parse the attributes and save them away. 1097cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1098cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>This is called every time the fragment is inflated, even if it is 10999277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * being inflated into a new instance with saved state. It typically makes 11009277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * sense to re-parse the parameters each time, to allow them to change with 11019277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * different configurations.</p> 11029277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 11039277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>Here is a typical implementation of a fragment that can take parameters 11049277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * both through attributes supplied here as well from {@link #getArguments()}:</p> 11059277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 11069277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java 11079277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * fragment} 11089277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 11099277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>Note that parsing the XML attributes uses a "styleable" resource. The 11109277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * declaration for the styleable used here is:</p> 11119277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 11129277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * {@sample development/samples/ApiDemos/res/values/attrs.xml fragment_arguments} 1113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 11149277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>The fragment can then be declared within its activity's content layout 11159277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * through a tag like this:</p> 11169277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 11179277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * {@sample development/samples/ApiDemos/res/layout/fragment_arguments.xml from_attributes} 11189277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 11199277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>This fragment can also be created dynamically from arguments given 11209277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * at runtime in the arguments Bundle; here is an example of doing so at 11219277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * creation of the containing activity:</p> 11229277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 11239277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java 11249277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * create} 11259277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 1126d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * @param context The Activity that is inflating this fragment. 1127cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param attrs The attributes at the tag where the fragment is 1128cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * being created. 1129cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 1130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 1131cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1132d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) { 1133d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = true; 1134d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy final Activity hostActivity = mHost == null ? null : mHost.getActivity(); 1135d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (hostActivity != null) { 1136d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = false; 1137d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy onInflate(hostActivity, attrs, savedInstanceState); 1138d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1139d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1140d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1141d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy /** 1142d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Called when a fragment is being created as part of a view layout 1143d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * inflation, typically from setting the content view of an activity. 1144d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * <p>Deprecated. See {@link #onInflate(Context, AttributeSet, Bundle)}. 1145d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy */ 1146d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Deprecated 11479277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { 1148cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 11509f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 1151cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1152d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Called when a fragment is first attached to its context. 1153d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * {@link #onCreate(Bundle)} will be called after this. 1154d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy */ 1155d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy public void onAttach(Context context) { 1156d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = true; 1157d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy final Activity hostActivity = mHost == null ? null : mHost.getActivity(); 1158d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (hostActivity != null) { 1159d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = false; 1160d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy onAttach(hostActivity); 1161d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1162d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1163d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1164d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy /** 1165cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a fragment is first attached to its activity. 1166cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreate(Bundle)} will be called after this. 1167d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * <p>Deprecated. See {@link #onAttach(Context)}. 1168cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1169d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Deprecated 1170cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onAttach(Activity activity) { 1171cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1172cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1173d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1174cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1175cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a fragment loads an animation. 1176cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 11779277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { 1178cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return null; 1179cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1180d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1181cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1182cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to do initial creation of a fragment. This is called after 1183cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onAttach(Activity)} and before 1184cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 1185cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1186cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>Note that this can be called while the fragment's activity is 1187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * still in the process of being created. As such, you can not rely 1188cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on things like the activity's content view hierarchy being initialized 1189cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * at this point. If you want to do work once the activity itself is 1190cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * created, see {@link #onActivityCreated(Bundle)}. 1191cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1192cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 1193cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 1194cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1195c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy public void onCreate(@Nullable Bundle savedInstanceState) { 1196cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1197cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 11980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to have the fragment instantiate its user interface view. 1201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is optional, and non-graphical fragments can return null (which 1202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is the default implementation). This will be called between 1203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}. 1204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>If you return a View from here, you will later be called in 1206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onDestroyView} when the view is being released. 1207cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1208cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param inflater The LayoutInflater object that can be used to inflate 1209cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * any views in the fragment, 1210cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param container If non-null, this is the parent view that the fragment's 1211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * UI should be attached to. The fragment should not add the view itself, 1212cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * but this can be used to generate the LayoutParams of the view. 1213cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If non-null, this fragment is being re-constructed 1214cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * from a previous saved state as given here. 1215cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return Return the View for the fragment's UI, or null. 1217cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1218c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy @Nullable 1219a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, 1220a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye @Nullable Bundle savedInstanceState) { 1221cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return null; 1222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 12230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1224cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1225e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} 1226e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * has returned, but before any saved state has been restored in to the view. 1227e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * This gives subclasses a chance to initialize themselves once 1228e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * they know their view hierarchy has been completely created. The fragment's 1229e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * view hierarchy is not however attached to its parent at this point. 1230e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 1231e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * @param savedInstanceState If non-null, this fragment is being re-constructed 1232e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * from a previous saved state as given here. 1233e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn */ 1234a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 1235e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 1236e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 1237e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn /** 1238cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}), 1239cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if provided. 1240cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1241cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return The fragment's root view, or null if it has no layout. 1242cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1243a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye @Nullable 1244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public View getView() { 1245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mView; 1246cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment's activity has been created and this 1250cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * fragment's view hierarchy instantiated. It can be used to do final 1251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * initialization once these pieces are in place, such as retrieving 1252cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * views or restoring state. It is also useful for fragments that use 1253cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #setRetainInstance(boolean)} to retain their instance, 1254cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * as this callback tells the fragment when it is fully associated with 1255cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the new activity instance. This is called after {@link #onCreateView} 12560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * and before {@link #onViewStateRestored(Bundle)}. 12570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 1258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 1259cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 1260cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1261a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public void onActivityCreated(@Nullable Bundle savedInstanceState) { 1262cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1263cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 12640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 12650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 12660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Called when all saved state has been restored into the view hierarchy 12670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * of the fragment. This can be used to do initialization based on saved 12680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * state that you are letting the view hierarchy track itself, such as 12690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * whether check box widgets are currently checked. This is called 12700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * after {@link #onActivityCreated(Bundle)} and before 12710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * {@link #onStart()}. 12720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 12730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 12740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * a previous saved state, this is the state. 12750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 1276a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public void onViewStateRestored(@Nullable Bundle savedInstanceState) { 12770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = true; 12780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 12790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1280cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1281cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is visible to the user. This is generally 1282cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onStart() Activity.onStart} of the containing 1283cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1284cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1285cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onStart() { 1286cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1287d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1288cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!mLoadersStarted) { 1289cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoadersStarted = true; 1290cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!mCheckedForLoaderManager) { 1291cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCheckedForLoaderManager = true; 1292d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false); 1293cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1294cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoaderManager != null) { 1295cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoaderManager.doStart(); 1296cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1297cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1298cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1299d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1300cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1301cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is visible to the user and actively running. 1302cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is generally 1303cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onResume() Activity.onResume} of the containing 1304cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1305cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1306cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onResume() { 1307cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1308cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1309cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1310cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1311cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to ask the fragment to save its current dynamic state, so it 1312cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can later be reconstructed in a new instance of its process is 1313cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * restarted. If a new instance of the fragment later needs to be 1314cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * created, the data you place in the Bundle here will be available 1315cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * in the Bundle given to {@link #onCreate(Bundle)}, 1316cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}, and 1317cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onActivityCreated(Bundle)}. 1318cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1319cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>This corresponds to {@link Activity#onSaveInstanceState(Bundle) 1320cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity.onSaveInstanceState(Bundle)} and most of the discussion there 1321cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * applies here as well. Note however: <em>this method may be called 1322cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * at any time before {@link #onDestroy()}</em>. There are many situations 1323cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * where a fragment may be mostly torn down (such as when placed on the 1324cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * back stack with no UI showing), but its state will not be saved until 1325cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * its owning activity actually needs to save its state. 1326cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1327cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param outState Bundle in which to place your saved state. 1328cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1329cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onSaveInstanceState(Bundle outState) { 1330cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1331cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1332cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onConfigurationChanged(Configuration newConfig) { 1333cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1334cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1335cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1336cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1337cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is no longer resumed. This is generally 1338cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onPause() Activity.onPause} of the containing 1339cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1340cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1341cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onPause() { 1342cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1343cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1344cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1345cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1346cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is no longer started. This is generally 1347cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onStop() Activity.onStop} of the containing 1348cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1349cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1350cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onStop() { 1351cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1352cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1353cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1354cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onLowMemory() { 1355cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1356cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1357cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1358cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1359cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the view previously created by {@link #onCreateView} has 1360cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * been detached from the fragment. The next time the fragment needs 1361cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to be displayed, a new view will be created. This is called 1362cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * after {@link #onStop()} and before {@link #onDestroy()}. It is called 1363cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <em>regardless</em> of whether {@link #onCreateView} returned a 1364cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * non-null view. Internally it is called after the view's state has 1365cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * been saved but before it has been removed from its parent. 1366cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1367cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroyView() { 1368cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1369cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1370cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1371cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1372cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is no longer in use. This is called 1373cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * after {@link #onStop()} and before {@link #onDetach()}. 1374cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1375cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroy() { 1376cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1377cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn //Log.v("foo", "onDestroy: mCheckedForLoaderManager=" + mCheckedForLoaderManager 1378cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // + " mLoaderManager=" + mLoaderManager); 1379cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!mCheckedForLoaderManager) { 1380cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCheckedForLoaderManager = true; 1381d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false); 1382cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1383cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoaderManager != null) { 1384cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoaderManager.doDestroy(); 1385cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1386cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1388cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 13899c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * Called by the fragment manager once this fragment has been removed, 13909c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * so that we don't have any left-over state if the application decides 13919c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * to re-use the instance. This only clears state that the framework 13929c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * internally manages, not things the application sets. 13939c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn */ 13949c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void initState() { 13959c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mIndex = -1; 13969c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mWho = null; 13979c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mAdded = false; 13989c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRemoving = false; 13999c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFromLayout = false; 14009c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mInLayout = false; 14019c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRestored = false; 14029c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mBackStackNesting = 0; 14039c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFragmentManager = null; 14046252d78085a07c9d6bb4645a4e8086bf23b0a49aTim Kilbourn mChildFragmentManager = null; 1405d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mHost = null; 14069c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFragmentId = 0; 14079c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mContainerId = 0; 14089c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mTag = null; 14099c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mHidden = false; 14109c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mDetached = false; 14119c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRetaining = false; 14129c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mLoaderManager = null; 14139c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mLoadersStarted = false; 14149c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mCheckedForLoaderManager = false; 14159c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 14169c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 14179c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn /** 1418cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is no longer attached to its activity. This 1419cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is called after {@link #onDestroy()}. 1420cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1421cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDetach() { 1422cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1423cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1424cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1425cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1426cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Initialize the contents of the Activity's standard options menu. You 1427cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * should place your menu items in to <var>menu</var>. For this method 1428cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to be called, you must have first called {@link #setHasOptionsMenu}. See 1429cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu} 1430cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for more information. 1431cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1432cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu in which you place your items. 1433cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1434cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #setHasOptionsMenu 1435cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onPrepareOptionsMenu 1436cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onOptionsItemSelected 1437cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1438cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 1439cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1440cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1441cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Prepare the Screen's standard options menu to be displayed. This is 1443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * called right before the menu is shown, every time it is shown. You can 1444cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * use this method to efficiently enable/disable items or otherwise 1445cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * dynamically modify the contents. See 1446cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu} 1447cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for more information. 1448cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu as last shown or first initialized by 1450cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * onCreateOptionsMenu(). 1451cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1452cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #setHasOptionsMenu 1453cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onCreateOptionsMenu 1454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onPrepareOptionsMenu(Menu menu) { 1456cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1457cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1458cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1459cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when this fragment's option menu items are no longer being 1460cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * included in the overall options menu. Receiving this call means that 1461cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the menu needed to be rebuilt, but this fragment's items were not 1462cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * included in the newly built menu (its {@link #onCreateOptionsMenu(Menu, MenuInflater)} 1463cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * was not called). 1464cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1465cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroyOptionsMenu() { 1466cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1467cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1468cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1469cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever an item in your options menu is selected. 1470cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * The default implementation simply returns false to have the normal 1471cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * processing happen (calling the item's Runnable or sending a message to 1472cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * its Handler as appropriate). You can use this method for any items 1473cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for which you would like to do processing without those other 1474cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * facilities. 1475cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1476cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>Derived classes should call through to the base class for it to 1477cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * perform the default menu handling. 1478cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1479cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param item The menu item that was selected. 1480cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1481cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return boolean Return false to allow normal menu processing to 1482cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * proceed, true to consume it here. 1483cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1484cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onCreateOptionsMenu 1485cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1486cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public boolean onOptionsItemSelected(MenuItem item) { 1487cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return false; 1488cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1489cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1490cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1491cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever the options menu is being closed (either by the user canceling 1492cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the menu with the back/menu button, or when an item is selected). 1493cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1494cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu as last shown or first initialized by 1495cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * onCreateOptionsMenu(). 1496cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1497cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onOptionsMenuClosed(Menu menu) { 1498cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1499cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1500cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1501cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a context menu for the {@code view} is about to be shown. 1502cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Unlike {@link #onCreateOptionsMenu}, this will be called every 1503cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * time the context menu is about to be shown and should be populated for 1504cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the view (or item inside the view for {@link AdapterView} subclasses, 1505cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * this can be found in the {@code menuInfo})). 1506cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1507cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an 1508cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * item has been selected. 1509cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1510cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * The default implementation calls up to 1511cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though 1512cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * you can not call this implementation if you don't want that behavior. 1513cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1514cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * It is not safe to hold onto the context menu after this method returns. 1515cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@inheritDoc} 1516cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1517d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Override 1518cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 1519cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn getActivity().onCreateContextMenu(menu, v, menuInfo); 1520cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1521cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1522cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1523cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Registers a context menu to be shown for the given view (multiple views 1524cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can show the context menu). This method will set the 1525cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link OnCreateContextMenuListener} on the view to this fragment, so 1526cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be 1527cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * called when it is time to show the context menu. 1528cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1529cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #unregisterForContextMenu(View) 1530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param view The view that should show a context menu. 1531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1532cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void registerForContextMenu(View view) { 1533cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn view.setOnCreateContextMenuListener(this); 1534cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Prevents a context menu to be shown for the given view. This method will 1538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * remove the {@link OnCreateContextMenuListener} on the view. 1539cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1540cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #registerForContextMenu(View) 1541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param view The view that should stop showing a context menu. 1542cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1543cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void unregisterForContextMenu(View view) { 1544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn view.setOnCreateContextMenuListener(null); 1545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever an item in a context menu is selected. The 1549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default implementation simply returns false to have the normal processing 1550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * happen (calling the item's Runnable or sending a message to its Handler 1551cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * as appropriate). You can use this method for any items for which you 1552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * would like to do processing without those other facilities. 1553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Use {@link MenuItem#getMenuInfo()} to get extra information set by the 1555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * View that added this menu item. 1556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Derived classes should call through to the base class for it to perform 1558cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the default menu handling. 1559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param item The context menu item that was selected. 1561cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return boolean Return false to allow normal context menu processing to 1562cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * proceed, true to consume it here. 1563cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1564cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public boolean onContextItemSelected(MenuItem item) { 1565cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return false; 1566cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1567e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes 1568cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 15699306f07b1d66f4974a81f781d29739b30124fff0George Mount * When custom transitions are used with Fragments, the enter transition callback 15709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is called when this Fragment is attached or detached when not popping the back stack. 15719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 15729306f07b1d66f4974a81f781d29739b30124fff0George Mount * @param callback Used to manipulate the shared element transitions on this Fragment 15739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when added not as a pop from the back stack. 15749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 1575b1413bc4de16e05ae0455cad93f1edfbcc4eced2George Mount public void setEnterSharedElementCallback(SharedElementCallback callback) { 15769306f07b1d66f4974a81f781d29739b30124fff0George Mount mEnterTransitionCallback = callback; 15779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 15789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 15799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 15809306f07b1d66f4974a81f781d29739b30124fff0George Mount * When custom transitions are used with Fragments, the exit transition callback 15819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is called when this Fragment is attached or detached when popping the back stack. 15829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 15839306f07b1d66f4974a81f781d29739b30124fff0George Mount * @param callback Used to manipulate the shared element transitions on this Fragment 15849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when added as a pop from the back stack. 15859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 1586b1413bc4de16e05ae0455cad93f1edfbcc4eced2George Mount public void setExitSharedElementCallback(SharedElementCallback callback) { 15879306f07b1d66f4974a81f781d29739b30124fff0George Mount mExitTransitionCallback = callback; 15889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 15899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 15909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 15919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views into the initial scene. The entering 15929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 15939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 15949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 15959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null, 15969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. 15979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 15989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views into the initial Scene. 15999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 16009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setEnterTransition(Object transition) { 16019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mEnterTransition = transition; 16029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 16039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 16049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 16059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views into the initial scene. The entering 16069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 16079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 16089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 16099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#INVISIBLE} to {@link View#VISIBLE}. 16109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 16119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views into the initial Scene. 16129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 16139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getEnterTransition() { 16149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return mEnterTransition; 16159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 16169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 16179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 16189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views out of the scene when the Fragment is 16199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * preparing to be removed, hidden, or detached because of popping the back stack. The exiting 16209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 16219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 16229f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 16239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null, 16249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. If nothing is set, the default will be to 16259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * use the same value as set in {@link #setEnterTransition(Object)}. 16269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 16279f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views out of the Scene when the Fragment 16289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is preparing to close. <code>transition</code> must be an 16299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * android.transition.Transition. 16309f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 16319f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setReturnTransition(Object transition) { 16329f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mReturnTransition = transition; 16339f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 16349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 16359f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 16369f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views out of the scene when the Fragment is 16379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * preparing to be removed, hidden, or detached because of popping the back stack. The exiting 16389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 16399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 16409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 16419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null, 16429f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. 16439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 16449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views out of the Scene when the Fragment 16459f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is preparing to close. 16469f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 16479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getReturnTransition() { 16489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return mReturnTransition == USE_DEFAULT_TRANSITION ? getEnterTransition() 16499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount : mReturnTransition; 16509f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 16519f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 16529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 16539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views out of the scene when the 16549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * fragment is removed, hidden, or detached when not popping the back stack. 16559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * The exiting Views will be those that are regular Views or ViewGroups that 16569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 16579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as exiting is governed by changing visibility 16589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will 16599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * remain unaffected. 16609f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 16619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views out of the Scene when the Fragment 16629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is being closed not due to popping the back stack. <code>transition</code> 16639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * must be an android.transition.Transition. 16649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 16659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setExitTransition(Object transition) { 16669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mExitTransition = transition; 16679f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 16689f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 16699f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 16709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views out of the scene when the 16719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * fragment is removed, hidden, or detached when not popping the back stack. 16729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * The exiting Views will be those that are regular Views or ViewGroups that 16739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 16749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as exiting is governed by changing visibility 16759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will 16769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * remain unaffected. 16779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 16789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views out of the Scene when the Fragment 16799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is being closed not due to popping the back stack. 16809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 16819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getExitTransition() { 16829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return mExitTransition; 16839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 16849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 16859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 16869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views in to the scene when returning due 16879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * to popping a back stack. The entering Views will be those that are regular Views 16889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions 16899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * will extend {@link android.transition.Visibility} as exiting is governed by changing 16909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, 16919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * the views will remain unaffected. If nothing is set, the default will be to use the same 16929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * transition as {@link #setExitTransition(Object)}. 16939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 16949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views into the scene when reentering from a 16959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * previously-started Activity. <code>transition</code> 16969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * must be an android.transition.Transition. 16979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 16989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setReenterTransition(Object transition) { 16999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mReenterTransition = transition; 17009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 17019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 17029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 17039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views in to the scene when returning due 17049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * to popping a back stack. The entering Views will be those that are regular Views 17059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions 17069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * will extend {@link android.transition.Visibility} as exiting is governed by changing 17079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, 17089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * the views will remain unaffected. If nothing is set, the default will be to use the same 17099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * transition as {@link #setExitTransition(Object)}. 17109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 17119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views into the scene when reentering from a 17129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * previously-started Activity. 17139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 17149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getReenterTransition() { 17159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return mReenterTransition == USE_DEFAULT_TRANSITION ? getExitTransition() 17169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount : mReenterTransition; 17179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 17189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 17199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 17209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used for shared elements transferred into the content 17219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. Typical Transitions will affect size and location, such as 17229f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 17239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 17249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 17259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use for shared elements transferred into the content 17269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. <code>transition</code> must be an android.transition.Transition. 17279f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 17289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setSharedElementEnterTransition(Object transition) { 17299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mSharedElementEnterTransition = transition; 17309f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 17319f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 17329f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 17339f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used for shared elements transferred into the content 17349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. Typical Transitions will affect size and location, such as 17359f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 17369f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 17379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 17389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return The Transition to use for shared elements transferred into the content 17399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. 17409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 17419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getSharedElementEnterTransition() { 17429f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return mSharedElementEnterTransition; 17439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 17449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 17459f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 17469f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used for shared elements transferred back during a 17479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * pop of the back stack. This Transition acts in the leaving Fragment. 17489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Typical Transitions will affect size and location, such as 17499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 17509f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 17519f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * If no value is set, the default will be to use the same value as 17529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link #setSharedElementEnterTransition(Object)}. 17539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 17549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use for shared elements transferred out of the content 17559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. <code>transition</code> must be an android.transition.Transition. 17569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 17579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setSharedElementReturnTransition(Object transition) { 17589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mSharedElementReturnTransition = transition; 17599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 17609f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 17619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 17629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Return the Transition that will be used for shared elements transferred back during a 17639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * pop of the back stack. This Transition acts in the leaving Fragment. 17649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Typical Transitions will affect size and location, such as 17659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 17669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 17679f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * If no value is set, the default will be to use the same value as 17689f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link #setSharedElementEnterTransition(Object)}. 17699f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 17709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return The Transition to use for shared elements transferred out of the content 17719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. 17729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 17739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getSharedElementReturnTransition() { 17749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return mSharedElementReturnTransition == USE_DEFAULT_TRANSITION ? 17759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount getSharedElementEnterTransition() : mSharedElementReturnTransition; 17769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 17779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 17789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 17799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets whether the the exit transition and enter transition overlap or not. 17809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the enter transition will start as soon as possible. When false, the 17819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * enter transition will wait until the exit transition completes before starting. 17829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 17839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param allow true to start the enter transition when possible or false to 17849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * wait until the exiting transition completes. 17859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 17869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setAllowEnterTransitionOverlap(boolean allow) { 17879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mAllowEnterTransitionOverlap = allow; 17889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 17899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 17909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 17919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns whether the the exit transition and enter transition overlap or not. 17929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the enter transition will start as soon as possible. When false, the 17939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * enter transition will wait until the exit transition completes before starting. 17949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 17959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return true when the enter transition should start as soon as possible or false to 17969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when it should wait until the exiting transition completes. 17979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 17989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public boolean getAllowEnterTransitionOverlap() { 17999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return (mAllowEnterTransitionOverlap == null) ? true : mAllowEnterTransitionOverlap; 18009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 18019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 18029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 18039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets whether the the return transition and reenter transition overlap or not. 18049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the reenter transition will start as soon as possible. When false, the 18059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * reenter transition will wait until the return transition completes before starting. 18069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 18079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param allow true to start the reenter transition when possible or false to wait until the 18089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * return transition completes. 18099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 18109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setAllowReturnTransitionOverlap(boolean allow) { 18119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount mAllowReturnTransitionOverlap = allow; 18129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 18139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 18149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 18159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns whether the the return transition and reenter transition overlap or not. 18169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the reenter transition will start as soon as possible. When false, the 18179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * reenter transition will wait until the return transition completes before starting. 18189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 18199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return true to start the reenter transition when possible or false to wait until the 18209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * return transition completes. 18219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 18229f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public boolean getAllowReturnTransitionOverlap() { 18239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount return (mAllowReturnTransitionOverlap == null) ? true : mAllowReturnTransitionOverlap; 18249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 18259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 18269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 1827cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Print the Fragments's state into the given stream. 1828cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1829cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param prefix Text to print at the front of each line. 1830cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fd The raw file descriptor that the dump is being sent to. 1831cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param writer The PrintWriter to which you should dump your state. This will be 1832cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * closed for you after you return. 1833cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param args additional arguments to the dump request. 1834cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1835cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { 1836cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mFragmentId=#"); 1837cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(Integer.toHexString(mFragmentId)); 18385506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn writer.print(" mContainerId=#"); 1839cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(Integer.toHexString(mContainerId)); 1840cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mTag="); writer.println(mTag); 1841cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mState="); writer.print(mState); 1842cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mIndex="); writer.print(mIndex); 1843cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mWho="); writer.print(mWho); 1844cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mBackStackNesting="); writer.println(mBackStackNesting); 1845cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mAdded="); writer.print(mAdded); 1846cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mRemoving="); writer.print(mRemoving); 1847cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mFromLayout="); writer.print(mFromLayout); 1848cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mInLayout="); writer.println(mInLayout); 1849cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mHidden="); writer.print(mHidden); 1850e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn writer.print(" mDetached="); writer.print(mDetached); 18512a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn writer.print(" mMenuVisible="); writer.print(mMenuVisible); 1852cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mHasMenu="); writer.println(mHasMenu); 18532a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn writer.print(prefix); writer.print("mRetainInstance="); writer.print(mRetainInstance); 185479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell writer.print(" mRetaining="); writer.print(mRetaining); 185579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell writer.print(" mUserVisibleHint="); writer.println(mUserVisibleHint); 1856cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mFragmentManager != null) { 1857cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mFragmentManager="); 1858cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mFragmentManager); 1859cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1860d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost != null) { 1861d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy writer.print(prefix); writer.print("mHost="); 1862d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy writer.println(mHost); 1863cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 18640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mParentFragment != null) { 18650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.print(prefix); writer.print("mParentFragment="); 18660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.println(mParentFragment); 18670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 1868cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mArguments != null) { 1869cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mArguments="); writer.println(mArguments); 1870cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1871cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedFragmentState != null) { 1872cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mSavedFragmentState="); 1873cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mSavedFragmentState); 1874cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1875cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedViewState != null) { 1876cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mSavedViewState="); 1877cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mSavedViewState); 1878cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1879cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mTarget != null) { 1880cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mTarget="); writer.print(mTarget); 1881cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mTargetRequestCode="); 1882cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mTargetRequestCode); 1883cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1884cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mNextAnim != 0) { 1885cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mNextAnim="); writer.println(mNextAnim); 1886cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1887cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mContainer != null) { 1888cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mContainer="); writer.println(mContainer); 1889cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1890cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mView != null) { 1891cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mView="); writer.println(mView); 1892cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1893cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mInnerView != null) { 1894cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mInnerView="); writer.println(mView); 1895cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1896cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mAnimatingAway != null) { 1897cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mAnimatingAway="); writer.println(mAnimatingAway); 1898cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mStateAfterAnimating="); 1899cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mStateAfterAnimating); 1900cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1901cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoaderManager != null) { 1902cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.println("Loader Manager:"); 1903cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoaderManager.dump(prefix + " ", fd, writer, args); 1904cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 19050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 19060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.print(prefix); writer.println("Child " + mChildFragmentManager + ":"); 19070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dump(prefix + " ", fd, writer, args); 19080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 19110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Fragment findFragmentByWho(String who) { 19120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (who.equals(mWho)) { 19130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return this; 19140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 19160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mChildFragmentManager.findFragmentByWho(who); 19170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return null; 19190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 19210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void instantiateChildFragmentManager() { 1922e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes mChildFragmentManager = new FragmentManagerImpl(); 1923d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mChildFragmentManager.attachController(mHost, new FragmentContainer() { 19240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn @Override 19250fb3ec354da6c1f3ed1777bca5270710cc537e92Scott Kennedy @Nullable 19268491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy public View onFindViewById(int id) { 19270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mView == null) { 19280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new IllegalStateException("Fragment does not have a view"); 19290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mView.findViewById(id); 19310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19327516316ffdf6fbf7b248c615404831191daa66a4George Mount 19337516316ffdf6fbf7b248c615404831191daa66a4George Mount @Override 19348491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy public boolean onHasView() { 19357516316ffdf6fbf7b248c615404831191daa66a4George Mount return (mView != null); 19367516316ffdf6fbf7b248c615404831191daa66a4George Mount } 19370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn }, this); 19380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 19400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performCreate(Bundle savedInstanceState) { 19410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 19420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 19430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 194420735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = CREATED; 19450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 19460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onCreate(savedInstanceState); 19470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 19480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 19490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onCreate()"); 19500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (savedInstanceState != null) { 19520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Parcelable p = savedInstanceState.getParcelable( 19530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn FragmentActivity.FRAGMENTS_TAG); 19540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (p != null) { 19550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager == null) { 19560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn instantiateChildFragmentManager(); 19570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.restoreAllState(p, null); 19590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchCreate(); 19600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 19640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn View performCreateView(LayoutInflater inflater, ViewGroup container, 19650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Bundle savedInstanceState) { 19660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 19670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 19680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return onCreateView(inflater, container, savedInstanceState); 19700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 19720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performActivityCreated(Bundle savedInstanceState) { 19730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 19740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 19750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 197620735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = ACTIVITY_CREATED; 19770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 19780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onActivityCreated(savedInstanceState); 19790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 19800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 19810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onActivityCreated()"); 19820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 19830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 19840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchActivityCreated(); 19850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 1986cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1987cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 19889c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void performStart() { 19890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 19900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 19910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 19920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 199320735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = STARTED; 19940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 19959c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn onStart(); 19960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 19970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 19980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onStart()"); 19990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 20010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStart(); 20020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20039c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn if (mLoaderManager != null) { 20049c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mLoaderManager.doReportStart(); 20059c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 20069c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 20079c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 20080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performResume() { 20090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 20100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 20110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 20120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 201320735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = RESUMED; 20140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 20150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onResume(); 20160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 20170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 20180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onResume()"); 20190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 20210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchResume(); 20220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 20230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 20260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performConfigurationChanged(Configuration newConfig) { 20270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onConfigurationChanged(newConfig); 20280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 20290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchConfigurationChanged(newConfig); 20300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 20330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performLowMemory() { 20340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onLowMemory(); 20350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 20360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchLowMemory(); 20370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 20400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /* 20410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performTrimMemory(int level) { 20420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onTrimMemory(level); 20430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 20440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchTrimMemory(level); 20450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 20480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 20490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performCreateOptionsMenu(Menu menu, MenuInflater inflater) { 20500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean show = false; 20510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 20520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 20530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show = true; 20540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onCreateOptionsMenu(menu, inflater); 20550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 20570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show |= mChildFragmentManager.dispatchCreateOptionsMenu(menu, inflater); 20580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return show; 20610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 20630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performPrepareOptionsMenu(Menu menu) { 20640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean show = false; 20650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 20660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 20670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show = true; 20680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onPrepareOptionsMenu(menu); 20690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 20710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show |= mChildFragmentManager.dispatchPrepareOptionsMenu(menu); 20720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return show; 20750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 20770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performOptionsItemSelected(MenuItem item) { 20780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 20790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 20800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (onOptionsItemSelected(item)) { 20810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 20820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 20850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager.dispatchOptionsItemSelected(item)) { 20860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 20870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return false; 20910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 20930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performContextItemSelected(MenuItem item) { 20940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 20950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (onContextItemSelected(item)) { 20960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 20970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 20980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 20990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager.dispatchContextItemSelected(item)) { 21000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 21010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 21020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 21030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 21040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return false; 21050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 21060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 21070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performOptionsMenuClosed(Menu menu) { 21080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 21090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 21100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onOptionsMenuClosed(menu); 21110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 21120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 21130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchOptionsMenuClosed(menu); 21140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 21150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 21160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 21170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 21180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performSaveInstanceState(Bundle outState) { 21190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onSaveInstanceState(outState); 21200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 21210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Parcelable p = mChildFragmentManager.saveAllState(); 21220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (p != null) { 21230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn outState.putParcelable(FragmentActivity.FRAGMENTS_TAG, p); 21240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 21250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 21260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 21270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 21280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performPause() { 21290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 21300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchPause(); 21310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 213220735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = STARTED; 21330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 21340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onPause(); 21350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 21360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 21370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onPause()"); 21380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 21390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 21400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 2141cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn void performStop() { 21420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 21430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStop(); 21440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 214520735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = STOPPED; 21460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 2147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn onStop(); 21480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 21490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 21500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onStop()"); 21510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2152681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn } 2153681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn 2154218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn void performReallyStop() { 21550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 21560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchReallyStop(); 21570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 215820735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = ACTIVITY_CREATED; 2159cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoadersStarted) { 2160cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoadersStarted = false; 2161cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!mCheckedForLoaderManager) { 2162cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCheckedForLoaderManager = true; 2163d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false); 2164cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2165cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mLoaderManager != null) { 216664ece2df3d6d789f7a642692acbe85fa1b998d6bTodd Kennedy if (mHost.getRetainLoaders()) { 2167cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mLoaderManager.doRetain(); 21682bdd09a243b422960168170e2344274cc9cfd788Todd Kennedy } else { 21692bdd09a243b422960168170e2344274cc9cfd788Todd Kennedy mLoaderManager.doStop(); 2170cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2171cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2172cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 21749c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 21759c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void performDestroyView() { 21760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 21770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchDestroyView(); 21780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 217920735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = CREATED; 21800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 21819c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn onDestroyView(); 21820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 21830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 21840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onDestroyView()"); 21850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 21869c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn if (mLoaderManager != null) { 21879c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mLoaderManager.doReportNextStart(); 21889c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 21899c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 21900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 21910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performDestroy() { 21920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 21930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchDestroy(); 21940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 219520735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = INITIALIZING; 21960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 21970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onDestroy(); 21980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 21990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 22000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onDestroy()"); 22010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 22020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn} 2204