Filter end actions for null, and allow Runnables from Java

Test: atest SystemUITests
Change-Id: I7521937000b624621275670472a49cccdab29d78
This commit is contained in:
Joshua Tsuji
2020-01-14 15:51:48 -05:00
parent 4ce22b5125
commit bace2241eb

View File

@@ -367,8 +367,17 @@ class PhysicsAnimator<T> private constructor (val target: T) {
* animation is explicitly canceled, use [addEndListener]. End listeners have an allEnded param,
* which indicates that all relevant animations have ended.
*/
fun withEndActions(vararg endActions: EndAction): PhysicsAnimator<T> {
this.endActions.addAll(endActions)
fun withEndActions(vararg endActions: EndAction?): PhysicsAnimator<T> {
this.endActions.addAll(endActions.filterNotNull())
return this
}
/**
* Helper overload so that callers from Java can use Runnables or method references as end
* actions without having to explicitly return Unit.
*/
fun withEndActions(vararg endActions: Runnable?): PhysicsAnimator<T> {
this.endActions.addAll(endActions.filterNotNull().map { it::run })
return this
}