Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add animation listener #17

Open
KhalidElSayed opened this issue Nov 23, 2016 · 4 comments
Open

add animation listener #17

KhalidElSayed opened this issue Nov 23, 2016 · 4 comments
Labels

Comments

@KhalidElSayed
Copy link

When I create an animation using actor like the following:

new Actor.Builder(SpringSystem.create(), rootView.findViewById(R.id.circle)) .addTranslateMotion(Imitator.TRACK_DELTA, Imitator.FOLLOW_EXACT, MotionProperty.X).build();

I want to add a listener to control the behavior of the animation itself or to track the user actions, ex. when the user touch the view down, up or start moving it.

Note: I want to use this animation to create "Slide to Cancel" function. how can I achieve this function using the above animation.

@ericleong
Copy link
Contributor

You can track the user actions by adding a View.OnTouchListener:

new Actor.Builder(SpringSystem.create(), rootView.findViewById(R.id.circle))
		.addTranslateMotion(Imitator.TRACK_DELTA, Imitator.FOLLOW_EXACT, MotionProperty.X)
		.onTouchListener(new View.OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// custom behavior
				return true;
			}
		})

But if you want to actually add new behavior to the animation, you can do something like this:, which will fade the view as the user moves it:

final View circle = rootView.findViewById(R.id.circle);
SpringSystem springSystem = SpringSystem.create();

new Actor.Builder(springSystem, rootView.findViewById(R.id.circle))
		.addMotion(springSystem.createSpring(), Imitator.TRACK_DELTA, Imitator.FOLLOW_EXACT,
				0, MotionProperty.X, new SimpleSpringListener() {
					@Override
					public void onSpringUpdate(Spring spring) {
						circle.setAlpha(
								1 - 2 * Math.abs((float) spring.getCurrentValue())
										/ rootView.getMeasuredWidth());
					}
				})
		.build();

But if you're looking to control the animation, that may get a little complicated since the spring will animate on its own, so you will need to decide whether or not to use the spring's value or your own custom value.

@Bharathbol
Copy link

That's program Errors create your

@Bharathbol
Copy link

Actor walk = new Actor.Builder(SpringSystem.create(), walker)
.addMotion(
new MotionImitator(MotionProperty.X),
new Performer(View.TRANSLATION_X))
.build();

@metin39
Copy link

metin39 commented Dec 26, 2023

rootView.findViewById(R.id.circle))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants