Search in sources :

Example 11 with Spring

use of com.facebook.rebound.Spring in project rebound by facebook.

the class PhotoGalleryExample method render.

private void render() {
    for (int i = 0; i < mImageViews.size(); i++) {
        ImageView imageView = mImageViews.get(i);
        if (mSpring.isAtRest() && mSpring.getCurrentValue() == 0) {
            // Performing the initial entry transition animation.
            Spring spring = mSpringChain.getAllSprings().get(i);
            float val = (float) spring.getCurrentValue();
            imageView.setScaleX(val);
            imageView.setScaleY(val);
            imageView.setAlpha(val);
            Point pos = mPositions.get(i);
            imageView.setTranslationX(pos.x);
            imageView.setTranslationY(pos.y);
        } else {
            // Scaling up a photo to fullscreen size.
            Point pos = mPositions.get(i);
            if (i == mActiveIndex) {
                float ww = imageView.getWidth();
                float hh = imageView.getHeight();
                float sx = getWidth() / ww;
                float sy = getHeight() / hh;
                float s = sx > sy ? sx : sy;
                float xlatX = (float) SpringUtil.mapValueFromRangeToRange(mSpring.getCurrentValue(), 0, 1, pos.x, 0);
                float xlatY = (float) SpringUtil.mapValueFromRangeToRange(mSpring.getCurrentValue(), 0, 1, pos.y, 0);
                imageView.setPivotX(0);
                imageView.setPivotY(0);
                imageView.setTranslationX(xlatX);
                imageView.setTranslationY(xlatY);
                float ss = (float) SpringUtil.mapValueFromRangeToRange(mSpring.getCurrentValue(), 0, 1, 1, s);
                imageView.setScaleX(ss);
                imageView.setScaleY(ss);
            } else {
                float val = (float) Math.max(0, 1 - mSpring.getCurrentValue());
                imageView.setAlpha(val);
            }
        }
    }
}
Also used : ImageView(android.widget.ImageView) Point(android.graphics.Point) Spring(com.facebook.rebound.Spring) Point(android.graphics.Point)

Example 12 with Spring

use of com.facebook.rebound.Spring in project Depth-LIB-Android- by danielzeller.

the class ReboundObjectAnimator method start.

public void start() {
    spring = SpringSystem.create().createSpring();
    spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(tension, friction));
    final float moveAmount = to - from;
    spring.addListener(new SimpleSpringListener() {

        @Override
        public void onSpringUpdate(Spring spring) {
            fraction = (float) spring.getCurrentValue();
            currentAnimatedValue = from + fraction * moveAmount;
            if (propertyMethod != null)
                try {
                    propertyMethod.invoke(target, currentAnimatedValue);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            else if (property != null)
                property.set((View) target, currentAnimatedValue);
            if (updateListeners != null)
                for (AnimatorUpdateListener updateListener : updateListeners) updateListener.onAnimationUpdate(ReboundObjectAnimator.this);
        }

        @Override
        public void onSpringAtRest(Spring spring) {
            super.onSpringAtRest(spring);
            spring.destroy();
            if (getListeners() != null)
                for (AnimatorListener listener : getListeners()) listener.onAnimationEnd(null);
            removeAllListeners();
        }
    });
    spring.setEndValue(1);
}
Also used : SimpleSpringListener(com.facebook.rebound.SimpleSpringListener) Spring(com.facebook.rebound.Spring) View(android.view.View) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 13 with Spring

use of com.facebook.rebound.Spring in project FloatingView by UFreedom.

the class SpringHelper method start.

public void start() {
    SpringSystem springSystem = SpringSystem.create();
    Spring spring = springSystem.createSpring();
    if (mConfig == 0) {
        spring.setSpringConfig(SpringConfig.fromBouncinessAndSpeed(mConfigValueOne, mConfigValueTwo));
    } else if (mConfig == 1) {
        spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(mConfigValueOne, mConfigValueTwo));
    }
    start(spring);
}
Also used : Spring(com.facebook.rebound.Spring) SpringSystem(com.facebook.rebound.SpringSystem)

Example 14 with Spring

use of com.facebook.rebound.Spring in project FloatingView by UFreedom.

the class SpringHelper method start.

public void start(final YumFloating yumFloating) {
    if (mConfig == -1) {
        throw new IllegalStateException("Hi , You must call one of the method configBouncinessAndSpeed and configTensionAndFriction to make mConfig");
    }
    Spring spring = null;
    if (mConfig == 0) {
        spring = yumFloating.createSpringByBouncinessAndSpeed(mConfigValueOne, mConfigValueTwo);
    } else if (mConfig == 1) {
        spring = yumFloating.createSpringByTensionAndFriction(mConfigValueOne, mConfigValueTwo);
    }
    start(spring);
}
Also used : Spring(com.facebook.rebound.Spring)

Example 15 with Spring

use of com.facebook.rebound.Spring in project Backboard by tumblr.

the class ExplosionFragment method createCircle.

private static void createCircle(Context context, ViewGroup rootView, SpringSystem springSystem, SpringConfig coasting, SpringConfig gravity, int diameter, Drawable backgroundDrawable) {
    final Spring xSpring = springSystem.createSpring().setSpringConfig(coasting);
    final Spring ySpring = springSystem.createSpring().setSpringConfig(gravity);
    // create view
    View view = new View(context);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(diameter, diameter);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    view.setLayoutParams(params);
    view.setBackgroundDrawable(backgroundDrawable);
    rootView.addView(view);
    // generate random direction and magnitude
    double magnitude = Math.random() * 1000 + 3000;
    double angle = Math.random() * Math.PI / 2 + Math.PI / 4;
    xSpring.setVelocity(magnitude * Math.cos(angle));
    ySpring.setVelocity(-magnitude * Math.sin(angle));
    int maxX = rootView.getMeasuredWidth() / 2 + diameter;
    xSpring.addListener(new Destroyer(rootView, view, -maxX, maxX));
    int maxY = rootView.getMeasuredHeight() / 2 + diameter;
    ySpring.addListener(new Destroyer(rootView, view, -maxY, maxY));
    xSpring.addListener(new Performer(view, View.TRANSLATION_X));
    ySpring.addListener(new Performer(view, View.TRANSLATION_Y));
    // set a different end value to cause the animation to play
    xSpring.setEndValue(2);
    ySpring.setEndValue(9001);
}
Also used : Performer(com.tumblr.backboard.performer.Performer) RelativeLayout(android.widget.RelativeLayout) Spring(com.facebook.rebound.Spring) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

Aggregations

Spring (com.facebook.rebound.Spring)18 SpringSystem (com.facebook.rebound.SpringSystem)11 View (android.view.View)10 SimpleSpringListener (com.facebook.rebound.SimpleSpringListener)7 Performer (com.tumblr.backboard.performer.Performer)5 SuppressLint (android.annotation.SuppressLint)3 TypedArray (android.content.res.TypedArray)3 RelativeLayout (android.widget.RelativeLayout)3 SpringConfig (com.facebook.rebound.SpringConfig)3 MotionEvent (android.view.MotionEvent)2 Actor (com.tumblr.backboard.Actor)2 ToggleImitator (com.tumblr.backboard.imitator.ToggleImitator)2 MapPerformer (com.tumblr.backboard.performer.MapPerformer)2 Point (android.graphics.Point)1 RecyclerView (android.support.v7.widget.RecyclerView)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 InjectView (butterknife.InjectView)1