Search in sources :

Example 1 with SpringConfig

use of com.facebook.rebound.SpringConfig 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 2 with SpringConfig

use of com.facebook.rebound.SpringConfig 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 3 with SpringConfig

use of com.facebook.rebound.SpringConfig in project TastyToast by yadav-rahul.

the class TastyToast method makeText.

public static Toast makeText(Context context, String msg, int length, int type) {
    Toast toast = new Toast(context);
    switch(type) {
        case 1:
            {
                View layout = LayoutInflater.from(context).inflate(R.layout.success_toast_layout, null, false);
                TextView text = (TextView) layout.findViewById(R.id.toastMessage);
                text.setText(msg);
                successToastView = (SuccessToastView) layout.findViewById(R.id.successView);
                successToastView.startAnim();
                text.setBackgroundResource(R.drawable.success_toast);
                text.setTextColor(Color.parseColor("#FFFFFF"));
                toast.setView(layout);
                break;
            }
        case 2:
            {
                View layout = LayoutInflater.from(context).inflate(R.layout.warning_toast_layout, null, false);
                TextView text = (TextView) layout.findViewById(R.id.toastMessage);
                text.setText(msg);
                warningToastView = (WarningToastView) layout.findViewById(R.id.warningView);
                SpringSystem springSystem = SpringSystem.create();
                final Spring spring = springSystem.createSpring();
                spring.setCurrentValue(1.8);
                SpringConfig config = new SpringConfig(40, 5);
                spring.setSpringConfig(config);
                spring.addListener(new SimpleSpringListener() {

                    @Override
                    public void onSpringUpdate(Spring spring) {
                        float value = (float) spring.getCurrentValue();
                        float scale = (float) (0.9f - (value * 0.5f));
                        warningToastView.setScaleX(scale);
                        warningToastView.setScaleY(scale);
                    }
                });
                Thread t = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                        }
                        spring.setEndValue(0.4f);
                    }
                });
                t.start();
                text.setBackgroundResource(R.drawable.warning_toast);
                text.setTextColor(Color.parseColor("#FFFFFF"));
                toast.setView(layout);
                break;
            }
        case 3:
            {
                View layout = LayoutInflater.from(context).inflate(R.layout.error_toast_layout, null, false);
                TextView text = (TextView) layout.findViewById(R.id.toastMessage);
                text.setText(msg);
                errorToastView = (ErrorToastView) layout.findViewById(R.id.errorView);
                errorToastView.startAnim();
                text.setBackgroundResource(R.drawable.error_toast);
                text.setTextColor(Color.parseColor("#FFFFFF"));
                toast.setView(layout);
                break;
            }
        case 4:
            {
                View layout = LayoutInflater.from(context).inflate(R.layout.info_toast_layout, null, false);
                TextView text = (TextView) layout.findViewById(R.id.toastMessage);
                text.setText(msg);
                infoToastView = (InfoToastView) layout.findViewById(R.id.infoView);
                infoToastView.startAnim();
                text.setBackgroundResource(R.drawable.info_toast);
                text.setTextColor(Color.parseColor("#FFFFFF"));
                toast.setView(layout);
                break;
            }
        case 5:
            {
                View layout = LayoutInflater.from(context).inflate(R.layout.default_toast_layout, null, false);
                TextView text = (TextView) layout.findViewById(R.id.toastMessage);
                text.setText(msg);
                defaultToastView = (DefaultToastView) layout.findViewById(R.id.defaultView);
                defaultToastView.startAnim();
                text.setBackgroundResource(R.drawable.default_toast);
                text.setTextColor(Color.parseColor("#FFFFFF"));
                toast.setView(layout);
                break;
            }
        case 6:
            {
                View layout = LayoutInflater.from(context).inflate(R.layout.confusing_toast_layout, null, false);
                TextView text = (TextView) layout.findViewById(R.id.toastMessage);
                text.setText(msg);
                confusingToastView = (ConfusingToastView) layout.findViewById(R.id.confusingView);
                confusingToastView.startAnim();
                text.setBackgroundResource(R.drawable.confusing_toast);
                text.setTextColor(Color.parseColor("#FFFFFF"));
                toast.setView(layout);
                break;
            }
    }
    toast.setDuration(length);
    toast.show();
    return toast;
}
Also used : SimpleSpringListener(com.facebook.rebound.SimpleSpringListener) Spring(com.facebook.rebound.Spring) TextView(android.widget.TextView) View(android.view.View) SpringSystem(com.facebook.rebound.SpringSystem) Toast(android.widget.Toast) TextView(android.widget.TextView) SpringConfig(com.facebook.rebound.SpringConfig)

Example 4 with SpringConfig

use of com.facebook.rebound.SpringConfig in project android_packages_apps_DUI by DirtyUnicorns.

the class SmartButtonView method setSpringEnabled.

private void setSpringEnabled(boolean enabled) {
    if (enabled) {
        mSpring = mHost.getSpringSystem().createSpring();
        mSpring.addListener(mSpringListener);
        SpringConfig config = new SpringConfig(TENSION, FRICTION);
        mSpring.setSpringConfig(config);
    } else {
        if (mSpring != null) {
            if (getScaleX() != 1f || getScaleY() != 1f) {
                mSpring.setCurrentValue(0f);
            }
            mSpring.removeListener(mSpringListener);
            mSpring.destroy();
            mSpring = null;
        }
    }
}
Also used : SpringConfig(com.facebook.rebound.SpringConfig)

Aggregations

SpringConfig (com.facebook.rebound.SpringConfig)4 SimpleSpringListener (com.facebook.rebound.SimpleSpringListener)3 Spring (com.facebook.rebound.Spring)3 SpringSystem (com.facebook.rebound.SpringSystem)3 View (android.view.View)2 RecyclerView (android.support.v7.widget.RecyclerView)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1