Search in sources :

Example 6 with SpringSystem

use of com.facebook.rebound.SpringSystem in project android-card-slide-panel by xmuSistone.

the class CardItemView method initSpring.

private void initSpring() {
    SpringConfig springConfig = SpringConfig.fromBouncinessAndSpeed(15, 20);
    SpringSystem mSpringSystem = SpringSystem.create();
    springX = mSpringSystem.createSpring().setSpringConfig(springConfig);
    springY = mSpringSystem.createSpring().setSpringConfig(springConfig);
    springX.addListener(new SimpleSpringListener() {

        @Override
        public void onSpringUpdate(Spring spring) {
            int xPos = (int) spring.getCurrentValue();
            setScreenX(xPos);
            parentView.onViewPosChanged(CardItemView.this);
        }
    });
    springY.addListener(new SimpleSpringListener() {

        @Override
        public void onSpringUpdate(Spring spring) {
            int yPos = (int) spring.getCurrentValue();
            setScreenY(yPos);
            parentView.onViewPosChanged(CardItemView.this);
        }
    });
}
Also used : SimpleSpringListener(com.facebook.rebound.SimpleSpringListener) SpringConfig(com.facebook.rebound.SpringConfig) Spring(com.facebook.rebound.Spring) SpringSystem(com.facebook.rebound.SpringSystem)

Example 7 with SpringSystem

use of com.facebook.rebound.SpringSystem in project LollipopShowcase by mikepenz.

the class ReboundItemAnimator method runPendingAnimations.

@Override
public void runPendingAnimations() {
    if (!mViewHolders.isEmpty()) {
        for (final RecyclerView.ViewHolder viewHolder : mViewHolders) {
            SpringSystem springSystem = SpringSystem.create();
            SpringConfig springConfig = new SpringConfig(70, 10);
            final View target = viewHolder.itemView;
            // Add a spring to the system.
            Spring spring = springSystem.createSpring();
            spring.setSpringConfig(springConfig);
            spring.setCurrentValue(0.0f);
            // Add a listener to observe the motion of the spring.
            spring.addListener(new SimpleSpringListener() {

                @Override
                public void onSpringUpdate(Spring spring) {
                    // You can observe the updates in the spring
                    // state by asking its current value in onSpringUpdate.
                    float value = (float) spring.getCurrentValue();
                    target.setScaleX(value);
                    target.setScaleY(value);
                }
            });
            // Set the spring in motion; moving from 0 to 1
            spring.setEndValue(1.0f);
        }
    }
}
Also used : SimpleSpringListener(com.facebook.rebound.SimpleSpringListener) RecyclerView(android.support.v7.widget.RecyclerView) SpringConfig(com.facebook.rebound.SpringConfig) Spring(com.facebook.rebound.Spring) SpringSystem(com.facebook.rebound.SpringSystem) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 8 with SpringSystem

use of com.facebook.rebound.SpringSystem 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 9 with SpringSystem

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

the class ScaleFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_scale, container, false);
    final View rect = rootView.findViewById(R.id.rect);
    final SpringSystem springSystem = SpringSystem.create();
    final Spring spring = springSystem.createSpring();
    spring.addListener(new Performer(rect, View.SCALE_X));
    spring.addListener(new Performer(rect, View.SCALE_Y));
    rootView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        @SuppressLint("ClickableViewAccessibility")
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    spring.setVelocity(0);
                case MotionEvent.ACTION_MOVE:
                    // can't use Imitation here because there is no nice mapping from
                    // an event property to a Spring
                    float scaleX, scaleY;
                    float delta = event.getX() - (rect.getX() + rect.getMeasuredWidth() / 2);
                    scaleX = Math.abs(delta) / (rect.getMeasuredWidth() / 2);
                    delta = event.getY() - (rect.getY() + rect.getMeasuredHeight() / 2);
                    scaleY = Math.abs(delta) / (rect.getMeasuredHeight() / 2);
                    float scale = Math.max(scaleX, scaleY);
                    spring.setEndValue(scale);
                    break;
                case MotionEvent.ACTION_UP:
                    spring.setEndValue(1f);
                    break;
            }
            return true;
        }
    });
    return rootView;
}
Also used : Performer(com.tumblr.backboard.performer.Performer) SuppressLint(android.annotation.SuppressLint) Spring(com.facebook.rebound.Spring) View(android.view.View) SpringSystem(com.facebook.rebound.SpringSystem) MotionEvent(android.view.MotionEvent)

Example 10 with SpringSystem

use of com.facebook.rebound.SpringSystem in project MaterialCalendar by Haoxiqiang.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.inject(this);
    TabooProxy.init();
    getSupportFragmentManager().beginTransaction().add(R.id.container, new CalendarFragment()).commit();
    SpringSystem mSpringSystem = SpringSystem.create();
    final Spring spring = mSpringSystem.createSpring();
    spring.addListener(new SimpleSpringListener() {

        @Override
        public void onSpringUpdate(Spring spring) {
            float mappedValue = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 0.6);
            ViewCompat.setScaleX(view, mappedValue);
            ViewCompat.setScaleY(view, mappedValue);
        }
    });
    view.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    // When pressed start solving the spring to 1.
                    spring.setEndValue(1);
                    break;
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL:
                    // When released start solving the spring to 0.
                    spring.setEndValue(0);
                    break;
            }
            return false;
        }
    });
}
Also used : SimpleSpringListener(com.facebook.rebound.SimpleSpringListener) CalendarFragment(info.hxq.materialcalendar.fragment.CalendarFragment) Spring(com.facebook.rebound.Spring) SpringSystem(com.facebook.rebound.SpringSystem) InjectView(butterknife.InjectView) View(android.view.View) MotionEvent(android.view.MotionEvent)

Aggregations

Spring (com.facebook.rebound.Spring)11 SpringSystem (com.facebook.rebound.SpringSystem)11 View (android.view.View)8 SimpleSpringListener (com.facebook.rebound.SimpleSpringListener)4 Performer (com.tumblr.backboard.performer.Performer)4 TypedArray (android.content.res.TypedArray)3 SpringConfig (com.facebook.rebound.SpringConfig)3 SuppressLint (android.annotation.SuppressLint)2 MotionEvent (android.view.MotionEvent)2 RelativeLayout (android.widget.RelativeLayout)2 Actor (com.tumblr.backboard.Actor)2 ToggleImitator (com.tumblr.backboard.imitator.ToggleImitator)2 MapPerformer (com.tumblr.backboard.performer.MapPerformer)2 RecyclerView (android.support.v7.widget.RecyclerView)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 InjectView (butterknife.InjectView)1 EventImitator (com.tumblr.backboard.imitator.EventImitator)1 MotionImitator (com.tumblr.backboard.imitator.MotionImitator)1