Backboard icon indicating copy to clipboard operation
Backboard copied to clipboard

add animation listener

Open KhalidElSayed opened this issue 8 years ago • 4 comments

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.

KhalidElSayed avatar Nov 23 '16 22:11 KhalidElSayed

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.

ericleong avatar Nov 25 '16 05:11 ericleong

That's program Errors create your

Bharathbol avatar Sep 22 '23 04:09 Bharathbol

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

Bharathbol avatar Sep 22 '23 04:09 Bharathbol

rootView.findViewById(R.id.circle))

metin39 avatar Dec 26 '23 15:12 metin39