1 package com.xtremelabs.robolectric.tester.android.util; 2 3 import android.support.v4.app.Fragment; 4 import android.support.v4.app.FragmentTransaction; 5 import android.view.View; 6 7 public class TestFragmentTransaction extends FragmentTransaction { 8 9 private TestFragmentManager fragmentManager; 10 private int containerViewId; 11 private String tag; 12 private Fragment fragment; 13 private boolean replacing; 14 private boolean starting; 15 private boolean removing; 16 private boolean addedToBackStack; 17 private boolean hiding; 18 private boolean showing; 19 private String backStackName; 20 private int lastEnterAnimation; 21 private int lastExitAnimation; 22 private Fragment fragmentToRemove; 23 private boolean committedAllowingStateLoss; 24 private Fragment fragmentToAttach; 25 TestFragmentTransaction(TestFragmentManager fragmentManager)26 public TestFragmentTransaction(TestFragmentManager fragmentManager) { 27 this.fragmentManager = fragmentManager; 28 } 29 30 @Override add(Fragment fragment, String tag)31 public FragmentTransaction add(Fragment fragment, String tag) { 32 return add(View.NO_ID, fragment, tag); 33 } 34 35 @Override add(int containerViewId, Fragment fragment)36 public FragmentTransaction add(int containerViewId, Fragment fragment) { 37 return add(containerViewId, fragment, null); 38 } 39 40 @Override add(int containerViewId, Fragment fragment, String tag)41 public FragmentTransaction add(int containerViewId, Fragment fragment, String tag) { 42 this.containerViewId = containerViewId; 43 this.tag = tag; 44 this.fragment = fragment; 45 this.starting = true; 46 return this; 47 } 48 49 @Override replace(int containerViewId, Fragment fragment)50 public FragmentTransaction replace(int containerViewId, Fragment fragment) { 51 return replace(containerViewId, fragment, null); 52 } 53 54 @Override replace(int containerViewId, Fragment fragment, String tag)55 public FragmentTransaction replace(int containerViewId, Fragment fragment, String tag) { 56 this.containerViewId = containerViewId; 57 this.tag = tag; 58 this.fragment = fragment; 59 this.replacing = true; 60 this.starting = true; 61 return this; 62 } 63 64 @Override remove(Fragment fragment)65 public FragmentTransaction remove(Fragment fragment) { 66 this.fragmentToRemove = fragment; 67 this.removing = true; 68 return this; 69 } 70 71 @Override hide(Fragment fragment)72 public FragmentTransaction hide(Fragment fragment) { 73 this.fragment = fragment; 74 this.hiding = true; 75 this.showing = false; 76 return this; 77 } 78 79 @Override show(Fragment fragment)80 public FragmentTransaction show(Fragment fragment) { 81 this.fragment = fragment; 82 this.showing = true; 83 this.hiding = false; 84 return this; 85 } 86 87 @Override detach(Fragment fragment)88 public FragmentTransaction detach(Fragment fragment) { 89 return null; 90 } 91 92 @Override attach(Fragment fragment)93 public FragmentTransaction attach(Fragment fragment) { 94 fragmentToAttach = fragment; 95 return this; 96 } 97 98 @Override isEmpty()99 public boolean isEmpty() { 100 return false; 101 } 102 103 @Override setCustomAnimations(int enter, int exit)104 public FragmentTransaction setCustomAnimations(int enter, int exit) { 105 this.lastEnterAnimation = enter; 106 this.lastExitAnimation = exit; 107 return this; 108 } 109 110 @Override setCustomAnimations(int enter, int exit, int popEnter, int popExit)111 public FragmentTransaction setCustomAnimations(int enter, int exit, int popEnter, int popExit) { 112 return null; 113 } 114 115 @Override setTransition(int transit)116 public FragmentTransaction setTransition(int transit) { 117 return null; 118 } 119 120 @Override setTransitionStyle(int styleRes)121 public FragmentTransaction setTransitionStyle(int styleRes) { 122 return null; 123 } 124 125 @Override addToBackStack(String name)126 public FragmentTransaction addToBackStack(String name) { 127 backStackName = name; 128 addedToBackStack = true; 129 return this; 130 } 131 132 @Override isAddToBackStackAllowed()133 public boolean isAddToBackStackAllowed() { 134 return false; 135 } 136 137 @Override disallowAddToBackStack()138 public FragmentTransaction disallowAddToBackStack() { 139 return null; 140 } 141 142 @Override setBreadCrumbTitle(int res)143 public FragmentTransaction setBreadCrumbTitle(int res) { 144 return null; 145 } 146 147 @Override setBreadCrumbTitle(CharSequence text)148 public FragmentTransaction setBreadCrumbTitle(CharSequence text) { 149 return null; 150 } 151 152 @Override setBreadCrumbShortTitle(int res)153 public FragmentTransaction setBreadCrumbShortTitle(int res) { 154 return null; 155 } 156 157 @Override setBreadCrumbShortTitle(CharSequence text)158 public FragmentTransaction setBreadCrumbShortTitle(CharSequence text) { 159 return null; 160 } 161 162 @Override commit()163 public int commit() { 164 fragmentManager.commitLater(this); 165 return 0; 166 } 167 168 @Override commitAllowingStateLoss()169 public int commitAllowingStateLoss() { 170 committedAllowingStateLoss = true; 171 return commit(); 172 } 173 isAddedToBackStack()174 public boolean isAddedToBackStack() { 175 return addedToBackStack; 176 } 177 getContainerViewId()178 public int getContainerViewId() { 179 return containerViewId; 180 } 181 getTag()182 public String getTag() { 183 return tag; 184 } 185 getFragment()186 public Fragment getFragment() { 187 return fragment; 188 } 189 isReplacing()190 public boolean isReplacing() { 191 return replacing; 192 } 193 isStarting()194 public boolean isStarting() { 195 return starting; 196 } 197 isRemoving()198 public boolean isRemoving() { 199 return removing; 200 } 201 isHiding()202 public boolean isHiding() { 203 return hiding; 204 } 205 isShowing()206 public boolean isShowing() { 207 return showing; 208 } 209 getBackStackName()210 public String getBackStackName() { 211 return backStackName; 212 } 213 getLastEnterAnimation()214 public int getLastEnterAnimation() { 215 return lastEnterAnimation; 216 } 217 getLastExitAnimation()218 public int getLastExitAnimation() { 219 return lastExitAnimation; 220 } 221 getManager()222 public TestFragmentManager getManager() { 223 return fragmentManager; 224 } 225 getFragmentToRemove()226 public Fragment getFragmentToRemove() { 227 return fragmentToRemove; 228 } 229 isCommittedAllowingStateLoss()230 public boolean isCommittedAllowingStateLoss() { 231 return committedAllowingStateLoss; 232 } 233 isAttaching()234 public boolean isAttaching() { 235 return fragmentToAttach != null; 236 } 237 getFragmentToAttach()238 public Fragment getFragmentToAttach() { 239 return fragmentToAttach; 240 } 241 } 242