Good evening. I write my custom widget, in which there is animation. You need to put a listener on the animation progress and implement a kelback so that you can use the progress percentage for the developer's actions.

What I want is present in BottomSheetBehavior.BottomSheetCallback , trying to get the code of this class (or the interface, I do not even know what it is used for) - to no avail. Help with any ideas. thank

  • Usually, on the contrary, there is a source of progress, and the widget only shows them. Or I did not understand the question. - tse
  • I just do not know how to explain. You need to somehow write in the widget the listener on the progress of the animation and add the ability to use it in the activity. It seems that you understood - Flippy
  • Then tell me why not the other way around? - tse
  • I do not understand: D - Flippy
  • Well, think. :) Android is a fairly flexible system. Deadlock in the decision usually means an error in architecture. It is unlikely that you have a task that contradicts the concept of UI. - tse

1 answer 1

What's the problem with the source code? It seems that here are the very sources.

But in general, as far as I know, there is no way to get exactly the animation progress event, although you can wait until the end of one animation using Animation.AnimationListener .

Alternatively, you can combine several animations in a chain using AnimatorSet.playSequentially , where you can also track the end of animations using Animator.AnimatorListener . Alas, not sure about the performance of the latter solution.

  • Apparently there are no solutions at all. - Flippy
  • Or maybe CountDownTimer ? Cheto doperlo like. Together with the animation run it as a step to take a millisecond. duration animation set as a finish. In the onTick method onTick changing the variable to initially zero for a millisecond more. But I do not understand how to prescribe everything. - Flippy
  • I do not understand how to prescribe the very logic of using this variable in activity. I thought of it. You can divide the variable by the duration animation and get a value of type float - Flippy
  • @ SergeyGrushin And why any additional variables? Your onTick is the place to call the callback. You know how much time is required for the operation and how much time has passed, based on this, the percentage of completion. So call the code you need directly from onTick . Only then is it worth to put a smaller number of ticks so that the callback is not called too often. And tell me more, what is the problem? Maybe you can do something else. - Agrgg
  • I am writing FlipView . There are two githubs on it, but I want to make it even better. And in general .. I do not understand)) I don’t have a task. I’m writing a custom view and I want to stuff it with everything I can so that there is good usability and the user-developer has easily adapted to it. But everyone has different needs. - Flippy