fragment/src/androidTest/java/androidx/fragment/app/FragmentTransitionTest.java
@Test
    public void complexSharedElementTransition() throws Throwable {
        TransitionFragment fragment1 = setupInitialFragment();

        // Now do a transition to scene2
        ComplexTransitionFragment fragment2 = new ComplexTransitionFragment();
        fragment2.setLayoutId(R.layout.scene2);

        final View startBlue = findBlue();
        final View startGreen = findGreen();
        final Rect startBlueBounds = getBoundsOnScreen(startBlue);

        mFragmentManager.beginTransaction()
                .addSharedElement(startBlue, "blueSquare")
                .addSharedElement(startGreen, "greenSquare")
                .replace(R.id.fragmentContainer, fragment2)
                .addToBackStack(null)
                .setReorderingAllowed(true)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);
        assertEquals(2, mOnBackStackChangedTimes);

        fragment1.waitForTransition();
        fragment2.waitForTransition();

        final View endBlue = findBlue();
        final View endGreen = findGreen();
        final Rect endBlueBounds = getBoundsOnScreen(endBlue);

        verifyAndClearTransition(fragment2.sharedElementEnterTransition1, startBlueBounds,
                startBlue, endBlue);
        verifyAndClearTransition(fragment2.sharedElementEnterTransition2, startBlueBounds,
                startGreen, endGreen);

        // Now see if it works when popped
        FragmentTestUtil.popBackStackImmediate(mActivityRule);
        assertEquals(3, mOnBackStackChangedTimes);

        fragment1.waitForTransition();
        fragment2.waitForTransition();

        final View reenterBlue = findBlue();
        final View reenterGreen = findGreen();

        verifyAndClearTransition(fragment2.sharedElementReturnTransition1, endBlueBounds,
                endBlue, reenterBlue);
        verifyAndClearTransition(fragment2.sharedElementReturnTransition2, endBlueBounds,
                endGreen, reenterGreen);
    }
// Ensure that shared element transitions that have targets properly target the views
Ensure that shared element transitions that have targets properly target the views
Ensure that shared element transitions that have targets properly target the views
@Test
    public void complexSharedElementTransition() throws Throwable {
        TransitionFragment fragment1 = setupInitialFragment();
        ComplexTransitionFragment fragment2 = new ComplexTransitionFragment();
        fragment2.setLayoutId(R.layout.scene2);
        final View startBlue = findBlue();
        final View startGreen = findGreen();
        final Rect startBlueBounds = getBoundsOnScreen(startBlue);
        mFragmentManager.beginTransaction()
                .addSharedElement(startBlue, "blueSquare")
                .addSharedElement(startGreen, "greenSquare")
                .replace(R.id.fragmentContainer, fragment2)
                .addToBackStack(null)
                .setReorderingAllowed(true)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);
        assertEquals(2, mOnBackStackChangedTimes);
        fragment1.waitForTransition();
        fragment2.waitForTransition();
        final View endBlue = findBlue();
        final View endGreen = findGreen();
        final Rect endBlueBounds = getBoundsOnScreen(endBlue);
        verifyAndClearTransition(fragment2.sharedElementEnterTransition1, startBlueBounds,
                startBlue, endBlue);
        verifyAndClearTransition(fragment2.sharedElementEnterTransition2, startBlueBounds,
                startGreen, endGreen);
        FragmentTestUtil.popBackStackImmediate(mActivityRule);
        assertEquals(3, mOnBackStackChangedTimes);
        fragment1.waitForTransition();
        fragment2.waitForTransition();
        final View reenterBlue = findBlue();
        final View reenterGreen = findGreen();
        verifyAndClearTransition(fragment2.sharedElementReturnTransition1, endBlueBounds,
                endBlue, reenterBlue);
        verifyAndClearTransition(fragment2.sharedElementReturnTransition2, endBlueBounds,
                endGreen, reenterGreen);
    }
@ Test public void complexSharedElementTransition ( ) throws Throwable { TransitionFragment fragment1 = setupInitialFragment ( ) ; ComplexTransitionFragment fragment2 = new ComplexTransitionFragment ( ) ; fragment2 . setLayoutId ( R . layout . scene2 ) ; final View startBlue = findBlue ( ) ; final View startGreen = findGreen ( ) ; final Rect startBlueBounds = getBoundsOnScreen ( startBlue ) ; mFragmentManager . beginTransaction ( ) . addSharedElement ( startBlue , "blueSquare" ) . addSharedElement ( startGreen , "greenSquare" ) . replace ( R . id . fragmentContainer , fragment2 ) . addToBackStack ( null ) . setReorderingAllowed ( true ) . commit ( ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; assertEquals ( 2 , mOnBackStackChangedTimes ) ; fragment1 . waitForTransition ( ) ; fragment2 . waitForTransition ( ) ; final View endBlue = findBlue ( ) ; final View endGreen = findGreen ( ) ; final Rect endBlueBounds = getBoundsOnScreen ( endBlue ) ; verifyAndClearTransition ( fragment2 . sharedElementEnterTransition1 , startBlueBounds , startBlue , endBlue ) ; verifyAndClearTransition ( fragment2 . sharedElementEnterTransition2 , startBlueBounds , startGreen , endGreen ) ; FragmentTestUtil . popBackStackImmediate ( mActivityRule ) ; assertEquals ( 3 , mOnBackStackChangedTimes ) ; fragment1 . waitForTransition ( ) ; fragment2 . waitForTransition ( ) ; final View reenterBlue = findBlue ( ) ; final View reenterGreen = findGreen ( ) ; verifyAndClearTransition ( fragment2 . sharedElementReturnTransition1 , endBlueBounds , endBlue , reenterBlue ) ; verifyAndClearTransition ( fragment2 . sharedElementReturnTransition2 , endBlueBounds , endGreen , reenterGreen ) ; }
Ensure that shared element transitions that have targets properly target the views
Ensure that shared element transitions that have targets properly target the views
// Now do a transition to scene2 // Now see if it works when popped