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