use of app.insti.fragment.TransitionTargetFragment in project IITB-App by wncc.
the class Utils method updateSharedElementFragment.
public static void updateSharedElementFragment(final Fragment fragment, final Fragment currentFragment, Map<View, String> sharedElements) {
FragmentTransaction ft = currentFragment.getActivity().getSupportFragmentManager().beginTransaction();
Transition transition = new DetailsTransition();
/* Set up transitions */
fragment.setSharedElementEnterTransition(transition);
fragment.setEnterTransition(new Slide());
currentFragment.setExitTransition(new Fade());
fragment.setSharedElementReturnTransition(transition);
/* Set transition for parent in case it is a child */
if (currentFragment instanceof TransitionTargetChild) {
((TransitionTargetChild) currentFragment).getParent().setExitTransition(new Fade());
}
transition.addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
}
@Override
public void onTransitionEnd(Transition transition) {
if (fragment instanceof TransitionTargetFragment) {
((TransitionTargetFragment) fragment).transitionEnd();
}
if (currentFragment instanceof TransitionTargetFragment) {
((TransitionTargetFragment) currentFragment).transitionEnd();
}
}
@Override
public void onTransitionCancel(Transition transition) {
}
@Override
public void onTransitionPause(Transition transition) {
}
@Override
public void onTransitionResume(Transition transition) {
}
});
/* Add all shared elements */
for (Map.Entry<View, String> entry : sharedElements.entrySet()) {
ft.addSharedElement(entry.getKey(), entry.getValue());
}
/* Update the fragment */
ft.replace(R.id.framelayout_for_fragment, fragment, getTag(fragment)).addToBackStack(getTag(fragment)).commit();
}
Aggregations