Search in sources :

Example 1 with CalendarFragment

use of info.hxq.materialcalendar.fragment.CalendarFragment 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

MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 InjectView (butterknife.InjectView)1 SimpleSpringListener (com.facebook.rebound.SimpleSpringListener)1 Spring (com.facebook.rebound.Spring)1 SpringSystem (com.facebook.rebound.SpringSystem)1 CalendarFragment (info.hxq.materialcalendar.fragment.CalendarFragment)1