FragmentManager.java revision 5ae74d6e89a30e79ea85c487b32223ef55314985
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
17package android.app;
18
19import android.content.res.TypedArray;
20import android.os.Bundle;
21import android.os.Handler;
22import android.os.Parcel;
23import android.os.Parcelable;
24import android.util.Log;
25import android.util.SparseArray;
26import android.view.View;
27import android.view.ViewGroup;
28import android.view.animation.Animation;
29import android.view.animation.AnimationUtils;
30
31import java.util.ArrayList;
32
33final class FragmentManagerState implements Parcelable {
34    FragmentState[] mActive;
35    int[] mAdded;
36    BackStackState[] mBackStack;
37
38    public FragmentManagerState() {
39    }
40
41    public FragmentManagerState(Parcel in) {
42        mActive = in.createTypedArray(FragmentState.CREATOR);
43        mAdded = in.createIntArray();
44        mBackStack = in.createTypedArray(BackStackState.CREATOR);
45    }
46
47    public int describeContents() {
48        return 0;
49    }
50
51    public void writeToParcel(Parcel dest, int flags) {
52        dest.writeTypedArray(mActive, flags);
53        dest.writeIntArray(mAdded);
54        dest.writeTypedArray(mBackStack, flags);
55    }
56
57    public static final Parcelable.Creator<FragmentManagerState> CREATOR
58            = new Parcelable.Creator<FragmentManagerState>() {
59        public FragmentManagerState createFromParcel(Parcel in) {
60            return new FragmentManagerState(in);
61        }
62
63        public FragmentManagerState[] newArray(int size) {
64            return new FragmentManagerState[size];
65        }
66    };
67}
68
69/**
70 * @hide
71 * Container for fragments associated with an activity.
72 */
73public class FragmentManager {
74    static final boolean DEBUG = true;
75    static final String TAG = "FragmentManager";
76
77    ArrayList<Fragment> mActive;
78    ArrayList<Fragment> mAdded;
79    ArrayList<Integer> mAvailIndices;
80    ArrayList<BackStackEntry> mBackStack;
81
82    int mCurState = Fragment.INITIALIZING;
83    Activity mActivity;
84
85    // Temporary vars for state save and restore.
86    Bundle mStateBundle = null;
87    SparseArray<Parcelable> mStateArray = null;
88
89    Animation loadAnimation(Fragment fragment, int transit, boolean enter,
90            int transitionStyle) {
91        Animation animObj = fragment.onCreateAnimation(transitionStyle, enter,
92                fragment.mNextAnim);
93        if (animObj != null) {
94            return animObj;
95        }
96
97        if (fragment.mNextAnim != 0) {
98            Animation anim = AnimationUtils.loadAnimation(mActivity, fragment.mNextAnim);
99            if (anim != null) {
100                return anim;
101            }
102        }
103
104        if (transit == 0) {
105            return null;
106        }
107
108        int styleIndex = transitToStyleIndex(transit, enter);
109        if (styleIndex < 0) {
110            return null;
111        }
112
113        if (transitionStyle == 0 && mActivity.getWindow() != null) {
114            transitionStyle = mActivity.getWindow().getAttributes().windowAnimations;
115        }
116        if (transitionStyle == 0) {
117            return null;
118        }
119
120        TypedArray attrs = mActivity.obtainStyledAttributes(transitionStyle,
121                com.android.internal.R.styleable.WindowAnimation);
122        int anim = attrs.getResourceId(styleIndex, 0);
123        attrs.recycle();
124
125        if (anim == 0) {
126            return null;
127        }
128
129        return AnimationUtils.loadAnimation(mActivity, anim);
130    }
131
132    void moveToState(Fragment f, int newState, int transit, int transitionStyle) {
133        // Fragments that are not currently added will sit in the onCreate() state.
134        if (!f.mAdded && newState > Fragment.CREATED) {
135            newState = Fragment.CREATED;
136        }
137
138        if (f.mState < newState) {
139            switch (f.mState) {
140                case Fragment.INITIALIZING:
141                    if (DEBUG) Log.v(TAG, "moveto CREATED: " + f);
142                    f.mActivity = mActivity;
143                    f.mCalled = false;
144                    f.onAttach(mActivity);
145                    if (!f.mCalled) {
146                        throw new SuperNotCalledException("Fragment " + f
147                                + " did not call through to super.onAttach()");
148                    }
149
150                    if (!f.mRetaining) {
151                        f.mCalled = false;
152                        f.onCreate(f.mSavedFragmentState);
153                        if (!f.mCalled) {
154                            throw new SuperNotCalledException("Fragment " + f
155                                    + " did not call through to super.onCreate()");
156                        }
157                    }
158                    f.mRetaining = false;
159                    if (f.mFromLayout) {
160                        // For fragments that are part of the content view
161                        // layout, we need to instantiate the view immediately
162                        // and the inflater will take care of adding it.
163                        f.mView = f.onCreateView(mActivity.getLayoutInflater(),
164                                null, f.mSavedFragmentState);
165                        if (f.mView != null) {
166                            f.mView.setSaveFromParentEnabled(false);
167                            f.restoreViewState();
168                            if (f.mHidden) f.mView.setVisibility(View.GONE);
169                        }
170                    }
171                case Fragment.CREATED:
172                    if (newState > Fragment.CREATED) {
173                        if (DEBUG) Log.v(TAG, "moveto CONTENT: " + f);
174                        if (!f.mFromLayout) {
175                            ViewGroup container = null;
176                            if (f.mContainerId != 0) {
177                                container = (ViewGroup)mActivity.findViewById(f.mContainerId);
178                                if (container == null) {
179                                    throw new IllegalArgumentException("New view found for id 0x"
180                                            + Integer.toHexString(f.mContainerId)
181                                            + " for fragment " + f);
182                                }
183                            }
184                            f.mContainer = container;
185                            f.mView = f.onCreateView(mActivity.getLayoutInflater(),
186                                    container, f.mSavedFragmentState);
187                            if (f.mView != null) {
188                                f.mView.setSaveFromParentEnabled(false);
189                                if (container != null) {
190                                    Animation anim = loadAnimation(f, transit, true,
191                                            transitionStyle);
192                                    if (anim != null) {
193                                        f.mView.setAnimation(anim);
194                                    }
195                                    container.addView(f.mView);
196                                    f.restoreViewState();
197                                }
198                                if (f.mHidden) f.mView.setVisibility(View.GONE);
199                            }
200                        }
201
202                        f.mCalled = false;
203                        f.onReady(f.mSavedFragmentState);
204                        if (!f.mCalled) {
205                            throw new SuperNotCalledException("Fragment " + f
206                                    + " did not call through to super.onReady()");
207                        }
208                        f.mSavedFragmentState = null;
209                    }
210                case Fragment.CONTENT:
211                    if (newState > Fragment.CONTENT) {
212                        if (DEBUG) Log.v(TAG, "moveto STARTED: " + f);
213                        f.mCalled = false;
214                        f.onStart();
215                        if (!f.mCalled) {
216                            throw new SuperNotCalledException("Fragment " + f
217                                    + " did not call through to super.onStart()");
218                        }
219                    }
220                case Fragment.STARTED:
221                    if (newState > Fragment.STARTED) {
222                        if (DEBUG) Log.v(TAG, "moveto RESUMED: " + f);
223                        f.mCalled = false;
224                        f.onResume();
225                        if (!f.mCalled) {
226                            throw new SuperNotCalledException("Fragment " + f
227                                    + " did not call through to super.onResume()");
228                        }
229                    }
230            }
231        } else if (f.mState > newState) {
232            switch (f.mState) {
233                case Fragment.RESUMED:
234                    if (newState < Fragment.RESUMED) {
235                        if (DEBUG) Log.v(TAG, "movefrom RESUMED: " + f);
236                        f.mCalled = false;
237                        f.onPause();
238                        if (!f.mCalled) {
239                            throw new SuperNotCalledException("Fragment " + f
240                                    + " did not call through to super.onPause()");
241                        }
242                    }
243                case Fragment.STARTED:
244                    if (newState < Fragment.STARTED) {
245                        if (DEBUG) Log.v(TAG, "movefrom STARTED: " + f);
246                        f.mCalled = false;
247                        f.onStop();
248                        if (!f.mCalled) {
249                            throw new SuperNotCalledException("Fragment " + f
250                                    + " did not call through to super.onStop()");
251                        }
252                    }
253                case Fragment.CONTENT:
254                    if (newState < Fragment.CONTENT) {
255                        if (DEBUG) Log.v(TAG, "movefrom CONTENT: " + f);
256                        if (f.mView != null) {
257                            // Need to save the current view state if not
258                            // done already.
259                            if (!mActivity.isFinishing() && f.mSavedFragmentState == null) {
260                                saveFragmentViewState(f);
261                            }
262                            if (f.mContainer != null) {
263                                if (mCurState > Fragment.INITIALIZING) {
264                                    Animation anim = loadAnimation(f, transit, false,
265                                            transitionStyle);
266                                    if (anim != null) {
267                                        f.mView.setAnimation(anim);
268                                    }
269                                }
270                                f.mContainer.removeView(f.mView);
271                            }
272                        }
273                        f.mContainer = null;
274                        f.mView = null;
275                    }
276                case Fragment.CREATED:
277                    if (newState < Fragment.CREATED) {
278                        if (DEBUG) Log.v(TAG, "movefrom CREATED: " + f);
279                        if (!f.mRetaining) {
280                            f.mCalled = false;
281                            f.onDestroy();
282                            if (!f.mCalled) {
283                                throw new SuperNotCalledException("Fragment " + f
284                                        + " did not call through to super.onDestroy()");
285                            }
286                        }
287
288                        f.mCalled = false;
289                        f.onDetach();
290                        if (!f.mCalled) {
291                            throw new SuperNotCalledException("Fragment " + f
292                                    + " did not call through to super.onDetach()");
293                        }
294                        f.mActivity = null;
295                    }
296            }
297        }
298
299        f.mState = newState;
300    }
301
302    void moveToState(int newState, boolean always) {
303        moveToState(newState, 0, 0, always);
304    }
305
306    void moveToState(int newState, int transit, int transitStyle, boolean always) {
307        if (mActivity == null && newState != Fragment.INITIALIZING) {
308            throw new IllegalStateException("No activity");
309        }
310
311        if (!always && mCurState == newState) {
312            return;
313        }
314
315        mCurState = newState;
316        if (mActive != null) {
317            for (int i=0; i<mActive.size(); i++) {
318                Fragment f = mActive.get(i);
319                if (f != null) {
320                    moveToState(f, newState, transit, transitStyle);
321                }
322            }
323        }
324    }
325
326    void makeActive(Fragment f) {
327        if (f.mIndex >= 0) {
328            return;
329        }
330
331        if (mAvailIndices == null || mAvailIndices.size() <= 0) {
332            if (mActive == null) {
333                mActive = new ArrayList<Fragment>();
334            }
335            f.setIndex(mActive.size());
336            mActive.add(f);
337
338        } else {
339            f.setIndex(mAvailIndices.remove(mAvailIndices.size()-1));
340            mActive.set(f.mIndex, f);
341        }
342    }
343
344    void makeInactive(Fragment f) {
345        if (f.mIndex < 0) {
346            return;
347        }
348
349        mActive.set(f.mIndex, null);
350        if (mAvailIndices == null) {
351            mAvailIndices = new ArrayList<Integer>();
352        }
353        mAvailIndices.add(f.mIndex);
354        f.clearIndex();
355    }
356
357    public void addFragment(Fragment fragment, boolean moveToStateNow) {
358        if (DEBUG) Log.v(TAG, "add: " + fragment);
359        if (mAdded == null) {
360            mAdded = new ArrayList<Fragment>();
361        }
362        mAdded.add(fragment);
363        makeActive(fragment);
364        fragment.mAdded = true;
365        if (moveToStateNow) {
366            moveToState(fragment, mCurState, 0, 0);
367        }
368    }
369
370    public void removeFragment(Fragment fragment, int transition, int transitionStyle) {
371        if (DEBUG) Log.v(TAG, "remove: " + fragment);
372        mAdded.remove(fragment);
373        final boolean inactive = fragment.mBackStackNesting <= 0;
374        if (inactive) {
375            makeInactive(fragment);
376        }
377        fragment.mAdded = false;
378        moveToState(fragment, inactive ? Fragment.INITIALIZING : Fragment.CREATED,
379                transition, transitionStyle);
380    }
381
382    public void hideFragment(Fragment fragment, int transition, int transitionStyle) {
383        if (DEBUG) Log.v(TAG, "hide: " + fragment);
384        if (!fragment.mHidden) {
385            fragment.mHidden = true;
386            if (fragment.mView != null) {
387                Animation anim = loadAnimation(fragment, transition, false,
388                        transitionStyle);
389                if (anim != null) {
390                    fragment.mView.setAnimation(anim);
391                }
392                fragment.mView.setVisibility(View.GONE);
393            }
394            fragment.onHiddenChanged(true);
395        }
396    }
397
398    public void showFragment(Fragment fragment, int transition, int transitionStyle) {
399        if (DEBUG) Log.v(TAG, "show: " + fragment);
400        if (fragment.mHidden) {
401            fragment.mHidden = false;
402            if (fragment.mView != null) {
403                Animation anim = loadAnimation(fragment, transition, true,
404                        transitionStyle);
405                if (anim != null) {
406                    fragment.mView.setAnimation(anim);
407                }
408                fragment.mView.setVisibility(View.VISIBLE);
409            }
410            fragment.onHiddenChanged(false);
411        }
412    }
413
414    public Fragment findFragmentById(int id) {
415        if (mActive != null) {
416            // First look through added fragments.
417            for (int i=mAdded.size()-1; i>=0; i--) {
418                Fragment f = mAdded.get(i);
419                if (f != null && f.mFragmentId == id) {
420                    return f;
421                }
422            }
423            // Now for any known fragment.
424            for (int i=mActive.size()-1; i>=0; i--) {
425                Fragment f = mActive.get(i);
426                if (f != null && f.mFragmentId == id) {
427                    return f;
428                }
429            }
430        }
431        return null;
432    }
433
434    public Fragment findFragmentByTag(String tag) {
435        if (mActive != null && tag != null) {
436            // First look through added fragments.
437            for (int i=mAdded.size()-1; i>=0; i--) {
438                Fragment f = mAdded.get(i);
439                if (f != null && tag.equals(f.mTag)) {
440                    return f;
441                }
442            }
443            // Now for any known fragment.
444            for (int i=mActive.size()-1; i>=0; i--) {
445                Fragment f = mActive.get(i);
446                if (f != null && tag.equals(f.mTag)) {
447                    return f;
448                }
449            }
450        }
451        return null;
452    }
453
454    public Fragment findFragmentByWho(String who) {
455        if (mActive != null && who != null) {
456            for (int i=mActive.size()-1; i>=0; i--) {
457                Fragment f = mActive.get(i);
458                if (f != null && who.equals(f.mWho)) {
459                    return f;
460                }
461            }
462        }
463        return null;
464    }
465
466    public void addBackStackState(BackStackEntry state) {
467        if (mBackStack == null) {
468            mBackStack = new ArrayList<BackStackEntry>();
469        }
470        mBackStack.add(state);
471    }
472
473    public boolean popBackStackState(Handler handler, String name) {
474        if (mBackStack == null) {
475            return false;
476        }
477        if (name == null) {
478            int last = mBackStack.size()-1;
479            if (last < 0) {
480                return false;
481            }
482            final BackStackEntry bss = mBackStack.remove(last);
483            handler.post(new Runnable() {
484                public void run() {
485                    bss.popFromBackStack();
486                    moveToState(mCurState, reverseTransit(bss.getTransition()),
487                            bss.getTransitionStyle(), true);
488                }
489            });
490        } else {
491            int index = mBackStack.size()-1;
492            while (index >= 0) {
493                BackStackEntry bss = mBackStack.get(index);
494                if (name.equals(bss.getName())) {
495                    break;
496                }
497            }
498            if (index < 0 || index == mBackStack.size()-1) {
499                return false;
500            }
501            final ArrayList<BackStackEntry> states
502                    = new ArrayList<BackStackEntry>();
503            for (int i=mBackStack.size()-1; i>index; i--) {
504                states.add(mBackStack.remove(i));
505            }
506            handler.post(new Runnable() {
507                public void run() {
508                    for (int i=0; i<states.size(); i++) {
509                        states.get(i).popFromBackStack();
510                    }
511                    moveToState(mCurState, true);
512                }
513            });
514        }
515        return true;
516    }
517
518    ArrayList<Fragment> retainNonConfig() {
519        ArrayList<Fragment> fragments = null;
520        if (mActive != null) {
521            for (int i=0; i<mActive.size(); i++) {
522                Fragment f = mActive.get(i);
523                if (f != null && f.mRetainInstance) {
524                    if (fragments == null) {
525                        fragments = new ArrayList<Fragment>();
526                    }
527                    fragments.add(f);
528                    f.mRetaining = true;
529                }
530            }
531        }
532        return fragments;
533    }
534
535    void saveFragmentViewState(Fragment f) {
536        if (f.mView == null) {
537            return;
538        }
539        if (mStateArray == null) {
540            mStateArray = new SparseArray<Parcelable>();
541        }
542        f.mView.saveHierarchyState(mStateArray);
543        if (mStateArray.size() > 0) {
544            f.mSavedViewState = mStateArray;
545            mStateArray = null;
546        }
547    }
548
549    Parcelable saveAllState() {
550        if (mActive == null || mActive.size() <= 0) {
551            return null;
552        }
553
554        // First collect all active fragments.
555        int N = mActive.size();
556        FragmentState[] active = new FragmentState[N];
557        boolean haveFragments = false;
558        for (int i=0; i<N; i++) {
559            Fragment f = mActive.get(i);
560            if (f != null) {
561                haveFragments = true;
562
563                FragmentState fs = new FragmentState(f);
564                active[i] = fs;
565
566                if (mStateBundle == null) {
567                    mStateBundle = new Bundle();
568                }
569                f.onSaveInstanceState(mStateBundle);
570                if (!mStateBundle.isEmpty()) {
571                    fs.mSavedFragmentState = mStateBundle;
572                    mStateBundle = null;
573                }
574
575                if (f.mView != null) {
576                    saveFragmentViewState(f);
577                    if (f.mSavedViewState != null) {
578                        if (fs.mSavedFragmentState == null) {
579                            fs.mSavedFragmentState = new Bundle();
580                        }
581                        fs.mSavedFragmentState.putSparseParcelableArray(
582                                FragmentState.VIEW_STATE_TAG, f.mSavedViewState);
583                    }
584                }
585
586            }
587        }
588
589        if (!haveFragments) {
590            return null;
591        }
592
593        int[] added = null;
594        BackStackState[] backStack = null;
595
596        // Build list of currently added fragments.
597        N = mAdded.size();
598        if (N > 0) {
599            added = new int[N];
600            for (int i=0; i<N; i++) {
601                added[i] = mAdded.get(i).mIndex;
602            }
603        }
604
605        // Now save back stack.
606        if (mBackStack != null) {
607            N = mBackStack.size();
608            if (N > 0) {
609                backStack = new BackStackState[N];
610                for (int i=0; i<N; i++) {
611                    backStack[i] = new BackStackState(this, mBackStack.get(i));
612                }
613            }
614        }
615
616        FragmentManagerState fms = new FragmentManagerState();
617        fms.mActive = active;
618        fms.mAdded = added;
619        fms.mBackStack = backStack;
620        return fms;
621    }
622
623    void restoreAllState(Parcelable state, ArrayList<Fragment> nonConfig) {
624        // If there is no saved state at all, then there can not be
625        // any nonConfig fragments either, so that is that.
626        if (state == null) return;
627        FragmentManagerState fms = (FragmentManagerState)state;
628        if (fms.mActive == null) return;
629
630        // First re-attach any non-config instances we are retaining back
631        // to their saved state, so we don't try to instantiate them again.
632        if (nonConfig != null) {
633            for (int i=0; i<nonConfig.size(); i++) {
634                Fragment f = nonConfig.get(i);
635                FragmentState fs = fms.mActive[f.mIndex];
636                fs.mInstance = f;
637                f.mSavedViewState = null;
638                f.mBackStackNesting = 0;
639                f.mAdded = false;
640                if (fs.mSavedFragmentState != null) {
641                    f.mSavedViewState = fs.mSavedFragmentState.getSparseParcelableArray(
642                            FragmentState.VIEW_STATE_TAG);
643                }
644            }
645        }
646
647        // Build the full list of active fragments, instantiating them from
648        // their saved state.
649        mActive = new ArrayList<Fragment>(fms.mActive.length);
650        if (mAvailIndices != null) {
651            mAvailIndices.clear();
652        }
653        for (int i=0; i<fms.mActive.length; i++) {
654            FragmentState fs = fms.mActive[i];
655            if (fs != null) {
656                mActive.add(fs.instantiate(mActivity));
657            } else {
658                mActive.add(null);
659                if (mAvailIndices == null) {
660                    mAvailIndices = new ArrayList<Integer>();
661                }
662                mAvailIndices.add(i);
663            }
664        }
665
666        // Build the list of currently added fragments.
667        if (fms.mAdded != null) {
668            mAdded = new ArrayList<Fragment>(fms.mAdded.length);
669            for (int i=0; i<fms.mAdded.length; i++) {
670                Fragment f = mActive.get(fms.mAdded[i]);
671                if (f == null) {
672                    throw new IllegalStateException(
673                            "No instantiated fragment for index #" + fms.mAdded[i]);
674                }
675                f.mAdded = true;
676                mAdded.add(f);
677            }
678        } else {
679            mAdded = null;
680        }
681
682        // Build the back stack.
683        if (fms.mBackStack != null) {
684            mBackStack = new ArrayList<BackStackEntry>(fms.mBackStack.length);
685            for (int i=0; i<fms.mBackStack.length; i++) {
686                BackStackEntry bse = fms.mBackStack[i].instantiate(this);
687                mBackStack.add(bse);
688            }
689        } else {
690            mBackStack = null;
691        }
692    }
693
694    public void attachActivity(Activity activity) {
695        if (mActivity != null) throw new IllegalStateException();
696        mActivity = activity;
697    }
698
699    public void dispatchCreate() {
700        moveToState(Fragment.CREATED, false);
701    }
702
703    public void dispatchStart() {
704        moveToState(Fragment.STARTED, false);
705    }
706
707    public void dispatchResume() {
708        moveToState(Fragment.RESUMED, false);
709    }
710
711    public void dispatchPause() {
712        moveToState(Fragment.STARTED, false);
713    }
714
715    public void dispatchStop() {
716        moveToState(Fragment.CONTENT, false);
717    }
718
719    public void dispatchDestroy() {
720        moveToState(Fragment.INITIALIZING, false);
721        mActivity = null;
722    }
723
724    public static int reverseTransit(int transit) {
725        int rev = 0;
726        switch (transit) {
727            case FragmentTransaction.TRANSIT_ENTER:
728                rev = FragmentTransaction.TRANSIT_EXIT;
729                break;
730            case FragmentTransaction.TRANSIT_EXIT:
731                rev = FragmentTransaction.TRANSIT_ENTER;
732                break;
733            case FragmentTransaction.TRANSIT_SHOW:
734                rev = FragmentTransaction.TRANSIT_HIDE;
735                break;
736            case FragmentTransaction.TRANSIT_HIDE:
737                rev = FragmentTransaction.TRANSIT_SHOW;
738                break;
739            case FragmentTransaction.TRANSIT_ACTIVITY_OPEN:
740                rev = FragmentTransaction.TRANSIT_ACTIVITY_CLOSE;
741                break;
742            case FragmentTransaction.TRANSIT_ACTIVITY_CLOSE:
743                rev = FragmentTransaction.TRANSIT_ACTIVITY_OPEN;
744                break;
745            case FragmentTransaction.TRANSIT_TASK_OPEN:
746                rev = FragmentTransaction.TRANSIT_TASK_CLOSE;
747                break;
748            case FragmentTransaction.TRANSIT_TASK_CLOSE:
749                rev = FragmentTransaction.TRANSIT_TASK_OPEN;
750                break;
751            case FragmentTransaction.TRANSIT_TASK_TO_FRONT:
752                rev = FragmentTransaction.TRANSIT_TASK_TO_BACK;
753                break;
754            case FragmentTransaction.TRANSIT_TASK_TO_BACK:
755                rev = FragmentTransaction.TRANSIT_TASK_TO_FRONT;
756                break;
757            case FragmentTransaction.TRANSIT_WALLPAPER_OPEN:
758                rev = FragmentTransaction.TRANSIT_WALLPAPER_CLOSE;
759                break;
760            case FragmentTransaction.TRANSIT_WALLPAPER_CLOSE:
761                rev = FragmentTransaction.TRANSIT_WALLPAPER_OPEN;
762                break;
763            case FragmentTransaction.TRANSIT_WALLPAPER_INTRA_OPEN:
764                rev = FragmentTransaction.TRANSIT_WALLPAPER_INTRA_CLOSE;
765                break;
766            case FragmentTransaction.TRANSIT_WALLPAPER_INTRA_CLOSE:
767                rev = FragmentTransaction.TRANSIT_WALLPAPER_INTRA_OPEN;
768                break;
769        }
770        return rev;
771
772    }
773
774    public static int transitToStyleIndex(int transit, boolean enter) {
775        int animAttr = -1;
776        switch (transit) {
777            case FragmentTransaction.TRANSIT_ENTER:
778                animAttr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
779                break;
780            case FragmentTransaction.TRANSIT_EXIT:
781                animAttr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
782                break;
783            case FragmentTransaction.TRANSIT_SHOW:
784                animAttr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
785                break;
786            case FragmentTransaction.TRANSIT_HIDE:
787                animAttr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
788                break;
789            case FragmentTransaction.TRANSIT_ACTIVITY_OPEN:
790                animAttr = enter
791                        ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation
792                        : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
793                break;
794            case FragmentTransaction.TRANSIT_ACTIVITY_CLOSE:
795                animAttr = enter
796                        ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation
797                        : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
798                break;
799            case FragmentTransaction.TRANSIT_TASK_OPEN:
800                animAttr = enter
801                        ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation
802                        : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
803                break;
804            case FragmentTransaction.TRANSIT_TASK_CLOSE:
805                animAttr = enter
806                        ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation
807                        : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
808                break;
809            case FragmentTransaction.TRANSIT_TASK_TO_FRONT:
810                animAttr = enter
811                        ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation
812                        : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
813                break;
814            case FragmentTransaction.TRANSIT_TASK_TO_BACK:
815                animAttr = enter
816                        ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation
817                        : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
818                break;
819            case FragmentTransaction.TRANSIT_WALLPAPER_OPEN:
820                animAttr = enter
821                        ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation
822                        : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
823                break;
824            case FragmentTransaction.TRANSIT_WALLPAPER_CLOSE:
825                animAttr = enter
826                        ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
827                        : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
828                break;
829            case FragmentTransaction.TRANSIT_WALLPAPER_INTRA_OPEN:
830                animAttr = enter
831                        ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation
832                        : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
833                break;
834            case FragmentTransaction.TRANSIT_WALLPAPER_INTRA_CLOSE:
835                animAttr = enter
836                        ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation
837                        : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
838                break;
839        }
840        return animAttr;
841    }
842}
843