Skip to content

Instantly share code, notes, and snippets.

@bwalkin
Created February 24, 2015 09:26
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save bwalkin/093f28328a6da0f2070f to your computer and use it in GitHub Desktop.
Save bwalkin/093f28328a6da0f2070f to your computer and use it in GitHub Desktop.
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() {
@Override
public void onSpringUpdate(Spring spring) {
setPhotoZoomProgress((float) spring.getCurrentValue());
}
});
fadeSpring = springSystem.createSpring()
.setSpringConfig(SpringConfig.withBouncinessAndSpeed(15, 2))
.addListener(new SimpleSpringListener() {
@Override
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);
story.setOpacity(alpha2);
float scale2 = transition(progress, 0.4797f, 0.55f);
photo.setScaleX(scale2);
photo.setScaleY(scale2);
float yPosition2 = transition(progress, -186f, 0f);
photo.setTranslationY(yPosition2);
float scale2 = transition(progress, 1f, 0.97f);
story.setScaleX(scale2);
story.setScaleY(scale2);
float rotation2 = transition(progress, 0f, 30f);
photo.setRotation(rotation2);
}
// fade transition
public void fade(boolean on) {
fadeSpring.setEndValue(on ? 1 : 0);
}
public void setFadeProgress(float progress) {
float alpha2 = transition(progress, 1f, 0.3f);
photo.setOpacity(alpha2);
}
// Utilities
public float transition (float progress, float startValue, float endValue) {
return (float) SpringUtil.mapValueFromRangeToRange(progress, 0, 1, startValue, endValue);
}
}
@mrantivirus
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