facebookarchive / rebound Goto Github PK
View Code? Open in Web Editor NEWA Java library that models spring dynamics and adds real world physics to your app.
Home Page: http://facebook.github.io/rebound/
License: Other
A Java library that models spring dynamics and adds real world physics to your app.
Home Page: http://facebook.github.io/rebound/
License: Other
Please explain differences between isAtRest()
and wasAtRest()
, thx.
Any chance Gradle/Maven support will be added?
Ideally a developer could add this to their project as simply as adding this to the build.gradle:
dependencies {
compile group: 'com.facebook.rebound', name: 'rebound', version: '1.0'
}
Hi,
At first, I referenced rebound library to sample project of rebound in eclipse and then
I am running sample project of rebound, gc overhead occurs in the eclipse and I can not launch sample project. Console window in my eclipse logs like following link : https://gist.github.com/sarizeybek/8280388#file-rebound_error
If I add rebound library to sample project as jar, android.view.InflateException error occurs. Details of logcat : https://gist.github.com/sarizeybek/8280452#file-rebound_layout_error
How can I fix those errors?
Thanks.
It's possible to use algebraic integration on the damped spring equation, and you get something that implements the same model as Rebound but is faster to compute, a pure function of time and more accurate than doing a numerical integration like RK4.
I did a Java implementation of this here: https://github.com/iamralpht/gravitas/blob/master/Gravitas/src/com/infinite_imagination/physics/Spring.java (the interface was inspired by Rebound, and I originally made it after playing with Rebound but wanting something fast enough that I could generate keyframes for a spring animation in a couple of ms on device).
Also I transliterated it to JavaScript here:
https://github.com/iamralpht/iamralpht.github.io/blob/master/fab/demo/fab.js (you can see it in action here: http://iamralpht.github.io/fab -- the UI was inspired by the Facebook Home menu system, which I really liked!).
It ends up being a lot less code than Rebound (but maybe Rebound does a lot more than damped springs...).
Finally, here's a link to the physics textbook I cribbed the equations from (although after playing around in Maxima I was able to reproduce them there): http://www.stewartcalculus.com/data/CALCULUS%20Concepts%20and%20Contexts/upfiles/3c3-AppsOf2ndOrders_Stu.pdf
This commit removed dependency on Guava but the downloadable jar has not been updated. It still requires Guava and crashes when it cannot find it. Either the Readme should be reverted to say that Guava is needed or the jar should be updated.
Hi, I would like to be able to download the samples apk.
I tried to compile the source code, but I just have the jdk 1.8 in my machine and #53 says it is not compatible with that..so, could you, please, make the samples apk available?
Am I missing something or do I have to download and look through the code (and possibly bundled examples) to see how this works? Normally a quick tutorial / wiki page with some examples can help greatly reduce the pain of going through code examples.
SpringScrollView
how to judge the slide to the bottom?
I cannot find any relevant resource to get started with it. Are there any documentation for Rebound Java ?
Thanks!
To synchronise Android Animators with Springs, it would be nice to know the time it takes for a spring to be back at rest
ie
Animator fadeIn = ...;
double springDuration = spring.duration(double startValue, double endValue);
fadeIn.setStartDelay(springDuration);
I realized there aren't many samples on the inter-webs on how to integrate rebound in android applications(and the ones there are scarcely descriptive). So, i have created a repository so that anyone willing can add there an example where rebound can be used. The first example ports the Scaling animation to android. I hope this helps developers who may want to use it.
@willbailey What do you think about a sequencer Spring? It's similar of SpringChain but without any interaction with another springs. Look like:
SpringSquencer().create()
.add(0, new Spring())
.add(1, new Spring(), 1000)
.add(2, new Spring());
The first spring(at 0 index) will run, when this animation ends, it will run the second spring(at index 1) and wait 1000 miliseconds to run the spring at index 2.
Reimplement the example animations shown in Pop Playground using Rebound on Android.
Would you explain to me how to understand these params by your sample app
// On each update of the spring value, we adjust the scale of the image view to match the
// springs new value. We use the SpringUtil linear interpolation function mapValueFromRangeToRange
// to translate the spring's 0 to 1 scale to a 100% to 50% scale range and apply that to the View
// with setScaleX/Y. Note that rendering is an implementation detail of the application and not
// Rebound itself. If you need Gingerbread compatibility consider using NineOldAndroids to update
// your view properties in a backwards compatible manner.
float mappedValue = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 0.5);
At the end, I would like to apply the spring's 0 to 1 to 400dp to 100 dp in the layout height. Please let me know how to apply it into SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 0.5);
. Thank you so much.
Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
...while parsing com/facebook/rebound/BaseSpringSystem.class
Error:1 error; aborting
Error:Execution failed for task ':rebound-android-playground:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.dx.command.Main with arguments {--dex --num-threads=4 --output /Users/huaihuhu/Desktop/rebound/rebound-0.3.8/rebound-android-playground/build/intermediates/transforms/dex/debug/folders/1000/1f/main /Users/huaihuhu/Desktop/rebound/rebound-0.3.8/rebound-core/build/libs/rebound-core.jar /Users/huaihuhu/Desktop/rebound/rebound-0.3.8/rebound-android/build/intermediates/bundles/default/classes.jar /Users/huaihuhu/Desktop/rebound/rebound-0.3.8/rebound-android-playground/build/intermediates/classes/debug}
Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
SpringSystem system = SpringSystem.create();
Spring a = system.createSpring();
Spring b = system.createSpring();
a.getSpringConfig().tension = 123;
a.getSpringConfig().friction = 456;
Log.e("REBOUND", "t: " + b.getSpringConfig().tension);
Log.e("REBOUND", "f: " + b.getSpringConfig().friction);
In this example, both a
and b
share the same default SpringConfig instance. This becomes an issue when code tries to mutate the SpringConfig on a
. We find that the SpringConfig on b
is accidentally mutated as well.
Guava is used for Preconditions
and list/map utilities. There is no reason to force downstream consumers of this library to bundle a massive 2.1MB jar when you aren't even really using it.
Preconditions
is easily inlined since they amount to just an if
+throw
. The list and map utilities are easily replaced by instantiating lists and maps yourself and using Collections.unmodifiableFoo(new Foo(thing))
for defensive copies.
I would have sent a pull request, but buck isn't on brew and didn't work with java 6, 7, or 8 on my system.
Thanks for the library, it is awesome.
I'm trying to use rebound for RecyclerView so that it can over scroll and bounce back just like the SpringScrollView in the playground-example. My implementation is working so far, but the way I do is using a wrapper adapter class and add a transparent header and footer rows into the original adapter. Then I use rebound library to handle the case when the header or footer row is visible. I'm not sure if it is the best way to do it or there is a better way. Can you give me an opinion or suggestion about that?
Thanks.
the project of rebound run with error:
Error:Execution failed for task ':rebound-android-example:preDexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
who can help me?thanks!
If you call the following consecutively it produces a Concurrent Exception, see the Stacktrace below.
Seems that ReentrantCallback
is not as safe as intended.
mSpringFrom.addListener(new SimpleSpringListener() {
@Override
public void onSpringUpdate(final Spring spring) {
from.setTranslationX((float) spring.getCurrentValue());
}
@Override
public void onSpringAtRest(final Spring spring) {
removeView(from);
mSpringFrom.removeListener(this);
}
});
java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:806)
at java.util.HashMap$KeyIterator.next(HashMap.java:833)
at java.util.Collections$UnmodifiableCollection$1.next(Collections.java:960)
at com.facebook.rebound.Spring.advance(Spring.java:402)
at com.facebook.rebound.BaseSpringSystem.advance(BaseSpringSystem.java:138)
at com.facebook.rebound.BaseSpringSystem.loop(BaseSpringSystem.java:159)
at com.facebook.rebound.AndroidSpringLooperFactory$ChoreographerAndroidSpringLooper$1.doFrame(AndroidSpringLooperFactory.java:108)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:759)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:543)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
In the Spring:
private ReentrantCallback mListeners = new ReentrantCallback();
In the SpringSystem:
private ReentrantCallback mListeners = new ReentrantCallback();
Why use List ? Can you for example? thank you.
can I use rebound library in listview or recycleview?
I'm currently using both libraries with nineoldandroids nested inside rebound to make the animations work on older android versions.
public void onSpringUpdate(Spring spring) {
float logoPosition = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, splash_logo.getBottom(), 0);
// this is where I nest the ObjectAnimator class from NineOldAndroids library
ObjectAnimator.ofFloat(splash_logo, "translationY", previousPosition, logoPosition).setDuration(1).start();
previousPosition = logoPosition;
}
Hello,
Does this lib work with markers/maps?
I would like to see one of those anmations everytime I add a new marker.
Thanks.
I was playing around with the demo and it's a cool library. Feeling mischievous, I put some negative values in for tension
to test the behavior. -1 and -10 seemed to work fine, but when I jumped up to -100 it quickly overloaded my browser's capabilities and crashed as the sample image outgrew its borders. Is it intended to accept negative values? Should there be some sort of cap or is it the developer's responsibility?
A quick Google search reveals that a negative tension may be breaking some laws of physics. Quoting an answer from a physics forum: "A negative tension, to my mind, would mean that the string should spontaneously blow itself apart."
I use ubuntu java oracle 1.8 android studio. Compile error: Error: Execution failed for task ': rebound-android-example: preDexDebug'.
Com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command' / usr / lib / jvm / java-8-oracle / bin / java '' finished with non-zero exit value 1
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dixeam.millionarequotes, PID: 20997 java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/rebound/SpringSystem;
at com.dixeam.millionarequotes.utils.RecyclerViewAnimator.(RecyclerViewAnimator.java:51) at com.dixeam.millionarequotes.Recent$SimpleStringRecyclerViewAdapter.(Recent.java:155) at com.dixeam.millionarequotes.Recent.setupRecyclerView(Recent.java:68) at com.dixeam.millionarequotes.Recent.onCreateView(Recent.java:53)
Please help me.
Do you have plans to release any documentation for the JS version?
Thanks!
I just try and want to enhance Usage in README.md.
Add spring.setEndValue(1) in myView OnTouchListener, otherwise onSpringUpdate won't be call.
I found out the example have this one, but on read me page didn't.
Thank you so much!
Thanks you very much for this excellent library! Great work on this! I was playing around with the samples and I would like to use the rubber effect for ListViews. Do you know a way how to integrate the spring physics in a ListView?
Would be really nice if you could make a sample ;-) Thank you for you help!
Can you add my app in the list? :)
BallExample.java Line125 ArrayIndexOutOfBoundsException: length=9; index=9
Smoji app for Android uses Rebound for most of spring animations including Smoji "chat heads" and hiding/expanding layout items.
https://play.google.com/store/apps/details?id=com.browselabs.smoji
I want one of my widgets can animate without bouncing, but I have to rely on changes in the value of the onSpringUpdate callback method.So is there a api to know Spring is in Bouncing?
I would like to use this librarySpringScrollView scrollbar
,
Make it with the SpringScrollView
effect, how to use
Hi,
Just saw we can list app using rebound here. Inflikr is using it for some animations.
Like here http://www.youtube.com/watch?v=a8A80I8S3fs#t=26
Playstore link https://play.google.com/store/apps/details?id=kr.infli
Thanks
The version of rebound.js on npm has an outdated version of createSpring:
createSpring: function() {
var spring = new Spring(this);
this.registerSpring(spring);
return spring;
},
Instead of what is in the docs
createSpring: function(tension, friction) {
var spring = new Spring(this);
this.registerSpring(spring);
if (typeof tension === 'undefined' || typeof friction === 'undefined') {
spring.setSpringConfig(SpringConfig.DEFAULT_ORIGAMI_SPRING_CONFIG);
} else {
var springConfig = SpringConfig.fromOrigamiTensionAndFriction(tension, friction);
spring.setSpringConfig(springConfig);
}
return spring;
},
When following the example in the docs it throws an error since this._springConfig is never defined in the old version. *Great addition btw
I would love to see rebound.js become it's own project with it's own repo etc. I have some performance improvements to add :)
Hi.
SpringOverScroller.java#L86-L87: getCurrVelocity
public float getCurrVelocity() {
double velX = mSpringX.getVelocity();
double velY = mSpringX.getVelocity();
return (int) Math.sqrt(velX * velX + velY * velY);
}
It is suspicious that the variables 'velX' and 'velY' are initialized with the same value.
Probably, it should be:
public float getCurrVelocity() {
double velX = mSpringX.getVelocity();
double velY = mSpringY.getVelocity();
return (int) Math.sqrt(velX * velX + velY * velY);
}
This possible defect found by AppChecker.
This would me amazing if you add my library to list of apps and libraries that uses Rebound. <3
gradle.build should be updated to represent the latest Gradle tools.
This means updating the buildscript dependencies (classpath 'com.android.tools.build:gradle:0.7.1+') and the defaultConfig (minSdkVersion 14 and targetSdkVersion 19)
Second these slides, add this property to the view will increase the performance of the animations. And did!
I've an complex animation on my application, a little bit slow. After I add this property, the animation runs at 60fps smoothly.
Usage:
@Override public void onSpringActivate(Spring spring) {
super.onSpringActivate(spring);
happyView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
@Override public void onSpringUpdate(Spring spring) {
//do something...
}
@Override public void onSpringAtRest(Spring spring) {
super.onSpringAtRest(spring);
happyView.setLayerType(View.LAYER_TYPE_NONE, null);
}
Or, we can use ViewCompat to support API 10 using:
ViewCompat.setLayerType();
We can advise the developers to don't forget this point.
Not sure if this is known, but installing Rebound using JDK 1.8u25 fails (both Playground and Example). It's weird because Gradle says the build succeeds until I try to push it to a device. JDK 1.7u75 has no issues, so I'm not too sure exactly what's going on. I don't see any specific build.gradle or settings.gradle files which specify a JDK version to build with either.
Error occurs during preDexDebug:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.processClass(Main.java:665)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
at com.android.dx.command.dexer.Main.access$600(Main.java:78)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:596)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
...while parsing com/facebook/rebound/BaseSpringSystem.class
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.