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

The following examples show how to use androidx.fragment.app.Fragment#setExitTransition() . 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: MainActivity.java    From Easy_xkcd with Apache License 2.0 6 votes vote down vote up
void showFavoritesFragment(boolean animate) {
    FragmentManager fragmentManager = getSupportFragmentManager();
    //mFab.setVisibility(prefHelper.fabDisabledFavorites() ? View.GONE : View.VISIBLE);

    FavoritesFragment favoritesFragment = new FavoritesFragment();
    final FragmentTransaction transaction = fragmentManager.beginTransaction();
    if (animate) {
        Fragment oldFragment = fragmentManager.findFragmentByTag(FRAGMENT_TAG);
        if (oldFragment != null) {
            Slide slideOut = new Slide(currentFragment == CurrentFragment.Browser ? Gravity.TOP : Gravity.BOTTOM);
            slideOut.setInterpolator(new AccelerateInterpolator(2.0f));
            oldFragment.setExitTransition(slideOut);
        }
        Slide slideIn = new Slide(currentFragment == CurrentFragment.Browser ? Gravity.BOTTOM : Gravity.TOP);
        slideIn.setInterpolator(new OvershootInterpolator(1.5f));
        favoritesFragment.setEnterTransition(slideIn);
        favoritesFragment.setAllowEnterTransitionOverlap(false);
    }
    transaction
            .replace(R.id.flContent, favoritesFragment, FRAGMENT_TAG);
    currentFragment = CurrentFragment.Favorites;
    transaction.commitNowAllowingStateLoss();
}
 
Example 4
Source File: MainActivity.java    From Easy_xkcd with Apache License 2.0 6 votes vote down vote up
void showBrowserFragment(boolean animate) {
    FragmentManager fragmentManager = getSupportFragmentManager();
    if (prefHelper.fabDisabledComicBrowser()) mFab.hide(); else mFab.show();

    ComicFragment comicFragment = fullOffline ? new OfflineFragment() : new ComicBrowserFragment();
    final FragmentTransaction transaction = fragmentManager.beginTransaction();
    if (animate) {
        Fragment oldFragment = fragmentManager.findFragmentByTag(FRAGMENT_TAG);
        if (oldFragment != null) {
            Slide slideOut = new Slide(Gravity.BOTTOM);
            slideOut.setInterpolator(new AccelerateInterpolator(2.0f));
            oldFragment.setExitTransition(slideOut);
        }

        Slide slideIn = new Slide(Gravity.TOP);
        slideIn.setInterpolator(new OvershootInterpolator(1.5f));
        comicFragment.setEnterTransition(slideIn);
        comicFragment.setAllowEnterTransitionOverlap(false);
    }
    transaction.replace(R.id.flContent, comicFragment, FRAGMENT_TAG);
    currentFragment = CurrentFragment.Browser;
    transaction.commitNowAllowingStateLoss();
}
 
Example 5
Source File: SharedElementTransition.java    From Kore with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the transition for the exiting fragment
 * @param fragment
 */
@TargetApi(21)
public void setupExitTransition(Context context, Fragment fragment) {
    Transition fade = TransitionInflater
            .from(context)
            .inflateTransition(android.R.transition.fade);
    fragment.setExitTransition(fade);
    fragment.setReenterTransition(fade);

    fragment.setExitSharedElementCallback(new SharedElementCallback() {
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            // 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 (clearSharedElements) {
                names.clear();
                sharedElements.clear();
                clearSharedElements = false;
            }
        }
    });
}
 
Example 6
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 7
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 8
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 9
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 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: FeatureDemoUtils.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
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 12
Source File: BaseMediaActivity.java    From Kore with Apache License 2.0 4 votes vote down vote up
@Override
@TargetApi(21)
protected void onCreate(Bundle savedInstanceState) {
    // Request transitions on lollipop
    if (Utils.isLollipopOrLater()) {
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    }
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_generic_media);
    ButterKnife.bind(this);

    // Set up the drawer.
    navigationDrawerFragment = (NavigationDrawerFragment)getSupportFragmentManager()
            .findFragmentById(R.id.navigation_drawer);
    navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));

    Toolbar toolbar = findViewById(R.id.default_toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        String actionBarTitle;
        boolean naviconIsArrow = false;
        if (savedInstanceState != null) {
            actionBarTitle = savedInstanceState.getString(ACTIONBAR_TITLE);
            naviconIsArrow = savedInstanceState.getBoolean(NAVICON_ISARROW);
        } else {
            actionBarTitle = getActionBarTitle();
        }

        actionBar.setDisplayHomeAsUpEnabled(true);
        updateActionBar(actionBarTitle, naviconIsArrow);
    }

    String fragmentTitle = getActionBarTitle();
    Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
    if (fragment == null) {
        fragment = createFragment();

        if (Utils.isLollipopOrLater()) {
            fragment.setExitTransition(null);
            fragment.setReenterTransition(TransitionInflater
                                                  .from(this)
                                                  .inflateTransition(android.R.transition.fade));
        }

        getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.fragment_container, fragment, fragmentTitle)
                .commit();
    }

    if (Utils.isLollipopOrLater()) {
        sharedElementTransition.setupExitTransition(this, fragment);
    }

    hostManager = HostManager.getInstance(this);
}
 
Example 13
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);
    }
}