Fragment.java revision 2ab15df66963610bc02cb30e9a459f2b49c2ccfa
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.support.v4.app; 18 19import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP; 20 21import android.app.Activity; 22import android.content.ComponentCallbacks; 23import android.content.Context; 24import android.content.Intent; 25import android.content.IntentSender; 26import android.content.res.Configuration; 27import android.content.res.Resources; 28import android.os.Bundle; 29import android.os.Looper; 30import android.os.Parcel; 31import android.os.Parcelable; 32import android.support.annotation.CallSuper; 33import android.support.annotation.NonNull; 34import android.support.annotation.Nullable; 35import android.support.annotation.RestrictTo; 36import android.support.annotation.StringRes; 37import android.support.v4.util.DebugUtils; 38import android.support.v4.util.SimpleArrayMap; 39import android.support.v4.view.LayoutInflaterCompat; 40import android.util.AttributeSet; 41import android.util.Log; 42import android.util.SparseArray; 43import android.view.ContextMenu; 44import android.view.ContextMenu.ContextMenuInfo; 45import android.view.LayoutInflater; 46import android.view.Menu; 47import android.view.MenuInflater; 48import android.view.MenuItem; 49import android.view.View; 50import android.view.View.OnCreateContextMenuListener; 51import android.view.ViewGroup; 52import android.view.animation.Animation; 53import android.widget.AdapterView; 54 55import java.io.FileDescriptor; 56import java.io.PrintWriter; 57 58final class FragmentState implements Parcelable { 59 final String mClassName; 60 final int mIndex; 61 final boolean mFromLayout; 62 final int mFragmentId; 63 final int mContainerId; 64 final String mTag; 65 final boolean mRetainInstance; 66 final boolean mDetached; 67 final Bundle mArguments; 68 final boolean mHidden; 69 70 Bundle mSavedFragmentState; 71 72 Fragment mInstance; 73 74 public FragmentState(Fragment frag) { 75 mClassName = frag.getClass().getName(); 76 mIndex = frag.mIndex; 77 mFromLayout = frag.mFromLayout; 78 mFragmentId = frag.mFragmentId; 79 mContainerId = frag.mContainerId; 80 mTag = frag.mTag; 81 mRetainInstance = frag.mRetainInstance; 82 mDetached = frag.mDetached; 83 mArguments = frag.mArguments; 84 mHidden = frag.mHidden; 85 } 86 87 public FragmentState(Parcel in) { 88 mClassName = in.readString(); 89 mIndex = in.readInt(); 90 mFromLayout = in.readInt() != 0; 91 mFragmentId = in.readInt(); 92 mContainerId = in.readInt(); 93 mTag = in.readString(); 94 mRetainInstance = in.readInt() != 0; 95 mDetached = in.readInt() != 0; 96 mArguments = in.readBundle(); 97 mHidden = in.readInt() != 0; 98 mSavedFragmentState = in.readBundle(); 99 } 100 101 public Fragment instantiate(FragmentHostCallback host, FragmentContainer container, 102 Fragment parent, FragmentManagerNonConfig childNonConfig) { 103 if (mInstance == null) { 104 final Context context = host.getContext(); 105 if (mArguments != null) { 106 mArguments.setClassLoader(context.getClassLoader()); 107 } 108 109 if (container != null) { 110 mInstance = container.instantiate(context, mClassName, mArguments); 111 } else { 112 mInstance = Fragment.instantiate(context, mClassName, mArguments); 113 } 114 115 if (mSavedFragmentState != null) { 116 mSavedFragmentState.setClassLoader(context.getClassLoader()); 117 mInstance.mSavedFragmentState = mSavedFragmentState; 118 } 119 mInstance.setIndex(mIndex, parent); 120 mInstance.mFromLayout = mFromLayout; 121 mInstance.mRestored = true; 122 mInstance.mFragmentId = mFragmentId; 123 mInstance.mContainerId = mContainerId; 124 mInstance.mTag = mTag; 125 mInstance.mRetainInstance = mRetainInstance; 126 mInstance.mDetached = mDetached; 127 mInstance.mHidden = mHidden; 128 mInstance.mFragmentManager = host.mFragmentManager; 129 130 if (FragmentManagerImpl.DEBUG) Log.v(FragmentManagerImpl.TAG, 131 "Instantiated fragment " + mInstance); 132 } 133 mInstance.mChildNonConfig = childNonConfig; 134 return mInstance; 135 } 136 137 @Override 138 public int describeContents() { 139 return 0; 140 } 141 142 @Override 143 public void writeToParcel(Parcel dest, int flags) { 144 dest.writeString(mClassName); 145 dest.writeInt(mIndex); 146 dest.writeInt(mFromLayout ? 1 : 0); 147 dest.writeInt(mFragmentId); 148 dest.writeInt(mContainerId); 149 dest.writeString(mTag); 150 dest.writeInt(mRetainInstance ? 1 : 0); 151 dest.writeInt(mDetached ? 1 : 0); 152 dest.writeBundle(mArguments); 153 dest.writeInt(mHidden? 1 : 0); 154 dest.writeBundle(mSavedFragmentState); 155 } 156 157 public static final Parcelable.Creator<FragmentState> CREATOR 158 = new Parcelable.Creator<FragmentState>() { 159 @Override 160 public FragmentState createFromParcel(Parcel in) { 161 return new FragmentState(in); 162 } 163 164 @Override 165 public FragmentState[] newArray(int size) { 166 return new FragmentState[size]; 167 } 168 }; 169} 170 171/** 172 * Static library support version of the framework's {@link android.app.Fragment}. 173 * Used to write apps that run on platforms prior to Android 3.0. When running 174 * on Android 3.0 or above, this implementation is still used; it does not try 175 * to switch to the framework's implementation. See the framework {@link android.app.Fragment} 176 * documentation for a class overview. 177 * 178 * <p>The main differences when using this support version instead of the framework version are: 179 * <ul> 180 * <li>Your activity must extend {@link FragmentActivity} 181 * <li>You must call {@link FragmentActivity#getSupportFragmentManager} to get the 182 * {@link FragmentManager} 183 * </ul> 184 * 185 */ 186public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener { 187 private static final SimpleArrayMap<String, Class<?>> sClassMap = 188 new SimpleArrayMap<String, Class<?>>(); 189 190 static final Object USE_DEFAULT_TRANSITION = new Object(); 191 192 static final int INITIALIZING = 0; // Not yet created. 193 static final int CREATED = 1; // Created. 194 static final int ACTIVITY_CREATED = 2; // The activity has finished its creation. 195 static final int STOPPED = 3; // Fully created, not started. 196 static final int STARTED = 4; // Created and started, not resumed. 197 static final int RESUMED = 5; // Created started and resumed. 198 199 int mState = INITIALIZING; 200 201 // When instantiated from saved state, this is the saved state. 202 Bundle mSavedFragmentState; 203 SparseArray<Parcelable> mSavedViewState; 204 205 // Index into active fragment array. 206 int mIndex = -1; 207 208 // Internal unique name for this fragment; 209 String mWho; 210 211 // Construction arguments; 212 Bundle mArguments; 213 214 // Target fragment. 215 Fragment mTarget; 216 217 // For use when retaining a fragment: this is the index of the last mTarget. 218 int mTargetIndex = -1; 219 220 // Target request code. 221 int mTargetRequestCode; 222 223 // True if the fragment is in the list of added fragments. 224 boolean mAdded; 225 226 // If set this fragment is being removed from its activity. 227 boolean mRemoving; 228 229 // Set to true if this fragment was instantiated from a layout file. 230 boolean mFromLayout; 231 232 // Set to true when the view has actually been inflated in its layout. 233 boolean mInLayout; 234 235 // True if this fragment has been restored from previously saved state. 236 boolean mRestored; 237 238 // True if performCreateView has been called and a matching call to performDestroyView 239 // has not yet happened. 240 boolean mPerformedCreateView; 241 242 // Number of active back stack entries this fragment is in. 243 int mBackStackNesting; 244 245 // The fragment manager we are associated with. Set as soon as the 246 // fragment is used in a transaction; cleared after it has been removed 247 // from all transactions. 248 FragmentManagerImpl mFragmentManager; 249 250 // Host this fragment is attached to. 251 FragmentHostCallback mHost; 252 253 // Private fragment manager for child fragments inside of this one. 254 FragmentManagerImpl mChildFragmentManager; 255 256 // For use when restoring fragment state and descendant fragments are retained. 257 // This state is set by FragmentState.instantiate and cleared in onCreate. 258 FragmentManagerNonConfig mChildNonConfig; 259 260 // If this Fragment is contained in another Fragment, this is that container. 261 Fragment mParentFragment; 262 263 // The optional identifier for this fragment -- either the container ID if it 264 // was dynamically added to the view hierarchy, or the ID supplied in 265 // layout. 266 int mFragmentId; 267 268 // When a fragment is being dynamically added to the view hierarchy, this 269 // is the identifier of the parent container it is being added to. 270 int mContainerId; 271 272 // The optional named tag for this fragment -- usually used to find 273 // fragments that are not part of the layout. 274 String mTag; 275 276 // Set to true when the app has requested that this fragment be hidden 277 // from the user. 278 boolean mHidden; 279 280 // Set to true when the app has requested that this fragment be deactivated. 281 boolean mDetached; 282 283 // If set this fragment would like its instance retained across 284 // configuration changes. 285 boolean mRetainInstance; 286 287 // If set this fragment is being retained across the current config change. 288 boolean mRetaining; 289 290 // If set this fragment has menu items to contribute. 291 boolean mHasMenu; 292 293 // Set to true to allow the fragment's menu to be shown. 294 boolean mMenuVisible = true; 295 296 // Used to verify that subclasses call through to super class. 297 boolean mCalled; 298 299 // The parent container of the fragment after dynamically added to UI. 300 ViewGroup mContainer; 301 302 // The View generated for this fragment. 303 View mView; 304 305 // The real inner view that will save/restore state. 306 View mInnerView; 307 308 // Whether this fragment should defer starting until after other fragments 309 // have been started and their loaders are finished. 310 boolean mDeferStart; 311 312 // Hint provided by the app that this fragment is currently visible to the user. 313 boolean mUserVisibleHint = true; 314 315 LoaderManagerImpl mLoaderManager; 316 boolean mLoadersStarted; 317 boolean mCheckedForLoaderManager; 318 319 // The animation and transition information for the fragment. This will be null 320 // unless the elements are explicitly accessed and should remain null for Fragments 321 // without Views. 322 AnimationInfo mAnimationInfo; 323 324 // True if the View was added, and its animation has yet to be run. This could 325 // also indicate that the fragment view hasn't been made visible, even if there is no 326 // animation for this fragment. 327 boolean mIsNewlyAdded; 328 329 // True if mHidden has been changed and the animation should be scheduled. 330 boolean mHiddenChanged; 331 332 // The alpha of the view when the view was added and then postponed. If the value is less 333 // than zero, this means that the view's add was canceled and should not participate in 334 // removal animations. 335 float mPostponedAlpha; 336 337 /** 338 * State information that has been retrieved from a fragment instance 339 * through {@link FragmentManager#saveFragmentInstanceState(Fragment) 340 * FragmentManager.saveFragmentInstanceState}. 341 */ 342 public static class SavedState implements Parcelable { 343 final Bundle mState; 344 345 SavedState(Bundle state) { 346 mState = state; 347 } 348 349 SavedState(Parcel in, ClassLoader loader) { 350 mState = in.readBundle(); 351 if (loader != null && mState != null) { 352 mState.setClassLoader(loader); 353 } 354 } 355 356 @Override 357 public int describeContents() { 358 return 0; 359 } 360 361 @Override 362 public void writeToParcel(Parcel dest, int flags) { 363 dest.writeBundle(mState); 364 } 365 366 public static final Parcelable.Creator<SavedState> CREATOR 367 = new Parcelable.Creator<SavedState>() { 368 @Override 369 public SavedState createFromParcel(Parcel in) { 370 return new SavedState(in, null); 371 } 372 373 @Override 374 public SavedState[] newArray(int size) { 375 return new SavedState[size]; 376 } 377 }; 378 } 379 380 /** 381 * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when 382 * there is an instantiation failure. 383 */ 384 static public class InstantiationException extends RuntimeException { 385 public InstantiationException(String msg, Exception cause) { 386 super(msg, cause); 387 } 388 } 389 390 /** 391 * Default constructor. <strong>Every</strong> fragment must have an 392 * empty constructor, so it can be instantiated when restoring its 393 * activity's state. It is strongly recommended that subclasses do not 394 * have other constructors with parameters, since these constructors 395 * will not be called when the fragment is re-instantiated; instead, 396 * arguments can be supplied by the caller with {@link #setArguments} 397 * and later retrieved by the Fragment with {@link #getArguments}. 398 * 399 * <p>Applications should generally not implement a constructor. Prefer 400 * {@link #onAttach(Context)} instead. It is the first place application code can run where 401 * the fragment is ready to be used - the point where the fragment is actually associated with 402 * its context. Some applications may also want to implement {@link #onInflate} to retrieve 403 * attributes from a layout resource, although note this happens when the fragment is attached. 404 */ 405 public Fragment() { 406 } 407 408 /** 409 * Like {@link #instantiate(Context, String, Bundle)} but with a null 410 * argument Bundle. 411 */ 412 public static Fragment instantiate(Context context, String fname) { 413 return instantiate(context, fname, null); 414 } 415 416 /** 417 * Create a new instance of a Fragment with the given class name. This is 418 * the same as calling its empty constructor. 419 * 420 * @param context The calling context being used to instantiate the fragment. 421 * This is currently just used to get its ClassLoader. 422 * @param fname The class name of the fragment to instantiate. 423 * @param args Bundle of arguments to supply to the fragment, which it 424 * can retrieve with {@link #getArguments()}. May be null. 425 * @return Returns a new fragment instance. 426 * @throws InstantiationException If there is a failure in instantiating 427 * the given fragment class. This is a runtime exception; it is not 428 * normally expected to happen. 429 */ 430 public static Fragment instantiate(Context context, String fname, @Nullable Bundle args) { 431 try { 432 Class<?> clazz = sClassMap.get(fname); 433 if (clazz == null) { 434 // Class not found in the cache, see if it's real, and try to add it 435 clazz = context.getClassLoader().loadClass(fname); 436 sClassMap.put(fname, clazz); 437 } 438 Fragment f = (Fragment)clazz.newInstance(); 439 if (args != null) { 440 args.setClassLoader(f.getClass().getClassLoader()); 441 f.setArguments(args); 442 } 443 return f; 444 } catch (ClassNotFoundException e) { 445 throw new InstantiationException("Unable to instantiate fragment " + fname 446 + ": make sure class name exists, is public, and has an" 447 + " empty constructor that is public", e); 448 } catch (java.lang.InstantiationException e) { 449 throw new InstantiationException("Unable to instantiate fragment " + fname 450 + ": make sure class name exists, is public, and has an" 451 + " empty constructor that is public", e); 452 } catch (IllegalAccessException e) { 453 throw new InstantiationException("Unable to instantiate fragment " + fname 454 + ": make sure class name exists, is public, and has an" 455 + " empty constructor that is public", e); 456 } 457 } 458 459 /** 460 * Determine if the given fragment name is a support library fragment class. 461 * 462 * @param context Context used to determine the correct ClassLoader to use 463 * @param fname Class name of the fragment to test 464 * @return true if <code>fname</code> is <code>android.support.v4.app.Fragment</code> 465 * or a subclass, false otherwise. 466 */ 467 static boolean isSupportFragmentClass(Context context, String fname) { 468 try { 469 Class<?> clazz = sClassMap.get(fname); 470 if (clazz == null) { 471 // Class not found in the cache, see if it's real, and try to add it 472 clazz = context.getClassLoader().loadClass(fname); 473 sClassMap.put(fname, clazz); 474 } 475 return Fragment.class.isAssignableFrom(clazz); 476 } catch (ClassNotFoundException e) { 477 return false; 478 } 479 } 480 481 final void restoreViewState(Bundle savedInstanceState) { 482 if (mSavedViewState != null) { 483 mInnerView.restoreHierarchyState(mSavedViewState); 484 mSavedViewState = null; 485 } 486 mCalled = false; 487 onViewStateRestored(savedInstanceState); 488 if (!mCalled) { 489 throw new SuperNotCalledException("Fragment " + this 490 + " did not call through to super.onViewStateRestored()"); 491 } 492 } 493 494 final void setIndex(int index, Fragment parent) { 495 mIndex = index; 496 if (parent != null) { 497 mWho = parent.mWho + ":" + mIndex; 498 } else { 499 mWho = "android:fragment:" + mIndex; 500 } 501 } 502 503 final boolean isInBackStack() { 504 return mBackStackNesting > 0; 505 } 506 507 /** 508 * Subclasses can not override equals(). 509 */ 510 @Override final public boolean equals(Object o) { 511 return super.equals(o); 512 } 513 514 /** 515 * Subclasses can not override hashCode(). 516 */ 517 @Override final public int hashCode() { 518 return super.hashCode(); 519 } 520 521 @Override 522 public String toString() { 523 StringBuilder sb = new StringBuilder(128); 524 DebugUtils.buildShortClassTag(this, sb); 525 if (mIndex >= 0) { 526 sb.append(" #"); 527 sb.append(mIndex); 528 } 529 if (mFragmentId != 0) { 530 sb.append(" id=0x"); 531 sb.append(Integer.toHexString(mFragmentId)); 532 } 533 if (mTag != null) { 534 sb.append(" "); 535 sb.append(mTag); 536 } 537 sb.append('}'); 538 return sb.toString(); 539 } 540 541 /** 542 * Return the identifier this fragment is known by. This is either 543 * the android:id value supplied in a layout or the container view ID 544 * supplied when adding the fragment. 545 */ 546 final public int getId() { 547 return mFragmentId; 548 } 549 550 /** 551 * Get the tag name of the fragment, if specified. 552 */ 553 final public String getTag() { 554 return mTag; 555 } 556 557 /** 558 * Supply the construction arguments for this fragment. 559 * The arguments supplied here will be retained across fragment destroy and 560 * creation. 561 * <p>This method cannot be called if the fragment is added to a FragmentManager and 562 * if {@link #isStateSaved()} would return true.</p> 563 */ 564 public void setArguments(Bundle args) { 565 if (mIndex >= 0 && isStateSaved()) { 566 throw new IllegalStateException("Fragment already active and state has been saved"); 567 } 568 mArguments = args; 569 } 570 571 /** 572 * Return the arguments supplied when the fragment was instantiated, 573 * if any. 574 */ 575 final public Bundle getArguments() { 576 return mArguments; 577 } 578 579 /** 580 * Returns true if this fragment is added and its state has already been saved 581 * by its host. Any operations that would change saved state should not be performed 582 * if this method returns true, and some operations such as {@link #setArguments(Bundle)} 583 * will fail. 584 * 585 * @return true if this fragment's state has already been saved by its host 586 */ 587 public final boolean isStateSaved() { 588 if (mFragmentManager == null) { 589 return false; 590 } 591 return mFragmentManager.isStateSaved(); 592 } 593 594 /** 595 * Set the initial saved state that this Fragment should restore itself 596 * from when first being constructed, as returned by 597 * {@link FragmentManager#saveFragmentInstanceState(Fragment) 598 * FragmentManager.saveFragmentInstanceState}. 599 * 600 * @param state The state the fragment should be restored from. 601 */ 602 public void setInitialSavedState(SavedState state) { 603 if (mIndex >= 0) { 604 throw new IllegalStateException("Fragment already active"); 605 } 606 mSavedFragmentState = state != null && state.mState != null 607 ? state.mState : null; 608 } 609 610 /** 611 * Optional target for this fragment. This may be used, for example, 612 * if this fragment is being started by another, and when done wants to 613 * give a result back to the first. The target set here is retained 614 * across instances via {@link FragmentManager#putFragment 615 * FragmentManager.putFragment()}. 616 * 617 * @param fragment The fragment that is the target of this one. 618 * @param requestCode Optional request code, for convenience if you 619 * are going to call back with {@link #onActivityResult(int, int, Intent)}. 620 */ 621 public void setTargetFragment(Fragment fragment, int requestCode) { 622 // Don't allow a caller to set a target fragment in another FragmentManager, 623 // but there's a snag: people do set target fragments before fragments get added. 624 // We'll have the FragmentManager check that for validity when we move 625 // the fragments to a valid state. 626 final FragmentManager mine = getFragmentManager(); 627 final FragmentManager theirs = fragment != null ? fragment.getFragmentManager() : null; 628 if (mine != null && theirs != null && mine != theirs) { 629 throw new IllegalArgumentException("Fragment " + fragment 630 + " must share the same FragmentManager to be set as a target fragment"); 631 } 632 633 // Don't let someone create a cycle. 634 for (Fragment check = fragment; check != null; check = check.getTargetFragment()) { 635 if (check == this) { 636 throw new IllegalArgumentException("Setting " + fragment + " as the target of " 637 + this + " would create a target cycle"); 638 } 639 } 640 mTarget = fragment; 641 mTargetRequestCode = requestCode; 642 } 643 644 /** 645 * Return the target fragment set by {@link #setTargetFragment}. 646 */ 647 final public Fragment getTargetFragment() { 648 return mTarget; 649 } 650 651 /** 652 * Return the target request code set by {@link #setTargetFragment}. 653 */ 654 final public int getTargetRequestCode() { 655 return mTargetRequestCode; 656 } 657 658 /** 659 * Return the {@link Context} this fragment is currently associated with. 660 */ 661 public Context getContext() { 662 return mHost == null ? null : mHost.getContext(); 663 } 664 665 /** 666 * Return the {@link FragmentActivity} this fragment is currently associated with. 667 * May return {@code null} if the fragment is associated with a {@link Context} 668 * instead. 669 */ 670 final public FragmentActivity getActivity() { 671 return mHost == null ? null : (FragmentActivity) mHost.getActivity(); 672 } 673 674 /** 675 * Return the host object of this fragment. May return {@code null} if the fragment 676 * isn't currently being hosted. 677 */ 678 final public Object getHost() { 679 return mHost == null ? null : mHost.onGetHost(); 680 } 681 682 /** 683 * Return <code>getActivity().getResources()</code>. 684 */ 685 final public Resources getResources() { 686 if (mHost == null) { 687 throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 688 } 689 return mHost.getContext().getResources(); 690 } 691 692 /** 693 * Return a localized, styled CharSequence from the application's package's 694 * default string table. 695 * 696 * @param resId Resource id for the CharSequence text 697 */ 698 public final CharSequence getText(@StringRes int resId) { 699 return getResources().getText(resId); 700 } 701 702 /** 703 * Return a localized string from the application's package's 704 * default string table. 705 * 706 * @param resId Resource id for the string 707 */ 708 public final String getString(@StringRes int resId) { 709 return getResources().getString(resId); 710 } 711 712 /** 713 * Return a localized formatted string from the application's package's 714 * default string table, substituting the format arguments as defined in 715 * {@link java.util.Formatter} and {@link java.lang.String#format}. 716 * 717 * @param resId Resource id for the format string 718 * @param formatArgs The format arguments that will be used for substitution. 719 */ 720 721 public final String getString(@StringRes int resId, Object... formatArgs) { 722 return getResources().getString(resId, formatArgs); 723 } 724 725 /** 726 * Return the FragmentManager for interacting with fragments associated 727 * with this fragment's activity. Note that this will be non-null slightly 728 * before {@link #getActivity()}, during the time from when the fragment is 729 * placed in a {@link FragmentTransaction} until it is committed and 730 * attached to its activity. 731 * 732 * <p>If this Fragment is a child of another Fragment, the FragmentManager 733 * returned here will be the parent's {@link #getChildFragmentManager()}. 734 */ 735 final public FragmentManager getFragmentManager() { 736 return mFragmentManager; 737 } 738 739 /** 740 * Return a private FragmentManager for placing and managing Fragments 741 * inside of this Fragment. 742 */ 743 final public FragmentManager getChildFragmentManager() { 744 if (mChildFragmentManager == null) { 745 instantiateChildFragmentManager(); 746 if (mState >= RESUMED) { 747 mChildFragmentManager.dispatchResume(); 748 } else if (mState >= STARTED) { 749 mChildFragmentManager.dispatchStart(); 750 } else if (mState >= ACTIVITY_CREATED) { 751 mChildFragmentManager.dispatchActivityCreated(); 752 } else if (mState >= CREATED) { 753 mChildFragmentManager.dispatchCreate(); 754 } 755 } 756 return mChildFragmentManager; 757 } 758 759 /** 760 * Return this fragment's child FragmentManager one has been previously created, 761 * otherwise null. 762 */ 763 FragmentManager peekChildFragmentManager() { 764 return mChildFragmentManager; 765 } 766 767 /** 768 * Returns the parent Fragment containing this Fragment. If this Fragment 769 * is attached directly to an Activity, returns null. 770 */ 771 final public Fragment getParentFragment() { 772 return mParentFragment; 773 } 774 775 /** 776 * Return true if the fragment is currently added to its activity. 777 */ 778 final public boolean isAdded() { 779 return mHost != null && mAdded; 780 } 781 782 /** 783 * Return true if the fragment has been explicitly detached from the UI. 784 * That is, {@link FragmentTransaction#detach(Fragment) 785 * FragmentTransaction.detach(Fragment)} has been used on it. 786 */ 787 final public boolean isDetached() { 788 return mDetached; 789 } 790 791 /** 792 * Return true if this fragment is currently being removed from its 793 * activity. This is <em>not</em> whether its activity is finishing, but 794 * rather whether it is in the process of being removed from its activity. 795 */ 796 final public boolean isRemoving() { 797 return mRemoving; 798 } 799 800 /** 801 * Return true if the layout is included as part of an activity view 802 * hierarchy via the <fragment> tag. This will always be true when 803 * fragments are created through the <fragment> tag, <em>except</em> 804 * in the case where an old fragment is restored from a previous state and 805 * it does not appear in the layout of the current state. 806 */ 807 final public boolean isInLayout() { 808 return mInLayout; 809 } 810 811 /** 812 * Return true if the fragment is in the resumed state. This is true 813 * for the duration of {@link #onResume()} and {@link #onPause()} as well. 814 */ 815 final public boolean isResumed() { 816 return mState >= RESUMED; 817 } 818 819 /** 820 * Return true if the fragment is currently visible to the user. This means 821 * it: (1) has been added, (2) has its view attached to the window, and 822 * (3) is not hidden. 823 */ 824 final public boolean isVisible() { 825 return isAdded() && !isHidden() && mView != null 826 && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE; 827 } 828 829 /** 830 * Return true if the fragment has been hidden. By default fragments 831 * are shown. You can find out about changes to this state with 832 * {@link #onHiddenChanged}. Note that the hidden state is orthogonal 833 * to other states -- that is, to be visible to the user, a fragment 834 * must be both started and not hidden. 835 */ 836 final public boolean isHidden() { 837 return mHidden; 838 } 839 840 /** @hide */ 841 @RestrictTo(LIBRARY_GROUP) 842 final public boolean hasOptionsMenu() { 843 return mHasMenu; 844 } 845 846 /** @hide */ 847 @RestrictTo(LIBRARY_GROUP) 848 final public boolean isMenuVisible() { 849 return mMenuVisible; 850 } 851 852 /** 853 * Called when the hidden state (as returned by {@link #isHidden()} of 854 * the fragment has changed. Fragments start out not hidden; this will 855 * be called whenever the fragment changes state from that. 856 * @param hidden True if the fragment is now hidden, false otherwise. 857 */ 858 public void onHiddenChanged(boolean hidden) { 859 } 860 861 /** 862 * Control whether a fragment instance is retained across Activity 863 * re-creation (such as from a configuration change). This can only 864 * be used with fragments not in the back stack. If set, the fragment 865 * lifecycle will be slightly different when an activity is recreated: 866 * <ul> 867 * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still 868 * will be, because the fragment is being detached from its current activity). 869 * <li> {@link #onCreate(Bundle)} will not be called since the fragment 870 * is not being re-created. 871 * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b> 872 * still be called. 873 * </ul> 874 */ 875 public void setRetainInstance(boolean retain) { 876 mRetainInstance = retain; 877 } 878 879 final public boolean getRetainInstance() { 880 return mRetainInstance; 881 } 882 883 /** 884 * Report that this fragment would like to participate in populating 885 * the options menu by receiving a call to {@link #onCreateOptionsMenu} 886 * and related methods. 887 * 888 * @param hasMenu If true, the fragment has menu items to contribute. 889 */ 890 public void setHasOptionsMenu(boolean hasMenu) { 891 if (mHasMenu != hasMenu) { 892 mHasMenu = hasMenu; 893 if (isAdded() && !isHidden()) { 894 mHost.onSupportInvalidateOptionsMenu(); 895 } 896 } 897 } 898 899 /** 900 * Set a hint for whether this fragment's menu should be visible. This 901 * is useful if you know that a fragment has been placed in your view 902 * hierarchy so that the user can not currently seen it, so any menu items 903 * it has should also not be shown. 904 * 905 * @param menuVisible The default is true, meaning the fragment's menu will 906 * be shown as usual. If false, the user will not see the menu. 907 */ 908 public void setMenuVisibility(boolean menuVisible) { 909 if (mMenuVisible != menuVisible) { 910 mMenuVisible = menuVisible; 911 if (mHasMenu && isAdded() && !isHidden()) { 912 mHost.onSupportInvalidateOptionsMenu(); 913 } 914 } 915 } 916 917 /** 918 * Set a hint to the system about whether this fragment's UI is currently visible 919 * to the user. This hint defaults to true and is persistent across fragment instance 920 * state save and restore. 921 * 922 * <p>An app may set this to false to indicate that the fragment's UI is 923 * scrolled out of visibility or is otherwise not directly visible to the user. 924 * This may be used by the system to prioritize operations such as fragment lifecycle updates 925 * or loader ordering behavior.</p> 926 * 927 * <p><strong>Note:</strong> This method may be called outside of the fragment lifecycle. 928 * and thus has no ordering guarantees with regard to fragment lifecycle method calls.</p> 929 * 930 * @param isVisibleToUser true if this fragment's UI is currently visible to the user (default), 931 * false if it is not. 932 */ 933 public void setUserVisibleHint(boolean isVisibleToUser) { 934 if (!mUserVisibleHint && isVisibleToUser && mState < STARTED 935 && mFragmentManager != null && isAdded()) { 936 mFragmentManager.performPendingDeferredStart(this); 937 } 938 mUserVisibleHint = isVisibleToUser; 939 mDeferStart = mState < STARTED && !isVisibleToUser; 940 } 941 942 /** 943 * @return The current value of the user-visible hint on this fragment. 944 * @see #setUserVisibleHint(boolean) 945 */ 946 public boolean getUserVisibleHint() { 947 return mUserVisibleHint; 948 } 949 950 /** 951 * Return the LoaderManager for this fragment, creating it if needed. 952 */ 953 public LoaderManager getLoaderManager() { 954 if (mLoaderManager != null) { 955 return mLoaderManager; 956 } 957 if (mHost == null) { 958 throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 959 } 960 mCheckedForLoaderManager = true; 961 mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, true); 962 return mLoaderManager; 963 } 964 965 /** 966 * Call {@link Activity#startActivity(Intent)} from the fragment's 967 * containing Activity. 968 */ 969 public void startActivity(Intent intent) { 970 startActivity(intent, null); 971 } 972 973 /** 974 * Call {@link Activity#startActivity(Intent, Bundle)} from the fragment's 975 * containing Activity. 976 */ 977 public void startActivity(Intent intent, @Nullable Bundle options) { 978 if (mHost == null) { 979 throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 980 } 981 mHost.onStartActivityFromFragment(this /*fragment*/, intent, -1, options); 982 } 983 984 /** 985 * Call {@link Activity#startActivityForResult(Intent, int)} from the fragment's 986 * containing Activity. 987 */ 988 public void startActivityForResult(Intent intent, int requestCode) { 989 startActivityForResult(intent, requestCode, null); 990 } 991 992 /** 993 * Call {@link Activity#startActivityForResult(Intent, int, Bundle)} from the fragment's 994 * containing Activity. 995 */ 996 public void startActivityForResult(Intent intent, int requestCode, @Nullable Bundle options) { 997 if (mHost == null) { 998 throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 999 } 1000 mHost.onStartActivityFromFragment(this /*fragment*/, intent, requestCode, options); 1001 } 1002 1003 /** 1004 * Call {@link Activity#startIntentSenderForResult(IntentSender, int, Intent, int, int, int, 1005 * Bundle)} from the fragment's containing Activity. 1006 */ 1007 public void startIntentSenderForResult(IntentSender intent, int requestCode, 1008 @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, 1009 Bundle options) throws IntentSender.SendIntentException { 1010 if (mHost == null) { 1011 throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 1012 } 1013 mHost.onStartIntentSenderFromFragment(this, intent, requestCode, fillInIntent, flagsMask, 1014 flagsValues, extraFlags, options); 1015 } 1016 1017 /** 1018 * Receive the result from a previous call to 1019 * {@link #startActivityForResult(Intent, int)}. This follows the 1020 * related Activity API as described there in 1021 * {@link Activity#onActivityResult(int, int, Intent)}. 1022 * 1023 * @param requestCode The integer request code originally supplied to 1024 * startActivityForResult(), allowing you to identify who this 1025 * result came from. 1026 * @param resultCode The integer result code returned by the child activity 1027 * through its setResult(). 1028 * @param data An Intent, which can return result data to the caller 1029 * (various data can be attached to Intent "extras"). 1030 */ 1031 public void onActivityResult(int requestCode, int resultCode, Intent data) { 1032 } 1033 1034 /** 1035 * Requests permissions to be granted to this application. These permissions 1036 * must be requested in your manifest, they should not be granted to your app, 1037 * and they should have protection level {@link android.content.pm.PermissionInfo 1038 * #PROTECTION_DANGEROUS dangerous}, regardless whether they are declared by 1039 * the platform or a third-party app. 1040 * <p> 1041 * Normal permissions {@link android.content.pm.PermissionInfo#PROTECTION_NORMAL} 1042 * are granted at install time if requested in the manifest. Signature permissions 1043 * {@link android.content.pm.PermissionInfo#PROTECTION_SIGNATURE} are granted at 1044 * install time if requested in the manifest and the signature of your app matches 1045 * the signature of the app declaring the permissions. 1046 * </p> 1047 * <p> 1048 * If your app does not have the requested permissions the user will be presented 1049 * with UI for accepting them. After the user has accepted or rejected the 1050 * requested permissions you will receive a callback on {@link 1051 * #onRequestPermissionsResult(int, String[], int[])} reporting whether the 1052 * permissions were granted or not. 1053 * </p> 1054 * <p> 1055 * Note that requesting a permission does not guarantee it will be granted and 1056 * your app should be able to run without having this permission. 1057 * </p> 1058 * <p> 1059 * This method may start an activity allowing the user to choose which permissions 1060 * to grant and which to reject. Hence, you should be prepared that your activity 1061 * may be paused and resumed. Further, granting some permissions may require 1062 * a restart of you application. In such a case, the system will recreate the 1063 * activity stack before delivering the result to {@link 1064 * #onRequestPermissionsResult(int, String[], int[])}. 1065 * </p> 1066 * <p> 1067 * When checking whether you have a permission you should use {@link 1068 * android.content.Context#checkSelfPermission(String)}. 1069 * </p> 1070 * <p> 1071 * Calling this API for permissions already granted to your app would show UI 1072 * to the user to decided whether the app can still hold these permissions. This 1073 * can be useful if the way your app uses the data guarded by the permissions 1074 * changes significantly. 1075 * </p> 1076 * <p> 1077 * A sample permissions request looks like this: 1078 * </p> 1079 * <code><pre><p> 1080 * private void showContacts() { 1081 * if (getActivity().checkSelfPermission(Manifest.permission.READ_CONTACTS) 1082 * != PackageManager.PERMISSION_GRANTED) { 1083 * requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, 1084 * PERMISSIONS_REQUEST_READ_CONTACTS); 1085 * } else { 1086 * doShowContacts(); 1087 * } 1088 * } 1089 * 1090 * {@literal @}Override 1091 * public void onRequestPermissionsResult(int requestCode, String[] permissions, 1092 * int[] grantResults) { 1093 * if (requestCode == PERMISSIONS_REQUEST_READ_CONTACTS 1094 * && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 1095 * doShowContacts(); 1096 * } 1097 * } 1098 * </code></pre></p> 1099 * 1100 * @param permissions The requested permissions. 1101 * @param requestCode Application specific request code to match with a result 1102 * reported to {@link #onRequestPermissionsResult(int, String[], int[])}. 1103 * 1104 * @see #onRequestPermissionsResult(int, String[], int[]) 1105 * @see android.content.Context#checkSelfPermission(String) 1106 */ 1107 public final void requestPermissions(@NonNull String[] permissions, int requestCode) { 1108 if (mHost == null) { 1109 throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 1110 } 1111 mHost.onRequestPermissionsFromFragment(this, permissions, requestCode); 1112 } 1113 1114 /** 1115 * Callback for the result from requesting permissions. This method 1116 * is invoked for every call on {@link #requestPermissions(String[], int)}. 1117 * <p> 1118 * <strong>Note:</strong> It is possible that the permissions request interaction 1119 * with the user is interrupted. In this case you will receive empty permissions 1120 * and results arrays which should be treated as a cancellation. 1121 * </p> 1122 * 1123 * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}. 1124 * @param permissions The requested permissions. Never null. 1125 * @param grantResults The grant results for the corresponding permissions 1126 * which is either {@link android.content.pm.PackageManager#PERMISSION_GRANTED} 1127 * or {@link android.content.pm.PackageManager#PERMISSION_DENIED}. Never null. 1128 * 1129 * @see #requestPermissions(String[], int) 1130 */ 1131 public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, 1132 @NonNull int[] grantResults) { 1133 /* callback - do nothing */ 1134 } 1135 1136 /** 1137 * Gets whether you should show UI with rationale for requesting a permission. 1138 * You should do this only if you do not have the permission and the context in 1139 * which the permission is requested does not clearly communicate to the user 1140 * what would be the benefit from granting this permission. 1141 * <p> 1142 * For example, if you write a camera app, requesting the camera permission 1143 * would be expected by the user and no rationale for why it is requested is 1144 * needed. If however, the app needs location for tagging photos then a non-tech 1145 * savvy user may wonder how location is related to taking photos. In this case 1146 * you may choose to show UI with rationale of requesting this permission. 1147 * </p> 1148 * 1149 * @param permission A permission your app wants to request. 1150 * @return Whether you can show permission rationale UI. 1151 * 1152 * @see Context#checkSelfPermission(String) 1153 * @see #requestPermissions(String[], int) 1154 * @see #onRequestPermissionsResult(int, String[], int[]) 1155 */ 1156 public boolean shouldShowRequestPermissionRationale(@NonNull String permission) { 1157 if (mHost != null) { 1158 return mHost.onShouldShowRequestPermissionRationale(permission); 1159 } 1160 return false; 1161 } 1162 1163 /** 1164 * Hack so that DialogFragment can make its Dialog before creating 1165 * its views, and the view construction can use the dialog's context for 1166 * inflation. Maybe this should become a public API. Note sure. 1167 * @hide 1168 */ 1169 @RestrictTo(LIBRARY_GROUP) 1170 public LayoutInflater getLayoutInflater(Bundle savedInstanceState) { 1171 LayoutInflater result = mHost.onGetLayoutInflater(); 1172 getChildFragmentManager(); // Init if needed; use raw implementation below. 1173 LayoutInflaterCompat.setFactory(result, mChildFragmentManager.getLayoutInflaterFactory()); 1174 return result; 1175 } 1176 1177 /** 1178 * Called when a fragment is being created as part of a view layout 1179 * inflation, typically from setting the content view of an activity. This 1180 * may be called immediately after the fragment is created from a <fragment> 1181 * tag in a layout file. Note this is <em>before</em> the fragment's 1182 * {@link #onAttach(Activity)} has been called; all you should do here is 1183 * parse the attributes and save them away. 1184 * 1185 * <p>This is called every time the fragment is inflated, even if it is 1186 * being inflated into a new instance with saved state. It typically makes 1187 * sense to re-parse the parameters each time, to allow them to change with 1188 * different configurations.</p> 1189 * 1190 * <p>Here is a typical implementation of a fragment that can take parameters 1191 * both through attributes supplied here as well from {@link #getArguments()}:</p> 1192 * 1193 * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentArgumentsSupport.java 1194 * fragment} 1195 * 1196 * <p>Note that parsing the XML attributes uses a "styleable" resource. The 1197 * declaration for the styleable used here is:</p> 1198 * 1199 * {@sample frameworks/support/samples/Support4Demos/res/values/attrs.xml fragment_arguments} 1200 * 1201 * <p>The fragment can then be declared within its activity's content layout 1202 * through a tag like this:</p> 1203 * 1204 * {@sample frameworks/support/samples/Support4Demos/res/layout/fragment_arguments_support.xml from_attributes} 1205 * 1206 * <p>This fragment can also be created dynamically from arguments given 1207 * at runtime in the arguments Bundle; here is an example of doing so at 1208 * creation of the containing activity:</p> 1209 * 1210 * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentArgumentsSupport.java 1211 * create} 1212 * 1213 * @param context The Activity that is inflating this fragment. 1214 * @param attrs The attributes at the tag where the fragment is 1215 * being created. 1216 * @param savedInstanceState If the fragment is being re-created from 1217 * a previous saved state, this is the state. 1218 */ 1219 @CallSuper 1220 public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) { 1221 mCalled = true; 1222 final Activity hostActivity = mHost == null ? null : mHost.getActivity(); 1223 if (hostActivity != null) { 1224 mCalled = false; 1225 onInflate(hostActivity, attrs, savedInstanceState); 1226 } 1227 } 1228 1229 /** 1230 * Called when a fragment is being created as part of a view layout 1231 * inflation, typically from setting the content view of an activity. 1232 * 1233 * @deprecated See {@link #onInflate(Context, AttributeSet, Bundle)}. 1234 */ 1235 @Deprecated 1236 @CallSuper 1237 public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { 1238 mCalled = true; 1239 } 1240 1241 /** 1242 * Called when a fragment is attached as a child of this fragment. 1243 * 1244 * <p>This is called after the attached fragment's <code>onAttach</code> and before 1245 * the attached fragment's <code>onCreate</code> if the fragment has not yet had a previous 1246 * call to <code>onCreate</code>.</p> 1247 * 1248 * @param childFragment child fragment being attached 1249 */ 1250 public void onAttachFragment(Fragment childFragment) { 1251 } 1252 1253 /** 1254 * Called when a fragment is first attached to its context. 1255 * {@link #onCreate(Bundle)} will be called after this. 1256 */ 1257 @CallSuper 1258 public void onAttach(Context context) { 1259 mCalled = true; 1260 final Activity hostActivity = mHost == null ? null : mHost.getActivity(); 1261 if (hostActivity != null) { 1262 mCalled = false; 1263 onAttach(hostActivity); 1264 } 1265 } 1266 1267 /** 1268 * Called when a fragment is first attached to its activity. 1269 * {@link #onCreate(Bundle)} will be called after this. 1270 * 1271 * @deprecated See {@link #onAttach(Context)}. 1272 */ 1273 @Deprecated 1274 @CallSuper 1275 public void onAttach(Activity activity) { 1276 mCalled = true; 1277 } 1278 1279 /** 1280 * Called when a fragment loads an animation. 1281 */ 1282 public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { 1283 return null; 1284 } 1285 1286 /** 1287 * Called to do initial creation of a fragment. This is called after 1288 * {@link #onAttach(Activity)} and before 1289 * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 1290 * 1291 * <p>Note that this can be called while the fragment's activity is 1292 * still in the process of being created. As such, you can not rely 1293 * on things like the activity's content view hierarchy being initialized 1294 * at this point. If you want to do work once the activity itself is 1295 * created, see {@link #onActivityCreated(Bundle)}. 1296 * 1297 * <p>Any restored child fragments will be created before the base 1298 * <code>Fragment.onCreate</code> method returns.</p> 1299 * 1300 * @param savedInstanceState If the fragment is being re-created from 1301 * a previous saved state, this is the state. 1302 */ 1303 @CallSuper 1304 public void onCreate(@Nullable Bundle savedInstanceState) { 1305 mCalled = true; 1306 restoreChildFragmentState(savedInstanceState); 1307 if (mChildFragmentManager != null 1308 && !mChildFragmentManager.isStateAtLeast(Fragment.CREATED)) { 1309 mChildFragmentManager.dispatchCreate(); 1310 } 1311 } 1312 1313 /** 1314 * Restore the state of the child FragmentManager. Called by either 1315 * {@link #onCreate(Bundle)} for non-retained instance fragments or by 1316 * {@link FragmentManagerImpl#moveToState(Fragment, int, int, int, boolean)} 1317 * for retained instance fragments. 1318 * 1319 * <p><strong>Postcondition:</strong> if there were child fragments to restore, 1320 * the child FragmentManager will be instantiated and brought to the {@link #CREATED} state. 1321 * </p> 1322 * 1323 * @param savedInstanceState the savedInstanceState potentially containing fragment info 1324 */ 1325 void restoreChildFragmentState(@Nullable Bundle savedInstanceState) { 1326 if (savedInstanceState != null) { 1327 Parcelable p = savedInstanceState.getParcelable( 1328 FragmentActivity.FRAGMENTS_TAG); 1329 if (p != null) { 1330 if (mChildFragmentManager == null) { 1331 instantiateChildFragmentManager(); 1332 } 1333 mChildFragmentManager.restoreAllState(p, mChildNonConfig); 1334 mChildNonConfig = null; 1335 mChildFragmentManager.dispatchCreate(); 1336 } 1337 } 1338 } 1339 1340 /** 1341 * Called to have the fragment instantiate its user interface view. 1342 * This is optional, and non-graphical fragments can return null (which 1343 * is the default implementation). This will be called between 1344 * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}. 1345 * 1346 * <p>If you return a View from here, you will later be called in 1347 * {@link #onDestroyView} when the view is being released. 1348 * 1349 * @param inflater The LayoutInflater object that can be used to inflate 1350 * any views in the fragment, 1351 * @param container If non-null, this is the parent view that the fragment's 1352 * UI should be attached to. The fragment should not add the view itself, 1353 * but this can be used to generate the LayoutParams of the view. 1354 * @param savedInstanceState If non-null, this fragment is being re-constructed 1355 * from a previous saved state as given here. 1356 * 1357 * @return Return the View for the fragment's UI, or null. 1358 */ 1359 @Nullable 1360 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, 1361 @Nullable Bundle savedInstanceState) { 1362 return null; 1363 } 1364 1365 /** 1366 * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} 1367 * has returned, but before any saved state has been restored in to the view. 1368 * This gives subclasses a chance to initialize themselves once 1369 * they know their view hierarchy has been completely created. The fragment's 1370 * view hierarchy is not however attached to its parent at this point. 1371 * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 1372 * @param savedInstanceState If non-null, this fragment is being re-constructed 1373 * from a previous saved state as given here. 1374 */ 1375 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 1376 } 1377 1378 /** 1379 * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}), 1380 * if provided. 1381 * 1382 * @return The fragment's root view, or null if it has no layout. 1383 */ 1384 @Nullable 1385 public View getView() { 1386 return mView; 1387 } 1388 1389 /** 1390 * Called when the fragment's activity has been created and this 1391 * fragment's view hierarchy instantiated. It can be used to do final 1392 * initialization once these pieces are in place, such as retrieving 1393 * views or restoring state. It is also useful for fragments that use 1394 * {@link #setRetainInstance(boolean)} to retain their instance, 1395 * as this callback tells the fragment when it is fully associated with 1396 * the new activity instance. This is called after {@link #onCreateView} 1397 * and before {@link #onViewStateRestored(Bundle)}. 1398 * 1399 * @param savedInstanceState If the fragment is being re-created from 1400 * a previous saved state, this is the state. 1401 */ 1402 @CallSuper 1403 public void onActivityCreated(@Nullable Bundle savedInstanceState) { 1404 mCalled = true; 1405 } 1406 1407 /** 1408 * Called when all saved state has been restored into the view hierarchy 1409 * of the fragment. This can be used to do initialization based on saved 1410 * state that you are letting the view hierarchy track itself, such as 1411 * whether check box widgets are currently checked. This is called 1412 * after {@link #onActivityCreated(Bundle)} and before 1413 * {@link #onStart()}. 1414 * 1415 * @param savedInstanceState If the fragment is being re-created from 1416 * a previous saved state, this is the state. 1417 */ 1418 @CallSuper 1419 public void onViewStateRestored(@Nullable Bundle savedInstanceState) { 1420 mCalled = true; 1421 } 1422 1423 /** 1424 * Called when the Fragment is visible to the user. This is generally 1425 * tied to {@link Activity#onStart() Activity.onStart} of the containing 1426 * Activity's lifecycle. 1427 */ 1428 @CallSuper 1429 public void onStart() { 1430 mCalled = true; 1431 1432 if (!mLoadersStarted) { 1433 mLoadersStarted = true; 1434 if (!mCheckedForLoaderManager) { 1435 mCheckedForLoaderManager = true; 1436 mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false); 1437 } 1438 if (mLoaderManager != null) { 1439 mLoaderManager.doStart(); 1440 } 1441 } 1442 } 1443 1444 /** 1445 * Called when the fragment is visible to the user and actively running. 1446 * This is generally 1447 * tied to {@link Activity#onResume() Activity.onResume} of the containing 1448 * Activity's lifecycle. 1449 */ 1450 @CallSuper 1451 public void onResume() { 1452 mCalled = true; 1453 } 1454 1455 /** 1456 * Called to ask the fragment to save its current dynamic state, so it 1457 * can later be reconstructed in a new instance of its process is 1458 * restarted. If a new instance of the fragment later needs to be 1459 * created, the data you place in the Bundle here will be available 1460 * in the Bundle given to {@link #onCreate(Bundle)}, 1461 * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}, and 1462 * {@link #onActivityCreated(Bundle)}. 1463 * 1464 * <p>This corresponds to {@link Activity#onSaveInstanceState(Bundle) 1465 * Activity.onSaveInstanceState(Bundle)} and most of the discussion there 1466 * applies here as well. Note however: <em>this method may be called 1467 * at any time before {@link #onDestroy()}</em>. There are many situations 1468 * where a fragment may be mostly torn down (such as when placed on the 1469 * back stack with no UI showing), but its state will not be saved until 1470 * its owning activity actually needs to save its state. 1471 * 1472 * @param outState Bundle in which to place your saved state. 1473 */ 1474 public void onSaveInstanceState(Bundle outState) { 1475 } 1476 1477 /** 1478 * Called when the Fragment's activity changes from fullscreen mode to multi-window mode and 1479 * visa-versa. This is generally tied to {@link Activity#onMultiWindowModeChanged} of the 1480 * containing Activity. 1481 * 1482 * @param isInMultiWindowMode True if the activity is in multi-window mode. 1483 */ 1484 public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { 1485 } 1486 1487 /** 1488 * Called by the system when the activity changes to and from picture-in-picture mode. This is 1489 * generally tied to {@link Activity#onPictureInPictureModeChanged} of the containing Activity. 1490 * 1491 * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode. 1492 */ 1493 public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { 1494 } 1495 1496 @Override 1497 @CallSuper 1498 public void onConfigurationChanged(Configuration newConfig) { 1499 mCalled = true; 1500 } 1501 1502 /** 1503 * Called when the Fragment is no longer resumed. This is generally 1504 * tied to {@link Activity#onPause() Activity.onPause} of the containing 1505 * Activity's lifecycle. 1506 */ 1507 @CallSuper 1508 public void onPause() { 1509 mCalled = true; 1510 } 1511 1512 /** 1513 * Called when the Fragment is no longer started. This is generally 1514 * tied to {@link Activity#onStop() Activity.onStop} of the containing 1515 * Activity's lifecycle. 1516 */ 1517 @CallSuper 1518 public void onStop() { 1519 mCalled = true; 1520 } 1521 1522 @Override 1523 @CallSuper 1524 public void onLowMemory() { 1525 mCalled = true; 1526 } 1527 1528 /** 1529 * Called when the view previously created by {@link #onCreateView} has 1530 * been detached from the fragment. The next time the fragment needs 1531 * to be displayed, a new view will be created. This is called 1532 * after {@link #onStop()} and before {@link #onDestroy()}. It is called 1533 * <em>regardless</em> of whether {@link #onCreateView} returned a 1534 * non-null view. Internally it is called after the view's state has 1535 * been saved but before it has been removed from its parent. 1536 */ 1537 @CallSuper 1538 public void onDestroyView() { 1539 mCalled = true; 1540 } 1541 1542 /** 1543 * Called when the fragment is no longer in use. This is called 1544 * after {@link #onStop()} and before {@link #onDetach()}. 1545 */ 1546 @CallSuper 1547 public void onDestroy() { 1548 mCalled = true; 1549 //Log.v("foo", "onDestroy: mCheckedForLoaderManager=" + mCheckedForLoaderManager 1550 // + " mLoaderManager=" + mLoaderManager); 1551 if (!mCheckedForLoaderManager) { 1552 mCheckedForLoaderManager = true; 1553 mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false); 1554 } 1555 if (mLoaderManager != null) { 1556 mLoaderManager.doDestroy(); 1557 } 1558 } 1559 1560 /** 1561 * Called by the fragment manager once this fragment has been removed, 1562 * so that we don't have any left-over state if the application decides 1563 * to re-use the instance. This only clears state that the framework 1564 * internally manages, not things the application sets. 1565 */ 1566 void initState() { 1567 mIndex = -1; 1568 mWho = null; 1569 mAdded = false; 1570 mRemoving = false; 1571 mFromLayout = false; 1572 mInLayout = false; 1573 mRestored = false; 1574 mBackStackNesting = 0; 1575 mFragmentManager = null; 1576 mChildFragmentManager = null; 1577 mHost = null; 1578 mFragmentId = 0; 1579 mContainerId = 0; 1580 mTag = null; 1581 mHidden = false; 1582 mDetached = false; 1583 mRetaining = false; 1584 mLoaderManager = null; 1585 mLoadersStarted = false; 1586 mCheckedForLoaderManager = false; 1587 } 1588 1589 /** 1590 * Called when the fragment is no longer attached to its activity. This 1591 * is called after {@link #onDestroy()}. 1592 */ 1593 @CallSuper 1594 public void onDetach() { 1595 mCalled = true; 1596 } 1597 1598 /** 1599 * Initialize the contents of the Fragment host's standard options menu. You 1600 * should place your menu items in to <var>menu</var>. For this method 1601 * to be called, you must have first called {@link #setHasOptionsMenu}. See 1602 * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu} 1603 * for more information. 1604 * 1605 * @param menu The options menu in which you place your items. 1606 * 1607 * @see #setHasOptionsMenu 1608 * @see #onPrepareOptionsMenu 1609 * @see #onOptionsItemSelected 1610 */ 1611 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 1612 } 1613 1614 /** 1615 * Prepare the Fragment host's standard options menu to be displayed. This is 1616 * called right before the menu is shown, every time it is shown. You can 1617 * use this method to efficiently enable/disable items or otherwise 1618 * dynamically modify the contents. See 1619 * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu} 1620 * for more information. 1621 * 1622 * @param menu The options menu as last shown or first initialized by 1623 * onCreateOptionsMenu(). 1624 * 1625 * @see #setHasOptionsMenu 1626 * @see #onCreateOptionsMenu 1627 */ 1628 public void onPrepareOptionsMenu(Menu menu) { 1629 } 1630 1631 /** 1632 * Called when this fragment's option menu items are no longer being 1633 * included in the overall options menu. Receiving this call means that 1634 * the menu needed to be rebuilt, but this fragment's items were not 1635 * included in the newly built menu (its {@link #onCreateOptionsMenu(Menu, MenuInflater)} 1636 * was not called). 1637 */ 1638 public void onDestroyOptionsMenu() { 1639 } 1640 1641 /** 1642 * This hook is called whenever an item in your options menu is selected. 1643 * The default implementation simply returns false to have the normal 1644 * processing happen (calling the item's Runnable or sending a message to 1645 * its Handler as appropriate). You can use this method for any items 1646 * for which you would like to do processing without those other 1647 * facilities. 1648 * 1649 * <p>Derived classes should call through to the base class for it to 1650 * perform the default menu handling. 1651 * 1652 * @param item The menu item that was selected. 1653 * 1654 * @return boolean Return false to allow normal menu processing to 1655 * proceed, true to consume it here. 1656 * 1657 * @see #onCreateOptionsMenu 1658 */ 1659 public boolean onOptionsItemSelected(MenuItem item) { 1660 return false; 1661 } 1662 1663 /** 1664 * This hook is called whenever the options menu is being closed (either by the user canceling 1665 * the menu with the back/menu button, or when an item is selected). 1666 * 1667 * @param menu The options menu as last shown or first initialized by 1668 * onCreateOptionsMenu(). 1669 */ 1670 public void onOptionsMenuClosed(Menu menu) { 1671 } 1672 1673 /** 1674 * Called when a context menu for the {@code view} is about to be shown. 1675 * Unlike {@link #onCreateOptionsMenu}, this will be called every 1676 * time the context menu is about to be shown and should be populated for 1677 * the view (or item inside the view for {@link AdapterView} subclasses, 1678 * this can be found in the {@code menuInfo})). 1679 * <p> 1680 * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an 1681 * item has been selected. 1682 * <p> 1683 * The default implementation calls up to 1684 * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though 1685 * you can not call this implementation if you don't want that behavior. 1686 * <p> 1687 * It is not safe to hold onto the context menu after this method returns. 1688 * {@inheritDoc} 1689 */ 1690 @Override 1691 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 1692 getActivity().onCreateContextMenu(menu, v, menuInfo); 1693 } 1694 1695 /** 1696 * Registers a context menu to be shown for the given view (multiple views 1697 * can show the context menu). This method will set the 1698 * {@link OnCreateContextMenuListener} on the view to this fragment, so 1699 * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be 1700 * called when it is time to show the context menu. 1701 * 1702 * @see #unregisterForContextMenu(View) 1703 * @param view The view that should show a context menu. 1704 */ 1705 public void registerForContextMenu(View view) { 1706 view.setOnCreateContextMenuListener(this); 1707 } 1708 1709 /** 1710 * Prevents a context menu to be shown for the given view. This method will 1711 * remove the {@link OnCreateContextMenuListener} on the view. 1712 * 1713 * @see #registerForContextMenu(View) 1714 * @param view The view that should stop showing a context menu. 1715 */ 1716 public void unregisterForContextMenu(View view) { 1717 view.setOnCreateContextMenuListener(null); 1718 } 1719 1720 /** 1721 * This hook is called whenever an item in a context menu is selected. The 1722 * default implementation simply returns false to have the normal processing 1723 * happen (calling the item's Runnable or sending a message to its Handler 1724 * as appropriate). You can use this method for any items for which you 1725 * would like to do processing without those other facilities. 1726 * <p> 1727 * Use {@link MenuItem#getMenuInfo()} to get extra information set by the 1728 * View that added this menu item. 1729 * <p> 1730 * Derived classes should call through to the base class for it to perform 1731 * the default menu handling. 1732 * 1733 * @param item The context menu item that was selected. 1734 * @return boolean Return false to allow normal context menu processing to 1735 * proceed, true to consume it here. 1736 */ 1737 public boolean onContextItemSelected(MenuItem item) { 1738 return false; 1739 } 1740 1741 /** 1742 * When custom transitions are used with Fragments, the enter transition callback 1743 * is called when this Fragment is attached or detached when not popping the back stack. 1744 * 1745 * @param callback Used to manipulate the shared element transitions on this Fragment 1746 * when added not as a pop from the back stack. 1747 */ 1748 public void setEnterSharedElementCallback(SharedElementCallback callback) { 1749 ensureAnimationInfo().mEnterTransitionCallback = callback; 1750 } 1751 1752 /** 1753 * When custom transitions are used with Fragments, the exit transition callback 1754 * is called when this Fragment is attached or detached when popping the back stack. 1755 * 1756 * @param callback Used to manipulate the shared element transitions on this Fragment 1757 * when added as a pop from the back stack. 1758 */ 1759 public void setExitSharedElementCallback(SharedElementCallback callback) { 1760 ensureAnimationInfo().mExitTransitionCallback = callback; 1761 } 1762 1763 /** 1764 * Sets the Transition that will be used to move Views into the initial scene. The entering 1765 * Views will be those that are regular Views or ViewGroups that have 1766 * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 1767 * {@link android.transition.Visibility} as entering is governed by changing visibility from 1768 * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null, 1769 * entering Views will remain unaffected. 1770 * 1771 * @param transition The Transition to use to move Views into the initial Scene. 1772 */ 1773 public void setEnterTransition(Object transition) { 1774 ensureAnimationInfo().mEnterTransition = transition; 1775 } 1776 1777 /** 1778 * Returns the Transition that will be used to move Views into the initial scene. The entering 1779 * Views will be those that are regular Views or ViewGroups that have 1780 * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 1781 * {@link android.transition.Visibility} as entering is governed by changing visibility from 1782 * {@link View#INVISIBLE} to {@link View#VISIBLE}. 1783 * 1784 * @return the Transition to use to move Views into the initial Scene. 1785 */ 1786 public Object getEnterTransition() { 1787 if (mAnimationInfo == null) { 1788 return null; 1789 } 1790 return mAnimationInfo.mEnterTransition; 1791 } 1792 1793 /** 1794 * Sets the Transition that will be used to move Views out of the scene when the Fragment is 1795 * preparing to be removed, hidden, or detached because of popping the back stack. The exiting 1796 * Views will be those that are regular Views or ViewGroups that have 1797 * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 1798 * {@link android.transition.Visibility} as entering is governed by changing visibility from 1799 * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null, 1800 * entering Views will remain unaffected. If nothing is set, the default will be to 1801 * use the same value as set in {@link #setEnterTransition(Object)}. 1802 * 1803 * @param transition The Transition to use to move Views out of the Scene when the Fragment 1804 * is preparing to close. <code>transition</code> must be an 1805 * android.transition.Transition. 1806 */ 1807 public void setReturnTransition(Object transition) { 1808 ensureAnimationInfo().mReturnTransition = transition; 1809 } 1810 1811 /** 1812 * Returns the Transition that will be used to move Views out of the scene when the Fragment is 1813 * preparing to be removed, hidden, or detached because of popping the back stack. The exiting 1814 * Views will be those that are regular Views or ViewGroups that have 1815 * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 1816 * {@link android.transition.Visibility} as entering is governed by changing visibility from 1817 * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null, 1818 * entering Views will remain unaffected. 1819 * 1820 * @return the Transition to use to move Views out of the Scene when the Fragment 1821 * is preparing to close. 1822 */ 1823 public Object getReturnTransition() { 1824 if (mAnimationInfo == null) { 1825 return null; 1826 } 1827 return mAnimationInfo.mReturnTransition == USE_DEFAULT_TRANSITION ? getEnterTransition() 1828 : mAnimationInfo.mReturnTransition; 1829 } 1830 1831 /** 1832 * Sets the Transition that will be used to move Views out of the scene when the 1833 * fragment is removed, hidden, or detached when not popping the back stack. 1834 * The exiting Views will be those that are regular Views or ViewGroups that 1835 * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 1836 * {@link android.transition.Visibility} as exiting is governed by changing visibility 1837 * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will 1838 * remain unaffected. 1839 * 1840 * @param transition The Transition to use to move Views out of the Scene when the Fragment 1841 * is being closed not due to popping the back stack. <code>transition</code> 1842 * must be an android.transition.Transition. 1843 */ 1844 public void setExitTransition(Object transition) { 1845 ensureAnimationInfo().mExitTransition = transition; 1846 } 1847 1848 /** 1849 * Returns the Transition that will be used to move Views out of the scene when the 1850 * fragment is removed, hidden, or detached when not popping the back stack. 1851 * The exiting Views will be those that are regular Views or ViewGroups that 1852 * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend 1853 * {@link android.transition.Visibility} as exiting is governed by changing visibility 1854 * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will 1855 * remain unaffected. 1856 * 1857 * @return the Transition to use to move Views out of the Scene when the Fragment 1858 * is being closed not due to popping the back stack. 1859 */ 1860 public Object getExitTransition() { 1861 if (mAnimationInfo == null) { 1862 return null; 1863 } 1864 return mAnimationInfo.mExitTransition; 1865 } 1866 1867 /** 1868 * Sets the Transition that will be used to move Views in to the scene when returning due 1869 * to popping a back stack. The entering Views will be those that are regular Views 1870 * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions 1871 * will extend {@link android.transition.Visibility} as exiting is governed by changing 1872 * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, 1873 * the views will remain unaffected. If nothing is set, the default will be to use the same 1874 * transition as {@link #setExitTransition(Object)}. 1875 * 1876 * @param transition The Transition to use to move Views into the scene when reentering from a 1877 * previously-started Activity. <code>transition</code> 1878 * must be an android.transition.Transition. 1879 */ 1880 public void setReenterTransition(Object transition) { 1881 ensureAnimationInfo().mReenterTransition = transition; 1882 } 1883 1884 /** 1885 * Returns the Transition that will be used to move Views in to the scene when returning due 1886 * to popping a back stack. The entering Views will be those that are regular Views 1887 * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions 1888 * will extend {@link android.transition.Visibility} as exiting is governed by changing 1889 * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, 1890 * the views will remain unaffected. If nothing is set, the default will be to use the same 1891 * transition as {@link #setExitTransition(Object)}. 1892 * 1893 * @return the Transition to use to move Views into the scene when reentering from a 1894 * previously-started Activity. 1895 */ 1896 public Object getReenterTransition() { 1897 if (mAnimationInfo == null) { 1898 return null; 1899 } 1900 return mAnimationInfo.mReenterTransition == USE_DEFAULT_TRANSITION ? getExitTransition() 1901 : mAnimationInfo.mReenterTransition; 1902 } 1903 1904 /** 1905 * Sets the Transition that will be used for shared elements transferred into the content 1906 * Scene. Typical Transitions will affect size and location, such as 1907 * {@link android.transition.ChangeBounds}. A null 1908 * value will cause transferred shared elements to blink to the final position. 1909 * 1910 * @param transition The Transition to use for shared elements transferred into the content 1911 * Scene. <code>transition</code> must be an android.transition.Transition. 1912 */ 1913 public void setSharedElementEnterTransition(Object transition) { 1914 ensureAnimationInfo().mSharedElementEnterTransition = transition; 1915 } 1916 1917 /** 1918 * Returns the Transition that will be used for shared elements transferred into the content 1919 * Scene. Typical Transitions will affect size and location, such as 1920 * {@link android.transition.ChangeBounds}. A null 1921 * value will cause transferred shared elements to blink to the final position. 1922 * 1923 * @return The Transition to use for shared elements transferred into the content 1924 * Scene. 1925 */ 1926 public Object getSharedElementEnterTransition() { 1927 if (mAnimationInfo == null) { 1928 return null; 1929 } 1930 return mAnimationInfo.mSharedElementEnterTransition; 1931 } 1932 1933 /** 1934 * Sets the Transition that will be used for shared elements transferred back during a 1935 * pop of the back stack. This Transition acts in the leaving Fragment. 1936 * Typical Transitions will affect size and location, such as 1937 * {@link android.transition.ChangeBounds}. A null 1938 * value will cause transferred shared elements to blink to the final position. 1939 * If no value is set, the default will be to use the same value as 1940 * {@link #setSharedElementEnterTransition(Object)}. 1941 * 1942 * @param transition The Transition to use for shared elements transferred out of the content 1943 * Scene. <code>transition</code> must be an android.transition.Transition. 1944 */ 1945 public void setSharedElementReturnTransition(Object transition) { 1946 ensureAnimationInfo().mSharedElementReturnTransition = transition; 1947 } 1948 1949 /** 1950 * Return the Transition that will be used for shared elements transferred back during a 1951 * pop of the back stack. This Transition acts in the leaving Fragment. 1952 * Typical Transitions will affect size and location, such as 1953 * {@link android.transition.ChangeBounds}. A null 1954 * value will cause transferred shared elements to blink to the final position. 1955 * If no value is set, the default will be to use the same value as 1956 * {@link #setSharedElementEnterTransition(Object)}. 1957 * 1958 * @return The Transition to use for shared elements transferred out of the content 1959 * Scene. 1960 */ 1961 public Object getSharedElementReturnTransition() { 1962 if (mAnimationInfo == null) { 1963 return null; 1964 } 1965 return mAnimationInfo.mSharedElementReturnTransition == USE_DEFAULT_TRANSITION 1966 ? getSharedElementEnterTransition() 1967 : mAnimationInfo.mSharedElementReturnTransition; 1968 } 1969 1970 /** 1971 * Sets whether the the exit transition and enter transition overlap or not. 1972 * When true, the enter transition will start as soon as possible. When false, the 1973 * enter transition will wait until the exit transition completes before starting. 1974 * 1975 * @param allow true to start the enter transition when possible or false to 1976 * wait until the exiting transition completes. 1977 */ 1978 public void setAllowEnterTransitionOverlap(boolean allow) { 1979 ensureAnimationInfo().mAllowEnterTransitionOverlap = allow; 1980 } 1981 1982 /** 1983 * Returns whether the the exit transition and enter transition overlap or not. 1984 * When true, the enter transition will start as soon as possible. When false, the 1985 * enter transition will wait until the exit transition completes before starting. 1986 * 1987 * @return true when the enter transition should start as soon as possible or false to 1988 * when it should wait until the exiting transition completes. 1989 */ 1990 public boolean getAllowEnterTransitionOverlap() { 1991 return (mAnimationInfo == null || mAnimationInfo.mAllowEnterTransitionOverlap == null) 1992 ? true : mAnimationInfo.mAllowEnterTransitionOverlap; 1993 } 1994 1995 /** 1996 * Sets whether the the return transition and reenter transition overlap or not. 1997 * When true, the reenter transition will start as soon as possible. When false, the 1998 * reenter transition will wait until the return transition completes before starting. 1999 * 2000 * @param allow true to start the reenter transition when possible or false to wait until the 2001 * return transition completes. 2002 */ 2003 public void setAllowReturnTransitionOverlap(boolean allow) { 2004 ensureAnimationInfo().mAllowReturnTransitionOverlap = allow; 2005 } 2006 2007 /** 2008 * Returns whether the the return transition and reenter transition overlap or not. 2009 * When true, the reenter transition will start as soon as possible. When false, the 2010 * reenter transition will wait until the return transition completes before starting. 2011 * 2012 * @return true to start the reenter transition when possible or false to wait until the 2013 * return transition completes. 2014 */ 2015 public boolean getAllowReturnTransitionOverlap() { 2016 return (mAnimationInfo == null || mAnimationInfo.mAllowReturnTransitionOverlap == null) 2017 ? true : mAnimationInfo.mAllowReturnTransitionOverlap; 2018 } 2019 2020 /** 2021 * Postpone the entering Fragment transition until {@link #startPostponedEnterTransition()} 2022 * or {@link FragmentManager#executePendingTransactions()} has been called. 2023 * <p> 2024 * This method gives the Fragment the ability to delay Fragment animations 2025 * until all data is loaded. Until then, the added, shown, and 2026 * attached Fragments will be INVISIBLE and removed, hidden, and detached Fragments won't 2027 * be have their Views removed. The transaction runs when all postponed added Fragments in the 2028 * transaction have called {@link #startPostponedEnterTransition()}. 2029 * <p> 2030 * This method should be called before being added to the FragmentTransaction or 2031 * in {@link #onCreate(Bundle), {@link #onAttach(Context)}, or 2032 * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}}. 2033 * {@link #startPostponedEnterTransition()} must be called to allow the Fragment to 2034 * start the transitions. 2035 * <p> 2036 * When a FragmentTransaction is started that may affect a postponed FragmentTransaction, 2037 * based on which containers are in their operations, the postponed FragmentTransaction 2038 * will have its start triggered. The early triggering may result in faulty or nonexistent 2039 * animations in the postponed transaction. FragmentTransactions that operate only on 2040 * independent containers will not interfere with each other's postponement. 2041 * <p> 2042 * Calling postponeEnterTransition on Fragments with a null View will not postpone the 2043 * transition. Likewise, postponement only works if FragmentTransaction optimizations are 2044 * enabled. 2045 * 2046 * @see Activity#postponeEnterTransition() 2047 * @see FragmentTransaction#setAllowOptimization(boolean) 2048 */ 2049 public void postponeEnterTransition() { 2050 ensureAnimationInfo().mEnterTransitionPostponed = true; 2051 } 2052 2053 /** 2054 * Begin postponed transitions after {@link #postponeEnterTransition()} was called. 2055 * If postponeEnterTransition() was called, you must call startPostponedEnterTransition() 2056 * or {@link FragmentManager#executePendingTransactions()} to complete the FragmentTransaction. 2057 * If postponement was interrupted with {@link FragmentManager#executePendingTransactions()}, 2058 * before {@code startPostponedEnterTransition()}, animations may not run or may execute 2059 * improperly. 2060 * 2061 * @see Activity#startPostponedEnterTransition() 2062 */ 2063 public void startPostponedEnterTransition() { 2064 if (mFragmentManager == null || mFragmentManager.mHost == null) { 2065 ensureAnimationInfo().mEnterTransitionPostponed = false; 2066 } else if (Looper.myLooper() != mFragmentManager.mHost.getHandler().getLooper()) { 2067 mFragmentManager.mHost.getHandler().postAtFrontOfQueue(new Runnable() { 2068 @Override 2069 public void run() { 2070 callStartTransitionListener(); 2071 } 2072 }); 2073 } else { 2074 callStartTransitionListener(); 2075 } 2076 } 2077 2078 /** 2079 * Calls the start transition listener. This must be called on the UI thread. 2080 */ 2081 private void callStartTransitionListener() { 2082 final OnStartEnterTransitionListener listener; 2083 if (mAnimationInfo == null) { 2084 listener = null; 2085 } else { 2086 mAnimationInfo.mEnterTransitionPostponed = false; 2087 listener = mAnimationInfo.mStartEnterTransitionListener; 2088 mAnimationInfo.mStartEnterTransitionListener = null; 2089 } 2090 if (listener != null) { 2091 listener.onStartEnterTransition(); 2092 } 2093 } 2094 2095 /** 2096 * Print the Fragments's state into the given stream. 2097 * 2098 * @param prefix Text to print at the front of each line. 2099 * @param fd The raw file descriptor that the dump is being sent to. 2100 * @param writer The PrintWriter to which you should dump your state. This will be 2101 * closed for you after you return. 2102 * @param args additional arguments to the dump request. 2103 */ 2104 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { 2105 writer.print(prefix); writer.print("mFragmentId=#"); 2106 writer.print(Integer.toHexString(mFragmentId)); 2107 writer.print(" mContainerId=#"); 2108 writer.print(Integer.toHexString(mContainerId)); 2109 writer.print(" mTag="); writer.println(mTag); 2110 writer.print(prefix); writer.print("mState="); writer.print(mState); 2111 writer.print(" mIndex="); writer.print(mIndex); 2112 writer.print(" mWho="); writer.print(mWho); 2113 writer.print(" mBackStackNesting="); writer.println(mBackStackNesting); 2114 writer.print(prefix); writer.print("mAdded="); writer.print(mAdded); 2115 writer.print(" mRemoving="); writer.print(mRemoving); 2116 writer.print(" mFromLayout="); writer.print(mFromLayout); 2117 writer.print(" mInLayout="); writer.println(mInLayout); 2118 writer.print(prefix); writer.print("mHidden="); writer.print(mHidden); 2119 writer.print(" mDetached="); writer.print(mDetached); 2120 writer.print(" mMenuVisible="); writer.print(mMenuVisible); 2121 writer.print(" mHasMenu="); writer.println(mHasMenu); 2122 writer.print(prefix); writer.print("mRetainInstance="); writer.print(mRetainInstance); 2123 writer.print(" mRetaining="); writer.print(mRetaining); 2124 writer.print(" mUserVisibleHint="); writer.println(mUserVisibleHint); 2125 if (mFragmentManager != null) { 2126 writer.print(prefix); writer.print("mFragmentManager="); 2127 writer.println(mFragmentManager); 2128 } 2129 if (mHost != null) { 2130 writer.print(prefix); writer.print("mHost="); 2131 writer.println(mHost); 2132 } 2133 if (mParentFragment != null) { 2134 writer.print(prefix); writer.print("mParentFragment="); 2135 writer.println(mParentFragment); 2136 } 2137 if (mArguments != null) { 2138 writer.print(prefix); writer.print("mArguments="); writer.println(mArguments); 2139 } 2140 if (mSavedFragmentState != null) { 2141 writer.print(prefix); writer.print("mSavedFragmentState="); 2142 writer.println(mSavedFragmentState); 2143 } 2144 if (mSavedViewState != null) { 2145 writer.print(prefix); writer.print("mSavedViewState="); 2146 writer.println(mSavedViewState); 2147 } 2148 if (mTarget != null) { 2149 writer.print(prefix); writer.print("mTarget="); writer.print(mTarget); 2150 writer.print(" mTargetRequestCode="); 2151 writer.println(mTargetRequestCode); 2152 } 2153 if (getNextAnim() != 0) { 2154 writer.print(prefix); writer.print("mNextAnim="); writer.println(getNextAnim()); 2155 } 2156 if (mContainer != null) { 2157 writer.print(prefix); writer.print("mContainer="); writer.println(mContainer); 2158 } 2159 if (mView != null) { 2160 writer.print(prefix); writer.print("mView="); writer.println(mView); 2161 } 2162 if (mInnerView != null) { 2163 writer.print(prefix); writer.print("mInnerView="); writer.println(mView); 2164 } 2165 if (getAnimatingAway() != null) { 2166 writer.print(prefix); 2167 writer.print("mAnimatingAway="); 2168 writer.println(getAnimatingAway()); 2169 writer.print(prefix); 2170 writer.print("mStateAfterAnimating="); 2171 writer.println(getStateAfterAnimating()); 2172 } 2173 if (mLoaderManager != null) { 2174 writer.print(prefix); writer.println("Loader Manager:"); 2175 mLoaderManager.dump(prefix + " ", fd, writer, args); 2176 } 2177 if (mChildFragmentManager != null) { 2178 writer.print(prefix); writer.println("Child " + mChildFragmentManager + ":"); 2179 mChildFragmentManager.dump(prefix + " ", fd, writer, args); 2180 } 2181 } 2182 2183 Fragment findFragmentByWho(String who) { 2184 if (who.equals(mWho)) { 2185 return this; 2186 } 2187 if (mChildFragmentManager != null) { 2188 return mChildFragmentManager.findFragmentByWho(who); 2189 } 2190 return null; 2191 } 2192 2193 void instantiateChildFragmentManager() { 2194 if (mHost == null) { 2195 throw new IllegalStateException("Fragment has not been attached yet."); 2196 } 2197 mChildFragmentManager = new FragmentManagerImpl(); 2198 mChildFragmentManager.attachController(mHost, new FragmentContainer() { 2199 @Override 2200 @Nullable 2201 public View onFindViewById(int id) { 2202 if (mView == null) { 2203 throw new IllegalStateException("Fragment does not have a view"); 2204 } 2205 return mView.findViewById(id); 2206 } 2207 2208 @Override 2209 public boolean onHasView() { 2210 return (mView != null); 2211 } 2212 2213 @Override 2214 public Fragment instantiate(Context context, String className, Bundle arguments) { 2215 return mHost.instantiate(context, className, arguments); 2216 } 2217 }, this); 2218 } 2219 2220 void performCreate(Bundle savedInstanceState) { 2221 if (mChildFragmentManager != null) { 2222 mChildFragmentManager.noteStateNotSaved(); 2223 } 2224 mState = CREATED; 2225 mCalled = false; 2226 onCreate(savedInstanceState); 2227 if (!mCalled) { 2228 throw new SuperNotCalledException("Fragment " + this 2229 + " did not call through to super.onCreate()"); 2230 } 2231 } 2232 2233 View performCreateView(LayoutInflater inflater, ViewGroup container, 2234 Bundle savedInstanceState) { 2235 if (mChildFragmentManager != null) { 2236 mChildFragmentManager.noteStateNotSaved(); 2237 } 2238 mPerformedCreateView = true; 2239 return onCreateView(inflater, container, savedInstanceState); 2240 } 2241 2242 void performActivityCreated(Bundle savedInstanceState) { 2243 if (mChildFragmentManager != null) { 2244 mChildFragmentManager.noteStateNotSaved(); 2245 } 2246 mState = ACTIVITY_CREATED; 2247 mCalled = false; 2248 onActivityCreated(savedInstanceState); 2249 if (!mCalled) { 2250 throw new SuperNotCalledException("Fragment " + this 2251 + " did not call through to super.onActivityCreated()"); 2252 } 2253 if (mChildFragmentManager != null) { 2254 mChildFragmentManager.dispatchActivityCreated(); 2255 } 2256 } 2257 2258 void performStart() { 2259 if (mChildFragmentManager != null) { 2260 mChildFragmentManager.noteStateNotSaved(); 2261 mChildFragmentManager.execPendingActions(); 2262 } 2263 mState = STARTED; 2264 mCalled = false; 2265 onStart(); 2266 if (!mCalled) { 2267 throw new SuperNotCalledException("Fragment " + this 2268 + " did not call through to super.onStart()"); 2269 } 2270 if (mChildFragmentManager != null) { 2271 mChildFragmentManager.dispatchStart(); 2272 } 2273 if (mLoaderManager != null) { 2274 mLoaderManager.doReportStart(); 2275 } 2276 } 2277 2278 void performResume() { 2279 if (mChildFragmentManager != null) { 2280 mChildFragmentManager.noteStateNotSaved(); 2281 mChildFragmentManager.execPendingActions(); 2282 } 2283 mState = RESUMED; 2284 mCalled = false; 2285 onResume(); 2286 if (!mCalled) { 2287 throw new SuperNotCalledException("Fragment " + this 2288 + " did not call through to super.onResume()"); 2289 } 2290 if (mChildFragmentManager != null) { 2291 mChildFragmentManager.dispatchResume(); 2292 mChildFragmentManager.execPendingActions(); 2293 } 2294 } 2295 2296 void performMultiWindowModeChanged(boolean isInMultiWindowMode) { 2297 onMultiWindowModeChanged(isInMultiWindowMode); 2298 if (mChildFragmentManager != null) { 2299 mChildFragmentManager.dispatchMultiWindowModeChanged(isInMultiWindowMode); 2300 } 2301 } 2302 2303 void performPictureInPictureModeChanged(boolean isInPictureInPictureMode) { 2304 onPictureInPictureModeChanged(isInPictureInPictureMode); 2305 if (mChildFragmentManager != null) { 2306 mChildFragmentManager.dispatchPictureInPictureModeChanged(isInPictureInPictureMode); 2307 } 2308 } 2309 2310 void performConfigurationChanged(Configuration newConfig) { 2311 onConfigurationChanged(newConfig); 2312 if (mChildFragmentManager != null) { 2313 mChildFragmentManager.dispatchConfigurationChanged(newConfig); 2314 } 2315 } 2316 2317 void performLowMemory() { 2318 onLowMemory(); 2319 if (mChildFragmentManager != null) { 2320 mChildFragmentManager.dispatchLowMemory(); 2321 } 2322 } 2323 2324 /* 2325 void performTrimMemory(int level) { 2326 onTrimMemory(level); 2327 if (mChildFragmentManager != null) { 2328 mChildFragmentManager.dispatchTrimMemory(level); 2329 } 2330 } 2331 */ 2332 2333 boolean performCreateOptionsMenu(Menu menu, MenuInflater inflater) { 2334 boolean show = false; 2335 if (!mHidden) { 2336 if (mHasMenu && mMenuVisible) { 2337 show = true; 2338 onCreateOptionsMenu(menu, inflater); 2339 } 2340 if (mChildFragmentManager != null) { 2341 show |= mChildFragmentManager.dispatchCreateOptionsMenu(menu, inflater); 2342 } 2343 } 2344 return show; 2345 } 2346 2347 boolean performPrepareOptionsMenu(Menu menu) { 2348 boolean show = false; 2349 if (!mHidden) { 2350 if (mHasMenu && mMenuVisible) { 2351 show = true; 2352 onPrepareOptionsMenu(menu); 2353 } 2354 if (mChildFragmentManager != null) { 2355 show |= mChildFragmentManager.dispatchPrepareOptionsMenu(menu); 2356 } 2357 } 2358 return show; 2359 } 2360 2361 boolean performOptionsItemSelected(MenuItem item) { 2362 if (!mHidden) { 2363 if (mHasMenu && mMenuVisible) { 2364 if (onOptionsItemSelected(item)) { 2365 return true; 2366 } 2367 } 2368 if (mChildFragmentManager != null) { 2369 if (mChildFragmentManager.dispatchOptionsItemSelected(item)) { 2370 return true; 2371 } 2372 } 2373 } 2374 return false; 2375 } 2376 2377 boolean performContextItemSelected(MenuItem item) { 2378 if (!mHidden) { 2379 if (onContextItemSelected(item)) { 2380 return true; 2381 } 2382 if (mChildFragmentManager != null) { 2383 if (mChildFragmentManager.dispatchContextItemSelected(item)) { 2384 return true; 2385 } 2386 } 2387 } 2388 return false; 2389 } 2390 2391 void performOptionsMenuClosed(Menu menu) { 2392 if (!mHidden) { 2393 if (mHasMenu && mMenuVisible) { 2394 onOptionsMenuClosed(menu); 2395 } 2396 if (mChildFragmentManager != null) { 2397 mChildFragmentManager.dispatchOptionsMenuClosed(menu); 2398 } 2399 } 2400 } 2401 2402 void performSaveInstanceState(Bundle outState) { 2403 onSaveInstanceState(outState); 2404 if (mChildFragmentManager != null) { 2405 Parcelable p = mChildFragmentManager.saveAllState(); 2406 if (p != null) { 2407 outState.putParcelable(FragmentActivity.FRAGMENTS_TAG, p); 2408 } 2409 } 2410 } 2411 2412 void performPause() { 2413 if (mChildFragmentManager != null) { 2414 mChildFragmentManager.dispatchPause(); 2415 } 2416 mState = STARTED; 2417 mCalled = false; 2418 onPause(); 2419 if (!mCalled) { 2420 throw new SuperNotCalledException("Fragment " + this 2421 + " did not call through to super.onPause()"); 2422 } 2423 } 2424 2425 void performStop() { 2426 if (mChildFragmentManager != null) { 2427 mChildFragmentManager.dispatchStop(); 2428 } 2429 mState = STOPPED; 2430 mCalled = false; 2431 onStop(); 2432 if (!mCalled) { 2433 throw new SuperNotCalledException("Fragment " + this 2434 + " did not call through to super.onStop()"); 2435 } 2436 } 2437 2438 void performReallyStop() { 2439 if (mChildFragmentManager != null) { 2440 mChildFragmentManager.dispatchReallyStop(); 2441 } 2442 mState = ACTIVITY_CREATED; 2443 if (mLoadersStarted) { 2444 mLoadersStarted = false; 2445 if (!mCheckedForLoaderManager) { 2446 mCheckedForLoaderManager = true; 2447 mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false); 2448 } 2449 if (mLoaderManager != null) { 2450 if (mHost.getRetainLoaders()) { 2451 mLoaderManager.doRetain(); 2452 } else { 2453 mLoaderManager.doStop(); 2454 } 2455 } 2456 } 2457 } 2458 2459 void performDestroyView() { 2460 if (mChildFragmentManager != null) { 2461 mChildFragmentManager.dispatchDestroyView(); 2462 } 2463 mState = CREATED; 2464 mCalled = false; 2465 onDestroyView(); 2466 if (!mCalled) { 2467 throw new SuperNotCalledException("Fragment " + this 2468 + " did not call through to super.onDestroyView()"); 2469 } 2470 if (mLoaderManager != null) { 2471 mLoaderManager.doReportNextStart(); 2472 } 2473 mPerformedCreateView = false; 2474 } 2475 2476 void performDestroy() { 2477 if (mChildFragmentManager != null) { 2478 mChildFragmentManager.dispatchDestroy(); 2479 } 2480 mState = INITIALIZING; 2481 mCalled = false; 2482 onDestroy(); 2483 if (!mCalled) { 2484 throw new SuperNotCalledException("Fragment " + this 2485 + " did not call through to super.onDestroy()"); 2486 } 2487 mChildFragmentManager = null; 2488 } 2489 2490 void performDetach() { 2491 mCalled = false; 2492 onDetach(); 2493 if (!mCalled) { 2494 throw new SuperNotCalledException("Fragment " + this 2495 + " did not call through to super.onDetach()"); 2496 } 2497 2498 // Destroy the child FragmentManager if we still have it here. 2499 // We won't unless we're retaining our instance and if we do, 2500 // our child FragmentManager instance state will have already been saved. 2501 if (mChildFragmentManager != null) { 2502 if (!mRetaining) { 2503 throw new IllegalStateException("Child FragmentManager of " + this + " was not " 2504 + " destroyed and this fragment is not retaining instance"); 2505 } 2506 mChildFragmentManager.dispatchDestroy(); 2507 mChildFragmentManager = null; 2508 } 2509 } 2510 2511 void setOnStartEnterTransitionListener(OnStartEnterTransitionListener listener) { 2512 ensureAnimationInfo(); 2513 if (listener == mAnimationInfo.mStartEnterTransitionListener) { 2514 return; 2515 } 2516 if (listener != null && mAnimationInfo.mStartEnterTransitionListener != null) { 2517 throw new IllegalStateException("Trying to set a replacement " 2518 + "startPostponedEnterTransition on " + this); 2519 } 2520 if (mAnimationInfo.mEnterTransitionPostponed) { 2521 mAnimationInfo.mStartEnterTransitionListener = listener; 2522 } 2523 if (listener != null) { 2524 listener.startListening(); 2525 } 2526 } 2527 2528 private AnimationInfo ensureAnimationInfo() { 2529 if (mAnimationInfo == null) { 2530 mAnimationInfo = new AnimationInfo(); 2531 } 2532 return mAnimationInfo; 2533 } 2534 2535 int getNextAnim() { 2536 if (mAnimationInfo == null) { 2537 return 0; 2538 } 2539 return mAnimationInfo.mNextAnim; 2540 } 2541 2542 void setNextAnim(int animResourceId) { 2543 if (mAnimationInfo == null && animResourceId == 0) { 2544 return; // no change! 2545 } 2546 ensureAnimationInfo().mNextAnim = animResourceId; 2547 } 2548 2549 int getNextTransition() { 2550 if (mAnimationInfo == null) { 2551 return 0; 2552 } 2553 return mAnimationInfo.mNextTransition; 2554 } 2555 2556 void setNextTransition(int nextTransition, int nextTransitionStyle) { 2557 if (mAnimationInfo == null && nextTransition == 0 && nextTransitionStyle == 0) { 2558 return; // no change! 2559 } 2560 ensureAnimationInfo(); 2561 mAnimationInfo.mNextTransition = nextTransition; 2562 mAnimationInfo.mNextTransitionStyle = nextTransitionStyle; 2563 } 2564 2565 int getNextTransitionStyle() { 2566 if (mAnimationInfo == null) { 2567 return 0; 2568 } 2569 return mAnimationInfo.mNextTransitionStyle; 2570 } 2571 2572 SharedElementCallback getEnterTransitionCallback() { 2573 if (mAnimationInfo == null) { 2574 return null; 2575 } 2576 return mAnimationInfo.mEnterTransitionCallback; 2577 } 2578 2579 SharedElementCallback getExitTransitionCallback() { 2580 if (mAnimationInfo == null) { 2581 return null; 2582 } 2583 return mAnimationInfo.mExitTransitionCallback; 2584 } 2585 2586 View getAnimatingAway() { 2587 if (mAnimationInfo == null) { 2588 return null; 2589 } 2590 return mAnimationInfo.mAnimatingAway; 2591 } 2592 2593 void setAnimatingAway(View view) { 2594 ensureAnimationInfo().mAnimatingAway = view; 2595 } 2596 2597 int getStateAfterAnimating() { 2598 if (mAnimationInfo == null) { 2599 return 0; 2600 } 2601 return mAnimationInfo.mStateAfterAnimating; 2602 } 2603 2604 void setStateAfterAnimating(int state) { 2605 ensureAnimationInfo().mStateAfterAnimating = state; 2606 } 2607 2608 boolean isPostponed() { 2609 if (mAnimationInfo == null) { 2610 return false; 2611 } 2612 return mAnimationInfo.mEnterTransitionPostponed; 2613 } 2614 2615 boolean isHideReplaced() { 2616 if (mAnimationInfo == null) { 2617 return false; 2618 } 2619 return mAnimationInfo.mIsHideReplaced; 2620 } 2621 2622 void setHideReplaced(boolean replaced) { 2623 ensureAnimationInfo().mIsHideReplaced = replaced; 2624 } 2625 2626 /** 2627 * Used internally to be notified when {@link #startPostponedEnterTransition()} has 2628 * been called. This listener will only be called once and then be removed from the 2629 * listeners. 2630 */ 2631 interface OnStartEnterTransitionListener { 2632 void onStartEnterTransition(); 2633 void startListening(); 2634 } 2635 2636 /** 2637 * Contains all the animation and transition information for a fragment. This will only 2638 * be instantiated for Fragments that have Views. 2639 */ 2640 static class AnimationInfo { 2641 // Non-null if the fragment's view hierarchy is currently animating away, 2642 // meaning we need to wait a bit on completely destroying it. This is the 2643 // view that is animating. 2644 View mAnimatingAway; 2645 2646 // If mAnimatingAway != null, this is the state we should move to once the 2647 // animation is done. 2648 int mStateAfterAnimating; 2649 2650 // If app has requested a specific animation, this is the one to use. 2651 int mNextAnim; 2652 2653 // If app has requested a specific transition, this is the one to use. 2654 int mNextTransition; 2655 2656 // If app has requested a specific transition style, this is the one to use. 2657 int mNextTransitionStyle; 2658 2659 private Object mEnterTransition = null; 2660 private Object mReturnTransition = USE_DEFAULT_TRANSITION; 2661 private Object mExitTransition = null; 2662 private Object mReenterTransition = USE_DEFAULT_TRANSITION; 2663 private Object mSharedElementEnterTransition = null; 2664 private Object mSharedElementReturnTransition = USE_DEFAULT_TRANSITION; 2665 private Boolean mAllowReturnTransitionOverlap; 2666 private Boolean mAllowEnterTransitionOverlap; 2667 2668 SharedElementCallback mEnterTransitionCallback = null; 2669 SharedElementCallback mExitTransitionCallback = null; 2670 2671 // True when postponeEnterTransition has been called and startPostponeEnterTransition 2672 // hasn't been called yet. 2673 boolean mEnterTransitionPostponed; 2674 2675 // Listener to wait for startPostponeEnterTransition. After being called, it will 2676 // be set to null 2677 OnStartEnterTransitionListener mStartEnterTransitionListener; 2678 2679 // True if the View was hidden, but the transition is handling the hide 2680 boolean mIsHideReplaced; 2681 } 2682} 2683