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);
}
});
}
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);
}
}
}
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);
}
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;
}
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;
}
});
}
Aggregations