3

I have an activity which has Fragment StatsDetailFragment loaded by default.

On press of a button, I'm replacing the fragment with another using the following code.

getSupportFragmentManager().beginTransaction()
                .replace(R.id.stats_detail_container, projectEntryListFragment, ProjectEntryListFragment.FRAGMENT_ID)
                .addToBackStack(FRAGMENT_CHART)
                .commit();

I'm setting up an Enter Transition for ProjectEntryListFragment using the custom transition class

public class RevealTransition extends Visibility {
    private final Point mEpicenter;
    private final int mSmallRadius;
    private final int mBigRadius;
    private final long mDuration;

    public RevealTransition(Point epicenter, int smallRadius, int bigRadius, long duration) {
        mEpicenter = epicenter;
        mSmallRadius = smallRadius;
        mBigRadius = bigRadius;
        mDuration = duration;
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    public Animator onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) {
        Animator animator = ViewAnimationUtils.createCircularReveal(view, mEpicenter.x, mEpicenter.y,
                mSmallRadius, mBigRadius);
        animator.setDuration(mDuration);
        return new WrapperAnimator(animator);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    public Animator onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) {
        Animator animator = ViewAnimationUtils.createCircularReveal(view, mEpicenter.x, mEpicenter.y,
                mBigRadius, mSmallRadius);
        animator.setDuration(mDuration);
        return new WrapperAnimator(animator);
    }
}

The transition works well. But the problem I'm facing is that when the reveal animation is performed on ProjectEntryListFragment, the StatsDetailFragment is already removed and that results in the reveal animation playing on top of a blank background. I would prefer it to be played over the StatsDetailFragment so that the StatsDetailFragment is visible as the reveal transition is played on ProjectListFragment.

I tried just adding the new fragment, but that just gives me an error on popping the backstack.

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.support.v4.app.Fragment.getAllowReturnTransitionOverlap()' on a null object reference

Any help will be hugely appreciated.

Manu Joseph
  • 155
  • 1
  • 13

1 Answers1

0

Set a animationlistener to your fragment. Before the animation runs give your rootview the color you want the ripple to be.in onAnimationEnd and onAnimationCanceled give your rootview the color you want it to have for your layout.

Also the visibilty "trick" runs kind of unstable(imo) Try a ViewTreeObserver.

Hope this helps:)

locomain
  • 185
  • 1
  • 15
  • I am not using animation, but Transition. But none the less, I tried setting TransitionListeners. But it does not seem to work. Neither is the ViewTreeObserver working.. :( – Manu Joseph Apr 14 '15 at 15:33
  • I had the same problem. Thats why i did a little visual trick on the fragment after the transition is done. It has the same visual effect. Run this code like this in your oncreateview view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { reveal();   ViewUtils.removeGlobalListeners(first, this); } }); – locomain Apr 14 '15 at 15:44
  • So you implemented the reveal as an animation? the reveal() method in the code does that I suppose? – Manu Joseph Apr 15 '15 at 03:12
  • I got it working to one extend... I attached a transition listener to the reveal transition and in the onTransitionStart() I used fragment.getView() to get the root view and set the background to a color. Now the problem is that I am able to set any color to the rootview, but not a transparent color. – Manu Joseph Apr 15 '15 at 03:43