Fragment.java revision e8ffa7a5775d29c6144ce0276cd4853baed5c1fb
1cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/* 2ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * Copyright 2018 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 17ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikaspackage androidx.fragment.app; 18cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 19ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; 20990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2115e593ea3575512d7072240d1db9d74fad8749a3George Mountimport android.animation.Animator; 22cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.app.Activity; 23cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.ComponentCallbacks; 24cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Context; 25cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Intent; 26fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarriimport android.content.IntentSender; 27cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Configuration; 28cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Resources; 29cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Bundle; 30990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mountimport android.os.Looper; 31cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcel; 32cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcelable; 33cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.AttributeSet; 34cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.SparseArray; 35cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ContextMenu; 369562a3b639225d406d736b64a12e2d75459259e3Alan Viveretteimport android.view.ContextMenu.ContextMenuInfo; 37cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.LayoutInflater; 38cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.Menu; 39cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuInflater; 40cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuItem; 41cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View; 42cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View.OnCreateContextMenuListener; 439562a3b639225d406d736b64a12e2d75459259e3Alan Viveretteimport android.view.ViewGroup; 44cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.animation.Animation; 45cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.widget.AdapterView; 46cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 47320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.annotation.CallSuper; 48320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.annotation.NonNull; 49320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.annotation.Nullable; 50320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.annotation.RestrictTo; 51320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.annotation.StringRes; 52320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.collection.SimpleArrayMap; 53320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.core.app.SharedElementCallback; 54320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.core.util.DebugUtils; 55320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.core.view.LayoutInflaterCompat; 56ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.lifecycle.Lifecycle; 57ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.lifecycle.LifecycleOwner; 58ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.lifecycle.LifecycleRegistry; 59ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.lifecycle.ViewModelStore; 60ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.lifecycle.ViewModelStoreOwner; 61320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.loader.app.LoaderManager; 62320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikas 63cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.FileDescriptor; 64cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.PrintWriter; 65b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikasimport java.lang.reflect.InvocationTargetException; 66cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 67cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/** 68cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Static library support version of the framework's {@link android.app.Fragment}. 69cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Used to write apps that run on platforms prior to Android 3.0. When running 70cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on Android 3.0 or above, this implementation is still used; it does not try 719dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * to switch to the framework's implementation. See the framework {@link android.app.Fragment} 72cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * documentation for a class overview. 739dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * 749dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <p>The main differences when using this support version instead of the framework version are: 759dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <ul> 769dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <li>Your activity must extend {@link FragmentActivity} 779dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <li>You must call {@link FragmentActivity#getSupportFragmentManager} to get the 789dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * {@link FragmentManager} 799dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * </ul> 809dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * 81cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 8241516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lakepublic class Fragment implements ComponentCallbacks, OnCreateContextMenuListener, LifecycleOwner, 8341516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake ViewModelStoreOwner { 842290993eddf5262a8df7fc9478daed52401e325aDianne Hackborn private static final SimpleArrayMap<String, Class<?>> sClassMap = 852290993eddf5262a8df7fc9478daed52401e325aDianne Hackborn new SimpleArrayMap<String, Class<?>>(); 869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount static final Object USE_DEFAULT_TRANSITION = new Object(); 889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 89cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int INITIALIZING = 0; // Not yet created. 90cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int CREATED = 1; // Created. 91cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int ACTIVITY_CREATED = 2; // The activity has finished its creation. 92e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn static final int STOPPED = 3; // Fully created, not started. 93e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn static final int STARTED = 4; // Created and started, not resumed. 94e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn static final int RESUMED = 5; // Created started and resumed. 954bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 96cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mState = INITIALIZING; 974bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 98cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // When instantiated from saved state, this is the saved state. 99cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Bundle mSavedFragmentState; 100cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn SparseArray<Parcelable> mSavedViewState; 101e8ffa7a5775d29c6144ce0276cd4853baed5c1fbIan Lake // If the userVisibleHint is changed before the state is set, 102e8ffa7a5775d29c6144ce0276cd4853baed5c1fbIan Lake // it is stored here 103e8ffa7a5775d29c6144ce0276cd4853baed5c1fbIan Lake @Nullable Boolean mSavedUserVisibleHint; 1044bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 105cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Index into active fragment array. 106cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mIndex = -1; 1074bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Internal unique name for this fragment; 109cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn String mWho; 1104bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 111cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Construction arguments; 112cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Bundle mArguments; 113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 114cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Target fragment. 115cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment mTarget; 116cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1172c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn // For use when retaining a fragment: this is the index of the last mTarget. 1182c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn int mTargetIndex = -1; 1192c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn 120cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Target request code. 121cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mTargetRequestCode; 122cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 123cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // True if the fragment is in the list of added fragments. 124cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mAdded; 1254bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 126cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment is being removed from its activity. 127cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRemoving; 1284bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 129cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true if this fragment was instantiated from a layout file. 130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mFromLayout; 1314bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true when the view has actually been inflated in its layout. 133cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mInLayout; 134cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 135cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // True if this fragment has been restored from previously saved state. 136cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRestored; 137d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 13837149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell // True if performCreateView has been called and a matching call to performDestroyView 13937149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell // has not yet happened. 14037149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell boolean mPerformedCreateView; 14137149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell 142cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Number of active back stack entries this fragment is in. 143cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mBackStackNesting; 144d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 145cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The fragment manager we are associated with. Set as soon as the 146cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // fragment is used in a transaction; cleared after it has been removed 147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // from all transactions. 148abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell FragmentManagerImpl mFragmentManager; 149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 150d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy // Host this fragment is attached to. 1518491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy FragmentHostCallback mHost; 1520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn // Private fragment manager for child fragments inside of this one. 1540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn FragmentManagerImpl mChildFragmentManager; 1550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 156c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell // For use when restoring fragment state and descendant fragments are retained. 157c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell // This state is set by FragmentState.instantiate and cleared in onCreate. 158c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell FragmentManagerNonConfig mChildNonConfig; 159c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell 16041516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake // ViewModelStore for storing ViewModels associated with this Fragment 16141516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake ViewModelStore mViewModelStore; 16241516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake 1630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn // If this Fragment is contained in another Fragment, this is that container. 1640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Fragment mParentFragment; 1650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 166cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The optional identifier for this fragment -- either the container ID if it 167cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // was dynamically added to the view hierarchy, or the ID supplied in 168cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // layout. 169cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mFragmentId; 1704bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 171cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // When a fragment is being dynamically added to the view hierarchy, this 172cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // is the identifier of the parent container it is being added to. 173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mContainerId; 1744bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 175cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The optional named tag for this fragment -- usually used to find 176cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // fragments that are not part of the layout. 177cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn String mTag; 1784bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 179cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true when the app has requested that this fragment be hidden 180cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // from the user. 181cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mHidden; 1824bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 183e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn // Set to true when the app has requested that this fragment be deactivated. 184e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn boolean mDetached; 185e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 186cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment would like its instance retained across 187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // configuration changes. 188cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRetainInstance; 1892bdd09a243b422960168170e2344274cc9cfd788Todd Kennedy 190cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment is being retained across the current config change. 191cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRetaining; 1924bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 193cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment has menu items to contribute. 194cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mHasMenu; 1952a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 1962a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn // Set to true to allow the fragment's menu to be shown. 1972a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn boolean mMenuVisible = true; 1982a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Used to verify that subclasses call through to super class. 200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mCalled; 2014bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The parent container of the fragment after dynamically added to UI. 203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn ViewGroup mContainer; 2044bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The View generated for this fragment. 206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn View mView; 2074bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 208cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The real inner view that will save/restore state. 209cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn View mInnerView; 210abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 211abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell // Whether this fragment should defer starting until after other fragments 212abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell // have been started and their loaders are finished. 213abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell boolean mDeferStart; 2144bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 21579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell // Hint provided by the app that this fragment is currently visible to the user. 21679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell boolean mUserVisibleHint = true; 217abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 218990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // The animation and transition information for the fragment. This will be null 219990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // unless the elements are explicitly accessed and should remain null for Fragments 220990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // without Views. 221990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount AnimationInfo mAnimationInfo; 2229f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 223990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // True if the View was added, and its animation has yet to be run. This could 224990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // also indicate that the fragment view hasn't been made visible, even if there is no 225990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // animation for this fragment. 226990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount boolean mIsNewlyAdded; 227990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 228990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // True if mHidden has been changed and the animation should be scheduled. 229990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount boolean mHiddenChanged; 2309f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 2310bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount // The alpha of the view when the view was added and then postponed. If the value is less 2320bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount // than zero, this means that the view's add was canceled and should not participate in 2330bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount // removal animations. 2340bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount float mPostponedAlpha; 2350bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount 2368b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount // The cached value from onGetLayoutInflater(Bundle) that will be returned from 2378b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount // getLayoutInflater() 2388b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount LayoutInflater mLayoutInflater; 2398b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount 240e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount // Keep track of whether or not this Fragment has run performCreate(). Retained instance 241e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount // fragments can have mRetaining set to true without going through creation, so we must 242e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount // track it separately. 243e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount boolean mIsCreated; 244e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount 245c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets LifecycleRegistry mLifecycleRegistry = new LifecycleRegistry(this); 246c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets 247c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets @Override 248c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets public Lifecycle getLifecycle() { 249c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets return mLifecycleRegistry; 250c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets } 251c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets 25241516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake @NonNull 25341516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake @Override 25441516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake public ViewModelStore getViewModelStore() { 25541516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake if (getContext() == null) { 25641516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake throw new IllegalStateException("Can't access ViewModels from detached fragment"); 25741516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake } 25841516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake if (mViewModelStore == null) { 25941516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake mViewModelStore = new ViewModelStore(); 26041516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake } 26141516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake return mViewModelStore; 26241516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake } 26341516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake 264cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 2655c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * State information that has been retrieved from a fragment instance 2665c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * through {@link FragmentManager#saveFragmentInstanceState(Fragment) 2675c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * FragmentManager.saveFragmentInstanceState}. 2685c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 2695c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public static class SavedState implements Parcelable { 2705c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn final Bundle mState; 2715c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 2725c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn SavedState(Bundle state) { 2735c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState = state; 2745c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 2755c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 2765c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn SavedState(Parcel in, ClassLoader loader) { 2775c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState = in.readBundle(); 2785c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn if (loader != null && mState != null) { 2795c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState.setClassLoader(loader); 2805c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 2815c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 2825c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 2835c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn @Override 2845c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public int describeContents() { 2855c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return 0; 2865c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 2875c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 2885c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn @Override 2895c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public void writeToParcel(Parcel dest, int flags) { 2905c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn dest.writeBundle(mState); 2915c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 2925c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 2935c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public static final Parcelable.Creator<SavedState> CREATOR 2945c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn = new Parcelable.Creator<SavedState>() { 295d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Override 2965c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public SavedState createFromParcel(Parcel in) { 2975c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return new SavedState(in, null); 2985c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 2995c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 300d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Override 3015c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public SavedState[] newArray(int size) { 3025c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return new SavedState[size]; 3035c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3045c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn }; 3055c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3065c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3075c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 308cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when 309cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * there is an instantiation failure. 310cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 311960e687174a4c2daca556d52bfd48e2fd8f4f317Jake Wharton @SuppressWarnings("JavaLangClash") 312960e687174a4c2daca556d52bfd48e2fd8f4f317Jake Wharton public static class InstantiationException extends RuntimeException { 313cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public InstantiationException(String msg, Exception cause) { 314cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn super(msg, cause); 315cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 316cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 317cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 318cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 319cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Default constructor. <strong>Every</strong> fragment must have an 320cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * empty constructor, so it can be instantiated when restoring its 321cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * activity's state. It is strongly recommended that subclasses do not 322cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * have other constructors with parameters, since these constructors 323cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * will not be called when the fragment is re-instantiated; instead, 324cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * arguments can be supplied by the caller with {@link #setArguments} 325cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * and later retrieved by the Fragment with {@link #getArguments}. 3264bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 32704f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * <p>Applications should generally not implement a constructor. Prefer 32804f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * {@link #onAttach(Context)} instead. It is the first place application code can run where 32904f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * the fragment is ready to be used - the point where the fragment is actually associated with 33004f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * its context. Some applications may also want to implement {@link #onInflate} to retrieve 33104f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * attributes from a layout resource, although note this happens when the fragment is attached. 332cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 333cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public Fragment() { 334cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 335cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 336cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 337cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Like {@link #instantiate(Context, String, Bundle)} but with a null 338cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * argument Bundle. 339cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 340cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public static Fragment instantiate(Context context, String fname) { 341cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return instantiate(context, fname, null); 342cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 343cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 344cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 345cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Create a new instance of a Fragment with the given class name. This is 346cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the same as calling its empty constructor. 347cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 348cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param context The calling context being used to instantiate the fragment. 349cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is currently just used to get its ClassLoader. 350cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fname The class name of the fragment to instantiate. 351cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param args Bundle of arguments to supply to the fragment, which it 352cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can retrieve with {@link #getArguments()}. May be null. 353cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return Returns a new fragment instance. 354cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @throws InstantiationException If there is a failure in instantiating 355cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the given fragment class. This is a runtime exception; it is not 356cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * normally expected to happen. 357cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 358c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy public static Fragment instantiate(Context context, String fname, @Nullable Bundle args) { 359cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn try { 360cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Class<?> clazz = sClassMap.get(fname); 361cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (clazz == null) { 362cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Class not found in the cache, see if it's real, and try to add it 363cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn clazz = context.getClassLoader().loadClass(fname); 364cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sClassMap.put(fname, clazz); 365cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 366b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas Fragment f = (Fragment) clazz.getConstructor().newInstance(); 367cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (args != null) { 368cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn args.setClassLoader(f.getClass().getClassLoader()); 36937149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell f.setArguments(args); 370cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 371cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return f; 372cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (ClassNotFoundException e) { 373cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 374cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 375cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 376cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (java.lang.InstantiationException e) { 377cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 378cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 379cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 380cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (IllegalAccessException e) { 381cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 382cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 383cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 384b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas } catch (NoSuchMethodException e) { 385b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas throw new InstantiationException("Unable to instantiate fragment " + fname 386b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas + ": could not find Fragment constructor", e); 387b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas } catch (InvocationTargetException e) { 388b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas throw new InstantiationException("Unable to instantiate fragment " + fname 389b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas + ": calling Fragment constructor caused an exception", e); 390cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 391cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 3923fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell 3933fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell /** 3943fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * Determine if the given fragment name is a support library fragment class. 3953fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * 3963fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * @param context Context used to determine the correct ClassLoader to use 3973fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * @param fname Class name of the fragment to test 398ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * @return true if <code>fname</code> is <code>androidx.fragment.app.Fragment</code> 3993fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * or a subclass, false otherwise. 4003fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell */ 4013fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell static boolean isSupportFragmentClass(Context context, String fname) { 4023fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell try { 4033fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell Class<?> clazz = sClassMap.get(fname); 4043fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell if (clazz == null) { 4053fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell // Class not found in the cache, see if it's real, and try to add it 4063fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell clazz = context.getClassLoader().loadClass(fname); 4073fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell sClassMap.put(fname, clazz); 4083fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 4093fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell return Fragment.class.isAssignableFrom(clazz); 4103fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } catch (ClassNotFoundException e) { 4113fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell return false; 4123fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 4133fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 4144bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 4150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final void restoreViewState(Bundle savedInstanceState) { 416cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedViewState != null) { 417cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInnerView.restoreHierarchyState(mSavedViewState); 418cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mSavedViewState = null; 419cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 4210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onViewStateRestored(savedInstanceState); 4220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 4230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 4240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onViewStateRestored()"); 4250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 426cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 4280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final void setIndex(int index, Fragment parent) { 429cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = index; 4300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (parent != null) { 4310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mWho = parent.mWho + ":" + mIndex; 4320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else { 4330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mWho = "android:fragment:" + mIndex; 4340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 435e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 4360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 437e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn final boolean isInBackStack() { 438e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn return mBackStackNesting > 0; 439e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 440e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 441cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Subclasses can not override equals(). 443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 444cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override final public boolean equals(Object o) { 445cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return super.equals(o); 446cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 447cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 448cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Subclasses can not override hashCode(). 450cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 451cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override final public int hashCode() { 452cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return super.hashCode(); 453cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4544bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override 456cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public String toString() { 457cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn StringBuilder sb = new StringBuilder(128); 458cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn DebugUtils.buildShortClassTag(this, sb); 459cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mIndex >= 0) { 460cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" #"); 461cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(mIndex); 462cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 463cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mFragmentId != 0) { 464cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" id=0x"); 465cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(Integer.toHexString(mFragmentId)); 466cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 467cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mTag != null) { 468cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" "); 469cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(mTag); 470cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 471cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append('}'); 472cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return sb.toString(); 473cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4744bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 475cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 476cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the identifier this fragment is known by. This is either 477cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the android:id value supplied in a layout or the container view ID 478cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * supplied when adding the fragment. 479cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 480cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public int getId() { 481cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mFragmentId; 482cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4834bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 484cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 485cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Get the tag name of the fragment, if specified. 486cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 4872a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 488cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public String getTag() { 489cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTag; 490cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4914bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 492cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 4935e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * Supply the construction arguments for this fragment. 4945e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * The arguments supplied here will be retained across fragment destroy and 495cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * creation. 4965e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * <p>This method cannot be called if the fragment is added to a FragmentManager and 4975e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * if {@link #isStateSaved()} would return true.</p> 498cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 4992a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setArguments(@Nullable Bundle args) { 5005e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell if (mIndex >= 0 && isStateSaved()) { 5015e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell throw new IllegalStateException("Fragment already active and state has been saved"); 502cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 503cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mArguments = args; 504cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 505cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 506cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 507cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the arguments supplied when the fragment was instantiated, 508cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if any. 509cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 5102a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 511cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public Bundle getArguments() { 512cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mArguments; 513cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 514cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 515cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 5165e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * Returns true if this fragment is added and its state has already been saved 5175e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * by its host. Any operations that would change saved state should not be performed 5185e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * if this method returns true, and some operations such as {@link #setArguments(Bundle)} 5195e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * will fail. 5205e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * 5215e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * @return true if this fragment's state has already been saved by its host 5225e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell */ 5235e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell public final boolean isStateSaved() { 5245e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell if (mFragmentManager == null) { 5255e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell return false; 5265e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell } 5275e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell return mFragmentManager.isStateSaved(); 5285e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell } 5295e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell 5305e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell /** 5315c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Set the initial saved state that this Fragment should restore itself 5325c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * from when first being constructed, as returned by 5335c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * {@link FragmentManager#saveFragmentInstanceState(Fragment) 5345c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * FragmentManager.saveFragmentInstanceState}. 5355c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * 5365c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param state The state the fragment should be restored from. 5375c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 5382a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setInitialSavedState(@Nullable SavedState state) { 5395c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn if (mIndex >= 0) { 5405c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn throw new IllegalStateException("Fragment already active"); 5415c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 5425c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mSavedFragmentState = state != null && state.mState != null 5435c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn ? state.mState : null; 5445c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 5455c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 5465c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Optional target for this fragment. This may be used, for example, 548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if this fragment is being started by another, and when done wants to 549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * give a result back to the first. The target set here is retained 550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * across instances via {@link FragmentManager#putFragment 551cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * FragmentManager.putFragment()}. 552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fragment The fragment that is the target of this one. 554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param requestCode Optional request code, for convenience if you 555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * are going to call back with {@link #onActivityResult(int, int, Intent)}. 556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 557b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas @SuppressWarnings("ReferenceEquality") 5582a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setTargetFragment(@Nullable Fragment fragment, int requestCode) { 559a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // Don't allow a caller to set a target fragment in another FragmentManager, 560a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // but there's a snag: people do set target fragments before fragments get added. 561a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // We'll have the FragmentManager check that for validity when we move 562a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // the fragments to a valid state. 563a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell final FragmentManager mine = getFragmentManager(); 5642ab15df66963610bc02cb30e9a459f2b49c2ccfaAdam Powell final FragmentManager theirs = fragment != null ? fragment.getFragmentManager() : null; 565a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell if (mine != null && theirs != null && mine != theirs) { 566a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell throw new IllegalArgumentException("Fragment " + fragment 567a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell + " must share the same FragmentManager to be set as a target fragment"); 568a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell } 569a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell 570a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // Don't let someone create a cycle. 571a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell for (Fragment check = fragment; check != null; check = check.getTargetFragment()) { 572a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell if (check == this) { 573a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell throw new IllegalArgumentException("Setting " + fragment + " as the target of " 574a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell + this + " would create a target cycle"); 575a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell } 576a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell } 577cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTarget = fragment; 578cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTargetRequestCode = requestCode; 579cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 580cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 581cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 582cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the target fragment set by {@link #setTargetFragment}. 583cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 5842a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 585cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public Fragment getTargetFragment() { 586cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTarget; 587cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 588cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 589cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 590cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the target request code set by {@link #setTargetFragment}. 591cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 592cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public int getTargetRequestCode() { 593cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTargetRequestCode; 594cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 595cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 596cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 597d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Return the {@link Context} this fragment is currently associated with. 598c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 599c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #requireContext() 600d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy */ 601b38fded102ffe4de21f2d048262f52d5bcefbfd5Jake Wharton @Nullable 602edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy public Context getContext() { 603d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy return mHost == null ? null : mHost.getContext(); 604d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 605d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 606d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy /** 607c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * Return the {@link Context} this fragment is currently associated with. 608c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 609c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @throws IllegalStateException if not currently associated with a context. 610c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #getContext() 611c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton */ 612c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton @NonNull 613c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton public final Context requireContext() { 614c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton Context context = getContext(); 615c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton if (context == null) { 616c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton throw new IllegalStateException("Fragment " + this + " not attached to a context."); 617c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton } 618c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton return context; 619c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton } 620c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton 621c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton /** 622d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Return the {@link FragmentActivity} this fragment is currently associated with. 623d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * May return {@code null} if the fragment is associated with a {@link Context} 624d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * instead. 625c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 626c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #requireActivity() 627cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 628b38fded102ffe4de21f2d048262f52d5bcefbfd5Jake Wharton @Nullable 629cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public FragmentActivity getActivity() { 630d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy return mHost == null ? null : (FragmentActivity) mHost.getActivity(); 631cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 632d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 633cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 634c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * Return the {@link FragmentActivity} this fragment is currently associated with. 635c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 636c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @throws IllegalStateException if not currently associated with an activity or if associated 637c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * only with a context. 638c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #getActivity() 639c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton */ 640c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton @NonNull 641c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton public final FragmentActivity requireActivity() { 642c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton FragmentActivity activity = getActivity(); 643c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton if (activity == null) { 644c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton throw new IllegalStateException("Fragment " + this + " not attached to an activity."); 645c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton } 646c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton return activity; 647c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton } 648c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton 649c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton /** 650edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy * Return the host object of this fragment. May return {@code null} if the fragment 651edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy * isn't currently being hosted. 652c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 653c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #requireHost() 654edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy */ 655b38fded102ffe4de21f2d048262f52d5bcefbfd5Jake Wharton @Nullable 656edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy final public Object getHost() { 6578491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy return mHost == null ? null : mHost.onGetHost(); 658edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy } 659edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy 660edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy /** 661c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * Return the host object of this fragment. 662c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 663c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @throws IllegalStateException if not currently associated with a host. 664c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #getHost() 665cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 6662a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @NonNull 667c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton public final Object requireHost() { 668c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton Object host = getHost(); 669c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton if (host == null) { 670c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton throw new IllegalStateException("Fragment " + this + " not attached to a host."); 671cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 672c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton return host; 673c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton } 674c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton 675c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton /** 676c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * Return <code>requireActivity().getResources()</code>. 677c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton */ 678c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton @NonNull 679c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton final public Resources getResources() { 680c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton return requireContext().getResources(); 681cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 682d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 683cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 684cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized, styled CharSequence from the application's package's 685cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table. 686cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 687cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the CharSequence text 688cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 6892a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @NonNull 690a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final CharSequence getText(@StringRes int resId) { 691cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getText(resId); 692cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 694cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 695cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized string from the application's package's 696cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table. 697cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 698cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the string 699cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 7002a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @NonNull 701a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final String getString(@StringRes int resId) { 702cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getString(resId); 703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 704cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized formatted string from the application's package's 707cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table, substituting the format arguments as defined in 708cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link java.util.Formatter} and {@link java.lang.String#format}. 709cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 710cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the format string 711cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param formatArgs The format arguments that will be used for substitution. 712cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 7132a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @NonNull 714a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final String getString(@StringRes int resId, Object... formatArgs) { 715cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getString(resId, formatArgs); 716cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 717cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 718cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 719cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the FragmentManager for interacting with fragments associated 720cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * with this fragment's activity. Note that this will be non-null slightly 721cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * before {@link #getActivity()}, during the time from when the fragment is 722cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * placed in a {@link FragmentTransaction} until it is committed and 723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * attached to its activity. 7240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 7250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * <p>If this Fragment is a child of another Fragment, the FragmentManager 7260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * returned here will be the parent's {@link #getChildFragmentManager()}. 727c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 728c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #requireFragmentManager() 729cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 730b38fded102ffe4de21f2d048262f52d5bcefbfd5Jake Wharton @Nullable 731cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public FragmentManager getFragmentManager() { 732cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mFragmentManager; 733cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 734cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 735cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 736c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * Return the FragmentManager for interacting with fragments associated 737c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * with this fragment's activity. Note that this will available slightly 738c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * before {@link #getActivity()}, during the time from when the fragment is 739c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * placed in a {@link FragmentTransaction} until it is committed and 740c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * attached to its activity. 741c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 742c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * <p>If this Fragment is a child of another Fragment, the FragmentManager 743c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * returned here will be the parent's {@link #getChildFragmentManager()}. 744c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 745c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @throws IllegalStateException if not associated with a transaction or host. 746c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #getFragmentManager() 747c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton */ 748c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton @NonNull 749c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton public final FragmentManager requireFragmentManager() { 750c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton FragmentManager fragmentManager = getFragmentManager(); 751c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton if (fragmentManager == null) { 752c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton throw new IllegalStateException( 753c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton "Fragment " + this + " not associated with a fragment manager."); 754c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton } 755c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton return fragmentManager; 756c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton } 757c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton 758c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton /** 7590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Return a private FragmentManager for placing and managing Fragments 7600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * inside of this Fragment. 7610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 7622a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @NonNull 7630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final public FragmentManager getChildFragmentManager() { 7640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager == null) { 7650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn instantiateChildFragmentManager(); 7660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mState >= RESUMED) { 7670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchResume(); 7680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= STARTED) { 7690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStart(); 7700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= ACTIVITY_CREATED) { 7710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchActivityCreated(); 7720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= CREATED) { 7730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchCreate(); 7740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 7750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 7760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mChildFragmentManager; 7770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 7780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 7790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 780267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell * Return this fragment's child FragmentManager one has been previously created, 781267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell * otherwise null. 782267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell */ 7832a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 784267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell FragmentManager peekChildFragmentManager() { 785267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell return mChildFragmentManager; 786267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell } 787267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell 788267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell /** 7890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Returns the parent Fragment containing this Fragment. If this Fragment 7900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * is attached directly to an Activity, returns null. 7910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 7922a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 7930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final public Fragment getParentFragment() { 7940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mParentFragment; 7950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 7960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 7970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 798cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is currently added to its activity. 799cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 800cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isAdded() { 801d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy return mHost != null && mAdded; 802cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 803cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 804cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 8059c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * Return true if the fragment has been explicitly detached from the UI. 8069c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * That is, {@link FragmentTransaction#detach(Fragment) 8079c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * FragmentTransaction.detach(Fragment)} has been used on it. 8089c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn */ 8099c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn final public boolean isDetached() { 8109c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn return mDetached; 8119c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 8129c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 8139c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn /** 814cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if this fragment is currently being removed from its 815cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * activity. This is <em>not</em> whether its activity is finishing, but 816cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * rather whether it is in the process of being removed from its activity. 817cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 818cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isRemoving() { 819cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mRemoving; 820cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8214bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 822cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 823cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the layout is included as part of an activity view 824cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * hierarchy via the <fragment> tag. This will always be true when 825cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * fragments are created through the <fragment> tag, <em>except</em> 826cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * in the case where an old fragment is restored from a previous state and 827cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * it does not appear in the layout of the current state. 828cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 829cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isInLayout() { 830cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mInLayout; 831cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 832cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 833cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 834cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is in the resumed state. This is true 835cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for the duration of {@link #onResume()} and {@link #onPause()} as well. 836cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 837cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isResumed() { 83820735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell return mState >= RESUMED; 839cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8404bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 841cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 842cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is currently visible to the user. This means 8434bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * it: (1) has been added, (2) has its view attached to the window, and 844cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * (3) is not hidden. 845cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 846cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isVisible() { 847cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return isAdded() && !isHidden() && mView != null 848cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE; 849cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8504bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 851cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 852cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment has been hidden. By default fragments 853cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * are shown. You can find out about changes to this state with 854cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onHiddenChanged}. Note that the hidden state is orthogonal 855cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to other states -- that is, to be visible to the user, a fragment 856cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * must be both started and not hidden. 857cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 858cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isHidden() { 859cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mHidden; 860cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8613a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 8623a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown /** @hide */ 8638e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas @RestrictTo(LIBRARY_GROUP) 8643a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown final public boolean hasOptionsMenu() { 8653a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown return mHasMenu; 8663a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown } 8673a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 8683a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown /** @hide */ 8698e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas @RestrictTo(LIBRARY_GROUP) 8703a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown final public boolean isMenuVisible() { 8713a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown return mMenuVisible; 8723a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown } 8733a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 874cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 875cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the hidden state (as returned by {@link #isHidden()} of 876cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the fragment has changed. Fragments start out not hidden; this will 877cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * be called whenever the fragment changes state from that. 878527415d706bf580ff2bb7b492e5202b985cfa2c7Aurimas Liutikas * @param hidden True if the fragment is now hidden, false otherwise. 879cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 880cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onHiddenChanged(boolean hidden) { 881cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8824bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 883cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 884cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Control whether a fragment instance is retained across Activity 885cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * re-creation (such as from a configuration change). This can only 886cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * be used with fragments not in the back stack. If set, the fragment 887cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * lifecycle will be slightly different when an activity is recreated: 888cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <ul> 889cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still 890cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * will be, because the fragment is being detached from its current activity). 891cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onCreate(Bundle)} will not be called since the fragment 892cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is not being re-created. 893cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b> 894cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * still be called. 895cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * </ul> 896cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 897cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setRetainInstance(boolean retain) { 898cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mRetainInstance = retain; 899cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9004bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 901cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean getRetainInstance() { 902cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mRetainInstance; 903cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9044bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 905cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 906cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Report that this fragment would like to participate in populating 907cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the options menu by receiving a call to {@link #onCreateOptionsMenu} 908cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * and related methods. 909d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * 910cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param hasMenu If true, the fragment has menu items to contribute. 911cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 912cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setHasOptionsMenu(boolean hasMenu) { 913cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mHasMenu != hasMenu) { 914cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mHasMenu = hasMenu; 915cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (isAdded() && !isHidden()) { 9168491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy mHost.onSupportInvalidateOptionsMenu(); 917cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 918cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 919cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9202a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 9212a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn /** 9222a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * Set a hint for whether this fragment's menu should be visible. This 9232a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * is useful if you know that a fragment has been placed in your view 9242a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * hierarchy so that the user can not currently seen it, so any menu items 9252a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * it has should also not be shown. 9262a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * 9272a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * @param menuVisible The default is true, meaning the fragment's menu will 9282a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * be shown as usual. If false, the user will not see the menu. 9292a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn */ 9302a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn public void setMenuVisibility(boolean menuVisible) { 9312a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn if (mMenuVisible != menuVisible) { 9322a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn mMenuVisible = menuVisible; 9332a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn if (mHasMenu && isAdded() && !isHidden()) { 9348491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy mHost.onSupportInvalidateOptionsMenu(); 9352a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 9362a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 9372a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 9382a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 939cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 94079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * Set a hint to the system about whether this fragment's UI is currently visible 94179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * to the user. This hint defaults to true and is persistent across fragment instance 94279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * state save and restore. 943abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell * 94479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * <p>An app may set this to false to indicate that the fragment's UI is 94579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * scrolled out of visibility or is otherwise not directly visible to the user. 94679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * This may be used by the system to prioritize operations such as fragment lifecycle updates 94779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * or loader ordering behavior.</p> 948abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell * 9490244762c99db7b1fb6c4905bc1224fefac927014Adam Powell * <p><strong>Note:</strong> This method may be called outside of the fragment lifecycle. 9500244762c99db7b1fb6c4905bc1224fefac927014Adam Powell * and thus has no ordering guarantees with regard to fragment lifecycle method calls.</p> 9510244762c99db7b1fb6c4905bc1224fefac927014Adam Powell * 95279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @param isVisibleToUser true if this fragment's UI is currently visible to the user (default), 95379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * false if it is not. 954abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell */ 95579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell public void setUserVisibleHint(boolean isVisibleToUser) { 9563ab5a96f51cbd0498a62f1e91f1ef99e95cb1b1cAdam Powell if (!mUserVisibleHint && isVisibleToUser && mState < STARTED 957261fa1b6dce85674f9a6fbe8a48851c80701b1dbIan Lake && mFragmentManager != null && isAdded() && mIsCreated) { 958abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell mFragmentManager.performPendingDeferredStart(this); 959abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 96079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell mUserVisibleHint = isVisibleToUser; 961c83dccecb0ec4bf9f4befdb18caccb8f373ed7bcAdam Powell mDeferStart = mState < STARTED && !isVisibleToUser; 9620d29663c8688de94a3260584037c21dfd9e4cbfaIan Lake if (mSavedFragmentState != null) { 9630d29663c8688de94a3260584037c21dfd9e4cbfaIan Lake // Ensure that if the user visible hint is set before the Fragment has 9640d29663c8688de94a3260584037c21dfd9e4cbfaIan Lake // restored its state that we don't lose the new value 965e8ffa7a5775d29c6144ce0276cd4853baed5c1fbIan Lake mSavedUserVisibleHint = isVisibleToUser; 9660d29663c8688de94a3260584037c21dfd9e4cbfaIan Lake } 967abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 968abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 969abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell /** 97079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @return The current value of the user-visible hint on this fragment. 97179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @see #setUserVisibleHint(boolean) 972abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell */ 97379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell public boolean getUserVisibleHint() { 97479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell return mUserVisibleHint; 975abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 976abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 977abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell /** 978afe28d91550483f9b7a82076a507151b4defd9baIan Lake * Return the LoaderManager for this fragment. 979c559bbd18f472db18dd7cbc9f4c520ffdebd97e8Ian Lake * 980c559bbd18f472db18dd7cbc9f4c520ffdebd97e8Ian Lake * @deprecated Use 981c559bbd18f472db18dd7cbc9f4c520ffdebd97e8Ian Lake * {@link LoaderManager#getInstance(LifecycleOwner) LoaderManager.getInstance(this)}. 982cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 983c559bbd18f472db18dd7cbc9f4c520ffdebd97e8Ian Lake @Deprecated 984cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public LoaderManager getLoaderManager() { 985afe28d91550483f9b7a82076a507151b4defd9baIan Lake return LoaderManager.getInstance(this); 986cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 987d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 988cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 9898491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy * Call {@link Activity#startActivity(Intent)} from the fragment's 990cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * containing Activity. 991cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 992cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void startActivity(Intent intent) { 9930e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick startActivity(intent, null); 9940e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick } 9950e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick 9960e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick /** 9970e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick * Call {@link Activity#startActivity(Intent, Bundle)} from the fragment's 9980e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick * containing Activity. 9990e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick */ 10000e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick public void startActivity(Intent intent, @Nullable Bundle options) { 1001d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost == null) { 1002cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 1003cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 10040e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick mHost.onStartActivityFromFragment(this /*fragment*/, intent, -1, options); 1005cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1006d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1007cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 10088491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy * Call {@link Activity#startActivityForResult(Intent, int)} from the fragment's 1009cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * containing Activity. 1010cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1011cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void startActivityForResult(Intent intent, int requestCode) { 10120e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick startActivityForResult(intent, requestCode, null); 10130e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick } 10140e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick 10150e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick /** 10160e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick * Call {@link Activity#startActivityForResult(Intent, int, Bundle)} from the fragment's 10170e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick * containing Activity. 10180e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick */ 10190e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick public void startActivityForResult(Intent intent, int requestCode, @Nullable Bundle options) { 1020d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost == null) { 1021cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 1022cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 10230e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick mHost.onStartActivityFromFragment(this /*fragment*/, intent, requestCode, options); 1024fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri } 1025fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri 1026fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri /** 1027fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri * Call {@link Activity#startIntentSenderForResult(IntentSender, int, Intent, int, int, int, 1028fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri * Bundle)} from the fragment's containing Activity. 1029fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri */ 1030fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri public void startIntentSenderForResult(IntentSender intent, int requestCode, 1031fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, 1032fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri Bundle options) throws IntentSender.SendIntentException { 1033fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri if (mHost == null) { 1034fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 1035fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri } 1036fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri mHost.onStartIntentSenderFromFragment(this, intent, requestCode, fillInIntent, flagsMask, 1037fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri flagsValues, extraFlags, options); 1038cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1039d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1040cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1041cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Receive the result from a previous call to 1042cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #startActivityForResult(Intent, int)}. This follows the 1043cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * related Activity API as described there in 1044cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onActivityResult(int, int, Intent)}. 1045d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * 1046cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param requestCode The integer request code originally supplied to 1047cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * startActivityForResult(), allowing you to identify who this 1048cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * result came from. 1049cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resultCode The integer result code returned by the child activity 1050cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * through its setResult(). 1051cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param data An Intent, which can return result data to the caller 1052cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * (various data can be attached to Intent "extras"). 1053cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1054cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onActivityResult(int requestCode, int resultCode, Intent data) { 1055cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1056d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1057cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1058e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Requests permissions to be granted to this application. These permissions 1059e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * must be requested in your manifest, they should not be granted to your app, 1060e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * and they should have protection level {@link android.content.pm.PermissionInfo 1061e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * #PROTECTION_DANGEROUS dangerous}, regardless whether they are declared by 1062e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * the platform or a third-party app. 1063e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1064e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Normal permissions {@link android.content.pm.PermissionInfo#PROTECTION_NORMAL} 1065e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * are granted at install time if requested in the manifest. Signature permissions 1066e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * {@link android.content.pm.PermissionInfo#PROTECTION_SIGNATURE} are granted at 1067e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * install time if requested in the manifest and the signature of your app matches 1068e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * the signature of the app declaring the permissions. 1069e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1070e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1071e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * If your app does not have the requested permissions the user will be presented 1072e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * with UI for accepting them. After the user has accepted or rejected the 1073e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * requested permissions you will receive a callback on {@link 1074e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * #onRequestPermissionsResult(int, String[], int[])} reporting whether the 1075e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * permissions were granted or not. 1076e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1077e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1078e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Note that requesting a permission does not guarantee it will be granted and 1079e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * your app should be able to run without having this permission. 1080e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1081e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1082e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * This method may start an activity allowing the user to choose which permissions 1083e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * to grant and which to reject. Hence, you should be prepared that your activity 1084e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * may be paused and resumed. Further, granting some permissions may require 1085e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * a restart of you application. In such a case, the system will recreate the 1086e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * activity stack before delivering the result to {@link 1087e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * #onRequestPermissionsResult(int, String[], int[])}. 1088e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1089e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1090e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * When checking whether you have a permission you should use {@link 1091e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * android.content.Context#checkSelfPermission(String)}. 1092e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1093e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 10942750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * Calling this API for permissions already granted to your app would show UI 10952750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * to the user to decided whether the app can still hold these permissions. This 10962750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * can be useful if the way your app uses the data guarded by the permissions 10972750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * changes significantly. 10982750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * </p> 10992750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * <p> 1100e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * A sample permissions request looks like this: 1101e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1102e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <code><pre><p> 1103e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * private void showContacts() { 1104e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * if (getActivity().checkSelfPermission(Manifest.permission.READ_CONTACTS) 1105e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * != PackageManager.PERMISSION_GRANTED) { 1106e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, 1107e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * PERMISSIONS_REQUEST_READ_CONTACTS); 1108e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } else { 1109e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * doShowContacts(); 1110e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1111e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1112e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1113e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * {@literal @}Override 1114e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * public void onRequestPermissionsResult(int requestCode, String[] permissions, 1115e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * int[] grantResults) { 1116e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * if (requestCode == PERMISSIONS_REQUEST_READ_CONTACTS 1117e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 1118e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * doShowContacts(); 1119e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1120e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1121e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </code></pre></p> 1122e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1123e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param permissions The requested permissions. 1124e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param requestCode Application specific request code to match with a result 1125e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * reported to {@link #onRequestPermissionsResult(int, String[], int[])}. 1126e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1127e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #onRequestPermissionsResult(int, String[], int[]) 1128e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see android.content.Context#checkSelfPermission(String) 1129e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav */ 1130e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav public final void requestPermissions(@NonNull String[] permissions, int requestCode) { 1131e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav if (mHost == null) { 1132e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 1133e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 11345fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian mHost.onRequestPermissionsFromFragment(this, permissions, requestCode); 1135e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1136e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav 1137e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /** 1138e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Callback for the result from requesting permissions. This method 1139e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * is invoked for every call on {@link #requestPermissions(String[], int)}. 1140dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * <p> 1141dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * <strong>Note:</strong> It is possible that the permissions request interaction 1142dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * with the user is interrupted. In this case you will receive empty permissions 1143dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * and results arrays which should be treated as a cancellation. 1144dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * </p> 1145e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1146e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}. 1147e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param permissions The requested permissions. Never null. 1148e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param grantResults The grant results for the corresponding permissions 1149e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * which is either {@link android.content.pm.PackageManager#PERMISSION_GRANTED} 1150e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * or {@link android.content.pm.PackageManager#PERMISSION_DENIED}. Never null. 1151e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1152e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #requestPermissions(String[], int) 1153e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav */ 1154e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, 1155e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav @NonNull int[] grantResults) { 1156e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /* callback - do nothing */ 1157e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1158e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav 1159e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /** 1160e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Gets whether you should show UI with rationale for requesting a permission. 1161e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * You should do this only if you do not have the permission and the context in 1162e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * which the permission is requested does not clearly communicate to the user 1163e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * what would be the benefit from granting this permission. 1164e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1165e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * For example, if you write a camera app, requesting the camera permission 1166e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * would be expected by the user and no rationale for why it is requested is 1167e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * needed. If however, the app needs location for tagging photos then a non-tech 1168e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * savvy user may wonder how location is related to taking photos. In this case 1169e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * you may choose to show UI with rationale of requesting this permission. 1170e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1171e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1172e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param permission A permission your app wants to request. 1173e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @return Whether you can show permission rationale UI. 1174e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1175e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see Context#checkSelfPermission(String) 1176e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #requestPermissions(String[], int) 1177e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #onRequestPermissionsResult(int, String[], int[]) 1178e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav */ 1179e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav public boolean shouldShowRequestPermissionRationale(@NonNull String permission) { 1180e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav if (mHost != null) { 1181e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav return mHost.onShouldShowRequestPermissionRationale(permission); 1182e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1183e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav return false; 1184e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1185e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav 1186e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /** 118796221034e4a23a2abb83f772a0281bb197ac5ac0George Mount * Returns the LayoutInflater used to inflate Views of this Fragment. The default 118896221034e4a23a2abb83f772a0281bb197ac5ac0George Mount * implementation will throw an exception if the Fragment is not attached. 118996221034e4a23a2abb83f772a0281bb197ac5ac0George Mount * 1190995c3504e6c5b1d20368c36193b44a7e6844709dGeorge Mount * @param savedInstanceState If the fragment is being re-created from 1191995c3504e6c5b1d20368c36193b44a7e6844709dGeorge Mount * a previous saved state, this is the state. 119296221034e4a23a2abb83f772a0281bb197ac5ac0George Mount * @return The LayoutInflater used to inflate Views of this Fragment. 1193cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1194b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton @NonNull 1195b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton public LayoutInflater onGetLayoutInflater(@Nullable Bundle savedInstanceState) { 11960abeed582ee0a105edb41181d76e8ee034750f22George Mount // TODO: move the implementation in getLayoutInflater to here 11970abeed582ee0a105edb41181d76e8ee034750f22George Mount return getLayoutInflater(savedInstanceState); 11980abeed582ee0a105edb41181d76e8ee034750f22George Mount } 11990abeed582ee0a105edb41181d76e8ee034750f22George Mount 12000abeed582ee0a105edb41181d76e8ee034750f22George Mount /** 12018b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * Returns the cached LayoutInflater used to inflate Views of this Fragment. If 12028b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #onGetLayoutInflater(Bundle)} has not been called {@link #onGetLayoutInflater(Bundle)} 12038b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * will be called with a {@code null} argument and that value will be cached. 12048b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * <p> 12058b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * The cached LayoutInflater will be replaced immediately prior to 12068b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} and cleared immediately after 12078b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #onDetach()}. 12088b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * 12098b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * @return The LayoutInflater used to inflate Views of this Fragment. 12108b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount */ 12118b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount public final LayoutInflater getLayoutInflater() { 12128b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount if (mLayoutInflater == null) { 12138b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount return performGetLayoutInflater(null); 12148b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount } 12158b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount return mLayoutInflater; 12168b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount } 12178b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount 12188b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount /** 12198b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * Calls {@link #onGetLayoutInflater(Bundle)} and caches the result for use by 12208b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #getLayoutInflater()}. 12218b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * 12228b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * @param savedInstanceState If the fragment is being re-created from 12238b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * a previous saved state, this is the state. 12248b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * @return The LayoutInflater used to inflate Views of this Fragment. 12258b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount */ 1226b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton @NonNull 1227b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton LayoutInflater performGetLayoutInflater(@Nullable Bundle savedInstanceState) { 12288b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount LayoutInflater layoutInflater = onGetLayoutInflater(savedInstanceState); 12298b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount mLayoutInflater = layoutInflater; 12308b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount return mLayoutInflater; 12318b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount } 12328b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount 12338b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount /** 12348b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * Override {@link #onGetLayoutInflater(Bundle)} when you need to change the 12358b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * LayoutInflater or call {@link #getLayoutInflater()} when you want to 12368b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * retrieve the current LayoutInflater. 12378b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * 12380abeed582ee0a105edb41181d76e8ee034750f22George Mount * @hide 12398b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * @deprecated Override {@link #onGetLayoutInflater(Bundle)} or call 12408b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #getLayoutInflater()} instead of this method. 12410abeed582ee0a105edb41181d76e8ee034750f22George Mount */ 12420abeed582ee0a105edb41181d76e8ee034750f22George Mount @Deprecated 1243b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton @NonNull 12440abeed582ee0a105edb41181d76e8ee034750f22George Mount @RestrictTo(LIBRARY_GROUP) 1245b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton public LayoutInflater getLayoutInflater(@Nullable Bundle savedFragmentState) { 124696221034e4a23a2abb83f772a0281bb197ac5ac0George Mount if (mHost == null) { 12470abeed582ee0a105edb41181d76e8ee034750f22George Mount throw new IllegalStateException("onGetLayoutInflater() cannot be executed until the " 124896221034e4a23a2abb83f772a0281bb197ac5ac0George Mount + "Fragment is attached to the FragmentManager."); 124996221034e4a23a2abb83f772a0281bb197ac5ac0George Mount } 12508491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy LayoutInflater result = mHost.onGetLayoutInflater(); 12510f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell getChildFragmentManager(); // Init if needed; use raw implementation below. 12524bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas LayoutInflaterCompat.setFactory2(result, mChildFragmentManager.getLayoutInflaterFactory()); 12530f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell return result; 1254cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1255d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1256cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1257cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a fragment is being created as part of a view layout 1258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * inflation, typically from setting the content view of an activity. This 12599277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * may be called immediately after the fragment is created from a <fragment> 1260cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tag in a layout file. Note this is <em>before</em> the fragment's 1261cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onAttach(Activity)} has been called; all you should do here is 12629277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * parse the attributes and save them away. 12634bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1264cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>This is called every time the fragment is inflated, even if it is 12659277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * being inflated into a new instance with saved state. It typically makes 12669277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * sense to re-parse the parameters each time, to allow them to change with 12679277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * different configurations.</p> 12689277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 12699277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>Here is a typical implementation of a fragment that can take parameters 12709277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * both through attributes supplied here as well from {@link #getArguments()}:</p> 12719277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 1272f266a0a76eb23a0a00ae16f823df2af73bff480fAurimas Liutikas * {@sample frameworks/support/samples/Support4Demos/src/main/java/com/example/android/supportv4/app/FragmentArgumentsSupport.java 12739277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * fragment} 12749277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 12759277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>Note that parsing the XML attributes uses a "styleable" resource. The 12769277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * declaration for the styleable used here is:</p> 12779277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 1278f266a0a76eb23a0a00ae16f823df2af73bff480fAurimas Liutikas * {@sample frameworks/support/samples/Support4Demos/src/main/res/values/attrs.xml fragment_arguments} 12794bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 12809277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>The fragment can then be declared within its activity's content layout 12819277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * through a tag like this:</p> 12829277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 1283f266a0a76eb23a0a00ae16f823df2af73bff480fAurimas Liutikas * {@sample frameworks/support/samples/Support4Demos/src/main/res/layout/fragment_arguments_support.xml from_attributes} 12849277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 12859277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>This fragment can also be created dynamically from arguments given 12869277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * at runtime in the arguments Bundle; here is an example of doing so at 12879277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * creation of the containing activity:</p> 12889277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 1289f266a0a76eb23a0a00ae16f823df2af73bff480fAurimas Liutikas * {@sample frameworks/support/samples/Support4Demos/src/main/java/com/example/android/supportv4/app/FragmentArgumentsSupport.java 12909277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * create} 12919277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 1292d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * @param context The Activity that is inflating this fragment. 1293cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param attrs The attributes at the tag where the fragment is 1294cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * being created. 1295cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 1296cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 1297cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1298916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1299d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) { 1300d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = true; 1301d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy final Activity hostActivity = mHost == null ? null : mHost.getActivity(); 1302d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (hostActivity != null) { 1303d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = false; 1304d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy onInflate(hostActivity, attrs, savedInstanceState); 1305d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1306d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1307d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1308d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy /** 1309d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Called when a fragment is being created as part of a view layout 1310d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * inflation, typically from setting the content view of an activity. 1311d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * 1312d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * @deprecated See {@link #onInflate(Context, AttributeSet, Bundle)}. 1313d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy */ 1314d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Deprecated 1315916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 13169277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { 1317cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1318cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 13199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 1320cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1321cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * Called when a fragment is attached as a child of this fragment. 1322cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * 1323cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * <p>This is called after the attached fragment's <code>onAttach</code> and before 1324cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * the attached fragment's <code>onCreate</code> if the fragment has not yet had a previous 1325cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * call to <code>onCreate</code>.</p> 1326cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * 1327cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * @param childFragment child fragment being attached 1328cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell */ 1329cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell public void onAttachFragment(Fragment childFragment) { 1330cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell } 1331cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell 1332cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell /** 1333d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Called when a fragment is first attached to its context. 1334d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * {@link #onCreate(Bundle)} will be called after this. 1335d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy */ 1336916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1337d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy public void onAttach(Context context) { 1338d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = true; 1339d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy final Activity hostActivity = mHost == null ? null : mHost.getActivity(); 1340d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (hostActivity != null) { 1341d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = false; 1342d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy onAttach(hostActivity); 1343d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1344d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1345d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1346d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy /** 1347cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a fragment is first attached to its activity. 1348cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreate(Bundle)} will be called after this. 1349d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * 1350d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * @deprecated See {@link #onAttach(Context)}. 1351cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1352d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Deprecated 1353916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1354cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onAttach(Activity activity) { 1355cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1356cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1357d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1358cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 135915e593ea3575512d7072240d1db9d74fad8749a3George Mount * Called when a fragment loads an animation. Note that if 136015e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int)} was called with 136115e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link Animator} resources instead of {@link Animation} resources, {@code nextAnim} 136215e593ea3575512d7072240d1db9d74fad8749a3George Mount * will be an animator resource. 136315e593ea3575512d7072240d1db9d74fad8749a3George Mount * 136415e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param transit The value set in {@link FragmentTransaction#setTransition(int)} or 0 if not 136515e593ea3575512d7072240d1db9d74fad8749a3George Mount * set. 136615e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param enter {@code true} when the fragment is added/attached/shown or {@code false} when 136715e593ea3575512d7072240d1db9d74fad8749a3George Mount * the fragment is removed/detached/hidden. 136815e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param nextAnim The resource set in 136915e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int)}, 137015e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int, int, int)}, or 137115e593ea3575512d7072240d1db9d74fad8749a3George Mount * 0 if neither was called. The value will depend on the current operation. 1372cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 13739277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { 1374cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return null; 1375cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1376d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1377cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 137815e593ea3575512d7072240d1db9d74fad8749a3George Mount * Called when a fragment loads an animator. This will be called when 137915e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link #onCreateAnimation(int, boolean, int)} returns null. Note that if 138015e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int)} was called with 138115e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link Animation} resources instead of {@link Animator} resources, {@code nextAnim} 138215e593ea3575512d7072240d1db9d74fad8749a3George Mount * will be an animation resource. 138315e593ea3575512d7072240d1db9d74fad8749a3George Mount * 138415e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param transit The value set in {@link FragmentTransaction#setTransition(int)} or 0 if not 138515e593ea3575512d7072240d1db9d74fad8749a3George Mount * set. 138615e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param enter {@code true} when the fragment is added/attached/shown or {@code false} when 138715e593ea3575512d7072240d1db9d74fad8749a3George Mount * the fragment is removed/detached/hidden. 138815e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param nextAnim The resource set in 138915e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int)}, 139015e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int, int, int)}, or 139115e593ea3575512d7072240d1db9d74fad8749a3George Mount * 0 if neither was called. The value will depend on the current operation. 139215e593ea3575512d7072240d1db9d74fad8749a3George Mount */ 139315e593ea3575512d7072240d1db9d74fad8749a3George Mount public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) { 139415e593ea3575512d7072240d1db9d74fad8749a3George Mount return null; 139515e593ea3575512d7072240d1db9d74fad8749a3George Mount } 139615e593ea3575512d7072240d1db9d74fad8749a3George Mount 139715e593ea3575512d7072240d1db9d74fad8749a3George Mount /** 1398cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to do initial creation of a fragment. This is called after 1399cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onAttach(Activity)} and before 1400cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 14014bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1402cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>Note that this can be called while the fragment's activity is 1403cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * still in the process of being created. As such, you can not rely 1404cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on things like the activity's content view hierarchy being initialized 1405cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * at this point. If you want to do work once the activity itself is 1406cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * created, see {@link #onActivityCreated(Bundle)}. 1407277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell * 1408277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell * <p>Any restored child fragments will be created before the base 1409277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell * <code>Fragment.onCreate</code> method returns.</p> 14104bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1411cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 1412cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 1413cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1414916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1415c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy public void onCreate(@Nullable Bundle savedInstanceState) { 1416cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 14179375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell restoreChildFragmentState(savedInstanceState); 1418fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell if (mChildFragmentManager != null 1419fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell && !mChildFragmentManager.isStateAtLeast(Fragment.CREATED)) { 1420fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell mChildFragmentManager.dispatchCreate(); 1421fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell } 14229375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell } 14239375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell 14249375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell /** 14259375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * Restore the state of the child FragmentManager. Called by either 14269375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * {@link #onCreate(Bundle)} for non-retained instance fragments or by 14279375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * {@link FragmentManagerImpl#moveToState(Fragment, int, int, int, boolean)} 14289375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * for retained instance fragments. 14299375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * 14309375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * <p><strong>Postcondition:</strong> if there were child fragments to restore, 14319375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * the child FragmentManager will be instantiated and brought to the {@link #CREATED} state. 14329375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * </p> 14339375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * 14349375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * @param savedInstanceState the savedInstanceState potentially containing fragment info 14359375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell */ 14369375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell void restoreChildFragmentState(@Nullable Bundle savedInstanceState) { 1437277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell if (savedInstanceState != null) { 1438277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell Parcelable p = savedInstanceState.getParcelable( 1439277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell FragmentActivity.FRAGMENTS_TAG); 1440277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell if (p != null) { 1441277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell if (mChildFragmentManager == null) { 1442277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell instantiateChildFragmentManager(); 1443277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell } 1444c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mChildFragmentManager.restoreAllState(p, mChildNonConfig); 1445c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mChildNonConfig = null; 1446277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell mChildFragmentManager.dispatchCreate(); 1447277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell } 1448277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell } 1449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 14500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1451cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1452cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to have the fragment instantiate its user interface view. 1453cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is optional, and non-graphical fragments can return null (which 1454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is the default implementation). This will be called between 1455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}. 14564bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1457cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>If you return a View from here, you will later be called in 1458cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onDestroyView} when the view is being released. 14594bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1460cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param inflater The LayoutInflater object that can be used to inflate 1461cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * any views in the fragment, 1462cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param container If non-null, this is the parent view that the fragment's 1463cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * UI should be attached to. The fragment should not add the view itself, 1464cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * but this can be used to generate the LayoutParams of the view. 1465cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If non-null, this fragment is being re-constructed 1466cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * from a previous saved state as given here. 14674bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1468cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return Return the View for the fragment's UI, or null. 1469cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1470c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy @Nullable 1471b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, 1472a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye @Nullable Bundle savedInstanceState) { 1473cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return null; 1474cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 14750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1476cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1477e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} 1478e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * has returned, but before any saved state has been restored in to the view. 1479e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * This gives subclasses a chance to initialize themselves once 1480e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * they know their view hierarchy has been completely created. The fragment's 1481e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * view hierarchy is not however attached to its parent at this point. 1482e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 1483e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * @param savedInstanceState If non-null, this fragment is being re-constructed 1484e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * from a previous saved state as given here. 1485e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn */ 1486cb3829a5ee01e3c0783019c04d083bde4d0082e8Jake Wharton public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 1487e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 1488e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 1489e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn /** 1490cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}), 1491cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if provided. 14924bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1493cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return The fragment's root view, or null if it has no layout. 1494cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1495a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye @Nullable 1496cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public View getView() { 1497cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mView; 1498cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 14994bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1500cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1501cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment's activity has been created and this 1502cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * fragment's view hierarchy instantiated. It can be used to do final 1503cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * initialization once these pieces are in place, such as retrieving 1504cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * views or restoring state. It is also useful for fragments that use 1505cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #setRetainInstance(boolean)} to retain their instance, 1506cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * as this callback tells the fragment when it is fully associated with 1507cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the new activity instance. This is called after {@link #onCreateView} 15080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * and before {@link #onViewStateRestored(Bundle)}. 15090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 1510cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 1511cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 1512cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1513916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1514a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public void onActivityCreated(@Nullable Bundle savedInstanceState) { 1515cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1516cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 15170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 15180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 15190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Called when all saved state has been restored into the view hierarchy 15200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * of the fragment. This can be used to do initialization based on saved 15210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * state that you are letting the view hierarchy track itself, such as 15220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * whether check box widgets are currently checked. This is called 15230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * after {@link #onActivityCreated(Bundle)} and before 15240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * {@link #onStart()}. 15250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 15260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 15270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * a previous saved state, this is the state. 15280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 1529916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1530a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public void onViewStateRestored(@Nullable Bundle savedInstanceState) { 15310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = true; 15320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 15330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1534cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is visible to the user. This is generally 1536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onStart() Activity.onStart} of the containing 1537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1539916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1540cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onStart() { 1541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1542cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1543d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is visible to the user and actively running. 1546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is generally 1547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onResume() Activity.onResume} of the containing 1548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1550916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1551cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onResume() { 1552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 15544bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to ask the fragment to save its current dynamic state, so it 1557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can later be reconstructed in a new instance of its process is 1558cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * restarted. If a new instance of the fragment later needs to be 1559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * created, the data you place in the Bundle here will be available 1560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * in the Bundle given to {@link #onCreate(Bundle)}, 1561cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}, and 1562cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onActivityCreated(Bundle)}. 1563cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1564cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>This corresponds to {@link Activity#onSaveInstanceState(Bundle) 1565cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity.onSaveInstanceState(Bundle)} and most of the discussion there 1566cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * applies here as well. Note however: <em>this method may be called 1567cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * at any time before {@link #onDestroy()}</em>. There are many situations 1568cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * where a fragment may be mostly torn down (such as when placed on the 1569cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * back stack with no UI showing), but its state will not be saved until 1570cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * its owning activity actually needs to save its state. 1571cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1572cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param outState Bundle in which to place your saved state. 1573cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1574abdae2e27083efa81020e1619250fb2864f3bbc4Jake Wharton public void onSaveInstanceState(@NonNull Bundle outState) { 1575cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 15765fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 15775fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian /** 15785fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * Called when the Fragment's activity changes from fullscreen mode to multi-window mode and 15795fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * visa-versa. This is generally tied to {@link Activity#onMultiWindowModeChanged} of the 15805fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * containing Activity. 15815fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * 15825fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * @param isInMultiWindowMode True if the activity is in multi-window mode. 15835fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian */ 15845fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { 15855fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 15865fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 15875fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian /** 15885fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * Called by the system when the activity changes to and from picture-in-picture mode. This is 15895fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * generally tied to {@link Activity#onPictureInPictureModeChanged} of the containing Activity. 15905fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * 15915fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode. 15925fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian */ 15935fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { 15945fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 15955fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 159690ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas @Override 1597916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1598cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onConfigurationChanged(Configuration newConfig) { 1599cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1600cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16015fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 1602cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1603cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is no longer resumed. This is generally 1604cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onPause() Activity.onPause} of the containing 1605cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1606cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1607916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1608cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onPause() { 1609cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1610cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16114bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1612cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1613cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is no longer started. This is generally 1614cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onStop() Activity.onStop} of the containing 1615cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1616cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1617916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1618cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onStop() { 1619cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1620cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1621916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell 162290ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas @Override 1623916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1624cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onLowMemory() { 1625cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1626cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16274bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1628cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1629cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the view previously created by {@link #onCreateView} has 1630cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * been detached from the fragment. The next time the fragment needs 1631cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to be displayed, a new view will be created. This is called 1632cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * after {@link #onStop()} and before {@link #onDestroy()}. It is called 1633cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <em>regardless</em> of whether {@link #onCreateView} returned a 1634cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * non-null view. Internally it is called after the view's state has 1635cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * been saved but before it has been removed from its parent. 1636cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1637916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1638cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroyView() { 1639cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1640cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16414bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1642cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1643cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is no longer in use. This is called 1644cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * after {@link #onStop()} and before {@link #onDetach()}. 1645cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1646916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1647cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroy() { 1648cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 16490d429d5f5bb0d6197d5c7a24b5c0bb5bcd5db8cdIan Lake // Use mStateSaved instead of isStateSaved() since we're past onStop() 16500d429d5f5bb0d6197d5c7a24b5c0bb5bcd5db8cdIan Lake if (mViewModelStore != null && !mHost.mFragmentManager.mStateSaved) { 165141516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake mViewModelStore.clear(); 165241516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake } 1653cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1654cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1655cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 16569c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * Called by the fragment manager once this fragment has been removed, 16579c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * so that we don't have any left-over state if the application decides 16589c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * to re-use the instance. This only clears state that the framework 16599c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * internally manages, not things the application sets. 16609c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn */ 16619c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void initState() { 16629c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mIndex = -1; 16639c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mWho = null; 16649c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mAdded = false; 16659c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRemoving = false; 16669c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFromLayout = false; 16679c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mInLayout = false; 16689c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRestored = false; 16699c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mBackStackNesting = 0; 16709c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFragmentManager = null; 16716252d78085a07c9d6bb4645a4e8086bf23b0a49aTim Kilbourn mChildFragmentManager = null; 1672d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mHost = null; 16739c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFragmentId = 0; 16749c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mContainerId = 0; 16759c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mTag = null; 16769c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mHidden = false; 16779c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mDetached = false; 16789c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRetaining = false; 16799c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 16809c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 16819c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn /** 1682cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is no longer attached to its activity. This 1683cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is called after {@link #onDestroy()}. 1684cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1685916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1686cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDetach() { 1687cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1688cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16894bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1690cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 16919375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * Initialize the contents of the Fragment host's standard options menu. You 1692cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * should place your menu items in to <var>menu</var>. For this method 1693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to be called, you must have first called {@link #setHasOptionsMenu}. See 1694cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu} 1695cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for more information. 16964bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1697cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu in which you place your items. 16984bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1699cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #setHasOptionsMenu 1700cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onPrepareOptionsMenu 1701cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onOptionsItemSelected 1702cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 1704cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 17079375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * Prepare the Fragment host's standard options menu to be displayed. This is 1708cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * called right before the menu is shown, every time it is shown. You can 1709cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * use this method to efficiently enable/disable items or otherwise 1710cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * dynamically modify the contents. See 1711cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu} 1712cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for more information. 17134bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1714cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu as last shown or first initialized by 1715cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * onCreateOptionsMenu(). 17164bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1717cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #setHasOptionsMenu 1718cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onCreateOptionsMenu 1719cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1720cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onPrepareOptionsMenu(Menu menu) { 1721cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1722cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1724cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when this fragment's option menu items are no longer being 1725cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * included in the overall options menu. Receiving this call means that 1726cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the menu needed to be rebuilt, but this fragment's items were not 1727cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * included in the newly built menu (its {@link #onCreateOptionsMenu(Menu, MenuInflater)} 1728cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * was not called). 1729cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1730cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroyOptionsMenu() { 1731cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 17324bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1733cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1734cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever an item in your options menu is selected. 1735cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * The default implementation simply returns false to have the normal 1736cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * processing happen (calling the item's Runnable or sending a message to 1737cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * its Handler as appropriate). You can use this method for any items 1738cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for which you would like to do processing without those other 1739cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * facilities. 17404bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1741cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>Derived classes should call through to the base class for it to 1742cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * perform the default menu handling. 17434bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1744cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param item The menu item that was selected. 17454bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1746cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return boolean Return false to allow normal menu processing to 1747cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * proceed, true to consume it here. 17484bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1749cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onCreateOptionsMenu 1750cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1751cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public boolean onOptionsItemSelected(MenuItem item) { 1752cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return false; 1753cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1754cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1755cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1756cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever the options menu is being closed (either by the user canceling 1757cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the menu with the back/menu button, or when an item is selected). 17584bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1759cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu as last shown or first initialized by 1760cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * onCreateOptionsMenu(). 1761cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1762cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onOptionsMenuClosed(Menu menu) { 1763cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 17644bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1765cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1766cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a context menu for the {@code view} is about to be shown. 1767cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Unlike {@link #onCreateOptionsMenu}, this will be called every 1768cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * time the context menu is about to be shown and should be populated for 1769cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the view (or item inside the view for {@link AdapterView} subclasses, 1770cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * this can be found in the {@code menuInfo})). 1771cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1772cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an 1773cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * item has been selected. 1774cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1775cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * The default implementation calls up to 1776cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though 1777cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * you can not call this implementation if you don't want that behavior. 1778cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1779cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * It is not safe to hold onto the context menu after this method returns. 1780cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@inheritDoc} 1781cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1782d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Override 1783cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 1784cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn getActivity().onCreateContextMenu(menu, v, menuInfo); 1785cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1786cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1787cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1788cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Registers a context menu to be shown for the given view (multiple views 1789cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can show the context menu). This method will set the 1790cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link OnCreateContextMenuListener} on the view to this fragment, so 1791cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be 1792cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * called when it is time to show the context menu. 17934bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1794cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #unregisterForContextMenu(View) 1795cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param view The view that should show a context menu. 1796cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1797cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void registerForContextMenu(View view) { 1798cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn view.setOnCreateContextMenuListener(this); 1799cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 18004bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1801cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1802cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Prevents a context menu to be shown for the given view. This method will 1803cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * remove the {@link OnCreateContextMenuListener} on the view. 18044bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1805cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #registerForContextMenu(View) 1806cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param view The view that should stop showing a context menu. 1807cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1808cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void unregisterForContextMenu(View view) { 1809cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn view.setOnCreateContextMenuListener(null); 1810cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 18114bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1812cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1813cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever an item in a context menu is selected. The 1814cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default implementation simply returns false to have the normal processing 1815cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * happen (calling the item's Runnable or sending a message to its Handler 1816cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * as appropriate). You can use this method for any items for which you 1817cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * would like to do processing without those other facilities. 1818cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1819cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Use {@link MenuItem#getMenuInfo()} to get extra information set by the 1820cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * View that added this menu item. 1821cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1822cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Derived classes should call through to the base class for it to perform 1823cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the default menu handling. 18244bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1825cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param item The context menu item that was selected. 1826cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return boolean Return false to allow normal context menu processing to 1827cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * proceed, true to consume it here. 1828cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1829cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public boolean onContextItemSelected(MenuItem item) { 1830cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return false; 1831cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1832e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes 1833cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 18349306f07b1d66f4974a81f781d29739b30124fff0George Mount * When custom transitions are used with Fragments, the enter transition callback 18359f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is called when this Fragment is attached or detached when not popping the back stack. 18369f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 18379306f07b1d66f4974a81f781d29739b30124fff0George Mount * @param callback Used to manipulate the shared element transitions on this Fragment 18389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when added not as a pop from the back stack. 18399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 1840b1413bc4de16e05ae0455cad93f1edfbcc4eced2George Mount public void setEnterSharedElementCallback(SharedElementCallback callback) { 1841990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mEnterTransitionCallback = callback; 18429f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 18439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 18449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 18459306f07b1d66f4974a81f781d29739b30124fff0George Mount * When custom transitions are used with Fragments, the exit transition callback 18469f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is called when this Fragment is attached or detached when popping the back stack. 18479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 18489306f07b1d66f4974a81f781d29739b30124fff0George Mount * @param callback Used to manipulate the shared element transitions on this Fragment 18499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when added as a pop from the back stack. 18509f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 1851b1413bc4de16e05ae0455cad93f1edfbcc4eced2George Mount public void setExitSharedElementCallback(SharedElementCallback callback) { 1852990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mExitTransitionCallback = callback; 18539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 18549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 18559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 18569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views into the initial scene. The entering 18579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 18589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 18599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 18609f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null, 18619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. 18629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 18639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views into the initial Scene. 18649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 18652a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setEnterTransition(@Nullable Object transition) { 1866990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mEnterTransition = transition; 18679f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 18689f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 18699f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 18709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views into the initial scene. The entering 18719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 18729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 18739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 18749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#INVISIBLE} to {@link View#VISIBLE}. 18759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 18769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views into the initial Scene. 18779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 18782a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 18799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getEnterTransition() { 1880990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 1881990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 1882990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 1883990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mEnterTransition; 18849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 18859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 18869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 18879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views out of the scene when the Fragment is 18889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * preparing to be removed, hidden, or detached because of popping the back stack. The exiting 18899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 18909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 18919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 18929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null, 18939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. If nothing is set, the default will be to 18949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * use the same value as set in {@link #setEnterTransition(Object)}. 18959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 18969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views out of the Scene when the Fragment 1897a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * is preparing to close. <code>transition</code> must be an 1898a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * {@link android.transition.Transition android.transition.Transition} or 1899ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * {@link androidx.transition.Transition androidx.transition.Transition}. 19009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19012a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setReturnTransition(@Nullable Object transition) { 1902990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mReturnTransition = transition; 19039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views out of the scene when the Fragment is 19079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * preparing to be removed, hidden, or detached because of popping the back stack. The exiting 19089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 19099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 19109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 19119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null, 19129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. 19139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views out of the Scene when the Fragment 19159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is preparing to close. 19169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19172a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 19189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getReturnTransition() { 1919990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 1920990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 1921990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 1922990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mReturnTransition == USE_DEFAULT_TRANSITION ? getEnterTransition() 1923990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount : mAnimationInfo.mReturnTransition; 19249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19279f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views out of the scene when the 19289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * fragment is removed, hidden, or detached when not popping the back stack. 19299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * The exiting Views will be those that are regular Views or ViewGroups that 19309f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 19319f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as exiting is governed by changing visibility 19329f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will 19339f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * remain unaffected. 19349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19359f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views out of the Scene when the Fragment 1936a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * is being closed not due to popping the back stack. <code>transition</code> 1937a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * must be an 1938a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * {@link android.transition.Transition android.transition.Transition} or 1939ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * {@link androidx.transition.Transition androidx.transition.Transition}. 19409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19412a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setExitTransition(@Nullable Object transition) { 1942990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mExitTransition = transition; 19439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19459f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19469f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views out of the scene when the 19479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * fragment is removed, hidden, or detached when not popping the back stack. 19489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * The exiting Views will be those that are regular Views or ViewGroups that 19499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 19509f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as exiting is governed by changing visibility 19519f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will 19529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * remain unaffected. 19539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views out of the Scene when the Fragment 19559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is being closed not due to popping the back stack. 19569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19572a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 19589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getExitTransition() { 1959990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 1960990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 1961990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 1962990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mExitTransition; 19639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views in to the scene when returning due 19679f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * to popping a back stack. The entering Views will be those that are regular Views 19689f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions 19699f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * will extend {@link android.transition.Visibility} as exiting is governed by changing 19709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, 19719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * the views will remain unaffected. If nothing is set, the default will be to use the same 19729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * transition as {@link #setExitTransition(Object)}. 19739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views into the scene when reentering from a 1975a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * previously-started Activity. <code>transition</code> 1976a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * must be an 1977a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * {@link android.transition.Transition android.transition.Transition} or 1978ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * {@link androidx.transition.Transition androidx.transition.Transition}. 19799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19802a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setReenterTransition(@Nullable Object transition) { 1981990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mReenterTransition = transition; 19829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views in to the scene when returning due 19869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * to popping a back stack. The entering Views will be those that are regular Views 19879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions 19889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * will extend {@link android.transition.Visibility} as exiting is governed by changing 19899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, 19909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * the views will remain unaffected. If nothing is set, the default will be to use the same 19919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * transition as {@link #setExitTransition(Object)}. 19929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views into the scene when reentering from a 19949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * previously-started Activity. 19959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getReenterTransition() { 1997990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 1998990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 1999990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2000990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mReenterTransition == USE_DEFAULT_TRANSITION ? getExitTransition() 2001990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount : mAnimationInfo.mReenterTransition; 20029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used for shared elements transferred into the content 20069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. Typical Transitions will affect size and location, such as 20079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 20089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 20099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use for shared elements transferred into the content 2011a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * Scene. <code>transition</code> must be an 2012a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * {@link android.transition.Transition android.transition.Transition} or 2013ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * {@link androidx.transition.Transition androidx.transition.Transition}. 20149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20152a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setSharedElementEnterTransition(@Nullable Object transition) { 2016990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mSharedElementEnterTransition = transition; 20179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used for shared elements transferred into the content 20219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. Typical Transitions will affect size and location, such as 20229f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 20239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 20249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return The Transition to use for shared elements transferred into the content 20269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. 20279f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20282a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 20299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getSharedElementEnterTransition() { 2030990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2031990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2032990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2033990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mSharedElementEnterTransition; 20349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20359f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20369f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used for shared elements transferred back during a 20389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * pop of the back stack. This Transition acts in the leaving Fragment. 20399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Typical Transitions will affect size and location, such as 20409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 20419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 20429f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * If no value is set, the default will be to use the same value as 20439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link #setSharedElementEnterTransition(Object)}. 20449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20459f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use for shared elements transferred out of the content 2046a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * Scene. <code>transition</code> must be an 2047a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * {@link android.transition.Transition android.transition.Transition} or 2048ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * {@link androidx.transition.Transition androidx.transition.Transition}. 20499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20502a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setSharedElementReturnTransition(@Nullable Object transition) { 2051990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mSharedElementReturnTransition = transition; 20529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Return the Transition that will be used for shared elements transferred back during a 20569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * pop of the back stack. This Transition acts in the leaving Fragment. 20579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Typical Transitions will affect size and location, such as 20589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 20599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 20609f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * If no value is set, the default will be to use the same value as 20619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link #setSharedElementEnterTransition(Object)}. 20629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return The Transition to use for shared elements transferred out of the content 20649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. 20659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20662a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 20679f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getSharedElementReturnTransition() { 2068990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2069990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2070990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2071990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mSharedElementReturnTransition == USE_DEFAULT_TRANSITION 2072990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ? getSharedElementEnterTransition() 2073990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount : mAnimationInfo.mSharedElementReturnTransition; 20749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets whether the the exit transition and enter transition overlap or not. 20789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the enter transition will start as soon as possible. When false, the 20799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * enter transition will wait until the exit transition completes before starting. 20809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param allow true to start the enter transition when possible or false to 20829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * wait until the exiting transition completes. 20839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setAllowEnterTransitionOverlap(boolean allow) { 2085990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mAllowEnterTransitionOverlap = allow; 20869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns whether the the exit transition and enter transition overlap or not. 20909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the enter transition will start as soon as possible. When false, the 20919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * enter transition will wait until the exit transition completes before starting. 20929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return true when the enter transition should start as soon as possible or false to 20949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when it should wait until the exiting transition completes. 20959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public boolean getAllowEnterTransitionOverlap() { 2097990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return (mAnimationInfo == null || mAnimationInfo.mAllowEnterTransitionOverlap == null) 2098990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ? true : mAnimationInfo.mAllowEnterTransitionOverlap; 20999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 21009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 21019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 21029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets whether the the return transition and reenter transition overlap or not. 21039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the reenter transition will start as soon as possible. When false, the 21049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * reenter transition will wait until the return transition completes before starting. 21059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 21069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param allow true to start the reenter transition when possible or false to wait until the 21079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * return transition completes. 21089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 21099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setAllowReturnTransitionOverlap(boolean allow) { 2110990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mAllowReturnTransitionOverlap = allow; 21119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 21129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 21139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 21149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns whether the the return transition and reenter transition overlap or not. 21159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the reenter transition will start as soon as possible. When false, the 21169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * reenter transition will wait until the return transition completes before starting. 21179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 21189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return true to start the reenter transition when possible or false to wait until the 21199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * return transition completes. 21209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 21219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public boolean getAllowReturnTransitionOverlap() { 2122990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return (mAnimationInfo == null || mAnimationInfo.mAllowReturnTransitionOverlap == null) 2123990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ? true : mAnimationInfo.mAllowReturnTransitionOverlap; 2124990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2125990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2126990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2127990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Postpone the entering Fragment transition until {@link #startPostponedEnterTransition()} 2128990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * or {@link FragmentManager#executePendingTransactions()} has been called. 2129990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * <p> 2130990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * This method gives the Fragment the ability to delay Fragment animations 2131990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * until all data is loaded. Until then, the added, shown, and 2132990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * attached Fragments will be INVISIBLE and removed, hidden, and detached Fragments won't 2133990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * be have their Views removed. The transaction runs when all postponed added Fragments in the 2134990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * transaction have called {@link #startPostponedEnterTransition()}. 2135990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * <p> 2136990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * This method should be called before being added to the FragmentTransaction or 2137990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * in {@link #onCreate(Bundle), {@link #onAttach(Context)}, or 2138990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}}. 2139990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * {@link #startPostponedEnterTransition()} must be called to allow the Fragment to 2140990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * start the transitions. 2141990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * <p> 2142990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * When a FragmentTransaction is started that may affect a postponed FragmentTransaction, 2143990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * based on which containers are in their operations, the postponed FragmentTransaction 2144990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * will have its start triggered. The early triggering may result in faulty or nonexistent 2145990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * animations in the postponed transaction. FragmentTransactions that operate only on 2146990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * independent containers will not interfere with each other's postponement. 2147990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * <p> 2148990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Calling postponeEnterTransition on Fragments with a null View will not postpone the 2149fda5be2466024a656152015c45a7681361d399bbGeorge Mount * transition. Likewise, postponement only works if 2150fda5be2466024a656152015c45a7681361d399bbGeorge Mount * {@link FragmentTransaction#setReorderingAllowed(boolean) FragmentTransaction reordering} is 2151990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * enabled. 2152990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * 2153990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * @see Activity#postponeEnterTransition() 2154fda5be2466024a656152015c45a7681361d399bbGeorge Mount * @see FragmentTransaction#setReorderingAllowed(boolean) 2155990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2156990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount public void postponeEnterTransition() { 2157990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mEnterTransitionPostponed = true; 2158990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2159990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2160990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2161990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Begin postponed transitions after {@link #postponeEnterTransition()} was called. 2162990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * If postponeEnterTransition() was called, you must call startPostponedEnterTransition() 2163990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * or {@link FragmentManager#executePendingTransactions()} to complete the FragmentTransaction. 2164990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * If postponement was interrupted with {@link FragmentManager#executePendingTransactions()}, 2165990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * before {@code startPostponedEnterTransition()}, animations may not run or may execute 2166990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * improperly. 2167990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * 2168990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * @see Activity#startPostponedEnterTransition() 2169990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2170990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount public void startPostponedEnterTransition() { 2171990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mFragmentManager == null || mFragmentManager.mHost == null) { 2172990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mEnterTransitionPostponed = false; 2173990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } else if (Looper.myLooper() != mFragmentManager.mHost.getHandler().getLooper()) { 2174990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mFragmentManager.mHost.getHandler().postAtFrontOfQueue(new Runnable() { 2175990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount @Override 2176990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount public void run() { 2177990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount callStartTransitionListener(); 2178990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2179990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount }); 2180990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } else { 2181990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount callStartTransitionListener(); 2182990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2183990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2184990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2185990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2186990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Calls the start transition listener. This must be called on the UI thread. 2187990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2188990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private void callStartTransitionListener() { 2189990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount final OnStartEnterTransitionListener listener; 2190990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2191990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount listener = null; 2192990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } else { 2193990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mEnterTransitionPostponed = false; 2194990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount listener = mAnimationInfo.mStartEnterTransitionListener; 2195990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mStartEnterTransitionListener = null; 2196990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2197990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (listener != null) { 2198990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount listener.onStartEnterTransition(); 2199990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 22009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 22019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 22029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 2203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Print the Fragments's state into the given stream. 2204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 2205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param prefix Text to print at the front of each line. 2206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fd The raw file descriptor that the dump is being sent to. 2207cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param writer The PrintWriter to which you should dump your state. This will be 2208cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * closed for you after you return. 2209cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param args additional arguments to the dump request. 2210cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 2211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { 2212cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mFragmentId=#"); 2213cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(Integer.toHexString(mFragmentId)); 22145506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn writer.print(" mContainerId=#"); 2215cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(Integer.toHexString(mContainerId)); 2216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mTag="); writer.println(mTag); 2217cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mState="); writer.print(mState); 2218cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mIndex="); writer.print(mIndex); 2219cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mWho="); writer.print(mWho); 2220cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mBackStackNesting="); writer.println(mBackStackNesting); 2221cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mAdded="); writer.print(mAdded); 2222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mRemoving="); writer.print(mRemoving); 2223cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mFromLayout="); writer.print(mFromLayout); 2224cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mInLayout="); writer.println(mInLayout); 2225cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mHidden="); writer.print(mHidden); 2226e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn writer.print(" mDetached="); writer.print(mDetached); 22272a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn writer.print(" mMenuVisible="); writer.print(mMenuVisible); 2228cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mHasMenu="); writer.println(mHasMenu); 22292a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn writer.print(prefix); writer.print("mRetainInstance="); writer.print(mRetainInstance); 223079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell writer.print(" mRetaining="); writer.print(mRetaining); 223179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell writer.print(" mUserVisibleHint="); writer.println(mUserVisibleHint); 2232cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mFragmentManager != null) { 2233cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mFragmentManager="); 2234cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mFragmentManager); 2235cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2236d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost != null) { 2237d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy writer.print(prefix); writer.print("mHost="); 2238d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy writer.println(mHost); 2239cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 22400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mParentFragment != null) { 22410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.print(prefix); writer.print("mParentFragment="); 22420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.println(mParentFragment); 22430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mArguments != null) { 2245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mArguments="); writer.println(mArguments); 2246cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedFragmentState != null) { 2248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mSavedFragmentState="); 2249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mSavedFragmentState); 2250cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedViewState != null) { 2252cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mSavedViewState="); 2253cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mSavedViewState); 2254cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2255cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mTarget != null) { 2256cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mTarget="); writer.print(mTarget); 2257cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mTargetRequestCode="); 2258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mTargetRequestCode); 2259cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2260990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (getNextAnim() != 0) { 2261990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print(prefix); writer.print("mNextAnim="); writer.println(getNextAnim()); 2262cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2263cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mContainer != null) { 2264cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mContainer="); writer.println(mContainer); 2265cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2266cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mView != null) { 2267cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mView="); writer.println(mView); 2268cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2269cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mInnerView != null) { 2270cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mInnerView="); writer.println(mView); 2271cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2272990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (getAnimatingAway() != null) { 2273990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print(prefix); 2274990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print("mAnimatingAway="); 2275990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.println(getAnimatingAway()); 2276990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print(prefix); 2277990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print("mStateAfterAnimating="); 2278990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.println(getStateAfterAnimating()); 2279cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2280afe28d91550483f9b7a82076a507151b4defd9baIan Lake LoaderManager.getInstance(this).dump(prefix, fd, writer, args); 22810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 22820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.print(prefix); writer.println("Child " + mChildFragmentManager + ":"); 22830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dump(prefix + " ", fd, writer, args); 22840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 22850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 22860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 22870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Fragment findFragmentByWho(String who) { 22880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (who.equals(mWho)) { 22890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return this; 22900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 22910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 22920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mChildFragmentManager.findFragmentByWho(who); 22930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 22940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return null; 22950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 22960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 22970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void instantiateChildFragmentManager() { 22981c7e1f738e202226b365c81715b221d2e864fdd5George Mount if (mHost == null) { 22991c7e1f738e202226b365c81715b221d2e864fdd5George Mount throw new IllegalStateException("Fragment has not been attached yet."); 23001c7e1f738e202226b365c81715b221d2e864fdd5George Mount } 2301e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes mChildFragmentManager = new FragmentManagerImpl(); 2302d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mChildFragmentManager.attachController(mHost, new FragmentContainer() { 23030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn @Override 23040fb3ec354da6c1f3ed1777bca5270710cc537e92Scott Kennedy @Nullable 23058491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy public View onFindViewById(int id) { 23060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mView == null) { 23070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new IllegalStateException("Fragment does not have a view"); 23080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mView.findViewById(id); 23100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23117516316ffdf6fbf7b248c615404831191daa66a4George Mount 23127516316ffdf6fbf7b248c615404831191daa66a4George Mount @Override 23138491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy public boolean onHasView() { 23147516316ffdf6fbf7b248c615404831191daa66a4George Mount return (mView != null); 23157516316ffdf6fbf7b248c615404831191daa66a4George Mount } 23164aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell 23174aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell @Override 23184aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell public Fragment instantiate(Context context, String className, Bundle arguments) { 23194aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell return mHost.instantiate(context, className, arguments); 23204aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell } 23210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn }, this); 23220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 23240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performCreate(Bundle savedInstanceState) { 23250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 23270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 232820735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = CREATED; 23290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 23300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onCreate(savedInstanceState); 2331e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount mIsCreated = true; 23320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 23330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 23340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onCreate()"); 23350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2336c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE); 23370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 2339b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton View performCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, 2340b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton @Nullable Bundle savedInstanceState) { 23410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 23430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 234437149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell mPerformedCreateView = true; 23450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return onCreateView(inflater, container, savedInstanceState); 23460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 23480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performActivityCreated(Bundle savedInstanceState) { 23490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 23510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 235220735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = ACTIVITY_CREATED; 23530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 23540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onActivityCreated(savedInstanceState); 23550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 23560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 23570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onActivityCreated()"); 23580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchActivityCreated(); 23610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2362cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2363cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 23649c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void performStart() { 23650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 23670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 23680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 236920735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = STARTED; 23700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 23719c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn onStart(); 23720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 23730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 23740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onStart()"); 23750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStart(); 23780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2379c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START); 23809c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 23819c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 23820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performResume() { 23830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 23850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 23860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 238720735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = RESUMED; 23880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 23890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onResume(); 23900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 23910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 23920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onResume()"); 23930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchResume(); 23960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 23970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2398c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME); 23990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24010765353c002bfdf681c982565810aa4be3499dd0George Mount void noteStateNotSaved() { 24020765353c002bfdf681c982565810aa4be3499dd0George Mount if (mChildFragmentManager != null) { 24030765353c002bfdf681c982565810aa4be3499dd0George Mount mChildFragmentManager.noteStateNotSaved(); 24040765353c002bfdf681c982565810aa4be3499dd0George Mount } 24050765353c002bfdf681c982565810aa4be3499dd0George Mount } 24060765353c002bfdf681c982565810aa4be3499dd0George Mount 24075fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian void performMultiWindowModeChanged(boolean isInMultiWindowMode) { 24085fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian onMultiWindowModeChanged(isInMultiWindowMode); 24095fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian if (mChildFragmentManager != null) { 24105fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian mChildFragmentManager.dispatchMultiWindowModeChanged(isInMultiWindowMode); 24115fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 24125fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 24135fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 24145fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian void performPictureInPictureModeChanged(boolean isInPictureInPictureMode) { 24155fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian onPictureInPictureModeChanged(isInPictureInPictureMode); 24165fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian if (mChildFragmentManager != null) { 24175fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian mChildFragmentManager.dispatchPictureInPictureModeChanged(isInPictureInPictureMode); 24185fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 24195fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 24205fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 24210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performConfigurationChanged(Configuration newConfig) { 24220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onConfigurationChanged(newConfig); 24230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchConfigurationChanged(newConfig); 24250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performLowMemory() { 24290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onLowMemory(); 24300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchLowMemory(); 24320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /* 24360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performTrimMemory(int level) { 24370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onTrimMemory(level); 24380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchTrimMemory(level); 24400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 24430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performCreateOptionsMenu(Menu menu, MenuInflater inflater) { 24450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean show = false; 24460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 24470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 24480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show = true; 24490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onCreateOptionsMenu(menu, inflater); 24500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show |= mChildFragmentManager.dispatchCreateOptionsMenu(menu, inflater); 24530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return show; 24560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performPrepareOptionsMenu(Menu menu) { 24590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean show = false; 24600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 24610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 24620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show = true; 24630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onPrepareOptionsMenu(menu); 24640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show |= mChildFragmentManager.dispatchPrepareOptionsMenu(menu); 24670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return show; 24700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performOptionsItemSelected(MenuItem item) { 24730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 24740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 24750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (onOptionsItemSelected(item)) { 24760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 24770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager.dispatchOptionsItemSelected(item)) { 24810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 24820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return false; 24860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performContextItemSelected(MenuItem item) { 24890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 24900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (onContextItemSelected(item)) { 24910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 24920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager.dispatchContextItemSelected(item)) { 24950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 24960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return false; 25000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 25020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performOptionsMenuClosed(Menu menu) { 25030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 25040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 25050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onOptionsMenuClosed(menu); 25060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchOptionsMenuClosed(menu); 25090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 25130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performSaveInstanceState(Bundle outState) { 25140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onSaveInstanceState(outState); 25150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Parcelable p = mChildFragmentManager.saveAllState(); 25170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (p != null) { 25180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn outState.putParcelable(FragmentActivity.FRAGMENTS_TAG, p); 25190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 25230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performPause() { 2524c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE); 25250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchPause(); 25270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 252820735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = STARTED; 25290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 25300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onPause(); 25310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 25320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 25330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onPause()"); 25340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 2537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn void performStop() { 2538c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP); 25390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStop(); 25410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 254220735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = STOPPED; 25430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 2544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn onStop(); 25450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 25460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 25470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onStop()"); 25480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2549681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn } 2550681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn 2551218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn void performReallyStop() { 25520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchReallyStop(); 25540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 255520735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = ACTIVITY_CREATED; 2556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 25579c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 25589c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void performDestroyView() { 25590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchDestroyView(); 25610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 256220735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = CREATED; 25630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 25649c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn onDestroyView(); 25650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 25660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 25670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onDestroyView()"); 25680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2569afe28d91550483f9b7a82076a507151b4defd9baIan Lake // Handles the detach/reattach case where the view hierarchy 2570afe28d91550483f9b7a82076a507151b4defd9baIan Lake // is destroyed and recreated and an additional call to 2571afe28d91550483f9b7a82076a507151b4defd9baIan Lake // onLoadFinished may be needed to ensure the new view 2572afe28d91550483f9b7a82076a507151b4defd9baIan Lake // hierarchy is populated from data from the Loaders 2573afe28d91550483f9b7a82076a507151b4defd9baIan Lake LoaderManager.getInstance(this).markForRedelivery(); 257437149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell mPerformedCreateView = false; 25759c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 25760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 25770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performDestroy() { 2578c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY); 25790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchDestroy(); 25810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 258220735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = INITIALIZING; 25830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 2584e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount mIsCreated = false; 25850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onDestroy(); 25860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 25870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 25880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onDestroy()"); 25890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25904706c089880423ee5929d4635c6dfc5c3151b20fGeorge Mount mChildFragmentManager = null; 25910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25929375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell 2593916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell void performDetach() { 2594916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell mCalled = false; 2595916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell onDetach(); 25968b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount mLayoutInflater = null; 2597916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell if (!mCalled) { 2598916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell throw new SuperNotCalledException("Fragment " + this 2599916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell + " did not call through to super.onDetach()"); 2600916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell } 2601916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell 2602916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell // Destroy the child FragmentManager if we still have it here. 2603916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell // We won't unless we're retaining our instance and if we do, 2604916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell // our child FragmentManager instance state will have already been saved. 2605916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell if (mChildFragmentManager != null) { 2606916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell if (!mRetaining) { 2607916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell throw new IllegalStateException("Child FragmentManager of " + this + " was not " 2608916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell + " destroyed and this fragment is not retaining instance"); 2609916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell } 2610916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell mChildFragmentManager.dispatchDestroy(); 2611916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell mChildFragmentManager = null; 2612916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell } 2613916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell } 2614916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell 2615990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setOnStartEnterTransitionListener(OnStartEnterTransitionListener listener) { 2616990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo(); 2617990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (listener == mAnimationInfo.mStartEnterTransitionListener) { 2618990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return; 2619990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2620990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (listener != null && mAnimationInfo.mStartEnterTransitionListener != null) { 2621990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount throw new IllegalStateException("Trying to set a replacement " 2622990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount + "startPostponedEnterTransition on " + this); 2623990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2624990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo.mEnterTransitionPostponed) { 2625990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mStartEnterTransitionListener = listener; 2626990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2627990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (listener != null) { 2628990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount listener.startListening(); 2629990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2630990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2631990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2632990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private AnimationInfo ensureAnimationInfo() { 2633990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2634990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo = new AnimationInfo(); 2635990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2636990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo; 2637990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2638990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2639990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int getNextAnim() { 2640990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2641990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return 0; 2642990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2643990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mNextAnim; 2644990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2645990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2646990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setNextAnim(int animResourceId) { 2647990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null && animResourceId == 0) { 2648990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return; // no change! 2649990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2650990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mNextAnim = animResourceId; 2651990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2652990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2653990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int getNextTransition() { 2654990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2655990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return 0; 2656990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2657990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mNextTransition; 2658990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2659990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2660990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setNextTransition(int nextTransition, int nextTransitionStyle) { 2661990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null && nextTransition == 0 && nextTransitionStyle == 0) { 2662990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return; // no change! 2663990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2664990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo(); 2665990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mNextTransition = nextTransition; 2666990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mNextTransitionStyle = nextTransitionStyle; 2667990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2668990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2669990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int getNextTransitionStyle() { 2670990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2671990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return 0; 2672990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2673990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mNextTransitionStyle; 2674990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2675990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2676990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount SharedElementCallback getEnterTransitionCallback() { 2677990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2678990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2679990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2680990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mEnterTransitionCallback; 2681990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2682990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2683990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount SharedElementCallback getExitTransitionCallback() { 2684990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2685990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2686990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2687990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mExitTransitionCallback; 2688990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2689990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2690990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount View getAnimatingAway() { 2691990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2692990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2693990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2694990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mAnimatingAway; 2695990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2696990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2697990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setAnimatingAway(View view) { 2698990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mAnimatingAway = view; 2699990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2700990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 270115e593ea3575512d7072240d1db9d74fad8749a3George Mount void setAnimator(Animator animator) { 270215e593ea3575512d7072240d1db9d74fad8749a3George Mount ensureAnimationInfo().mAnimator = animator; 270315e593ea3575512d7072240d1db9d74fad8749a3George Mount } 270415e593ea3575512d7072240d1db9d74fad8749a3George Mount 270515e593ea3575512d7072240d1db9d74fad8749a3George Mount Animator getAnimator() { 270615e593ea3575512d7072240d1db9d74fad8749a3George Mount if (mAnimationInfo == null) { 270715e593ea3575512d7072240d1db9d74fad8749a3George Mount return null; 270815e593ea3575512d7072240d1db9d74fad8749a3George Mount } 270915e593ea3575512d7072240d1db9d74fad8749a3George Mount return mAnimationInfo.mAnimator; 271015e593ea3575512d7072240d1db9d74fad8749a3George Mount } 271115e593ea3575512d7072240d1db9d74fad8749a3George Mount 2712990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int getStateAfterAnimating() { 2713990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2714990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return 0; 2715990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2716990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mStateAfterAnimating; 2717990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2718990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2719990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setStateAfterAnimating(int state) { 2720990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mStateAfterAnimating = state; 2721990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2722990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2723990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount boolean isPostponed() { 2724990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2725990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return false; 2726990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2727990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mEnterTransitionPostponed; 2728990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2729990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2730667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount boolean isHideReplaced() { 2731667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount if (mAnimationInfo == null) { 2732667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount return false; 2733667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount } 2734667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount return mAnimationInfo.mIsHideReplaced; 2735667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount } 2736667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount 2737667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount void setHideReplaced(boolean replaced) { 2738667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount ensureAnimationInfo().mIsHideReplaced = replaced; 2739667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount } 2740667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount 2741990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2742990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Used internally to be notified when {@link #startPostponedEnterTransition()} has 2743990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * been called. This listener will only be called once and then be removed from the 2744990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * listeners. 2745990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2746990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount interface OnStartEnterTransitionListener { 2747990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void onStartEnterTransition(); 2748990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void startListening(); 2749990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2750990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2751990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2752990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Contains all the animation and transition information for a fragment. This will only 2753990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * be instantiated for Fragments that have Views. 2754990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2755990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount static class AnimationInfo { 2756990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // Non-null if the fragment's view hierarchy is currently animating away, 2757990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // meaning we need to wait a bit on completely destroying it. This is the 2758990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // view that is animating. 2759990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount View mAnimatingAway; 2760990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 276115e593ea3575512d7072240d1db9d74fad8749a3George Mount // Non-null if the fragment's view hierarchy is currently animating away with an 276215e593ea3575512d7072240d1db9d74fad8749a3George Mount // animator instead of an animation. 276315e593ea3575512d7072240d1db9d74fad8749a3George Mount Animator mAnimator; 276415e593ea3575512d7072240d1db9d74fad8749a3George Mount 2765990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // If mAnimatingAway != null, this is the state we should move to once the 2766990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // animation is done. 2767990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int mStateAfterAnimating; 2768990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2769990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // If app has requested a specific animation, this is the one to use. 2770990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int mNextAnim; 2771990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2772990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // If app has requested a specific transition, this is the one to use. 2773990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int mNextTransition; 2774990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2775990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // If app has requested a specific transition style, this is the one to use. 2776990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int mNextTransitionStyle; 2777990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2778990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mEnterTransition = null; 2779990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mReturnTransition = USE_DEFAULT_TRANSITION; 2780990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mExitTransition = null; 2781990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mReenterTransition = USE_DEFAULT_TRANSITION; 2782990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mSharedElementEnterTransition = null; 2783990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mSharedElementReturnTransition = USE_DEFAULT_TRANSITION; 2784990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Boolean mAllowReturnTransitionOverlap; 2785990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Boolean mAllowEnterTransitionOverlap; 2786990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2787990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount SharedElementCallback mEnterTransitionCallback = null; 2788990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount SharedElementCallback mExitTransitionCallback = null; 2789990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2790990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // True when postponeEnterTransition has been called and startPostponeEnterTransition 2791990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // hasn't been called yet. 2792990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount boolean mEnterTransitionPostponed; 2793990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2794990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // Listener to wait for startPostponeEnterTransition. After being called, it will 2795990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // be set to null 2796990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount OnStartEnterTransitionListener mStartEnterTransitionListener; 2797990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2798667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount // True if the View was hidden, but the transition is handling the hide 2799667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount boolean mIsHideReplaced; 2800990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2801cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn} 2802