Java Code Examples for androidx.fragment.app.Fragment#setSharedElementReturnTransition()
The following examples show how to use
androidx.fragment.app.Fragment#setSharedElementReturnTransition() .
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 |
@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 |
@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: GalleryDetailScene.java From EhViewer with Apache License 2.0 | 6 votes |
@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 4
Source File: EnterGalleryDetailTransaction.java From EhViewer with Apache License 2.0 | 6 votes |
@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 5
Source File: TransitionContainerTransformDemoFragment.java From material-components-android with Apache License 2.0 | 5 votes |
private void configureTransitions(Fragment fragment) { // For all 3 container layer colors, use colorSurface since this transform can be configured // using any fade mode and some of the start views don't have a background and the end view // doesn't have a background. int colorSurface = MaterialColors.getColor(requireView(), R.attr.colorSurface); MaterialContainerTransform enterContainerTransform = buildContainerTransform(true); enterContainerTransform.setAllContainerColors(colorSurface); fragment.setSharedElementEnterTransition(enterContainerTransform); holdTransition.setDuration(enterContainerTransform.getDuration()); MaterialContainerTransform returnContainerTransform = buildContainerTransform(false); returnContainerTransform.setAllContainerColors(colorSurface); fragment.setSharedElementReturnTransition(returnContainerTransform); }
Example 6
Source File: SharedElementTransition.java From Kore with Apache License 2.0 | 5 votes |
/** * 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 7
Source File: StageActivity.java From MHViewer with Apache License 2.0 | 4 votes |
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 8
Source File: StageActivity.java From EhViewer with Apache License 2.0 | 4 votes |
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); } }