2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.support.v2.app;
20 * Static library support version of the framework's {@link android.app.FragmentTransaction}.
21 * Used to write apps that run on platforms prior to Android 3.0. When running
22 * on Android 3.0 or above, this implementation is still used; it does not try
23 * to switch to the framework's implementation. See the framework SDK
24 * documentation for a class overview.
26 public abstract class FragmentTransaction {
28 * Calls {@link #add(int, Fragment, String)} with a 0 containerViewId.
30 public abstract FragmentTransaction add(Fragment fragment, String tag);
33 * Calls {@link #add(int, Fragment, String)} with a null tag.
35 public abstract FragmentTransaction add(int containerViewId, Fragment fragment);
38 * Add a fragment to the activity state. This fragment may optionally
39 * also have its view (if {@link Fragment#onCreateView Fragment.onCreateView}
40 * returns non-null) into a container view of the activity.
42 * @param containerViewId Optional identifier of the container this fragment is
43 * to be placed in. If 0, it will not be placed in a container.
44 * @param fragment The fragment to be added. This fragment must not already
45 * be added to the activity.
46 * @param tag Optional tag name for the fragment, to later retrieve the
47 * fragment with {@link FragmentManager#findFragmentByTag(String)
48 * FragmentManager.findFragmentByTag(String)}.
50 * @return Returns the same FragmentTransaction instance.
52 public abstract FragmentTransaction add(int containerViewId, Fragment fragment, String tag);
55 * Calls {@link #replace(int, Fragment, String)} with a null tag.
57 public abstract FragmentTransaction replace(int containerViewId, Fragment fragment);
60 * Replace an existing fragment that was added to a container. This is
61 * essentially the same as calling {@link #remove(Fragment)} for all
62 * currently added fragments that were added with the same containerViewId
63 * and then {@link #add(int, Fragment, String)} with the same arguments
66 * @param containerViewId Identifier of the container whose fragment(s) are
68 * @param fragment The new fragment to place in the container.
69 * @param tag Optional tag name for the fragment, to later retrieve the
70 * fragment with {@link FragmentManager#findFragmentByTag(String)
71 * FragmentManager.findFragmentByTag(String)}.
73 * @return Returns the same FragmentTransaction instance.
75 public abstract FragmentTransaction replace(int containerViewId, Fragment fragment, String tag);
78 * Remove an existing fragment. If it was added to a container, its view
79 * is also removed from that container.
81 * @param fragment The fragment to be removed.
83 * @return Returns the same FragmentTransaction instance.
85 public abstract FragmentTransaction remove(Fragment fragment);
88 * Hides an existing fragment. This is only relevant for fragments whose
89 * views have been added to a container, as this will cause the view to
92 * @param fragment The fragment to be hidden.
94 * @return Returns the same FragmentTransaction instance.
96 public abstract FragmentTransaction hide(Fragment fragment);
99 * Shows a previously hidden fragment. This is only relevant for fragments whose
100 * views have been added to a container, as this will cause the view to
103 * @param fragment The fragment to be shown.
105 * @return Returns the same FragmentTransaction instance.
107 public abstract FragmentTransaction show(Fragment fragment);
110 * @return <code>true</code> if this transaction contains no operations,
111 * <code>false</code> otherwise.
113 public abstract boolean isEmpty();
116 * Bit mask that is set for all enter transitions.
118 public static final int TRANSIT_ENTER_MASK = 0x1000;
121 * Bit mask that is set for all exit transitions.
123 public static final int TRANSIT_EXIT_MASK = 0x2000;
125 /** Not set up for a transition. */
126 public static final int TRANSIT_UNSET = -1;
127 /** No animation for transition. */
128 public static final int TRANSIT_NONE = 0;
129 /** Fragment is being added onto the stack */
130 public static final int TRANSIT_FRAGMENT_OPEN = 1 | TRANSIT_ENTER_MASK;
131 /** Fragment is being removed from the stack */
132 public static final int TRANSIT_FRAGMENT_CLOSE = 2 | TRANSIT_EXIT_MASK;
133 /** Fragment should simply fade in or out; that is, no strong navigation associated
134 * with it except that it is appearing or disappearing for some reason. */
135 public static final int TRANSIT_FRAGMENT_FADE = 3 | TRANSIT_ENTER_MASK;
138 * Set specific animation resources to run for the fragments that are
139 * entering and exiting in this transaction.
141 public abstract FragmentTransaction setCustomAnimations(int enter, int exit);
144 * Select a standard transition animation for this transaction. May be
145 * one of {@link #TRANSIT_NONE}, {@link #TRANSIT_FRAGMENT_OPEN},
146 * or {@link #TRANSIT_FRAGMENT_CLOSE}
148 public abstract FragmentTransaction setTransition(int transit);
151 * Set a custom style resource that will be used for resolving transit
154 public abstract FragmentTransaction setTransitionStyle(int styleRes);
157 * Add this transaction to the back stack. This means that the transaction
158 * will be remembered after it is committed, and will reverse its operation
159 * when later popped off the stack.
161 * @param name An optional name for this back stack state, or null.
163 public abstract FragmentTransaction addToBackStack(String name);
166 * Returns true if this FragmentTransaction is allowed to be added to the back
167 * stack. If this method would return false, {@link #addToBackStack(String)}
168 * will throw {@link IllegalStateException}.
170 * @return True if {@link #addToBackStack(String)} is permitted on this transaction.
172 public abstract boolean isAddToBackStackAllowed();
175 * Disallow calls to {@link #addToBackStack(String)}. Any future calls to
176 * addToBackStack will throw {@link IllegalStateException}. If addToBackStack
177 * has already been called, this method will throw IllegalStateException.
179 public abstract FragmentTransaction disallowAddToBackStack();
182 * Set the full title to show as a bread crumb when this transaction
183 * is on the back stack, as used by {@link FragmentBreadCrumbs}.
185 * @param res A string resource containing the title.
187 public abstract FragmentTransaction setBreadCrumbTitle(int res);
190 * Like {@link #setBreadCrumbTitle(int)} but taking a raw string; this
191 * method is <em>not</em> recommended, as the string can not be changed
192 * later if the locale changes.
194 public abstract FragmentTransaction setBreadCrumbTitle(CharSequence text);
197 * Set the short title to show as a bread crumb when this transaction
198 * is on the back stack, as used by {@link FragmentBreadCrumbs}.
200 * @param res A string resource containing the title.
202 public abstract FragmentTransaction setBreadCrumbShortTitle(int res);
205 * Like {@link #setBreadCrumbShortTitle(int)} but taking a raw string; this
206 * method is <em>not</em> recommended, as the string can not be changed
207 * later if the locale changes.
209 public abstract FragmentTransaction setBreadCrumbShortTitle(CharSequence text);
212 * Schedules a commit of this transaction. The commit does
213 * not happen immediately; it will be scheduled as work on the main thread
214 * to be done the next time that thread is ready.
216 * <p class="note">A transaction can only be committed with this method
217 * prior to its containing activity saving its state. If the commit is
218 * attempted after that point, an exception will be thrown. This is
219 * because the state after the commit can be lost if the activity needs to
220 * be restored from its state. See {@link #commitAllowingStateLoss()} for
221 * situations where it may be okay to lose the commit.</p>
223 * @return Returns the identifier of this transaction's back stack entry,
224 * if {@link #addToBackStack(String)} had been called. Otherwise, returns
227 public abstract int commit();
230 * Like {@link #commit} but allows the commit to be executed after an
231 * activity's state is saved. This is dangerous because the commit can
232 * be lost if the activity needs to later be restored from its state, so
233 * this should only be used for cases where it is okay for the UI state
234 * to change unexpectedly on the user.
236 public abstract int commitAllowingStateLoss();