blob: c0e757d1ab0b72bd1dcf3c244ab95294d25fd7b8 [file] [log] [blame]
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001/*
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
17package android.app;
18
Dianne Hackbornf121be72010-05-06 14:10:32 -070019import android.content.res.TypedArray;
Dianne Hackborn2dedce62010-04-15 14:45:25 -070020import android.os.Bundle;
Dianne Hackbornba51c3d2010-05-05 18:49:48 -070021import android.os.Handler;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070022import android.os.Parcel;
23import android.os.Parcelable;
Dianne Hackborn5ae74d62010-05-19 19:14:57 -070024import android.util.Log;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070025import android.util.SparseArray;
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -070026import android.view.Menu;
27import android.view.MenuInflater;
28import android.view.MenuItem;
Dianne Hackborn5ae74d62010-05-19 19:14:57 -070029import android.view.View;
Dianne Hackborn2dedce62010-04-15 14:45:25 -070030import android.view.ViewGroup;
Dianne Hackbornf121be72010-05-06 14:10:32 -070031import android.view.animation.Animation;
32import android.view.animation.AnimationUtils;
Dianne Hackborn2dedce62010-04-15 14:45:25 -070033
34import java.util.ArrayList;
35
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070036final class FragmentManagerState implements Parcelable {
Dianne Hackborn6e8304e2010-05-14 00:42:53 -070037 FragmentState[] mActive;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070038 int[] mAdded;
39 BackStackState[] mBackStack;
40
41 public FragmentManagerState() {
42 }
43
44 public FragmentManagerState(Parcel in) {
Dianne Hackborn6e8304e2010-05-14 00:42:53 -070045 mActive = in.createTypedArray(FragmentState.CREATOR);
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070046 mAdded = in.createIntArray();
47 mBackStack = in.createTypedArray(BackStackState.CREATOR);
48 }
49
50 public int describeContents() {
51 return 0;
52 }
53
54 public void writeToParcel(Parcel dest, int flags) {
Dianne Hackborn6e8304e2010-05-14 00:42:53 -070055 dest.writeTypedArray(mActive, flags);
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070056 dest.writeIntArray(mAdded);
57 dest.writeTypedArray(mBackStack, flags);
58 }
59
60 public static final Parcelable.Creator<FragmentManagerState> CREATOR
61 = new Parcelable.Creator<FragmentManagerState>() {
62 public FragmentManagerState createFromParcel(Parcel in) {
63 return new FragmentManagerState(in);
64 }
65
66 public FragmentManagerState[] newArray(int size) {
67 return new FragmentManagerState[size];
68 }
69 };
Dianne Hackbornba51c3d2010-05-05 18:49:48 -070070}
71
Dianne Hackborn2dedce62010-04-15 14:45:25 -070072/**
Dianne Hackbornf121be72010-05-06 14:10:32 -070073 * @hide
Dianne Hackborn2dedce62010-04-15 14:45:25 -070074 * Container for fragments associated with an activity.
75 */
Dianne Hackbornf121be72010-05-06 14:10:32 -070076public class FragmentManager {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -070077 static final boolean DEBUG = true;
78 static final String TAG = "FragmentManager";
79
Dianne Hackborn445646c2010-06-25 15:52:59 -070080 ArrayList<Runnable> mPendingActions;
81 Runnable[] mTmpActions;
82 boolean mExecutingActions;
83
Dianne Hackborn6e8304e2010-05-14 00:42:53 -070084 ArrayList<Fragment> mActive;
85 ArrayList<Fragment> mAdded;
86 ArrayList<Integer> mAvailIndices;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070087 ArrayList<BackStackEntry> mBackStack;
Dianne Hackborn2dedce62010-04-15 14:45:25 -070088
Dianne Hackborndd913a52010-07-22 12:17:04 -070089 // Must be accessed while locked.
90 ArrayList<BackStackEntry> mBackStackIndices;
91 ArrayList<Integer> mAvailBackStackIndices;
92
Dianne Hackborn2dedce62010-04-15 14:45:25 -070093 int mCurState = Fragment.INITIALIZING;
94 Activity mActivity;
95
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -070096 boolean mNeedMenuInvalidate;
97
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070098 // Temporary vars for state save and restore.
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070099 Bundle mStateBundle = null;
100 SparseArray<Parcelable> mStateArray = null;
101
Dianne Hackborn445646c2010-06-25 15:52:59 -0700102 Runnable mExecCommit = new Runnable() {
103 @Override
104 public void run() {
105 execPendingActions();
106 }
107 };
108
Dianne Hackbornf121be72010-05-06 14:10:32 -0700109 Animation loadAnimation(Fragment fragment, int transit, boolean enter,
110 int transitionStyle) {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700111 Animation animObj = fragment.onCreateAnimation(transitionStyle, enter,
112 fragment.mNextAnim);
Dianne Hackbornf121be72010-05-06 14:10:32 -0700113 if (animObj != null) {
114 return animObj;
115 }
116
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700117 if (fragment.mNextAnim != 0) {
118 Animation anim = AnimationUtils.loadAnimation(mActivity, fragment.mNextAnim);
119 if (anim != null) {
120 return anim;
121 }
122 }
123
Dianne Hackbornf121be72010-05-06 14:10:32 -0700124 if (transit == 0) {
125 return null;
126 }
127
128 int styleIndex = transitToStyleIndex(transit, enter);
129 if (styleIndex < 0) {
130 return null;
131 }
132
133 if (transitionStyle == 0 && mActivity.getWindow() != null) {
134 transitionStyle = mActivity.getWindow().getAttributes().windowAnimations;
135 }
136 if (transitionStyle == 0) {
137 return null;
138 }
139
140 TypedArray attrs = mActivity.obtainStyledAttributes(transitionStyle,
141 com.android.internal.R.styleable.WindowAnimation);
142 int anim = attrs.getResourceId(styleIndex, 0);
143 attrs.recycle();
144
145 if (anim == 0) {
146 return null;
147 }
148
149 return AnimationUtils.loadAnimation(mActivity, anim);
150 }
151
152 void moveToState(Fragment f, int newState, int transit, int transitionStyle) {
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700153 // Fragments that are not currently added will sit in the onCreate() state.
154 if (!f.mAdded && newState > Fragment.CREATED) {
155 newState = Fragment.CREATED;
156 }
157
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700158 if (f.mState < newState) {
159 switch (f.mState) {
160 case Fragment.INITIALIZING:
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700161 if (DEBUG) Log.v(TAG, "moveto CREATED: " + f);
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700162 f.mActivity = mActivity;
163 f.mCalled = false;
164 f.onAttach(mActivity);
165 if (!f.mCalled) {
166 throw new SuperNotCalledException("Fragment " + f
167 + " did not call through to super.onAttach()");
168 }
Dianne Hackbornc8017682010-07-06 13:34:38 -0700169 mActivity.onAttachFragment(f);
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700170
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700171 if (!f.mRetaining) {
172 f.mCalled = false;
173 f.onCreate(f.mSavedFragmentState);
174 if (!f.mCalled) {
175 throw new SuperNotCalledException("Fragment " + f
176 + " did not call through to super.onCreate()");
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700177 }
178 }
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700179 f.mRetaining = false;
180 if (f.mFromLayout) {
181 // For fragments that are part of the content view
182 // layout, we need to instantiate the view immediately
183 // and the inflater will take care of adding it.
184 f.mView = f.onCreateView(mActivity.getLayoutInflater(),
185 null, f.mSavedFragmentState);
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700186 if (f.mView != null) {
187 f.mView.setSaveFromParentEnabled(false);
188 f.restoreViewState();
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700189 if (f.mHidden) f.mView.setVisibility(View.GONE);
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700190 }
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700191 }
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700192 case Fragment.CREATED:
193 if (newState > Fragment.CREATED) {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700194 if (DEBUG) Log.v(TAG, "moveto CONTENT: " + f);
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700195 if (!f.mFromLayout) {
196 ViewGroup container = null;
197 if (f.mContainerId != 0) {
198 container = (ViewGroup)mActivity.findViewById(f.mContainerId);
199 if (container == null) {
200 throw new IllegalArgumentException("New view found for id 0x"
201 + Integer.toHexString(f.mContainerId)
202 + " for fragment " + f);
203 }
204 }
205 f.mContainer = container;
206 f.mView = f.onCreateView(mActivity.getLayoutInflater(),
207 container, f.mSavedFragmentState);
208 if (f.mView != null) {
209 f.mView.setSaveFromParentEnabled(false);
210 if (container != null) {
211 Animation anim = loadAnimation(f, transit, true,
212 transitionStyle);
213 if (anim != null) {
214 f.mView.setAnimation(anim);
215 }
216 container.addView(f.mView);
217 f.restoreViewState();
218 }
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700219 if (f.mHidden) f.mView.setVisibility(View.GONE);
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700220 }
221 }
222
223 f.mCalled = false;
Dianne Hackbornc8017682010-07-06 13:34:38 -0700224 f.onActivityCreated(f.mSavedFragmentState);
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700225 if (!f.mCalled) {
226 throw new SuperNotCalledException("Fragment " + f
227 + " did not call through to super.onReady()");
228 }
229 f.mSavedFragmentState = null;
230 }
Dianne Hackbornc8017682010-07-06 13:34:38 -0700231 case Fragment.ACTIVITY_CREATED:
232 if (newState > Fragment.ACTIVITY_CREATED) {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700233 if (DEBUG) Log.v(TAG, "moveto STARTED: " + f);
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700234 f.mCalled = false;
235 f.onStart();
236 if (!f.mCalled) {
237 throw new SuperNotCalledException("Fragment " + f
238 + " did not call through to super.onStart()");
239 }
240 }
241 case Fragment.STARTED:
242 if (newState > Fragment.STARTED) {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700243 if (DEBUG) Log.v(TAG, "moveto RESUMED: " + f);
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700244 f.mCalled = false;
Dianne Hackborn2707d602010-07-09 18:01:20 -0700245 f.mResumed = true;
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700246 f.onResume();
247 if (!f.mCalled) {
248 throw new SuperNotCalledException("Fragment " + f
249 + " did not call through to super.onResume()");
250 }
251 }
252 }
253 } else if (f.mState > newState) {
254 switch (f.mState) {
255 case Fragment.RESUMED:
256 if (newState < Fragment.RESUMED) {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700257 if (DEBUG) Log.v(TAG, "movefrom RESUMED: " + f);
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700258 f.mCalled = false;
259 f.onPause();
260 if (!f.mCalled) {
261 throw new SuperNotCalledException("Fragment " + f
262 + " did not call through to super.onPause()");
263 }
Dianne Hackborn2707d602010-07-09 18:01:20 -0700264 f.mResumed = false;
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700265 }
266 case Fragment.STARTED:
267 if (newState < Fragment.STARTED) {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700268 if (DEBUG) Log.v(TAG, "movefrom STARTED: " + f);
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700269 f.mCalled = false;
Dianne Hackborn2707d602010-07-09 18:01:20 -0700270 f.performStop();
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700271 if (!f.mCalled) {
272 throw new SuperNotCalledException("Fragment " + f
273 + " did not call through to super.onStop()");
274 }
275 }
Dianne Hackbornc8017682010-07-06 13:34:38 -0700276 case Fragment.ACTIVITY_CREATED:
277 if (newState < Fragment.ACTIVITY_CREATED) {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700278 if (DEBUG) Log.v(TAG, "movefrom CONTENT: " + f);
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700279 if (f.mView != null) {
Dianne Hackborn5ddd1272010-06-12 10:15:28 -0700280 f.mCalled = false;
281 f.onDestroyView();
282 if (!f.mCalled) {
283 throw new SuperNotCalledException("Fragment " + f
284 + " did not call through to super.onDestroyedView()");
285 }
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700286 // Need to save the current view state if not
287 // done already.
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700288 if (!mActivity.isFinishing() && f.mSavedFragmentState == null) {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700289 saveFragmentViewState(f);
Dianne Hackbornf121be72010-05-06 14:10:32 -0700290 }
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700291 if (f.mContainer != null) {
292 if (mCurState > Fragment.INITIALIZING) {
293 Animation anim = loadAnimation(f, transit, false,
294 transitionStyle);
295 if (anim != null) {
296 f.mView.setAnimation(anim);
297 }
298 }
299 f.mContainer.removeView(f.mView);
300 }
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700301 }
302 f.mContainer = null;
303 f.mView = null;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700304 }
305 case Fragment.CREATED:
306 if (newState < Fragment.CREATED) {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700307 if (DEBUG) Log.v(TAG, "movefrom CREATED: " + f);
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700308 if (!f.mRetaining) {
309 f.mCalled = false;
310 f.onDestroy();
311 if (!f.mCalled) {
312 throw new SuperNotCalledException("Fragment " + f
313 + " did not call through to super.onDestroy()");
314 }
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700315 }
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700316
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700317 f.mCalled = false;
318 f.onDetach();
319 if (!f.mCalled) {
320 throw new SuperNotCalledException("Fragment " + f
321 + " did not call through to super.onDetach()");
322 }
323 f.mActivity = null;
324 }
325 }
326 }
327
328 f.mState = newState;
329 }
330
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700331 void moveToState(int newState, boolean always) {
Dianne Hackbornf121be72010-05-06 14:10:32 -0700332 moveToState(newState, 0, 0, always);
333 }
334
335 void moveToState(int newState, int transit, int transitStyle, boolean always) {
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700336 if (mActivity == null && newState != Fragment.INITIALIZING) {
337 throw new IllegalStateException("No activity");
338 }
339
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700340 if (!always && mCurState == newState) {
341 return;
342 }
343
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700344 mCurState = newState;
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700345 if (mActive != null) {
346 for (int i=0; i<mActive.size(); i++) {
347 Fragment f = mActive.get(i);
348 if (f != null) {
349 moveToState(f, newState, transit, transitStyle);
350 }
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700351 }
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700352 }
353 }
354
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700355 void makeActive(Fragment f) {
356 if (f.mIndex >= 0) {
357 return;
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700358 }
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700359
360 if (mAvailIndices == null || mAvailIndices.size() <= 0) {
361 if (mActive == null) {
362 mActive = new ArrayList<Fragment>();
363 }
364 f.setIndex(mActive.size());
365 mActive.add(f);
366
367 } else {
368 f.setIndex(mAvailIndices.remove(mAvailIndices.size()-1));
369 mActive.set(f.mIndex, f);
370 }
371 }
372
373 void makeInactive(Fragment f) {
374 if (f.mIndex < 0) {
375 return;
376 }
377
378 mActive.set(f.mIndex, null);
379 if (mAvailIndices == null) {
380 mAvailIndices = new ArrayList<Integer>();
381 }
382 mAvailIndices.add(f.mIndex);
Dianne Hackborn9e14e9f32010-07-14 11:07:38 -0700383 mActivity.invalidateFragmentIndex(f.mIndex);
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700384 f.clearIndex();
385 }
386
387 public void addFragment(Fragment fragment, boolean moveToStateNow) {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700388 if (DEBUG) Log.v(TAG, "add: " + fragment);
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700389 if (mAdded == null) {
390 mAdded = new ArrayList<Fragment>();
391 }
392 mAdded.add(fragment);
393 makeActive(fragment);
394 fragment.mAdded = true;
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700395 if (fragment.mHasMenu) {
396 mNeedMenuInvalidate = true;
397 }
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700398 if (moveToStateNow) {
Dianne Hackbornf121be72010-05-06 14:10:32 -0700399 moveToState(fragment, mCurState, 0, 0);
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700400 }
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700401 }
402
Dianne Hackbornf121be72010-05-06 14:10:32 -0700403 public void removeFragment(Fragment fragment, int transition, int transitionStyle) {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700404 if (DEBUG) Log.v(TAG, "remove: " + fragment);
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700405 mAdded.remove(fragment);
406 final boolean inactive = fragment.mBackStackNesting <= 0;
407 if (inactive) {
408 makeInactive(fragment);
409 }
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700410 if (fragment.mHasMenu) {
411 mNeedMenuInvalidate = true;
412 }
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700413 fragment.mAdded = false;
414 moveToState(fragment, inactive ? Fragment.INITIALIZING : Fragment.CREATED,
415 transition, transitionStyle);
Dianne Hackbornf121be72010-05-06 14:10:32 -0700416 }
417
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700418 public void hideFragment(Fragment fragment, int transition, int transitionStyle) {
419 if (DEBUG) Log.v(TAG, "hide: " + fragment);
420 if (!fragment.mHidden) {
421 fragment.mHidden = true;
422 if (fragment.mView != null) {
423 Animation anim = loadAnimation(fragment, transition, false,
424 transitionStyle);
425 if (anim != null) {
426 fragment.mView.setAnimation(anim);
427 }
428 fragment.mView.setVisibility(View.GONE);
429 }
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700430 if (fragment.mAdded && fragment.mHasMenu) {
431 mNeedMenuInvalidate = true;
432 }
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700433 fragment.onHiddenChanged(true);
434 }
435 }
436
437 public void showFragment(Fragment fragment, int transition, int transitionStyle) {
438 if (DEBUG) Log.v(TAG, "show: " + fragment);
439 if (fragment.mHidden) {
440 fragment.mHidden = false;
441 if (fragment.mView != null) {
442 Animation anim = loadAnimation(fragment, transition, true,
443 transitionStyle);
444 if (anim != null) {
445 fragment.mView.setAnimation(anim);
446 }
447 fragment.mView.setVisibility(View.VISIBLE);
448 }
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700449 if (fragment.mAdded && fragment.mHasMenu) {
450 mNeedMenuInvalidate = true;
451 }
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700452 fragment.onHiddenChanged(false);
453 }
454 }
455
Dianne Hackbornf121be72010-05-06 14:10:32 -0700456 public Fragment findFragmentById(int id) {
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700457 if (mActive != null) {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700458 // First look through added fragments.
459 for (int i=mAdded.size()-1; i>=0; i--) {
460 Fragment f = mAdded.get(i);
461 if (f != null && f.mFragmentId == id) {
462 return f;
463 }
464 }
465 // Now for any known fragment.
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700466 for (int i=mActive.size()-1; i>=0; i--) {
467 Fragment f = mActive.get(i);
468 if (f != null && f.mFragmentId == id) {
Dianne Hackbornf121be72010-05-06 14:10:32 -0700469 return f;
470 }
471 }
472 }
473 return null;
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700474 }
475
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700476 public Fragment findFragmentByTag(String tag) {
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700477 if (mActive != null && tag != null) {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700478 // First look through added fragments.
479 for (int i=mAdded.size()-1; i>=0; i--) {
480 Fragment f = mAdded.get(i);
481 if (f != null && tag.equals(f.mTag)) {
482 return f;
483 }
484 }
485 // Now for any known fragment.
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700486 for (int i=mActive.size()-1; i>=0; i--) {
487 Fragment f = mActive.get(i);
488 if (f != null && tag.equals(f.mTag)) {
489 return f;
490 }
491 }
492 }
493 return null;
494 }
495
496 public Fragment findFragmentByWho(String who) {
497 if (mActive != null && who != null) {
498 for (int i=mActive.size()-1; i>=0; i--) {
499 Fragment f = mActive.get(i);
500 if (f != null && who.equals(f.mWho)) {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700501 return f;
502 }
503 }
504 }
505 return null;
506 }
507
Dianne Hackborn445646c2010-06-25 15:52:59 -0700508 public void enqueueAction(Runnable action) {
509 synchronized (this) {
510 if (mPendingActions == null) {
511 mPendingActions = new ArrayList<Runnable>();
512 }
513 mPendingActions.add(action);
514 if (mPendingActions.size() == 1) {
515 mActivity.mHandler.removeCallbacks(mExecCommit);
516 mActivity.mHandler.post(mExecCommit);
517 }
518 }
519 }
520
Dianne Hackborndd913a52010-07-22 12:17:04 -0700521 public int allocBackStackIndex(BackStackEntry bse) {
522 synchronized (this) {
523 if (mAvailBackStackIndices == null || mAvailBackStackIndices.size() <= 0) {
524 if (mBackStackIndices == null) {
525 mBackStackIndices = new ArrayList<BackStackEntry>();
526 }
527 int index = mBackStackIndices.size();
528 if (DEBUG) Log.v(TAG, "Setting back stack index " + index + " to " + bse);
529 mBackStackIndices.add(bse);
530 return index;
531
532 } else {
533 int index = mAvailBackStackIndices.remove(mAvailBackStackIndices.size()-1);
534 if (DEBUG) Log.v(TAG, "Adding back stack index " + index + " with " + bse);
535 mBackStackIndices.set(index, bse);
536 return index;
537 }
538 }
539 }
540
541 public void setBackStackIndex(int index, BackStackEntry bse) {
542 synchronized (this) {
543 if (mBackStackIndices == null) {
544 mBackStackIndices = new ArrayList<BackStackEntry>();
545 }
546 int N = mBackStackIndices.size();
547 if (index < N) {
548 if (DEBUG) Log.v(TAG, "Setting back stack index " + index + " to " + bse);
549 mBackStackIndices.set(index, bse);
550 } else {
551 while (N < index) {
552 mBackStackIndices.add(null);
553 if (mAvailBackStackIndices == null) {
554 mAvailBackStackIndices = new ArrayList<Integer>();
555 }
556 if (DEBUG) Log.v(TAG, "Adding available back stack index " + N);
557 mAvailBackStackIndices.add(N);
558 N++;
559 }
560 if (DEBUG) Log.v(TAG, "Adding back stack index " + index + " with " + bse);
561 mBackStackIndices.add(bse);
562 }
563 }
564 }
565
566 public void freeBackStackIndex(int index) {
567 synchronized (this) {
568 mBackStackIndices.set(index, null);
569 if (mAvailBackStackIndices == null) {
570 mAvailBackStackIndices = new ArrayList<Integer>();
571 }
572 if (DEBUG) Log.v(TAG, "Freeing back stack index " + index);
573 mAvailBackStackIndices.add(index);
574 }
575 }
576
Dianne Hackborn445646c2010-06-25 15:52:59 -0700577 /**
578 * Only call from main thread!
579 */
580 public void execPendingActions() {
581 if (mExecutingActions) {
582 throw new IllegalStateException("Recursive entry to execPendingActions");
583 }
584
585 while (true) {
586 int numActions;
587
588 synchronized (this) {
589 if (mPendingActions == null || mPendingActions.size() == 0) {
590 return;
591 }
592
593 numActions = mPendingActions.size();
594 if (mTmpActions == null || mTmpActions.length < numActions) {
595 mTmpActions = new Runnable[numActions];
596 }
597 mPendingActions.toArray(mTmpActions);
598 mPendingActions.clear();
599 mActivity.mHandler.removeCallbacks(mExecCommit);
600 }
601
602 mExecutingActions = true;
603 for (int i=0; i<numActions; i++) {
604 mTmpActions[i].run();
605 }
606 mExecutingActions = false;
607 }
608 }
609
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700610 public void addBackStackState(BackStackEntry state) {
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700611 if (mBackStack == null) {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700612 mBackStack = new ArrayList<BackStackEntry>();
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700613 }
614 mBackStack.add(state);
615 }
616
Dianne Hackborndd913a52010-07-22 12:17:04 -0700617 public boolean popBackStackState(Handler handler, String name, int flags) {
618 return popBackStackState(handler, name, -1, flags);
619 }
620
621 public boolean popBackStackState(Handler handler, int id, int flags) {
622 if (id < 0) {
623 return false;
624 }
625 return popBackStackState(handler, null, id, flags);
626 }
627
628 boolean popBackStackState(Handler handler, String name, int id, int flags) {
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700629 if (mBackStack == null) {
630 return false;
631 }
Dianne Hackborndd913a52010-07-22 12:17:04 -0700632 if (name == null && id < 0) {
Dianne Hackbornf121be72010-05-06 14:10:32 -0700633 int last = mBackStack.size()-1;
634 if (last < 0) {
635 return false;
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700636 }
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700637 final BackStackEntry bss = mBackStack.remove(last);
Dianne Hackborn445646c2010-06-25 15:52:59 -0700638 enqueueAction(new Runnable() {
Dianne Hackbornf121be72010-05-06 14:10:32 -0700639 public void run() {
Dianne Hackborn445646c2010-06-25 15:52:59 -0700640 if (DEBUG) Log.v(TAG, "Popping back stack state: " + bss);
Dianne Hackbornf121be72010-05-06 14:10:32 -0700641 bss.popFromBackStack();
642 moveToState(mCurState, reverseTransit(bss.getTransition()),
643 bss.getTransitionStyle(), true);
644 }
645 });
646 } else {
647 int index = mBackStack.size()-1;
648 while (index >= 0) {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700649 BackStackEntry bss = mBackStack.get(index);
Dianne Hackborndd913a52010-07-22 12:17:04 -0700650 if (name != null && name.equals(bss.getName())) {
Dianne Hackbornf121be72010-05-06 14:10:32 -0700651 break;
652 }
Dianne Hackborndd913a52010-07-22 12:17:04 -0700653 if (id >= 0 && id == bss.mIndex) {
654 break;
655 }
656 index--;
Dianne Hackbornf121be72010-05-06 14:10:32 -0700657 }
Dianne Hackborndd913a52010-07-22 12:17:04 -0700658 if (index < 0) {
659 return false;
660 }
661 if ((flags&Activity.POP_BACK_STACK_INCLUSIVE) != 0) {
662 index--;
663 }
664 if (index == mBackStack.size()-1) {
Dianne Hackbornf121be72010-05-06 14:10:32 -0700665 return false;
666 }
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700667 final ArrayList<BackStackEntry> states
668 = new ArrayList<BackStackEntry>();
Dianne Hackbornf121be72010-05-06 14:10:32 -0700669 for (int i=mBackStack.size()-1; i>index; i--) {
670 states.add(mBackStack.remove(i));
671 }
Dianne Hackborn445646c2010-06-25 15:52:59 -0700672 enqueueAction(new Runnable() {
Dianne Hackbornf121be72010-05-06 14:10:32 -0700673 public void run() {
674 for (int i=0; i<states.size(); i++) {
Dianne Hackborn445646c2010-06-25 15:52:59 -0700675 if (DEBUG) Log.v(TAG, "Popping back stack state: " + states.get(i));
Dianne Hackbornf121be72010-05-06 14:10:32 -0700676 states.get(i).popFromBackStack();
677 }
678 moveToState(mCurState, true);
679 }
680 });
681 }
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700682 return true;
683 }
684
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700685 ArrayList<Fragment> retainNonConfig() {
686 ArrayList<Fragment> fragments = null;
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700687 if (mActive != null) {
688 for (int i=0; i<mActive.size(); i++) {
689 Fragment f = mActive.get(i);
690 if (f != null && f.mRetainInstance) {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700691 if (fragments == null) {
692 fragments = new ArrayList<Fragment>();
693 }
694 fragments.add(f);
695 f.mRetaining = true;
696 }
697 }
698 }
699 return fragments;
700 }
701
702 void saveFragmentViewState(Fragment f) {
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700703 if (f.mView == null) {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700704 return;
705 }
706 if (mStateArray == null) {
707 mStateArray = new SparseArray<Parcelable>();
708 }
709 f.mView.saveHierarchyState(mStateArray);
710 if (mStateArray.size() > 0) {
711 f.mSavedViewState = mStateArray;
712 mStateArray = null;
713 }
714 }
715
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700716 Parcelable saveAllState() {
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700717 if (mActive == null || mActive.size() <= 0) {
718 return null;
719 }
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700720
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700721 // First collect all active fragments.
722 int N = mActive.size();
723 FragmentState[] active = new FragmentState[N];
724 boolean haveFragments = false;
725 for (int i=0; i<N; i++) {
726 Fragment f = mActive.get(i);
727 if (f != null) {
728 haveFragments = true;
729
730 FragmentState fs = new FragmentState(f);
731 active[i] = fs;
732
733 if (mStateBundle == null) {
734 mStateBundle = new Bundle();
735 }
736 f.onSaveInstanceState(mStateBundle);
737 if (!mStateBundle.isEmpty()) {
738 fs.mSavedFragmentState = mStateBundle;
739 mStateBundle = null;
740 }
741
742 if (f.mView != null) {
743 saveFragmentViewState(f);
744 if (f.mSavedViewState != null) {
745 if (fs.mSavedFragmentState == null) {
746 fs.mSavedFragmentState = new Bundle();
747 }
748 fs.mSavedFragmentState.putSparseParcelableArray(
749 FragmentState.VIEW_STATE_TAG, f.mSavedViewState);
750 }
751 }
752
753 }
754 }
755
756 if (!haveFragments) {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700757 return null;
758 }
759
760 int[] added = null;
761 BackStackState[] backStack = null;
762
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700763 // Build list of currently added fragments.
764 N = mAdded.size();
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700765 if (N > 0) {
766 added = new int[N];
767 for (int i=0; i<N; i++) {
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700768 added[i] = mAdded.get(i).mIndex;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700769 }
770 }
771
772 // Now save back stack.
773 if (mBackStack != null) {
774 N = mBackStack.size();
775 if (N > 0) {
776 backStack = new BackStackState[N];
777 for (int i=0; i<N; i++) {
778 backStack[i] = new BackStackState(this, mBackStack.get(i));
779 }
780 }
781 }
782
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700783 FragmentManagerState fms = new FragmentManagerState();
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700784 fms.mActive = active;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700785 fms.mAdded = added;
786 fms.mBackStack = backStack;
787 return fms;
788 }
789
790 void restoreAllState(Parcelable state, ArrayList<Fragment> nonConfig) {
791 // If there is no saved state at all, then there can not be
792 // any nonConfig fragments either, so that is that.
793 if (state == null) return;
794 FragmentManagerState fms = (FragmentManagerState)state;
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700795 if (fms.mActive == null) return;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700796
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700797 // First re-attach any non-config instances we are retaining back
798 // to their saved state, so we don't try to instantiate them again.
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700799 if (nonConfig != null) {
800 for (int i=0; i<nonConfig.size(); i++) {
801 Fragment f = nonConfig.get(i);
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700802 FragmentState fs = fms.mActive[f.mIndex];
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700803 fs.mInstance = f;
804 f.mSavedViewState = null;
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700805 f.mBackStackNesting = 0;
806 f.mAdded = false;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700807 if (fs.mSavedFragmentState != null) {
808 f.mSavedViewState = fs.mSavedFragmentState.getSparseParcelableArray(
809 FragmentState.VIEW_STATE_TAG);
810 }
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700811 }
812 }
813
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700814 // Build the full list of active fragments, instantiating them from
815 // their saved state.
816 mActive = new ArrayList<Fragment>(fms.mActive.length);
817 if (mAvailIndices != null) {
818 mAvailIndices.clear();
819 }
820 for (int i=0; i<fms.mActive.length; i++) {
821 FragmentState fs = fms.mActive[i];
822 if (fs != null) {
823 mActive.add(fs.instantiate(mActivity));
824 } else {
825 mActive.add(null);
826 if (mAvailIndices == null) {
827 mAvailIndices = new ArrayList<Integer>();
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700828 }
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700829 mAvailIndices.add(i);
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700830 }
831 }
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700832
833 // Build the list of currently added fragments.
834 if (fms.mAdded != null) {
835 mAdded = new ArrayList<Fragment>(fms.mAdded.length);
836 for (int i=0; i<fms.mAdded.length; i++) {
837 Fragment f = mActive.get(fms.mAdded[i]);
838 if (f == null) {
839 throw new IllegalStateException(
840 "No instantiated fragment for index #" + fms.mAdded[i]);
841 }
842 f.mAdded = true;
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700843 f.mImmediateActivity = mActivity;
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700844 mAdded.add(f);
845 }
846 } else {
847 mAdded = null;
848 }
849
850 // Build the back stack.
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700851 if (fms.mBackStack != null) {
852 mBackStack = new ArrayList<BackStackEntry>(fms.mBackStack.length);
853 for (int i=0; i<fms.mBackStack.length; i++) {
854 BackStackEntry bse = fms.mBackStack[i].instantiate(this);
855 mBackStack.add(bse);
Dianne Hackborndd913a52010-07-22 12:17:04 -0700856 if (bse.mIndex >= 0) {
857 setBackStackIndex(bse.mIndex, bse);
858 }
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700859 }
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700860 } else {
861 mBackStack = null;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700862 }
863 }
864
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700865 public void attachActivity(Activity activity) {
866 if (mActivity != null) throw new IllegalStateException();
867 mActivity = activity;
868 }
869
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700870 public void dispatchCreate() {
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700871 moveToState(Fragment.CREATED, false);
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700872 }
873
Dianne Hackbornc8017682010-07-06 13:34:38 -0700874 public void dispatchActivityCreated() {
875 moveToState(Fragment.ACTIVITY_CREATED, false);
876 }
877
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700878 public void dispatchStart() {
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700879 moveToState(Fragment.STARTED, false);
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700880 }
881
882 public void dispatchResume() {
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700883 moveToState(Fragment.RESUMED, false);
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700884 }
885
886 public void dispatchPause() {
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700887 moveToState(Fragment.STARTED, false);
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700888 }
889
890 public void dispatchStop() {
Dianne Hackbornc8017682010-07-06 13:34:38 -0700891 moveToState(Fragment.ACTIVITY_CREATED, false);
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700892 }
893
894 public void dispatchDestroy() {
Dianne Hackbornba51c3d2010-05-05 18:49:48 -0700895 moveToState(Fragment.INITIALIZING, false);
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700896 mActivity = null;
897 }
Dianne Hackbornf121be72010-05-06 14:10:32 -0700898
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700899 public boolean dispatchCreateOptionsMenu(Menu menu, MenuInflater inflater) {
900 boolean show = false;
901 if (mActive != null) {
902 for (int i=0; i<mAdded.size(); i++) {
903 Fragment f = mAdded.get(i);
904 if (f != null && !f.mHidden && f.mHasMenu) {
905 show = true;
906 f.onCreateOptionsMenu(menu, inflater);
907 }
908 }
909 }
910 return show;
911 }
912
913 public boolean dispatchPrepareOptionsMenu(Menu menu) {
914 boolean show = false;
915 if (mActive != null) {
916 for (int i=0; i<mAdded.size(); i++) {
917 Fragment f = mAdded.get(i);
918 if (f != null && !f.mHidden && f.mHasMenu) {
919 show = true;
920 f.onPrepareOptionsMenu(menu);
921 }
922 }
923 }
924 return show;
925 }
926
927 public boolean dispatchOptionsItemSelected(MenuItem item) {
928 if (mActive != null) {
929 for (int i=0; i<mAdded.size(); i++) {
930 Fragment f = mAdded.get(i);
931 if (f != null && !f.mHidden && f.mHasMenu) {
932 if (f.onOptionsItemSelected(item)) {
933 return true;
934 }
935 }
936 }
937 }
938 return false;
939 }
940
Dianne Hackborn5ddd1272010-06-12 10:15:28 -0700941 public boolean dispatchContextItemSelected(MenuItem item) {
942 if (mActive != null) {
943 for (int i=0; i<mAdded.size(); i++) {
944 Fragment f = mAdded.get(i);
945 if (f != null && !f.mHidden) {
946 if (f.onContextItemSelected(item)) {
947 return true;
948 }
949 }
950 }
951 }
952 return false;
953 }
954
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700955 public void dispatchOptionsMenuClosed(Menu menu) {
956 if (mActive != null) {
957 for (int i=0; i<mAdded.size(); i++) {
958 Fragment f = mAdded.get(i);
959 if (f != null && !f.mHidden && f.mHasMenu) {
960 f.onOptionsMenuClosed(menu);
961 }
962 }
963 }
964 }
965
Dianne Hackbornf121be72010-05-06 14:10:32 -0700966 public static int reverseTransit(int transit) {
967 int rev = 0;
968 switch (transit) {
969 case FragmentTransaction.TRANSIT_ENTER:
970 rev = FragmentTransaction.TRANSIT_EXIT;
971 break;
972 case FragmentTransaction.TRANSIT_EXIT:
973 rev = FragmentTransaction.TRANSIT_ENTER;
974 break;
975 case FragmentTransaction.TRANSIT_SHOW:
976 rev = FragmentTransaction.TRANSIT_HIDE;
977 break;
978 case FragmentTransaction.TRANSIT_HIDE:
979 rev = FragmentTransaction.TRANSIT_SHOW;
980 break;
981 case FragmentTransaction.TRANSIT_ACTIVITY_OPEN:
982 rev = FragmentTransaction.TRANSIT_ACTIVITY_CLOSE;
983 break;
984 case FragmentTransaction.TRANSIT_ACTIVITY_CLOSE:
985 rev = FragmentTransaction.TRANSIT_ACTIVITY_OPEN;
986 break;
987 case FragmentTransaction.TRANSIT_TASK_OPEN:
988 rev = FragmentTransaction.TRANSIT_TASK_CLOSE;
989 break;
990 case FragmentTransaction.TRANSIT_TASK_CLOSE:
991 rev = FragmentTransaction.TRANSIT_TASK_OPEN;
992 break;
993 case FragmentTransaction.TRANSIT_TASK_TO_FRONT:
994 rev = FragmentTransaction.TRANSIT_TASK_TO_BACK;
995 break;
996 case FragmentTransaction.TRANSIT_TASK_TO_BACK:
997 rev = FragmentTransaction.TRANSIT_TASK_TO_FRONT;
998 break;
999 case FragmentTransaction.TRANSIT_WALLPAPER_OPEN:
1000 rev = FragmentTransaction.TRANSIT_WALLPAPER_CLOSE;
1001 break;
1002 case FragmentTransaction.TRANSIT_WALLPAPER_CLOSE:
1003 rev = FragmentTransaction.TRANSIT_WALLPAPER_OPEN;
1004 break;
1005 case FragmentTransaction.TRANSIT_WALLPAPER_INTRA_OPEN:
1006 rev = FragmentTransaction.TRANSIT_WALLPAPER_INTRA_CLOSE;
1007 break;
1008 case FragmentTransaction.TRANSIT_WALLPAPER_INTRA_CLOSE:
1009 rev = FragmentTransaction.TRANSIT_WALLPAPER_INTRA_OPEN;
1010 break;
1011 }
1012 return rev;
1013
1014 }
1015
1016 public static int transitToStyleIndex(int transit, boolean enter) {
1017 int animAttr = -1;
1018 switch (transit) {
1019 case FragmentTransaction.TRANSIT_ENTER:
1020 animAttr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
1021 break;
1022 case FragmentTransaction.TRANSIT_EXIT:
1023 animAttr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
1024 break;
1025 case FragmentTransaction.TRANSIT_SHOW:
1026 animAttr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
1027 break;
1028 case FragmentTransaction.TRANSIT_HIDE:
1029 animAttr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
1030 break;
1031 case FragmentTransaction.TRANSIT_ACTIVITY_OPEN:
1032 animAttr = enter
1033 ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
1034 : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
1035 break;
1036 case FragmentTransaction.TRANSIT_ACTIVITY_CLOSE:
1037 animAttr = enter
1038 ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
1039 : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
1040 break;
1041 case FragmentTransaction.TRANSIT_TASK_OPEN:
1042 animAttr = enter
1043 ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
1044 : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
1045 break;
1046 case FragmentTransaction.TRANSIT_TASK_CLOSE:
1047 animAttr = enter
1048 ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
1049 : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
1050 break;
1051 case FragmentTransaction.TRANSIT_TASK_TO_FRONT:
1052 animAttr = enter
1053 ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
1054 : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
1055 break;
1056 case FragmentTransaction.TRANSIT_TASK_TO_BACK:
1057 animAttr = enter
1058 ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
1059 : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
1060 break;
1061 case FragmentTransaction.TRANSIT_WALLPAPER_OPEN:
1062 animAttr = enter
1063 ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
1064 : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
1065 break;
1066 case FragmentTransaction.TRANSIT_WALLPAPER_CLOSE:
1067 animAttr = enter
1068 ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
1069 : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
1070 break;
1071 case FragmentTransaction.TRANSIT_WALLPAPER_INTRA_OPEN:
1072 animAttr = enter
1073 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
1074 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
1075 break;
1076 case FragmentTransaction.TRANSIT_WALLPAPER_INTRA_CLOSE:
1077 animAttr = enter
1078 ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
1079 : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
1080 break;
1081 }
1082 return animAttr;
1083 }
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001084}