Search in sources :

Example 16 with Spring

use of com.facebook.rebound.Spring 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 17 with Spring

use of com.facebook.rebound.Spring 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)

Example 18 with Spring

use of com.facebook.rebound.Spring 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)

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