Search in sources :

Example 1 with SpringConfig

use of com.marshalchen.common.uimodule.rebound.SpringConfig in project UltimateAndroid by cymcsg.

the class KugouLayout method init.

private void init(Context context) {
    setBackgroundColor(0x0);
    /**
         * Distance in pixels a touch can wander before we think the user is scrolling
         * */
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledTouchSlop();
    mMaxVelocity = configuration.getScaledMaximumFlingVelocity();
    mContentContainer = new UnClickableFrameLayout(context);
    mContentContainer.setId(R.id.kugou_layout_md__content);
    /**
         * init Property Animation
         * */
    mAnimatorSet = new AnimatorSet();
    mOffsetAnimator = ObjectAnimator.ofFloat(this, aOffset, 0, 0);
    mOffsetAnimator.setDuration(ANIM_DURATION);
    mAnimatorSet.playTogether(mOffsetAnimator);
    mAnimatorSet.setInterpolator(mInterpolator);
    mOffsetAnimator.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            float endValue = (Float) mOffsetAnimator.getAnimatedValue();
            if ((endValue == getWidth() || endValue == -getWidth())) {
                setVisibility(INVISIBLE);
                if (null != mLayoutCloseListener) {
                    mLayoutCloseListener.onLayoutClose();
                }
            } else if (endValue == 0 && showingChangeAlpha) {
                showingChangeAlpha = false;
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    /**
         * create rebound animator
         * */
    mSpringSystem = SpringSystem.create();
    mSpring = mSpringSystem.createSpring();
    SpringConfig config = new SpringConfig(70, 9);
    mSpring.setSpringConfig(config);
    mSpring.setCurrentValue(0);
    mSpring.addListener(new SpringListener() {

        @Override
        public void onSpringUpdate(Spring spring) {
            if (doAnim) {
                double newValue = 1 - spring.getCurrentValue();
                mOffsetPixels = (float) newValue * mBeginOffsetX;
                moveContent();
                if (showingChangeAlpha) {
                    changeAlpha();
                }
            }
        }

        @Override
        public void onSpringAtRest(Spring spring) {
        }

        @Override
        public void onSpringActivate(Spring spring) {
        }

        @Override
        public void onSpringEndStateChange(Spring spring) {
        }
    });
    /**
         * add frame_layout mContentContainer as the parent of the activity's content view
         * */
    super.addView(mContentContainer, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    mContentContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
Also used : ViewConfiguration(android.view.ViewConfiguration) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) SpringListener(com.marshalchen.common.uimodule.rebound.SpringListener) AnimatorSet(android.animation.AnimatorSet) SpringConfig(com.marshalchen.common.uimodule.rebound.SpringConfig) Spring(com.marshalchen.common.uimodule.rebound.Spring)

Aggregations

Animator (android.animation.Animator)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 ViewConfiguration (android.view.ViewConfiguration)1 Spring (com.marshalchen.common.uimodule.rebound.Spring)1 SpringConfig (com.marshalchen.common.uimodule.rebound.SpringConfig)1 SpringListener (com.marshalchen.common.uimodule.rebound.SpringListener)1