1cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/* 2cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Copyright (C) 2011 The Android Open Source Project 3cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 4cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License"); 5cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * you may not use this file except in compliance with the License. 6cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * You may obtain a copy of the License at 7cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 8cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * http://www.apache.org/licenses/LICENSE-2.0 9cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * 10cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Unless required by applicable law or agreed to in writing, software 11cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS, 12cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * See the License for the specific language governing permissions and 14cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * limitations under the License. 15cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 16cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 17cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornpackage android.support.v4.app; 18cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 19cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcel; 20cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcelable; 21cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.text.TextUtils; 22cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.Log; 23cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 24cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.FileDescriptor; 25cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.PrintWriter; 26cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.util.ArrayList; 27cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 28cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornfinal class BackStackState implements Parcelable { 29cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int[] mOps; 30cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int mTransition; 31cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int mTransitionStyle; 32cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final String mName; 33cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int mIndex; 34cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int mBreadCrumbTitleRes; 35cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final CharSequence mBreadCrumbTitleText; 36cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int mBreadCrumbShortTitleRes; 37cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final CharSequence mBreadCrumbShortTitleText; 38cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 39cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public BackStackState(FragmentManagerImpl fm, BackStackRecord bse) { 40cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int numRemoved = 0; 41cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn BackStackRecord.Op op = bse.mHead; 42cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn while (op != null) { 43cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (op.removed != null) numRemoved += op.removed.size(); 44cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op = op.next; 45cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 46df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn mOps = new int[bse.mNumOp*7 + numRemoved]; 47cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 48cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!bse.mAddToBackStack) { 49cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Not on back stack"); 50cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 51cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 52cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op = bse.mHead; 53cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int pos = 0; 54cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn while (op != null) { 55cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mOps[pos++] = op.cmd; 565506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn mOps[pos++] = op.fragment != null ? op.fragment.mIndex : -1; 57cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mOps[pos++] = op.enterAnim; 58cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mOps[pos++] = op.exitAnim; 59df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn mOps[pos++] = op.popEnterAnim; 60df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn mOps[pos++] = op.popExitAnim; 61cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (op.removed != null) { 62cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int N = op.removed.size(); 63cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mOps[pos++] = N; 64cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn for (int i=0; i<N; i++) { 65cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mOps[pos++] = op.removed.get(i).mIndex; 66cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 67cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } else { 68cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mOps[pos++] = 0; 69cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 70cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op = op.next; 71cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 72cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTransition = bse.mTransition; 73cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTransitionStyle = bse.mTransitionStyle; 74cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mName = bse.mName; 75cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = bse.mIndex; 76cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbTitleRes = bse.mBreadCrumbTitleRes; 77cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbTitleText = bse.mBreadCrumbTitleText; 78cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbShortTitleRes = bse.mBreadCrumbShortTitleRes; 79cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbShortTitleText = bse.mBreadCrumbShortTitleText; 80cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 81cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 82cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public BackStackState(Parcel in) { 83cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mOps = in.createIntArray(); 84cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTransition = in.readInt(); 85cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTransitionStyle = in.readInt(); 86cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mName = in.readString(); 87cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = in.readInt(); 88cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbTitleRes = in.readInt(); 89cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbTitleText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); 90cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbShortTitleRes = in.readInt(); 91cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbShortTitleText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); 92cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 93cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 94cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public BackStackRecord instantiate(FragmentManagerImpl fm) { 95cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn BackStackRecord bse = new BackStackRecord(fm); 96cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int pos = 0; 97cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn while (pos < mOps.length) { 98cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn BackStackRecord.Op op = new BackStackRecord.Op(); 99cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.cmd = mOps[pos++]; 100cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (FragmentManagerImpl.DEBUG) Log.v(FragmentManagerImpl.TAG, 101cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn "BSE " + bse + " set base fragment #" + mOps[pos]); 1025506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn int findex = mOps[pos++]; 1035506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn if (findex >= 0) { 1045506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn Fragment f = fm.mActive.get(findex); 1055506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn op.fragment = f; 1065506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn } else { 1075506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn op.fragment = null; 1085506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn } 109cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.enterAnim = mOps[pos++]; 110cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.exitAnim = mOps[pos++]; 111df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn op.popEnterAnim = mOps[pos++]; 112df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn op.popExitAnim = mOps[pos++]; 113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final int N = mOps[pos++]; 114cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (N > 0) { 115cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.removed = new ArrayList<Fragment>(N); 116cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn for (int i=0; i<N; i++) { 117cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (FragmentManagerImpl.DEBUG) Log.v(FragmentManagerImpl.TAG, 118cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn "BSE " + bse + " set remove fragment #" + mOps[pos]); 119cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment r = fm.mActive.get(mOps[pos++]); 120cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.removed.add(r); 121cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 122cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 123cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn bse.addOp(op); 124cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 125cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn bse.mTransition = mTransition; 126cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn bse.mTransitionStyle = mTransitionStyle; 127cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn bse.mName = mName; 128cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn bse.mIndex = mIndex; 129cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn bse.mAddToBackStack = true; 130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn bse.mBreadCrumbTitleRes = mBreadCrumbTitleRes; 131cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn bse.mBreadCrumbTitleText = mBreadCrumbTitleText; 132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn bse.mBreadCrumbShortTitleRes = mBreadCrumbShortTitleRes; 133cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn bse.mBreadCrumbShortTitleText = mBreadCrumbShortTitleText; 134cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn bse.bumpBackStackNesting(1); 135cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return bse; 136cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 137cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 138cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public int describeContents() { 139cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return 0; 140cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 141cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 142cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void writeToParcel(Parcel dest, int flags) { 143cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeIntArray(mOps); 144cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mTransition); 145cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mTransitionStyle); 146cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeString(mName); 147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mIndex); 148cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mBreadCrumbTitleRes); 149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn TextUtils.writeToParcel(mBreadCrumbTitleText, dest, 0); 150cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn dest.writeInt(mBreadCrumbShortTitleRes); 151cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn TextUtils.writeToParcel(mBreadCrumbShortTitleText, dest, 0); 152cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 153cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 154cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public static final Parcelable.Creator<BackStackState> CREATOR 155cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn = new Parcelable.Creator<BackStackState>() { 156cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public BackStackState createFromParcel(Parcel in) { 157cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return new BackStackState(in); 158cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 159cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 160cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public BackStackState[] newArray(int size) { 161cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return new BackStackState[size]; 162cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 163cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn }; 164cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn} 165cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 166cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/** 167cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * @hide Entry of an operation on the fragment back stack. 168cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */ 169cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornfinal class BackStackRecord extends FragmentTransaction implements 170cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn FragmentManager.BackStackEntry, Runnable { 171cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final String TAG = "BackStackEntry"; 172cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn final FragmentManagerImpl mManager; 174cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 175cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int OP_NULL = 0; 176cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int OP_ADD = 1; 177cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int OP_REPLACE = 2; 178cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int OP_REMOVE = 3; 179cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int OP_HIDE = 4; 180cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final int OP_SHOW = 5; 181eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn static final int OP_DETACH = 6; 182eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn static final int OP_ATTACH = 7; 183cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 184cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn static final class Op { 185cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Op next; 186cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Op prev; 187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int cmd; 188cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment fragment; 189cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int enterAnim; 190cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int exitAnim; 191df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn int popEnterAnim; 192df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn int popExitAnim; 193cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn ArrayList<Fragment> removed; 194cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 195cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 196cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Op mHead; 197cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Op mTail; 198cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mNumOp; 199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mEnterAnim; 200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mExitAnim; 201df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn int mPopEnterAnim; 202df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn int mPopExitAnim; 203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mTransition; 204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mTransitionStyle; 205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mAddToBackStack; 206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mAllowAddToBackStack = true; 207cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn String mName; 208cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn boolean mCommitted; 209cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mIndex; 210cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mBreadCrumbTitleRes; 212cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn CharSequence mBreadCrumbTitleText; 213cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int mBreadCrumbShortTitleRes; 214cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn CharSequence mBreadCrumbShortTitleText; 215cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { 217cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mName="); writer.print(mName); 218cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mIndex="); writer.print(mIndex); 219cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mCommitted="); writer.println(mCommitted); 220cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mTransition != FragmentTransaction.TRANSIT_NONE) { 221cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mTransition=#"); 222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(Integer.toHexString(mTransition)); 223cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mTransitionStyle=#"); 224cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(Integer.toHexString(mTransitionStyle)); 225cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 226cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mEnterAnim != 0 || mExitAnim !=0) { 227cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mEnterAnim=#"); 228cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(Integer.toHexString(mEnterAnim)); 229cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mExitAnim=#"); 230cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(Integer.toHexString(mExitAnim)); 231cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 232df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn if (mPopEnterAnim != 0 || mPopExitAnim !=0) { 233df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn writer.print(prefix); writer.print("mPopEnterAnim=#"); 234df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn writer.print(Integer.toHexString(mPopEnterAnim)); 235df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn writer.print(" mPopExitAnim=#"); 236df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn writer.println(Integer.toHexString(mPopExitAnim)); 237df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn } 238cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mBreadCrumbTitleRes != 0 || mBreadCrumbTitleText != null) { 239cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mBreadCrumbTitleRes=#"); 240cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(Integer.toHexString(mBreadCrumbTitleRes)); 241cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mBreadCrumbTitleText="); 242cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mBreadCrumbTitleText); 243cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mBreadCrumbShortTitleRes != 0 || mBreadCrumbShortTitleText != null) { 245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print("mBreadCrumbShortTitleRes=#"); 246cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(Integer.toHexString(mBreadCrumbShortTitleRes)); 247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" mBreadCrumbShortTitleText="); 248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(mBreadCrumbShortTitleText); 249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 250cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mHead != null) { 252cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.println("Operations:"); 253cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn String innerPrefix = prefix + " "; 254cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Op op = mHead; 255cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int num = 0; 256cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn while (op != null) { 257cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(prefix); writer.print(" Op #"); writer.print(num); 258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(":"); 259cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(innerPrefix); writer.print("cmd="); writer.print(op.cmd); 260cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(" fragment="); writer.println(op.fragment); 261cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (op.enterAnim != 0 || op.exitAnim != 0) { 262df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn writer.print(prefix); writer.print("enterAnim=#"); 263df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn writer.print(Integer.toHexString(op.enterAnim)); 264df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn writer.print(" exitAnim=#"); 265df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn writer.println(Integer.toHexString(op.exitAnim)); 266df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn } 267df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn if (op.popEnterAnim != 0 || op.popExitAnim != 0) { 268df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn writer.print(prefix); writer.print("popEnterAnim=#"); 269df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn writer.print(Integer.toHexString(op.popEnterAnim)); 270df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn writer.print(" popExitAnim=#"); 271df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn writer.println(Integer.toHexString(op.popExitAnim)); 272cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 273cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (op.removed != null && op.removed.size() > 0) { 274cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn for (int i=0; i<op.removed.size(); i++) { 275cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(innerPrefix); 276cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (op.removed.size() == 1) { 277cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print("Removed: "); 278cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } else { 279cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println("Removed:"); 280cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(innerPrefix); writer.print(" #"); writer.print(num); 281cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.print(": "); 282cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 283cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn writer.println(op.removed.get(i)); 284cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 285cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 286cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op = op.next; 287cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 288cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 289cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 290cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 291cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public BackStackRecord(FragmentManagerImpl manager) { 292cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager = manager; 293cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 294cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 295cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public int getId() { 296cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mIndex; 297cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 298cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 299cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public int getBreadCrumbTitleRes() { 300cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mBreadCrumbTitleRes; 301cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 302cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 303cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public int getBreadCrumbShortTitleRes() { 304cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mBreadCrumbShortTitleRes; 305cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 306cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 307cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public CharSequence getBreadCrumbTitle() { 308cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mBreadCrumbTitleRes != 0) { 309cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mManager.mActivity.getText(mBreadCrumbTitleRes); 310cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 311cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mBreadCrumbTitleText; 312cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 313cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 314cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public CharSequence getBreadCrumbShortTitle() { 315cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mBreadCrumbShortTitleRes != 0) { 316cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mManager.mActivity.getText(mBreadCrumbShortTitleRes); 317cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 318cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mBreadCrumbShortTitleText; 319cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 320cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 321cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn void addOp(Op op) { 322cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mHead == null) { 323cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mHead = mTail = op; 324cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } else { 325cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.prev = mTail; 326cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTail.next = op; 327cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTail = op; 328cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 329cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.enterAnim = mEnterAnim; 330cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.exitAnim = mExitAnim; 331df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn op.popEnterAnim = mPopEnterAnim; 332df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn op.popExitAnim = mPopExitAnim; 333cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mNumOp++; 334cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 335cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 336cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction add(Fragment fragment, String tag) { 337cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn doAddOp(0, fragment, tag, OP_ADD); 338cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 339cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 340cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 341cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction add(int containerViewId, Fragment fragment) { 342cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn doAddOp(containerViewId, fragment, null, OP_ADD); 343cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 344cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 345cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 346cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction add(int containerViewId, Fragment fragment, String tag) { 347cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn doAddOp(containerViewId, fragment, tag, OP_ADD); 348cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 349cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 350cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 351cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn private void doAddOp(int containerViewId, Fragment fragment, String tag, int opcmd) { 352cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn fragment.mFragmentManager = mManager; 353cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 354cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (tag != null) { 355cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (fragment.mTag != null && !tag.equals(fragment.mTag)) { 356cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Can't change tag of fragment " 357cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + fragment + ": was " + fragment.mTag 358cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " now " + tag); 359cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 360cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn fragment.mTag = tag; 361cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 362cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 363cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (containerViewId != 0) { 364cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (fragment.mFragmentId != 0 && fragment.mFragmentId != containerViewId) { 365cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("Can't change container ID of fragment " 366cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + fragment + ": was " + fragment.mFragmentId 367cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " now " + containerViewId); 368cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 369cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn fragment.mContainerId = fragment.mFragmentId = containerViewId; 370cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 371cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 372cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Op op = new Op(); 373cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.cmd = opcmd; 374cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.fragment = fragment; 375cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn addOp(op); 376cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 377cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 378cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction replace(int containerViewId, Fragment fragment) { 379cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return replace(containerViewId, fragment, null); 380cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 381cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 382cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction replace(int containerViewId, Fragment fragment, String tag) { 383cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (containerViewId == 0) { 384cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalArgumentException("Must use non-zero containerViewId"); 385cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 386cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn doAddOp(containerViewId, fragment, tag, OP_REPLACE); 388cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 389cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 390cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 391cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction remove(Fragment fragment) { 392cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Op op = new Op(); 393cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.cmd = OP_REMOVE; 394cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.fragment = fragment; 395cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn addOp(op); 396cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 397cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 398cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 399cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 400cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction hide(Fragment fragment) { 401cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Op op = new Op(); 402cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.cmd = OP_HIDE; 403cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.fragment = fragment; 404cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn addOp(op); 405cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 406cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 407cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 408cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 409cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction show(Fragment fragment) { 410cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Op op = new Op(); 411cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.cmd = OP_SHOW; 412cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op.fragment = fragment; 413cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn addOp(op); 414cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 415cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 416cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 417cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 418eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn public FragmentTransaction detach(Fragment fragment) { 419eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn Op op = new Op(); 420eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn op.cmd = OP_DETACH; 421eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn op.fragment = fragment; 422eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn addOp(op); 423eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn 424eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn return this; 425eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn } 426eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn 427eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn public FragmentTransaction attach(Fragment fragment) { 428eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn Op op = new Op(); 429eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn op.cmd = OP_ATTACH; 430eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn op.fragment = fragment; 431eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn addOp(op); 432eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn 433eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn return this; 434eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn } 435eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn 436cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction setCustomAnimations(int enter, int exit) { 437df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn return setCustomAnimations(enter, exit, 0, 0); 438df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn } 439df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn 440df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn public FragmentTransaction setCustomAnimations(int enter, int exit, 441df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn int popEnter, int popExit) { 442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mEnterAnim = enter; 443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mExitAnim = exit; 444df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn mPopEnterAnim = popEnter; 445df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn mPopExitAnim = popExit; 446cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 447cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 448cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction setTransition(int transition) { 450cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTransition = transition; 451cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 452cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 453cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction setTransitionStyle(int styleRes) { 455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTransitionStyle = styleRes; 456cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 457cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 458cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 459cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction addToBackStack(String name) { 460cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!mAllowAddToBackStack) { 461cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException( 462cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn "This FragmentTransaction is not allowed to be added to the back stack."); 463cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 464cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mAddToBackStack = true; 465cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mName = name; 466cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 467cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 468cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 469cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public boolean isAddToBackStackAllowed() { 470cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mAllowAddToBackStack; 471cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 472cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 473cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction disallowAddToBackStack() { 474cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mAddToBackStack) { 475cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException( 476cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn "This transaction is already being added to the back stack"); 477cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 478cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mAllowAddToBackStack = false; 479cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 480cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 481cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 482cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction setBreadCrumbTitle(int res) { 483cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbTitleRes = res; 484cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbTitleText = null; 485cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 486cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 487cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 488cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction setBreadCrumbTitle(CharSequence text) { 489cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbTitleRes = 0; 490cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbTitleText = text; 491cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 492cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 493cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 494cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction setBreadCrumbShortTitle(int res) { 495cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbShortTitleRes = res; 496cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbShortTitleText = null; 497cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 498cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 499cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 500cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public FragmentTransaction setBreadCrumbShortTitle(CharSequence text) { 501cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbShortTitleRes = 0; 502cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mBreadCrumbShortTitleText = text; 503cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return this; 504cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 505cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 506cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn void bumpBackStackNesting(int amt) { 507cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (!mAddToBackStack) { 508cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return; 509cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 510cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (FragmentManagerImpl.DEBUG) Log.v(TAG, "Bump nesting in " + this 511cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + " by " + amt); 512cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Op op = mHead; 513cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn while (op != null) { 5145506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn if (op.fragment != null) { 5155506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn op.fragment.mBackStackNesting += amt; 5165506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn if (FragmentManagerImpl.DEBUG) Log.v(TAG, "Bump nesting of " 5175506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn + op.fragment + " to " + op.fragment.mBackStackNesting); 5185506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn } 519cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (op.removed != null) { 520cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn for (int i=op.removed.size()-1; i>=0; i--) { 521cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment r = op.removed.get(i); 522cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn r.mBackStackNesting += amt; 523cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (FragmentManagerImpl.DEBUG) Log.v(TAG, "Bump nesting of " 524cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn + r + " to " + r.mBackStackNesting); 525cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 526cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 527cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op = op.next; 528cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 529cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public int commit() { 532cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return commitInternal(false); 533cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 534cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public int commitAllowingStateLoss() { 536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return commitInternal(true); 537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 539cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn int commitInternal(boolean allowStateLoss) { 540cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mCommitted) throw new IllegalStateException("commit already called"); 541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (FragmentManagerImpl.DEBUG) Log.v(TAG, "Commit: " + this); 542cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mCommitted = true; 543cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mAddToBackStack) { 544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = mManager.allocBackStackIndex(this); 545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } else { 546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = -1; 547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager.enqueueAction(this, allowStateLoss); 549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mIndex; 550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 551cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void run() { 553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (FragmentManagerImpl.DEBUG) Log.v(TAG, "Run: " + this); 554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mAddToBackStack) { 556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mIndex < 0) { 557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalStateException("addToBackStack() called after commit()"); 558cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 561cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn bumpBackStackNesting(1); 562cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 563cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Op op = mHead; 564cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn while (op != null) { 565cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn switch (op.cmd) { 566cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn case OP_ADD: { 567cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment f = op.fragment; 568cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn f.mNextAnim = op.enterAnim; 569cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager.addFragment(f, false); 570cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } break; 571cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn case OP_REPLACE: { 572cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment f = op.fragment; 573cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mManager.mAdded != null) { 574cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn for (int i=0; i<mManager.mAdded.size(); i++) { 575cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment old = mManager.mAdded.get(i); 576cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (FragmentManagerImpl.DEBUG) Log.v(TAG, 577cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn "OP_REPLACE: adding=" + f + " old=" + old); 5785506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn if (f == null || old.mContainerId == f.mContainerId) { 5795506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn if (old == f) { 5805506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn op.fragment = f = null; 5815506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn } else { 5825506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn if (op.removed == null) { 5835506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn op.removed = new ArrayList<Fragment>(); 5845506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn } 5855506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn op.removed.add(old); 5865506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn old.mNextAnim = op.exitAnim; 5875506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn if (mAddToBackStack) { 5885506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn old.mBackStackNesting += 1; 5895506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn if (FragmentManagerImpl.DEBUG) Log.v(TAG, "Bump nesting of " 5905506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn + old + " to " + old.mBackStackNesting); 5915506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn } 5925506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn mManager.removeFragment(old, mTransition, mTransitionStyle); 593cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 594cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 595cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 596cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 5975506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn if (f != null) { 5985506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn f.mNextAnim = op.enterAnim; 5995506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn mManager.addFragment(f, false); 6005506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn } 601cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } break; 602cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn case OP_REMOVE: { 603cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment f = op.fragment; 604cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn f.mNextAnim = op.exitAnim; 605cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager.removeFragment(f, mTransition, mTransitionStyle); 606cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } break; 607cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn case OP_HIDE: { 608cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment f = op.fragment; 609cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn f.mNextAnim = op.exitAnim; 610cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager.hideFragment(f, mTransition, mTransitionStyle); 611cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } break; 612cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn case OP_SHOW: { 613cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment f = op.fragment; 614cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn f.mNextAnim = op.enterAnim; 615cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager.showFragment(f, mTransition, mTransitionStyle); 616cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } break; 617eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn case OP_DETACH: { 618eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn Fragment f = op.fragment; 619eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn f.mNextAnim = op.exitAnim; 620eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn mManager.detachFragment(f, mTransition, mTransitionStyle); 621eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn } break; 622eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn case OP_ATTACH: { 623eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn Fragment f = op.fragment; 624eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn f.mNextAnim = op.enterAnim; 625eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn mManager.attachFragment(f, mTransition, mTransitionStyle); 626eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn } break; 627cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn default: { 628cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalArgumentException("Unknown cmd: " + op.cmd); 629cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 630cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 631cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 632cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op = op.next; 633cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 634cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 635cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager.moveToState(mManager.mCurState, mTransition, 636cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTransitionStyle, true); 637cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 638cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mAddToBackStack) { 639cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager.addBackStackState(this); 640cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 641cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 642cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 643cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public void popFromBackStack(boolean doStateMove) { 644cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (FragmentManagerImpl.DEBUG) Log.v(TAG, "popFromBackStack: " + this); 645cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 646cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn bumpBackStackNesting(-1); 647cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 648cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Op op = mTail; 649cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn while (op != null) { 650cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn switch (op.cmd) { 651cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn case OP_ADD: { 652cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment f = op.fragment; 653df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn f.mNextAnim = op.popExitAnim; 654cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager.removeFragment(f, 655cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn FragmentManagerImpl.reverseTransit(mTransition), 656cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mTransitionStyle); 657cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } break; 658cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn case OP_REPLACE: { 659cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment f = op.fragment; 6605506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn if (f != null) { 6615506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn f.mNextAnim = op.popExitAnim; 6625506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn mManager.removeFragment(f, 6635506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn FragmentManagerImpl.reverseTransit(mTransition), 6645506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn mTransitionStyle); 6655506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn } 666cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (op.removed != null) { 667cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn for (int i=0; i<op.removed.size(); i++) { 668cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment old = op.removed.get(i); 669df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn old.mNextAnim = op.popEnterAnim; 670cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager.addFragment(old, false); 671cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 672cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 673cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } break; 674cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn case OP_REMOVE: { 675cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment f = op.fragment; 676df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn f.mNextAnim = op.popEnterAnim; 677cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager.addFragment(f, false); 678cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } break; 679cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn case OP_HIDE: { 680cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment f = op.fragment; 681df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn f.mNextAnim = op.popEnterAnim; 682cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager.showFragment(f, 683cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle); 684cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } break; 685cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn case OP_SHOW: { 686cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn Fragment f = op.fragment; 687df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn f.mNextAnim = op.popExitAnim; 688cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager.hideFragment(f, 689cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle); 690cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } break; 691eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn case OP_DETACH: { 692eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn Fragment f = op.fragment; 693df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn f.mNextAnim = op.popEnterAnim; 694eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn mManager.attachFragment(f, 695eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle); 696eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn } break; 697eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn case OP_ATTACH: { 698eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn Fragment f = op.fragment; 699df6f1393f73a488ba2661b28d3d88a5ac19c4ea2Dianne Hackborn f.mNextAnim = op.popEnterAnim; 700eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn mManager.detachFragment(f, 701eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle); 702eedc67283a5a49dce86c625e54596dfdea9465a7Dianne Hackborn } break; 703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn default: { 704cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn throw new IllegalArgumentException("Unknown cmd: " + op.cmd); 705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 707cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 708cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn op = op.prev; 709cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 710cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 711cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (doStateMove) { 712cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager.moveToState(mManager.mCurState, 713cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle, true); 714cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 715cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 716cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn if (mIndex >= 0) { 717cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mManager.freeBackStackIndex(mIndex); 718cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn mIndex = -1; 719cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 720cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 721cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 722cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public String getName() { 723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mName; 724cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 725cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 726cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public int getTransition() { 727cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTransition; 728cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 729cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 730cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public int getTransitionStyle() { 731cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mTransitionStyle; 732cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 733cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn 734cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn public boolean isEmpty() { 735cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn return mNumOp == 0; 736cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn } 737cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn} 738