Skip to content

Instantly share code, notes, and snippets.

Created February 24, 2015 09:26
What would you like to do?
Android Code Exported from Origami
package com.facebook.origami;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import com.facebook.rebound.SimpleSpringListener;
import com.facebook.rebound.Spring;
import com.facebook.rebound.SpringConfig;
import com.facebook.rebound.SpringSystem;
import com.facebook.rebound.SpringUtil;
public class OrigamiAnimationView extends FrameLayout {
private final SpringSystem springSystem;
private final Spring photoZoomSpring;
private final Spring fadeSpring;
private final View story;
private final View photo;
public OrigamiAnimationView(Context context) {
this(context, null);
public OrigamiAnimationView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
public OrigamiAnimationView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// Hook up variables to your views here
story = null;
photo = null;
springSystem = SpringSystem.create();
photoZoomSpring = springSystem.createSpring()
.setSpringConfig(SpringConfig.withBouncinessAndSpeed(7, 2))
.addListener(new SimpleSpringListener() {
public void onSpringUpdate(Spring spring) {
setPhotoZoomProgress((float) spring.getCurrentValue());
fadeSpring = springSystem.createSpring()
.setSpringConfig(SpringConfig.withBouncinessAndSpeed(15, 2))
.addListener(new SimpleSpringListener() {
public void onSpringUpdate(Spring spring) {
setFadeProgress((float) spring.getCurrentValue());
// photoZoom transition
public void photoZoom(boolean on) {
photoZoomSpring.setEndValue(on ? 1 : 0);
public void setPhotoZoomProgress(float progress) {
float alpha2 = transition(progress, 1f, 0f);
float scale2 = transition(progress, 0.4797f, 0.55f);
float yPosition2 = transition(progress, -186f, 0f);
float scale2 = transition(progress, 1f, 0.97f);
float rotation2 = transition(progress, 0f, 30f);
// fade transition
public void fade(boolean on) {
fadeSpring.setEndValue(on ? 1 : 0);
public void setFadeProgress(float progress) {
float alpha2 = transition(progress, 1f, 0.3f);
// Utilities
public float transition (float progress, float startValue, float endValue) {
return (float) SpringUtil.mapValueFromRangeToRange(progress, 0, 1, startValue, endValue);
Copy link

What pcqpcq mean to say was line 68 and line 78. They both instantiate float scale2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment