Skip to content

Instantly share code, notes, and snippets.

Embed
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() {
@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);
}
}
@Mr-Antivirus

This comment has been minimized.

Copy link

commented Oct 17, 2016

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
You can’t perform that action at this time.