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; 48eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lakeimport androidx.annotation.MainThread; 49320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.annotation.NonNull; 50320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.annotation.Nullable; 51320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.annotation.RestrictTo; 52320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.annotation.StringRes; 53320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.collection.SimpleArrayMap; 54320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.core.app.SharedElementCallback; 55320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.core.util.DebugUtils; 56320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.core.view.LayoutInflaterCompat; 57ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.lifecycle.Lifecycle; 58ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.lifecycle.LifecycleOwner; 59ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.lifecycle.LifecycleRegistry; 60eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lakeimport androidx.lifecycle.LiveData; 61eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lakeimport androidx.lifecycle.MutableLiveData; 62ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.lifecycle.ViewModelStore; 63ba069d50913c3fb250bb60ec310439db36895337Alan Viveretteimport androidx.lifecycle.ViewModelStoreOwner; 64320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikasimport androidx.loader.app.LoaderManager; 65320113721c2e14bbc2403809046fa2959a665c11Aurimas Liutikas 66cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.FileDescriptor; 67cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.PrintWriter; 68b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikasimport java.lang.reflect.InvocationTargetException; 69cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 70cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/** 71cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Static library support version of the framework's {@link android.app.Fragment}. 72cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Used to write apps that run on platforms prior to Android 3.0. When running 73cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on Android 3.0 or above, this implementation is still used; it does not try 749dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * to switch to the framework's implementation. See the framework {@link android.app.Fragment} 75cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * documentation for a class overview. 769dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * 779dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <p>The main differences when using this support version instead of the framework version are: 789dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <ul> 799dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <li>Your activity must extend {@link FragmentActivity} 809dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <li>You must call {@link FragmentActivity#getSupportFragmentManager} to get the 819dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * {@link FragmentManager} 829dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * </ul> 839dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * 84cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 8541516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lakepublic class Fragment implements ComponentCallbacks, OnCreateContextMenuListener, LifecycleOwner, 8641516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake ViewModelStoreOwner { 872290993eddf5262a8df7fc9478daed52401e325aDianne Hackborn private static final SimpleArrayMap<String, Class<?>> sClassMap = 882290993eddf5262a8df7fc9478daed52401e325aDianne Hackborn new SimpleArrayMap<String, Class<?>>(); 899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount static final Object USE_DEFAULT_TRANSITION = new Object(); 919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 92cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int INITIALIZING = 0; // Not yet created. 93cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int CREATED = 1; // Created. 9417d9d287fd6d180c6c48d62305ae4d7265056410Ian Lake static final int ACTIVITY_CREATED = 2; // Fully created, not started. 9517d9d287fd6d180c6c48d62305ae4d7265056410Ian Lake static final int STARTED = 3; // Created and started, not resumed. 9617d9d287fd6d180c6c48d62305ae4d7265056410Ian Lake static final int RESUMED = 4; // Created started and resumed. 974bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 98cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mState = INITIALIZING; 994bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 100cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // When instantiated from saved state, this is the saved state. 101cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Bundle mSavedFragmentState; 102cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn SparseArray<Parcelable> mSavedViewState; 103e8ffa7a5775d29c6144ce0276cd4853baed5c1fbIan Lake // If the userVisibleHint is changed before the state is set, 104e8ffa7a5775d29c6144ce0276cd4853baed5c1fbIan Lake // it is stored here 105e8ffa7a5775d29c6144ce0276cd4853baed5c1fbIan Lake @Nullable Boolean mSavedUserVisibleHint; 1064bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 107cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Index into active fragment array. 108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mIndex = -1; 1094bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 110cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Internal unique name for this fragment; 111cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn String mWho; 1124bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Construction arguments; 114cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Bundle mArguments; 115cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 116cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Target fragment. 117cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment mTarget; 118cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1192c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn // For use when retaining a fragment: this is the index of the last mTarget. 1202c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn int mTargetIndex = -1; 1212c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn 122cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Target request code. 123cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mTargetRequestCode; 124cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 125cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // True if the fragment is in the list of added fragments. 126cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mAdded; 1274bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 128cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment is being removed from its activity. 129cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRemoving; 1304bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 131cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true if this fragment was instantiated from a layout file. 132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mFromLayout; 1334bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 134cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true when the view has actually been inflated in its layout. 135cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mInLayout; 136cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 137cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // True if this fragment has been restored from previously saved state. 138cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRestored; 139d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 14037149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell // True if performCreateView has been called and a matching call to performDestroyView 14137149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell // has not yet happened. 14237149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell boolean mPerformedCreateView; 14337149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell 144cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Number of active back stack entries this fragment is in. 145cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mBackStackNesting; 146d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The fragment manager we are associated with. Set as soon as the 148cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // fragment is used in a transaction; cleared after it has been removed 149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // from all transactions. 150abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell FragmentManagerImpl mFragmentManager; 151cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 152d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy // Host this fragment is attached to. 1538491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy FragmentHostCallback mHost; 1540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn // Private fragment manager for child fragments inside of this one. 1560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn FragmentManagerImpl mChildFragmentManager; 1570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 158c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell // For use when restoring fragment state and descendant fragments are retained. 159c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell // This state is set by FragmentState.instantiate and cleared in onCreate. 160c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell FragmentManagerNonConfig mChildNonConfig; 161c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell 16241516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake // ViewModelStore for storing ViewModels associated with this Fragment 16341516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake ViewModelStore mViewModelStore; 16441516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake 1650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn // If this Fragment is contained in another Fragment, this is that container. 1660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Fragment mParentFragment; 1670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 168cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The optional identifier for this fragment -- either the container ID if it 169cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // was dynamically added to the view hierarchy, or the ID supplied in 170cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // layout. 171cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mFragmentId; 1724bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // When a fragment is being dynamically added to the view hierarchy, this 174cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // is the identifier of the parent container it is being added to. 175cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mContainerId; 1764bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 177cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The optional named tag for this fragment -- usually used to find 178cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // fragments that are not part of the layout. 179cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn String mTag; 1804bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 181cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Set to true when the app has requested that this fragment be hidden 182cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // from the user. 183cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mHidden; 1844bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 185e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn // Set to true when the app has requested that this fragment be deactivated. 186e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn boolean mDetached; 187e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 188cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment would like its instance retained across 189cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // configuration changes. 190cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRetainInstance; 1912bdd09a243b422960168170e2344274cc9cfd788Todd Kennedy 192cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment is being retained across the current config change. 193cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mRetaining; 1944bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 195cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // If set this fragment has menu items to contribute. 196cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mHasMenu; 1972a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 1982a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn // Set to true to allow the fragment's menu to be shown. 1992a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn boolean mMenuVisible = true; 2002a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Used to verify that subclasses call through to super class. 202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mCalled; 2034bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The parent container of the fragment after dynamically added to UI. 205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn ViewGroup mContainer; 2064bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 207cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The View generated for this fragment. 208cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn View mView; 2094bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 210cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // The real inner view that will save/restore state. 211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn View mInnerView; 212abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 213abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell // Whether this fragment should defer starting until after other fragments 214abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell // have been started and their loaders are finished. 215abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell boolean mDeferStart; 2164bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 21779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell // Hint provided by the app that this fragment is currently visible to the user. 21879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell boolean mUserVisibleHint = true; 219abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 220990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // The animation and transition information for the fragment. This will be null 221990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // unless the elements are explicitly accessed and should remain null for Fragments 222990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // without Views. 223990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount AnimationInfo mAnimationInfo; 2249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 225990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // True if the View was added, and its animation has yet to be run. This could 226990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // also indicate that the fragment view hasn't been made visible, even if there is no 227990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // animation for this fragment. 228990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount boolean mIsNewlyAdded; 229990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 230990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // True if mHidden has been changed and the animation should be scheduled. 231990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount boolean mHiddenChanged; 2329f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 2330bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount // The alpha of the view when the view was added and then postponed. If the value is less 2340bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount // than zero, this means that the view's add was canceled and should not participate in 2350bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount // removal animations. 2360bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount float mPostponedAlpha; 2370bb3f19c91311de0b6619c7728a7bcc1f6863132George Mount 2388b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount // The cached value from onGetLayoutInflater(Bundle) that will be returned from 2398b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount // getLayoutInflater() 2408b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount LayoutInflater mLayoutInflater; 2418b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount 242e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount // Keep track of whether or not this Fragment has run performCreate(). Retained instance 243e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount // fragments can have mRetaining set to true without going through creation, so we must 244e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount // track it separately. 245e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount boolean mIsCreated; 246e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount 247c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets LifecycleRegistry mLifecycleRegistry = new LifecycleRegistry(this); 248c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets 249eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake // These are initialized in performCreateView and unavailable outside of the 250eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake // onCreateView/onDestroyView lifecycle 251eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake private LifecycleRegistry mViewLifecycleRegistry; 252eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake LifecycleOwner mViewLifecycleOwner; 253eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake MutableLiveData<LifecycleOwner> mViewLifecycleOwnerLiveData = new MutableLiveData<>(); 254eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake 255c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets @Override 256c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets public Lifecycle getLifecycle() { 257c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets return mLifecycleRegistry; 258c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets } 259c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets 260eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake /** 261eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * Get a {@link LifecycleOwner} that represents the {@link #getView() Fragment's View} 262eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * lifecycle. In most cases, this mirrors the lifecycle of the Fragment itself, but in cases 263eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * of {@link FragmentTransaction#detach(Fragment) detached} Fragments, the lifecycle of the 264eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * Fragment can be considerably longer than the lifecycle of the View itself. 265eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * <p> 266eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * Namely, the lifecycle of the Fragment's View is: 267eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * <ol> 268eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * <li>{@link Lifecycle.Event#ON_CREATE created} in {@link #onViewStateRestored(Bundle)}</li> 269eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * <li>{@link Lifecycle.Event#ON_START started} in {@link #onStart()}</li> 270eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * <li>{@link Lifecycle.Event#ON_RESUME resumed} in {@link #onResume()}</li> 271eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * <li>{@link Lifecycle.Event#ON_PAUSE paused} in {@link #onPause()}</li> 272eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * <li>{@link Lifecycle.Event#ON_STOP stopped} in {@link #onStop()}</li> 273eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * <li>{@link Lifecycle.Event#ON_DESTROY destroyed} in {@link #onDestroyView()}</li> 274eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * </ol> 275eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * 276eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * The first method where it is safe to access the view lifecycle is 277eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} under the condition that you must 278eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * return a non-null view (an IllegalStateException will be thrown if you access the view 279eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * lifecycle but don't return a non-null view). 280eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * <p>The view lifecycle remains valid through the call to {@link #onDestroyView()}, after which 281eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * {@link #getView()} will return null, the view lifecycle will be destroyed, and this method 282eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * will throw an IllegalStateException. Consider using 283eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * {@link #getViewLifecycleOwnerLiveData()} or {@link FragmentTransaction#runOnCommit(Runnable)} 284eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * to receive a callback for when the Fragment's view lifecycle is available. 285eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * <p> 286eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * This should only be called on the main thread. 287eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * 288eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * @return A {@link LifecycleOwner} that represents the {@link #getView() Fragment's View} 289eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * lifecycle. 290eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * @throws IllegalStateException if the {@link #getView() Fragment's View is null}. 291eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake */ 292eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake @MainThread 293eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake @NonNull 294eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake public LifecycleOwner getViewLifecycleOwner() { 295eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake if (mViewLifecycleOwner == null) { 296eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake throw new IllegalStateException("Can't access the Fragment View's LifecycleOwner when " 297eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake + "getView() is null i.e., before onCreateView() or after onDestroyView()"); 298eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake } 299eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake return mViewLifecycleOwner; 300eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake } 301eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake 302eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake /** 303eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * Retrieve a {@link LiveData} which allows you to observe the 304eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * {@link #getViewLifecycleOwner() lifecycle of the Fragment's View}. 305eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * <p> 306eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * This will be set to the new {@link LifecycleOwner} after {@link #onCreateView} returns a 307eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * non-null View and will set to null after {@link #onDestroyView()}. 308eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * 309eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake * @return A LiveData that changes in sync with {@link #getViewLifecycleOwner()}. 310eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake */ 311eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake @NonNull 312eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake public LiveData<LifecycleOwner> getViewLifecycleOwnerLiveData() { 313eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake return mViewLifecycleOwnerLiveData; 314eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake } 315eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake 31641516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake @NonNull 31741516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake @Override 31841516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake public ViewModelStore getViewModelStore() { 31941516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake if (getContext() == null) { 32041516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake throw new IllegalStateException("Can't access ViewModels from detached fragment"); 32141516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake } 32241516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake if (mViewModelStore == null) { 32341516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake mViewModelStore = new ViewModelStore(); 32441516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake } 32541516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake return mViewModelStore; 32641516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake } 32741516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake 328cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 3295c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * State information that has been retrieved from a fragment instance 3305c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * through {@link FragmentManager#saveFragmentInstanceState(Fragment) 3315c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * FragmentManager.saveFragmentInstanceState}. 3325c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 3335c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public static class SavedState implements Parcelable { 3345c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn final Bundle mState; 3355c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3365c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn SavedState(Bundle state) { 3375c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState = state; 3385c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3395c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3405c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn SavedState(Parcel in, ClassLoader loader) { 3415c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState = in.readBundle(); 3425c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn if (loader != null && mState != null) { 3435c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mState.setClassLoader(loader); 3445c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3455c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3465c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3475c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn @Override 3485c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public int describeContents() { 3495c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return 0; 3505c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3515c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3525c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn @Override 3535c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public void writeToParcel(Parcel dest, int flags) { 3545c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn dest.writeBundle(mState); 3555c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3565c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3575c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public static final Parcelable.Creator<SavedState> CREATOR 3585c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn = new Parcelable.Creator<SavedState>() { 359d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Override 3605c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public SavedState createFromParcel(Parcel in) { 3615c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return new SavedState(in, null); 3625c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3635c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 364d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Override 3655c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public SavedState[] newArray(int size) { 3665c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn return new SavedState[size]; 3675c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3685c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn }; 3695c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 3705c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 3715c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 372cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when 373cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * there is an instantiation failure. 374cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 375960e687174a4c2daca556d52bfd48e2fd8f4f317Jake Wharton @SuppressWarnings("JavaLangClash") 376960e687174a4c2daca556d52bfd48e2fd8f4f317Jake Wharton public static class InstantiationException extends RuntimeException { 377cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public InstantiationException(String msg, Exception cause) { 378cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn super(msg, cause); 379cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 380cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 381cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 382cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 383cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Default constructor. <strong>Every</strong> fragment must have an 384cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * empty constructor, so it can be instantiated when restoring its 385cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * activity's state. It is strongly recommended that subclasses do not 386cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * have other constructors with parameters, since these constructors 387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * will not be called when the fragment is re-instantiated; instead, 388cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * arguments can be supplied by the caller with {@link #setArguments} 389cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * and later retrieved by the Fragment with {@link #getArguments}. 3904bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 39104f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * <p>Applications should generally not implement a constructor. Prefer 39204f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * {@link #onAttach(Context)} instead. It is the first place application code can run where 39304f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * the fragment is ready to be used - the point where the fragment is actually associated with 39404f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * its context. Some applications may also want to implement {@link #onInflate} to retrieve 39504f7579a1350af17f700a392f986efd126ccc68bAurimas Liutikas * attributes from a layout resource, although note this happens when the fragment is attached. 396cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 397cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public Fragment() { 398cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 399cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 400cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 401cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Like {@link #instantiate(Context, String, Bundle)} but with a null 402cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * argument Bundle. 403cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 404cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public static Fragment instantiate(Context context, String fname) { 405cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return instantiate(context, fname, null); 406cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 407cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 408cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 409cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Create a new instance of a Fragment with the given class name. This is 410cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the same as calling its empty constructor. 411cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 412cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param context The calling context being used to instantiate the fragment. 413cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is currently just used to get its ClassLoader. 414cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fname The class name of the fragment to instantiate. 415cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param args Bundle of arguments to supply to the fragment, which it 416cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can retrieve with {@link #getArguments()}. May be null. 417cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return Returns a new fragment instance. 418cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @throws InstantiationException If there is a failure in instantiating 419cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the given fragment class. This is a runtime exception; it is not 420cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * normally expected to happen. 421cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 422c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy public static Fragment instantiate(Context context, String fname, @Nullable Bundle args) { 423cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn try { 424cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Class<?> clazz = sClassMap.get(fname); 425cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (clazz == null) { 426cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn // Class not found in the cache, see if it's real, and try to add it 427cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn clazz = context.getClassLoader().loadClass(fname); 428cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sClassMap.put(fname, clazz); 429cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 430b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas Fragment f = (Fragment) clazz.getConstructor().newInstance(); 431cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (args != null) { 432cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn args.setClassLoader(f.getClass().getClassLoader()); 43337149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell f.setArguments(args); 434cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 435cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return f; 436cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (ClassNotFoundException e) { 437cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 438cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 439cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 440cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (java.lang.InstantiationException e) { 441cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 444cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } catch (IllegalAccessException e) { 445cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 446cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + ": make sure class name exists, is public, and has an" 447cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " empty constructor that is public", e); 448b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas } catch (NoSuchMethodException e) { 449b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas throw new InstantiationException("Unable to instantiate fragment " + fname 450b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas + ": could not find Fragment constructor", e); 451b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas } catch (InvocationTargetException e) { 452b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas throw new InstantiationException("Unable to instantiate fragment " + fname 453b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas + ": calling Fragment constructor caused an exception", e); 454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4563fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell 4573fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell /** 4583fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * Determine if the given fragment name is a support library fragment class. 4593fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * 4603fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * @param context Context used to determine the correct ClassLoader to use 4613fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * @param fname Class name of the fragment to test 462ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * @return true if <code>fname</code> is <code>androidx.fragment.app.Fragment</code> 4633fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell * or a subclass, false otherwise. 4643fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell */ 4653fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell static boolean isSupportFragmentClass(Context context, String fname) { 4663fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell try { 4673fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell Class<?> clazz = sClassMap.get(fname); 4683fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell if (clazz == null) { 4693fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell // Class not found in the cache, see if it's real, and try to add it 4703fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell clazz = context.getClassLoader().loadClass(fname); 4713fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell sClassMap.put(fname, clazz); 4723fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 4733fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell return Fragment.class.isAssignableFrom(clazz); 4743fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } catch (ClassNotFoundException e) { 4753fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell return false; 4763fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 4773fafb0817f980d1819d0708b3c3da00454ba4c1fAdam Powell } 4784bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 4790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final void restoreViewState(Bundle savedInstanceState) { 480cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedViewState != null) { 481cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mInnerView.restoreHierarchyState(mSavedViewState); 482cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mSavedViewState = null; 483cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 4850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onViewStateRestored(savedInstanceState); 4860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 4870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 4880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onViewStateRestored()"); 4890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 490cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 4910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 4920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final void setIndex(int index, Fragment parent) { 493cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = index; 4940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (parent != null) { 4950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mWho = parent.mWho + ":" + mIndex; 4960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else { 4970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mWho = "android:fragment:" + mIndex; 4980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 499e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 5000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 501e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn final boolean isInBackStack() { 502e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn return mBackStackNesting > 0; 503e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 504e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 505cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 506cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Subclasses can not override equals(). 507cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 508cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override final public boolean equals(Object o) { 509cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return super.equals(o); 510cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 511cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 512cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 513cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Subclasses can not override hashCode(). 514cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 515cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override final public int hashCode() { 516cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return super.hashCode(); 517cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 5184bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 519cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn @Override 520cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public String toString() { 521cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn StringBuilder sb = new StringBuilder(128); 522cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn DebugUtils.buildShortClassTag(this, sb); 523cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mIndex >= 0) { 524cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" #"); 525cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(mIndex); 526cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 527cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mFragmentId != 0) { 528cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" id=0x"); 529cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(Integer.toHexString(mFragmentId)); 530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mTag != null) { 532cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(" "); 533cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append(mTag); 534cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn sb.append('}'); 536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return sb.toString(); 537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 5384bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 539cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 540cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the identifier this fragment is known by. This is either 541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the android:id value supplied in a layout or the container view ID 542cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * supplied when adding the fragment. 543cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public int getId() { 545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mFragmentId; 546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 5474bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Get the tag name of the fragment, if specified. 550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 5512a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public String getTag() { 553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTag; 554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 5554bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 5575e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * Supply the construction arguments for this fragment. 5585e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * The arguments supplied here will be retained across fragment destroy and 559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * creation. 5605e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * <p>This method cannot be called if the fragment is added to a FragmentManager and 5615e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * if {@link #isStateSaved()} would return true.</p> 562cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 5632a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setArguments(@Nullable Bundle args) { 5645e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell if (mIndex >= 0 && isStateSaved()) { 5655e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell throw new IllegalStateException("Fragment already active and state has been saved"); 566cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 567cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mArguments = args; 568cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 569cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 570cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 571cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the arguments supplied when the fragment was instantiated, 572cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if any. 573cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 5742a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 575cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public Bundle getArguments() { 576cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mArguments; 577cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 578cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 579cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 5805e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * Returns true if this fragment is added and its state has already been saved 5815e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * by its host. Any operations that would change saved state should not be performed 5825e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * if this method returns true, and some operations such as {@link #setArguments(Bundle)} 5835e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * will fail. 5845e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * 5855e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell * @return true if this fragment's state has already been saved by its host 5865e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell */ 5875e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell public final boolean isStateSaved() { 5885e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell if (mFragmentManager == null) { 5895e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell return false; 5905e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell } 5915e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell return mFragmentManager.isStateSaved(); 5925e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell } 5935e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell 5945e2b030b851bde2b4569104a01b4acf6960327a6Adam Powell /** 5955c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Set the initial saved state that this Fragment should restore itself 5965c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * from when first being constructed, as returned by 5975c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * {@link FragmentManager#saveFragmentInstanceState(Fragment) 5985c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * FragmentManager.saveFragmentInstanceState}. 5995c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * 6005c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param state The state the fragment should be restored from. 6015c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 6022a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setInitialSavedState(@Nullable SavedState state) { 6035c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn if (mIndex >= 0) { 6045c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn throw new IllegalStateException("Fragment already active"); 6055c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 6065c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn mSavedFragmentState = state != null && state.mState != null 6075c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn ? state.mState : null; 6085c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn } 6095c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 6105c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 611cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Optional target for this fragment. This may be used, for example, 612cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if this fragment is being started by another, and when done wants to 613cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * give a result back to the first. The target set here is retained 614cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * across instances via {@link FragmentManager#putFragment 615cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * FragmentManager.putFragment()}. 616cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 617cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fragment The fragment that is the target of this one. 618cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param requestCode Optional request code, for convenience if you 619cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * are going to call back with {@link #onActivityResult(int, int, Intent)}. 620cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 621b7a2c474fc66d5b7f2a57f2c212f8ac5a9e6de70Aurimas Liutikas @SuppressWarnings("ReferenceEquality") 6222a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setTargetFragment(@Nullable Fragment fragment, int requestCode) { 623a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // Don't allow a caller to set a target fragment in another FragmentManager, 624a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // but there's a snag: people do set target fragments before fragments get added. 625a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // We'll have the FragmentManager check that for validity when we move 626a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // the fragments to a valid state. 627a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell final FragmentManager mine = getFragmentManager(); 6282ab15df66963610bc02cb30e9a459f2b49c2ccfaAdam Powell final FragmentManager theirs = fragment != null ? fragment.getFragmentManager() : null; 629a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell if (mine != null && theirs != null && mine != theirs) { 630a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell throw new IllegalArgumentException("Fragment " + fragment 631a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell + " must share the same FragmentManager to be set as a target fragment"); 632a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell } 633a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell 634a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell // Don't let someone create a cycle. 635a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell for (Fragment check = fragment; check != null; check = check.getTargetFragment()) { 636a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell if (check == this) { 637a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell throw new IllegalArgumentException("Setting " + fragment + " as the target of " 638a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell + this + " would create a target cycle"); 639a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell } 640a4fd990846a60f3647445bf65980faad47b4cc68Adam Powell } 641cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTarget = fragment; 642cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTargetRequestCode = requestCode; 643cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 644cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 645cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 646cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the target fragment set by {@link #setTargetFragment}. 647cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 6482a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 649cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public Fragment getTargetFragment() { 650cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTarget; 651cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 652cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 653cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 654cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the target request code set by {@link #setTargetFragment}. 655cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 656cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public int getTargetRequestCode() { 657cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTargetRequestCode; 658cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 659cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 660cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 661d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Return the {@link Context} this fragment is currently associated with. 662c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 663c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #requireContext() 664d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy */ 665b38fded102ffe4de21f2d048262f52d5bcefbfd5Jake Wharton @Nullable 666edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy public Context getContext() { 667d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy return mHost == null ? null : mHost.getContext(); 668d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 669d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 670d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy /** 671c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * Return the {@link Context} this fragment is currently associated with. 672c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 673c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @throws IllegalStateException if not currently associated with a context. 674c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #getContext() 675c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton */ 676c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton @NonNull 677c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton public final Context requireContext() { 678c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton Context context = getContext(); 679c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton if (context == null) { 680c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton throw new IllegalStateException("Fragment " + this + " not attached to a context."); 681c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton } 682c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton return context; 683c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton } 684c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton 685c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton /** 686d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Return the {@link FragmentActivity} this fragment is currently associated with. 687d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * May return {@code null} if the fragment is associated with a {@link Context} 688d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * instead. 689c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 690c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #requireActivity() 691cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 692b38fded102ffe4de21f2d048262f52d5bcefbfd5Jake Wharton @Nullable 693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public FragmentActivity getActivity() { 694d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy return mHost == null ? null : (FragmentActivity) mHost.getActivity(); 695cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 696d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 697cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 698c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * Return the {@link FragmentActivity} this fragment is currently associated with. 699c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 700c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @throws IllegalStateException if not currently associated with an activity or if associated 701c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * only with a context. 702c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #getActivity() 703c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton */ 704c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton @NonNull 705c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton public final FragmentActivity requireActivity() { 706c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton FragmentActivity activity = getActivity(); 707c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton if (activity == null) { 708c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton throw new IllegalStateException("Fragment " + this + " not attached to an activity."); 709c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton } 710c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton return activity; 711c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton } 712c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton 713c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton /** 714edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy * Return the host object of this fragment. May return {@code null} if the fragment 715edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy * isn't currently being hosted. 716c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 717c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #requireHost() 718edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy */ 719b38fded102ffe4de21f2d048262f52d5bcefbfd5Jake Wharton @Nullable 720edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy final public Object getHost() { 7218491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy return mHost == null ? null : mHost.onGetHost(); 722edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy } 723edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy 724edaa101bfa72b5e5a5b14b9e6c66579eaed5e8ccTodd Kennedy /** 725c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * Return the host object of this fragment. 726c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 727c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @throws IllegalStateException if not currently associated with a host. 728c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #getHost() 729cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 7302a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @NonNull 731c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton public final Object requireHost() { 732c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton Object host = getHost(); 733c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton if (host == null) { 734c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton throw new IllegalStateException("Fragment " + this + " not attached to a host."); 735cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 736c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton return host; 737c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton } 738c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton 739c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton /** 740c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * Return <code>requireActivity().getResources()</code>. 741c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton */ 742c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton @NonNull 743c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton final public Resources getResources() { 744c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton return requireContext().getResources(); 745cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 746d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 747cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 748cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized, styled CharSequence from the application's package's 749cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table. 750cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 751cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the CharSequence text 752cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 7532a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @NonNull 754a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final CharSequence getText(@StringRes int resId) { 755cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getText(resId); 756cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 757cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 758cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 759cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized string from the application's package's 760cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table. 761cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 762cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the string 763cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 7642a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @NonNull 765a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final String getString(@StringRes int resId) { 766cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getString(resId); 767cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 768cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 769cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 770cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return a localized formatted string from the application's package's 771cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default string table, substituting the format arguments as defined in 772cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link java.util.Formatter} and {@link java.lang.String#format}. 773cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 774cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resId Resource id for the format string 775cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param formatArgs The format arguments that will be used for substitution. 776cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 7772a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @NonNull 778a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public final String getString(@StringRes int resId, Object... formatArgs) { 779cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return getResources().getString(resId, formatArgs); 780cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 781cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 782cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 783cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return the FragmentManager for interacting with fragments associated 784cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * with this fragment's activity. Note that this will be non-null slightly 785cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * before {@link #getActivity()}, during the time from when the fragment is 786cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * placed in a {@link FragmentTransaction} until it is committed and 787cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * attached to its activity. 7880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 7890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * <p>If this Fragment is a child of another Fragment, the FragmentManager 7900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * returned here will be the parent's {@link #getChildFragmentManager()}. 791c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 792c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #requireFragmentManager() 793cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 794b38fded102ffe4de21f2d048262f52d5bcefbfd5Jake Wharton @Nullable 795cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public FragmentManager getFragmentManager() { 796cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mFragmentManager; 797cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 798cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 799cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 800c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * Return the FragmentManager for interacting with fragments associated 801c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * with this fragment's activity. Note that this will available slightly 802c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * before {@link #getActivity()}, during the time from when the fragment is 803c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * placed in a {@link FragmentTransaction} until it is committed and 804c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * attached to its activity. 805c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 806c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * <p>If this Fragment is a child of another Fragment, the FragmentManager 807c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * returned here will be the parent's {@link #getChildFragmentManager()}. 808c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * 809c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @throws IllegalStateException if not associated with a transaction or host. 810c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton * @see #getFragmentManager() 811c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton */ 812c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton @NonNull 813c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton public final FragmentManager requireFragmentManager() { 814c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton FragmentManager fragmentManager = getFragmentManager(); 815c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton if (fragmentManager == null) { 816c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton throw new IllegalStateException( 817c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton "Fragment " + this + " not associated with a fragment manager."); 818c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton } 819c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton return fragmentManager; 820c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton } 821c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton 822c7dd6a0b8a02ed90a16d55afa0c83fa8b986dbabJake Wharton /** 8230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Return a private FragmentManager for placing and managing Fragments 8240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * inside of this Fragment. 8250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 8262a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @NonNull 8270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final public FragmentManager getChildFragmentManager() { 8280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager == null) { 8290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn instantiateChildFragmentManager(); 8300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mState >= RESUMED) { 8310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchResume(); 8320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= STARTED) { 8330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStart(); 8340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= ACTIVITY_CREATED) { 8350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchActivityCreated(); 8360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } else if (mState >= CREATED) { 8370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchCreate(); 8380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 8390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 8400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mChildFragmentManager; 8410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 8420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 8430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 844267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell * Return this fragment's child FragmentManager one has been previously created, 845267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell * otherwise null. 846267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell */ 8472a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 848267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell FragmentManager peekChildFragmentManager() { 849267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell return mChildFragmentManager; 850267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell } 851267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell 852267b02ebf455fa4d7de59150548676e406b2dd2bAdam Powell /** 8530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Returns the parent Fragment containing this Fragment. If this Fragment 8540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * is attached directly to an Activity, returns null. 8550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 8562a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 8570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn final public Fragment getParentFragment() { 8580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mParentFragment; 8590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 8600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 8610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 862cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is currently added to its activity. 863cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 864cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isAdded() { 865d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy return mHost != null && mAdded; 866cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 867cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 868cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 8699c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * Return true if the fragment has been explicitly detached from the UI. 8709c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * That is, {@link FragmentTransaction#detach(Fragment) 8719c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * FragmentTransaction.detach(Fragment)} has been used on it. 8729c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn */ 8739c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn final public boolean isDetached() { 8749c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn return mDetached; 8759c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 8769c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 8779c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn /** 878cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if this fragment is currently being removed from its 879cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * activity. This is <em>not</em> whether its activity is finishing, but 880cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * rather whether it is in the process of being removed from its activity. 881cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 882cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isRemoving() { 883cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mRemoving; 884cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 8854bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 886cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 887cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the layout is included as part of an activity view 888cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * hierarchy via the <fragment> tag. This will always be true when 889cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * fragments are created through the <fragment> tag, <em>except</em> 890cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * in the case where an old fragment is restored from a previous state and 891cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * it does not appear in the layout of the current state. 892cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 893cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isInLayout() { 894cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mInLayout; 895cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 896cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 897cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 898cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is in the resumed state. This is true 899cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for the duration of {@link #onResume()} and {@link #onPause()} as well. 900cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 901cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isResumed() { 90220735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell return mState >= RESUMED; 903cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9044bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 905cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 906cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment is currently visible to the user. This means 9074bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * it: (1) has been added, (2) has its view attached to the window, and 908cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * (3) is not hidden. 909cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 910cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isVisible() { 911cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return isAdded() && !isHidden() && mView != null 912cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE; 913cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9144bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 915cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 916cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Return true if the fragment has been hidden. By default fragments 917cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * are shown. You can find out about changes to this state with 918cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onHiddenChanged}. Note that the hidden state is orthogonal 919cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to other states -- that is, to be visible to the user, a fragment 920cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * must be both started and not hidden. 921cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 922cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean isHidden() { 923cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mHidden; 924cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9253a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 9263a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown /** @hide */ 9278e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas @RestrictTo(LIBRARY_GROUP) 9283a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown final public boolean hasOptionsMenu() { 9293a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown return mHasMenu; 9303a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown } 9313a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 9323a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown /** @hide */ 9338e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas @RestrictTo(LIBRARY_GROUP) 9343a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown final public boolean isMenuVisible() { 9353a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown return mMenuVisible; 9363a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown } 9373a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown 938cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 939cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the hidden state (as returned by {@link #isHidden()} of 940cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the fragment has changed. Fragments start out not hidden; this will 941cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * be called whenever the fragment changes state from that. 942527415d706bf580ff2bb7b492e5202b985cfa2c7Aurimas Liutikas * @param hidden True if the fragment is now hidden, false otherwise. 943cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 944cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onHiddenChanged(boolean hidden) { 945cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9464bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 947cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 948cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Control whether a fragment instance is retained across Activity 949cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * re-creation (such as from a configuration change). This can only 950cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * be used with fragments not in the back stack. If set, the fragment 951cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * lifecycle will be slightly different when an activity is recreated: 952cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <ul> 953cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still 954cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * will be, because the fragment is being detached from its current activity). 955cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onCreate(Bundle)} will not be called since the fragment 956cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is not being re-created. 957cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b> 958cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * still be called. 959cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * </ul> 960cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 961cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setRetainInstance(boolean retain) { 962cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mRetainInstance = retain; 963cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9644bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 965cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final public boolean getRetainInstance() { 966cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mRetainInstance; 967cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9684bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 969cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 970cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Report that this fragment would like to participate in populating 971cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the options menu by receiving a call to {@link #onCreateOptionsMenu} 972cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * and related methods. 973d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * 974cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param hasMenu If true, the fragment has menu items to contribute. 975cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 976cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void setHasOptionsMenu(boolean hasMenu) { 977cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mHasMenu != hasMenu) { 978cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mHasMenu = hasMenu; 979cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (isAdded() && !isHidden()) { 9808491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy mHost.onSupportInvalidateOptionsMenu(); 981cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 982cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 983cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 9842a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 9852a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn /** 9862a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * Set a hint for whether this fragment's menu should be visible. This 9872a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * is useful if you know that a fragment has been placed in your view 9882a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * hierarchy so that the user can not currently seen it, so any menu items 9892a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * it has should also not be shown. 9902a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * 9912a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * @param menuVisible The default is true, meaning the fragment's menu will 9922a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn * be shown as usual. If false, the user will not see the menu. 9932a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn */ 9942a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn public void setMenuVisibility(boolean menuVisible) { 9952a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn if (mMenuVisible != menuVisible) { 9962a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn mMenuVisible = menuVisible; 9972a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn if (mHasMenu && isAdded() && !isHidden()) { 9988491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy mHost.onSupportInvalidateOptionsMenu(); 9992a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 10002a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 10012a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn } 10022a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn 1003cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 100479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * Set a hint to the system about whether this fragment's UI is currently visible 100579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * to the user. This hint defaults to true and is persistent across fragment instance 100679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * state save and restore. 1007abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell * 100879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * <p>An app may set this to false to indicate that the fragment's UI is 100979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * scrolled out of visibility or is otherwise not directly visible to the user. 101079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * This may be used by the system to prioritize operations such as fragment lifecycle updates 101179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * or loader ordering behavior.</p> 1012abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell * 10130244762c99db7b1fb6c4905bc1224fefac927014Adam Powell * <p><strong>Note:</strong> This method may be called outside of the fragment lifecycle. 10140244762c99db7b1fb6c4905bc1224fefac927014Adam Powell * and thus has no ordering guarantees with regard to fragment lifecycle method calls.</p> 10150244762c99db7b1fb6c4905bc1224fefac927014Adam Powell * 101679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @param isVisibleToUser true if this fragment's UI is currently visible to the user (default), 101779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * false if it is not. 1018abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell */ 101979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell public void setUserVisibleHint(boolean isVisibleToUser) { 10203ab5a96f51cbd0498a62f1e91f1ef99e95cb1b1cAdam Powell if (!mUserVisibleHint && isVisibleToUser && mState < STARTED 1021261fa1b6dce85674f9a6fbe8a48851c80701b1dbIan Lake && mFragmentManager != null && isAdded() && mIsCreated) { 1022abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell mFragmentManager.performPendingDeferredStart(this); 1023abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 102479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell mUserVisibleHint = isVisibleToUser; 1025c83dccecb0ec4bf9f4befdb18caccb8f373ed7bcAdam Powell mDeferStart = mState < STARTED && !isVisibleToUser; 10260d29663c8688de94a3260584037c21dfd9e4cbfaIan Lake if (mSavedFragmentState != null) { 10270d29663c8688de94a3260584037c21dfd9e4cbfaIan Lake // Ensure that if the user visible hint is set before the Fragment has 10280d29663c8688de94a3260584037c21dfd9e4cbfaIan Lake // restored its state that we don't lose the new value 1029e8ffa7a5775d29c6144ce0276cd4853baed5c1fbIan Lake mSavedUserVisibleHint = isVisibleToUser; 10300d29663c8688de94a3260584037c21dfd9e4cbfaIan Lake } 1031abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 1032abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 1033abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell /** 103479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @return The current value of the user-visible hint on this fragment. 103579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell * @see #setUserVisibleHint(boolean) 1036abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell */ 103779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell public boolean getUserVisibleHint() { 103879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell return mUserVisibleHint; 1039abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell } 1040abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell 1041abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell /** 1042afe28d91550483f9b7a82076a507151b4defd9baIan Lake * Return the LoaderManager for this fragment. 1043c559bbd18f472db18dd7cbc9f4c520ffdebd97e8Ian Lake * 1044c559bbd18f472db18dd7cbc9f4c520ffdebd97e8Ian Lake * @deprecated Use 1045c559bbd18f472db18dd7cbc9f4c520ffdebd97e8Ian Lake * {@link LoaderManager#getInstance(LifecycleOwner) LoaderManager.getInstance(this)}. 1046cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1047c559bbd18f472db18dd7cbc9f4c520ffdebd97e8Ian Lake @Deprecated 1048cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public LoaderManager getLoaderManager() { 1049afe28d91550483f9b7a82076a507151b4defd9baIan Lake return LoaderManager.getInstance(this); 1050cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1051d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1052cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 10538491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy * Call {@link Activity#startActivity(Intent)} from the fragment's 1054cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * containing Activity. 1055cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1056cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void startActivity(Intent intent) { 10570e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick startActivity(intent, null); 10580e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick } 10590e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick 10600e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick /** 10610e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick * Call {@link Activity#startActivity(Intent, Bundle)} from the fragment's 10620e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick * containing Activity. 10630e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick */ 10640e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick public void startActivity(Intent intent, @Nullable Bundle options) { 1065d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost == null) { 1066cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 1067cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 10680e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick mHost.onStartActivityFromFragment(this /*fragment*/, intent, -1, options); 1069cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1070d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1071cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 10728491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy * Call {@link Activity#startActivityForResult(Intent, int)} from the fragment's 1073cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * containing Activity. 1074cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1075cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void startActivityForResult(Intent intent, int requestCode) { 10760e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick startActivityForResult(intent, requestCode, null); 10770e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick } 10780e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick 10790e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick /** 10800e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick * Call {@link Activity#startActivityForResult(Intent, int, Bundle)} from the fragment's 10810e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick * containing Activity. 10820e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick */ 10830e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick public void startActivityForResult(Intent intent, int requestCode, @Nullable Bundle options) { 1084d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost == null) { 1085cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 1086cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 10870e35b9f59703416786e7ac460726c2c06a9194fcDaniel Resnick mHost.onStartActivityFromFragment(this /*fragment*/, intent, requestCode, options); 1088fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri } 1089fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri 1090fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri /** 1091fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri * Call {@link Activity#startIntentSenderForResult(IntentSender, int, Intent, int, int, int, 1092fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri * Bundle)} from the fragment's containing Activity. 1093fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri */ 1094fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri public void startIntentSenderForResult(IntentSender intent, int requestCode, 1095fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, 1096fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri Bundle options) throws IntentSender.SendIntentException { 1097fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri if (mHost == null) { 1098fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 1099fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri } 1100fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri mHost.onStartIntentSenderFromFragment(this, intent, requestCode, fillInIntent, flagsMask, 1101fed04169c31e7e3d8c7a328876358dd3564062bbClara Bayarri flagsValues, extraFlags, options); 1102cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1103d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1104cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1105cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Receive the result from a previous call to 1106cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #startActivityForResult(Intent, int)}. This follows the 1107cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * related Activity API as described there in 1108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onActivityResult(int, int, Intent)}. 1109d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * 1110cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param requestCode The integer request code originally supplied to 1111cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * startActivityForResult(), allowing you to identify who this 1112cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * result came from. 1113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param resultCode The integer result code returned by the child activity 1114cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * through its setResult(). 1115cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param data An Intent, which can return result data to the caller 1116cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * (various data can be attached to Intent "extras"). 1117cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1118cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onActivityResult(int requestCode, int resultCode, Intent data) { 1119cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1120d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1121cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1122e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Requests permissions to be granted to this application. These permissions 1123e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * must be requested in your manifest, they should not be granted to your app, 1124e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * and they should have protection level {@link android.content.pm.PermissionInfo 1125e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * #PROTECTION_DANGEROUS dangerous}, regardless whether they are declared by 1126e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * the platform or a third-party app. 1127e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1128e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Normal permissions {@link android.content.pm.PermissionInfo#PROTECTION_NORMAL} 1129e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * are granted at install time if requested in the manifest. Signature permissions 1130e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * {@link android.content.pm.PermissionInfo#PROTECTION_SIGNATURE} are granted at 1131e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * install time if requested in the manifest and the signature of your app matches 1132e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * the signature of the app declaring the permissions. 1133e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1134e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1135e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * If your app does not have the requested permissions the user will be presented 1136e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * with UI for accepting them. After the user has accepted or rejected the 1137e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * requested permissions you will receive a callback on {@link 1138e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * #onRequestPermissionsResult(int, String[], int[])} reporting whether the 1139e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * permissions were granted or not. 1140e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1141e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1142e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Note that requesting a permission does not guarantee it will be granted and 1143e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * your app should be able to run without having this permission. 1144e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1145e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1146e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * This method may start an activity allowing the user to choose which permissions 1147e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * to grant and which to reject. Hence, you should be prepared that your activity 1148e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * may be paused and resumed. Further, granting some permissions may require 1149e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * a restart of you application. In such a case, the system will recreate the 1150e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * activity stack before delivering the result to {@link 1151e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * #onRequestPermissionsResult(int, String[], int[])}. 1152e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1153e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1154e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * When checking whether you have a permission you should use {@link 1155e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * android.content.Context#checkSelfPermission(String)}. 1156e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1157e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 11582750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * Calling this API for permissions already granted to your app would show UI 11592750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * to the user to decided whether the app can still hold these permissions. This 11602750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * can be useful if the way your app uses the data guarded by the permissions 11612750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * changes significantly. 11622750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * </p> 11632750390fbdc2e7037a7e10141d23f2068ae8c2d7Svet Ganov * <p> 1164e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * A sample permissions request looks like this: 1165e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1166e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <code><pre><p> 1167e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * private void showContacts() { 1168e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * if (getActivity().checkSelfPermission(Manifest.permission.READ_CONTACTS) 1169e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * != PackageManager.PERMISSION_GRANTED) { 1170e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, 1171e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * PERMISSIONS_REQUEST_READ_CONTACTS); 1172e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } else { 1173e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * doShowContacts(); 1174e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1175e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1176e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1177e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * {@literal @}Override 1178e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * public void onRequestPermissionsResult(int requestCode, String[] permissions, 1179e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * int[] grantResults) { 1180e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * if (requestCode == PERMISSIONS_REQUEST_READ_CONTACTS 1181e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 1182e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * doShowContacts(); 1183e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1184e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * } 1185e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </code></pre></p> 1186e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1187e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param permissions The requested permissions. 1188e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param requestCode Application specific request code to match with a result 1189e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * reported to {@link #onRequestPermissionsResult(int, String[], int[])}. 1190e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1191e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #onRequestPermissionsResult(int, String[], int[]) 1192e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see android.content.Context#checkSelfPermission(String) 1193e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav */ 1194e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav public final void requestPermissions(@NonNull String[] permissions, int requestCode) { 1195e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav if (mHost == null) { 1196e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 1197e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 11985fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian mHost.onRequestPermissionsFromFragment(this, permissions, requestCode); 1199e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1200e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav 1201e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /** 1202e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Callback for the result from requesting permissions. This method 1203e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * is invoked for every call on {@link #requestPermissions(String[], int)}. 1204dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * <p> 1205dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * <strong>Note:</strong> It is possible that the permissions request interaction 1206dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * with the user is interrupted. In this case you will receive empty permissions 1207dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * and results arrays which should be treated as a cancellation. 1208dddb7e2bbb343ecb435026c13028ba5cd1ae42a5Svet Ganov * </p> 1209e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1210e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}. 1211e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param permissions The requested permissions. Never null. 1212e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param grantResults The grant results for the corresponding permissions 1213e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * which is either {@link android.content.pm.PackageManager#PERMISSION_GRANTED} 1214e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * or {@link android.content.pm.PackageManager#PERMISSION_DENIED}. Never null. 1215e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1216e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #requestPermissions(String[], int) 1217e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav */ 1218e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, 1219e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav @NonNull int[] grantResults) { 1220e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /* callback - do nothing */ 1221e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1222e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav 1223e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /** 1224e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * Gets whether you should show UI with rationale for requesting a permission. 1225e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * You should do this only if you do not have the permission and the context in 1226e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * which the permission is requested does not clearly communicate to the user 1227e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * what would be the benefit from granting this permission. 1228e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * <p> 1229e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * For example, if you write a camera app, requesting the camera permission 1230e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * would be expected by the user and no rationale for why it is requested is 1231e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * needed. If however, the app needs location for tagging photos then a non-tech 1232e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * savvy user may wonder how location is related to taking photos. In this case 1233e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * you may choose to show UI with rationale of requesting this permission. 1234e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * </p> 1235e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1236e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @param permission A permission your app wants to request. 1237e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @return Whether you can show permission rationale UI. 1238e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * 1239e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see Context#checkSelfPermission(String) 1240e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #requestPermissions(String[], int) 1241e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav * @see #onRequestPermissionsResult(int, String[], int[]) 1242e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav */ 1243e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav public boolean shouldShowRequestPermissionRationale(@NonNull String permission) { 1244e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav if (mHost != null) { 1245e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav return mHost.onShouldShowRequestPermissionRationale(permission); 1246e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1247e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav return false; 1248e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav } 1249e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav 1250e1e957f536c20ebe2a7e6c417ccb2fd8f7fa845bSvetoslav /** 125196221034e4a23a2abb83f772a0281bb197ac5ac0George Mount * Returns the LayoutInflater used to inflate Views of this Fragment. The default 125296221034e4a23a2abb83f772a0281bb197ac5ac0George Mount * implementation will throw an exception if the Fragment is not attached. 125396221034e4a23a2abb83f772a0281bb197ac5ac0George Mount * 1254995c3504e6c5b1d20368c36193b44a7e6844709dGeorge Mount * @param savedInstanceState If the fragment is being re-created from 1255995c3504e6c5b1d20368c36193b44a7e6844709dGeorge Mount * a previous saved state, this is the state. 125696221034e4a23a2abb83f772a0281bb197ac5ac0George Mount * @return The LayoutInflater used to inflate Views of this Fragment. 1257cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1258b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton @NonNull 1259b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton public LayoutInflater onGetLayoutInflater(@Nullable Bundle savedInstanceState) { 12600abeed582ee0a105edb41181d76e8ee034750f22George Mount // TODO: move the implementation in getLayoutInflater to here 12610abeed582ee0a105edb41181d76e8ee034750f22George Mount return getLayoutInflater(savedInstanceState); 12620abeed582ee0a105edb41181d76e8ee034750f22George Mount } 12630abeed582ee0a105edb41181d76e8ee034750f22George Mount 12640abeed582ee0a105edb41181d76e8ee034750f22George Mount /** 12658b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * Returns the cached LayoutInflater used to inflate Views of this Fragment. If 12668b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #onGetLayoutInflater(Bundle)} has not been called {@link #onGetLayoutInflater(Bundle)} 12678b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * will be called with a {@code null} argument and that value will be cached. 12688b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * <p> 12698b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * The cached LayoutInflater will be replaced immediately prior to 12708b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} and cleared immediately after 12718b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #onDetach()}. 12728b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * 12738b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * @return The LayoutInflater used to inflate Views of this Fragment. 12748b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount */ 12758b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount public final LayoutInflater getLayoutInflater() { 12768b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount if (mLayoutInflater == null) { 12778b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount return performGetLayoutInflater(null); 12788b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount } 12798b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount return mLayoutInflater; 12808b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount } 12818b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount 12828b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount /** 12838b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * Calls {@link #onGetLayoutInflater(Bundle)} and caches the result for use by 12848b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #getLayoutInflater()}. 12858b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * 12868b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * @param savedInstanceState If the fragment is being re-created from 12878b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * a previous saved state, this is the state. 12888b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * @return The LayoutInflater used to inflate Views of this Fragment. 12898b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount */ 1290b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton @NonNull 1291b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton LayoutInflater performGetLayoutInflater(@Nullable Bundle savedInstanceState) { 12928b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount LayoutInflater layoutInflater = onGetLayoutInflater(savedInstanceState); 12938b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount mLayoutInflater = layoutInflater; 12948b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount return mLayoutInflater; 12958b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount } 12968b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount 12978b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount /** 12988b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * Override {@link #onGetLayoutInflater(Bundle)} when you need to change the 12998b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * LayoutInflater or call {@link #getLayoutInflater()} when you want to 13008b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * retrieve the current LayoutInflater. 13018b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * 13020abeed582ee0a105edb41181d76e8ee034750f22George Mount * @hide 13038b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * @deprecated Override {@link #onGetLayoutInflater(Bundle)} or call 13048b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount * {@link #getLayoutInflater()} instead of this method. 13050abeed582ee0a105edb41181d76e8ee034750f22George Mount */ 13060abeed582ee0a105edb41181d76e8ee034750f22George Mount @Deprecated 1307b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton @NonNull 13080abeed582ee0a105edb41181d76e8ee034750f22George Mount @RestrictTo(LIBRARY_GROUP) 1309b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton public LayoutInflater getLayoutInflater(@Nullable Bundle savedFragmentState) { 131096221034e4a23a2abb83f772a0281bb197ac5ac0George Mount if (mHost == null) { 13110abeed582ee0a105edb41181d76e8ee034750f22George Mount throw new IllegalStateException("onGetLayoutInflater() cannot be executed until the " 131296221034e4a23a2abb83f772a0281bb197ac5ac0George Mount + "Fragment is attached to the FragmentManager."); 131396221034e4a23a2abb83f772a0281bb197ac5ac0George Mount } 13148491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy LayoutInflater result = mHost.onGetLayoutInflater(); 13150f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell getChildFragmentManager(); // Init if needed; use raw implementation below. 13164bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas LayoutInflaterCompat.setFactory2(result, mChildFragmentManager.getLayoutInflaterFactory()); 13170f3dfb28a503b3fb3e51666dd565b0d17eaebfbbAdam Powell return result; 1318cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1319d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1320cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1321cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a fragment is being created as part of a view layout 1322cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * inflation, typically from setting the content view of an activity. This 13239277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * may be called immediately after the fragment is created from a <fragment> 1324cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tag in a layout file. Note this is <em>before</em> the fragment's 1325cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onAttach(Activity)} has been called; all you should do here is 13269277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * parse the attributes and save them away. 13274bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1328cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>This is called every time the fragment is inflated, even if it is 13299277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * being inflated into a new instance with saved state. It typically makes 13309277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * sense to re-parse the parameters each time, to allow them to change with 13319277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * different configurations.</p> 13329277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 13339277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>Here is a typical implementation of a fragment that can take parameters 13349277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * both through attributes supplied here as well from {@link #getArguments()}:</p> 13359277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 1336f266a0a76eb23a0a00ae16f823df2af73bff480fAurimas Liutikas * {@sample frameworks/support/samples/Support4Demos/src/main/java/com/example/android/supportv4/app/FragmentArgumentsSupport.java 13379277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * fragment} 13389277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 13399277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>Note that parsing the XML attributes uses a "styleable" resource. The 13409277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * declaration for the styleable used here is:</p> 13419277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 1342f266a0a76eb23a0a00ae16f823df2af73bff480fAurimas Liutikas * {@sample frameworks/support/samples/Support4Demos/src/main/res/values/attrs.xml fragment_arguments} 13434bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 13449277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>The fragment can then be declared within its activity's content layout 13459277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * through a tag like this:</p> 13469277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 1347f266a0a76eb23a0a00ae16f823df2af73bff480fAurimas Liutikas * {@sample frameworks/support/samples/Support4Demos/src/main/res/layout/fragment_arguments_support.xml from_attributes} 13489277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 13499277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * <p>This fragment can also be created dynamically from arguments given 13509277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * at runtime in the arguments Bundle; here is an example of doing so at 13519277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * creation of the containing activity:</p> 13529277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 1353f266a0a76eb23a0a00ae16f823df2af73bff480fAurimas Liutikas * {@sample frameworks/support/samples/Support4Demos/src/main/java/com/example/android/supportv4/app/FragmentArgumentsSupport.java 13549277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * create} 13559277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn * 1356d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * @param context The Activity that is inflating this fragment. 1357cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param attrs The attributes at the tag where the fragment is 1358cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * being created. 1359cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 1360cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 1361cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1362916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1363d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) { 1364d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = true; 1365d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy final Activity hostActivity = mHost == null ? null : mHost.getActivity(); 1366d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (hostActivity != null) { 1367d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = false; 1368d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy onInflate(hostActivity, attrs, savedInstanceState); 1369d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1370d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1371d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1372d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy /** 1373d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Called when a fragment is being created as part of a view layout 1374d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * inflation, typically from setting the content view of an activity. 1375d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * 1376d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * @deprecated See {@link #onInflate(Context, AttributeSet, Bundle)}. 1377d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy */ 1378d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Deprecated 1379916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 13809277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { 1381cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1382cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 13839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 1384cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1385cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * Called when a fragment is attached as a child of this fragment. 1386cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * 1387cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * <p>This is called after the attached fragment's <code>onAttach</code> and before 1388cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * the attached fragment's <code>onCreate</code> if the fragment has not yet had a previous 1389cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * call to <code>onCreate</code>.</p> 1390cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * 1391cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell * @param childFragment child fragment being attached 1392cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell */ 1393cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell public void onAttachFragment(Fragment childFragment) { 1394cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell } 1395cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell 1396cef09fee2126f901aa164f6e89c370ab81cff1b3Adam Powell /** 1397d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * Called when a fragment is first attached to its context. 1398d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy * {@link #onCreate(Bundle)} will be called after this. 1399d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy */ 1400916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1401d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy public void onAttach(Context context) { 1402d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = true; 1403d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy final Activity hostActivity = mHost == null ? null : mHost.getActivity(); 1404d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (hostActivity != null) { 1405d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mCalled = false; 1406d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy onAttach(hostActivity); 1407d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1408d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy } 1409d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1410d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy /** 1411cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a fragment is first attached to its activity. 1412cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreate(Bundle)} will be called after this. 1413d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * 1414d805095048f6be52cddbd572ee343c4639ba8187Alan Viverette * @deprecated See {@link #onAttach(Context)}. 1415cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1416d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Deprecated 1417916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1418cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onAttach(Activity activity) { 1419cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1420cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1421d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1422cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 142315e593ea3575512d7072240d1db9d74fad8749a3George Mount * Called when a fragment loads an animation. Note that if 142415e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int)} was called with 142515e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link Animator} resources instead of {@link Animation} resources, {@code nextAnim} 142615e593ea3575512d7072240d1db9d74fad8749a3George Mount * will be an animator resource. 142715e593ea3575512d7072240d1db9d74fad8749a3George Mount * 142815e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param transit The value set in {@link FragmentTransaction#setTransition(int)} or 0 if not 142915e593ea3575512d7072240d1db9d74fad8749a3George Mount * set. 143015e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param enter {@code true} when the fragment is added/attached/shown or {@code false} when 143115e593ea3575512d7072240d1db9d74fad8749a3George Mount * the fragment is removed/detached/hidden. 143215e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param nextAnim The resource set in 143315e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int)}, 143415e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int, int, int)}, or 143515e593ea3575512d7072240d1db9d74fad8749a3George Mount * 0 if neither was called. The value will depend on the current operation. 1436cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 14379277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { 1438cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return null; 1439cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1440d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1441cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 144215e593ea3575512d7072240d1db9d74fad8749a3George Mount * Called when a fragment loads an animator. This will be called when 144315e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link #onCreateAnimation(int, boolean, int)} returns null. Note that if 144415e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int)} was called with 144515e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link Animation} resources instead of {@link Animator} resources, {@code nextAnim} 144615e593ea3575512d7072240d1db9d74fad8749a3George Mount * will be an animation resource. 144715e593ea3575512d7072240d1db9d74fad8749a3George Mount * 144815e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param transit The value set in {@link FragmentTransaction#setTransition(int)} or 0 if not 144915e593ea3575512d7072240d1db9d74fad8749a3George Mount * set. 145015e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param enter {@code true} when the fragment is added/attached/shown or {@code false} when 145115e593ea3575512d7072240d1db9d74fad8749a3George Mount * the fragment is removed/detached/hidden. 145215e593ea3575512d7072240d1db9d74fad8749a3George Mount * @param nextAnim The resource set in 145315e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int)}, 145415e593ea3575512d7072240d1db9d74fad8749a3George Mount * {@link FragmentTransaction#setCustomAnimations(int, int, int, int)}, or 145515e593ea3575512d7072240d1db9d74fad8749a3George Mount * 0 if neither was called. The value will depend on the current operation. 145615e593ea3575512d7072240d1db9d74fad8749a3George Mount */ 145715e593ea3575512d7072240d1db9d74fad8749a3George Mount public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) { 145815e593ea3575512d7072240d1db9d74fad8749a3George Mount return null; 145915e593ea3575512d7072240d1db9d74fad8749a3George Mount } 146015e593ea3575512d7072240d1db9d74fad8749a3George Mount 146115e593ea3575512d7072240d1db9d74fad8749a3George Mount /** 1462cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to do initial creation of a fragment. This is called after 1463cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onAttach(Activity)} and before 1464cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 14654bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1466cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>Note that this can be called while the fragment's activity is 1467cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * still in the process of being created. As such, you can not rely 1468cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on things like the activity's content view hierarchy being initialized 1469cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * at this point. If you want to do work once the activity itself is 1470cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * created, see {@link #onActivityCreated(Bundle)}. 1471277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell * 1472277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell * <p>Any restored child fragments will be created before the base 1473277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell * <code>Fragment.onCreate</code> method returns.</p> 14744bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1475cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 1476cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 1477cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1478916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1479c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy public void onCreate(@Nullable Bundle savedInstanceState) { 1480cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 14819375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell restoreChildFragmentState(savedInstanceState); 1482fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell if (mChildFragmentManager != null 1483fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell && !mChildFragmentManager.isStateAtLeast(Fragment.CREATED)) { 1484fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell mChildFragmentManager.dispatchCreate(); 1485fd15fbacc1d0cb92f2edf72137e4940be2547aa4Adam Powell } 14869375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell } 14879375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell 14889375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell /** 14899375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * Restore the state of the child FragmentManager. Called by either 14909375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * {@link #onCreate(Bundle)} for non-retained instance fragments or by 14919375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * {@link FragmentManagerImpl#moveToState(Fragment, int, int, int, boolean)} 14929375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * for retained instance fragments. 14939375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * 14949375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * <p><strong>Postcondition:</strong> if there were child fragments to restore, 14959375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * the child FragmentManager will be instantiated and brought to the {@link #CREATED} state. 14969375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * </p> 14979375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * 14989375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * @param savedInstanceState the savedInstanceState potentially containing fragment info 14999375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell */ 15009375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell void restoreChildFragmentState(@Nullable Bundle savedInstanceState) { 1501277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell if (savedInstanceState != null) { 1502277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell Parcelable p = savedInstanceState.getParcelable( 1503277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell FragmentActivity.FRAGMENTS_TAG); 1504277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell if (p != null) { 1505277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell if (mChildFragmentManager == null) { 1506277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell instantiateChildFragmentManager(); 1507277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell } 1508c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mChildFragmentManager.restoreAllState(p, mChildNonConfig); 1509c077b4cd990a9f220a27ad5eca04828e17136064Adam Powell mChildNonConfig = null; 1510277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell mChildFragmentManager.dispatchCreate(); 1511277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell } 1512277f9d9ad10cd8e989619ee51c888761029daa98Adam Powell } 1513cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 15140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1515cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1516cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to have the fragment instantiate its user interface view. 1517cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is optional, and non-graphical fragments can return null (which 1518cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is the default implementation). This will be called between 1519cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}. 15204bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1521cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>If you return a View from here, you will later be called in 1522cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onDestroyView} when the view is being released. 15234bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1524cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param inflater The LayoutInflater object that can be used to inflate 1525cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * any views in the fragment, 1526cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param container If non-null, this is the parent view that the fragment's 1527cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * UI should be attached to. The fragment should not add the view itself, 1528cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * but this can be used to generate the LayoutParams of the view. 1529cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If non-null, this fragment is being re-constructed 1530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * from a previous saved state as given here. 15314bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1532cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return Return the View for the fragment's UI, or null. 1533cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1534c861fd8b28b0b878ccc194ee6099b3b1bc4c3ae8Scott Kennedy @Nullable 1535b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, 1536a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye @Nullable Bundle savedInstanceState) { 1537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return null; 1538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 15390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1540cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1541e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} 1542e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * has returned, but before any saved state has been restored in to the view. 1543e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * This gives subclasses a chance to initialize themselves once 1544e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * they know their view hierarchy has been completely created. The fragment's 1545e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * view hierarchy is not however attached to its parent at this point. 1546e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 1547e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * @param savedInstanceState If non-null, this fragment is being re-constructed 1548e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn * from a previous saved state as given here. 1549e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn */ 1550cb3829a5ee01e3c0783019c04d083bde4d0082e8Jake Wharton public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 1551e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn } 1552e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn 1553e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn /** 1554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}), 1555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * if provided. 15564bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return The fragment's root view, or null if it has no layout. 1558cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1559a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye @Nullable 1560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public View getView() { 1561cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mView; 1562cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 15634bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1564cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1565cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment's activity has been created and this 1566cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * fragment's view hierarchy instantiated. It can be used to do final 1567cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * initialization once these pieces are in place, such as retrieving 1568cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * views or restoring state. It is also useful for fragments that use 1569cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #setRetainInstance(boolean)} to retain their instance, 1570cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * as this callback tells the fragment when it is fully associated with 1571cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the new activity instance. This is called after {@link #onCreateView} 15720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * and before {@link #onViewStateRestored(Bundle)}. 15730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 1574cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 1575cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * a previous saved state, this is the state. 1576cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1577916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1578a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public void onActivityCreated(@Nullable Bundle savedInstanceState) { 1579cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1580cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 15810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 15820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /** 15830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Called when all saved state has been restored into the view hierarchy 15840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * of the fragment. This can be used to do initialization based on saved 15850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * state that you are letting the view hierarchy track itself, such as 15860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * whether check box widgets are currently checked. This is called 15870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * after {@link #onActivityCreated(Bundle)} and before 15880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * {@link #onStart()}. 15890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * 15900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 15910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * a previous saved state, this is the state. 15920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 1593916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1594a3ff3273e976adf19770651dcf473fa67b38eb22Tor Norbye public void onViewStateRestored(@Nullable Bundle savedInstanceState) { 15950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = true; 1596eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake if (mView != null) { 1597eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake mViewLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE); 1598eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake } 15990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 16000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 1601cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1602cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is visible to the user. This is generally 1603cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onStart() Activity.onStart} of the containing 1604cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1605cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1606916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1607cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onStart() { 1608cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1609cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1610d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy 1611cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1612cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is visible to the user and actively running. 1613cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This is generally 1614cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onResume() Activity.onResume} of the containing 1615cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1616cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1617916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1618cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onResume() { 1619cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1620cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16214bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1622cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1623cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called to ask the fragment to save its current dynamic state, so it 1624cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can later be reconstructed in a new instance of its process is 1625cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * restarted. If a new instance of the fragment later needs to be 1626cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * created, the data you place in the Bundle here will be available 1627cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * in the Bundle given to {@link #onCreate(Bundle)}, 1628cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}, and 1629cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onActivityCreated(Bundle)}. 1630cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1631cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>This corresponds to {@link Activity#onSaveInstanceState(Bundle) 1632cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity.onSaveInstanceState(Bundle)} and most of the discussion there 1633cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * applies here as well. Note however: <em>this method may be called 1634cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * at any time before {@link #onDestroy()}</em>. There are many situations 1635cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * where a fragment may be mostly torn down (such as when placed on the 1636cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * back stack with no UI showing), but its state will not be saved until 1637cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * its owning activity actually needs to save its state. 1638cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 1639cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param outState Bundle in which to place your saved state. 1640cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1641abdae2e27083efa81020e1619250fb2864f3bbc4Jake Wharton public void onSaveInstanceState(@NonNull Bundle outState) { 1642cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16435fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 16445fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian /** 16455fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * Called when the Fragment's activity changes from fullscreen mode to multi-window mode and 16465fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * visa-versa. This is generally tied to {@link Activity#onMultiWindowModeChanged} of the 16475fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * containing Activity. 16485fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * 16495fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * @param isInMultiWindowMode True if the activity is in multi-window mode. 16505fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian */ 16515fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { 16525fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 16535fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 16545fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian /** 16555fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * Called by the system when the activity changes to and from picture-in-picture mode. This is 16565fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * generally tied to {@link Activity#onPictureInPictureModeChanged} of the containing Activity. 16575fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * 16585fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode. 16595fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian */ 16605fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { 16615fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 16625fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 166390ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas @Override 1664916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1665cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onConfigurationChanged(Configuration newConfig) { 1666cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1667cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16685fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 1669cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1670cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is no longer resumed. This is generally 1671cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onPause() Activity.onPause} of the containing 1672cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1673cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1674916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1675cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onPause() { 1676cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1677cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16784bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1679cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1680cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the Fragment is no longer started. This is generally 1681cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * tied to {@link Activity#onStop() Activity.onStop} of the containing 1682cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Activity's lifecycle. 1683cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1684916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1685cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onStop() { 1686cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1687cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1688916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell 168990ac236504c1a4cac7e91f1ffc523334f2a8f399Aurimas Liutikas @Override 1690916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1691cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onLowMemory() { 1692cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 16944bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1695cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1696cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the view previously created by {@link #onCreateView} has 1697cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * been detached from the fragment. The next time the fragment needs 1698cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to be displayed, a new view will be created. This is called 1699cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * after {@link #onStop()} and before {@link #onDestroy()}. It is called 1700cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <em>regardless</em> of whether {@link #onCreateView} returned a 1701cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * non-null view. Internally it is called after the view's state has 1702cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * been saved but before it has been removed from its parent. 1703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1704916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroyView() { 1706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1707eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake if (mView != null) { 1708eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake mViewLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY); 1709eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake } 1710cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 17114bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1712cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1713cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is no longer in use. This is called 1714cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * after {@link #onStop()} and before {@link #onDetach()}. 1715cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1716916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1717cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroy() { 1718cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 17190d429d5f5bb0d6197d5c7a24b5c0bb5bcd5db8cdIan Lake // Use mStateSaved instead of isStateSaved() since we're past onStop() 17200d429d5f5bb0d6197d5c7a24b5c0bb5bcd5db8cdIan Lake if (mViewModelStore != null && !mHost.mFragmentManager.mStateSaved) { 172141516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake mViewModelStore.clear(); 172241516afc57ee5165d3a4e6c8a36f798d2cf6be4fIan Lake } 1723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1724cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1725cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 17269c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * Called by the fragment manager once this fragment has been removed, 17279c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * so that we don't have any left-over state if the application decides 17289c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * to re-use the instance. This only clears state that the framework 17299c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn * internally manages, not things the application sets. 17309c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn */ 17319c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void initState() { 17329c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mIndex = -1; 17339c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mWho = null; 17349c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mAdded = false; 17359c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRemoving = false; 17369c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFromLayout = false; 17379c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mInLayout = false; 17389c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRestored = false; 17399c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mBackStackNesting = 0; 17409c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFragmentManager = null; 17416252d78085a07c9d6bb4645a4e8086bf23b0a49aTim Kilbourn mChildFragmentManager = null; 1742d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mHost = null; 17439c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mFragmentId = 0; 17449c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mContainerId = 0; 17459c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mTag = null; 17469c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mHidden = false; 17479c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mDetached = false; 17489c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn mRetaining = false; 17499c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 17509c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 17519c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn /** 1752cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when the fragment is no longer attached to its activity. This 1753cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * is called after {@link #onDestroy()}. 1754cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1755916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell @CallSuper 1756cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDetach() { 1757cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCalled = true; 1758cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 17594bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1760cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 17619375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * Initialize the contents of the Fragment host's standard options menu. You 1762cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * should place your menu items in to <var>menu</var>. For this method 1763cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to be called, you must have first called {@link #setHasOptionsMenu}. See 1764cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu} 1765cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for more information. 17664bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1767cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu in which you place your items. 17684bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1769cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #setHasOptionsMenu 1770cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onPrepareOptionsMenu 1771cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onOptionsItemSelected 1772cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1773cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 1774cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1775cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1776cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 17779375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell * Prepare the Fragment host's standard options menu to be displayed. This is 1778cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * called right before the menu is shown, every time it is shown. You can 1779cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * use this method to efficiently enable/disable items or otherwise 1780cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * dynamically modify the contents. See 1781cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu} 1782cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for more information. 17834bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1784cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu as last shown or first initialized by 1785cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * onCreateOptionsMenu(). 17864bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1787cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #setHasOptionsMenu 1788cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onCreateOptionsMenu 1789cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1790cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onPrepareOptionsMenu(Menu menu) { 1791cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1792cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1793cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1794cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when this fragment's option menu items are no longer being 1795cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * included in the overall options menu. Receiving this call means that 1796cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the menu needed to be rebuilt, but this fragment's items were not 1797cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * included in the newly built menu (its {@link #onCreateOptionsMenu(Menu, MenuInflater)} 1798cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * was not called). 1799cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1800cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onDestroyOptionsMenu() { 1801cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 18024bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1803cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1804cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever an item in your options menu is selected. 1805cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * The default implementation simply returns false to have the normal 1806cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * processing happen (calling the item's Runnable or sending a message to 1807cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * its Handler as appropriate). You can use this method for any items 1808cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * for which you would like to do processing without those other 1809cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * facilities. 18104bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1811cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p>Derived classes should call through to the base class for it to 1812cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * perform the default menu handling. 18134bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1814cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param item The menu item that was selected. 18154bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1816cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return boolean Return false to allow normal menu processing to 1817cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * proceed, true to consume it here. 18184bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1819cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #onCreateOptionsMenu 1820cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1821cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public boolean onOptionsItemSelected(MenuItem item) { 1822cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return false; 1823cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1824cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1825cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1826cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever the options menu is being closed (either by the user canceling 1827cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the menu with the back/menu button, or when an item is selected). 18284bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1829cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param menu The options menu as last shown or first initialized by 1830cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * onCreateOptionsMenu(). 1831cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1832cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onOptionsMenuClosed(Menu menu) { 1833cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 18344bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1835cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1836cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Called when a context menu for the {@code view} is about to be shown. 1837cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Unlike {@link #onCreateOptionsMenu}, this will be called every 1838cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * time the context menu is about to be shown and should be populated for 1839cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the view (or item inside the view for {@link AdapterView} subclasses, 1840cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * this can be found in the {@code menuInfo})). 1841cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1842cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an 1843cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * item has been selected. 1844cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1845cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * The default implementation calls up to 1846cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though 1847cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * you can not call this implementation if you don't want that behavior. 1848cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1849cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * It is not safe to hold onto the context menu after this method returns. 1850cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@inheritDoc} 1851cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1852d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy @Override 1853cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 1854cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn getActivity().onCreateContextMenu(menu, v, menuInfo); 1855cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1856cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 1857cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1858cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Registers a context menu to be shown for the given view (multiple views 1859cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * can show the context menu). This method will set the 1860cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link OnCreateContextMenuListener} on the view to this fragment, so 1861cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be 1862cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * called when it is time to show the context menu. 18634bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1864cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #unregisterForContextMenu(View) 1865cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param view The view that should show a context menu. 1866cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1867cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void registerForContextMenu(View view) { 1868cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn view.setOnCreateContextMenuListener(this); 1869cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 18704bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1871cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1872cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Prevents a context menu to be shown for the given view. This method will 1873cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * remove the {@link OnCreateContextMenuListener} on the view. 18744bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1875cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @see #registerForContextMenu(View) 1876cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param view The view that should stop showing a context menu. 1877cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1878cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void unregisterForContextMenu(View view) { 1879cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn view.setOnCreateContextMenuListener(null); 1880cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 18814bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas 1882cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 1883cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * This hook is called whenever an item in a context menu is selected. The 1884cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * default implementation simply returns false to have the normal processing 1885cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * happen (calling the item's Runnable or sending a message to its Handler 1886cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * as appropriate). You can use this method for any items for which you 1887cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * would like to do processing without those other facilities. 1888cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1889cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Use {@link MenuItem#getMenuInfo()} to get extra information set by the 1890cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * View that added this menu item. 1891cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * <p> 1892cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Derived classes should call through to the base class for it to perform 1893cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * the default menu handling. 18944bf8c3d1aeb944a993c946db770604b55f981341Aurimas Liutikas * 1895cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param item The context menu item that was selected. 1896cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @return boolean Return false to allow normal context menu processing to 1897cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * proceed, true to consume it here. 1898cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 1899cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public boolean onContextItemSelected(MenuItem item) { 1900cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return false; 1901cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 1902e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes 1903cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn /** 19049306f07b1d66f4974a81f781d29739b30124fff0George Mount * When custom transitions are used with Fragments, the enter transition callback 19059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is called when this Fragment is attached or detached when not popping the back stack. 19069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19079306f07b1d66f4974a81f781d29739b30124fff0George Mount * @param callback Used to manipulate the shared element transitions on this Fragment 19089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when added not as a pop from the back stack. 19099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 1910b1413bc4de16e05ae0455cad93f1edfbcc4eced2George Mount public void setEnterSharedElementCallback(SharedElementCallback callback) { 1911990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mEnterTransitionCallback = callback; 19129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19159306f07b1d66f4974a81f781d29739b30124fff0George Mount * When custom transitions are used with Fragments, the exit transition callback 19169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is called when this Fragment is attached or detached when popping the back stack. 19179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19189306f07b1d66f4974a81f781d29739b30124fff0George Mount * @param callback Used to manipulate the shared element transitions on this Fragment 19199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when added as a pop from the back stack. 19209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 1921b1413bc4de16e05ae0455cad93f1edfbcc4eced2George Mount public void setExitSharedElementCallback(SharedElementCallback callback) { 1922990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mExitTransitionCallback = callback; 19239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views into the initial scene. The entering 19279f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 19289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 19299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 19309f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null, 19319f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. 19329f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19339f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views into the initial Scene. 19349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19352a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setEnterTransition(@Nullable Object transition) { 1936990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mEnterTransition = transition; 19379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views into the initial scene. The entering 19419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 19429f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 19439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 19449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#INVISIBLE} to {@link View#VISIBLE}. 19459f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19469f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views into the initial Scene. 19479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19482a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 19499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getEnterTransition() { 1950990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 1951990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 1952990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 1953990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mEnterTransition; 19549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views out of the scene when the Fragment is 19589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * preparing to be removed, hidden, or detached because of popping the back stack. The exiting 19599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 19609f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 19619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 19629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null, 19639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. If nothing is set, the default will be to 19649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * use the same value as set in {@link #setEnterTransition(Object)}. 19659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views out of the Scene when the Fragment 1967a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * is preparing to close. <code>transition</code> must be an 1968a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * {@link android.transition.Transition android.transition.Transition} or 1969ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * {@link androidx.transition.Transition androidx.transition.Transition}. 19709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19712a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setReturnTransition(@Nullable Object transition) { 1972990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mReturnTransition = transition; 19739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views out of the scene when the Fragment is 19779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * preparing to be removed, hidden, or detached because of popping the back stack. The exiting 19789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Views will be those that are regular Views or ViewGroups that have 19799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 19809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as entering is governed by changing visibility from 19819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null, 19829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * entering Views will remain unaffected. 19839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 19849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views out of the Scene when the Fragment 19859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is preparing to close. 19869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 19872a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 19889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getReturnTransition() { 1989990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 1990990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 1991990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 1992990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mReturnTransition == USE_DEFAULT_TRANSITION ? getEnterTransition() 1993990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount : mAnimationInfo.mReturnTransition; 19949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 19959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 19969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 19979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views out of the scene when the 19989f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * fragment is removed, hidden, or detached when not popping the back stack. 19999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * The exiting Views will be those that are regular Views or ViewGroups that 20009f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 20019f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as exiting is governed by changing visibility 20029f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will 20039f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * remain unaffected. 20049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views out of the Scene when the Fragment 2006a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * is being closed not due to popping the back stack. <code>transition</code> 2007a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * must be an 2008a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * {@link android.transition.Transition android.transition.Transition} or 2009ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * {@link androidx.transition.Transition androidx.transition.Transition}. 20109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20112a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setExitTransition(@Nullable Object transition) { 2012990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mExitTransition = transition; 20139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20169f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views out of the scene when the 20179f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * fragment is removed, hidden, or detached when not popping the back stack. 20189f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * The exiting Views will be those that are regular Views or ViewGroups that 20199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 20209f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.Visibility} as exiting is governed by changing visibility 20219f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will 20229f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * remain unaffected. 20239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views out of the Scene when the Fragment 20259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * is being closed not due to popping the back stack. 20269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20272a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 20289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getExitTransition() { 2029990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2030990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2031990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2032990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mExitTransition; 20339f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20359f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20369f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used to move Views in to the scene when returning due 20379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * to popping a back stack. The entering Views will be those that are regular Views 20389f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions 20399f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * will extend {@link android.transition.Visibility} as exiting is governed by changing 20409f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, 20419f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * the views will remain unaffected. If nothing is set, the default will be to use the same 20429f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * transition as {@link #setExitTransition(Object)}. 20439f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use to move Views into the scene when reentering from a 2045a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * previously-started Activity. <code>transition</code> 2046a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * 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 setReenterTransition(@Nullable Object transition) { 2051990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mReenterTransition = transition; 20529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20559f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used to move Views in to the scene when returning due 20569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * to popping a back stack. The entering Views will be those that are regular Views 20579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions 20589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * will extend {@link android.transition.Visibility} as exiting is governed by changing 20599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, 20609f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * the views will remain unaffected. If nothing is set, the default will be to use the same 20619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * transition as {@link #setExitTransition(Object)}. 20629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return the Transition to use to move Views into the scene when reentering from a 20649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * previously-started Activity. 20659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getReenterTransition() { 2067990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2068990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2069990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2070990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mReenterTransition == USE_DEFAULT_TRANSITION ? getExitTransition() 2071990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount : mAnimationInfo.mReenterTransition; 20729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used for shared elements transferred into the content 20769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. Typical Transitions will affect size and location, such as 20779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 20789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 20799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20809f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use for shared elements transferred into the content 2081a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * Scene. <code>transition</code> must be an 2082a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * {@link android.transition.Transition android.transition.Transition} or 2083ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * {@link androidx.transition.Transition androidx.transition.Transition}. 20849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20852a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setSharedElementEnterTransition(@Nullable Object transition) { 2086990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mSharedElementEnterTransition = transition; 20879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 20889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 20899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 20909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns the Transition that will be used for shared elements transferred into the content 20919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. Typical Transitions will affect size and location, such as 20929f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 20939f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 20949f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 20959f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return The Transition to use for shared elements transferred into the content 20969f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. 20979f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 20982a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 20999f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getSharedElementEnterTransition() { 2100990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2101990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2102990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2103990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mSharedElementEnterTransition; 21049f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 21059f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 21069f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 21079f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets the Transition that will be used for shared elements transferred back during a 21089f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * pop of the back stack. This Transition acts in the leaving Fragment. 21099f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Typical Transitions will affect size and location, such as 21109f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 21119f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 21129f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * If no value is set, the default will be to use the same value as 21139f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link #setSharedElementEnterTransition(Object)}. 21149f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 21159f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param transition The Transition to use for shared elements transferred out of the content 2116a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * Scene. <code>transition</code> must be an 2117a318550a4904d11021bbf03f4d3970e7f9a61036Andrew Solovay * {@link android.transition.Transition android.transition.Transition} or 2118ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * {@link androidx.transition.Transition androidx.transition.Transition}. 21199f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 21202a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton public void setSharedElementReturnTransition(@Nullable Object transition) { 2121990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mSharedElementReturnTransition = transition; 21229f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 21239f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 21249f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 21259f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Return the Transition that will be used for shared elements transferred back during a 21269f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * pop of the back stack. This Transition acts in the leaving Fragment. 21279f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Typical Transitions will affect size and location, such as 21289f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link android.transition.ChangeBounds}. A null 21299f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * value will cause transferred shared elements to blink to the final position. 21309f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * If no value is set, the default will be to use the same value as 21319f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * {@link #setSharedElementEnterTransition(Object)}. 21329f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 21339f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return The Transition to use for shared elements transferred out of the content 21349f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Scene. 21359f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 21362a37c0088889b865ee9a044c49f58d82a4e75786Jake Wharton @Nullable 21379f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public Object getSharedElementReturnTransition() { 2138990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2139990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2140990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2141990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mSharedElementReturnTransition == USE_DEFAULT_TRANSITION 2142990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ? getSharedElementEnterTransition() 2143990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount : mAnimationInfo.mSharedElementReturnTransition; 21449f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 21459f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 21469f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 21479f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets whether the the exit transition and enter transition overlap or not. 21489f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the enter transition will start as soon as possible. When false, the 21499f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * enter transition will wait until the exit transition completes before starting. 21509f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 21519f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param allow true to start the enter transition when possible or false to 21529f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * wait until the exiting transition completes. 21539f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 21549f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setAllowEnterTransitionOverlap(boolean allow) { 2155990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mAllowEnterTransitionOverlap = allow; 21569f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 21579f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 21589f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 21599f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns whether the the exit transition and enter transition overlap or not. 21609f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the enter transition will start as soon as possible. When false, the 21619f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * enter transition will wait until the exit transition completes before starting. 21629f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 21639f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return true when the enter transition should start as soon as possible or false to 21649f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * when it should wait until the exiting transition completes. 21659f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 21669f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public boolean getAllowEnterTransitionOverlap() { 2167990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return (mAnimationInfo == null || mAnimationInfo.mAllowEnterTransitionOverlap == null) 2168990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ? true : mAnimationInfo.mAllowEnterTransitionOverlap; 21699f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 21709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 21719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 21729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Sets whether the the return transition and reenter transition overlap or not. 21739f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the reenter transition will start as soon as possible. When false, the 21749f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * reenter transition will wait until the return transition completes before starting. 21759f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 21769f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @param allow true to start the reenter transition when possible or false to wait until the 21779f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * return transition completes. 21789f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 21799f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public void setAllowReturnTransitionOverlap(boolean allow) { 2180990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mAllowReturnTransitionOverlap = allow; 21819f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 21829f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 21839f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 21849f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * Returns whether the the return transition and reenter transition overlap or not. 21859f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * When true, the reenter transition will start as soon as possible. When false, the 21869f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * reenter transition will wait until the return transition completes before starting. 21879f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * 21889f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * @return true to start the reenter transition when possible or false to wait until the 21899f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount * return transition completes. 21909f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount */ 21919f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount public boolean getAllowReturnTransitionOverlap() { 2192990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return (mAnimationInfo == null || mAnimationInfo.mAllowReturnTransitionOverlap == null) 2193990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ? true : mAnimationInfo.mAllowReturnTransitionOverlap; 2194990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2195990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2196990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2197990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Postpone the entering Fragment transition until {@link #startPostponedEnterTransition()} 2198990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * or {@link FragmentManager#executePendingTransactions()} has been called. 2199990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * <p> 2200990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * This method gives the Fragment the ability to delay Fragment animations 2201990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * until all data is loaded. Until then, the added, shown, and 2202990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * attached Fragments will be INVISIBLE and removed, hidden, and detached Fragments won't 2203990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * be have their Views removed. The transaction runs when all postponed added Fragments in the 2204990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * transaction have called {@link #startPostponedEnterTransition()}. 2205990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * <p> 2206990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * This method should be called before being added to the FragmentTransaction or 2207990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * in {@link #onCreate(Bundle), {@link #onAttach(Context)}, or 2208990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}}. 2209990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * {@link #startPostponedEnterTransition()} must be called to allow the Fragment to 2210990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * start the transitions. 2211990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * <p> 2212990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * When a FragmentTransaction is started that may affect a postponed FragmentTransaction, 2213990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * based on which containers are in their operations, the postponed FragmentTransaction 2214990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * will have its start triggered. The early triggering may result in faulty or nonexistent 2215990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * animations in the postponed transaction. FragmentTransactions that operate only on 2216990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * independent containers will not interfere with each other's postponement. 2217990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * <p> 2218990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Calling postponeEnterTransition on Fragments with a null View will not postpone the 2219fda5be2466024a656152015c45a7681361d399bbGeorge Mount * transition. Likewise, postponement only works if 2220fda5be2466024a656152015c45a7681361d399bbGeorge Mount * {@link FragmentTransaction#setReorderingAllowed(boolean) FragmentTransaction reordering} is 2221990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * enabled. 2222990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * 2223990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * @see Activity#postponeEnterTransition() 2224fda5be2466024a656152015c45a7681361d399bbGeorge Mount * @see FragmentTransaction#setReorderingAllowed(boolean) 2225990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2226990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount public void postponeEnterTransition() { 2227990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mEnterTransitionPostponed = true; 2228990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2229990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2230990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2231990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Begin postponed transitions after {@link #postponeEnterTransition()} was called. 2232990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * If postponeEnterTransition() was called, you must call startPostponedEnterTransition() 2233990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * or {@link FragmentManager#executePendingTransactions()} to complete the FragmentTransaction. 2234990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * If postponement was interrupted with {@link FragmentManager#executePendingTransactions()}, 2235990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * before {@code startPostponedEnterTransition()}, animations may not run or may execute 2236990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * improperly. 2237990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * 2238990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * @see Activity#startPostponedEnterTransition() 2239990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2240990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount public void startPostponedEnterTransition() { 2241990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mFragmentManager == null || mFragmentManager.mHost == null) { 2242990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mEnterTransitionPostponed = false; 2243990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } else if (Looper.myLooper() != mFragmentManager.mHost.getHandler().getLooper()) { 2244990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mFragmentManager.mHost.getHandler().postAtFrontOfQueue(new Runnable() { 2245990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount @Override 2246990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount public void run() { 2247990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount callStartTransitionListener(); 2248990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2249990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount }); 2250990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } else { 2251990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount callStartTransitionListener(); 2252990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2253990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2254990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2255990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2256990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Calls the start transition listener. This must be called on the UI thread. 2257990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2258990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private void callStartTransitionListener() { 2259990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount final OnStartEnterTransitionListener listener; 2260990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2261990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount listener = null; 2262990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } else { 2263990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mEnterTransitionPostponed = false; 2264990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount listener = mAnimationInfo.mStartEnterTransitionListener; 2265990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mStartEnterTransitionListener = null; 2266990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2267990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (listener != null) { 2268990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount listener.onStartEnterTransition(); 2269990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 22709f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount } 22719f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount 22729f4a046cbeb22a24d322a644323b41022ad9d15aGeorge Mount /** 2273cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Print the Fragments's state into the given stream. 2274cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 2275cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param prefix Text to print at the front of each line. 2276cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param fd The raw file descriptor that the dump is being sent to. 2277cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param writer The PrintWriter to which you should dump your state. This will be 2278cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * closed for you after you return. 2279cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @param args additional arguments to the dump request. 2280cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 2281cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { 2282cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mFragmentId=#"); 2283cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(Integer.toHexString(mFragmentId)); 22845506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn writer.print(" mContainerId=#"); 2285cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(Integer.toHexString(mContainerId)); 2286cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mTag="); writer.println(mTag); 2287cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mState="); writer.print(mState); 2288cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mIndex="); writer.print(mIndex); 2289cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mWho="); writer.print(mWho); 2290cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mBackStackNesting="); writer.println(mBackStackNesting); 2291cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mAdded="); writer.print(mAdded); 2292cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mRemoving="); writer.print(mRemoving); 2293cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mFromLayout="); writer.print(mFromLayout); 2294cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mInLayout="); writer.println(mInLayout); 2295cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mHidden="); writer.print(mHidden); 2296e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn writer.print(" mDetached="); writer.print(mDetached); 22972a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn writer.print(" mMenuVisible="); writer.print(mMenuVisible); 2298cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mHasMenu="); writer.println(mHasMenu); 22992a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn writer.print(prefix); writer.print("mRetainInstance="); writer.print(mRetainInstance); 230079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell writer.print(" mRetaining="); writer.print(mRetaining); 230179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell writer.print(" mUserVisibleHint="); writer.println(mUserVisibleHint); 2302cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mFragmentManager != null) { 2303cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mFragmentManager="); 2304cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mFragmentManager); 2305cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2306d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy if (mHost != null) { 2307d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy writer.print(prefix); writer.print("mHost="); 2308d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy writer.println(mHost); 2309cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 23100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mParentFragment != null) { 23110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.print(prefix); writer.print("mParentFragment="); 23120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.println(mParentFragment); 23130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2314cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mArguments != null) { 2315cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mArguments="); writer.println(mArguments); 2316cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2317cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedFragmentState != null) { 2318cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mSavedFragmentState="); 2319cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mSavedFragmentState); 2320cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2321cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mSavedViewState != null) { 2322cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mSavedViewState="); 2323cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mSavedViewState); 2324cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2325cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mTarget != null) { 2326cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mTarget="); writer.print(mTarget); 2327cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mTargetRequestCode="); 2328cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mTargetRequestCode); 2329cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2330990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (getNextAnim() != 0) { 2331990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print(prefix); writer.print("mNextAnim="); writer.println(getNextAnim()); 2332cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2333cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mContainer != null) { 2334cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mContainer="); writer.println(mContainer); 2335cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2336cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mView != null) { 2337cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mView="); writer.println(mView); 2338cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2339cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mInnerView != null) { 2340cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mInnerView="); writer.println(mView); 2341cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2342990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (getAnimatingAway() != null) { 2343990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print(prefix); 2344990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print("mAnimatingAway="); 2345990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.println(getAnimatingAway()); 2346990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print(prefix); 2347990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.print("mStateAfterAnimating="); 2348990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount writer.println(getStateAfterAnimating()); 2349cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2350afe28d91550483f9b7a82076a507151b4defd9baIan Lake LoaderManager.getInstance(this).dump(prefix, fd, writer, args); 23510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn writer.print(prefix); writer.println("Child " + mChildFragmentManager + ":"); 23530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dump(prefix + " ", fd, writer, args); 23540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 23570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Fragment findFragmentByWho(String who) { 23580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (who.equals(mWho)) { 23590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return this; 23600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mChildFragmentManager.findFragmentByWho(who); 23630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return null; 23650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 23670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void instantiateChildFragmentManager() { 23681c7e1f738e202226b365c81715b221d2e864fdd5George Mount if (mHost == null) { 23691c7e1f738e202226b365c81715b221d2e864fdd5George Mount throw new IllegalStateException("Fragment has not been attached yet."); 23701c7e1f738e202226b365c81715b221d2e864fdd5George Mount } 2371e0f27d39b0a4f0ef30ef6446e7b675279961cc94Chris Banes mChildFragmentManager = new FragmentManagerImpl(); 2372d608cf6e08769bf320c1b595cbbd9a7664160449Todd Kennedy mChildFragmentManager.attachController(mHost, new FragmentContainer() { 23730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn @Override 23740fb3ec354da6c1f3ed1777bca5270710cc537e92Scott Kennedy @Nullable 23758491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy public View onFindViewById(int id) { 23760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mView == null) { 23770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new IllegalStateException("Fragment does not have a view"); 23780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return mView.findViewById(id); 23800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23817516316ffdf6fbf7b248c615404831191daa66a4George Mount 23827516316ffdf6fbf7b248c615404831191daa66a4George Mount @Override 23838491eb62f621cd5de4b4caed839be09c77011f53Todd Kennedy public boolean onHasView() { 23847516316ffdf6fbf7b248c615404831191daa66a4George Mount return (mView != null); 23857516316ffdf6fbf7b248c615404831191daa66a4George Mount } 23864aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell 23874aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell @Override 23884aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell public Fragment instantiate(Context context, String className, Bundle arguments) { 23894aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell return mHost.instantiate(context, className, arguments); 23904aebb5be19bbf9314e7474dd62df8dd915313436Adam Powell } 23910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn }, this); 23920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 23930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 23940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performCreate(Bundle savedInstanceState) { 23950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 23960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 23970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 239820735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = CREATED; 23990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 24000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onCreate(savedInstanceState); 2401e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount mIsCreated = true; 24020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 24030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 24040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onCreate()"); 24050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2406c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE); 24070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 2409eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake void performCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, 2410b4e1bbef8044fdd791edf6dfc3284b765abbe505Jake Wharton @Nullable Bundle savedInstanceState) { 24110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 24130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 241437149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell mPerformedCreateView = true; 2415eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake mViewLifecycleOwner = new LifecycleOwner() { 2416eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake @Override 2417eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake public Lifecycle getLifecycle() { 2418eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake if (mViewLifecycleRegistry == null) { 2419eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake mViewLifecycleRegistry = new LifecycleRegistry(mViewLifecycleOwner); 2420eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake } 2421eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake return mViewLifecycleRegistry; 2422eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake } 2423eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake }; 2424eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake mViewLifecycleRegistry = null; 2425eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake mView = onCreateView(inflater, container, savedInstanceState); 2426eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake if (mView != null) { 2427eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake // Initialize the LifecycleRegistry if needed 2428eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake mViewLifecycleOwner.getLifecycle(); 2429eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake // Then inform any Observers of the new LifecycleOwner 2430eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake mViewLifecycleOwnerLiveData.setValue(mViewLifecycleOwner); 2431eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake } else { 2432eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake if (mViewLifecycleRegistry != null) { 2433eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake throw new IllegalStateException("Called getViewLifecycleOwner() but " 2434eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake + "onCreateView() returned null"); 2435eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake } 2436eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake mViewLifecycleOwner = null; 2437eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake } 24380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performActivityCreated(Bundle savedInstanceState) { 24410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 24430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 244420735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = ACTIVITY_CREATED; 24450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 24460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onActivityCreated(savedInstanceState); 24470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 24480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 24490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onActivityCreated()"); 24500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchActivityCreated(); 24530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 2455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 24569c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void performStart() { 24570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 24590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 24600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 246120735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = STARTED; 24620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 24639c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn onStart(); 24640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 24650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 24660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onStart()"); 24670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStart(); 24700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2471c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START); 2472eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake if (mView != null) { 2473eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake mViewLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START); 2474eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake } 24759c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 24769c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn 24770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performResume() { 24780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.noteStateNotSaved(); 24800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 24810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 248220735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = RESUMED; 24830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 24840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onResume(); 24850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 24860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 24870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onResume()"); 24880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 24900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchResume(); 24910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.execPendingActions(); 24920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2493c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME); 2494eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake if (mView != null) { 2495eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake mViewLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME); 2496eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake } 24970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 24980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 24990765353c002bfdf681c982565810aa4be3499dd0George Mount void noteStateNotSaved() { 25000765353c002bfdf681c982565810aa4be3499dd0George Mount if (mChildFragmentManager != null) { 25010765353c002bfdf681c982565810aa4be3499dd0George Mount mChildFragmentManager.noteStateNotSaved(); 25020765353c002bfdf681c982565810aa4be3499dd0George Mount } 25030765353c002bfdf681c982565810aa4be3499dd0George Mount } 25040765353c002bfdf681c982565810aa4be3499dd0George Mount 25055fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian void performMultiWindowModeChanged(boolean isInMultiWindowMode) { 25065fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian onMultiWindowModeChanged(isInMultiWindowMode); 25075fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian if (mChildFragmentManager != null) { 25085fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian mChildFragmentManager.dispatchMultiWindowModeChanged(isInMultiWindowMode); 25095fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 25105fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 25115fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 25125fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian void performPictureInPictureModeChanged(boolean isInPictureInPictureMode) { 25135fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian onPictureInPictureModeChanged(isInPictureInPictureMode); 25145fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian if (mChildFragmentManager != null) { 25155fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian mChildFragmentManager.dispatchPictureInPictureModeChanged(isInPictureInPictureMode); 25165fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 25175fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian } 25185fa6d3dd3f408ceb2ff7368fd0259713d9382ad8Andrii Kulian 25190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performConfigurationChanged(Configuration newConfig) { 25200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onConfigurationChanged(newConfig); 25210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25220adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchConfigurationChanged(newConfig); 25230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25240adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25250adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 25260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performLowMemory() { 25270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onLowMemory(); 25280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchLowMemory(); 25300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 25330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn /* 25340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performTrimMemory(int level) { 25350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onTrimMemory(level); 25360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchTrimMemory(level); 25380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */ 25410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 25420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performCreateOptionsMenu(Menu menu, MenuInflater inflater) { 25430adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean show = false; 25440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 25450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 25460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show = true; 25470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onCreateOptionsMenu(menu, inflater); 25480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25500adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show |= mChildFragmentManager.dispatchCreateOptionsMenu(menu, inflater); 25510adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25520adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return show; 25540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 25560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performPrepareOptionsMenu(Menu menu) { 25570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean show = false; 25580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 25590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 25600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show = true; 25610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onPrepareOptionsMenu(menu); 25620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25630adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25640adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn show |= mChildFragmentManager.dispatchPrepareOptionsMenu(menu); 25650adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25660adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return show; 25680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 25700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performOptionsItemSelected(MenuItem item) { 25710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 25720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 25730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (onOptionsItemSelected(item)) { 25740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 25750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager.dispatchOptionsItemSelected(item)) { 25790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 25800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return false; 25840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 25860adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn boolean performContextItemSelected(MenuItem item) { 25870adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 25880adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (onContextItemSelected(item)) { 25890adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 25900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 25920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager.dispatchContextItemSelected(item)) { 25930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return true; 25940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn return false; 25980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 25990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 26000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performOptionsMenuClosed(Menu menu) { 26010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mHidden) { 26020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mHasMenu && mMenuVisible) { 26030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onOptionsMenuClosed(menu); 26040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 26050adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 26060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchOptionsMenuClosed(menu); 26070adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 26080adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 26090adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 26100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 26110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performSaveInstanceState(Bundle outState) { 26120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onSaveInstanceState(outState); 26130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 26140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn Parcelable p = mChildFragmentManager.saveAllState(); 26150adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (p != null) { 26160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn outState.putParcelable(FragmentActivity.FRAGMENTS_TAG, p); 26170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 26180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 26190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 26200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 26210adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performPause() { 2622eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake if (mView != null) { 2623eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake mViewLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE); 2624eb89fcf1decf9044f53330ea4bb689d25d2328b1Ian Lake } 2625c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE); 26260adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 26270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchPause(); 26280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 262920735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = STARTED; 26300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 26310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onPause(); 26320adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 26330adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 26340adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onPause()"); 26350adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 26360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 26370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 2638cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn void performStop() { 2639c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP); 26400adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 26410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchStop(); 26420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 264317d9d287fd6d180c6c48d62305ae4d7265056410Ian Lake mState = ACTIVITY_CREATED; 26440adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 2645cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn onStop(); 26460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 26470adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 26480adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onStop()"); 26490adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2650681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn } 2651681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn 26529c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn void performDestroyView() { 26530adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 26540adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchDestroyView(); 26550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 265620735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = CREATED; 26570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 26589c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn onDestroyView(); 26590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 26600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 26610adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onDestroyView()"); 26620adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 2663afe28d91550483f9b7a82076a507151b4defd9baIan Lake // Handles the detach/reattach case where the view hierarchy 2664afe28d91550483f9b7a82076a507151b4defd9baIan Lake // is destroyed and recreated and an additional call to 2665afe28d91550483f9b7a82076a507151b4defd9baIan Lake // onLoadFinished may be needed to ensure the new view 2666afe28d91550483f9b7a82076a507151b4defd9baIan Lake // hierarchy is populated from data from the Loaders 2667afe28d91550483f9b7a82076a507151b4defd9baIan Lake LoaderManager.getInstance(this).markForRedelivery(); 266837149f137aad1b2ec06df63807cef6713da3ca2fAdam Powell mPerformedCreateView = false; 26699c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn } 26700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn 26710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn void performDestroy() { 2672c2986284e6cbb4fd73b5db0145bc01ca83fab59dSergey Vasilinets mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY); 26730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (mChildFragmentManager != null) { 26740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mChildFragmentManager.dispatchDestroy(); 26750adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 267620735a45289fdad3d5d31228992e0dccd3d5dd4fAdam Powell mState = INITIALIZING; 26770adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn mCalled = false; 2678e97d1f2defa08e9bff9d39d6157981e30407e90aGeorge Mount mIsCreated = false; 26790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn onDestroy(); 26800adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn if (!mCalled) { 26810adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn throw new SuperNotCalledException("Fragment " + this 26820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn + " did not call through to super.onDestroy()"); 26830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 26844706c089880423ee5929d4635c6dfc5c3151b20fGeorge Mount mChildFragmentManager = null; 26850adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn } 26869375145b63d854c64aad99e6e50c5b7e5ba32b95Adam Powell 2687916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell void performDetach() { 2688916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell mCalled = false; 2689916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell onDetach(); 26908b60e88655f6d4191e55b1dd8706e4ae2ae21b04George Mount mLayoutInflater = null; 2691916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell if (!mCalled) { 2692916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell throw new SuperNotCalledException("Fragment " + this 2693916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell + " did not call through to super.onDetach()"); 2694916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell } 2695916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell 2696916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell // Destroy the child FragmentManager if we still have it here. 2697916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell // We won't unless we're retaining our instance and if we do, 2698916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell // our child FragmentManager instance state will have already been saved. 2699916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell if (mChildFragmentManager != null) { 2700916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell if (!mRetaining) { 2701916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell throw new IllegalStateException("Child FragmentManager of " + this + " was not " 2702916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell + " destroyed and this fragment is not retaining instance"); 2703916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell } 2704916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell mChildFragmentManager.dispatchDestroy(); 2705916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell mChildFragmentManager = null; 2706916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell } 2707916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell } 2708916455675ddb34d0eb848b2355550268d82c3ce7Adam Powell 2709990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setOnStartEnterTransitionListener(OnStartEnterTransitionListener listener) { 2710990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo(); 2711990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (listener == mAnimationInfo.mStartEnterTransitionListener) { 2712990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return; 2713990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2714990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (listener != null && mAnimationInfo.mStartEnterTransitionListener != null) { 2715990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount throw new IllegalStateException("Trying to set a replacement " 2716990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount + "startPostponedEnterTransition on " + this); 2717990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2718990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo.mEnterTransitionPostponed) { 2719990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mStartEnterTransitionListener = listener; 2720990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2721990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (listener != null) { 2722990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount listener.startListening(); 2723990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2724990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2725990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2726990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private AnimationInfo ensureAnimationInfo() { 2727990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2728990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo = new AnimationInfo(); 2729990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2730990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo; 2731990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2732990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2733990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int getNextAnim() { 2734990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2735990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return 0; 2736990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2737990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mNextAnim; 2738990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2739990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2740990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setNextAnim(int animResourceId) { 2741990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null && animResourceId == 0) { 2742990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return; // no change! 2743990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2744990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mNextAnim = animResourceId; 2745990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2746990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2747990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int getNextTransition() { 2748990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2749990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return 0; 2750990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2751990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mNextTransition; 2752990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2753990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2754990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setNextTransition(int nextTransition, int nextTransitionStyle) { 2755990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null && nextTransition == 0 && nextTransitionStyle == 0) { 2756990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return; // no change! 2757990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2758990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo(); 2759990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mNextTransition = nextTransition; 2760990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount mAnimationInfo.mNextTransitionStyle = nextTransitionStyle; 2761990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2762990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2763990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int getNextTransitionStyle() { 2764990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2765990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return 0; 2766990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2767990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mNextTransitionStyle; 2768990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2769990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2770990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount SharedElementCallback getEnterTransitionCallback() { 2771990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2772990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2773990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2774990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mEnterTransitionCallback; 2775990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2776990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2777990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount SharedElementCallback getExitTransitionCallback() { 2778990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2779990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2780990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2781990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mExitTransitionCallback; 2782990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2783990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2784990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount View getAnimatingAway() { 2785990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2786990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return null; 2787990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2788990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mAnimatingAway; 2789990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2790990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2791990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setAnimatingAway(View view) { 2792990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mAnimatingAway = view; 2793990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2794990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 279515e593ea3575512d7072240d1db9d74fad8749a3George Mount void setAnimator(Animator animator) { 279615e593ea3575512d7072240d1db9d74fad8749a3George Mount ensureAnimationInfo().mAnimator = animator; 279715e593ea3575512d7072240d1db9d74fad8749a3George Mount } 279815e593ea3575512d7072240d1db9d74fad8749a3George Mount 279915e593ea3575512d7072240d1db9d74fad8749a3George Mount Animator getAnimator() { 280015e593ea3575512d7072240d1db9d74fad8749a3George Mount if (mAnimationInfo == null) { 280115e593ea3575512d7072240d1db9d74fad8749a3George Mount return null; 280215e593ea3575512d7072240d1db9d74fad8749a3George Mount } 280315e593ea3575512d7072240d1db9d74fad8749a3George Mount return mAnimationInfo.mAnimator; 280415e593ea3575512d7072240d1db9d74fad8749a3George Mount } 280515e593ea3575512d7072240d1db9d74fad8749a3George Mount 2806990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int getStateAfterAnimating() { 2807990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2808990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return 0; 2809990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2810990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mStateAfterAnimating; 2811990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2812990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2813990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void setStateAfterAnimating(int state) { 2814990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount ensureAnimationInfo().mStateAfterAnimating = state; 2815990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2816990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2817990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount boolean isPostponed() { 2818990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount if (mAnimationInfo == null) { 2819990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return false; 2820990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2821990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount return mAnimationInfo.mEnterTransitionPostponed; 2822990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2823990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2824667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount boolean isHideReplaced() { 2825667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount if (mAnimationInfo == null) { 2826667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount return false; 2827667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount } 2828667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount return mAnimationInfo.mIsHideReplaced; 2829667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount } 2830667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount 2831667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount void setHideReplaced(boolean replaced) { 2832667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount ensureAnimationInfo().mIsHideReplaced = replaced; 2833667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount } 2834667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount 2835990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2836990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Used internally to be notified when {@link #startPostponedEnterTransition()} has 2837990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * been called. This listener will only be called once and then be removed from the 2838990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * listeners. 2839990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2840990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount interface OnStartEnterTransitionListener { 2841990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void onStartEnterTransition(); 2842990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount void startListening(); 2843990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2844990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2845990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount /** 2846990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * Contains all the animation and transition information for a fragment. This will only 2847990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount * be instantiated for Fragments that have Views. 2848990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount */ 2849990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount static class AnimationInfo { 2850990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // Non-null if the fragment's view hierarchy is currently animating away, 2851990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // meaning we need to wait a bit on completely destroying it. This is the 2852990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // view that is animating. 2853990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount View mAnimatingAway; 2854990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 285515e593ea3575512d7072240d1db9d74fad8749a3George Mount // Non-null if the fragment's view hierarchy is currently animating away with an 285615e593ea3575512d7072240d1db9d74fad8749a3George Mount // animator instead of an animation. 285715e593ea3575512d7072240d1db9d74fad8749a3George Mount Animator mAnimator; 285815e593ea3575512d7072240d1db9d74fad8749a3George Mount 2859990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // If mAnimatingAway != null, this is the state we should move to once the 2860990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // animation is done. 2861990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int mStateAfterAnimating; 2862990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2863990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // If app has requested a specific animation, this is the one to use. 2864990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int mNextAnim; 2865990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2866990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // If app has requested a specific transition, this is the one to use. 2867990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int mNextTransition; 2868990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2869990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // If app has requested a specific transition style, this is the one to use. 2870990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount int mNextTransitionStyle; 2871990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2872990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mEnterTransition = null; 2873990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mReturnTransition = USE_DEFAULT_TRANSITION; 2874990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mExitTransition = null; 2875990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mReenterTransition = USE_DEFAULT_TRANSITION; 2876990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mSharedElementEnterTransition = null; 2877990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Object mSharedElementReturnTransition = USE_DEFAULT_TRANSITION; 2878990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Boolean mAllowReturnTransitionOverlap; 2879990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount private Boolean mAllowEnterTransitionOverlap; 2880990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2881990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount SharedElementCallback mEnterTransitionCallback = null; 2882990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount SharedElementCallback mExitTransitionCallback = null; 2883990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2884990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // True when postponeEnterTransition has been called and startPostponeEnterTransition 2885990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // hasn't been called yet. 2886990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount boolean mEnterTransitionPostponed; 2887990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2888990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // Listener to wait for startPostponeEnterTransition. After being called, it will 2889990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount // be set to null 2890990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount OnStartEnterTransitionListener mStartEnterTransitionListener; 2891990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount 2892667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount // True if the View was hidden, but the transition is handling the hide 2893667ec4150c78bf295b3db1fa4d546def9ade9d20George Mount boolean mIsHideReplaced; 2894990e6fc0326f5948736650c0cb71b6002d443c9cGeorge Mount } 2895cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn} 2896