nvanbenschoten / motion

An Android library allowing images to exhibit a parallax effect that reacts to the device's tilt
Apache License 2.0
776 stars 89 forks source link

Image "jumps" when leaving activity #6

Closed Mathbl closed 10 years ago

Mathbl commented 10 years ago

First, great library!

Second, i'm wondering if anyone have an idea/fix for this situation : I'm registering/unregistering the sensor in onResume/onPause. But when i'm leaving the activity for another one, the sensor unregister and the image "jumps" to it's original position.

So, anyone have an idea on how to fix the image to the actual position (sort of snapshot) when unregistering sensor.

nvanbenschoten commented 10 years ago

Hey Mathieu,

Thanks for the interest in the library and thanks for the idea! Looking at the source code, I actually see a pretty easy fix for this that should be fully backwards compatible. I just wanted to run the API change by you before I push it.

Right now, the only way to unregister the sensor manager is to use the method

unregisterSensorManager();

I could add a second method

unregisterSensorManager(boolean resetTranslation)

If this reset flag is set to true, the current behavior will be seen. If it is set to false, the sensor manager will be unregistered, but the image will maintain its current translation state. The old parameter-less version of the method will simply call the new method with a resetTranslation of true.

Does this sound like it would work for you?

Mathbl commented 10 years ago

Sounds great. Curious to see the result. But it sounds like it would fix the issue.

Mathbl commented 10 years ago

I just tested the fix. It works as expected. Good job. I think it is a nice option to have.

If you can push it to mavenCentral, when you have time, that would be great.

Thank you!

nvanbenschoten commented 10 years ago

Sorry for the delay. The update should be pushed to Maven Central now.

If you look over the last commit, you'll also notice I've defaulted unregistering the sensor manager to not reset the image translation. I think this will improve the library for the average user. Thanks for the contribution!