Java Code Examples for androidx.fragment.app.FragmentTransaction#addSharedElement()
The following examples show how to use
androidx.fragment.app.FragmentTransaction#addSharedElement() .
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: BaseActivity.java From NewFastFrame with Apache License 2.0 | 6 votes |
protected void addBackStackFragment(Fragment fragment, boolean needAddBackStack, View... views) { if (backStackLayoutId == 0) { return; } FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); if (views != null && views.length > 0) { fragmentTransaction.replace(backStackLayoutId, fragment); for (View item : views) { fragmentTransaction.addSharedElement(item, ViewCompat.getTransitionName(item)); } } else { fragmentTransaction .add(backStackLayoutId, fragment); } if (needAddBackStack) { fragmentTransaction.addToBackStack(null); } fragmentTransaction.commit(); }
Example 4
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 5
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 6
Source File: GalleryFragment.java From animation-samples with Apache License 2.0 | 5 votes |
private void createAndAddTransitionParticipants(@NonNull GalleryViewHolder itemHolder, @NonNull FragmentTransaction transaction) { transaction.addSharedElement(itemHolder.descriptionContainer, getString(R.string.transition_description)); transaction.addSharedElement(itemHolder.mapView, getString(R.string.transition_map)); }
Example 7
Source File: LollipopTransitionAnimation.java From Alligator with MIT License | 5 votes |
@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 8
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 9
Source File: EmailActivity.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
@Override public void onNewUser(User user) { // New user, direct them to create an account with email/password // if account creation is enabled in SignInIntentBuilder TextInputLayout emailLayout = findViewById(R.id.email_layout); AuthUI.IdpConfig emailConfig = ProviderUtils.getConfigFromIdps(getFlowParams().providers, EmailAuthProvider.PROVIDER_ID); if (emailConfig == null) { emailConfig = ProviderUtils.getConfigFromIdps(getFlowParams().providers, EMAIL_LINK_PROVIDER); } if (emailConfig.getParams().getBoolean(ExtraConstants.ALLOW_NEW_EMAILS, true)) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); if (emailConfig.getProviderId().equals(EMAIL_LINK_PROVIDER)) { showRegisterEmailLinkFragment(emailConfig, user.getEmail()); } else { RegisterEmailFragment fragment = RegisterEmailFragment.newInstance(user); ft.replace(R.id.fragment_register_email, fragment, RegisterEmailFragment.TAG); if (emailLayout != null) { String emailFieldName = getString(R.string.fui_email_field_name); ViewCompat.setTransitionName(emailLayout, emailFieldName); ft.addSharedElement(emailLayout, emailFieldName); } ft.disallowAddToBackStack().commit(); } } else { emailLayout.setError(getString(R.string.fui_error_email_does_not_exist)); } }
Example 10
Source File: FeatureDemoUtils.java From material-components-android with Apache License 2.0 | 4 votes |
public static void startFragmentInternal( FragmentActivity activity, Fragment fragment, String tag, @Nullable View sharedElement, @Nullable String sharedElementName, @Nullable ContainerTransformConfiguration containerTransformConfiguration) { FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction(); if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP && sharedElement != null && sharedElementName != null) { Fragment currentFragment = getCurrentFragment(activity); Hold hold = new Hold(); // Add root view as target for the Hold so that the entire view hierarchy is held in place as // one instead of each child view individually. Helps keep shadows during the transition. hold.addTarget(currentFragment.getView()); currentFragment.setExitTransition(hold); MaterialContainerTransform transform = new MaterialContainerTransform(); if (containerTransformConfiguration != null && containerTransformConfiguration.isArcMotionEnabled()) { transform.setPathMotion(new MaterialArcMotion()); } transform.setContainerColor(MaterialColors.getColor(sharedElement, R.attr.colorSurface)); transform.setFadeMode(MaterialContainerTransform.FADE_MODE_THROUGH); fragment.setSharedElementEnterTransition(transform); transaction.addSharedElement(sharedElement, sharedElementName); if (fragment.getArguments() == null) { Bundle args = new Bundle(); args.putString(ARG_TRANSITION_NAME, sharedElementName); fragment.setArguments(args); } else { fragment.getArguments().putString(ARG_TRANSITION_NAME, sharedElementName); } } else { transaction.setCustomAnimations( R.anim.abc_grow_fade_in_from_bottom, R.anim.abc_fade_out, R.anim.abc_fade_in, R.anim.abc_shrink_fade_out_from_bottom); } transaction .replace(MAIN_ACTIVITY_FRAGMENT_CONTAINER_ID, fragment, tag) .addToBackStack(null /* name */) .commit(); }
Example 11
Source File: OverviewBaseFragment.java From Easy_xkcd with Apache License 2.0 | 4 votes |
public void goToComic(final int number, final int position) { //TODO add shared elements, maybe? databaseManager.setRead(number, true); Timber.d("number: %d", number); ((MainActivity) getActivity()).lastComicNumber = number; FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); transaction.setReorderingAllowed(true); TextView title = getCurrentTitleTextView(position); if (title != null) { transaction.addSharedElement(title, title.getTransitionName()); Timber.d("selected title %s", title.getText()); } ImageView thumbnail = getCurrentThumbnail(position); if (thumbnail != null) { transaction.addSharedElement(thumbnail, thumbnail.getTransitionName()); } ComicFragment comicFragment; if (prefHelper.overviewFav()) { comicFragment = new FavoritesFragment(); } else if (prefHelper.fullOfflineEnabled()) { comicFragment = new OfflineFragment(); } else { comicFragment = new ComicBrowserFragment(); } comicFragment.lastComicNumber = number; comicFragment.transitionPending = true; transaction.replace(R.id.flContent, comicFragment, MainActivity.FRAGMENT_TAG) .commitAllowingStateLoss(); ((MainActivity) getActivity()).setCurrentFragment(prefHelper.overviewFav() ? MainActivity.CurrentFragment.Favorites : MainActivity.CurrentFragment.Browser); /*android.support.v4.app.FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); ComicFragment fragment; FragmentTransaction transaction = getFragmentManager().beginTransaction(); int subtitle; if (!prefHelper.overviewFav()) { FavoritesFragment favorites = (FavoritesFragment) fragmentManager.findFragmentByTag(FAV_TAG); if (favorites != null) transaction.hide(favorites); fragment = (ComicFragment) fragmentManager.findFragmentByTag(BROWSER_TAG); fragment.scrollTo(number, false); transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left) .hide(fragmentManager.findFragmentByTag(OVERVIEW_TAG)) .show(fragment) .commit(); subtitle = fragment.lastComicNumber; } else { transaction .setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left) .hide(fragmentManager.findFragmentByTag(BROWSER_TAG)) .hide(fragmentManager.findFragmentByTag(OVERVIEW_TAG)); fragment = (FavoritesFragment) fragmentManager.findFragmentByTag(FAV_TAG); //int index = Arrays.binarySearch(databaseManager.getFavComicsLegacy(), number + 1); RealmResults<RealmComic> favorites = databaseManager.getFavComics(); int index = 0; for (int i = 0; i < favorites.size(); i++) { if (favorites.get(i).getComicNumber() == number + 1) { index = i; } } if (fragment == null || index < 0) { if (index < 0) { // If the comic for some reason is in realm, but not in shared prefs, add it now index = -index - 1; databaseManager.setFavorite(number + 1, true); } fragment = new FavoritesFragment(); transaction.add(R.id.flContent, fragment, FAV_TAG); } else { transaction.show(fragment); fragment.scrollTo(index, false); } fragment.favoriteIndex = index; subtitle = number + 1; transaction.commit(); ((MainActivity) getActivity()).setCurrentFragment(MainActivity.CurrentFragment.Favorites); ((MainActivity) getActivity()).getSupportActionBar().setTitle(getActivity().getResources().getString(R.string.nv_favorites)); ((MainActivity) getActivity()).getNavView().getMenu().findItem(R.id.nav_favorites).setChecked(true); } if (prefHelper.subtitleEnabled()) ((MainActivity) getActivity()).getToolbar().setSubtitle(String.valueOf(subtitle)); */ }