FragmentManager.java revision f4c0cf637ba73374a206cec26c09d4dfa4c1a364
1bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson/* 2bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson * Copyright (C) 2011 The Android Open Source Project 3bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson * 4bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson * Licensed under the Apache License, Version 2.0 (the "License"); 5bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson * you may not use this file except in compliance with the License. 6bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson * You may obtain a copy of the License at 7bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson * 8bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 9bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson * 10bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson * Unless required by applicable law or agreed to in writing, software 11bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 12bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson * See the License for the specific language governing permissions and 14bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson * limitations under the License. 15bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson */ 16bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson 17bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilsonpackage android.support.v4.app; 18bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilson 19bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilsonimport android.content.Context; 20bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilsonimport android.content.res.Configuration; 21bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilsonimport android.os.Bundle; 22bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilsonimport android.os.Handler; 23bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilsonimport android.os.Looper; 24bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilsonimport android.os.Parcel; 25bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilsonimport android.os.Parcelable; 26bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilsonimport android.support.v4.util.DebugUtils; 27bf1df887d4b87f7da69cd4fe9306eb0d19166d52Jesse Wilsonimport android.support.v4.util.LogWriter; 28import android.util.Log; 29import android.util.SparseArray; 30import android.view.animation.AccelerateInterpolator; 31import android.view.animation.AlphaAnimation; 32import android.view.animation.Animation; 33import android.view.animation.AnimationSet; 34import android.view.animation.AnimationUtils; 35import android.view.animation.DecelerateInterpolator; 36import android.view.animation.Interpolator; 37import android.view.animation.ScaleAnimation; 38import android.view.animation.Animation.AnimationListener; 39import android.view.Menu; 40import android.view.MenuInflater; 41import android.view.MenuItem; 42import android.view.View; 43import android.view.ViewGroup; 44 45import java.io.FileDescriptor; 46import java.io.PrintWriter; 47import java.util.ArrayList; 48import java.util.Arrays; 49 50/** 51 * Static library support version of the framework's {@link android.app.FragmentManager}. 52 * Used to write apps that run on platforms prior to Android 3.0. When running 53 * on Android 3.0 or above, this implementation is still used; it does not try 54 * to switch to the framework's implementation. See the framework SDK 55 * documentation for a class overview. 56 * 57 * <p>Your activity must derive from {@link FragmentActivity} to use this. 58 */ 59public abstract class FragmentManager { 60 /** 61 * Representation of an entry on the fragment back stack, as created 62 * with {@link FragmentTransaction#addToBackStack(String) 63 * FragmentTransaction.addToBackStack()}. Entries can later be 64 * retrieved with {@link FragmentManager#getBackStackEntryAt(int) 65 * FragmentManager.getBackStackEntry()}. 66 * 67 * <p>Note that you should never hold on to a BackStackEntry object; 68 * the identifier as returned by {@link #getId} is the only thing that 69 * will be persisted across activity instances. 70 */ 71 public interface BackStackEntry { 72 /** 73 * Return the unique identifier for the entry. This is the only 74 * representation of the entry that will persist across activity 75 * instances. 76 */ 77 public int getId(); 78 79 /** 80 * Get the name that was supplied to 81 * {@link FragmentTransaction#addToBackStack(String) 82 * FragmentTransaction.addToBackStack(String)} when creating this entry. 83 */ 84 public String getName(); 85 86 /** 87 * Return the full bread crumb title resource identifier for the entry, 88 * or 0 if it does not have one. 89 */ 90 public int getBreadCrumbTitleRes(); 91 92 /** 93 * Return the short bread crumb title resource identifier for the entry, 94 * or 0 if it does not have one. 95 */ 96 public int getBreadCrumbShortTitleRes(); 97 98 /** 99 * Return the full bread crumb title for the entry, or null if it 100 * does not have one. 101 */ 102 public CharSequence getBreadCrumbTitle(); 103 104 /** 105 * Return the short bread crumb title for the entry, or null if it 106 * does not have one. 107 */ 108 public CharSequence getBreadCrumbShortTitle(); 109 } 110 111 /** 112 * Interface to watch for changes to the back stack. 113 */ 114 public interface OnBackStackChangedListener { 115 /** 116 * Called whenever the contents of the back stack change. 117 */ 118 public void onBackStackChanged(); 119 } 120 121 /** 122 * Start a series of edit operations on the Fragments associated with 123 * this FragmentManager. 124 * 125 * <p>Note: A fragment transaction can only be created/committed prior 126 * to an activity saving its state. If you try to commit a transaction 127 * after {@link FragmentActivity#onSaveInstanceState FragmentActivity.onSaveInstanceState()} 128 * (and prior to a following {@link FragmentActivity#onStart FragmentActivity.onStart} 129 * or {@link FragmentActivity#onResume FragmentActivity.onResume()}, you will get an error. 130 * This is because the framework takes care of saving your current fragments 131 * in the state, and if changes are made after the state is saved then they 132 * will be lost.</p> 133 */ 134 public abstract FragmentTransaction beginTransaction(); 135 136 /** @hide -- remove once prebuilts are in. */ 137 @Deprecated 138 public FragmentTransaction openTransaction() { 139 return beginTransaction(); 140 } 141 142 /** 143 * After a {@link FragmentTransaction} is committed with 144 * {@link FragmentTransaction#commit FragmentTransaction.commit()}, it 145 * is scheduled to be executed asynchronously on the process's main thread. 146 * If you want to immediately executing any such pending operations, you 147 * can call this function (only from the main thread) to do so. Note that 148 * all callbacks and other related behavior will be done from within this 149 * call, so be careful about where this is called from. 150 * 151 * @return Returns true if there were any pending transactions to be 152 * executed. 153 */ 154 public abstract boolean executePendingTransactions(); 155 156 /** 157 * Finds a fragment that was identified by the given id either when inflated 158 * from XML or as the container ID when added in a transaction. This first 159 * searches through fragments that are currently added to the manager's 160 * activity; if no such fragment is found, then all fragments currently 161 * on the back stack associated with this ID are searched. 162 * @return The fragment if found or null otherwise. 163 */ 164 public abstract Fragment findFragmentById(int id); 165 166 /** 167 * Finds a fragment that was identified by the given tag either when inflated 168 * from XML or as supplied when added in a transaction. This first 169 * searches through fragments that are currently added to the manager's 170 * activity; if no such fragment is found, then all fragments currently 171 * on the back stack are searched. 172 * @return The fragment if found or null otherwise. 173 */ 174 public abstract Fragment findFragmentByTag(String tag); 175 176 /** 177 * Flag for {@link #popBackStack(String, int)} 178 * and {@link #popBackStack(int, int)}: If set, and the name or ID of 179 * a back stack entry has been supplied, then all matching entries will 180 * be consumed until one that doesn't match is found or the bottom of 181 * the stack is reached. Otherwise, all entries up to but not including that entry 182 * will be removed. 183 */ 184 public static final int POP_BACK_STACK_INCLUSIVE = 1<<0; 185 186 /** 187 * Pop the top state off the back stack. Returns true if there was one 188 * to pop, else false. This function is asynchronous -- it enqueues the 189 * request to pop, but the action will not be performed until the application 190 * returns to its event loop. 191 */ 192 public abstract void popBackStack(); 193 194 /** 195 * Like {@link #popBackStack()}, but performs the operation immediately 196 * inside of the call. This is like calling {@link #executePendingTransactions()} 197 * afterwards. 198 * @return Returns true if there was something popped, else false. 199 */ 200 public abstract boolean popBackStackImmediate(); 201 202 /** 203 * Pop the last fragment transition from the manager's fragment 204 * back stack. If there is nothing to pop, false is returned. 205 * This function is asynchronous -- it enqueues the 206 * request to pop, but the action will not be performed until the application 207 * returns to its event loop. 208 * 209 * @param name If non-null, this is the name of a previous back state 210 * to look for; if found, all states up to that state will be popped. The 211 * {@link #POP_BACK_STACK_INCLUSIVE} flag can be used to control whether 212 * the named state itself is popped. If null, only the top state is popped. 213 * @param flags Either 0 or {@link #POP_BACK_STACK_INCLUSIVE}. 214 */ 215 public abstract void popBackStack(String name, int flags); 216 217 /** 218 * Like {@link #popBackStack(String, int)}, but performs the operation immediately 219 * inside of the call. This is like calling {@link #executePendingTransactions()} 220 * afterwards. 221 * @return Returns true if there was something popped, else false. 222 */ 223 public abstract boolean popBackStackImmediate(String name, int flags); 224 225 /** 226 * Pop all back stack states up to the one with the given identifier. 227 * This function is asynchronous -- it enqueues the 228 * request to pop, but the action will not be performed until the application 229 * returns to its event loop. 230 * 231 * @param id Identifier of the stated to be popped. If no identifier exists, 232 * false is returned. 233 * The identifier is the number returned by 234 * {@link FragmentTransaction#commit() FragmentTransaction.commit()}. The 235 * {@link #POP_BACK_STACK_INCLUSIVE} flag can be used to control whether 236 * the named state itself is popped. 237 * @param flags Either 0 or {@link #POP_BACK_STACK_INCLUSIVE}. 238 */ 239 public abstract void popBackStack(int id, int flags); 240 241 /** 242 * Like {@link #popBackStack(int, int)}, but performs the operation immediately 243 * inside of the call. This is like calling {@link #executePendingTransactions()} 244 * afterwards. 245 * @return Returns true if there was something popped, else false. 246 */ 247 public abstract boolean popBackStackImmediate(int id, int flags); 248 249 /** 250 * Return the number of entries currently in the back stack. 251 */ 252 public abstract int getBackStackEntryCount(); 253 254 /** 255 * Return the BackStackEntry at index <var>index</var> in the back stack; 256 * entries start index 0 being the bottom of the stack. 257 */ 258 public abstract BackStackEntry getBackStackEntryAt(int index); 259 260 /** 261 * Add a new listener for changes to the fragment back stack. 262 */ 263 public abstract void addOnBackStackChangedListener(OnBackStackChangedListener listener); 264 265 /** 266 * Remove a listener that was previously added with 267 * {@link #addOnBackStackChangedListener(OnBackStackChangedListener)}. 268 */ 269 public abstract void removeOnBackStackChangedListener(OnBackStackChangedListener listener); 270 271 /** 272 * Put a reference to a fragment in a Bundle. This Bundle can be 273 * persisted as saved state, and when later restoring 274 * {@link #getFragment(Bundle, String)} will return the current 275 * instance of the same fragment. 276 * 277 * @param bundle The bundle in which to put the fragment reference. 278 * @param key The name of the entry in the bundle. 279 * @param fragment The Fragment whose reference is to be stored. 280 */ 281 public abstract void putFragment(Bundle bundle, String key, Fragment fragment); 282 283 /** 284 * Retrieve the current Fragment instance for a reference previously 285 * placed with {@link #putFragment(Bundle, String, Fragment)}. 286 * 287 * @param bundle The bundle from which to retrieve the fragment reference. 288 * @param key The name of the entry in the bundle. 289 * @return Returns the current Fragment instance that is associated with 290 * the given reference. 291 */ 292 public abstract Fragment getFragment(Bundle bundle, String key); 293 294 /** 295 * Save the current instance state of the given Fragment. This can be 296 * used later when creating a new instance of the Fragment and adding 297 * it to the fragment manager, to have it create itself to match the 298 * current state returned here. Note that there are limits on how 299 * this can be used: 300 * 301 * <ul> 302 * <li>The Fragment must currently be attached to the FragmentManager. 303 * <li>A new Fragment created using this saved state must be the same class 304 * type as the Fragment it was created from. 305 * <li>The saved state can not contain dependencies on other fragments -- 306 * that is it can't use {@link #putFragment(Bundle, String, Fragment)} to 307 * store a fragment reference because that reference may not be valid when 308 * this saved state is later used. Likewise the Fragment's target and 309 * result code are not included in this state. 310 * </ul> 311 * 312 * @param f The Fragment whose state is to be saved. 313 * @return The generated state. This will be null if there was no 314 * interesting state created by the fragment. 315 */ 316 public abstract Fragment.SavedState saveFragmentInstanceState(Fragment f); 317 318 /** 319 * Print the FragmentManager's state into the given stream. 320 * 321 * @param prefix Text to print at the front of each line. 322 * @param fd The raw file descriptor that the dump is being sent to. 323 * @param writer A PrintWriter to which the dump is to be set. 324 * @param args Additional arguments to the dump request. 325 */ 326 public abstract void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args); 327 328 /** 329 * Control whether the framework's internal fragment manager debugging 330 * logs are turned on. If enabled, you will see output in logcat as 331 * the framework performs fragment operations. 332 */ 333 public static void enableDebugLogging(boolean enabled) { 334 FragmentManagerImpl.DEBUG = enabled; 335 } 336} 337 338final class FragmentManagerState implements Parcelable { 339 FragmentState[] mActive; 340 int[] mAdded; 341 BackStackState[] mBackStack; 342 343 public FragmentManagerState() { 344 } 345 346 public FragmentManagerState(Parcel in) { 347 mActive = in.createTypedArray(FragmentState.CREATOR); 348 mAdded = in.createIntArray(); 349 mBackStack = in.createTypedArray(BackStackState.CREATOR); 350 } 351 352 public int describeContents() { 353 return 0; 354 } 355 356 public void writeToParcel(Parcel dest, int flags) { 357 dest.writeTypedArray(mActive, flags); 358 dest.writeIntArray(mAdded); 359 dest.writeTypedArray(mBackStack, flags); 360 } 361 362 public static final Parcelable.Creator<FragmentManagerState> CREATOR 363 = new Parcelable.Creator<FragmentManagerState>() { 364 public FragmentManagerState createFromParcel(Parcel in) { 365 return new FragmentManagerState(in); 366 } 367 368 public FragmentManagerState[] newArray(int size) { 369 return new FragmentManagerState[size]; 370 } 371 }; 372} 373 374/** 375 * Container for fragments associated with an activity. 376 */ 377final class FragmentManagerImpl extends FragmentManager { 378 static boolean DEBUG = false; 379 static final String TAG = "FragmentManager"; 380 381 static final boolean HONEYCOMB = android.os.Build.VERSION.SDK_INT >= 11; 382 383 static final String TARGET_REQUEST_CODE_STATE_TAG = "android:target_req_state"; 384 static final String TARGET_STATE_TAG = "android:target_state"; 385 static final String VIEW_STATE_TAG = "android:view_state"; 386 static final String USER_VISIBLE_HINT_TAG = "android:user_visible_hint"; 387 388 ArrayList<Runnable> mPendingActions; 389 Runnable[] mTmpActions; 390 boolean mExecutingActions; 391 392 ArrayList<Fragment> mActive; 393 ArrayList<Fragment> mAdded; 394 ArrayList<Integer> mAvailIndices; 395 ArrayList<BackStackRecord> mBackStack; 396 ArrayList<Fragment> mCreatedMenus; 397 398 // Must be accessed while locked. 399 ArrayList<BackStackRecord> mBackStackIndices; 400 ArrayList<Integer> mAvailBackStackIndices; 401 402 ArrayList<OnBackStackChangedListener> mBackStackChangeListeners; 403 404 int mCurState = Fragment.INITIALIZING; 405 FragmentActivity mActivity; 406 407 boolean mNeedMenuInvalidate; 408 boolean mStateSaved; 409 boolean mDestroyed; 410 String mNoTransactionsBecause; 411 boolean mHavePendingDeferredStart; 412 413 // Temporary vars for state save and restore. 414 Bundle mStateBundle = null; 415 SparseArray<Parcelable> mStateArray = null; 416 417 Runnable mExecCommit = new Runnable() { 418 @Override 419 public void run() { 420 execPendingActions(); 421 } 422 }; 423 424 @Override 425 public FragmentTransaction beginTransaction() { 426 return new BackStackRecord(this); 427 } 428 429 @Override 430 public boolean executePendingTransactions() { 431 return execPendingActions(); 432 } 433 434 @Override 435 public void popBackStack() { 436 enqueueAction(new Runnable() { 437 @Override public void run() { 438 popBackStackState(mActivity.mHandler, null, -1, 0); 439 } 440 }, false); 441 } 442 443 @Override 444 public boolean popBackStackImmediate() { 445 checkStateLoss(); 446 executePendingTransactions(); 447 return popBackStackState(mActivity.mHandler, null, -1, 0); 448 } 449 450 @Override 451 public void popBackStack(final String name, final int flags) { 452 enqueueAction(new Runnable() { 453 @Override public void run() { 454 popBackStackState(mActivity.mHandler, name, -1, flags); 455 } 456 }, false); 457 } 458 459 @Override 460 public boolean popBackStackImmediate(String name, int flags) { 461 checkStateLoss(); 462 executePendingTransactions(); 463 return popBackStackState(mActivity.mHandler, name, -1, flags); 464 } 465 466 @Override 467 public void popBackStack(final int id, final int flags) { 468 if (id < 0) { 469 throw new IllegalArgumentException("Bad id: " + id); 470 } 471 enqueueAction(new Runnable() { 472 @Override public void run() { 473 popBackStackState(mActivity.mHandler, null, id, flags); 474 } 475 }, false); 476 } 477 478 @Override 479 public boolean popBackStackImmediate(int id, int flags) { 480 checkStateLoss(); 481 executePendingTransactions(); 482 if (id < 0) { 483 throw new IllegalArgumentException("Bad id: " + id); 484 } 485 return popBackStackState(mActivity.mHandler, null, id, flags); 486 } 487 488 @Override 489 public int getBackStackEntryCount() { 490 return mBackStack != null ? mBackStack.size() : 0; 491 } 492 493 @Override 494 public BackStackEntry getBackStackEntryAt(int index) { 495 return mBackStack.get(index); 496 } 497 498 @Override 499 public void addOnBackStackChangedListener(OnBackStackChangedListener listener) { 500 if (mBackStackChangeListeners == null) { 501 mBackStackChangeListeners = new ArrayList<OnBackStackChangedListener>(); 502 } 503 mBackStackChangeListeners.add(listener); 504 } 505 506 @Override 507 public void removeOnBackStackChangedListener(OnBackStackChangedListener listener) { 508 if (mBackStackChangeListeners != null) { 509 mBackStackChangeListeners.remove(listener); 510 } 511 } 512 513 @Override 514 public void putFragment(Bundle bundle, String key, Fragment fragment) { 515 if (fragment.mIndex < 0) { 516 throw new IllegalStateException("Fragment " + fragment 517 + " is not currently in the FragmentManager"); 518 } 519 bundle.putInt(key, fragment.mIndex); 520 } 521 522 @Override 523 public Fragment getFragment(Bundle bundle, String key) { 524 int index = bundle.getInt(key, -1); 525 if (index == -1) { 526 return null; 527 } 528 if (index >= mActive.size()) { 529 throw new IllegalStateException("Fragement no longer exists for key " 530 + key + ": index " + index); 531 } 532 Fragment f = mActive.get(index); 533 if (f == null) { 534 throw new IllegalStateException("Fragement no longer exists for key " 535 + key + ": index " + index); 536 } 537 return f; 538 } 539 540 @Override 541 public Fragment.SavedState saveFragmentInstanceState(Fragment fragment) { 542 if (fragment.mIndex < 0) { 543 throw new IllegalStateException("Fragment " + fragment 544 + " is not currently in the FragmentManager"); 545 } 546 if (fragment.mState > Fragment.INITIALIZING) { 547 Bundle result = saveFragmentBasicState(fragment); 548 return result != null ? new Fragment.SavedState(result) : null; 549 } 550 return null; 551 } 552 553 @Override 554 public String toString() { 555 StringBuilder sb = new StringBuilder(128); 556 sb.append("FragmentManager{"); 557 sb.append(Integer.toHexString(System.identityHashCode(this))); 558 sb.append(" in "); 559 DebugUtils.buildShortClassTag(mActivity, sb); 560 sb.append("}}"); 561 return sb.toString(); 562 } 563 564 @Override 565 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { 566 String innerPrefix = prefix + " "; 567 568 int N; 569 if (mActive != null) { 570 N = mActive.size(); 571 if (N > 0) { 572 writer.print(prefix); writer.print("Active Fragments in "); 573 writer.print(Integer.toHexString(System.identityHashCode(this))); 574 writer.println(":"); 575 for (int i=0; i<N; i++) { 576 Fragment f = mActive.get(i); 577 writer.print(prefix); writer.print(" #"); writer.print(i); 578 writer.print(": "); writer.println(f); 579 if (f != null) { 580 f.dump(innerPrefix, fd, writer, args); 581 } 582 } 583 } 584 } 585 586 if (mAdded != null) { 587 N = mAdded.size(); 588 if (N > 0) { 589 writer.print(prefix); writer.println("Added Fragments:"); 590 for (int i=0; i<N; i++) { 591 Fragment f = mAdded.get(i); 592 writer.print(prefix); writer.print(" #"); writer.print(i); 593 writer.print(": "); writer.println(f.toString()); 594 } 595 } 596 } 597 598 if (mCreatedMenus != null) { 599 N = mCreatedMenus.size(); 600 if (N > 0) { 601 writer.print(prefix); writer.println("Fragments Created Menus:"); 602 for (int i=0; i<N; i++) { 603 Fragment f = mCreatedMenus.get(i); 604 writer.print(prefix); writer.print(" #"); writer.print(i); 605 writer.print(": "); writer.println(f.toString()); 606 } 607 } 608 } 609 610 if (mBackStack != null) { 611 N = mBackStack.size(); 612 if (N > 0) { 613 writer.print(prefix); writer.println("Back Stack:"); 614 for (int i=0; i<N; i++) { 615 BackStackRecord bs = mBackStack.get(i); 616 writer.print(prefix); writer.print(" #"); writer.print(i); 617 writer.print(": "); writer.println(bs.toString()); 618 bs.dump(innerPrefix, fd, writer, args); 619 } 620 } 621 } 622 623 synchronized (this) { 624 if (mBackStackIndices != null) { 625 N = mBackStackIndices.size(); 626 if (N > 0) { 627 writer.print(prefix); writer.println("Back Stack Indices:"); 628 for (int i=0; i<N; i++) { 629 BackStackRecord bs = mBackStackIndices.get(i); 630 writer.print(prefix); writer.print(" #"); writer.print(i); 631 writer.print(": "); writer.println(bs); 632 } 633 } 634 } 635 636 if (mAvailBackStackIndices != null && mAvailBackStackIndices.size() > 0) { 637 writer.print(prefix); writer.print("mAvailBackStackIndices: "); 638 writer.println(Arrays.toString(mAvailBackStackIndices.toArray())); 639 } 640 } 641 642 if (mPendingActions != null) { 643 N = mPendingActions.size(); 644 if (N > 0) { 645 writer.print(prefix); writer.println("Pending Actions:"); 646 for (int i=0; i<N; i++) { 647 Runnable r = mPendingActions.get(i); 648 writer.print(prefix); writer.print(" #"); writer.print(i); 649 writer.print(": "); writer.println(r); 650 } 651 } 652 } 653 654 writer.print(prefix); writer.println("FragmentManager misc state:"); 655 writer.print(prefix); writer.print(" mCurState="); writer.print(mCurState); 656 writer.print(" mStateSaved="); writer.print(mStateSaved); 657 writer.print(" mDestroyed="); writer.println(mDestroyed); 658 if (mNeedMenuInvalidate) { 659 writer.print(prefix); writer.print(" mNeedMenuInvalidate="); 660 writer.println(mNeedMenuInvalidate); 661 } 662 if (mNoTransactionsBecause != null) { 663 writer.print(prefix); writer.print(" mNoTransactionsBecause="); 664 writer.println(mNoTransactionsBecause); 665 } 666 if (mAvailIndices != null && mAvailIndices.size() > 0) { 667 writer.print(prefix); writer.print(" mAvailIndices: "); 668 writer.println(Arrays.toString(mAvailIndices.toArray())); 669 } 670 } 671 672 static final Interpolator DECELERATE_QUINT = new DecelerateInterpolator(2.5f); 673 static final Interpolator DECELERATE_CUBIC = new DecelerateInterpolator(1.5f); 674 static final Interpolator ACCELERATE_QUINT = new AccelerateInterpolator(2.5f); 675 static final Interpolator ACCELERATE_CUBIC = new AccelerateInterpolator(1.5f); 676 677 static final int ANIM_DUR = 220; 678 679 static Animation makeOpenCloseAnimation(Context context, float startScale, 680 float endScale, float startAlpha, float endAlpha) { 681 AnimationSet set = new AnimationSet(false); 682 ScaleAnimation scale = new ScaleAnimation(startScale, endScale, startScale, endScale, 683 Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f); 684 scale.setInterpolator(DECELERATE_QUINT); 685 scale.setDuration(ANIM_DUR); 686 set.addAnimation(scale); 687 AlphaAnimation alpha = new AlphaAnimation(startAlpha, endAlpha); 688 alpha.setInterpolator(DECELERATE_CUBIC); 689 alpha.setDuration(ANIM_DUR); 690 set.addAnimation(alpha); 691 return set; 692 } 693 694 static Animation makeFadeAnimation(Context context, float start, float end) { 695 AlphaAnimation anim = new AlphaAnimation(start, end); 696 anim.setInterpolator(DECELERATE_CUBIC); 697 anim.setDuration(ANIM_DUR); 698 return anim; 699 } 700 701 Animation loadAnimation(Fragment fragment, int transit, boolean enter, 702 int transitionStyle) { 703 Animation animObj = fragment.onCreateAnimation(transit, enter, 704 fragment.mNextAnim); 705 if (animObj != null) { 706 return animObj; 707 } 708 709 if (fragment.mNextAnim != 0) { 710 Animation anim = AnimationUtils.loadAnimation(mActivity, fragment.mNextAnim); 711 if (anim != null) { 712 return anim; 713 } 714 } 715 716 if (transit == 0) { 717 return null; 718 } 719 720 int styleIndex = transitToStyleIndex(transit, enter); 721 if (styleIndex < 0) { 722 return null; 723 } 724 725 switch (styleIndex) { 726 case ANIM_STYLE_OPEN_ENTER: 727 return makeOpenCloseAnimation(mActivity, 1.125f, 1.0f, 0, 1); 728 case ANIM_STYLE_OPEN_EXIT: 729 return makeOpenCloseAnimation(mActivity, 1.0f, .975f, 1, 0); 730 case ANIM_STYLE_CLOSE_ENTER: 731 return makeOpenCloseAnimation(mActivity, .975f, 1.0f, 0, 1); 732 case ANIM_STYLE_CLOSE_EXIT: 733 return makeOpenCloseAnimation(mActivity, 1.0f, 1.075f, 1, 0); 734 case ANIM_STYLE_FADE_ENTER: 735 return makeFadeAnimation(mActivity, 0, 1); 736 case ANIM_STYLE_FADE_EXIT: 737 return makeFadeAnimation(mActivity, 1, 0); 738 } 739 740 if (transitionStyle == 0 && mActivity.getWindow() != null) { 741 transitionStyle = mActivity.getWindow().getAttributes().windowAnimations; 742 } 743 if (transitionStyle == 0) { 744 return null; 745 } 746 747 //TypedArray attrs = mActivity.obtainStyledAttributes(transitionStyle, 748 // com.android.internal.R.styleable.FragmentAnimation); 749 //int anim = attrs.getResourceId(styleIndex, 0); 750 //attrs.recycle(); 751 752 //if (anim == 0) { 753 // return null; 754 //} 755 756 //return AnimatorInflater.loadAnimator(mActivity, anim); 757 return null; 758 } 759 760 public void performPendingDeferredStart(Fragment f) { 761 if (f.mDeferStart) { 762 if (mExecutingActions) { 763 // Wait until we're done executing our pending transactions 764 mHavePendingDeferredStart = true; 765 return; 766 } 767 f.mDeferStart = false; 768 moveToState(f, mCurState, 0, 0); 769 } 770 } 771 772 void moveToState(Fragment f, int newState, int transit, int transitionStyle) { 773 // Fragments that are not currently added will sit in the onCreate() state. 774 if (!f.mAdded && newState > Fragment.CREATED) { 775 newState = Fragment.CREATED; 776 } 777 if (f.mRemoving && newState > f.mState) { 778 // While removing a fragment, we can't change it to a higher state. 779 newState = f.mState; 780 } 781 // Defer start if requested; don't allow it to move to STARTED or higher 782 // if it's not already started. 783 if (f.mDeferStart && f.mState < Fragment.STARTED && newState > Fragment.STOPPED) { 784 newState = Fragment.STOPPED; 785 } 786 if (f.mState < newState) { 787 // For fragments that are created from a layout, when restoring from 788 // state we don't want to allow them to be created until they are 789 // being reloaded from the layout. 790 if (f.mFromLayout && !f.mInLayout) { 791 return; 792 } 793 if (f.mAnimatingAway != null) { 794 // The fragment is currently being animated... but! Now we 795 // want to move our state back up. Give up on waiting for the 796 // animation, move to whatever the final state should be once 797 // the animation is done, and then we can proceed from there. 798 f.mAnimatingAway = null; 799 moveToState(f, f.mStateAfterAnimating, 0, 0); 800 } 801 switch (f.mState) { 802 case Fragment.INITIALIZING: 803 if (DEBUG) Log.v(TAG, "moveto CREATED: " + f); 804 if (f.mSavedFragmentState != null) { 805 f.mSavedViewState = f.mSavedFragmentState.getSparseParcelableArray( 806 FragmentManagerImpl.VIEW_STATE_TAG); 807 f.mTarget = getFragment(f.mSavedFragmentState, 808 FragmentManagerImpl.TARGET_STATE_TAG); 809 if (f.mTarget != null) { 810 f.mTargetRequestCode = f.mSavedFragmentState.getInt( 811 FragmentManagerImpl.TARGET_REQUEST_CODE_STATE_TAG, 0); 812 } 813 f.mUserVisibleHint = f.mSavedFragmentState.getBoolean( 814 FragmentManagerImpl.USER_VISIBLE_HINT_TAG, true); 815 if (!f.mUserVisibleHint) { 816 f.mDeferStart = true; 817 if (newState > Fragment.STOPPED) { 818 newState = Fragment.STOPPED; 819 } 820 } 821 } 822 f.mActivity = mActivity; 823 f.mFragmentManager = mActivity.mFragments; 824 f.mCalled = false; 825 f.onAttach(mActivity); 826 if (!f.mCalled) { 827 throw new SuperNotCalledException("Fragment " + f 828 + " did not call through to super.onAttach()"); 829 } 830 mActivity.onAttachFragment(f); 831 832 if (!f.mRetaining) { 833 f.mCalled = false; 834 f.onCreate(f.mSavedFragmentState); 835 if (!f.mCalled) { 836 throw new SuperNotCalledException("Fragment " + f 837 + " did not call through to super.onCreate()"); 838 } 839 } 840 f.mRetaining = false; 841 if (f.mFromLayout) { 842 // For fragments that are part of the content view 843 // layout, we need to instantiate the view immediately 844 // and the inflater will take care of adding it. 845 f.mView = f.onCreateView(f.getLayoutInflater(f.mSavedFragmentState), 846 null, f.mSavedFragmentState); 847 if (f.mView != null) { 848 f.mInnerView = f.mView; 849 f.mView = NoSaveStateFrameLayout.wrap(f.mView); 850 if (f.mHidden) f.mView.setVisibility(View.GONE); 851 f.onViewCreated(f.mView, f.mSavedFragmentState); 852 } else { 853 f.mInnerView = null; 854 } 855 } 856 case Fragment.CREATED: 857 if (newState > Fragment.CREATED) { 858 if (DEBUG) Log.v(TAG, "moveto ACTIVITY_CREATED: " + f); 859 if (!f.mFromLayout) { 860 ViewGroup container = null; 861 if (f.mContainerId != 0) { 862 container = (ViewGroup)mActivity.findViewById(f.mContainerId); 863 if (container == null && !f.mRestored) { 864 throw new IllegalArgumentException("No view found for id 0x" 865 + Integer.toHexString(f.mContainerId) 866 + " for fragment " + f); 867 } 868 } 869 f.mContainer = container; 870 f.mView = f.onCreateView(f.getLayoutInflater(f.mSavedFragmentState), 871 container, f.mSavedFragmentState); 872 if (f.mView != null) { 873 f.mInnerView = f.mView; 874 f.mView = NoSaveStateFrameLayout.wrap(f.mView); 875 if (container != null) { 876 Animation anim = loadAnimation(f, transit, true, 877 transitionStyle); 878 if (anim != null) { 879 f.mView.startAnimation(anim); 880 } 881 container.addView(f.mView); 882 } 883 if (f.mHidden) f.mView.setVisibility(View.GONE); 884 f.onViewCreated(f.mView, f.mSavedFragmentState); 885 } else { 886 f.mInnerView = null; 887 } 888 } 889 890 f.mCalled = false; 891 f.onActivityCreated(f.mSavedFragmentState); 892 if (!f.mCalled) { 893 throw new SuperNotCalledException("Fragment " + f 894 + " did not call through to super.onActivityCreated()"); 895 } 896 if (f.mView != null) { 897 f.restoreViewState(); 898 } 899 f.mSavedFragmentState = null; 900 } 901 case Fragment.ACTIVITY_CREATED: 902 case Fragment.STOPPED: 903 if (newState > Fragment.STOPPED) { 904 if (DEBUG) Log.v(TAG, "moveto STARTED: " + f); 905 f.mCalled = false; 906 f.performStart(); 907 if (!f.mCalled) { 908 throw new SuperNotCalledException("Fragment " + f 909 + " did not call through to super.onStart()"); 910 } 911 } 912 case Fragment.STARTED: 913 if (newState > Fragment.STARTED) { 914 if (DEBUG) Log.v(TAG, "moveto RESUMED: " + f); 915 f.mCalled = false; 916 f.mResumed = true; 917 f.onResume(); 918 if (!f.mCalled) { 919 throw new SuperNotCalledException("Fragment " + f 920 + " did not call through to super.onResume()"); 921 } 922 f.mSavedFragmentState = null; 923 f.mSavedViewState = null; 924 } 925 } 926 } else if (f.mState > newState) { 927 switch (f.mState) { 928 case Fragment.RESUMED: 929 if (newState < Fragment.RESUMED) { 930 if (DEBUG) Log.v(TAG, "movefrom RESUMED: " + f); 931 f.mCalled = false; 932 f.onPause(); 933 if (!f.mCalled) { 934 throw new SuperNotCalledException("Fragment " + f 935 + " did not call through to super.onPause()"); 936 } 937 f.mResumed = false; 938 } 939 case Fragment.STARTED: 940 if (newState < Fragment.STARTED) { 941 if (DEBUG) Log.v(TAG, "movefrom STARTED: " + f); 942 f.mCalled = false; 943 f.performStop(); 944 if (!f.mCalled) { 945 throw new SuperNotCalledException("Fragment " + f 946 + " did not call through to super.onStop()"); 947 } 948 } 949 case Fragment.STOPPED: 950 if (newState < Fragment.STOPPED) { 951 if (DEBUG) Log.v(TAG, "movefrom STOPPED: " + f); 952 f.performReallyStop(); 953 } 954 case Fragment.ACTIVITY_CREATED: 955 if (newState < Fragment.ACTIVITY_CREATED) { 956 if (DEBUG) Log.v(TAG, "movefrom ACTIVITY_CREATED: " + f); 957 if (f.mView != null) { 958 // Need to save the current view state if not 959 // done already. 960 if (!mActivity.isFinishing() && f.mSavedViewState == null) { 961 saveFragmentViewState(f); 962 } 963 } 964 f.mCalled = false; 965 f.performDestroyView(); 966 if (!f.mCalled) { 967 throw new SuperNotCalledException("Fragment " + f 968 + " did not call through to super.onDestroyView()"); 969 } 970 if (f.mView != null && f.mContainer != null) { 971 Animation anim = null; 972 if (mCurState > Fragment.INITIALIZING && !mDestroyed) { 973 anim = loadAnimation(f, transit, false, 974 transitionStyle); 975 } 976 if (anim != null) { 977 final Fragment fragment = f; 978 f.mAnimatingAway = f.mView; 979 f.mStateAfterAnimating = newState; 980 anim.setAnimationListener(new AnimationListener() { 981 @Override 982 public void onAnimationEnd(Animation animation) { 983 if (fragment.mAnimatingAway != null) { 984 fragment.mAnimatingAway = null; 985 moveToState(fragment, fragment.mStateAfterAnimating, 986 0, 0); 987 } 988 } 989 @Override 990 public void onAnimationRepeat(Animation animation) { 991 } 992 @Override 993 public void onAnimationStart(Animation animation) { 994 } 995 }); 996 f.mView.startAnimation(anim); 997 } 998 f.mContainer.removeView(f.mView); 999 } 1000 f.mContainer = null; 1001 f.mView = null; 1002 f.mInnerView = null; 1003 } 1004 case Fragment.CREATED: 1005 if (newState < Fragment.CREATED) { 1006 if (mDestroyed) { 1007 if (f.mAnimatingAway != null) { 1008 // The fragment's containing activity is 1009 // being destroyed, but this fragment is 1010 // currently animating away. Stop the 1011 // animation right now -- it is not needed, 1012 // and we can't wait any more on destroying 1013 // the fragment. 1014 View v = f.mAnimatingAway; 1015 f.mAnimatingAway = null; 1016 v.clearAnimation(); 1017 } 1018 } 1019 if (f.mAnimatingAway != null) { 1020 // We are waiting for the fragment's view to finish 1021 // animating away. Just make a note of the state 1022 // the fragment now should move to once the animation 1023 // is done. 1024 f.mStateAfterAnimating = newState; 1025 newState = Fragment.CREATED; 1026 } else { 1027 if (DEBUG) Log.v(TAG, "movefrom CREATED: " + f); 1028 if (!f.mRetaining) { 1029 f.mCalled = false; 1030 f.onDestroy(); 1031 if (!f.mCalled) { 1032 throw new SuperNotCalledException("Fragment " + f 1033 + " did not call through to super.onDestroy()"); 1034 } 1035 } 1036 1037 f.mCalled = false; 1038 f.onDetach(); 1039 if (!f.mCalled) { 1040 throw new SuperNotCalledException("Fragment " + f 1041 + " did not call through to super.onDetach()"); 1042 } 1043 if (!f.mRetaining) { 1044 makeInactive(f); 1045 } else { 1046 f.mActivity = null; 1047 f.mFragmentManager = null; 1048 } 1049 } 1050 } 1051 } 1052 } 1053 1054 f.mState = newState; 1055 } 1056 1057 void moveToState(Fragment f) { 1058 moveToState(f, mCurState, 0, 0); 1059 } 1060 1061 void moveToState(int newState, boolean always) { 1062 moveToState(newState, 0, 0, always); 1063 } 1064 1065 void moveToState(int newState, int transit, int transitStyle, boolean always) { 1066 if (mActivity == null && newState != Fragment.INITIALIZING) { 1067 throw new IllegalStateException("No activity"); 1068 } 1069 1070 if (!always && mCurState == newState) { 1071 return; 1072 } 1073 1074 mCurState = newState; 1075 if (mActive != null) { 1076 boolean loadersRunning = false; 1077 for (int i=0; i<mActive.size(); i++) { 1078 Fragment f = mActive.get(i); 1079 if (f != null) { 1080 moveToState(f, newState, transit, transitStyle); 1081 if (f.mLoaderManager != null) { 1082 loadersRunning |= f.mLoaderManager.hasRunningLoaders(); 1083 } 1084 } 1085 } 1086 1087 if (!loadersRunning) { 1088 startPendingDeferredFragments(); 1089 } 1090 1091 if (mNeedMenuInvalidate && mActivity != null && mCurState == Fragment.RESUMED) { 1092 mActivity.supportInvalidateOptionsMenu(); 1093 mNeedMenuInvalidate = false; 1094 } 1095 } 1096 } 1097 1098 void startPendingDeferredFragments() { 1099 if (mActive == null) return; 1100 1101 for (int i=0; i<mActive.size(); i++) { 1102 Fragment f = mActive.get(i); 1103 if (f != null) { 1104 performPendingDeferredStart(f); 1105 } 1106 } 1107 } 1108 1109 void makeActive(Fragment f) { 1110 if (f.mIndex >= 0) { 1111 return; 1112 } 1113 1114 if (mAvailIndices == null || mAvailIndices.size() <= 0) { 1115 if (mActive == null) { 1116 mActive = new ArrayList<Fragment>(); 1117 } 1118 f.setIndex(mActive.size()); 1119 mActive.add(f); 1120 1121 } else { 1122 f.setIndex(mAvailIndices.remove(mAvailIndices.size()-1)); 1123 mActive.set(f.mIndex, f); 1124 } 1125 } 1126 1127 void makeInactive(Fragment f) { 1128 if (f.mIndex < 0) { 1129 return; 1130 } 1131 1132 if (DEBUG) Log.v(TAG, "Freeing fragment index " + f.mIndex); 1133 mActive.set(f.mIndex, null); 1134 if (mAvailIndices == null) { 1135 mAvailIndices = new ArrayList<Integer>(); 1136 } 1137 mAvailIndices.add(f.mIndex); 1138 mActivity.invalidateSupportFragmentIndex(f.mIndex); 1139 f.initState(); 1140 } 1141 1142 public void addFragment(Fragment fragment, boolean moveToStateNow) { 1143 if (mAdded == null) { 1144 mAdded = new ArrayList<Fragment>(); 1145 } 1146 if (DEBUG) Log.v(TAG, "add: " + fragment); 1147 makeActive(fragment); 1148 if (!fragment.mDetached) { 1149 mAdded.add(fragment); 1150 fragment.mAdded = true; 1151 fragment.mRemoving = false; 1152 if (fragment.mHasMenu && fragment.mMenuVisible) { 1153 mNeedMenuInvalidate = true; 1154 } 1155 if (moveToStateNow) { 1156 moveToState(fragment); 1157 } 1158 } 1159 } 1160 1161 public void removeFragment(Fragment fragment, int transition, int transitionStyle) { 1162 if (DEBUG) Log.v(TAG, "remove: " + fragment + " nesting=" + fragment.mBackStackNesting); 1163 final boolean inactive = !fragment.isInBackStack(); 1164 if (!fragment.mDetached || inactive) { 1165 mAdded.remove(fragment); 1166 if (fragment.mHasMenu && fragment.mMenuVisible) { 1167 mNeedMenuInvalidate = true; 1168 } 1169 fragment.mAdded = false; 1170 fragment.mRemoving = true; 1171 moveToState(fragment, inactive ? Fragment.INITIALIZING : Fragment.CREATED, 1172 transition, transitionStyle); 1173 } 1174 } 1175 1176 public void hideFragment(Fragment fragment, int transition, int transitionStyle) { 1177 if (DEBUG) Log.v(TAG, "hide: " + fragment); 1178 if (!fragment.mHidden) { 1179 fragment.mHidden = true; 1180 if (fragment.mView != null) { 1181 Animation anim = loadAnimation(fragment, transition, true, 1182 transitionStyle); 1183 if (anim != null) { 1184 fragment.mView.startAnimation(anim); 1185 } 1186 fragment.mView.setVisibility(View.GONE); 1187 } 1188 if (fragment.mAdded && fragment.mHasMenu && fragment.mMenuVisible) { 1189 mNeedMenuInvalidate = true; 1190 } 1191 fragment.onHiddenChanged(true); 1192 } 1193 } 1194 1195 public void showFragment(Fragment fragment, int transition, int transitionStyle) { 1196 if (DEBUG) Log.v(TAG, "show: " + fragment); 1197 if (fragment.mHidden) { 1198 fragment.mHidden = false; 1199 if (fragment.mView != null) { 1200 Animation anim = loadAnimation(fragment, transition, true, 1201 transitionStyle); 1202 if (anim != null) { 1203 fragment.mView.startAnimation(anim); 1204 } 1205 fragment.mView.setVisibility(View.VISIBLE); 1206 } 1207 if (fragment.mAdded && fragment.mHasMenu && fragment.mMenuVisible) { 1208 mNeedMenuInvalidate = true; 1209 } 1210 fragment.onHiddenChanged(false); 1211 } 1212 } 1213 1214 public void detachFragment(Fragment fragment, int transition, int transitionStyle) { 1215 if (DEBUG) Log.v(TAG, "detach: " + fragment); 1216 if (!fragment.mDetached) { 1217 fragment.mDetached = true; 1218 if (fragment.mAdded) { 1219 // We are not already in back stack, so need to remove the fragment. 1220 mAdded.remove(fragment); 1221 if (fragment.mHasMenu && fragment.mMenuVisible) { 1222 mNeedMenuInvalidate = true; 1223 } 1224 fragment.mAdded = false; 1225 moveToState(fragment, Fragment.CREATED, transition, transitionStyle); 1226 } 1227 } 1228 } 1229 1230 public void attachFragment(Fragment fragment, int transition, int transitionStyle) { 1231 if (DEBUG) Log.v(TAG, "attach: " + fragment); 1232 if (fragment.mDetached) { 1233 fragment.mDetached = false; 1234 if (!fragment.mAdded) { 1235 mAdded.add(fragment); 1236 fragment.mAdded = true; 1237 if (fragment.mHasMenu && fragment.mMenuVisible) { 1238 mNeedMenuInvalidate = true; 1239 } 1240 moveToState(fragment, mCurState, transition, transitionStyle); 1241 } 1242 } 1243 } 1244 1245 public Fragment findFragmentById(int id) { 1246 if (mActive != null) { 1247 // First look through added fragments. 1248 for (int i=mAdded.size()-1; i>=0; i--) { 1249 Fragment f = mAdded.get(i); 1250 if (f != null && f.mFragmentId == id) { 1251 return f; 1252 } 1253 } 1254 // Now for any known fragment. 1255 for (int i=mActive.size()-1; i>=0; i--) { 1256 Fragment f = mActive.get(i); 1257 if (f != null && f.mFragmentId == id) { 1258 return f; 1259 } 1260 } 1261 } 1262 return null; 1263 } 1264 1265 public Fragment findFragmentByTag(String tag) { 1266 if (mActive != null && tag != null) { 1267 // First look through added fragments. 1268 for (int i=mAdded.size()-1; i>=0; i--) { 1269 Fragment f = mAdded.get(i); 1270 if (f != null && tag.equals(f.mTag)) { 1271 return f; 1272 } 1273 } 1274 // Now for any known fragment. 1275 for (int i=mActive.size()-1; i>=0; i--) { 1276 Fragment f = mActive.get(i); 1277 if (f != null && tag.equals(f.mTag)) { 1278 return f; 1279 } 1280 } 1281 } 1282 return null; 1283 } 1284 1285 public Fragment findFragmentByWho(String who) { 1286 if (mActive != null && who != null) { 1287 for (int i=mActive.size()-1; i>=0; i--) { 1288 Fragment f = mActive.get(i); 1289 if (f != null && who.equals(f.mWho)) { 1290 return f; 1291 } 1292 } 1293 } 1294 return null; 1295 } 1296 1297 private void checkStateLoss() { 1298 if (mStateSaved) { 1299 throw new IllegalStateException( 1300 "Can not perform this action after onSaveInstanceState"); 1301 } 1302 if (mNoTransactionsBecause != null) { 1303 throw new IllegalStateException( 1304 "Can not perform this action inside of " + mNoTransactionsBecause); 1305 } 1306 } 1307 1308 public void enqueueAction(Runnable action, boolean allowStateLoss) { 1309 if (!allowStateLoss) { 1310 checkStateLoss(); 1311 } 1312 synchronized (this) { 1313 if (mActivity == null) { 1314 throw new IllegalStateException("Activity has been destroyed"); 1315 } 1316 if (mPendingActions == null) { 1317 mPendingActions = new ArrayList<Runnable>(); 1318 } 1319 mPendingActions.add(action); 1320 if (mPendingActions.size() == 1) { 1321 mActivity.mHandler.removeCallbacks(mExecCommit); 1322 mActivity.mHandler.post(mExecCommit); 1323 } 1324 } 1325 } 1326 1327 public int allocBackStackIndex(BackStackRecord bse) { 1328 synchronized (this) { 1329 if (mAvailBackStackIndices == null || mAvailBackStackIndices.size() <= 0) { 1330 if (mBackStackIndices == null) { 1331 mBackStackIndices = new ArrayList<BackStackRecord>(); 1332 } 1333 int index = mBackStackIndices.size(); 1334 if (DEBUG) Log.v(TAG, "Setting back stack index " + index + " to " + bse); 1335 mBackStackIndices.add(bse); 1336 return index; 1337 1338 } else { 1339 int index = mAvailBackStackIndices.remove(mAvailBackStackIndices.size()-1); 1340 if (DEBUG) Log.v(TAG, "Adding back stack index " + index + " with " + bse); 1341 mBackStackIndices.set(index, bse); 1342 return index; 1343 } 1344 } 1345 } 1346 1347 public void setBackStackIndex(int index, BackStackRecord bse) { 1348 synchronized (this) { 1349 if (mBackStackIndices == null) { 1350 mBackStackIndices = new ArrayList<BackStackRecord>(); 1351 } 1352 int N = mBackStackIndices.size(); 1353 if (index < N) { 1354 if (DEBUG) Log.v(TAG, "Setting back stack index " + index + " to " + bse); 1355 mBackStackIndices.set(index, bse); 1356 } else { 1357 while (N < index) { 1358 mBackStackIndices.add(null); 1359 if (mAvailBackStackIndices == null) { 1360 mAvailBackStackIndices = new ArrayList<Integer>(); 1361 } 1362 if (DEBUG) Log.v(TAG, "Adding available back stack index " + N); 1363 mAvailBackStackIndices.add(N); 1364 N++; 1365 } 1366 if (DEBUG) Log.v(TAG, "Adding back stack index " + index + " with " + bse); 1367 mBackStackIndices.add(bse); 1368 } 1369 } 1370 } 1371 1372 public void freeBackStackIndex(int index) { 1373 synchronized (this) { 1374 mBackStackIndices.set(index, null); 1375 if (mAvailBackStackIndices == null) { 1376 mAvailBackStackIndices = new ArrayList<Integer>(); 1377 } 1378 if (DEBUG) Log.v(TAG, "Freeing back stack index " + index); 1379 mAvailBackStackIndices.add(index); 1380 } 1381 } 1382 1383 /** 1384 * Only call from main thread! 1385 */ 1386 public boolean execPendingActions() { 1387 if (mExecutingActions) { 1388 throw new IllegalStateException("Recursive entry to executePendingTransactions"); 1389 } 1390 1391 if (Looper.myLooper() != mActivity.mHandler.getLooper()) { 1392 throw new IllegalStateException("Must be called from main thread of process"); 1393 } 1394 1395 boolean didSomething = false; 1396 1397 while (true) { 1398 int numActions; 1399 1400 synchronized (this) { 1401 if (mPendingActions == null || mPendingActions.size() == 0) { 1402 break; 1403 } 1404 1405 numActions = mPendingActions.size(); 1406 if (mTmpActions == null || mTmpActions.length < numActions) { 1407 mTmpActions = new Runnable[numActions]; 1408 } 1409 mPendingActions.toArray(mTmpActions); 1410 mPendingActions.clear(); 1411 mActivity.mHandler.removeCallbacks(mExecCommit); 1412 } 1413 1414 mExecutingActions = true; 1415 for (int i=0; i<numActions; i++) { 1416 mTmpActions[i].run(); 1417 mTmpActions[i] = null; 1418 } 1419 mExecutingActions = false; 1420 didSomething = true; 1421 } 1422 1423 if (mHavePendingDeferredStart) { 1424 boolean loadersRunning = false; 1425 for (int i=0; i<mActive.size(); i++) { 1426 Fragment f = mActive.get(i); 1427 if (f != null && f.mLoaderManager != null) { 1428 loadersRunning |= f.mLoaderManager.hasRunningLoaders(); 1429 } 1430 } 1431 if (!loadersRunning) { 1432 mHavePendingDeferredStart = false; 1433 startPendingDeferredFragments(); 1434 } 1435 } 1436 return didSomething; 1437 } 1438 1439 void reportBackStackChanged() { 1440 if (mBackStackChangeListeners != null) { 1441 for (int i=0; i<mBackStackChangeListeners.size(); i++) { 1442 mBackStackChangeListeners.get(i).onBackStackChanged(); 1443 } 1444 } 1445 } 1446 1447 void addBackStackState(BackStackRecord state) { 1448 if (mBackStack == null) { 1449 mBackStack = new ArrayList<BackStackRecord>(); 1450 } 1451 mBackStack.add(state); 1452 reportBackStackChanged(); 1453 } 1454 1455 boolean popBackStackState(Handler handler, String name, int id, int flags) { 1456 if (mBackStack == null) { 1457 return false; 1458 } 1459 if (name == null && id < 0 && (flags&POP_BACK_STACK_INCLUSIVE) == 0) { 1460 int last = mBackStack.size()-1; 1461 if (last < 0) { 1462 return false; 1463 } 1464 final BackStackRecord bss = mBackStack.remove(last); 1465 bss.popFromBackStack(true); 1466 reportBackStackChanged(); 1467 } else { 1468 int index = -1; 1469 if (name != null || id >= 0) { 1470 // If a name or ID is specified, look for that place in 1471 // the stack. 1472 index = mBackStack.size()-1; 1473 while (index >= 0) { 1474 BackStackRecord bss = mBackStack.get(index); 1475 if (name != null && name.equals(bss.getName())) { 1476 break; 1477 } 1478 if (id >= 0 && id == bss.mIndex) { 1479 break; 1480 } 1481 index--; 1482 } 1483 if (index < 0) { 1484 return false; 1485 } 1486 if ((flags&POP_BACK_STACK_INCLUSIVE) != 0) { 1487 index--; 1488 // Consume all following entries that match. 1489 while (index >= 0) { 1490 BackStackRecord bss = mBackStack.get(index); 1491 if ((name != null && name.equals(bss.getName())) 1492 || (id >= 0 && id == bss.mIndex)) { 1493 index--; 1494 continue; 1495 } 1496 break; 1497 } 1498 } 1499 } 1500 if (index == mBackStack.size()-1) { 1501 return false; 1502 } 1503 final ArrayList<BackStackRecord> states 1504 = new ArrayList<BackStackRecord>(); 1505 for (int i=mBackStack.size()-1; i>index; i--) { 1506 states.add(mBackStack.remove(i)); 1507 } 1508 final int LAST = states.size()-1; 1509 for (int i=0; i<=LAST; i++) { 1510 if (DEBUG) Log.v(TAG, "Popping back stack state: " + states.get(i)); 1511 states.get(i).popFromBackStack(i == LAST); 1512 } 1513 reportBackStackChanged(); 1514 } 1515 return true; 1516 } 1517 1518 ArrayList<Fragment> retainNonConfig() { 1519 ArrayList<Fragment> fragments = null; 1520 if (mActive != null) { 1521 for (int i=0; i<mActive.size(); i++) { 1522 Fragment f = mActive.get(i); 1523 if (f != null && f.mRetainInstance) { 1524 if (fragments == null) { 1525 fragments = new ArrayList<Fragment>(); 1526 } 1527 fragments.add(f); 1528 f.mRetaining = true; 1529 f.mTargetIndex = f.mTarget != null ? f.mTarget.mIndex : -1; 1530 } 1531 } 1532 } 1533 return fragments; 1534 } 1535 1536 void saveFragmentViewState(Fragment f) { 1537 if (f.mInnerView == null) { 1538 return; 1539 } 1540 if (mStateArray == null) { 1541 mStateArray = new SparseArray<Parcelable>(); 1542 } else { 1543 mStateArray.clear(); 1544 } 1545 f.mInnerView.saveHierarchyState(mStateArray); 1546 if (mStateArray.size() > 0) { 1547 f.mSavedViewState = mStateArray; 1548 mStateArray = null; 1549 } 1550 } 1551 1552 Bundle saveFragmentBasicState(Fragment f) { 1553 Bundle result = null; 1554 1555 if (mStateBundle == null) { 1556 mStateBundle = new Bundle(); 1557 } 1558 f.onSaveInstanceState(mStateBundle); 1559 if (!mStateBundle.isEmpty()) { 1560 result = mStateBundle; 1561 mStateBundle = null; 1562 } 1563 1564 if (f.mView != null) { 1565 saveFragmentViewState(f); 1566 } 1567 if (f.mSavedViewState != null) { 1568 if (result == null) { 1569 result = new Bundle(); 1570 } 1571 result.putSparseParcelableArray( 1572 FragmentManagerImpl.VIEW_STATE_TAG, f.mSavedViewState); 1573 } 1574 if (!f.mUserVisibleHint) { 1575 if (result == null) { 1576 result = new Bundle(); 1577 } 1578 // Only add this if it's not the default value 1579 result.putBoolean(FragmentManagerImpl.USER_VISIBLE_HINT_TAG, f.mUserVisibleHint); 1580 } 1581 1582 return result; 1583 } 1584 1585 Parcelable saveAllState() { 1586 // Make sure all pending operations have now been executed to get 1587 // our state update-to-date. 1588 execPendingActions(); 1589 1590 if (HONEYCOMB) { 1591 // As of Honeycomb, we save state after pausing. Prior to that 1592 // it is before pausing. With fragments this is an issue, since 1593 // there are many things you may do after pausing but before 1594 // stopping that change the fragment state. For those older 1595 // devices, we will not at this point say that we have saved 1596 // the state, so we will allow them to continue doing fragment 1597 // transactions. This retains the same semantics as Honeycomb, 1598 // though you do have the risk of losing the very most recent state 1599 // if the process is killed... we'll live with that. 1600 mStateSaved = true; 1601 } 1602 1603 if (mActive == null || mActive.size() <= 0) { 1604 return null; 1605 } 1606 1607 // First collect all active fragments. 1608 int N = mActive.size(); 1609 FragmentState[] active = new FragmentState[N]; 1610 boolean haveFragments = false; 1611 for (int i=0; i<N; i++) { 1612 Fragment f = mActive.get(i); 1613 if (f != null) { 1614 haveFragments = true; 1615 1616 FragmentState fs = new FragmentState(f); 1617 active[i] = fs; 1618 1619 if (f.mState > Fragment.INITIALIZING && fs.mSavedFragmentState == null) { 1620 fs.mSavedFragmentState = saveFragmentBasicState(f); 1621 1622 if (f.mTarget != null) { 1623 if (f.mTarget.mIndex < 0) { 1624 String msg = "Failure saving state: " + f 1625 + " has target not in fragment manager: " + f.mTarget; 1626 Log.e(TAG, msg); 1627 dump(" ", null, new PrintWriter(new LogWriter(TAG)), new String[] { }); 1628 throw new IllegalStateException(msg); 1629 } 1630 if (fs.mSavedFragmentState == null) { 1631 fs.mSavedFragmentState = new Bundle(); 1632 } 1633 putFragment(fs.mSavedFragmentState, 1634 FragmentManagerImpl.TARGET_STATE_TAG, f.mTarget); 1635 if (f.mTargetRequestCode != 0) { 1636 fs.mSavedFragmentState.putInt( 1637 FragmentManagerImpl.TARGET_REQUEST_CODE_STATE_TAG, 1638 f.mTargetRequestCode); 1639 } 1640 } 1641 1642 } else { 1643 fs.mSavedFragmentState = f.mSavedFragmentState; 1644 } 1645 1646 if (DEBUG) Log.v(TAG, "Saved state of " + f + ": " 1647 + fs.mSavedFragmentState); 1648 } 1649 } 1650 1651 if (!haveFragments) { 1652 if (DEBUG) Log.v(TAG, "saveAllState: no fragments!"); 1653 return null; 1654 } 1655 1656 int[] added = null; 1657 BackStackState[] backStack = null; 1658 1659 // Build list of currently added fragments. 1660 if (mAdded != null) { 1661 N = mAdded.size(); 1662 if (N > 0) { 1663 added = new int[N]; 1664 for (int i=0; i<N; i++) { 1665 added[i] = mAdded.get(i).mIndex; 1666 if (DEBUG) Log.v(TAG, "saveAllState: adding fragment #" + i 1667 + ": " + mAdded.get(i)); 1668 } 1669 } 1670 } 1671 1672 // Now save back stack. 1673 if (mBackStack != null) { 1674 N = mBackStack.size(); 1675 if (N > 0) { 1676 backStack = new BackStackState[N]; 1677 for (int i=0; i<N; i++) { 1678 backStack[i] = new BackStackState(this, mBackStack.get(i)); 1679 if (DEBUG) Log.v(TAG, "saveAllState: adding back stack #" + i 1680 + ": " + mBackStack.get(i)); 1681 } 1682 } 1683 } 1684 1685 FragmentManagerState fms = new FragmentManagerState(); 1686 fms.mActive = active; 1687 fms.mAdded = added; 1688 fms.mBackStack = backStack; 1689 return fms; 1690 } 1691 1692 void restoreAllState(Parcelable state, ArrayList<Fragment> nonConfig) { 1693 // If there is no saved state at all, then there can not be 1694 // any nonConfig fragments either, so that is that. 1695 if (state == null) return; 1696 FragmentManagerState fms = (FragmentManagerState)state; 1697 if (fms.mActive == null) return; 1698 1699 // First re-attach any non-config instances we are retaining back 1700 // to their saved state, so we don't try to instantiate them again. 1701 if (nonConfig != null) { 1702 for (int i=0; i<nonConfig.size(); i++) { 1703 Fragment f = nonConfig.get(i); 1704 if (DEBUG) Log.v(TAG, "restoreAllState: re-attaching retained " + f); 1705 FragmentState fs = fms.mActive[f.mIndex]; 1706 fs.mInstance = f; 1707 f.mSavedViewState = null; 1708 f.mBackStackNesting = 0; 1709 f.mInLayout = false; 1710 f.mAdded = false; 1711 f.mTarget = null; 1712 if (fs.mSavedFragmentState != null) { 1713 fs.mSavedFragmentState.setClassLoader(mActivity.getClassLoader()); 1714 f.mSavedViewState = fs.mSavedFragmentState.getSparseParcelableArray( 1715 FragmentManagerImpl.VIEW_STATE_TAG); 1716 } 1717 } 1718 } 1719 1720 // Build the full list of active fragments, instantiating them from 1721 // their saved state. 1722 mActive = new ArrayList<Fragment>(fms.mActive.length); 1723 if (mAvailIndices != null) { 1724 mAvailIndices.clear(); 1725 } 1726 for (int i=0; i<fms.mActive.length; i++) { 1727 FragmentState fs = fms.mActive[i]; 1728 if (fs != null) { 1729 Fragment f = fs.instantiate(mActivity); 1730 if (DEBUG) Log.v(TAG, "restoreAllState: adding #" + i + ": " + f); 1731 mActive.add(f); 1732 // Now that the fragment is instantiated (or came from being 1733 // retained above), clear mInstance in case we end up re-restoring 1734 // from this FragmentState again. 1735 fs.mInstance = null; 1736 } else { 1737 if (DEBUG) Log.v(TAG, "restoreAllState: adding #" + i + ": (null)"); 1738 mActive.add(null); 1739 if (mAvailIndices == null) { 1740 mAvailIndices = new ArrayList<Integer>(); 1741 } 1742 if (DEBUG) Log.v(TAG, "restoreAllState: adding avail #" + i); 1743 mAvailIndices.add(i); 1744 } 1745 } 1746 1747 // Update the target of all retained fragments. 1748 if (nonConfig != null) { 1749 for (int i=0; i<nonConfig.size(); i++) { 1750 Fragment f = nonConfig.get(i); 1751 if (f.mTargetIndex >= 0) { 1752 if (f.mTargetIndex < mActive.size()) { 1753 f.mTarget = mActive.get(f.mTargetIndex); 1754 } else { 1755 Log.w(TAG, "Re-attaching retained fragment " + f 1756 + " target no longer exists: " + f.mTargetIndex); 1757 f.mTarget = null; 1758 } 1759 } 1760 } 1761 } 1762 1763 // Build the list of currently added fragments. 1764 if (fms.mAdded != null) { 1765 mAdded = new ArrayList<Fragment>(fms.mAdded.length); 1766 for (int i=0; i<fms.mAdded.length; i++) { 1767 Fragment f = mActive.get(fms.mAdded[i]); 1768 if (f == null) { 1769 throw new IllegalStateException( 1770 "No instantiated fragment for index #" + fms.mAdded[i]); 1771 } 1772 f.mAdded = true; 1773 if (DEBUG) Log.v(TAG, "restoreAllState: making added #" + i + ": " + f); 1774 mAdded.add(f); 1775 } 1776 } else { 1777 mAdded = null; 1778 } 1779 1780 // Build the back stack. 1781 if (fms.mBackStack != null) { 1782 mBackStack = new ArrayList<BackStackRecord>(fms.mBackStack.length); 1783 for (int i=0; i<fms.mBackStack.length; i++) { 1784 BackStackRecord bse = fms.mBackStack[i].instantiate(this); 1785 if (DEBUG) Log.v(TAG, "restoreAllState: adding bse #" + i 1786 + " (index " + bse.mIndex + "): " + bse); 1787 mBackStack.add(bse); 1788 if (bse.mIndex >= 0) { 1789 setBackStackIndex(bse.mIndex, bse); 1790 } 1791 } 1792 } else { 1793 mBackStack = null; 1794 } 1795 } 1796 1797 public void attachActivity(FragmentActivity activity) { 1798 if (mActivity != null) throw new IllegalStateException(); 1799 mActivity = activity; 1800 } 1801 1802 public void noteStateNotSaved() { 1803 mStateSaved = false; 1804 } 1805 1806 public void dispatchCreate() { 1807 mStateSaved = false; 1808 moveToState(Fragment.CREATED, false); 1809 } 1810 1811 public void dispatchActivityCreated() { 1812 mStateSaved = false; 1813 moveToState(Fragment.ACTIVITY_CREATED, false); 1814 } 1815 1816 public void dispatchStart() { 1817 mStateSaved = false; 1818 moveToState(Fragment.STARTED, false); 1819 } 1820 1821 public void dispatchResume() { 1822 mStateSaved = false; 1823 moveToState(Fragment.RESUMED, false); 1824 } 1825 1826 public void dispatchPause() { 1827 moveToState(Fragment.STARTED, false); 1828 } 1829 1830 public void dispatchStop() { 1831 // See saveAllState() for the explanation of this. We do this for 1832 // all platform versions, to keep our behavior more consistent between 1833 // them. 1834 mStateSaved = true; 1835 1836 moveToState(Fragment.STOPPED, false); 1837 } 1838 1839 public void dispatchReallyStop() { 1840 moveToState(Fragment.ACTIVITY_CREATED, false); 1841 } 1842 1843 public void dispatchDestroy() { 1844 mDestroyed = true; 1845 execPendingActions(); 1846 moveToState(Fragment.INITIALIZING, false); 1847 mActivity = null; 1848 } 1849 1850 public void dispatchConfigurationChanged(Configuration newConfig) { 1851 if (mActive != null) { 1852 for (int i=0; i<mAdded.size(); i++) { 1853 Fragment f = mAdded.get(i); 1854 if (f != null) { 1855 f.onConfigurationChanged(newConfig); 1856 } 1857 } 1858 } 1859 } 1860 1861 public void dispatchLowMemory() { 1862 if (mActive != null) { 1863 for (int i=0; i<mAdded.size(); i++) { 1864 Fragment f = mAdded.get(i); 1865 if (f != null) { 1866 f.onLowMemory(); 1867 } 1868 } 1869 } 1870 } 1871 1872 public boolean dispatchCreateOptionsMenu(Menu menu, MenuInflater inflater) { 1873 boolean show = false; 1874 ArrayList<Fragment> newMenus = null; 1875 if (mActive != null) { 1876 for (int i=0; i<mAdded.size(); i++) { 1877 Fragment f = mAdded.get(i); 1878 if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) { 1879 show = true; 1880 f.onCreateOptionsMenu(menu, inflater); 1881 if (newMenus == null) { 1882 newMenus = new ArrayList<Fragment>(); 1883 } 1884 newMenus.add(f); 1885 } 1886 } 1887 } 1888 1889 if (mCreatedMenus != null) { 1890 for (int i=0; i<mCreatedMenus.size(); i++) { 1891 Fragment f = mCreatedMenus.get(i); 1892 if (newMenus == null || !newMenus.contains(f)) { 1893 f.onDestroyOptionsMenu(); 1894 } 1895 } 1896 } 1897 1898 mCreatedMenus = newMenus; 1899 1900 return show; 1901 } 1902 1903 public boolean dispatchPrepareOptionsMenu(Menu menu) { 1904 boolean show = false; 1905 if (mActive != null) { 1906 for (int i=0; i<mAdded.size(); i++) { 1907 Fragment f = mAdded.get(i); 1908 if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) { 1909 show = true; 1910 f.onPrepareOptionsMenu(menu); 1911 } 1912 } 1913 } 1914 return show; 1915 } 1916 1917 public boolean dispatchOptionsItemSelected(MenuItem item) { 1918 if (mActive != null) { 1919 for (int i=0; i<mAdded.size(); i++) { 1920 Fragment f = mAdded.get(i); 1921 if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) { 1922 if (f.onOptionsItemSelected(item)) { 1923 return true; 1924 } 1925 } 1926 } 1927 } 1928 return false; 1929 } 1930 1931 public boolean dispatchContextItemSelected(MenuItem item) { 1932 if (mActive != null) { 1933 for (int i=0; i<mAdded.size(); i++) { 1934 Fragment f = mAdded.get(i); 1935 if (f != null && !f.mHidden) { 1936 if (f.onContextItemSelected(item)) { 1937 return true; 1938 } 1939 } 1940 } 1941 } 1942 return false; 1943 } 1944 1945 public void dispatchOptionsMenuClosed(Menu menu) { 1946 if (mActive != null) { 1947 for (int i=0; i<mAdded.size(); i++) { 1948 Fragment f = mAdded.get(i); 1949 if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) { 1950 f.onOptionsMenuClosed(menu); 1951 } 1952 } 1953 } 1954 } 1955 1956 public static int reverseTransit(int transit) { 1957 int rev = 0; 1958 switch (transit) { 1959 case FragmentTransaction.TRANSIT_FRAGMENT_OPEN: 1960 rev = FragmentTransaction.TRANSIT_FRAGMENT_CLOSE; 1961 break; 1962 case FragmentTransaction.TRANSIT_FRAGMENT_CLOSE: 1963 rev = FragmentTransaction.TRANSIT_FRAGMENT_OPEN; 1964 break; 1965 case FragmentTransaction.TRANSIT_FRAGMENT_FADE: 1966 rev = FragmentTransaction.TRANSIT_FRAGMENT_FADE; 1967 break; 1968 } 1969 return rev; 1970 1971 } 1972 1973 public static final int ANIM_STYLE_OPEN_ENTER = 1; 1974 public static final int ANIM_STYLE_OPEN_EXIT = 2; 1975 public static final int ANIM_STYLE_CLOSE_ENTER = 3; 1976 public static final int ANIM_STYLE_CLOSE_EXIT = 4; 1977 public static final int ANIM_STYLE_FADE_ENTER = 5; 1978 public static final int ANIM_STYLE_FADE_EXIT = 6; 1979 1980 public static int transitToStyleIndex(int transit, boolean enter) { 1981 int animAttr = -1; 1982 switch (transit) { 1983 case FragmentTransaction.TRANSIT_FRAGMENT_OPEN: 1984 animAttr = enter ? ANIM_STYLE_OPEN_ENTER : ANIM_STYLE_OPEN_EXIT; 1985 break; 1986 case FragmentTransaction.TRANSIT_FRAGMENT_CLOSE: 1987 animAttr = enter ? ANIM_STYLE_CLOSE_ENTER : ANIM_STYLE_CLOSE_EXIT; 1988 break; 1989 case FragmentTransaction.TRANSIT_FRAGMENT_FADE: 1990 animAttr = enter ? ANIM_STYLE_FADE_ENTER : ANIM_STYLE_FADE_EXIT; 1991 break; 1992 } 1993 return animAttr; 1994 } 1995} 1996