Java Code Examples for androidx.fragment.app.Fragment#setEnterTransition()

The following examples show how to use androidx.fragment.app.Fragment#setEnterTransition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GalleryDetailScene.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onTransition(Context context,
                            FragmentTransaction transaction, Fragment exit, Fragment enter) {
    if (!(enter instanceof GalleryListScene) && !(enter instanceof DownloadsScene) &&
            !(enter instanceof FavoritesScene) && !(enter instanceof HistoryScene)) {
        return false;
    }

    String transitionName = ViewCompat.getTransitionName(mThumb);
    if (transitionName != null) {
        exit.setSharedElementReturnTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
        exit.setExitTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_fade));
        enter.setSharedElementEnterTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
        enter.setEnterTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_fade));
        transaction.addSharedElement(mThumb, transitionName);
    }
    return true;
}
 
Example 2
Source File: EnterGalleryDetailTransaction.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onTransition(Context context, FragmentTransaction transaction,
        Fragment exit, Fragment enter) {
    if (mThumb == null || !(enter instanceof GalleryDetailScene)) {
        return false;
    }

    String transitionName = ViewCompat.getTransitionName(mThumb);
    if (transitionName != null) {
        exit.setSharedElementReturnTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
        exit.setExitTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_fade));
        enter.setSharedElementEnterTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
        enter.setEnterTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_fade));
        transaction.addSharedElement(mThumb, transitionName);
    }
    return true;
}
 
Example 3
Source File: TransitionSharedAxisDemoFragment.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void replaceFragment(@LayoutRes int layoutResId) {
  boolean entering = layoutResId == LAYOUT_RES_ID_END;

  Fragment fragment = TransitionSimpleLayoutFragment.newInstance(layoutResId);
  // Set the transition as the Fragment's enter transition. This will be used when the fragment
  // is added to the container and re-used when the fragment is removed from the container.
  fragment.setEnterTransition(createTransition(entering));

  getChildFragmentManager()
      .beginTransaction()
      .replace(R.id.fragment_container, fragment)
      .commit();

  backButton.setEnabled(entering);
  nextButton.setEnabled(!entering);
}
 
Example 4
Source File: GalleryDetailScene.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onTransition(Context context,
        FragmentTransaction transaction, Fragment exit, Fragment enter) {
    if (!(enter instanceof GalleryListScene) && !(enter instanceof DownloadsScene) &&
            !(enter instanceof FavoritesScene) && !(enter instanceof HistoryScene)) {
        return false;
    }

    String transitionName = ViewCompat.getTransitionName(mThumb);
    if (transitionName != null) {
        exit.setSharedElementReturnTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
        exit.setExitTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_fade));
        enter.setSharedElementEnterTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
        enter.setEnterTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_fade));
        transaction.addSharedElement(mThumb, transitionName);
    }
    return true;
}
 
Example 5
Source File: EnterGalleryDetailTransaction.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onTransition(Context context, FragmentTransaction transaction,
        Fragment exit, Fragment enter) {
    if (mThumb == null || !(enter instanceof GalleryDetailScene)) {
        return false;
    }

    String transitionName = ViewCompat.getTransitionName(mThumb);
    if (transitionName != null) {
        exit.setSharedElementReturnTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
        exit.setExitTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_fade));
        enter.setSharedElementEnterTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
        enter.setEnterTransition(
                TransitionInflater.from(context).inflateTransition(R.transition.trans_fade));
        transaction.addSharedElement(mThumb, transitionName);
    }
    return true;
}
 
Example 6
Source File: LollipopTransitionAnimation.java    From Alligator with MIT License 5 votes vote down vote up
@Override
public void applyBeforeFragmentTransactionExecuted(@NonNull FragmentTransaction transaction, @NonNull Fragment enteringFragment, @NonNull Fragment exitingFragment) {
	enteringFragment.setEnterTransition(mEnterTransition);
	exitingFragment.setExitTransition(mExitTransition);
	enteringFragment.setSharedElementEnterTransition(mSharedElementTransition);
	enteringFragment.setAllowEnterTransitionOverlap(mAllowEnterTransitionOverlap);
	if (mSharedElements != null) {
		for (Pair<View, String> sharedElement : mSharedElements) {
			transaction.addSharedElement(sharedElement.first, sharedElement.second);
		}
	}
}
 
Example 7
Source File: LollipopTransitionAnimation.java    From Alligator with MIT License 5 votes vote down vote up
@Override
public void applyAfterFragmentTransactionExecuted(@NonNull Fragment enteringFragment, @NonNull Fragment exitingFragment) {
	enteringFragment.setEnterTransition(null);
	exitingFragment.setExitTransition(null);
	enteringFragment.setSharedElementEnterTransition(null);
	enteringFragment.setAllowEnterTransitionOverlap(true);
}
 
Example 8
Source File: TransitionFadeThroughDemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void replaceFragment(@IdRes int itemId) {
  Fragment fragment = TransitionSimpleLayoutFragment.newInstance(getLayoutForItemId(itemId));
  // Set the transition as the Fragment's enter transition. This will be used when the fragment
  // is added to the container and re-used when the fragment is removed from the container.
  fragment.setEnterTransition(createTransition());

  getChildFragmentManager()
      .beginTransaction()
      .replace(R.id.fragment_container, fragment)
      .commit();
}
 
Example 9
Source File: SharedElementTransition.java    From Kore with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up the transition for the entering fragment
 * @param fragmentTransaction
 * @param fragment entering fragment
 * @param sharedElement must have the transition name set
 */
@TargetApi(21)
public void setupEnterTransition(Context context,
                                 FragmentTransaction fragmentTransaction,
                                 final Fragment fragment,
                                 View sharedElement) {
    if (!(fragment instanceof SharedElement)) {
        LogUtils.LOGD(TAG, "Enter transition fragment must implement SharedElement interface");
        return;
    }

    androidx.core.app.SharedElementCallback seCallback = new androidx.core.app.SharedElementCallback() {
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            // On returning, onMapSharedElements for the exiting fragment is called before the onMapSharedElements
            // for the reentering fragment. We use this to determine if we are returning and if
            // we should clear the shared element lists. Note that, clearing must be done in the reentering fragment
            // as this is called last. Otherwise, the app will crash during transition setup. Not sure, but might
            // be a v4 support package bug.
            if (fragment.isVisible() && (!((SharedElement) fragment).isSharedElementVisible())) {
                // shared element not visible
                clearSharedElements = true;
            }
        }
    };
    fragment.setEnterSharedElementCallback(seCallback);

    fragment.setEnterTransition(TransitionInflater
                                        .from(context)
                                        .inflateTransition(R.transition.media_details));
    fragment.setReturnTransition(null);

    Transition changeImageTransition = TransitionInflater.from(
            context).inflateTransition(R.transition.change_image);
    fragment.setSharedElementReturnTransition(changeImageTransition);
    fragment.setSharedElementEnterTransition(changeImageTransition);

    fragmentTransaction.addSharedElement(sharedElement, sharedElement.getTransitionName());
}
 
Example 10
Source File: StageActivity.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
private void finishScene(String tag, TransitionHelper transitionHelper) {
    FragmentManager fragmentManager = getSupportFragmentManager();

    // Get scene
    Fragment scene = fragmentManager.findFragmentByTag(tag);
    if (scene == null) {
        Log.e(TAG, "finishScene: Can't find scene by tag: " + tag);
        return;
    }

    // Get scene index
    int index = mSceneTagList.indexOf(tag);
    if (index < 0) {
        Log.e(TAG, "finishScene: Can't find the tag in tag list: " + tag);
        return;
    }

    if (mSceneTagList.size() == 1) {
        // It is the last fragment, finish Activity now
        Log.i(TAG, "finishScene: It is the last scene, finish activity now");
        finish();
        return;
    }

    Fragment next = null;
    if (index == mSceneTagList.size() - 1) {
        // It is first fragment, show the next one
        next = fragmentManager.findFragmentByTag(mSceneTagList.get(index - 1));
    }

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    if (next != null) {
        if (transitionHelper == null || !transitionHelper.onTransition(
                this, transaction, scene, next)) {
            // Clear shared item
            scene.setSharedElementEnterTransition(null);
            scene.setSharedElementReturnTransition(null);
            scene.setEnterTransition(null);
            scene.setExitTransition(null);
            next.setSharedElementEnterTransition(null);
            next.setSharedElementReturnTransition(null);
            next.setEnterTransition(null);
            next.setExitTransition(null);
            // Do not show animate if it is not the first fragment
            transaction.setCustomAnimations(R.anim.scene_close_enter, R.anim.scene_close_exit);
        }
        // Attach fragment
        transaction.attach(next);
    }
    transaction.remove(scene);
    transaction.commitAllowingStateLoss();
    onTransactScene();

    // Remove tag
    mSceneTagList.remove(index);

    // Return result
    if (scene instanceof SceneFragment) {
        ((SceneFragment) scene).returnResult(this);
    }
}
 
Example 11
Source File: StageActivity.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
private void finishScene(String tag, TransitionHelper transitionHelper) {
    FragmentManager fragmentManager = getSupportFragmentManager();

    // Get scene
    Fragment scene = fragmentManager.findFragmentByTag(tag);
    if (scene == null) {
        Log.e(TAG, "finishScene: Can't find scene by tag: " + tag);
        return;
    }

    // Get scene index
    int index = mSceneTagList.indexOf(tag);
    if (index < 0) {
        Log.e(TAG, "finishScene: Can't find the tag in tag list: " + tag);
        return;
    }

    if (mSceneTagList.size() == 1) {
        // It is the last fragment, finish Activity now
        Log.i(TAG, "finishScene: It is the last scene, finish activity now");
        finish();
        return;
    }

    Fragment next = null;
    if (index == mSceneTagList.size() - 1) {
        // It is first fragment, show the next one
        next = fragmentManager.findFragmentByTag(mSceneTagList.get(index - 1));
    }

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    if (next != null) {
        if (transitionHelper == null || !transitionHelper.onTransition(
                this, transaction, scene, next)) {
            // Clear shared item
            scene.setSharedElementEnterTransition(null);
            scene.setSharedElementReturnTransition(null);
            scene.setEnterTransition(null);
            scene.setExitTransition(null);
            next.setSharedElementEnterTransition(null);
            next.setSharedElementReturnTransition(null);
            next.setEnterTransition(null);
            next.setExitTransition(null);
            // Do not show animate if it is not the first fragment
            transaction.setCustomAnimations(R.anim.scene_close_enter, R.anim.scene_close_exit);
        }
        // Attach fragment
        transaction.attach(next);
    }
    transaction.remove(scene);
    transaction.commitAllowingStateLoss();
    onTransactScene();

    // Remove tag
    mSceneTagList.remove(index);

    // Return result
    if (scene instanceof SceneFragment) {
        ((SceneFragment) scene).returnResult(this);
    }
}