use of com.facebook.rebound.Spring in project rebound by facebook.
the class PhotoGalleryExample method render.
private void render() {
for (int i = 0; i < mImageViews.size(); i++) {
ImageView imageView = mImageViews.get(i);
if (mSpring.isAtRest() && mSpring.getCurrentValue() == 0) {
// Performing the initial entry transition animation.
Spring spring = mSpringChain.getAllSprings().get(i);
float val = (float) spring.getCurrentValue();
imageView.setScaleX(val);
imageView.setScaleY(val);
imageView.setAlpha(val);
Point pos = mPositions.get(i);
imageView.setTranslationX(pos.x);
imageView.setTranslationY(pos.y);
} else {
// Scaling up a photo to fullscreen size.
Point pos = mPositions.get(i);
if (i == mActiveIndex) {
float ww = imageView.getWidth();
float hh = imageView.getHeight();
float sx = getWidth() / ww;
float sy = getHeight() / hh;
float s = sx > sy ? sx : sy;
float xlatX = (float) SpringUtil.mapValueFromRangeToRange(mSpring.getCurrentValue(), 0, 1, pos.x, 0);
float xlatY = (float) SpringUtil.mapValueFromRangeToRange(mSpring.getCurrentValue(), 0, 1, pos.y, 0);
imageView.setPivotX(0);
imageView.setPivotY(0);
imageView.setTranslationX(xlatX);
imageView.setTranslationY(xlatY);
float ss = (float) SpringUtil.mapValueFromRangeToRange(mSpring.getCurrentValue(), 0, 1, 1, s);
imageView.setScaleX(ss);
imageView.setScaleY(ss);
} else {
float val = (float) Math.max(0, 1 - mSpring.getCurrentValue());
imageView.setAlpha(val);
}
}
}
}
use of com.facebook.rebound.Spring in project Depth-LIB-Android- by danielzeller.
the class ReboundObjectAnimator method start.
public void start() {
spring = SpringSystem.create().createSpring();
spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(tension, friction));
final float moveAmount = to - from;
spring.addListener(new SimpleSpringListener() {
@Override
public void onSpringUpdate(Spring spring) {
fraction = (float) spring.getCurrentValue();
currentAnimatedValue = from + fraction * moveAmount;
if (propertyMethod != null)
try {
propertyMethod.invoke(target, currentAnimatedValue);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
else if (property != null)
property.set((View) target, currentAnimatedValue);
if (updateListeners != null)
for (AnimatorUpdateListener updateListener : updateListeners) updateListener.onAnimationUpdate(ReboundObjectAnimator.this);
}
@Override
public void onSpringAtRest(Spring spring) {
super.onSpringAtRest(spring);
spring.destroy();
if (getListeners() != null)
for (AnimatorListener listener : getListeners()) listener.onAnimationEnd(null);
removeAllListeners();
}
});
spring.setEndValue(1);
}
use of com.facebook.rebound.Spring 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.Spring in project FloatingView by UFreedom.
the class SpringHelper method start.
public void start(final YumFloating yumFloating) {
if (mConfig == -1) {
throw new IllegalStateException("Hi , You must call one of the method configBouncinessAndSpeed and configTensionAndFriction to make mConfig");
}
Spring spring = null;
if (mConfig == 0) {
spring = yumFloating.createSpringByBouncinessAndSpeed(mConfigValueOne, mConfigValueTwo);
} else if (mConfig == 1) {
spring = yumFloating.createSpringByTensionAndFriction(mConfigValueOne, mConfigValueTwo);
}
start(spring);
}
use of com.facebook.rebound.Spring in project Backboard by tumblr.
the class ExplosionFragment method createCircle.
private static void createCircle(Context context, ViewGroup rootView, SpringSystem springSystem, SpringConfig coasting, SpringConfig gravity, int diameter, Drawable backgroundDrawable) {
final Spring xSpring = springSystem.createSpring().setSpringConfig(coasting);
final Spring ySpring = springSystem.createSpring().setSpringConfig(gravity);
// create view
View view = new View(context);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(diameter, diameter);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
view.setLayoutParams(params);
view.setBackgroundDrawable(backgroundDrawable);
rootView.addView(view);
// generate random direction and magnitude
double magnitude = Math.random() * 1000 + 3000;
double angle = Math.random() * Math.PI / 2 + Math.PI / 4;
xSpring.setVelocity(magnitude * Math.cos(angle));
ySpring.setVelocity(-magnitude * Math.sin(angle));
int maxX = rootView.getMeasuredWidth() / 2 + diameter;
xSpring.addListener(new Destroyer(rootView, view, -maxX, maxX));
int maxY = rootView.getMeasuredHeight() / 2 + diameter;
ySpring.addListener(new Destroyer(rootView, view, -maxY, maxY));
xSpring.addListener(new Performer(view, View.TRANSLATION_X));
ySpring.addListener(new Performer(view, View.TRANSLATION_Y));
// set a different end value to cause the animation to play
xSpring.setEndValue(2);
ySpring.setEndValue(9001);
}
Aggregations