Search in sources :

Example 6 with SwipeLayout

use of com.daimajia.swipe.SwipeLayout in project TransitionPlayer by linfaxin.

the class ChromeHomeDemo method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.demo_chrome_home);
    swipeLayout = (SwipeLayout) findViewById(R.id.swipeLayout);
    swipeLayout.getDragEdgeMap().clear();
    swipeLayout.addDrag(SwipeLayout.DragEdge.Top, swipeLayout.getChildAt(0));
    swipeLayout.addRevealListener(R.id.placeHolder, new SwipeLayout.OnRevealListener() {

        @Override
        public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int distance) {
            transitionPlayer.setCurrentFraction(fraction);
        }
    });
    swipeLayout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {
            swipeLayout.getViewTreeObserver().removeOnPreDrawListener(this);
            ViewGroup mSceneRoot = (ViewGroup) findViewById(R.id.sceneRootView);
            Scene scene = Scene.getSceneForLayout(mSceneRoot, R.layout.chrome_home_head_state_expand, ChromeHomeDemo.this);
            transitionPlayer.setPlayControl(new ModifyAnimatorsPlayControl() {

                @Override
                protected Animator onModifyAnimator(Transition transition, ValueAnimator animator) {
                    if (!(animator instanceof ObjectAnimator))
                        return animator;
                    Object target = ((ObjectAnimator) animator).getTarget();
                    if (!(target instanceof View))
                        return animator;
                    View targetView = (View) target;
                    //input view
                    if (targetView.getId() == R.id.editText) {
                        if (transition instanceof ChangeBounds) {
                            AnimatorSet animatorSet = new AnimatorSet();
                            for (ValueAnimator subAnimator : AnimatorUtils.splitAnimatorByValues(animator)) {
                                animatorSet.playTogether(subAnimator);
                                //let input view fast animate to right edge
                                if (subAnimator instanceof ObjectAnimator && "right".equals(((ObjectAnimator) subAnimator).getPropertyName())) {
                                    MultiTimeInterpolator multi = new MultiTimeInterpolator();
                                    TimeInterpolator i = animator.getInterpolator();
                                    multi.addInterpolator(i, 6);
                                    LockEndTimeInterpolator end = new LockEndTimeInterpolator(i);
                                    multi.addInterpolator(end, 4);
                                    subAnimator.setInterpolator(multi);
                                }
                            }
                            return animatorSet;
                        } else if (transition instanceof ChangeTextColor) {
                            TimeInterpolator i = animator.getInterpolator();
                            LockEndTimeInterpolator end = new LockEndTimeInterpolator(i);
                            ReverseTimeInterpolator r = new ReverseTimeInterpolator(i);
                            animator.setInterpolator(new MultiTimeInterpolator(i, end, r));
                        }
                    }
                    //logo view
                    if (targetView.getId() == R.id.imageView && transition instanceof ChangeAlpha) {
                        MultiTimeInterpolator multi = new MultiTimeInterpolator();
                        TimeInterpolator i = new DecelerateInterpolator(1.6f);
                        TimeInterpolator start = new LockStartTimeInterpolator(i);
                        multi.addInterpolator(start, 4);
                        multi.addInterpolator(i, 6);
                        animator.setInterpolator(multi);
                    }
                    return animator;
                }
            });
            TransitionManager.go(scene, transitionPlayer);
            //after start transition, then init click.
            mSceneRoot.findViewById(R.id.editText).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    swipeLayout.close();
                }
            });
            return false;
        }
    });
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) AnimatorSet(android.animation.AnimatorSet) ChangeTextColor(com.linfaxin.transitionplayer.transitions.ChangeTextColor) ValueAnimator(android.animation.ValueAnimator) ChangeAlpha(com.linfaxin.transitionplayer.transitions.ChangeAlpha) LockStartTimeInterpolator(com.linfaxin.transitionplayer.interpolators.LockStartTimeInterpolator) LockEndTimeInterpolator(com.linfaxin.transitionplayer.interpolators.LockEndTimeInterpolator) SwipeLayout(com.daimajia.swipe.SwipeLayout) ViewTreeObserver(android.view.ViewTreeObserver) ViewGroup(android.view.ViewGroup) ObjectAnimator(android.animation.ObjectAnimator) ChangeBounds(android.transitions.everywhere.ChangeBounds) Scene(android.transitions.everywhere.Scene) View(android.view.View) TimeInterpolator(android.animation.TimeInterpolator) ReverseTimeInterpolator(com.linfaxin.transitionplayer.interpolators.ReverseTimeInterpolator) MultiTimeInterpolator(com.linfaxin.transitionplayer.interpolators.MultiTimeInterpolator) LockEndTimeInterpolator(com.linfaxin.transitionplayer.interpolators.LockEndTimeInterpolator) LockStartTimeInterpolator(com.linfaxin.transitionplayer.interpolators.LockStartTimeInterpolator) ReverseTimeInterpolator(com.linfaxin.transitionplayer.interpolators.ReverseTimeInterpolator) MultiTimeInterpolator(com.linfaxin.transitionplayer.interpolators.MultiTimeInterpolator) ModifyAnimatorsPlayControl(com.linfaxin.transitionplayer.control.ModifyAnimatorsPlayControl) Transition(android.transitions.everywhere.Transition)

Aggregations

SwipeLayout (com.daimajia.swipe.SwipeLayout)6 View (android.view.View)5 TextView (android.widget.TextView)2 SimpleSwipeListener (com.daimajia.swipe.SimpleSwipeListener)2 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 TimeInterpolator (android.animation.TimeInterpolator)1 ValueAnimator (android.animation.ValueAnimator)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ChangeBounds (android.transitions.everywhere.ChangeBounds)1 Scene (android.transitions.everywhere.Scene)1 Transition (android.transitions.everywhere.Transition)1 ViewGroup (android.view.ViewGroup)1 ViewTreeObserver (android.view.ViewTreeObserver)1 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)1 ModifyAnimatorsPlayControl (com.linfaxin.transitionplayer.control.ModifyAnimatorsPlayControl)1 LockEndTimeInterpolator (com.linfaxin.transitionplayer.interpolators.LockEndTimeInterpolator)1 LockStartTimeInterpolator (com.linfaxin.transitionplayer.interpolators.LockStartTimeInterpolator)1 MultiTimeInterpolator (com.linfaxin.transitionplayer.interpolators.MultiTimeInterpolator)1 ReverseTimeInterpolator (com.linfaxin.transitionplayer.interpolators.ReverseTimeInterpolator)1